package org.jeecg.modules.flowable.controller;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.flowable.service.IFlowInstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>工作流流程实例管理<p>
 */
@Slf4j
@RestController
@RequestMapping("/flowable/instance")
public class FlowInstanceController {

    @Autowired
    private IFlowInstanceService flowInstanceService;

    /*@ApiOperation(value = "根据流程定义id启动流程实例")
    @PostMapping("/startBy/{procDefId}")
    public Result startById(@ApiParam(value = "流程定义id") @PathVariable(value = "procDefId") String procDefId,
                                @ApiParam(value = "变量集合,json对象") @RequestBody Map<String, Object> variables) {
        return flowInstanceService.startProcessInstanceById(procDefId, variables);

    }*/

    @PostMapping(value = "/updateState")
    public Result updateState(@RequestParam Integer state,
                              @RequestParam String instanceId) {
        flowInstanceService.updateState(state,instanceId);
        return Result.OK();
    }

    /*@ApiOperation("结束流程实例")
    @PostMapping(value = "/stopProcessInstance")
    public Result stopProcessInstance(@RequestBody FlowTaskVo flowTaskVo) {
        flowInstanceService.stopProcessInstance(flowTaskVo);
        return Result.OK();
    }*/
    @DeleteMapping(value = "/delete")
    public Result delete(@RequestParam String instanceId,
                         @RequestParam(required = false) String deleteReason) {
        flowInstanceService.delete(instanceId,deleteReason);
        return Result.OK();
    }

    @PostMapping(value = "/deleteByDataId")
    public Result deleteByDataId(
            @RequestParam String dataId,
            @RequestParam(required = false) String deleteReason) {
        flowInstanceService.deleteByDataId(dataId,deleteReason);
        return Result.OK();
    }

    @DeleteMapping(value = "/delete/{instanceIds}")
    public Result delete(@PathVariable String[] instanceIds,
                         @RequestParam(required = false) String deleteReason) {
        for (String instanceId : instanceIds) {
            flowInstanceService.delete(instanceId,deleteReason);
        }
        return Result.OK();
    }

}
