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

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

import com.ruoyi.system.entity.runbpm.IntoProduction;
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.execution.produce.dispersed.enetity.BpmExecuteProcess;
import com.ruoyi.execution.produce.dispersed.service.IBpmExecuteProcessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

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

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

    /**
     * 导出流程执行任务列表
     */
    @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.DELETE)
    @PostMapping("/productionScheduling")
    public AjaxResult productionScheduling(IntoProduction intoProduction) {
        return bpmExecuteProcessService.productionScheduling(intoProduction);
    }


}
