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.AndonRule;
import com.aucma.production.service.IAndonRuleService;
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/andonRule" )
public class AndonRuleController extends BaseController {
    @Autowired
    private IAndonRuleService andonRuleService;

    /**
     * 查询安灯规则配置列表
     */
    @PreAuthorize("@ss.hasPermi('production:andonRule:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(AndonRule andonRule) {
        startPage();
        List<AndonRule> list = andonRuleService.selectAndonRuleList(andonRule);
        return getDataTable(list);
    }

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

    /**
     * 获取安灯规则配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:andonRule:query')" )
    @GetMapping(value = "/{ruleId}" )
    public AjaxResult getInfo(@PathVariable("ruleId" ) Long ruleId) {
        return success(andonRuleService.selectAndonRuleByRuleId(ruleId));
    }

    /**
     * 新增安灯规则配置
     */
    @PreAuthorize("@ss.hasPermi('production:andonRule:add')" )
    @Log(title = "安灯规则配置" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AndonRule andonRule) {
        andonRule.setCreateBy(getUsername());
        andonRule.setCreateTime(DateUtils.getNowDate());
        return toAjax(andonRuleService.insertAndonRule(andonRule));
    }

    /**
     * 修改安灯规则配置
     */
    @PreAuthorize("@ss.hasPermi('production:andonRule:edit')" )
    @Log(title = "安灯规则配置" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AndonRule andonRule) {
        andonRule.setUpdateBy(getUsername());
        andonRule.setUpdateTime(DateUtils.getNowDate());
        return toAjax(andonRuleService.updateAndonRule(andonRule));
    }

    /**
     * 删除安灯规则配置
     */
    @PreAuthorize("@ss.hasPermi('production:andonRule:remove')" )
    @Log(title = "安灯规则配置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ruleIds}" )
    public AjaxResult remove(@PathVariable Long[] ruleIds) {
        return toAjax(andonRuleService.deleteAndonRuleByRuleIds(ruleIds));
    }


    /**
     * 查询安灯规则配置列表
     */
    @PreAuthorize("@ss.hasPermi('production:andonRule:list')" )
    @GetMapping("/getAndonRuleList" )
    public AjaxResult getAndonRuleList(AndonRule andonRule) {
        List<AndonRule> list = andonRuleService.selectAndonRuleList(andonRule);
        return success(list);
    }

}
