| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.common.engine.api.FlowableException; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.identitylink.api.IdentityLink; |
| | | import org.flowable.task.api.Task; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | |
| | | import org.jeecg.modules.dnc.utils.ValidateUtil; |
| | | import org.jeecg.modules.dncFlow.constant.GuideCardBatchEnum; |
| | | import org.jeecg.modules.dncFlow.entity.DispatchFile; |
| | | import org.jeecg.modules.dncFlow.vo.AssignEquipmentFileStreamVo; |
| | | import org.jeecg.modules.dncFlow.vo.GuideCardBatchFlowTaskVo; |
| | | import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness; |
| | | import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService; |
| | |
| | | import org.jeecg.modules.flowable.service.IFlowDefinitionService; |
| | | import org.jeecg.modules.flowable.service.IFlowTaskService; |
| | | import org.jeecg.modules.system.service.ISysDictService; |
| | | import org.jeecg.modules.system.service.ISysUserRoleService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private IFlowMyBusinessService flowMyBusinessService; |
| | | |
| | | @Autowired |
| | | private ISysUserRoleService sysUserRoleService; |
| | | /** |
| | | * 生成流水号 |
| | | * @param code |
| | |
| | | if (guideCardBatch==null) { |
| | | return Result.ok("未找到对应的程序加工确认表"); |
| | | } |
| | | Result result=reStartDispatchFile(id); |
| | | if (result==null) { |
| | | //填充数据 |
| | | guideCardBatch.setCompiler(user.getUsername()); |
| | | guideCardBatch.setCompilerTime(new Date()); |
| | |
| | | variables.put("organization", "用户"+user.getRealname()+"发起流程"); |
| | | variables.put("comment", "用户"+user.getRealname()+"发起流程"); |
| | | variables.put("proofreading",true); |
| | | Result result= flowDefinitionService.startProcessInstanceByKey("nc_guide_card_batch", variables); |
| | | if (!result.isSuccess()) { |
| | | Result flowResult= flowDefinitionService.startProcessInstanceByKey("nc_guide_card_batch", variables); |
| | | if (!flowResult.isSuccess()) { |
| | | guideCardBatch.setCompiler(null); |
| | | guideCardBatch.setCompilerTime(null); |
| | | this.updateById(guideCardBatch); |
| | | } |
| | | return flowResult; |
| | | }else { |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 重新启动 |
| | | * @param id |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public Result<?> reStartDispatchFile(String id) { |
| | | GuideCardBatch guideCardBatch=this.getById(id); |
| | | if (guideCardBatch!=null){ |
| | | if (!guideCardBatch.getFlowStatus().equals(GuideCardBatchEnum.VERIFY.getCode())){ |
| | | //重新启动流程 |
| | | try { |
| | | // 1. 获取当前用户并校验登录状态 |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (user == null) { |
| | | return Result.error("用户未登录"); |
| | | } |
| | | |
| | | // 2. 查询流程业务记录(处理空结果) |
| | | List<FlowMyBusiness> businessList = flowMyBusinessService.list( |
| | | new QueryWrapper<FlowMyBusiness>() |
| | | .eq("data_id", guideCardBatch.getId()) |
| | | ); |
| | | if (businessList.isEmpty()) { |
| | | return Result.error("流程记录不存在"); |
| | | } |
| | | FlowMyBusiness flowMyBusiness = businessList.get(0); |
| | | |
| | | // 3. 校验用户是否为候选处理人 |
| | | List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class); |
| | | if (todoUsers == null || !todoUsers.contains(user.getUsername())) { |
| | | return Result.error("用户无权操作此任务"); |
| | | } |
| | | |
| | | // 4. 认领任务(处理已被认领的情况) |
| | | String taskId = flowMyBusiness.getTaskId(); |
| | | Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); |
| | | if (task == null) { |
| | | return Result.error("任务不存在或已完成"); |
| | | } |
| | | if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) { |
| | | return Result.error("任务已被他人认领"); |
| | | } |
| | | taskService.claim(taskId, user.getUsername()); |
| | | |
| | | // 5. 完成任务并传递变量 |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("dataId", flowMyBusiness.getDataId()); |
| | | variables.put("organization","重新发起流程"); |
| | | variables.put("assignee", user.getUsername()); |
| | | variables.put("comment", "重新发起流程"); |
| | | taskService.complete(taskId, variables); |
| | | |
| | | // 6. 获取下一任务并更新业务记录 |
| | | List<Task> nextTasks = taskService.createTaskQuery() |
| | | .processInstanceId(flowMyBusiness.getProcessInstanceId()) |
| | | .list(); |
| | | if (!nextTasks.isEmpty()) { |
| | | Task nextTask = nextTasks.get(0); // 假设取第一个任务 |
| | | flowMyBusiness.setTaskId(nextTask.getId()); |
| | | flowMyBusiness.setTaskName(nextTask.getName()); |
| | | |
| | | // 动态获取下一节点候选人(示例) |
| | | List<String> nextTodoUsers = getNextTaskCandidates(nextTask.getId()); |
| | | flowMyBusiness.setTodoUsers(JSON.toJSONString(nextTodoUsers)); |
| | | } else { |
| | | // 流程已结束,清空任务信息 |
| | | flowMyBusiness.setTaskId(null); |
| | | flowMyBusiness.setTaskName(null); |
| | | flowMyBusiness.setTodoUsers(null); |
| | | } |
| | | flowMyBusinessService.updateById(flowMyBusiness); |
| | | guideCardBatch.setFlowStatus(GuideCardBatchEnum.VERIFY.getCode()); |
| | | this.updateById(guideCardBatch); |
| | | return Result.ok("流程重启成功"); |
| | | } catch (FlowableException e) { |
| | | return Result.error("流程操作失败: " + e.getMessage()); |
| | | } catch (Exception e) { |
| | | return Result.error("系统错误: " + e.getMessage()); |
| | | } |
| | | }else { |
| | | return null; |
| | | } |
| | | } |
| | | return Result.error("数据不存在"); |
| | | } |
| | | |
| | | // 辅助方法:获取下一任务的所有候选信息(处理人、候选用户、候选组) |
| | | private List<String> getNextTaskCandidates(String taskId) { |
| | | List<IdentityLink> links = taskService.getIdentityLinksForTask(taskId); |
| | | List<String> candidates = new ArrayList<>(); |
| | | |
| | | // 1. 获取直接处理人(assignee) |
| | | links.stream() |
| | | .filter(link -> "assignee".equals(link.getType())) |
| | | .map(IdentityLink::getUserId) |
| | | .filter(Objects::nonNull) |
| | | .forEach(candidates::add); |
| | | |
| | | // 2. 获取候选用户和候选组 |
| | | links.stream() |
| | | .filter(link -> "candidate".equals(link.getType())) |
| | | .forEach(link -> { |
| | | if (link.getUserId() != null) { |
| | | // 候选用户直接添加 |
| | | candidates.add(link.getUserId()); |
| | | } else if (link.getGroupId() != null) { |
| | | // 候选组转换为实际用户(示例逻辑,需根据业务实现) |
| | | List<String> groupUsers = convertGroupToUsers(link.getGroupId()); |
| | | candidates.addAll(groupUsers); |
| | | } |
| | | }); |
| | | |
| | | return candidates; |
| | | } |
| | | |
| | | // 示例方法:将候选组ID转换为用户列表(需自定义实现) |
| | | private List<String> convertGroupToUsers(String groupId) { |
| | | // 实际业务中调用服务接口获取组成员 |
| | | return sysUserRoleService.getUserNameByRoleId(groupId); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 流程节点审核 |