| | |
| | | package org.springblade.mdm.flow.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.task.api.Task; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springblade.mdm.flow.entity.ApproveRecord; |
| | | import org.springblade.mdm.flow.excution.StartDispatcher; |
| | | import org.springblade.mdm.flow.service.ApproveRecordService; |
| | | import org.springblade.mdm.flow.service.FlowCommonService; |
| | | import org.springblade.mdm.flow.vo.TaskAssignVO; |
| | | import org.springblade.mdm.program.entity.ProcessProgRef; |
| | | import org.springblade.mdm.program.service.ProcessProgRefService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | @AllArgsConstructor |
| | | @RequestMapping("/flow/dispatch") |
| | | @Tag(name = "派工流程", description = "派工流程") |
| | | public class DispatchController { |
| | | |
| | | @Autowired |
| | | private StartDispatcher dispatcher; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | private final StartDispatcher dispatcher; |
| | | |
| | | private final TaskService taskService; |
| | | |
| | | private final ProcessProgRefService processProgRefService; |
| | | |
| | | private ApproveRecordService approveRecordService; |
| | | private final FlowCommonService flowCommonService; |
| | | /** |
| | | * 新增 |
| | | */ |
| | | @PostMapping("/start") |
| | | @Operation(summary = "任务计划(派工流程)", description = "启动派工流程") |
| | | public R<Boolean> save(@RequestBody TaskAssignVO startVO) { |
| | | public R<Boolean> start(@RequestBody TaskAssignVO startVO) { |
| | | dispatcher.start(startVO); |
| | | return R.status(true); |
| | | } |
| | | |
| | | @Operation(summary = "完成任务", description = "流向下一个节点") |
| | | @PostMapping("completeTask") |
| | | public R<Void> completeTask(String taskId, String processInstanceId, String comment, @Parameter(name = "variables", description = "任务变量") @RequestBody Map<String, Object> variables) { |
| | | public R<Void> completeTask(String taskId, String processInstanceId, String comment,@Parameter(name = "variables", description = "任务变量") @RequestBody Map<String, Object> variables) { |
| | | // 增加评论 |
| | | if (StringUtil.isNoneBlank(processInstanceId, comment)) { |
| | | taskService.addComment(taskId, processInstanceId, comment); |
| | |
| | | if (Func.isEmpty(variables)) { |
| | | variables = Kv.create(); |
| | | } |
| | | String programIds = null; |
| | | if(variables.containsKey("programIds")){ |
| | | programIds = variables.get("programIds").toString(); |
| | | } |
| | | if(StringUtils.isNotEmpty(programIds)) { |
| | | processProgRefService.addRelations(processInstanceId,Func.toLongList(programIds)); |
| | | } |
| | | |
| | | //加入审批用户 |
| | | variables.put("approveUserNickName",AuthUtil.getNickName()); |
| | | |
| | | if(variables.containsKey("assignee")){ |
| | | |
| | | addApproveRecord(taskId,processInstanceId,comment,variables); |
| | | //指定了下一步执行人 |
| | | taskService.complete(taskId, variables); |
| | | |
| | | return R.success("流程提交成功"); |
| | | }else { |
| | | // 完成任务,给默认用户 |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | void addApproveRecord(String taskId, String processInstanceId, String comment,Map<String, Object> variables){ |
| | | String operateResult = variables.get("approve")+""; |
| | | |
| | | Task task = taskService.createTaskQuery() |
| | | .taskId(taskId) |
| | | .singleResult(); |
| | | approveRecordService.saveApproveRecords(task,processInstanceId,operateResult,comment); |
| | | |
| | | } |
| | | } |