作者 朱兆平

update:

1 验放规则成功后,发布事件.
2 增加账册订阅事件类.
package com.sy.event;
import com.sy.model.GatherInfo;
import org.basis.enhance.groovy.entity.ExecuteParams;
import org.springframework.context.ApplicationEvent;
public class EngineCheckPassedEvent extends ApplicationEvent {
private final GatherInfo gatherInfo;
private final ExecuteParams executeParams;
public EngineCheckPassedEvent(
Object source,
GatherInfo gatherInfo,
ExecuteParams executeParams
) {
super(source);
this.gatherInfo = gatherInfo;
this.executeParams = executeParams;
}
// 提供getter方法
public GatherInfo getGatherInfo() {
return gatherInfo;
}
public ExecuteParams getExecuteParams() {
return executeParams;
}
}
... ...
package com.sy.event.listener;
import com.sy.event.EngineCheckPassedEvent;
import com.sy.model.GatherInfo;
import com.sy.model.LAND_BUSINEESTYPE_LIST_INFO;
import com.sy.model.LandBusinessTypeList;
import lombok.extern.slf4j.Slf4j;
import org.basis.enhance.groovy.entity.ExecuteParams;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Optional;
@Component
@Slf4j
public class AccontBookLisener {
@EventListener // 自动监听事件
public void handleEngineCheckPassed(EngineCheckPassedEvent event) {
// 从事件中获取参数
GatherInfo gatherInfo = event.getGatherInfo();
ExecuteParams executeParams = event.getExecuteParams();
// ✅ 在这里编写新业务逻辑(完全独立于原方法)
/**
* 1 获取申报信息
*/
LandBusinessTypeList chanelFormInfo = Optional.ofNullable(executeParams.get("ChanelFormInfo"))
.filter(obj -> obj instanceof LandBusinessTypeList)
.map(obj -> (LandBusinessTypeList) obj)
.orElse(null); // 或者使用.orElseThrow()抛出异常
if (chanelFormInfo != null) {
//1. 获取表头-业务类型
String businesstype = chanelFormInfo.getBusinesstype();
//1.1 获取表头-通道类型
String chaneltype = chanelFormInfo.getTurnoverflag();
//2. 获取表头-申报条码
String barcode = chanelFormInfo.getBarcode();
//2. 获取表体提运单列表
List<LAND_BUSINEESTYPE_LIST_INFO> landBusineestypeListInfoList = chanelFormInfo.getLandBusineestypeListInfoList();
}
// 例如:发送通知、更新状态、调用外部系统等
System.out.println("新业务处理: " + gatherInfo.getBarcode());
// 注意:此处异常不会影响原主流程(除非配置同步异常传播)
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.sy.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sy.event.EngineCheckPassedEvent;
import com.sy.mapper.RuleChannelConfigDao;
import com.sy.model.*;
import com.sy.service.*;
... ... @@ -15,6 +16,7 @@ import org.basis.enhance.groovy.entity.ScriptQuery;
import org.basis.enhance.groovy.executor.EngineExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
... ... @@ -64,6 +66,9 @@ public class EnginCheckServiceImpl implements EnginCheckService {
@Value("${devdebug}")
private Boolean debug;
@Autowired
private ApplicationEventPublisher eventPublisher;
@Override
public Boolean enginCheckByGatherInfo(GatherInfo gatherInfo,ExecuteParams executeParams) {
... ... @@ -395,19 +400,28 @@ public class EnginCheckServiceImpl implements EnginCheckService {
}
}
/**
* 关锁验放异步后置处理
* @param gatherInfo
*/
@Override
public void lockNoticeContinueCheck(GatherInfo gatherInfo) {
ExecuteParams executeParams = makeParaByGagherInfo(gatherInfo);
Boolean check = enginCheckByLockNotice(gatherInfo,executeParams);
if (check){
log.info("脚本验放通过");
log.info("[关锁异步验放流程]-规则脚本验放通过");
//放行
pass(gatherInfo,executeParams);
formRelease(gatherInfo,executeParams);
//发布事件.
eventPublisher.publishEvent(
new EngineCheckPassedEvent(this, gatherInfo, executeParams)
);
}else {
log.error("验放失败");
log.error("[关锁异步验放流程]-验放失败");
}
}
... ...
... ... @@ -3,6 +3,7 @@ package com.sy.service.router;
import com.alibaba.fastjson.JSON;
import com.sy.bwAnalysis.GatherInfoAnalysis;
import com.sy.bwAssist.Message;
import com.sy.event.EngineCheckPassedEvent;
import com.sy.mapper.LandListDao;
import com.sy.mapper.LandRouterConfigDao;
import com.sy.model.*;
... ... @@ -14,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.basis.enhance.groovy.entity.ExecuteParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
... ... @@ -60,6 +62,9 @@ public class MessageRouterX21 implements MessageRouter {
@Resource
private LandListDao landListDao;
@Autowired
private ApplicationEventPublisher eventPublisher; // Spring事件发布器
/**
* 入场标识
*/
... ... @@ -246,6 +251,11 @@ public class MessageRouterX21 implements MessageRouter {
enginCheckService.pass(gatherInfo,executeParams);
enginCheckService.formRelease(gatherInfo,executeParams);
//发布事件.
eventPublisher.publishEvent(
new EngineCheckPassedEvent(this, gatherInfo, executeParams)
);
}else {
log.error("脚本验放测试失败或等待关锁施解封");
}
... ...