package com.hw.system.common.controller;

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

import com.hw.common.security.annotation.InnerAuth;
import com.hw.system.api.domain.common.WfProcessActivity;
import com.hw.system.api.domain.common.vo.WfProcessActivityVo;
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.service.IWfProcessActivityService;
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("/wfprocessactivity")
public class WfProcessActivityController extends BaseController
{
    @Autowired
    private IWfProcessActivityService wfProcessActivityService;

    /**
     * 查询工单流程节点步骤列表
     */
    @RequiresPermissions("system:wfprocessactivity:list")
    @GetMapping("/list")
    public TableDataInfo list(WfProcessActivity wfProcessActivity)
    {
        startPage();
        List<WfProcessActivity> list = wfProcessActivityService.selectWfProcessActivityList(wfProcessActivity);
        return getDataTable(list);
    }

    /**
     * 导出工单流程节点步骤列表
     */
    @RequiresPermissions("system:wfprocessactivity:export")
    @Log(title = "工单流程节点步骤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfProcessActivity wfProcessActivity)
    {
        List<WfProcessActivity> list = wfProcessActivityService.selectWfProcessActivityList(wfProcessActivity);
        ExcelUtil<WfProcessActivity> util = new ExcelUtil<WfProcessActivity>(WfProcessActivity.class);
        util.exportExcel(response, list, "工单流程节点步骤数据");
    }

    /**
     * 获取工单流程节点步骤详细信息
     */
    @RequiresPermissions("system:wfprocessactivity:query")
    @GetMapping(value = "/{processActivityId}")
    public AjaxResult getInfo(@PathVariable("processActivityId") Long processActivityId)
    {
        return success(wfProcessActivityService.selectWfProcessActivityByProcessActivityId(processActivityId));
    }

    /**
     * 新增工单流程节点步骤
     */
    @RequiresPermissions("system:wfprocessactivity:add")
    @Log(title = "工单流程节点步骤", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfProcessActivity wfProcessActivity)
    {
        return toAjax(wfProcessActivityService.insertWfProcessActivity(wfProcessActivity));
    }

    /**
     * 修改工单流程节点步骤
     */
    @RequiresPermissions("system:wfprocessactivity:edit")
    @Log(title = "工单流程节点步骤", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfProcessActivity wfProcessActivity)
    {
        return toAjax(wfProcessActivityService.updateWfProcessActivity(wfProcessActivity));
    }

    /**
     * 删除工单流程节点步骤
     */
    @RequiresPermissions("system:wfprocessactivity:remove")
    @Log(title = "工单流程节点步骤", businessType = BusinessType.DELETE)
	@DeleteMapping("/{processActivityIds}")
    public AjaxResult remove(@PathVariable Long[] processActivityIds)
    {
        return toAjax(wfProcessActivityService.deleteWfProcessActivityByProcessActivityIds(processActivityIds));
    }
    /**
     * 通过wfid查询第一步的主键id
     * */
    @PostMapping("/selectProcessActivityIdByWfProcessId")
    public Long selectProcessActivityIdByWfProcessId(@RequestBody  Long wfProcessId){
        return wfProcessActivityService.selectProcessActivityIdByWfProcessId(wfProcessId);
//        return 200l;
    }



    @InnerAuth
    @PostMapping("/getWfProcessActivityByUI")
    public AjaxResult getWfProcessActivityByUI(@RequestBody WfProcessActivityVo queryProcessActivityVo) {
        return success(wfProcessActivityService.selectWfProcessActivityByUI(queryProcessActivityVo.getWfProcessId(),
                queryProcessActivityVo.getProcessActivityOrder()));
    }
}
