package com.ruoyi.web.controller.work;

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

import com.ruoyi.system.domain.vo.WordVo;
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:jd')")
    @Log(title = "工单信息", businessType = BusinessType.UPDATE)
    @PostMapping("/jd")
    public AjaxResult jd(@RequestBody WorkOrderInfo workOrderInfo)
    {
        return toAjax(workOrderInfoService.jd(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));
    }

    /**
     * 生成电子工单
     */
    @PreAuthorize("@ss.hasPermi('work:info:dz')")
    @GetMapping(value = "/dzgd/{orderId}")
    public AjaxResult dzgd(@PathVariable("orderId") String orderId)
    {
        return workOrderInfoService.dzgd(orderId);
    }

    /**
     * 签名
     */
    @PreAuthorize("@ss.hasPermi('work:info:qm')")
    @PostMapping(value = "/dzgd/qm")
    public AjaxResult qm(@RequestBody WordVo wordVo)
    {
        return workOrderInfoService.qm(wordVo);
    }

    /**
     * pc首页本月工单统计（流程）
     */
    @PreAuthorize("@ss.hasPermi('work:statistics:lc')")
    @GetMapping(value = "/statistics/lc")
    public AjaxResult lc()
    {
        return workOrderInfoService.lc();
    }

    /**
     * pc首页本月工单统计（服务）
     */
    @PreAuthorize("@ss.hasPermi('work:statistics:fw')")
    @GetMapping(value = "/statistics/fw")
    public AjaxResult fw()
    {
        return workOrderInfoService.fw();
    }

    /**
     * pc首页较上月工单统计（服务）
     */
    @PreAuthorize("@ss.hasPermi('work:statistics:bj')")
    @GetMapping(value = "/statistics/bj")
    public AjaxResult bj()
    {
        return workOrderInfoService.bj();
    }

    /**
     * pc首页top6员工（月）
     */
    @PreAuthorize("@ss.hasPermi('work:month:px')")
    @GetMapping(value = "/month/px")
    public AjaxResult monthPx(String time)
    {
        return workOrderInfoService.monthPx(time);
    }

    /**
     * app首页top6员工（年）
     */
    @PreAuthorize("@ss.hasPermi('work:year:px')")
    @GetMapping(value = "/year/px")
    public AjaxResult yearPx(String time)
    {
        return workOrderInfoService.yearPx(time);
    }

    /**
     * app服务类型单量统计（年）
     */
    @PreAuthorize("@ss.hasPermi('work:year:fwlx')")
    @GetMapping(value = "/year/fwlx")
    public AjaxResult yearFwlx(String time)
    {
        return workOrderInfoService.yearFwlx(time);
    }

    /**
     * APP首页季度个人接单统计
     */
    @PreAuthorize("@ss.hasPermi('work:statistics:jd')")
    @GetMapping(value = "/statistics/jd")
    public AjaxResult statisticsJd()
    {
        return workOrderInfoService.statisticsJd();
    }

    /**
     * APP我的年度工单统计（流程）
     */
    @PreAuthorize("@ss.hasPermi('work:year:lc')")
    @GetMapping(value = "/year/lc")
    public AjaxResult yearLc(String time)
    {
        return workOrderInfoService.yearLc(time);
    }

    /**
     * APP年度单量统计（折线图）
     */
    @PreAuthorize("@ss.hasPermi('work:year:month')")
    @GetMapping(value = "/year/month")
    public AjaxResult yearMonth(String time)
    {
        return workOrderInfoService.yearMonth(time);
    }

    /**
     * APP部门统计（流程）
     */
    @PreAuthorize("@ss.hasPermi('work:dept:lc')")
    @GetMapping(value = "/dept/lc")
    public AjaxResult deptLc(String time)
    {
        return workOrderInfoService.deptLc(time);
    }

    /**
     * 待办事项数量
     */
    @PreAuthorize("@ss.hasPermi('work:db:num')")
    @GetMapping(value = "/db/num")
    public AjaxResult dbNum()
    {
        return workOrderInfoService.dbNum();
    }
}
