package com.zhyc.module.work.controller;

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

import com.zhyc.module.work.domain.WorkOrder;
import com.zhyc.module.work.service.IWorkOrderService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhyc.common.annotation.Log;
import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult;
import com.zhyc.common.enums.BusinessType;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 派工单Controller
 * 
 * @author piaobo
 * @date 2025-12-07
 */
@RestController
@RequestMapping("/work/work")
public class WorkOrderController extends BaseController
{
    @Autowired
    private IWorkOrderService workOrderService;

    /**
     * 查询派工单列表
     */
    @PreAuthorize("@ss.hasPermi('work:work:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkOrder workOrder)
    {
        startPage();
        List<WorkOrder> list = workOrderService.selectWorkOrderList(workOrder);

        return getDataTable(list);
    }

    /**
     * 导出派工单列表
     */
    @PreAuthorize("@ss.hasPermi('work:work:export')")
    @Log(title = "派工单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkOrder workOrder)
    {
        List<WorkOrder> list = workOrderService.selectWorkOrderList(workOrder);
        ExcelUtil<WorkOrder> util = new ExcelUtil<WorkOrder>(WorkOrder.class);
        util.exportExcel(response, list, "派工单数据");
    }

    /**
     * 获取派工单详细信息
     */
    @PreAuthorize("@ss.hasPermi('work:work:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workOrderService.selectWorkOrderById(id));
    }

    /**
     * 新增派工单
     */
    @PreAuthorize("@ss.hasPermi('work:work:add')")
    @Log(title = "派工单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkOrder workOrder)
    {
        workOrder.setDeptId(getDeptId());   //修改成你对应的实体类
        workOrder.setUserId(getUserId());
        return toAjax(workOrderService.insertWorkOrder(workOrder));
    }

    /**
     * 修改派工单
     */
    @PreAuthorize("@ss.hasPermi('work:work:edit')")
    @Log(title = "派工单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkOrder workOrder)
    {
        return toAjax(workOrderService.updateWorkOrder(workOrder));
    }

    /**
     * 删除派工单
     */
    @PreAuthorize("@ss.hasPermi('work:work:remove')")
    @Log(title = "派工单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workOrderService.deleteWorkOrderByIds(ids));
    }
}
