package com.inspect.metadata.bdconfig.controller;

import com.inspect.metadata.bdconfig.domain.BasedataBdConfigMainSystem;
import com.inspect.metadata.bdconfig.service.IBasedataBdConfigMainSystemService;
import com.inspect.base.core.utils.poi.ExcelUtil;
import com.inspect.base.core.web.controller.BaseController;
import com.inspect.base.core.web.domain.AjaxResult;
import com.inspect.base.core.web.page.TableDataInfo;
import com.inspect.common.log.annotation.Log;
import com.inspect.common.log.enums.BizType;
import com.inspect.common.security.annotation.RequiresPermissions;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/bdconfig/mainsystem"})
public class BasedataBdConfigMainSystemController extends BaseController {
    private final IBasedataBdConfigMainSystemService basedataBdConfigMainSystemService;

    public BasedataBdConfigMainSystemController(IBasedataBdConfigMainSystemService basedataBdConfigMainSystemService) {
        this.basedataBdConfigMainSystemService = basedataBdConfigMainSystemService;
    }

    @RequiresPermissions({"basedata/bdconfig:mainsystem:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(BasedataBdConfigMainSystem basedataBdconfigMainsystem) {
        this.startPage();
        List<BasedataBdConfigMainSystem> list = this.basedataBdConfigMainSystemService.selectBasedataBdConfigMainSystemList(basedataBdconfigMainsystem);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"basedata/bdconfig:mainsystem:export"})
    @Log(
            title = "基础数据-主系统配置",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, BasedataBdConfigMainSystem basedataBdconfigMainsystem) {
        List<BasedataBdConfigMainSystem> list = this.basedataBdConfigMainSystemService.selectBasedataBdConfigMainSystemList(basedataBdconfigMainsystem);
        ExcelUtil<BasedataBdConfigMainSystem> util = new ExcelUtil<>(BasedataBdConfigMainSystem.class);
        util.exportExcel(response, list, "基础数据-主系统配置数据");
    }

    @RequiresPermissions({"basedata/bdconfig:mainsystem:query"})
    @GetMapping({"/{mainsystemId}"})
    public AjaxResult getInfo(@PathVariable("mainsystemId") Long mainSystemId) {
        return AjaxResult.success(this.basedataBdConfigMainSystemService.selectBasedataBdConfigMainSystemByMainSystemId(mainSystemId));
    }

    @RequiresPermissions({"basedata/bdconfig:mainsystem:add"})
    @Log(
            title = "基础数据-主系统配置",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody BasedataBdConfigMainSystem basedataBdconfigMainsystem) {
        return this.toAjax(this.basedataBdConfigMainSystemService.insertBasedataBdConfigMainSystem(basedataBdconfigMainsystem));
    }

    @RequiresPermissions({"basedata/bdconfig:mainsystem:edit"})
    @Log(
            title = "基础数据-主系统配置",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody BasedataBdConfigMainSystem basedataBdconfigMainsystem) {
        return this.toAjax(this.basedataBdConfigMainSystemService.updateBasedataBdConfigMainSystem(basedataBdconfigMainsystem));
    }

    @RequiresPermissions({"basedata/bdconfig:mainsystem:remove"})
    @Log(
            title = "基础数据-主系统配置",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{mainsystemIds}"})
    public AjaxResult remove(@PathVariable("mainsystemIds") Long[] mainSystemIds) {
        return this.toAjax(this.basedataBdConfigMainSystemService.deleteBasedataBdConfigMainSystemByMainSystemIds(mainSystemIds));
    }

    @RequiresPermissions({"basedata/bdconfig:mainsystem:list"})
    @Log(
            title = "基础数据-主系统配置",
            businessType = BizType.OTHER
    )
    @PostMapping({"/getBdconfigMainsystem"})
    public AjaxResult getBdConfigMainSystem() {
        List<BasedataBdConfigMainSystem> list = this.basedataBdConfigMainSystemService.selectBasedataBdConfigMainSystemList(new BasedataBdConfigMainSystem());
        return AjaxResult.success(list);
    }
}
