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.AndonEventAssignment;
import com.aucma.production.service.IAndonEventAssignmentService;
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/andonEventAssignment" )
public class AndonEventAssignmentController extends BaseController {
    @Autowired
    private IAndonEventAssignmentService andonEventAssignmentService;

    /**
     * 查询安灯派工记录（派工即通知/待办）列表
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventAssignment:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(AndonEventAssignment andonEventAssignment) {
        startPage();
        List<AndonEventAssignment> list = andonEventAssignmentService.selectAndonEventAssignmentList(andonEventAssignment);
        return getDataTable(list);
    }

    /**
     * 导出安灯派工记录（派工即通知/待办）列表
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventAssignment:export')" )
    @Log(title = "安灯派工记录（派工即通知/待办）" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, AndonEventAssignment andonEventAssignment) {
        List<AndonEventAssignment> list = andonEventAssignmentService.selectAndonEventAssignmentList(andonEventAssignment);
        ExcelUtil<AndonEventAssignment> util = new ExcelUtil<AndonEventAssignment>(AndonEventAssignment. class);
        util.exportExcel(response, list, "安灯派工记录（派工即通知/待办）数据" );
    }

    /**
     * 获取安灯派工记录（派工即通知/待办）详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventAssignment:query')" )
    @GetMapping(value = "/{assignmentId}" )
    public AjaxResult getInfo(@PathVariable("assignmentId" ) Long assignmentId) {
        return success(andonEventAssignmentService.selectAndonEventAssignmentByAssignmentId(assignmentId));
    }

    /**
     * 新增安灯派工记录（派工即通知/待办）
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventAssignment:add')" )
    @Log(title = "安灯派工记录（派工即通知/待办）" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AndonEventAssignment andonEventAssignment) {
        andonEventAssignment.setCreateBy(getUsername());
        andonEventAssignment.setCreateTime(DateUtils.getNowDate());
        return toAjax(andonEventAssignmentService.insertAndonEventAssignment(andonEventAssignment));
    }

    /**
     * 修改安灯派工记录（派工即通知/待办）
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventAssignment:edit')" )
    @Log(title = "安灯派工记录（派工即通知/待办）" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AndonEventAssignment andonEventAssignment) {
        andonEventAssignment.setUpdateBy(getUsername());
        andonEventAssignment.setUpdateTime(DateUtils.getNowDate());
        return toAjax(andonEventAssignmentService.updateAndonEventAssignment(andonEventAssignment));
    }

    /**
     * 删除安灯派工记录（派工即通知/待办）
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventAssignment:remove')" )
    @Log(title = "安灯派工记录（派工即通知/待办）" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{assignmentIds}" )
    public AjaxResult remove(@PathVariable Long[] assignmentIds) {
        return toAjax(andonEventAssignmentService.deleteAndonEventAssignmentByAssignmentIds(assignmentIds));
    }


    /**
     * 查询安灯派工记录（派工即通知/待办）列表
     */
    @PreAuthorize("@ss.hasPermi('production:andonEventAssignment:list')" )
    @GetMapping("/getAndonEventAssignmentList" )
    public AjaxResult getAndonEventAssignmentList(AndonEventAssignment andonEventAssignment) {
        List<AndonEventAssignment> list = andonEventAssignmentService.selectAndonEventAssignmentList(andonEventAssignment);
        return success(list);
    }

}
