Commit eddd0a8801d656f0ed0ae8a83ff9acdd48bf2c90

Authored by puhui999
2 parents 5892c889 4066ad3e

Merge remote-tracking branch 'yudao/develop' into develop

# Conflicts:
#	yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java
Showing 13 changed files with 37 additions and 126 deletions
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/api/listener/BpmResultListenerApi.java deleted
1   -package cn.iocoder.yudao.module.bpm.api.listener;
2   -
3   -import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
4   -
5   -// TODO @芋艿:后续改成支持 RPC
6   -/**
7   - * 业务流程实例的结果发生变化的监听器 Api
8   - *
9   - * @author HUIHUI
10   - */
11   -public interface BpmResultListenerApi {
12   -
13   - /**
14   - * 监听的流程定义 Key
15   - *
16   - * @return 返回监听的流程定义 Key
17   - */
18   - String getProcessDefinitionKey();
19   -
20   - /**
21   - * 处理事件
22   - *
23   - * @param event 事件
24   - */
25   - void onEvent(BpmResultListenerRespDTO event);
26   -
27   -}
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/api/listener/dto/BpmResultListenerRespDTO.java deleted
1   -package cn.iocoder.yudao.module.bpm.api.listener.dto;
2   -
3   -import lombok.Data;
4   -
5   -// TODO @芋艿:后续改成支持 RPC
6   -/**
7   - * 业务流程实例的结果 Response DTO
8   - *
9   - * @author HUIHUI
10   - */
11   -@Data
12   -public class BpmResultListenerRespDTO {
13   -
14   - /**
15   - * 流程实例的编号
16   - */
17   - private String id;
18   - /**
19   - * 流程实例的 key
20   - */
21   - private String processDefinitionKey;
22   - /**
23   - * 流程实例的结果
24   - */
25   - private Integer result;
26   - /**
27   - * 流程实例对应的业务标识
28   - * 例如说,请假
29   - */
30   - private String businessKey;
31   -
32   -}
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/bpm/core/event/BpmProcessInstanceResultEvent.java renamed to yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/event/BpmProcessInstanceResultEvent.java
1   -package cn.iocoder.yudao.module.bpm.framework.bpm.core.event;
  1 +package cn.iocoder.yudao.module.bpm.event;
2 2  
3   -import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmProcessInstanceExtDO;
  3 +import jakarta.validation.constraints.NotNull;
4 4 import lombok.Data;
5 5 import org.springframework.context.ApplicationEvent;
6 6  
7   -import jakarta.validation.constraints.NotNull;
8   -
9 7 /**
10 8 * 流程实例的结果发生变化的 Event
11 9 * 定位:由于额外增加了 {@link BpmProcessInstanceExtDO#getResult()} 结果,所以增加该事件
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/bpm/core/event/BpmProcessInstanceResultEventListener.java renamed to yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/event/BpmProcessInstanceResultEventListener.java
1   -package cn.iocoder.yudao.module.bpm.framework.bpm.core.event;
  1 +package cn.iocoder.yudao.module.bpm.event;
2 2  
3 3 import cn.hutool.core.util.StrUtil;
4 4 import org.springframework.context.ApplicationListener;
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmProcessInstanceConvert.java
... ... @@ -7,7 +7,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessI
7 7 import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceRespVO;
8 8 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionExtDO;
9 9 import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmProcessInstanceExtDO;
10   -import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEvent;
  10 +import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceResultEvent;
11 11 import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenProcessInstanceApproveReqDTO;
12 12 import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenProcessInstanceRejectReqDTO;
13 13 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/bpm/core/event/BpmProcessInstanceResultEventPublisher.java
1 1 package cn.iocoder.yudao.module.bpm.framework.bpm.core.event;
2 2  
  3 +import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceResultEvent;
3 4 import lombok.AllArgsConstructor;
4 5 import org.springframework.context.ApplicationEventPublisher;
5 6 import org.springframework.validation.annotation.Validated;
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/bpm/listener/BpmServiceResultListener.java deleted
1   -package cn.iocoder.yudao.module.bpm.framework.bpm.listener;
2   -
3   -import cn.hutool.core.util.StrUtil;
4   -import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5   -import cn.iocoder.yudao.module.bpm.api.listener.BpmResultListenerApi;
6   -import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
7   -import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEvent;
8   -import jakarta.annotation.Resource;
9   -import org.springframework.context.ApplicationListener;
10   -import org.springframework.stereotype.Component;
11   -
12   -import java.util.List;
13   -
14   -// TODO @芋艿:后续改成支持 RPC
15   -/**
16   - * 业务流程结果监听器实现类
17   - *
18   - * @author HUIHUI
19   - */
20   -@Component
21   -public class BpmServiceResultListener implements ApplicationListener<BpmProcessInstanceResultEvent> {
22   -
23   - @Resource
24   - private List<BpmResultListenerApi> bpmResultListenerApis;
25   -
26   - @Override
27   - public final void onApplicationEvent(BpmProcessInstanceResultEvent event) {
28   - bpmResultListenerApis.forEach(bpmResultListenerApi -> {
29   - if (!StrUtil.equals(event.getProcessDefinitionKey(), bpmResultListenerApi.getProcessDefinitionKey())) {
30   - return;
31   - }
32   - bpmResultListenerApi.onEvent(BeanUtils.toBean(event, BpmResultListenerRespDTO.class));
33   - });
34   - }
35   -
36   -}
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/oa/listener/BpmOALeaveResultListener.java
1 1 package cn.iocoder.yudao.module.bpm.service.oa.listener;
2 2  
3   -import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEvent;
4   -import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEventListener;
  3 +import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceResultEvent;
  4 +import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceResultEventListener;
5 5 import cn.iocoder.yudao.module.bpm.service.oa.BpmOALeaveService;
6 6 import cn.iocoder.yudao.module.bpm.service.oa.BpmOALeaveServiceImpl;
7 7 import org.springframework.stereotype.Component;
... ...
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
... ... @@ -11,8 +11,9 @@ public interface ErrorCodeConstants {
11 11  
12 12 // ========== 合同管理 1-020-000-000 ==========
13 13 ErrorCode CONTRACT_NOT_EXISTS = new ErrorCode(1_020_000_000, "合同不存在");
14   - ErrorCode CONTRACT_UPDATE_FAIL_EDITING_PROHIBITED = new ErrorCode(1_020_000_001, "更新合同失败,原因:禁止编辑");
  14 + ErrorCode CONTRACT_UPDATE_FAIL_NOT_DRAFT = new ErrorCode(1_020_000_001, "合同更新失败,原因:合同不是草稿状态");
15 15 ErrorCode CONTRACT_SUBMIT_FAIL_NOT_DRAFT = new ErrorCode(1_020_000_002, "合同提交审核失败,原因:合同没处在未提交状态");
  16 + ErrorCode CONTRACT_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_000_003, "更新合同审核状态失败,原因:合同不是处理中状态");
16 17  
17 18 // ========== 线索管理 1-020-001-000 ==========
18 19 ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在");
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/CrmContractRespVO.java
... ... @@ -58,7 +58,7 @@ public class CrmContractRespVO {
58 58  
59 59 @Schema(description = "工作流编号", example = "1043")
60 60 @ExcelProperty("工作流编号")
61   - private Long processInstanceId;
  61 + private String processInstanceId;
62 62  
63 63 @Schema(description = "审批状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
64 64 @ExcelProperty("审批状态")
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java
1 1 package cn.iocoder.yudao.module.crm.service.contract;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
5 4 import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
6 5 import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractSaveReqVO;
7 6 import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO;
... ... @@ -72,9 +71,10 @@ public interface CrmContractService {
72 71 /**
73 72 * 更新合同流程审批结果
74 73 *
75   - * @param event 审批结果
  74 + * @param id 合同编号
  75 + * @param bpmResult BPM 审批结果
76 76 */
77   - void updateContractAuditStatus(BpmResultListenerRespDTO event);
  77 + void updateContractAuditStatus(Long id, Integer bpmResult);
78 78  
79 79 /**
80 80 * 获得合同
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java
... ... @@ -8,9 +8,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
8 8 import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
9 9 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
10 10 import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
11   -import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
12 11 import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
13 12 import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
  13 +import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
14 14 import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
15 15 import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractSaveReqVO;
16 16 import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO;
... ... @@ -34,6 +34,7 @@ import com.mzt.logapi.context.LogRecordContext;
34 34 import com.mzt.logapi.service.impl.DiffParseFunction;
35 35 import com.mzt.logapi.starter.annotation.LogRecord;
36 36 import jakarta.annotation.Resource;
  37 +import lombok.extern.slf4j.Slf4j;
37 38 import org.springframework.stereotype.Service;
38 39 import org.springframework.transaction.annotation.Transactional;
39 40 import org.springframework.validation.annotation.Validated;
... ... @@ -47,8 +48,6 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
47 48 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
48 49 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
49 50 import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
50   -import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.convertAuditStatus;
51   -import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.isEndResult;
52 51  
53 52 /**
54 53 * CRM 合同 Service 实现类
... ... @@ -57,6 +56,7 @@ import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.isEndResult;
57 56 */
58 57 @Service
59 58 @Validated
  59 +@Slf4j
60 60 public class CrmContractServiceImpl implements CrmContractService {
61 61  
62 62 /**
... ... @@ -130,7 +130,7 @@ public class CrmContractServiceImpl implements CrmContractService {
130 130 // 1.2 只有草稿、审批中,可以编辑;
131 131 if (!ObjectUtils.equalsAny(contract.getAuditStatus(), CrmAuditStatusEnum.DRAFT.getStatus(),
132 132 CrmAuditStatusEnum.PROCESS.getStatus())) {
133   - throw exception(CONTRACT_UPDATE_FAIL_EDITING_PROHIBITED);
  133 + throw exception(CONTRACT_UPDATE_FAIL_NOT_DRAFT);
134 134 }
135 135 // 1.3 校验产品项的有效性
136 136 List<CrmContractProductDO> contractProducts = validateContractProducts(updateReqVO.getProducts());
... ... @@ -292,15 +292,22 @@ public class CrmContractServiceImpl implements CrmContractService {
292 292 }
293 293  
294 294 @Override
295   - public void updateContractAuditStatus(BpmResultListenerRespDTO event) {
296   - // 判断下状态是否符合预期
297   - if (!isEndResult(event.getResult())) {
298   - return;
  295 + public void updateContractAuditStatus(Long id, Integer bpmResult) {
  296 + // 1.1 校验合同是否存在
  297 + CrmContractDO contract = validateContractExists(id);
  298 + // 1.2 只有审批中,可以更新审批结果
  299 + if (ObjUtil.notEqual(contract.getAuditStatus(), CrmAuditStatusEnum.PROCESS.getStatus())) {
  300 + log.error("[updateContractAuditStatus][contract({}) 不处于审批中,无法更新审批结果({})]",
  301 + contract.getId(), bpmResult);
  302 + throw exception(CONTRACT_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS);
299 303 }
300   - convertAuditStatus(event);
301   - // 更新合同状态
302   - contractMapper.updateById(new CrmContractDO().setId(Long.parseLong(event.getBusinessKey()))
303   - .setAuditStatus(event.getResult()));
  304 +
  305 + // 2. 更新合同审批结果
  306 + Integer auditStatus = BpmProcessInstanceResultEnum.APPROVE.getResult().equals(bpmResult) ? CrmAuditStatusEnum.APPROVE.getStatus()
  307 + : BpmProcessInstanceResultEnum.REJECT.getResult().equals(bpmResult) ? CrmAuditStatusEnum.REJECT.getStatus()
  308 + : BpmProcessInstanceResultEnum.CANCEL.getResult();
  309 + Assert.notNull(auditStatus, "BPM 审批结果({}) 转换失败", bpmResult);
  310 + contractMapper.updateById(new CrmContractDO().setId(id).setAuditStatus(auditStatus));
304 311 }
305 312  
306 313 //======================= 查询相关 =======================
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/listener/CrmContractResultListener.java
1 1 package cn.iocoder.yudao.module.crm.service.contract.listener;
2 2  
3   -import cn.iocoder.yudao.module.bpm.api.listener.BpmResultListenerApi;
4   -import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
  3 +import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceResultEvent;
  4 +import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceResultEventListener;
5 5 import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
6 6 import cn.iocoder.yudao.module.crm.service.contract.CrmContractServiceImpl;
7 7 import jakarta.annotation.Resource;
8 8 import org.springframework.stereotype.Component;
9 9  
10   -// TODO @芋艿:后续改成支持 RPC
11 10 /**
12 11 * 合同审批的结果的监听器实现类
13 12 *
14 13 * @author HUIHUI
15 14 */
16 15 @Component
17   -public class CrmContractResultListener implements BpmResultListenerApi {
  16 +public class CrmContractResultListener extends BpmProcessInstanceResultEventListener {
18 17  
19 18 @Resource
20 19 private CrmContractService contractService;
... ... @@ -25,8 +24,8 @@ public class CrmContractResultListener implements BpmResultListenerApi {
25 24 }
26 25  
27 26 @Override
28   - public void onEvent(BpmResultListenerRespDTO event) {
29   - contractService.updateContractAuditStatus(event);
  27 + protected void onEvent(BpmProcessInstanceResultEvent event) {
  28 + contractService.updateContractAuditStatus(Long.parseLong(event.getBusinessKey()), event.getResult());
30 29 }
31 30  
32 31 }
... ...