作者 朱兆平

规则引擎+加验放规则动态配置

... ... @@ -21,3 +21,5 @@
###### 测试代码
##### pom.xml
###### maven引入jar所在
# 北货金二项目并且加规则引擎验证模式
... ...
... ... @@ -21,6 +21,10 @@ spring.mvc.view.prefix=.jsp
spring.redis.host=192.168.1.53
spring.redis.port=6379
#spring.redis.database=2
spring.redis.lettuce.pool.max-active=16
spring.redis.lettuce.pool.min-idle=16
spring.redis.lettuce.pool.max-wait=5000
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 测试环境
... ... @@ -72,6 +76,8 @@ feign.httpclient.connection-timeout=3000
#logback日志配置
logging.config=config/logback-dev.xml
logging.level.org.basis=info
logging.level.org.basis.groovy.mapper=debug
# 这个是刷新接口
#curl -X POST http://localhost:8080/actuator/refresh
management.endpoints.web.exposure.include=refresh
... ... @@ -88,3 +94,18 @@ custom.receptDirectory= bw/read/
interface.lock.url=http://127.0.0.1:8848
devdebug=true
g2.onoff=false
# 规则引擎相关配置
# 脚本检查更新周期(单位:秒),(默认300L)
enhance.groovy.engine.polling-cycle=10000
# 开启功能
enhance.groovy.engine.enable=true
# 缓存过期时间(默认600L分钟)
enhance.groovy.engine.cache-expire-after-write=20
#缓存初始容量(默认100)
enhance.groovy.engine.cache-initial-capacity=50
# 缓存最大容量(默认500)
enhance.groovy.engine.cache-maximum-size=50
# 开启基于Redis加载groovy脚本
enhance.groovy.engine.redis-loader.namespace=kako-release-check
enhance.groovy.engine.redis-loader.enable=true
... ...
... ... @@ -5,7 +5,7 @@
<groupId>com.sy</groupId>
<artifactId>analysis_imf</artifactId>
<version>4.0-LOCK-SNAPSHOT</version>
<version>4.5-ENGINE-SNAPSHOT</version>
<packaging>jar</packaging>
<name>analysis_imf</name>
<description>北货集成金二抬杆指令判定</description>
... ... @@ -133,6 +133,29 @@
<version>3.3.0</version>
</dependency>
<!--规则引擎-核心依赖-->
<!-- <dependency>-->
<!-- <artifactId>enhance-groovy-engine-core</artifactId>-->
<!-- <groupId>org.basis.enhance</groupId>-->
<!-- <version>1.0-SNAPSHOT</version>-->
<!-- </dependency>-->
<!--加载Redis下的groovy脚本loader依赖-->
<dependency>
<artifactId>enhance-groovy-redis-loader</artifactId>
<groupId>org.basis.enhance</groupId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--加载classpath下的groovy脚本loader依赖-->
<!-- <dependency>-->
<!-- <artifactId>enhance-groovy-classpath-loader</artifactId>-->
<!-- <groupId>org.basis.enhance</groupId>-->
<!-- <version>1.0-SNAPSHOT</version>-->
<!-- </dependency>-->
<!--Apache的 common-pool2(至少是2.2)提供连接池,供redis客户端使用-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<!--IMF need jar-->
<dependency>
<groupId>org.apache.xmlbeans</groupId>
... ...
... ... @@ -18,7 +18,7 @@ public class IMF_Tesk {
public static IMFClient client = null;
//todo:测试关,生产开
@Scheduled(fixedRate = 5000)
// @Scheduled(fixedRate = 5000)
private static void start() {
//尝试catch SDK异常
try{
... ...
package com.sy.controller;
import com.sy.model.GatherInfo;
import lombok.extern.slf4j.Slf4j;
import org.basis.enhance.groovy.entity.EngineExecutorResult;
import org.basis.enhance.groovy.entity.ExecuteParams;
import org.basis.enhance.groovy.entity.ScriptQuery;
import org.basis.enhance.groovy.executor.EngineExecutor;
import org.basis.enhance.groovy.helper.RefreshScriptHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
@RestController
@Slf4j
@RequestMapping("/v1/load-from-redis")
public class EnginTestController {
@Autowired
private EngineExecutor engineExecutor;
@Autowired
private RefreshScriptHelper refreshScriptHelper;
@GetMapping("/x21-check")
public String x21Check(String scriptName) {
// 构建参数
ExecuteParams executeParams = buildGatherInfoParams();
// 执行脚本中指定的方法 changeProduct
EngineExecutorResult executorResult = engineExecutor.execute(
"baseCheck", new ScriptQuery(scriptName), executeParams);
log.info("使用groovy脚本来动态修改闪屏信息=========>>>>>>>>>>>执行结果:{}", executorResult);
return "success";
}
@GetMapping("/form-check")
public String formCheck(String scriptName) {
// 构建参数
ExecuteParams executeParams = buildGatherInfoParams();
// 执行脚本中指定的方法 changeProduct
EngineExecutorResult executorResult = engineExecutor.execute(
"formCheck", new ScriptQuery(scriptName), executeParams);
log.info("使用groovy脚本来动态修改闪屏信息=========>>>>>>>>>>>执行结果:{}", executorResult);
return "success";
}
/**
* 过磅x21报文实体
*/
public ExecuteParams buildGatherInfoParams(){
GatherInfo gatherInfo = new GatherInfo();
gatherInfo.setAreaid("4604600000");
gatherInfo.setChnlno("4604601010");
gatherInfo.setBarcode("fe3-4c1b-befe-afa4a68d80c1");
gatherInfo.setGrosswt(new BigDecimal("6478"));
gatherInfo.setSeqno("20220630184441000028");
gatherInfo.setIetype("I");
gatherInfo.setVename("豫A61CR7");
ExecuteParams executeParams = new ExecuteParams();
executeParams.put("gatherInfo", gatherInfo);
return executeParams;
}
@GetMapping("/refreshCache")
public String refresh(String scriptName) {
// 手动刷新脚本到内存
boolean flag = refreshScriptHelper.refresh(new ScriptQuery(scriptName), true);
System.out.println("是否刷新成功:" + flag);
return String.valueOf(flag);
}
/**
* 手动刷新所有脚本到内存
* url: http://localhost:1234/v1/refresh/test02
*/
@GetMapping("/refreshCacheAll")
public String refreshAll() throws Exception {
// 手动刷新所有脚本到内存
boolean flag = refreshScriptHelper.refreshAll();
System.out.println("是否刷新成功:" + flag);
return String.valueOf(flag);
}
}
... ...
package com.sy.groovy
import com.sy.model.GatherInfo
import com.sy.model.LandBusinessTypeList
import com.sy.service.impl.GatherInfoHandle
import org.basis.enhance.groovy.entity.ExecuteParams
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
//通道申请信息验放
class BaseFormCacheCheck extends Script {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final String CHANEL_ERR= "无对应通道流转申请,走错通道";
private final String IEPORSE = "无相对应进出场申请";
/**x21指令判定
* 传入gatherInfo
*
* 传入从redis读取的申请表体实体,验证
* 进行通道比对
*/
Boolean check(ExecuteParams executeParams) {
try{
// 获取product对象
GatherInfo gatherInfo = (GatherInfo) executeParams.get("gatherInfo");
LandBusinessTypeList chanelFormInfo = (LandBusinessTypeList) executeParams.get("chanelFormInfo");
// 调用方法
ApplicationContext context = getContext();
// 获取容器中的bean
GatherInfoHandle gatherInfoHandle = context.getBean(GatherInfoHandle.class);
if (chanelFormInfo==null){
logger.error("[FORM-CHECK-ERR]:车辆-{}的流转申请校验失败,无对应通道流转申请信息",gatherInfo.getVename());
gatherInfoHandle.sendBw(gatherInfo,false, gatherInfo.getVename()+IEPORSE,null,null);
return false;
}
logger.info("[FORM-CHECK]:车辆-{}的流转申请校验通过",gatherInfo.getVename());
return true;
}catch (Exception e){
e.printStackTrace();
logger.error("[CACHE-PARSE-ERROR]:",e);
return false;
}
}
@Override
Object run() {
return false;
}
// 获取spring容器
ApplicationContext getContext() {
// 获取spring IOC容器
ApplicationContext context = applicationContext;
return context;
}
}
... ...
package com.sy.groovy
import com.sy.model.GatherInfo
import com.sy.model.LandRoadVe
import com.sy.service.LandRoadVeService
import com.sy.service.impl.GatherInfoHandle
import org.apache.commons.lang3.StringUtils
import org.basis.enhance.groovy.entity.ExecuteParams
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
//基本信息验放
class BaseVeCheck extends Script {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final String NORECORD = "车辆未备案或者识别错误,车牌号:";
private final String VE_RECORD_WEIGHT_ERR = "车辆备案信息异常";
private final String BLACKLIST= "车辆已被拉进黑名单,不允许出区";
/**x21指令判定
* 传入gatherInfo,三大属性验证,二维码/车牌/过卡重量
* 车辆备案实体
* 从redis读取的申请表体实体
*/
Boolean check(ExecuteParams executeParams) {
try{
GatherInfo gatherInfo = (GatherInfo) executeParams.get("gatherInfo");
LandRoadVe ve = (LandRoadVe) executeParams.get("LandRoadVe");
//3.车辆备案验证
// 调用方法
ApplicationContext context = getContext();
// 获取容器中的bean
GatherInfoHandle gatherInfoHandle = context.getBean(GatherInfoHandle.class);
//若无备案信息或者黑名单,返回车辆未备案或者识别错误,
if (ve == null) {
logger.error(NORECORD+gatherInfo.getVename());
gatherInfoHandle.sendBw(gatherInfo,false,NORECORD + gatherInfo.getVename(),null,null);
return false;
}
logger.info("[VE-CHECK-SUCCESS]:{}:备案验证通过",gatherInfo.getVename());
//车辆备案重量
Double selfWt=Double.parseDouble(ve.getSelfWt());
if (!(selfWt>0)){
logger.error(VE_RECORD_WEIGHT_ERR+gatherInfo.getVename());
gatherInfoHandle.sendBw(gatherInfo,false,gatherInfo.getVename()+VE_RECORD_WEIGHT_ERR,null,null);
return false;
}
logger.info("[VE-CHECK-SUCCESS]:{}备案重量[{}]验证通过",gatherInfo.getVename(),selfWt)
//车辆黑名单校验
if (!veBlackListCheck(ve)){
logger.error(BLACKLIST+gatherInfo.getVename());
gatherInfoHandle.sendBw(gatherInfo,false,gatherInfo.getVename()+BLACKLIST,null,null);
return false;
}
logger.info("[VE-CHECK-SUCCESS]:{}黑名单验证通过",gatherInfo.getVename());
//todo:车辆备案信息缓存,在哪里做申请提运单列表缓存?
logger.info("[VE-CHECK-SUCCESS]:{}车辆信息验证通过",gatherInfo.getVename());
return true;
}catch (Exception e){
e.printStackTrace();
logger.error("[VE-CHECK-ERROR]:",e);
return false;
}
}
@Override
Object run() {
return null
}
// 获取spring容器
ApplicationContext getContext() {
// 获取spring IOC容器
ApplicationContext context = applicationContext;
return context;
}
Boolean veBlackListCheck(LandRoadVe ve){
//Y 是拉黑了
if("Y".equals(ve.getVeState())){
return false;
}
return true;
}
}
... ...
package com.sy.groovy
import com.sy.model.GatherInfo
import com.sy.service.impl.GatherInfoHandle
import org.apache.commons.lang3.StringUtils
import org.basis.enhance.groovy.entity.ExecuteParams
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
//基本信息验放
class BaseX21GatherInfoCheck extends Script {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final String X21_WEIGHT_ERR = "车辆过卡重量异常";
/**x21指令判定
* 传入gatherInfo,三大属性验证,二维码/车牌/过卡重量
*/
Boolean check(ExecuteParams executeParams) {
try{
GatherInfo gatherInfo = (GatherInfo) executeParams.get("gatherInfo");
// 获取容器中的bean
// 调用方法
ApplicationContext context = getContext();
GatherInfoHandle gatherInfoHandle = context.getBean(GatherInfoHandle.class);
if (gatherInfo == null){
logger.error("[ENGIN-BASE-CHECK-ERR]-过卡信息未获取到");
return false;
}
//基本验放信息
//2.车牌号验证,从过卡信息读取
if(StringUtils.isEmpty(gatherInfo.getVename())){
logger.error("[ENGIN-BASE-CHECK-ERR]-车牌信息未获取到");
return false;
}
if(StringUtils.isEmpty(gatherInfo.getBarcode())){
logger.error("[ENGIN-BASE-CHECK-ERR]-二维码信息未获取到");
return false;
}
//4.车辆过卡重量验证,重量大于0 就正常
if (!(gatherInfo.grosswt>0)){
logger.error(X21_WEIGHT_ERR+gatherInfo.getVename());
gatherInfoHandle.sendBw(gatherInfo,false,X21_WEIGHT_ERR,null,null);
return false;
}
logger.info("[BASE-CHECK-SUCCESS]:{}过卡基本信息验证通过",gatherInfo.getVename());
return true;
}catch (Exception e){
e.printStackTrace();
logger.error("[BASE-CHECK-ERROR]:",e);
return false;
}
}
@Override
Object run() {
return null
}
// 获取spring容器
ApplicationContext getContext() {
// 获取spring IOC容器
ApplicationContext context = applicationContext;
return context;
}
}
... ...
package com.sy.groovy;
import org.basis.enhance.groovy.entity.ExecuteParams;
/**
* @author mrz
* @date 2023-05-01
* 规则脚本对应通道验放规则接口类声明
* 通道规则验放必须包含check方法,且方法结果为布尔类型,验放通过为true.否则为false
*/
public abstract class ChannelCheckScript {
public abstract Boolean check(ExecuteParams executeParams);
}
... ...
package com.sy.groovy
/**
* 关锁验放规则
*/
class CustomsLockCheck extends Script {
@Override
Object run() {
return null
}
}
... ...
package com.sy.groovy
import com.sy.model.GatherInfo
import com.sy.model.LAND_BUSINEESTYPE_LIST_INFO
import com.sy.model.LandBusinessTypeList
import com.sy.service.ResMessageService
import com.sy.service.WeightCheckHandleService
import com.sy.service.impl.GatherInfoHandle
import org.basis.enhance.groovy.entity.ExecuteParams
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
//过卡单证验放-放行验放
class ReleaseCheck extends Script {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final String FANGXING= "有运单未放行";
/**x21指令判定
* 传入gatherInfo,三大属性验证,二维码/车牌/过卡重量
* 车辆备案实体
* 从redis读取的申请表体实体
* 适用于进口转关,进口提货业务类型
*/
Boolean check(ExecuteParams executeParams) {
try{
GatherInfo gatherInfo = (GatherInfo) executeParams.get("gatherInfo");
LandBusinessTypeList landBusinessTypeList = (LandBusinessTypeList) executeParams.get("ChanelFormInfo");
List<LAND_BUSINEESTYPE_LIST_INFO> listinfos = (List<LAND_BUSINEESTYPE_LIST_INFO>) executeParams.get("ChanelFormBillLists");
//3.车辆备案验证
// 调用方法
ApplicationContext context = getContext();
// 获取容器中的bean
GatherInfoHandle gatherInfoHandle = context.getBean(GatherInfoHandle.class);
//重量校验算法
ResMessageService resMessageService = context.getBean(ResMessageService.class);
if (listinfos!=null && !listinfos.isEmpty() && resMessageService.checkManifestRelease(gatherInfo,listinfos)){
return true;
}else {
//有运单未放行
logger.error("[Release-check]-单证未通过校验:"+FANGXING+landBusinessTypeList.getMasterList());
gatherInfoHandle.sendBw(gatherInfo,false,FANGXING,landBusinessTypeList,listinfos);
return false;
}
}catch (Exception e){
e.printStackTrace();
logger.error("[Release-check-ERROR]:",e);
return false;
}
}
@Override
Object run() {
return null
}
// 获取spring容器
ApplicationContext getContext() {
// 获取spring IOC容器
ApplicationContext context = applicationContext;
return context;
}
}
... ...
package com.sy.groovy
import com.sy.model.GatherInfo
import com.sy.model.LAND_BUSINEESTYPE_LIST_INFO
import com.sy.model.LandBusinessTypeList
import com.sy.service.WeightCheckHandleService
import com.sy.service.impl.GatherInfoHandle
import org.basis.enhance.groovy.entity.ExecuteParams
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
//过卡重量验放-分拨调拨验放
class WeightCheckAllocateOrDispatch extends Script {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final String GROWSSEXCETION = "禁止通行,重量不在可控范围";
/**过磅重量判定
* 传入gatherInfo,三大属性验证,二维码/车牌/过卡重量
* 适用于分拨业务或者调拨业务
*/
Boolean check(ExecuteParams executeParams) {
try{
GatherInfo gatherInfo = (GatherInfo) executeParams.get("gatherInfo");
LandBusinessTypeList landBusinessTypeList = (LandBusinessTypeList) executeParams.get("ChanelFormInfo");
Double selfWt = (Double) executeParams.get("selfWt");
Double goodsWt = (Double) executeParams.get("goodsWt");
Double inAisleWT = (Double) executeParams.get("inAisleWT");
List<LAND_BUSINEESTYPE_LIST_INFO> listinfos = (List<LAND_BUSINEESTYPE_LIST_INFO>) executeParams.get("ChanelFormBillLists");
//3.车辆备案验证
// 调用方法
ApplicationContext context = getContext();
// 获取容器中的bean
GatherInfoHandle gatherInfoHandle = context.getBean(GatherInfoHandle.class);
//重量校验算法
WeightCheckHandleService weightCheckHandleService = context.getBean(WeightCheckHandleService.class);
logger.info("[进出场申请]-业务类型为:{}-{}",landBusinessTypeList.getCocode(),landBusinessTypeList.getBusinesstype());
if (weightCheckHandleService.checkAllocateOrDispatch(gatherInfo.getGrosswt(), selfWt, goodsWt,inAisleWT)){
return true;
}else {
gatherInfoHandle.sendBw(gatherInfo,false,GROWSSEXCETION,landBusinessTypeList,listinfos);
return false;
}
}catch (Exception e){
e.printStackTrace();
logger.error("[ExportUnloadWeightCheck-ERROR]:",e);
return false;
}
}
@Override
Object run() {
return null
}
// 获取spring容器
ApplicationContext getContext() {
// 获取spring IOC容器
ApplicationContext context = applicationContext;
return context;
}
}
... ...
package com.sy.groovy
import com.sy.model.GatherInfo
import com.sy.model.LAND_BUSINEESTYPE_LIST_INFO
import com.sy.model.LandBusinessTypeList
import com.sy.service.WeightCheckHandleService
import com.sy.service.impl.GatherInfoHandle
import org.basis.enhance.groovy.entity.ExecuteParams
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
//过卡重量验放-提货验放
class WeightCheckEmpty extends Script {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final String GROWSSEXCETION = "禁止通行,重量不在可控范围";
/**x21指令判定
* 传入gatherInfo,三大属性验证,二维码/车牌/过卡重量
* 车辆备案实体
* 从redis读取的申请表体实体
* 适用于进口转关,进口提货业务类型
*/
Boolean check(ExecuteParams executeParams) {
try{
GatherInfo gatherInfo = (GatherInfo) executeParams.get("gatherInfo");
LandBusinessTypeList landBusinessTypeList = (LandBusinessTypeList) executeParams.get("ChanelFormInfo");
Double selfWt = (Double) executeParams.get("selfWt");
Double goodsWt = (Double) executeParams.get("goodsWt");
Double inAisleWT = (Double) executeParams.get("inAisleWT");
List<LAND_BUSINEESTYPE_LIST_INFO> listinfos = (List<LAND_BUSINEESTYPE_LIST_INFO>) executeParams.get("ChanelFormBillLists");
//3.车辆备案验证
// 调用方法
ApplicationContext context = getContext();
// 获取容器中的bean
GatherInfoHandle gatherInfoHandle = context.getBean(GatherInfoHandle.class);
//重量校验算法
WeightCheckHandleService weightCheckHandleService = context.getBean(WeightCheckHandleService.class);
logger.info("[进出场申请]-业务类型为:{}-{}",landBusinessTypeList.getCocode(),landBusinessTypeList.getBusinesstype());
if (weightCheckHandleService.checkEmpty(gatherInfo.getGrosswt(), selfWt)){
return true;
}else {
logger.error("[空车业务]-出场重量未通过校验:"+GROWSSEXCETION);
gatherInfoHandle.sendBw(gatherInfo,false,GROWSSEXCETION,landBusinessTypeList,listinfos);
return false;
}
}catch (Exception e){
e.printStackTrace();
logger.error("[VE-CHECK-ERROR]:",e);
return false;
}
}
@Override
Object run() {
return null
}
// 获取spring容器
ApplicationContext getContext() {
// 获取spring IOC容器
ApplicationContext context = applicationContext;
return context;
}
}
... ...
package com.sy.groovy
import com.sy.model.GatherInfo
import com.sy.model.LAND_BUSINEESTYPE_LIST_INFO
import com.sy.model.LandBusinessTypeList
import com.sy.service.WeightCheckHandleService
import com.sy.service.impl.GatherInfoHandle
import org.basis.enhance.groovy.entity.ExecuteParams
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
//过卡重量验放-送货验放
class WeightCheckExportUnload extends Script {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final String GROWSSEXCETION = "禁止通行,重量不在可控范围";
/**x21指令判定
* 传入gatherInfo,三大属性验证,二维码/车牌/过卡重量
* 车辆备案实体
* 从redis读取的申请表体实体
* 适用于出口送货,出口转关
*/
Boolean check(ExecuteParams executeParams) {
try{
GatherInfo gatherInfo = (GatherInfo) executeParams.get("gatherInfo");
LandBusinessTypeList landBusinessTypeList = (LandBusinessTypeList) executeParams.get("ChanelFormInfo");
Double selfWt = (Double) executeParams.get("selfWt");
Double goodsWt = (Double) executeParams.get("goodsWt");
Double inAisleWT = (Double) executeParams.get("inAisleWT");
List<LAND_BUSINEESTYPE_LIST_INFO> listinfos = (List<LAND_BUSINEESTYPE_LIST_INFO>) executeParams.get("ChanelFormBillLists");
//3.车辆备案验证
// 调用方法
ApplicationContext context = getContext();
// 获取容器中的bean
GatherInfoHandle gatherInfoHandle = context.getBean(GatherInfoHandle.class);
//重量校验算法
WeightCheckHandleService weightCheckHandleService = context.getBean(WeightCheckHandleService.class);
logger.info("[进出场申请]-业务类型为:{}-{}",landBusinessTypeList.getCocode(),landBusinessTypeList.getBusinesstype());
if (weightCheckHandleService.checkExportDownLoading(gatherInfo.getGrosswt(), selfWt, goodsWt,inAisleWT)){
return true;
}else {
logger.error("[ExportUnloadWeightCheck]-出场重量未通过校验:"+GROWSSEXCETION);
gatherInfoHandle.sendBw(gatherInfo,false,GROWSSEXCETION,landBusinessTypeList,listinfos);
return false;
}
}catch (Exception e){
e.printStackTrace();
logger.error("[ExportUnloadWeightCheck-ERROR]:",e);
return false;
}
}
@Override
Object run() {
return null
}
// 获取spring容器
ApplicationContext getContext() {
// 获取spring IOC容器
ApplicationContext context = applicationContext;
return context;
}
}
... ...
package com.sy.groovy
import com.sy.model.GatherInfo
import com.sy.model.LAND_BUSINEESTYPE_LIST_INFO
import com.sy.model.LandBusinessTypeList
import com.sy.service.WeightCheckHandleService
import com.sy.service.impl.GatherInfoHandle
import org.basis.enhance.groovy.entity.ExecuteParams
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
//过卡重量验放-提货验放
class WeightCheckImportDlv extends Script {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final String GROWSSEXCETION = "禁止通行,重量不在可控范围";
/**x21指令判定
* 传入gatherInfo,三大属性验证,二维码/车牌/过卡重量
* 车辆备案实体
* 从redis读取的申请表体实体
* 适用于进口转关,进口提货业务类型
*/
Boolean check(ExecuteParams executeParams) {
try{
GatherInfo gatherInfo = (GatherInfo) executeParams.get("gatherInfo");
LandBusinessTypeList landBusinessTypeList = (LandBusinessTypeList) executeParams.get("ChanelFormInfo");
Double selfWt = (Double) executeParams.get("selfWt");
Double goodsWt = (Double) executeParams.get("goodsWt");
Double inAisleWT = (Double) executeParams.get("inAisleWT");
List<LAND_BUSINEESTYPE_LIST_INFO> listinfos = (List<LAND_BUSINEESTYPE_LIST_INFO>) executeParams.get("ChanelFormBillLists");
//3.车辆备案验证
// 调用方法
ApplicationContext context = getContext();
// 获取容器中的bean
GatherInfoHandle gatherInfoHandle = context.getBean(GatherInfoHandle.class);
//重量校验算法
WeightCheckHandleService weightCheckHandleService = context.getBean(WeightCheckHandleService.class);
logger.info("[进出场申请]-业务类型为:{}-{}",landBusinessTypeList.getCocode(),landBusinessTypeList.getBusinesstype());
if (weightCheckHandleService.checkImportDlv(gatherInfo.getGrosswt(), selfWt, goodsWt,inAisleWT)){
return true;
}else {
logger.error("[进口提货]-出场重量未通过校验:"+GROWSSEXCETION);
gatherInfoHandle.sendBw(gatherInfo,false,GROWSSEXCETION,landBusinessTypeList,listinfos);
return false;
}
}catch (Exception e){
e.printStackTrace();
logger.error("[VE-CHECK-ERROR]:",e);
return false;
}
}
@Override
Object run() {
return null
}
// 获取spring容器
ApplicationContext getContext() {
// 获取spring IOC容器
ApplicationContext context = applicationContext;
return context;
}
}
... ...
package com.sy.groovy
import com.sy.model.GatherInfo
import com.sy.model.LandBusinessTypeList
import com.sy.service.impl.GatherInfoHandle
import org.basis.enhance.groovy.entity.ExecuteParams
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
import java.util.stream.Collectors
//申请单核销判定
class X21FormReleaseCheck extends Script {
private final Logger logger = LoggerFactory.getLogger(getClass());
/**x21指令判定
* 传入gatherInfo
*
* 传入从redis读取的申请表体实体,验证
* 进行通道比对
*/
void releaseCheck(ExecuteParams executeParams) {
try{
// 获取product对象
GatherInfo gatherInfo = (GatherInfo) executeParams.get("gatherInfo");
List<LandBusinessTypeList> formList = (List<LandBusinessTypeList>) executeParams.get("formList");
// 调用方法
ApplicationContext context = getContext();
// 获取容器中的bean
GatherInfoHandle gatherInfoHandle = context.getBean(GatherInfoHandle.class);
List<LandBusinessTypeList> temp = new ArrayList<>(formList);
//二维码已出区的记录
List<LandBusinessTypeList> havenCrossList = gatherInfoHandle.listService.selectByBarcodeWithE(gatherInfo.getBarcode());
if (formList == null && formList.isEmpty() ){
logger.error("[FORM-RELEASE-CHECK]-车辆进出场对应申请缓存数据为空:{}",gatherInfo.getBarcode());
return;
}
if (havenCrossList.isEmpty()){
logger.error("[FORM-RELEASE-CHECK]{}:车辆无离场数据,不核销",gatherInfo.getVename());
return;
}
logger.info("[FORM-RELEASE-CHECK]:已过卡数量:[{}]",havenCrossList.size())
//申请核销判定,已出区的记录与流转申请数据核碰.如果流转申请列表核碰完,还剩下的需要出区的场站则不核销.
for (LandBusinessTypeList businessTypeList : havenCrossList) {
List<LandBusinessTypeList> r = formList.stream().filter({item ->
//判断还有没有没有出区的场站,还有没有出区的场站就不核销
logger.debug("[releaseFormCheck-Stream-loop]-缓存与已出核碰,缓存元素场站:[{}],已出记录场站:[{}]",item.getEndstation(),businessTypeList.getEndstation());
//解决缓存那里存储有不一样的把人错的的有问题的点,二维码不一致也把缓存删除
if (!item.getBarcode().equals(businessTypeList.getBarcode())){
return true;
}
if(item.getEndstation().equals(businessTypeList.getEndstation())) {
logger.info("[releaseFormCheck-Stream-loop]-缓存元素场站:[{}],已出记录场站:[{}]-核销判定对碰成功",item.getEndstation(),businessTypeList.getEndstation());
return true;
}else {
return false;
}
}).collect(Collectors.toList());
temp.removeAll(r);
}
logger.info("[FORM-RELEASE-CHECK]-核销判定结果:{}",temp.size());
if (temp.isEmpty()){
//todo:流转申请状态核销
logger.info("[进出场申请]-流转申请开始核销:"+gatherInfo.getVename());
//二维码核销
// gatherInfoHandle.releaseBarCode();
logger.info("[进出场申请]-流转申请已核销:"+gatherInfo.getVename());
}
}catch (Exception e){
e.printStackTrace();
logger.error("[FORM-RELEASE-ERROR]:",e);
}
}
@Override
Object run() {
return false;
}
// 获取spring容器
ApplicationContext getContext() {
// 获取spring IOC容器
ApplicationContext context = applicationContext;
return context;
}
}
... ...
... ... @@ -606,7 +606,7 @@ public class GatherInfoHandle implements GatherInfoService {
case "调拨业务":
if (gatherInfoHandle.weightCheckHandleService.checkAllocateOrDispatch(growssWt, selfWt, goodsWt,inWt)){
/**
* 调拨业务如果空车出,可出.(就是申请不带运单的)
* 调拨业务如果空车出,可出.(就是申请不带运单的,比如综保区的车辆)
*/
if (listinfos!=null && listinfos.isEmpty()){
log.info("[调拨-空车]-{}空车离场",info.getVename());
... ... @@ -717,7 +717,7 @@ public class GatherInfoHandle implements GatherInfoService {
/**
* 二维码失效核销->判定及失效通知.
*/
private void releaseBarCode(){
public void releaseBarCode(){
//是否有未驶离的流转记录二维码判定
int count=gatherInfoHandle.listService.selectlaststation(info.getVename(),info.getBarcode());
//二维码失效通知,已进入场站的与缓存比较.
... ... @@ -766,7 +766,7 @@ public class GatherInfoHandle implements GatherInfoService {
* @param list_infos 流转申请表体信息
* @return 调试模式 直接返回true,生产模式按业务走
*/
private boolean sendBw(GatherInfo info, boolean check, String reason, LandBusinessTypeList land, List<LAND_BUSINEESTYPE_LIST_INFO> list_infos) {
public boolean sendBw(GatherInfo info, boolean check, String reason, LandBusinessTypeList land, List<LAND_BUSINEESTYPE_LIST_INFO> list_infos) {
//调试模式 直接返回true
if (gatherInfoHandle.debug){
if (check) {
... ...
... ... @@ -116,7 +116,7 @@ public class LandBusListServiceImpl implements LandBusListService {
}
/**
* 根据gatherInfo获取对应的流转申请
* 根据gatherInfo获取对应的通道流转申请,没有对应通道的流转申请,则不抬杆放行.
* @return 流转申请信息
*/
@Override
... ...
... ... @@ -17,6 +17,7 @@ import java.util.concurrent.TimeUnit;
@Slf4j
public class BeihuoTests {
String ffm = "";
private static ThreadPoolExecutor threadPoolEs = XMLThreadPoolFactory.instance("kakou");
private AnalysisRoute analysisRoute=new AnalysisRoute();
... ...
package com.sy.engin;
import com.alibaba.fastjson.JSONArray;
import com.sy.model.GatherInfo;
import com.sy.model.LAND_BUSINEESTYPE_LIST_INFO;
import com.sy.model.LandBusinessTypeList;
import com.sy.model.LandRoadVe;
import com.sy.service.BusnesslistinfoService;
import com.sy.service.LandBusListService;
import com.sy.service.LandRoadVeService;
import com.sy.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.basis.enhance.groovy.entity.EngineExecutorResult;
import org.basis.enhance.groovy.entity.ExecuteParams;
import org.basis.enhance.groovy.entity.ScriptQuery;
import org.basis.enhance.groovy.executor.EngineExecutor;
import org.basis.enhance.groovy.helper.RefreshScriptHelper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class EnginTest {
private static String IEPORSE = "无相对应进出场申请";
private static String CHANEL_ERR= "无对应通道流转申请,走错通道";
@Autowired
private EngineExecutor engineExecutor;
@Autowired
private BusnesslistinfoService busnesslistinfoService;
@Autowired
private LandBusListService landBusListService;
@Autowired
private RedisService redisService;
@Autowired
private LandBusListService listService;
@Autowired
LandRoadVeService veService;
/**
* 过磅x21报文实体
*/
ExecuteParams buildGatherInfoParams(){
GatherInfo gatherInfo = new GatherInfo();
gatherInfo.setAreaid("4604600000");
gatherInfo.setChnlno("4604601010");
gatherInfo.setBarcode("edb-4ebc-919b-7d7b118da052");
gatherInfo.setGrosswt(new BigDecimal("6478"));
gatherInfo.setSeqno("20220630184441000028");
gatherInfo.setIetype("I");
gatherInfo.setVename("豫A61CR8");
ExecuteParams executeParams = new ExecuteParams();
//初始化
executeParams.put("gatherInfo", gatherInfo);
executeParams.put("formList", null);
executeParams.put("ChanelFormInfo", null);
executeParams.put("ChanelFormBillLists", null);
executeParams.put("LandRoadVe", null);
executeParams.put("inAisleWT", 0.0);
executeParams.put("diffVal", 0.0);
executeParams.put("selfWt", 0.0);
executeParams.put("goodsWt", 0.0);
//车辆备案信息
LandRoadVe ve = veService.selectByFrameNo(gatherInfo.getVename());
if (ve != null) {
//车辆备案重量
Double selfWt=Double.parseDouble(ve.getSelfWt());
executeParams.put("LandRoadVe", ve);
executeParams.put("selfWt", selfWt);
}
//获取申请单表体
log.info("[FORM-CACHE-GET]:车辆-{}核碰缓存",gatherInfo.getVename());
String landBusinessJson = redisService.get(gatherInfo.getVename());
if (StringUtils.isNotEmpty(landBusinessJson)) {
//这个是申请单表体
List<LandBusinessTypeList> list = JSONArray.parseArray(landBusinessJson, LandBusinessTypeList.class);
executeParams.put("formList", list);
//通道对应申请信息
LandBusinessTypeList chanelFormInfo = landBusListService.getLandBusinessTypeListByGather(gatherInfo);
executeParams.put("ChanelFormInfo", chanelFormInfo);
if (chanelFormInfo!= null){
executeParams.put("goodsWt", chanelFormInfo.getRemark());
}
//查询申请单运单列表
List<LAND_BUSINEESTYPE_LIST_INFO> chanelFormBillLists= busnesslistinfoService.selectmanilist(gatherInfo.getBarcode());
executeParams.put("ChanelFormBillLists", chanelFormBillLists);
}
//对应场站入场信息重量
if ("E".equals(gatherInfo.getIetype())){
List<LandBusinessTypeList> stationInChanleInfo= listService.selectwt(gatherInfo.getVename(),gatherInfo.getBarcode(),gatherInfo.getAreaid(),"I");
if (stationInChanleInfo.isEmpty()){
log.info("未查询到车辆:{}的入场信息",gatherInfo.getVename());
}else {
for(LandBusinessTypeList typeList:stationInChanleInfo){
if(typeList.getAislewt()!=null){
//对应场站进场过磅重量
Double inAisleWT = typeList.getAislewt();
executeParams.put("inAisleWT", inAisleWT);
//离场与入场重量差值
Double diffVal = inAisleWT- gatherInfo.getGrosswt().doubleValue();
executeParams.put("diffVal", diffVal);
}
}
//TODO:进场校验 增加 车辆备案重量要 <= 进场过磅重量 ,要有误差判定
}
}
return executeParams;
}
@Test
public void x21Check() {
long time = System.currentTimeMillis(); //do something that takes some time... long completedIn = System.currentTimeMillis() - time;
System.out.println("验证开始"+time);
String scriptName = "x21-check";
// String scriptName = "form-check";
// 构建参数
ExecuteParams executeParams = buildGatherInfoParams();
// 执行脚本中指定的方法 changeProduct
EngineExecutorResult executorResult = engineExecutor.execute(
"baseCheck", new ScriptQuery("x21-check"), executeParams);
log.info("使用groovy脚本来验证过卡判定放行结果=========>>>>>>>>>>>执行结果:{}", executorResult);
EngineExecutorResult formCheckResult = engineExecutor.execute(
"formCheck", new ScriptQuery("form-check"), executeParams);
EngineExecutorResult veCheckResult = engineExecutor.execute(
"veCheck", new ScriptQuery("ve-check"), executeParams);
EngineExecutorResult releaseCheckResult = engineExecutor.execute(
"releaseCheck", new ScriptQuery("form-release"), executeParams);
log.info("success");
System.out.println("验证结束"+(System.currentTimeMillis()-time));
}
@Test
public void arrTest(){
String[] busType = new String[] {"区内分拨","区内调拨"};
String[] goodsType = new String[] {"普通货物","转关货物","退库货物","换单货物","查验货物"};
String[] rules = new String[] {"基本验放规则","核销判定"};
int i = 0;
for (String bus : busType) {
for (String good : goodsType) {
for (String rule : rules) {
log.info("插入一条数据:业务类型-[{}]-货物类型:[{}]-验放规则:[{}]",bus,good,rule);
i++;
}
}
}
String[] busType1 = new String[] {"区内分拨"};
String[] goodsType1 = new String[] {"快件货物"};
String[] rules1 = new String[] {"关锁判定"};
for (String bus : busType1) {
for (String good : goodsType1) {
for (String rule : rules1) {
log.info("插入一条数据:业务类型-[{}]-货物类型:[{}]-验放规则:[{}]",bus,good,rule);
i++;
}
}
}
log.info("共插入{}条规则",i);
}
}
... ...