潘志宝
2024-12-03 51c1c2c9fa28fb1765dd6e81c70b78566792aebe
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.bpm.controller.admin.task;
H 2
3 import cn.hutool.core.collection.CollUtil;
4 import com.iailab.framework.common.pojo.CommonResult;
5 import com.iailab.framework.common.pojo.PageResult;
6 import com.iailab.framework.common.util.collection.MapUtils;
7 import com.iailab.framework.common.util.date.DateUtils;
8 import com.iailab.framework.common.util.object.BeanUtils;
9 import com.iailab.module.bpm.controller.admin.task.vo.cc.BpmProcessInstanceCopyRespVO;
10 import com.iailab.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyPageReqVO;
11 import com.iailab.module.bpm.dal.dataobject.task.BpmProcessInstanceCopyDO;
12 import com.iailab.module.bpm.service.task.BpmProcessInstanceCopyService;
13 import com.iailab.module.bpm.service.task.BpmProcessInstanceService;
14 import com.iailab.module.bpm.service.task.BpmTaskService;
15 import com.iailab.module.system.api.user.AdminUserApi;
16 import com.iailab.module.system.api.user.dto.AdminUserRespDTO;
17 import io.swagger.v3.oas.annotations.Operation;
18 import io.swagger.v3.oas.annotations.tags.Tag;
19 import org.flowable.engine.history.HistoricProcessInstance;
20 import org.springframework.security.access.prepost.PreAuthorize;
21 import org.springframework.validation.annotation.Validated;
22 import org.springframework.web.bind.annotation.GetMapping;
23 import org.springframework.web.bind.annotation.RequestMapping;
24 import org.springframework.web.bind.annotation.RestController;
25
26 import javax.annotation.Resource;
27 import javax.validation.Valid;
28 import java.util.Map;
29 import java.util.stream.Stream;
30
31 import static com.iailab.framework.common.pojo.CommonResult.success;
32 import static com.iailab.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
33 import static com.iailab.framework.common.util.collection.CollectionUtils.convertSet;
34 import static com.iailab.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
35
36 @Tag(name = "管理后台 - 流程实例抄送")
37 @RestController
38 @RequestMapping("/bpm/process-instance/copy")
39 @Validated
40 public class BpmProcessInstanceCopyController {
41
42     @Resource
43     private BpmProcessInstanceCopyService processInstanceCopyService;
44     @Resource
45     private BpmProcessInstanceService processInstanceService;
46     @Resource
47     private BpmTaskService taskService;
48
49     @Resource
50     private AdminUserApi adminUserApi;
51
52     @GetMapping("/page")
53     @Operation(summary = "获得抄送流程分页列表")
54     @PreAuthorize("@ss.hasPermission('bpm:process-instance-cc:query')")
55     public CommonResult<PageResult<BpmProcessInstanceCopyRespVO>> getProcessInstanceCopyPage(
56             @Valid BpmProcessInstanceCopyPageReqVO pageReqVO) {
57         PageResult<BpmProcessInstanceCopyDO> pageResult = processInstanceCopyService.getProcessInstanceCopyPage(
58                 getLoginUserId(), pageReqVO);
59         if (CollUtil.isEmpty(pageResult.getList())) {
60             return success(new PageResult<>(pageResult.getTotal()));
61         }
62
63         // 拼接返回
64         Map<String, String> taskNameMap = taskService.getTaskNameByTaskIds(
65                 convertSet(pageResult.getList(), BpmProcessInstanceCopyDO::getTaskId));
66         Map<String, HistoricProcessInstance> processInstanceMap = processInstanceService.getHistoricProcessInstanceMap(
67                 convertSet(pageResult.getList(), BpmProcessInstanceCopyDO::getProcessInstanceId));
68         Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(pageResult.getList(),
69                 copy -> Stream.of(copy.getStartUserId(), Long.parseLong(copy.getCreator()))));
70         return success(BeanUtils.toBean(pageResult, BpmProcessInstanceCopyRespVO.class, copyVO -> {
71             MapUtils.findAndThen(userMap, Long.valueOf(copyVO.getCreator()), user -> copyVO.setCreatorName(user.getNickname()));
72             MapUtils.findAndThen(userMap, copyVO.getStartUserId(), user -> copyVO.setStartUserName(user.getNickname()));
73             MapUtils.findAndThen(taskNameMap, copyVO.getTaskId(), copyVO::setTaskName);
74             MapUtils.findAndThen(processInstanceMap, copyVO.getProcessInstanceId(),
75                     processInstance -> copyVO.setProcessInstanceStartTime(DateUtils.of(processInstance.getStartTime())));
76         }));
77     }
78
79 }