package com.zkqy.execution.produce.dispersed.controller;

import javax.servlet.http.HttpServletResponse;

import com.zkqy.execution.produce.dispersed.runbpm.PreExecutionToolClass;
import com.zkqy.execution.produce.dispersed.runbpm.RunImplementationClass;
import com.zkqy.system.entity.CommonEntity;
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.zkqy.common.annotation.Log;
import com.zkqy.common.core.controller.BaseController;
import com.zkqy.common.core.domain.AjaxResult;
import com.zkqy.common.enums.BusinessType;
import com.zkqy.execution.produce.dispersed.entity.BpmExecuteProcess;
import com.zkqy.execution.produce.dispersed.service.IBpmExecuteProcessService;
import com.zkqy.common.core.page.TableDataInfo;

import java.util.Map;

/**
 * 流程执行任务Controller
 *
 * @author hzh
 * @date 2023-11-01
 */
@RestController
@RequestMapping("/system/execute/process")
public class BpmExecuteProcessController extends BaseController {
    @Autowired
    private IBpmExecuteProcessService bpmExecuteProcessService;
    @Autowired
    private RunImplementationClass implementationClass;
    @Autowired
    private PreExecutionToolClass PreExecutionToolClass;

    /**
     * 查询流程执行任务列表
     */
    // @PreAuthorize("@ss.hasPermi('system:process:list')")
    @GetMapping("/list")
    public TableDataInfo list(BpmExecuteProcess bpmExecuteProcess) throws Exception {
        startPage();
        return getDataTable(bpmExecuteProcessService.selectBpmExecuteProcessList(bpmExecuteProcess));
    }

    /**
     * 导出流程执行任务列表
     */
    // @PreAuthorize("@ss.hasPermi('system:process:export')")
    @Log(title = "流程执行任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BpmExecuteProcess bpmExecuteProcess) {
//        List<BpmExecuteProcess> list = bpmExecuteProcessService.selectBpmExecuteProcessList(bpmExecuteProcess);
//        ExcelUtil<BpmExecuteProcess> util = new ExcelUtil<BpmExecuteProcess>(BpmExecuteProcess.class);
//        util.exportExcel(response, list, "流程执行任务数据");
    }

    /**
     * 获取流程执行任务详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:process:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bpmExecuteProcessService.selectBpmExecuteProcessById(id));
    }

    /**
     * 新增流程执行任务
     */
    // @PreAuthorize("@ss.hasPermi('system:process:add')")
    @Log(title = "流程执行任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BpmExecuteProcess bpmExecuteProcess) {
        return toAjax(bpmExecuteProcessService.insertBpmExecuteProcess(bpmExecuteProcess));
    }

    /**
     * 修改流程执行任务
     */
    // @PreAuthorize("@ss.hasPermi('system:process:edit')")
    @Log(title = "流程执行任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BpmExecuteProcess bpmExecuteProcess) {
        return toAjax(bpmExecuteProcessService.updateBpmExecuteProcess(bpmExecuteProcess));
    }

    /**
     * 删除流程执行任务
     */
    // @PreAuthorize("@ss.hasPermi('system:process:remove')")
    @Log(title = "流程执行任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bpmExecuteProcessService.deleteBpmExecuteProcessByIds(ids));
    }

    /**
     * 共通投产流程接口
     */
    @Log(title = "投产执行流程", businessType = BusinessType.INSERT)
    @PostMapping("/productionScheduling")
    public AjaxResult productionScheduling(@RequestBody CommonEntity commonEntity)   {
        return bpmExecuteProcessService.productionScheduling(commonEntity);
    }

    /**
     * 查询节点表单信息
     */
    @GetMapping("/getNodeFormInfos")
    public AjaxResult getNodeFormInfos(Map<String,String> nodeForm) {
        return AjaxResult.success(PreExecutionToolClass.getNodeFormInfos(nodeForm));
    }

}
