Browse Source

优化流程记录接口

master
dimengzhe 2 months ago
parent
commit
75ff358d6d
  1. 13
      anrui-flowable/anrui-flowable-biz/src/main/java/com/yxt/anrui/flowable/biz/flowtask/FlowTaskService.java
  2. 5
      anrui-portal/anrui-portal-biz/src/main/java/com/yxt/anrui/portal/biz/flow/FlowableRest.java

13
anrui-flowable/anrui-flowable-biz/src/main/java/com/yxt/anrui/flowable/biz/flowtask/FlowTaskService.java

@ -330,10 +330,12 @@ public class FlowTaskService extends MybatisBaseService<FlowTaskMapper, FlowTask
// 将 Set<String> 转换为以逗号分隔的字符串
String assigneeIdsStr = String.join(",", assigneeIds);
Map<String, SysUserVo> userMap = new HashMap<>();
if(StringUtils.isNotBlank(assigneeIdsStr)){
// 远程调用批量查询用户信息
Map<String, SysUserVo> userMap = sysUserFeign.fetchBySids(assigneeIdsStr).getData().stream()
userMap = sysUserFeign.fetchBySids(assigneeIdsStr).getData().stream()
.collect(Collectors.toMap(SysUserVo::getSid, user -> user));
}
// 直接查询所有流程实例评论
List<Comment> commentList = taskService.getProcessInstanceComments(procInsId);
@ -345,6 +347,7 @@ public class FlowTaskService extends MybatisBaseService<FlowTaskMapper, FlowTask
List<FlowTask> finalHisFlowList = Collections.synchronizedList(hisFlowList);
// 使用 parallelStream 前先进行 null 检查和过滤
Map<String, SysUserVo> finalUserMap = userMap;
hisFlowList = list.parallelStream()
.filter(histIns -> histIns != null && histIns.getTaskId() != null) // 过滤掉 histIns 或 histIns.getTaskId() 为 null 的元素
.map(histIns -> {
@ -366,8 +369,8 @@ public class FlowTaskService extends MybatisBaseService<FlowTaskMapper, FlowTask
flowTask.setProcessEndTime(processInstance.get("END_TIME_") == null ? "" : "end");
// 处理审批人员
if (StringUtils.isNotBlank(histIns.getAssignee()) && userMap.containsKey(histIns.getAssignee())) {
SysUserVo user = userMap.get(histIns.getAssignee());
if (StringUtils.isNotBlank(histIns.getAssignee()) && finalUserMap.containsKey(histIns.getAssignee())) {
SysUserVo user = finalUserMap.get(histIns.getAssignee());
if (user != null) {
TaskUserInfo taskUserInfo = new TaskUserInfo();
taskUserInfo.setAssigneeName(user.getName());
@ -386,7 +389,7 @@ public class FlowTaskService extends MybatisBaseService<FlowTaskMapper, FlowTask
if ("4".equals(type)) { // 加签审批意见
FlowTask flowTask1 = new FlowTask();
String userSid = comment.getUserId();
SysUserVo user = userMap.get(userSid);
SysUserVo user = finalUserMap.get(userSid);
TaskUserInfo taskUserInfo = new TaskUserInfo();
taskUserInfo.setAssigneeName(user != null ? user.getName() : "");

5
anrui-portal/anrui-portal-biz/src/main/java/com/yxt/anrui/portal/biz/flow/FlowableRest.java

@ -48,6 +48,7 @@ import com.yxt.common.core.query.PagerQuery;
import com.yxt.common.core.result.ResultBean;
import com.yxt.common.core.vo.PagerVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.comparators.NullComparator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -75,6 +76,7 @@ import java.util.stream.Collectors;
@RestController
@RequestMapping("v1/flow")
@Api(tags = "业务系统中业务和工作流相关操作")
@Slf4j
public class FlowableRest implements FlowableFeign {
@Autowired
@ -166,6 +168,7 @@ public class FlowableRest implements FlowableFeign {
@Override
public ResultBean<List<PCHistTaskListAndCommentList>> flowRecordAndComment(String procInsId, String deployId) {
long startTimes = System.currentTimeMillis(); // 记录开始时间
// 并行调用外部服务
CompletableFuture<ResultBean<com.yxt.anrui.flowable.api.flowtask.FlowRecordVo>> flowRecordFuture =
CompletableFuture.supplyAsync(() -> flowableService.flowRecord(procInsId, deployId));
@ -266,6 +269,8 @@ public class FlowableRest implements FlowableFeign {
// 返回结果
ResultBean<List<PCHistTaskListAndCommentList>> resultBean = new ResultBean<List<PCHistTaskListAndCommentList>>().success();
resultBean.setData(flowList);
long endTime = System.currentTimeMillis();
log.info("流程记录接口耗时 {} ms", endTime - startTimes);
return resultBean;
}

Loading…
Cancel
Save