|
@@ -1,17 +1,22 @@
|
|
|
package com.aizuda.boot.modules.test.service.impl;
|
|
|
|
|
|
+import com.aizuda.boot.modules.flw.entity.dto.ProcessStartDTO;
|
|
|
import com.aizuda.boot.modules.flw.service.IFlwProcessService;
|
|
|
import com.aizuda.boot.modules.test.entity.TestPurchaseOrder;
|
|
|
import com.aizuda.boot.modules.test.entity.dto.TestProcessStartDTO;
|
|
|
import com.aizuda.boot.modules.test.mapper.TestPurchaseOrderMapper;
|
|
|
import com.aizuda.boot.modules.test.service.ITestPurchaseOrderService;
|
|
|
import com.aizuda.bpm.engine.core.FlowCreator;
|
|
|
+import com.aizuda.bpm.engine.core.enums.EventType;
|
|
|
+import com.aizuda.bpm.engine.entity.FlwInstance;
|
|
|
+import com.aizuda.bpm.spring.event.InstanceEvent;
|
|
|
import com.aizuda.core.api.ApiAssert;
|
|
|
import com.aizuda.service.service.BaseServiceImpl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -45,7 +50,9 @@ public class TestPurchaseOrderServiceImpl extends BaseServiceImpl<TestPurchaseOr
|
|
|
ApiAssert.fail(null != dbTpo.getFlwInstanceId(), "请勿重复发起审批");
|
|
|
|
|
|
// 启动流程审批
|
|
|
- Long flwInstanceId = flwProcessService.launchProcess(dto.getProcessStart(), flowCreator);
|
|
|
+ ProcessStartDTO processStart = dto.getProcessStart();
|
|
|
+ processStart.setBusinessKey("purchaseOrder");
|
|
|
+ Long flwInstanceId = flwProcessService.launchProcess(processStart, flowCreator);
|
|
|
ApiAssert.fail(null == flwInstanceId, "流程发起失败");
|
|
|
TestPurchaseOrder tpo = new TestPurchaseOrder();
|
|
|
tpo.setId(dto.getId());
|
|
@@ -54,4 +61,23 @@ public class TestPurchaseOrderServiceImpl extends BaseServiceImpl<TestPurchaseOr
|
|
|
tpo.setStatus(1);
|
|
|
return super.updateById(tpo);
|
|
|
}
|
|
|
+
|
|
|
+ // application.yml 开启 flowlong.eventing.instance = true
|
|
|
+ @EventListener(condition = "#event.flwInstance.businessKey == 'purchaseOrder'")
|
|
|
+ public void onInstanceEvent(InstanceEvent event) {
|
|
|
+ EventType eventType = event.getEventType();
|
|
|
+ if (eventType == EventType.end || eventType == EventType.reject) {
|
|
|
+ // 审批结束更新业务状态为 2,已通过 3,已拒绝
|
|
|
+ TestPurchaseOrder tpo = new TestPurchaseOrder();
|
|
|
+ if (eventType == EventType.end) {
|
|
|
+ tpo.setStatus(2);
|
|
|
+ tpo.setFlwComment("审批完成");
|
|
|
+ } else {
|
|
|
+ tpo.setStatus(3);
|
|
|
+ tpo.setFlwComment("审批拒绝");
|
|
|
+ }
|
|
|
+ FlwInstance flwInstance = event.getFlwInstance();
|
|
|
+ baseMapper.update(tpo, Wrappers.<TestPurchaseOrder>lambdaQuery().eq(TestPurchaseOrder::getFlwInstanceId, flwInstance.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|