package com.ruoyi.web.controller.work;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WorkOrderInfo;
import com.ruoyi.system.service.IWorkOrderInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工单信息Controller
 * 
 * @author ruoyi
 * @date 2025-05-12
 */
@RestController
@RequestMapping("/work/info")
public class WorkOrderInfoController extends BaseController
{
    @Autowired
    private IWorkOrderInfoService workOrderInfoService;

    /**
     * 查询工单信息列表
     */
    @PreAuthorize("@ss.hasPermi('work:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkOrderInfo workOrderInfo)
    {
        startPage();
        List<WorkOrderInfo> list = workOrderInfoService.selectWorkOrderInfoList(workOrderInfo);
        return getDataTable(list);
    }

    /**
     * 导出工单信息列表
     */
    @PreAuthorize("@ss.hasPermi('work:info:export')")
    @Log(title = "工单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkOrderInfo workOrderInfo)
    {
        List<WorkOrderInfo> list = workOrderInfoService.selectWorkOrderInfoList(workOrderInfo);
        ExcelUtil<WorkOrderInfo> util = new ExcelUtil<WorkOrderInfo>(WorkOrderInfo.class);
        util.exportExcel(response, list, "工单信息数据");
    }

    /**
     * 获取工单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('work:info:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
    {
        return success(workOrderInfoService.selectWorkOrderInfoByOrderId(orderId));
    }

    /**
     * 新增工单信息
     */
    @PreAuthorize("@ss.hasPermi('work:info:add')")
    @Log(title = "工单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkOrderInfo workOrderInfo)
    {
        return toAjax(workOrderInfoService.insertWorkOrderInfo(workOrderInfo));
    }

    /**
     * 修改工单信息
     */
    @PreAuthorize("@ss.hasPermi('work:info:edit')")
    @Log(title = "工单信息", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody WorkOrderInfo workOrderInfo)
    {
        return toAjax(workOrderInfoService.updateWorkOrderInfo(workOrderInfo));
    }

    /**
     * 删除工单信息
     */
    @PreAuthorize("@ss.hasPermi('work:info:remove')")
    @Log(title = "工单信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds)
    {
        return toAjax(workOrderInfoService.deleteWorkOrderInfoByOrderIds(orderIds));
    }
}
