package com.aucma.dms.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.poi.ExcelUtil;
import com.aucma.dms.domain.DmsDispatchPlan;
import com.aucma.dms.service.IDmsDispatchPlanService;
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 Cascade AI
 * @date 2025-01-10
 */
@RestController
@RequestMapping("/dms/dispatchPlan")
public class DmsDispatchPlanController extends BaseController {
    
    @Autowired
    private IDmsDispatchPlanService dmsDispatchPlanService;

    /**
     * 查询派工计划列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:dispatchPlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsDispatchPlan dmsDispatchPlan) {
        startPage();
        List<DmsDispatchPlan> list = dmsDispatchPlanService.selectDmsDispatchPlanList(dmsDispatchPlan);
        return getDataTable(list);
    }

    /**
     * 导出派工计划列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:dispatchPlan:export')")
    @Log(title = "派工计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsDispatchPlan dmsDispatchPlan) {
        List<DmsDispatchPlan> list = dmsDispatchPlanService.selectDmsDispatchPlanList(dmsDispatchPlan);
        ExcelUtil<DmsDispatchPlan> util = new ExcelUtil<DmsDispatchPlan>(DmsDispatchPlan.class);
        util.exportExcel(response, list, "派工计划数据");
    }

    /**
     * 获取派工计划详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:dispatchPlan:query')")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId) {
        return AjaxResult.success(dmsDispatchPlanService.selectDmsDispatchPlanByPlanId(planId));
    }

    /**
     * 新增派工计划
     */
    //@PreAuthorize("@ss.hasPermi('dms:dispatchPlan:add')")
    @Log(title = "派工计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsDispatchPlan dmsDispatchPlan) {
        return toAjax(dmsDispatchPlanService.insertDmsDispatchPlan(dmsDispatchPlan));
    }

    /**
     * 修改派工计划
     */
    //@PreAuthorize("@ss.hasPermi('dms:dispatchPlan:edit')")
    @Log(title = "派工计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsDispatchPlan dmsDispatchPlan) {
        return toAjax(dmsDispatchPlanService.updateDmsDispatchPlan(dmsDispatchPlan));
    }

    /**
     * 删除派工计划
     */
    //@PreAuthorize("@ss.hasPermi('dms:dispatchPlan:remove')")
    @Log(title = "派工计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds) {
        return toAjax(dmsDispatchPlanService.deleteDmsDispatchPlanByPlanIds(planIds));
    }

    /**
     * 接收派工
     */
    //@PreAuthorize("@ss.hasPermi('dms:dispatchPlan:receive')")
    @Log(title = "接收派工", businessType = BusinessType.UPDATE)
    @PostMapping("/receive")
    public AjaxResult receive(@RequestBody DmsDispatchPlan dmsDispatchPlan) {
        return toAjax(dmsDispatchPlanService.receiveDispatch(dmsDispatchPlan.getPlanId()));
    }

    /**
     * 拒绝派工
     */
    //@PreAuthorize("@ss.hasPermi('dms:dispatchPlan:reject')")
    @Log(title = "拒绝派工", businessType = BusinessType.UPDATE)
    @PostMapping("/reject")
    public AjaxResult reject(@RequestBody DmsDispatchPlan dmsDispatchPlan) {
        return toAjax(dmsDispatchPlanService.rejectDispatch(dmsDispatchPlan));
    }
}
