Commit 624b35988ec2a008190bab1b532af4d7ea6f55c9
1 parent
acb8d3f2
BPM: 实现业务流程结果监听器
Showing
10 changed files
with
147 additions
and
8 deletions
pom.xml
| @@ -16,7 +16,7 @@ | @@ -16,7 +16,7 @@ | ||
| 16 | <module>yudao-module-system</module> | 16 | <module>yudao-module-system</module> |
| 17 | <module>yudao-module-infra</module> | 17 | <module>yudao-module-infra</module> |
| 18 | <!-- <module>yudao-module-member</module>--> | 18 | <!-- <module>yudao-module-member</module>--> |
| 19 | -<!-- <module>yudao-module-bpm</module>--> | 19 | + <module>yudao-module-bpm</module> |
| 20 | <!-- <module>yudao-module-report</module>--> | 20 | <!-- <module>yudao-module-report</module>--> |
| 21 | <!-- <module>yudao-module-mp</module>--> | 21 | <!-- <module>yudao-module-mp</module>--> |
| 22 | <!-- <module>yudao-module-pay</module>--> | 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,6 +28,7 @@ import com.mzt.logapi.context.LogRecordContext; | ||
| 28 | import com.mzt.logapi.service.impl.DiffParseFunction; | 28 | import com.mzt.logapi.service.impl.DiffParseFunction; |
| 29 | import com.mzt.logapi.starter.annotation.LogRecord; | 29 | import com.mzt.logapi.starter.annotation.LogRecord; |
| 30 | import jakarta.annotation.Resource; | 30 | import jakarta.annotation.Resource; |
| 31 | +import org.springframework.context.annotation.Lazy; | ||
| 31 | import org.springframework.stereotype.Service; | 32 | import org.springframework.stereotype.Service; |
| 32 | import org.springframework.transaction.annotation.Transactional; | 33 | import org.springframework.transaction.annotation.Transactional; |
| 33 | import org.springframework.validation.annotation.Validated; | 34 | import org.springframework.validation.annotation.Validated; |
| @@ -56,6 +57,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -56,6 +57,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 56 | @Resource | 57 | @Resource |
| 57 | private CrmBusinessProductService businessProductService; | 58 | private CrmBusinessProductService businessProductService; |
| 58 | @Resource | 59 | @Resource |
| 60 | + @Lazy | ||
| 59 | private CrmContractService contractService; | 61 | private CrmContractService contractService; |
| 60 | @Resource | 62 | @Resource |
| 61 | private CrmPermissionService permissionService; | 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,6 +25,7 @@ import com.mzt.logapi.context.LogRecordContext; | ||
| 25 | import com.mzt.logapi.service.impl.DiffParseFunction; | 25 | import com.mzt.logapi.service.impl.DiffParseFunction; |
| 26 | import com.mzt.logapi.starter.annotation.LogRecord; | 26 | import com.mzt.logapi.starter.annotation.LogRecord; |
| 27 | import jakarta.annotation.Resource; | 27 | import jakarta.annotation.Resource; |
| 28 | +import org.springframework.context.annotation.Lazy; | ||
| 28 | import org.springframework.stereotype.Service; | 29 | import org.springframework.stereotype.Service; |
| 29 | import org.springframework.transaction.annotation.Transactional; | 30 | import org.springframework.transaction.annotation.Transactional; |
| 30 | import org.springframework.validation.annotation.Validated; | 31 | import org.springframework.validation.annotation.Validated; |
| @@ -56,6 +57,7 @@ public class CrmContactServiceImpl implements CrmContactService { | @@ -56,6 +57,7 @@ public class CrmContactServiceImpl implements CrmContactService { | ||
| 56 | @Resource | 57 | @Resource |
| 57 | private CrmPermissionService permissionService; | 58 | private CrmPermissionService permissionService; |
| 58 | @Resource | 59 | @Resource |
| 60 | + @Lazy | ||
| 59 | private CrmContractService contractService; | 61 | private CrmContractService contractService; |
| 60 | @Resource | 62 | @Resource |
| 61 | private CrmContactBusinessService contactBusinessService; | 63 | private CrmContactBusinessService contactBusinessService; |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java
| 1 | package cn.iocoder.yudao.module.crm.service.contract; | 1 | package cn.iocoder.yudao.module.crm.service.contract; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | +import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO; | ||
| 4 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO; | 5 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO; |
| 5 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractSaveReqVO; | 6 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractSaveReqVO; |
| 6 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO; | 7 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO; |
| @@ -66,6 +67,12 @@ public interface CrmContractService { | @@ -66,6 +67,12 @@ public interface CrmContractService { | ||
| 66 | void handleApprove(Long id, Long userId); | 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 | * @param id 编号 | 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 +6,7 @@ import cn.hutool.core.util.ObjUtil; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | 7 | import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; |
| 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 9 | +import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO; | ||
| 9 | import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi; | 10 | import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi; |
| 10 | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; | 11 | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| 11 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO; | 12 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO; |
| @@ -33,6 +34,7 @@ import com.mzt.logapi.context.LogRecordContext; | @@ -33,6 +34,7 @@ import com.mzt.logapi.context.LogRecordContext; | ||
| 33 | import com.mzt.logapi.service.impl.DiffParseFunction; | 34 | import com.mzt.logapi.service.impl.DiffParseFunction; |
| 34 | import com.mzt.logapi.starter.annotation.LogRecord; | 35 | import com.mzt.logapi.starter.annotation.LogRecord; |
| 35 | import jakarta.annotation.Resource; | 36 | import jakarta.annotation.Resource; |
| 37 | +import org.springframework.context.annotation.Lazy; | ||
| 36 | import org.springframework.stereotype.Service; | 38 | import org.springframework.stereotype.Service; |
| 37 | import org.springframework.transaction.annotation.Transactional; | 39 | import org.springframework.transaction.annotation.Transactional; |
| 38 | import org.springframework.validation.annotation.Validated; | 40 | import org.springframework.validation.annotation.Validated; |
| @@ -73,8 +75,10 @@ public class CrmContractServiceImpl implements CrmContractService { | @@ -73,8 +75,10 @@ public class CrmContractServiceImpl implements CrmContractService { | ||
| 73 | @Resource | 75 | @Resource |
| 74 | private CrmCustomerService customerService; | 76 | private CrmCustomerService customerService; |
| 75 | @Resource | 77 | @Resource |
| 78 | + @Lazy | ||
| 76 | private CrmContactService contactService; | 79 | private CrmContactService contactService; |
| 77 | @Resource | 80 | @Resource |
| 81 | + @Lazy | ||
| 78 | private CrmBusinessService businessService; | 82 | private CrmBusinessService businessService; |
| 79 | @Resource | 83 | @Resource |
| 80 | private AdminUserApi adminUserApi; | 84 | private AdminUserApi adminUserApi; |
| @@ -244,6 +248,12 @@ public class CrmContractServiceImpl implements CrmContractService { | @@ -244,6 +248,12 @@ public class CrmContractServiceImpl implements CrmContractService { | ||
| 244 | .setAuditStatus(CrmAuditStatusEnum.PROCESS.getStatus())); | 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 | @Override | 259 | @Override |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/listener/CrmContractResultListener.java
| 1 | package cn.iocoder.yudao.module.crm.service.contract.listener; | 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,11 +46,11 @@ | ||
| 46 | <!-- <version>${revision}</version>--> | 46 | <!-- <version>${revision}</version>--> |
| 47 | <!-- </dependency>--> | 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 | <!-- <dependency>--> | 55 | <!-- <dependency>--> |
| 56 | <!-- <groupId>cn.iocoder.boot</groupId>--> | 56 | <!-- <groupId>cn.iocoder.boot</groupId>--> |