diff --git a/pom.xml b/pom.xml
index 89807a7d0..5cf738c52 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,7 @@
yudao-module-system
yudao-module-infra
-
+ yudao-module-bpm
diff --git a/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/api/listener/BpmResultListenerApi.java b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/api/listener/BpmResultListenerApi.java
new file mode 100644
index 000000000..65b038311
--- /dev/null
+++ b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/api/listener/BpmResultListenerApi.java
@@ -0,0 +1,26 @@
+package cn.iocoder.yudao.module.bpm.api.listener;
+
+import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
+
+/**
+ * 业务流程实例的结果发生变化的监听器 Api
+ *
+ * @author HUIHUI
+ */
+public interface BpmResultListenerApi {
+
+ /**
+ * 监听的流程定义 Key
+ *
+ * @return 返回监听的流程定义 Key
+ */
+ String getProcessDefinitionKey();
+
+ /**
+ * 处理事件
+ *
+ * @param event 事件
+ */
+ void onEvent(BpmResultListenerRespDTO event);
+
+}
diff --git a/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/api/listener/dto/BpmResultListenerRespDTO.java b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/api/listener/dto/BpmResultListenerRespDTO.java
new file mode 100644
index 000000000..75f9d02f0
--- /dev/null
+++ b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/api/listener/dto/BpmResultListenerRespDTO.java
@@ -0,0 +1,31 @@
+package cn.iocoder.yudao.module.bpm.api.listener.dto;
+
+import lombok.Data;
+
+/**
+ * 业务流程实例的结果 Response DTO
+ *
+ * @author HUIHUI
+ */
+@Data
+public class BpmResultListenerRespDTO {
+
+ /**
+ * 流程实例的编号
+ */
+ private String id;
+ /**
+ * 流程实例的 key
+ */
+ private String processDefinitionKey;
+ /**
+ * 流程实例的结果
+ */
+ private Integer result;
+ /**
+ * 流程实例对应的业务标识
+ * 例如说,请假
+ */
+ private String businessKey;
+
+}
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/bpm/listener/BpmServiceResultListener.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/bpm/listener/BpmServiceResultListener.java
new file mode 100644
index 000000000..3081fb360
--- /dev/null
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/bpm/listener/BpmServiceResultListener.java
@@ -0,0 +1,35 @@
+package cn.iocoder.yudao.module.bpm.framework.bpm.listener;
+
+import cn.hutool.core.util.StrUtil;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.bpm.api.listener.BpmResultListenerApi;
+import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
+import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEvent;
+import jakarta.annotation.Resource;
+import org.springframework.context.ApplicationListener;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * 业务流程结果监听器实现类
+ *
+ * @author HUIHUI
+ */
+@Component
+public class BpmServiceResultListener implements ApplicationListener {
+
+ @Resource
+ private List bpmResultListenerApis;
+
+ @Override
+ public final void onApplicationEvent(BpmProcessInstanceResultEvent event) {
+ bpmResultListenerApis.forEach(bpmResultListenerApi -> {
+ if (!StrUtil.equals(event.getProcessDefinitionKey(), bpmResultListenerApi.getProcessDefinitionKey())) {
+ return;
+ }
+ bpmResultListenerApi.onEvent(BeanUtils.toBean(event, BpmResultListenerRespDTO.class));
+ });
+ }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java
index 716485007..877971435 100644
--- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java
+++ b/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;
import com.mzt.logapi.service.impl.DiffParseFunction;
import com.mzt.logapi.starter.annotation.LogRecord;
import jakarta.annotation.Resource;
+import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -56,6 +57,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
@Resource
private CrmBusinessProductService businessProductService;
@Resource
+ @Lazy
private CrmContractService contractService;
@Resource
private CrmPermissionService permissionService;
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java
index 52f2d6cf7..4c1a7fd95 100644
--- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java
+++ b/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;
import com.mzt.logapi.service.impl.DiffParseFunction;
import com.mzt.logapi.starter.annotation.LogRecord;
import jakarta.annotation.Resource;
+import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -56,6 +57,7 @@ public class CrmContactServiceImpl implements CrmContactService {
@Resource
private CrmPermissionService permissionService;
@Resource
+ @Lazy
private CrmContractService contractService;
@Resource
private CrmContactBusinessService contactBusinessService;
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java
index 9847af328..9d3cdb85b 100644
--- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractService.java
@@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.crm.service.contract;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractSaveReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO;
@@ -65,6 +66,12 @@ public interface CrmContractService {
*/
void handleApprove(Long id, Long userId);
+ /**
+ * 更新合同流程审批结果
+ *
+ * @param event 审批结果
+ */
+ void updateContractAuditStatus(BpmResultListenerRespDTO event);
/**
* 获得合同
*
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java
index 59274b522..c58ce15f0 100644
--- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java
+++ b/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;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
@@ -33,6 +34,7 @@ import com.mzt.logapi.context.LogRecordContext;
import com.mzt.logapi.service.impl.DiffParseFunction;
import com.mzt.logapi.starter.annotation.LogRecord;
import jakarta.annotation.Resource;
+import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -73,8 +75,10 @@ public class CrmContractServiceImpl implements CrmContractService {
@Resource
private CrmCustomerService customerService;
@Resource
+ @Lazy
private CrmContactService contactService;
@Resource
+ @Lazy
private CrmBusinessService businessService;
@Resource
private AdminUserApi adminUserApi;
@@ -244,6 +248,12 @@ public class CrmContractServiceImpl implements CrmContractService {
.setAuditStatus(CrmAuditStatusEnum.PROCESS.getStatus()));
}
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void updateContractAuditStatus(BpmResultListenerRespDTO event) {
+ contractMapper.updateById(new CrmContractDO().setId(Long.parseLong(event.getBusinessKey())).setAuditStatus(event.getResult()));
+ }
+
//======================= 查询相关 =======================
@Override
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/listener/CrmContractResultListener.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/listener/CrmContractResultListener.java
index e393c2664..f175bd43d 100644
--- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/listener/CrmContractResultListener.java
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/listener/CrmContractResultListener.java
@@ -1,5 +1,31 @@
package cn.iocoder.yudao.module.crm.service.contract.listener;
-public class CrmContractResultListener {
- // TODO puhui999: @芋艿: 艿艿写一下这个,没研究明白哈哈
+import cn.iocoder.yudao.module.bpm.api.listener.BpmResultListenerApi;
+import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO;
+import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
+import cn.iocoder.yudao.module.crm.service.contract.CrmContractServiceImpl;
+import jakarta.annotation.Resource;
+import org.springframework.stereotype.Component;
+
+/**
+ * 合同审批的结果的监听器实现类
+ *
+ * @author HUIHUI
+ */
+@Component
+public class CrmContractResultListener implements BpmResultListenerApi {
+
+ @Resource
+ private CrmContractService contractService;
+
+ @Override
+ public String getProcessDefinitionKey() {
+ return CrmContractServiceImpl.CONTRACT_APPROVE;
+ }
+
+ @Override
+ public void onEvent(BpmResultListenerRespDTO event) {
+ contractService.updateContractAuditStatus(event);
+ }
+
}
diff --git a/yudao-server/pom.xml b/yudao-server/pom.xml
index 39d6c14c7..bf640588b 100644
--- a/yudao-server/pom.xml
+++ b/yudao-server/pom.xml
@@ -46,11 +46,11 @@
-
-
-
-
-
+
+ cn.iocoder.boot
+ yudao-module-bpm-biz
+ ${revision}
+