commit
bb9173f7f0
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
@ -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<BpmProcessInstanceResultEvent> {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private List<BpmResultListenerApi> 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));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,5 +1,59 @@
|
|||||||
package cn.iocoder.yudao.module.crm.service.contract.listener;
|
package cn.iocoder.yudao.module.crm.service.contract.listener;
|
||||||
|
|
||||||
public class CrmContractResultListener {
|
import cn.hutool.core.util.ObjUtil;
|
||||||
// TODO puhui999: @芋艿: 艿艿写一下这个,没研究明白哈哈
|
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||||
|
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.enums.task.BpmProcessInstanceResultEnum;
|
||||||
|
import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum;
|
||||||
|
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) {
|
||||||
|
boolean currentTaskFinish = isEndResult(event.getResult());
|
||||||
|
if (!currentTaskFinish) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ObjUtil.equal(event.getResult(), BpmProcessInstanceResultEnum.APPROVE.getResult())) {
|
||||||
|
event.setResult(CrmAuditStatusEnum.APPROVE.getStatus());
|
||||||
|
}
|
||||||
|
if (ObjUtil.equal(event.getResult(), BpmProcessInstanceResultEnum.REJECT.getResult())) {
|
||||||
|
event.setResult(CrmAuditStatusEnum.REJECT.getStatus());
|
||||||
|
}
|
||||||
|
if (ObjUtil.equal(event.getResult(), BpmProcessInstanceResultEnum.CANCEL.getResult())) {
|
||||||
|
event.setResult(CrmAuditStatusEnum.CANCEL.getStatus());
|
||||||
|
}
|
||||||
|
contractService.updateContractAuditStatus(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断该结果是否处于 End 最终结果
|
||||||
|
*
|
||||||
|
* @param result 结果
|
||||||
|
* @return 是否
|
||||||
|
*/
|
||||||
|
public static boolean isEndResult(Integer result) {
|
||||||
|
return ObjectUtils.equalsAny(result, BpmProcessInstanceResultEnum.APPROVE.getResult(),
|
||||||
|
BpmProcessInstanceResultEnum.REJECT.getResult(), BpmProcessInstanceResultEnum.CANCEL.getResult());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue