package com.ruoyi.web.controller.doubleDefense;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.doubledefense.domain.FourColorDiagram;
import com.ruoyi.doubledefense.service.IFourColorDiagramService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 四色图Controller
 *
 * @author lyp
 * @date 2023-09-16
 */
@RestController
@RequestMapping("/doubledefense/diagram")
public class FourColorDiagramController extends BaseController {
    @Autowired
    private IFourColorDiagramService fourColorDiagramService;

    /**
     * 查询四色图列表
     */
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:diagram:list')")
    @GetMapping("/list")
    public TableDataInfo list(FourColorDiagram fourColorDiagram) {
        startPage();
        List<FourColorDiagram> list = fourColorDiagramService.selectFourColorDiagramList(fourColorDiagram);
        return getDataTable(list);
    }

    /**
     * 导出四色图列表
     */
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:diagram:export')")
    @Log(title = "四色图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FourColorDiagram fourColorDiagram) {
        List<FourColorDiagram> list = fourColorDiagramService.selectFourColorDiagramList(fourColorDiagram);
        ExcelUtil<FourColorDiagram> util = new ExcelUtil<FourColorDiagram>(FourColorDiagram.class);
        util.exportExcel(response, list, "四色图数据");
    }

    /**
     * 获取四色图详细信息
     */
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:diagram:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(fourColorDiagramService.selectFourColorDiagramById(id));
    }

    /**
     * 新增四色图
     */
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:diagram:add')")
    @Log(title = "四色图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FourColorDiagram fourColorDiagram) {
        return toAjax(fourColorDiagramService.insertFourColorDiagram(fourColorDiagram));
    }

    /**
     * 修改四色图
     */
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:diagram:edit')")
    @Log(title = "四色图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FourColorDiagram fourColorDiagram) {
        return toAjax(fourColorDiagramService.updateFourColorDiagram(fourColorDiagram));
    }

    /**
     * 删除四色图
     */
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:diagram:remove')")
    @Log(title = "四色图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(fourColorDiagramService.deleteFourColorDiagramByIds(ids));
    }
}
