Commit 624b35988ec2a008190bab1b532af4d7ea6f55c9
1 parent
acb8d3f2
BPM: 实现业务流程结果监听器
Showing
10 changed files
with
147 additions
and
8 deletions
pom.xml
| ... | ... | @@ -16,7 +16,7 @@ |
| 16 | 16 | <module>yudao-module-system</module> |
| 17 | 17 | <module>yudao-module-infra</module> |
| 18 | 18 | <!-- <module>yudao-module-member</module>--> |
| 19 | -<!-- <module>yudao-module-bpm</module>--> | |
| 19 | + <module>yudao-module-bpm</module> | |
| 20 | 20 | <!-- <module>yudao-module-report</module>--> |
| 21 | 21 | <!-- <module>yudao-module-mp</module>--> |
| 22 | 22 | <!-- <module>yudao-module-pay</module>--> | ... | ... |
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/api/listener/BpmResultListenerApi.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.bpm.api.listener; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 业务流程实例的结果发生变化的监听器 Api | |
| 7 | + * | |
| 8 | + * @author HUIHUI | |
| 9 | + */ | |
| 10 | +public interface BpmResultListenerApi { | |
| 11 | + | |
| 12 | + /** | |
| 13 | + * 监听的流程定义 Key | |
| 14 | + * | |
| 15 | + * @return 返回监听的流程定义 Key | |
| 16 | + */ | |
| 17 | + String getProcessDefinitionKey(); | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 处理事件 | |
| 21 | + * | |
| 22 | + * @param event 事件 | |
| 23 | + */ | |
| 24 | + void onEvent(BpmResultListenerRespDTO event); | |
| 25 | + | |
| 26 | +} | ... | ... |
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/api/listener/dto/BpmResultListenerRespDTO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.bpm.api.listener.dto; | |
| 2 | + | |
| 3 | +import lombok.Data; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 业务流程实例的结果 Response DTO | |
| 7 | + * | |
| 8 | + * @author HUIHUI | |
| 9 | + */ | |
| 10 | +@Data | |
| 11 | +public class BpmResultListenerRespDTO { | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 流程实例的编号 | |
| 15 | + */ | |
| 16 | + private String id; | |
| 17 | + /** | |
| 18 | + * 流程实例的 key | |
| 19 | + */ | |
| 20 | + private String processDefinitionKey; | |
| 21 | + /** | |
| 22 | + * 流程实例的结果 | |
| 23 | + */ | |
| 24 | + private Integer result; | |
| 25 | + /** | |
| 26 | + * 流程实例对应的业务标识 | |
| 27 | + * 例如说,请假 | |
| 28 | + */ | |
| 29 | + private String businessKey; | |
| 30 | + | |
| 31 | +} | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/bpm/listener/BpmServiceResultListener.java
0 → 100644
| 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 | +/** | |
| 15 | + * 业务流程结果监听器实现类 | |
| 16 | + * | |
| 17 | + * @author HUIHUI | |
| 18 | + */ | |
| 19 | +@Component | |
| 20 | +public class BpmServiceResultListener implements ApplicationListener<BpmProcessInstanceResultEvent> { | |
| 21 | + | |
| 22 | + @Resource | |
| 23 | + private List<BpmResultListenerApi> bpmResultListenerApis; | |
| 24 | + | |
| 25 | + @Override | |
| 26 | + public final void onApplicationEvent(BpmProcessInstanceResultEvent event) { | |
| 27 | + bpmResultListenerApis.forEach(bpmResultListenerApi -> { | |
| 28 | + if (!StrUtil.equals(event.getProcessDefinitionKey(), bpmResultListenerApi.getProcessDefinitionKey())) { | |
| 29 | + return; | |
| 30 | + } | |
| 31 | + bpmResultListenerApi.onEvent(BeanUtils.toBean(event, BpmResultListenerRespDTO.class)); | |
| 32 | + }); | |
| 33 | + } | |
| 34 | + | |
| 35 | +} | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java
| ... | ... | @@ -28,6 +28,7 @@ import com.mzt.logapi.context.LogRecordContext; |
| 28 | 28 | import com.mzt.logapi.service.impl.DiffParseFunction; |
| 29 | 29 | import com.mzt.logapi.starter.annotation.LogRecord; |
| 30 | 30 | import jakarta.annotation.Resource; |
| 31 | +import org.springframework.context.annotation.Lazy; | |
| 31 | 32 | import org.springframework.stereotype.Service; |
| 32 | 33 | import org.springframework.transaction.annotation.Transactional; |
| 33 | 34 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -56,6 +57,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { |
| 56 | 57 | @Resource |
| 57 | 58 | private CrmBusinessProductService businessProductService; |
| 58 | 59 | @Resource |
| 60 | + @Lazy | |
| 59 | 61 | private CrmContractService contractService; |
| 60 | 62 | @Resource |
| 61 | 63 | private CrmPermissionService permissionService; | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java
| ... | ... | @@ -25,6 +25,7 @@ import com.mzt.logapi.context.LogRecordContext; |
| 25 | 25 | import com.mzt.logapi.service.impl.DiffParseFunction; |
| 26 | 26 | import com.mzt.logapi.starter.annotation.LogRecord; |
| 27 | 27 | import jakarta.annotation.Resource; |
| 28 | +import org.springframework.context.annotation.Lazy; | |
| 28 | 29 | import org.springframework.stereotype.Service; |
| 29 | 30 | import org.springframework.transaction.annotation.Transactional; |
| 30 | 31 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -56,6 +57,7 @@ public class CrmContactServiceImpl implements CrmContactService { |
| 56 | 57 | @Resource |
| 57 | 58 | private CrmPermissionService permissionService; |
| 58 | 59 | @Resource |
| 60 | + @Lazy | |
| 59 | 61 | private CrmContractService contractService; |
| 60 | 62 | @Resource |
| 61 | 63 | private CrmContactBusinessService contactBusinessService; | ... | ... |
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; | |
| 4 | 5 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO; |
| 5 | 6 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractSaveReqVO; |
| 6 | 7 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO; |
| ... | ... | @@ -66,6 +67,12 @@ public interface CrmContractService { |
| 66 | 67 | void handleApprove(Long id, Long userId); |
| 67 | 68 | |
| 68 | 69 | /** |
| 70 | + * 更新合同流程审批结果 | |
| 71 | + * | |
| 72 | + * @param event 审批结果 | |
| 73 | + */ | |
| 74 | + void updateContractAuditStatus(BpmResultListenerRespDTO event); | |
| 75 | + /** | |
| 69 | 76 | * 获得合同 |
| 70 | 77 | * |
| 71 | 78 | * @param id 编号 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java
| ... | ... | @@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjUtil; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 9 | +import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO; | |
| 9 | 10 | import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi; |
| 10 | 11 | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| 11 | 12 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO; |
| ... | ... | @@ -33,6 +34,7 @@ import com.mzt.logapi.context.LogRecordContext; |
| 33 | 34 | import com.mzt.logapi.service.impl.DiffParseFunction; |
| 34 | 35 | import com.mzt.logapi.starter.annotation.LogRecord; |
| 35 | 36 | import jakarta.annotation.Resource; |
| 37 | +import org.springframework.context.annotation.Lazy; | |
| 36 | 38 | import org.springframework.stereotype.Service; |
| 37 | 39 | import org.springframework.transaction.annotation.Transactional; |
| 38 | 40 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -73,8 +75,10 @@ public class CrmContractServiceImpl implements CrmContractService { |
| 73 | 75 | @Resource |
| 74 | 76 | private CrmCustomerService customerService; |
| 75 | 77 | @Resource |
| 78 | + @Lazy | |
| 76 | 79 | private CrmContactService contactService; |
| 77 | 80 | @Resource |
| 81 | + @Lazy | |
| 78 | 82 | private CrmBusinessService businessService; |
| 79 | 83 | @Resource |
| 80 | 84 | private AdminUserApi adminUserApi; |
| ... | ... | @@ -244,6 +248,12 @@ public class CrmContractServiceImpl implements CrmContractService { |
| 244 | 248 | .setAuditStatus(CrmAuditStatusEnum.PROCESS.getStatus())); |
| 245 | 249 | } |
| 246 | 250 | |
| 251 | + @Override | |
| 252 | + @Transactional(rollbackFor = Exception.class) | |
| 253 | + public void updateContractAuditStatus(BpmResultListenerRespDTO event) { | |
| 254 | + contractMapper.updateById(new CrmContractDO().setId(Long.parseLong(event.getBusinessKey())).setAuditStatus(event.getResult())); | |
| 255 | + } | |
| 256 | + | |
| 247 | 257 | //======================= 查询相关 ======================= |
| 248 | 258 | |
| 249 | 259 | @Override | ... | ... |
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 | -public class CrmContractResultListener { | |
| 4 | - // TODO puhui999: @芋艿: 艿艿写一下这个,没研究明白哈哈 | |
| 3 | +import cn.iocoder.yudao.module.bpm.api.listener.BpmResultListenerApi; | |
| 4 | +import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO; | |
| 5 | +import cn.iocoder.yudao.module.crm.service.contract.CrmContractService; | |
| 6 | +import cn.iocoder.yudao.module.crm.service.contract.CrmContractServiceImpl; | |
| 7 | +import jakarta.annotation.Resource; | |
| 8 | +import org.springframework.stereotype.Component; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 合同审批的结果的监听器实现类 | |
| 12 | + * | |
| 13 | + * @author HUIHUI | |
| 14 | + */ | |
| 15 | +@Component | |
| 16 | +public class CrmContractResultListener implements BpmResultListenerApi { | |
| 17 | + | |
| 18 | + @Resource | |
| 19 | + private CrmContractService contractService; | |
| 20 | + | |
| 21 | + @Override | |
| 22 | + public String getProcessDefinitionKey() { | |
| 23 | + return CrmContractServiceImpl.CONTRACT_APPROVE; | |
| 24 | + } | |
| 25 | + | |
| 26 | + @Override | |
| 27 | + public void onEvent(BpmResultListenerRespDTO event) { | |
| 28 | + contractService.updateContractAuditStatus(event); | |
| 29 | + } | |
| 30 | + | |
| 5 | 31 | } | ... | ... |
yudao-server/pom.xml
| ... | ... | @@ -46,11 +46,11 @@ |
| 46 | 46 | <!-- <version>${revision}</version>--> |
| 47 | 47 | <!-- </dependency>--> |
| 48 | 48 | <!-- 工作流。默认注释,保证编译速度 --> |
| 49 | -<!-- <dependency>--> | |
| 50 | -<!-- <groupId>cn.iocoder.boot</groupId>--> | |
| 51 | -<!-- <artifactId>yudao-module-bpm-biz</artifactId>--> | |
| 52 | -<!-- <version>${revision}</version>--> | |
| 53 | -<!-- </dependency>--> | |
| 49 | + <dependency> | |
| 50 | + <groupId>cn.iocoder.boot</groupId> | |
| 51 | + <artifactId>yudao-module-bpm-biz</artifactId> | |
| 52 | + <version>${revision}</version> | |
| 53 | + </dependency> | |
| 54 | 54 | <!-- 支付服务。默认注释,保证编译速度 --> |
| 55 | 55 | <!-- <dependency>--> |
| 56 | 56 | <!-- <groupId>cn.iocoder.boot</groupId>--> | ... | ... |