From e969dbe8b74a770828c4c9b6ec69ac6ceb05d120 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 10 Nov 2021 09:11:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=E7=9A=84=20code=20r?= =?UTF-8?q?eview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/workflow/TaskController.java | 4 +-- .../bpm/controller/workflow/vo/FileResp.java | 4 +++ .../bpm/enums/oa/OAErrorCodeConstants.java | 4 +++ .../workflow/impl/TaskServiceImpl.java | 28 +++++++++---------- .../config/YudaoActivitiConfiguration.java | 7 ++--- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/TaskController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/TaskController.java index 32ff94c75..a379332ea 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/TaskController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/TaskController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow; +import cn.hutool.core.io.IoUtil; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.*; import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.TaskService; import cn.iocoder.yudao.framework.common.pojo.CommonResult; @@ -60,6 +61,7 @@ public class TaskController { return success(taskService.getHistorySteps(processInstanceId)); } + // TODO @Li: 项目里,暂时不使用 path 路径参数,监控等麻烦 /** * 返回高亮的流转图SVG * @param processInstanceId @@ -70,6 +72,4 @@ public class TaskController { ServletUtils.writeAttachment(response, fileResp.getFileName(), fileResp.getFileByte()); } - - } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/vo/FileResp.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/vo/FileResp.java index 7bb1a96e5..f3fdedb1a 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/vo/FileResp.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/vo/FileResp.java @@ -2,12 +2,15 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo; import lombok.Data; +// TODO @Li:1)改成 HighlightImgRespVO 吧。2)swagger 注解要补充;3)fileByte => fileContent /** * 文件输出类 + * * @author yunlongn */ @Data public class FileResp { + /** * 文件名字 */ @@ -17,4 +20,5 @@ public class FileResp { * 文件输出流 */ private byte[] fileByte; + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/oa/OAErrorCodeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/oa/OAErrorCodeConstants.java index b857cb761..6790edd5f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/oa/OAErrorCodeConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/oa/OAErrorCodeConstants.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.adminserver.modules.bpm.enums.oa; import cn.iocoder.yudao.framework.common.exception.ErrorCode; + +// TODO @jason:错误码整理下,和其它模块保持一致。包括前缀 /** * activiti 系统 错误码枚举类 * @@ -9,6 +11,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; * activiti 系统,使用 1-003-000-000 段 */ public interface OAErrorCodeConstants { + ErrorCode LEAVE_NOT_EXISTS = new ErrorCode(1003001001, "请假申请不存在"); ErrorCode PM_POST_NOT_EXISTS = new ErrorCode(1003001002, "项目经理岗位未设置"); ErrorCode DEPART_PM_POST_NOT_EXISTS = new ErrorCode(1003001003, "部门的项目经理不存在"); @@ -19,4 +22,5 @@ public interface OAErrorCodeConstants { ErrorCode PROCESS_INSTANCE_NOT_EXISTS = new ErrorCode(1003001008, "流程实例不存在"); ErrorCode HIGHLIGHT_IMG_ERROR = new ErrorCode(1003001009, "获取高亮流程图异常"); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/TaskServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/TaskServiceImpl.java index fc75772b8..ac10c45c4 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/TaskServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/TaskServiceImpl.java @@ -5,7 +5,6 @@ import cn.hutool.core.io.IoUtil; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.*; import cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow.TaskConvert; import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.TaskService; -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; @@ -33,17 +32,18 @@ import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.net.URLEncoder; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; -import static cn.iocoder.yudao.adminserver.modules.bpm.enums.oa.OAErrorCodeConstants.*; +import static cn.iocoder.yudao.adminserver.modules.bpm.enums.oa.OAErrorCodeConstants.HIGHLIGHT_IMG_ERROR; +import static cn.iocoder.yudao.adminserver.modules.bpm.enums.oa.OAErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @Slf4j @Service @@ -166,7 +166,7 @@ public class TaskServiceImpl implements TaskService { @Override public TodoTaskRespVO getTaskFormKey(TaskQueryReqVO taskQuery) { final Task task = taskRuntime.task(taskQuery.getTaskId()); - // 转换结果 + // 转换结果 TODO @jason:放到 convert 类里 TodoTaskRespVO respVO = new TodoTaskRespVO(); respVO.setFormKey(task.getFormKey()); respVO.setBusinessKey(task.getBusinessKey()); @@ -175,7 +175,6 @@ public class TaskServiceImpl implements TaskService { return respVO; } - @Override public FileResp getHighlightImg(String processInstanceId) { // 查询历史 @@ -184,7 +183,7 @@ public class TaskServiceImpl implements TaskService { HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); // 如果不存在实例。 说明数据异常 if (hpi == null) { - throw ServiceExceptionUtil.exception(PROCESS_INSTANCE_NOT_EXISTS); + throw exception(PROCESS_INSTANCE_NOT_EXISTS); } // 没有结束时间。说明流程在执行过程中 // TODO @Li:一些 runtimeService 的查询,貌似比较通用,是不是抽一些小方法出来 @@ -194,9 +193,7 @@ public class TaskServiceImpl implements TaskService { // 获取所有活动节点 List finishedInstances = historyService.createHistoricActivityInstanceQuery() .processInstanceId(processInstanceId).finished().list(); - // TODO @Li:highLightedActivities 结果,可以使用 CollUtils.buildList() 方法。即使不用,也应该用 stream。简洁很重要。 - finishedInstances.stream() - .map(HistoricActivityInstance::getActivityId) + finishedInstances.stream().map(HistoricActivityInstance::getActivityId) .forEach(highLightedActivities::add); // 已完成的节点+当前节点 highLightedActivities.addAll(runtimeService.getActiveActivityIds(processInstanceId)); @@ -209,13 +206,14 @@ public class TaskServiceImpl implements TaskService { try (InputStream inputStream = processDiagramGenerator.generateDiagram(bpmnModel, highLightedActivities, highLightedFlowIds, "宋体", "宋体", "宋体")){ FileResp fileResp = new FileResp(); - String picName = hpi.getProcessDefinitionName() + ".svg"; + String picName = hpi.getProcessDefinitionName() + ".svg"; // TODO @Li:一次性的变量,可以直接 set 的时候,直接拼接 fileResp.setFileName(picName); fileResp.setFileByte(IoUtil.readBytes(inputStream)); return fileResp; } catch (IOException e) { + // TODO @Li:log.error("[getHighlightImg][流程({}) 生成图表失败]", processInstanceId, e) log.error(ExceptionUtils.getStackTrace(e)); - throw ServiceExceptionUtil.exception(HIGHLIGHT_IMG_ERROR); + throw exception(HIGHLIGHT_IMG_ERROR); } } diff --git a/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/config/YudaoActivitiConfiguration.java b/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/config/YudaoActivitiConfiguration.java index 30577ed6a..4af1e2f45 100644 --- a/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/config/YudaoActivitiConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/config/YudaoActivitiConfiguration.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.framework.activiti.config; import lombok.AllArgsConstructor; -import org.activiti.api.runtime.shared.identity.UserGroupManager; import org.activiti.image.ProcessDiagramGenerator; import org.activiti.image.impl.DefaultProcessDiagramGenerator; import org.activiti.spring.SpringProcessEngineConfiguration; @@ -14,13 +13,11 @@ import org.springframework.stereotype.Component; @Configuration public class YudaoActivitiConfiguration { - /** - * 流程中生成基于图表交换信息的 svg 的类。 提供绘制方法 - * @return ProcessDiagramGenerator + * Activiti 流程图的生成器。目前管理后台的流程图 svg,通过它绘制生成。 */ @Bean - public ProcessDiagramGenerator processDiagramGenerator (){ + public ProcessDiagramGenerator processDiagramGenerator() { return new DefaultProcessDiagramGenerator(); }