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.AndonEventLog;
import com.aucma.production.service.IAndonEventLogService;
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/andonEventLog" )
public class AndonEventLogController extends BaseController {
    @Autowired
    private IAndonEventLogService andonEventLogService;

    /**
     * 查询安灯事件操作日志（审计与追踪）列表
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventLog:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(AndonEventLog andonEventLog) {
        startPage();
        List<AndonEventLog> list = andonEventLogService.selectAndonEventLogList(andonEventLog);
        return getDataTable(list);
    }

    /**
     * 导出安灯事件操作日志（审计与追踪）列表
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventLog:export')" )
    @Log(title = "安灯事件操作日志（审计与追踪）" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, AndonEventLog andonEventLog) {
        List<AndonEventLog> list = andonEventLogService.selectAndonEventLogList(andonEventLog);
        ExcelUtil<AndonEventLog> util = new ExcelUtil<AndonEventLog>(AndonEventLog. class);
        util.exportExcel(response, list, "安灯事件操作日志（审计与追踪）数据" );
    }

    /**
     * 获取安灯事件操作日志（审计与追踪）详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventLog:query')" )
    @GetMapping(value = "/{logId}" )
    public AjaxResult getInfo(@PathVariable("logId" ) Long logId) {
        return success(andonEventLogService.selectAndonEventLogByLogId(logId));
    }

    /**
     * 新增安灯事件操作日志（审计与追踪）
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventLog:add')" )
    @Log(title = "安灯事件操作日志（审计与追踪）" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AndonEventLog andonEventLog) {
        andonEventLog.setCreateBy(getUsername());
        andonEventLog.setCreateTime(DateUtils.getNowDate());
        return toAjax(andonEventLogService.insertAndonEventLog(andonEventLog));
    }

    /**
     * 修改安灯事件操作日志（审计与追踪）
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventLog:edit')" )
    @Log(title = "安灯事件操作日志（审计与追踪）" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AndonEventLog andonEventLog) {
        andonEventLog.setUpdateBy(getUsername());
        andonEventLog.setUpdateTime(DateUtils.getNowDate());
        return toAjax(andonEventLogService.updateAndonEventLog(andonEventLog));
    }

    /**
     * 删除安灯事件操作日志（审计与追踪）
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventLog:remove')" )
    @Log(title = "安灯事件操作日志（审计与追踪）" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{logIds}" )
    public AjaxResult remove(@PathVariable Long[] logIds) {
        return toAjax(andonEventLogService.deleteAndonEventLogByLogIds(logIds));
    }


    /**
     * 查询安灯事件操作日志（审计与追踪）列表
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventLog:list')" )
    @GetMapping("/getAndonEventLogList" )
    public AjaxResult getAndonEventLogList(AndonEventLog andonEventLog) {
        List<AndonEventLog> list = andonEventLogService.selectAndonEventLogList(andonEventLog);
        return success(list);
    }

}
