package com.aucma.production.controller;

import com.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.core.page.TableDataInfo;
import com.aucma.common.enums.BusinessType;
import com.aucma.common.utils.DateUtils;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.production.domain.AndonBoardConfig;
import com.aucma.production.service.IAndonBoardConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 安灯看板配置Controller
 *
 * @author Yinq
 * @date 2025-10-28
 */
@RestController
@RequestMapping("/production/andonBoardConfig" )
public class AndonBoardConfigController extends BaseController {
    @Autowired
    private IAndonBoardConfigService andonBoardConfigService;

    /**
     * 查询安灯看板配置列表
     */
    @PreAuthorize("@ss.hasPermi('production:andonBoardConfig:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(AndonBoardConfig andonBoardConfig) {
        startPage();
        List<AndonBoardConfig> list = andonBoardConfigService.selectAndonBoardConfigList(andonBoardConfig);
        return getDataTable(list);
    }

    /**
     * 导出安灯看板配置列表
     */
    @PreAuthorize("@ss.hasPermi('production:andonBoardConfig:export')" )
    @Log(title = "安灯看板配置" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, AndonBoardConfig andonBoardConfig) {
        List<AndonBoardConfig> list = andonBoardConfigService.selectAndonBoardConfigList(andonBoardConfig);
        ExcelUtil<AndonBoardConfig> util = new ExcelUtil<AndonBoardConfig>(AndonBoardConfig. class);
        util.exportExcel(response, list, "安灯看板配置数据" );
    }

    /**
     * 获取安灯看板配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:andonBoardConfig:query')" )
    @GetMapping(value = "/{boardId}" )
    public AjaxResult getInfo(@PathVariable("boardId" ) Long boardId) {
        return success(andonBoardConfigService.selectAndonBoardConfigByBoardId(boardId));
    }

    /**
     * 新增安灯看板配置
     */
    @PreAuthorize("@ss.hasPermi('production:andonBoardConfig:add')" )
    @Log(title = "安灯看板配置" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AndonBoardConfig andonBoardConfig) {
        andonBoardConfig.setCreateBy(getUsername());
        andonBoardConfig.setCreateTime(DateUtils.getNowDate());
        return toAjax(andonBoardConfigService.insertAndonBoardConfig(andonBoardConfig));
    }

    /**
     * 修改安灯看板配置
     */
    @PreAuthorize("@ss.hasPermi('production:andonBoardConfig:edit')" )
    @Log(title = "安灯看板配置" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AndonBoardConfig andonBoardConfig) {
        andonBoardConfig.setUpdateBy(getUsername());
        andonBoardConfig.setUpdateTime(DateUtils.getNowDate());
        return toAjax(andonBoardConfigService.updateAndonBoardConfig(andonBoardConfig));
    }

    /**
     * 删除安灯看板配置
     */
    @PreAuthorize("@ss.hasPermi('production:andonBoardConfig:remove')" )
    @Log(title = "安灯看板配置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{boardIds}" )
    public AjaxResult remove(@PathVariable Long[] boardIds) {
        return toAjax(andonBoardConfigService.deleteAndonBoardConfigByBoardIds(boardIds));
    }


    /**
     * 查询安灯看板配置列表
     */
    @PreAuthorize("@ss.hasPermi('production:andonBoardConfig:list')" )
    @GetMapping("/getAndonBoardConfigList" )
    public AjaxResult getAndonBoardConfigList(AndonBoardConfig andonBoardConfig) {
        List<AndonBoardConfig> list = andonBoardConfigService.selectAndonBoardConfigList(andonBoardConfig);
        return success(list);
    }

}
