| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ycl.common.constant.ProcessConstants; |
| | | import com.ycl.common.core.domain.AjaxResult; |
| | | import com.ycl.common.core.domain.entity.SysDept; |
| | | import com.ycl.common.core.domain.entity.SysRole; |
| | | import com.ycl.common.core.domain.entity.SysUser; |
| | | import com.ycl.common.enums.FlowComment; |
| | |
| | | import com.ycl.service.ISysDeployFormService; |
| | | import com.ycl.service.ISysFormService; |
| | | import com.ycl.service.common.TaskCommonService; |
| | | import com.ycl.system.service.ISysDeptService; |
| | | import com.ycl.system.service.ISysRoleService; |
| | | import com.ycl.system.service.ISysUserService; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | |
| | | private final ISysUserService sysUserService; |
| | | private final ISysRoleService sysRoleService; |
| | | private final ISysDeptService sysDeptService; |
| | | private final ISysDeployFormService sysInstanceFormService; |
| | | private final ISysFormService sysFormService; |
| | | private final TaskCommonService taskCommonService; |
| | |
| | | stringBuilder.append(sysUser.getNickName()).append(","); |
| | | } |
| | | if (StringUtils.isNotBlank(identityLink.getGroupId())) { |
| | | SysRole sysRole = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId())); |
| | | stringBuilder.append(sysRole.getRoleName()).append(","); |
| | | if (identityLink.getGroupId().contains("dept")) { |
| | | SysDept sysDept = sysDeptService.selectDeptById(Long.parseLong(identityLink.getGroupId().split(":")[1])); |
| | | stringBuilder.append(sysDept.getDeptName()).append(","); |
| | | } else { |
| | | SysRole sysRole = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId())); |
| | | stringBuilder.append(sysRole.getRoleName()).append(","); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | map.put("flowList", hisFlowList); |
| | | } |
| | | // 第一次申请获取初始化表单 |
| | | if (StringUtils.isNotBlank(deployId)) { |
| | | SysForm sysForm = sysInstanceFormService.selectSysDeployFormByDeployId(deployId); |
| | | if (Objects.isNull(sysForm)) { |
| | | return AjaxResult.error("请先配置流程表单"); |
| | | } |
| | | map.put("formData", JSONObject.parseObject(sysForm.getFormContent())); |
| | | } |
| | | // // 第一次申请获取初始化表单 |
| | | // if (StringUtils.isNotBlank(deployId)) { |
| | | // SysForm sysForm = sysInstanceFormService.selectSysDeployFormByDeployId(deployId); |
| | | // if (Objects.isNull(sysForm)) { |
| | | // return AjaxResult.error("请先配置流程表单"); |
| | | // } |
| | | // map.put("formData", JSONObject.parseObject(sysForm.getFormContent())); |
| | | // } |
| | | return AjaxResult.success(map); |
| | | } |
| | | |
| | |
| | | } else { |
| | | parameters = taskService.getVariables(taskId); |
| | | } |
| | | List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, task.getFormKey(), task.getName(), task.getProcessDefinitionId(), task.getTaskDefinitionKey(), Boolean.FALSE); |
| | | return AjaxResult.success(beforeNodes); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult detail(String taskId) { |
| | | Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); |
| | | // 流程变量 |
| | | Map<String, Object> parameters = new HashMap<>(); |
| | | if (Objects.isNull(task)) { |
| | | // 如果为空,可能是任务已经结束 |
| | | HistoricTaskInstance hisTask = historyService.createHistoricTaskInstanceQuery().taskId(taskId).includeProcessVariables().singleResult(); |
| | | if (Objects.isNull(hisTask)) { |
| | | throw new RuntimeException("该任务不存在"); |
| | | } |
| | | parameters = hisTask.getProcessVariables(); |
| | | List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, hisTask.getFormKey(), hisTask.getName(), hisTask.getProcessDefinitionId(), hisTask.getTaskDefinitionKey(), Boolean.TRUE); |
| | | return AjaxResult.success(beforeNodes); |
| | | } else { |
| | | parameters = taskService.getVariables(taskId); |
| | | List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, task.getFormKey(), task.getName(), task.getProcessDefinitionId(), task.getTaskDefinitionKey(), Boolean.TRUE); |
| | | return AjaxResult.success(beforeNodes); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取当前节点和上一节点的表单内容 |
| | | * |
| | | * @param parameters 根据任务查找出来的参数 |
| | | * @param formKey task自身关联的表单id |
| | | * @param taskName task自身的任务名 |
| | | * @param processDefId 流程定义id |
| | | * @param processDefKey 流程实例id |
| | | * @return |
| | | */ |
| | | private List<FormDetailVO> getBeforeNodeForm(Map<String, Object> parameters, String formKey, String taskName, String processDefId, String processDefKey, Boolean currentNeedData) { |
| | | if (! parameters.keySet().stream().anyMatch(key -> key.contains(ProcessConstants.TASK_FORM_KEY))) { |
| | | // 如果是空的,使用formId去查 |
| | | if (StringUtils.isNotBlank(task.getFormKey())) { |
| | | SysForm sysForm = sysFormService.selectSysFormById(Long.parseLong(task.getFormKey())); |
| | | if (StringUtils.isNotBlank(formKey)) { |
| | | SysForm sysForm = sysFormService.selectSysFormById(Long.parseLong(formKey)); |
| | | if (Objects.isNull(sysForm)) { |
| | | throw new RuntimeException("该流程绑定的表单不存在或已被删除"); |
| | | } |
| | |
| | | Map<String, Object> data = new HashMap<>(1); |
| | | data.put(ProcessConstants.TASK_FORM_KEY, JSONObject.parseObject(sysForm.getFormContent())); |
| | | formDetailVO.setFormJsonObj(data); |
| | | formDetailVO.setBeforeNodeName(task.getName()); |
| | | formDetailVO.setBeforeNodeName(taskName); |
| | | formDetailVO.setCurrent(Boolean.TRUE); |
| | | return AjaxResult.success(Arrays.asList(formDetailVO)); |
| | | return Arrays.asList(formDetailVO); |
| | | } else { |
| | | return AjaxResult.success(new ArrayList<>(1)); |
| | | return new ArrayList<>(1); |
| | | } |
| | | } |
| | | // 这里只需要查自身以及上一个节点(如果并行的有多个)的表单数据 |
| | | List<FormDetailVO> beforeNodes = taskCommonService.getBeforeNodeDefId(task.getProcessDefinitionId(), task.getTaskDefinitionKey(), sysFormService); |
| | | List<String> beforeNodeDefIds = beforeNodes.stream().filter(item -> !item.getCurrent()).map(FormDetailVO::getBeforeNodeDefId).collect(Collectors.toList()); |
| | | List<FormDetailVO> beforeNodes = taskCommonService.getBeforeNodeDefInfo(processDefId, processDefKey, sysFormService, Boolean.TRUE); |
| | | List<String> beforeNodeDefIds = beforeNodes.stream().filter(item -> !item.getCurrent() || currentNeedData).map(FormDetailVO::getBeforeNodeDefId).collect(Collectors.toList()); |
| | | Map<String, Object> newP = new HashMap<>(); |
| | | if (CollectionUtils.isNotEmpty(beforeNodeDefIds)) { |
| | | for (String key : parameters.keySet()) { |
| | | // 过滤目标数据,将目标表单数据放到新map中 |
| | | // 过滤拿到目标数据,将目标表单数据放到新map中 |
| | | if (beforeNodeDefIds.stream().anyMatch(defId -> key.startsWith(defId))) { |
| | | if (key.contains(ProcessConstants.TASK_FORM_KEY)) { |
| | | newP.put(key, parameters.get(key)); |
| | | } else { |
| | | } |
| | | else { |
| | | newP.put(key.split("&")[1], parameters.get(key)); |
| | | } |
| | | } |
| | |
| | | |
| | | // 拿到目标表单后,再处理每个表单的数据 |
| | | for (FormDetailVO formDetailVO : beforeNodes) { |
| | | if (formDetailVO.getCurrent()) { |
| | | continue; // 跳过当前节点,因为当前节点在获取前置节点时已经设置过了 |
| | | if (formDetailVO.getCurrent() && !currentNeedData) { |
| | | continue; // 跳过当前节点,因为当前节点在获取前置节点时已经设置过了(但表单数据没有给) |
| | | } |
| | | Object form = newP.get(formDetailVO.getBeforeNodeDefId() + "&" + ProcessConstants.TASK_FORM_KEY); |
| | | if (Objects.nonNull(form)) { |
| | |
| | | formDetailVO.setFormJsonObj(newP); |
| | | } |
| | | } |
| | | |
| | | return AjaxResult.success(beforeNodes); |
| | | return beforeNodes; |
| | | } |
| | | |
| | | /** |