package com.hw.system.common.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
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.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.system.common.domain.WfProcess;
import com.hw.system.common.service.IWfProcessService;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.utils.poi.ExcelUtil;
import com.hw.common.core.web.page.TableDataInfo;

/**
 * 工单流程Controller
 *
 * @author xins
 * @date 2024-01-19
 */
@RestController
@RequestMapping("/wfprocess")
public class WfProcessController extends BaseController
{
    @Autowired
    private IWfProcessService wfProcessService;

    /**
     * 查询工单流程列表
     */
    @RequiresPermissions("system:wfprocess:list")
    @GetMapping("/list")
    public TableDataInfo list(WfProcess wfProcess)
    {
        startPage();
        List<WfProcess> list = wfProcessService.selectWfProcessList(wfProcess);
        return getDataTable(list);
    }

    /**
     * 导出工单流程列表
     */
    @RequiresPermissions("system:wfprocess:export")
    @Log(title = "工单流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfProcess wfProcess)
    {
        List<WfProcess> list = wfProcessService.selectWfProcessList(wfProcess);
        ExcelUtil<WfProcess> util = new ExcelUtil<WfProcess>(WfProcess.class);
        util.exportExcel(response, list, "工单流程数据");
    }

    /**
     * 获取工单流程详细信息
     */
    @RequiresPermissions("system:wfprocess:query")
    @GetMapping(value = "/{wfProcessId}")
    public AjaxResult getInfo(@PathVariable("wfProcessId") Long wfProcessId)
    {
        return success(wfProcessService.selectWfProcessByWfProcessId(wfProcessId));
    }

    /**
     * 新增工单流程
     */
    @RequiresPermissions("system:wfprocess:add")
    @Log(title = "工单流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfProcess wfProcess)
    {
        return toAjax(wfProcessService.insertWfProcess(wfProcess));
    }

    /**
     * 修改工单流程
     */
    @RequiresPermissions("system:wfprocess:edit")
    @Log(title = "工单流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfProcess wfProcess)
    {


        return toAjax(wfProcessService.updateWfProcess(wfProcess));
    }

    /**
     * 删除工单流程
     */
    @RequiresPermissions("system:wfprocess:remove")
    @Log(title = "工单流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wfProcessIds}")
    public AjaxResult remove(@PathVariable Long[] wfProcessIds)
    {
        return toAjax(wfProcessService.deleteWfProcessByWfProcessIds(wfProcessIds));
    }
}
