作者 朱兆平

关锁业务处理:

1. 新增配置文件增加关锁通知接口地址配置
2. 新增关锁施解封逻辑判定
3. 新增关锁回调接口
4. 更新X21插入关锁通知判定逻辑
5. 更新gatherinfoHandle插入关锁判定
6. 流转申请实体类增加关锁字段
@@ -84,5 +84,7 @@ nmms.interface.host=http://10.50.3.82:8081/ @@ -84,5 +84,7 @@ nmms.interface.host=http://10.50.3.82:8081/
84 nmms.site.host=http://nmms1.15miaoo.com:17999 84 nmms.site.host=http://nmms1.15miaoo.com:17999
85 custom.receptDirectory= bw/read/ 85 custom.receptDirectory= bw/read/
86 86
  87 +# 卡口指令通知接口
  88 +interface.lock.url=http://127.0.0.1:8848
87 devdebug=true 89 devdebug=true
88 g2.onoff=false 90 g2.onoff=false
  1 +package com.sy.controller;
  2 +
  3 +
  4 +import com.alibaba.fastjson.JSON;
  5 +import com.sy.model.GatherInfo;
  6 +import com.sy.model.LockFeedBack;
  7 +import com.sy.model.LockFeignResponse;
  8 +import com.sy.model.NoticeLock;
  9 +import com.sy.response.ResultJson;
  10 +import com.sy.service.CommandLogService;
  11 +import com.sy.service.CustomsLockService;
  12 +import lombok.extern.slf4j.Slf4j;
  13 +import org.apache.commons.lang.StringUtils;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.web.bind.annotation.PostMapping;
  16 +import org.springframework.web.bind.annotation.RequestBody;
  17 +import org.springframework.web.bind.annotation.RequestMapping;
  18 +import org.springframework.web.bind.annotation.RestController;
  19 +
  20 +@RestController
  21 +@RequestMapping("/lock")
  22 +@Slf4j
  23 +public class CustomsLockController {
  24 +
  25 + @Autowired
  26 + CustomsLockService customsLockService;
  27 +
  28 + @Autowired
  29 + CommandLogService commandLogService;
  30 +
  31 + @PostMapping("response")
  32 + public ResultJson lockResponse(@RequestBody LockFeedBack feedBack){
  33 +
  34 + if (StringUtils.isEmpty(feedBack.barcode)){
  35 + return new ResultJson("400","缺少二维码信息","缺少二维码信息");
  36 + }
  37 +
  38 + log.info("收到关锁通知");
  39 + StringBuilder sb = new StringBuilder();
  40 + sb.append("施解封时间:").append(feedBack.locktime).append("\n")
  41 + .append("关锁秘钥:").append(feedBack.secret).append("\n")
  42 + .append("施解封内容:").append(feedBack.feedbackconten).append("\n")
  43 + .append("施解封状态:").append(feedBack.feedbackcode).append("\n");
  44 +
  45 + String LOCK_TYPE_UNLOCK = "2";
  46 + /**
  47 + * 关锁施解封类型
  48 + * 1 施封
  49 + * 2 解封
  50 + */
  51 + String LOCK_TYPE_LOCK = "1";
  52 + if (LOCK_TYPE_LOCK.equals(feedBack.type)){
  53 + sb.append("施解封类型:").append("施封").append("\n");
  54 + }else if (LOCK_TYPE_UNLOCK.equals(feedBack.type)){
  55 + sb.append("施解封类型:").append("解封").append("\n");
  56 + }else {
  57 + sb.append("施解封类型:").append("未知").append("\n");
  58 + sb.append("施解封类型:").append(feedBack.type).append("\n");
  59 + }
  60 +
  61 +
  62 + //判定关锁返回结果,结果正常,继续走抬杆指令,结果异常 不走抬杆指令,转人工抬杆
  63 + /**
  64 + * 关锁通知施解封状态
  65 + * 01 成功
  66 + * 02 失败
  67 + */
  68 + String LOCK_SUCCESS = "01";
  69 + if(LOCK_SUCCESS.equals(feedBack.feedbackcode)){
  70 + //读取缓存
  71 + GatherInfo gatherInfo = customsLockService.cacheRead(feedBack.barcode);
  72 + sb.append("成功");
  73 + if (gatherInfo!=null){
  74 + commandLogService.commandlog(gatherInfo,true,sb.toString(),null,null,0.0,0.0,0.0,0.0);
  75 + customsLockService.localGatherInfoHandle(gatherInfo);
  76 + }else {
  77 + sb.append("关锁缓存信息读取失败");
  78 + gatherInfo = new GatherInfo();
  79 + gatherInfo.setBarcode(feedBack.barcode);
  80 + commandLogService.commandlog(gatherInfo,false,sb.toString(),null,null,0.0,0.0,0.0,0.0);
  81 + log.info("[LOCK-RSP]-关锁缓存信息读取失败");
  82 + }
  83 + }else {
  84 + sb.append("关锁缓存信息读取失败");
  85 + GatherInfo gatherInfo = new GatherInfo();
  86 + gatherInfo.setBarcode(feedBack.barcode);
  87 + commandLogService.commandlog(gatherInfo,false,sb.toString(),null,null,0.0,0.0,0.0,0.0);
  88 + log.info("[LOCK-RSP]-关锁施解封失败");
  89 + }
  90 + return new ResultJson("200","success");
  91 + }
  92 +
  93 +}
  1 +package com.sy.controller;
  2 +
  3 +
  4 +import com.alibaba.fastjson.JSON;
  5 +import com.sy.model.GatherInfo;
  6 +import com.sy.model.LockFeedBack;
  7 +import com.sy.model.LockFeignResponse;
  8 +import com.sy.model.NoticeLock;
  9 +import com.sy.response.ResultJson;
  10 +import com.sy.service.CommandLogService;
  11 +import com.sy.service.CustomsLockService;
  12 +import lombok.extern.slf4j.Slf4j;
  13 +import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.web.bind.annotation.PostMapping;
  15 +import org.springframework.web.bind.annotation.RequestBody;
  16 +import org.springframework.web.bind.annotation.RequestMapping;
  17 +import org.springframework.web.bind.annotation.RestController;
  18 +
  19 +@RestController
  20 +@Slf4j
  21 +public class CustomsLockTestController {
  22 +
  23 + @PostMapping("/bizApi/noticeLock")
  24 + public LockFeignResponse lockTest(@RequestBody NoticeLock noticeLock){
  25 + log.info("测试接口接收到关锁通知施解封:{}", JSON.toJSONString(noticeLock));
  26 + LockFeignResponse lockFeignResponse = new LockFeignResponse();
  27 + lockFeignResponse.success=true;
  28 + lockFeignResponse.code=0;
  29 + lockFeignResponse.message="关锁通知测试接收成功";
  30 + return lockFeignResponse;
  31 + }
  32 +}
@@ -59,4 +59,22 @@ public interface LandBusinessTypeListMapper { @@ -59,4 +59,22 @@ public interface LandBusinessTypeListMapper {
59 //查询出场申请为最后一个 59 //查询出场申请为最后一个
60 int selectlaststation(@Param("trailerFrameNo") String trailerFrameNo, @Param("barcode") String barcode); 60 int selectlaststation(@Param("trailerFrameNo") String trailerFrameNo, @Param("barcode") String barcode);
61 61
  62 + /**
  63 + * 首次离场查询
  64 + * @param barcode 二维码
  65 + * @param trailerFrameNo 车牌
  66 + * @param turnoverflag 进出标识
  67 + * @return 0 代表首次离场,大于0代表非首次离场已经产生过离场记录
  68 + */
  69 + int selectFirstLeave(@Param("trailerFrameNo") String trailerFrameNo, @Param("barcode") String barcode,
  70 + @Param("turnoverflag") String turnoverflag);
  71 +
  72 + /**
  73 + * 查询二维码车辆进出场记录信息
  74 + * @param trailerFrameNo
  75 + * @param barcode
  76 + * @return
  77 + */
  78 + List<LandBusinessTypeList> selectHistory (@Param("trailerFrameNo") String trailerFrameNo, @Param("barcode") String barcode);
  79 +
62 } 80 }
@@ -11,6 +11,13 @@ public interface LandListDao { @@ -11,6 +11,13 @@ public interface LandListDao {
11 11
12 LandList selectByPrimaryKey(String id); 12 LandList selectByPrimaryKey(String id);
13 13
  14 + /**
  15 + * 根据二维码找申请单的关锁信息
  16 + * @param barcode 二维码, 二维码要做数据库的唯一索引
  17 + * @return 申请单信息
  18 + */
  19 + LandList selectLockInfoByBarcode(String barcode);
  20 +
14 int updateByPrimaryKeySelective(LandList record); 21 int updateByPrimaryKeySelective(LandList record);
15 22
16 int updateByPrimaryKey(LandList record); 23 int updateByPrimaryKey(LandList record);
@@ -13,6 +13,8 @@ public class LAND_BUSINEESTYPE_LIST_INFO { @@ -13,6 +13,8 @@ public class LAND_BUSINEESTYPE_LIST_INFO {
13 13
14 private String applicationformid; 14 private String applicationformid;
15 15
  16 + private String endcarlogo;
  17 +
16 private String ext1; 18 private String ext1;
17 19
18 private String ext2; 20 private String ext2;
@@ -21,6 +23,11 @@ public class LAND_BUSINEESTYPE_LIST_INFO { @@ -21,6 +23,11 @@ public class LAND_BUSINEESTYPE_LIST_INFO {
21 23
22 private String ext4; 24 private String ext4;
23 25
  26 + private String flightno;
  27 +
  28 + private String piece;
  29 +
  30 +
24 public String getId() { 31 public String getId() {
25 return id; 32 return id;
26 } 33 }
@@ -100,4 +107,29 @@ public class LAND_BUSINEESTYPE_LIST_INFO { @@ -100,4 +107,29 @@ public class LAND_BUSINEESTYPE_LIST_INFO {
100 public void setExt4(String ext4) { 107 public void setExt4(String ext4) {
101 this.ext4 = ext4 == null ? null : ext4.trim(); 108 this.ext4 = ext4 == null ? null : ext4.trim();
102 } 109 }
  110 +
  111 +
  112 + public String getEndcarlogo() {
  113 + return endcarlogo;
  114 + }
  115 +
  116 + public void setEndcarlogo(String endcarlogo) {
  117 + this.endcarlogo = endcarlogo;
  118 + }
  119 +
  120 + public String getFlightno() {
  121 + return flightno;
  122 + }
  123 +
  124 + public void setFlightno(String flightno) {
  125 + this.flightno = flightno;
  126 + }
  127 +
  128 + public String getPiece() {
  129 + return piece;
  130 + }
  131 +
  132 + public void setPiece(String piece) {
  133 + this.piece = piece;
  134 + }
103 } 135 }
1 package com.sy.model; 1 package com.sy.model;
2 2
3 import java.util.Date; 3 import java.util.Date;
  4 +import java.util.List;
4 5
5 public class LandBusinessTypeList { 6 public class LandBusinessTypeList {
6 private String id; 7 private String id;
@@ -69,6 +70,10 @@ public class LandBusinessTypeList { @@ -69,6 +70,10 @@ public class LandBusinessTypeList {
69 70
70 private String veProperty; 71 private String veProperty;
71 72
  73 + private List<String> endstationList;
  74 +
  75 + private List<LAND_BUSINEESTYPE_LIST_INFO> landBusineestypeListInfoList;
  76 +
72 public String getIsthree() { 77 public String getIsthree() {
73 return isthree; 78 return isthree;
74 } 79 }
@@ -342,4 +347,21 @@ public class LandBusinessTypeList { @@ -342,4 +347,21 @@ public class LandBusinessTypeList {
342 public void setVeProperty(String veProperty) { 347 public void setVeProperty(String veProperty) {
343 this.veProperty = veProperty; 348 this.veProperty = veProperty;
344 } 349 }
  350 +
  351 +
  352 + public List<String> getEndstationList() {
  353 + return endstationList;
  354 + }
  355 +
  356 + public void setEndstationList(List<String> endstationList) {
  357 + this.endstationList = endstationList;
  358 + }
  359 +
  360 + public List<LAND_BUSINEESTYPE_LIST_INFO> getLandBusineestypeListInfoList() {
  361 + return landBusineestypeListInfoList;
  362 + }
  363 +
  364 + public void setLandBusineestypeListInfoList(List<LAND_BUSINEESTYPE_LIST_INFO> landBusineestypeListInfoList) {
  365 + this.landBusineestypeListInfoList = landBusineestypeListInfoList;
  366 + }
345 } 367 }
@@ -205,5 +205,11 @@ public class LandList implements Serializable { @@ -205,5 +205,11 @@ public class LandList implements Serializable {
205 */ 205 */
206 private String modeTransportation; 206 private String modeTransportation;
207 207
  208 + /**
  209 + * 关锁号
  210 + */
  211 + private String lockNum;
  212 +
  213 +
208 private static final long serialVersionUID = 1L; 214 private static final long serialVersionUID = 1L;
209 } 215 }
  1 +package com.sy.model;
  2 +
  3 +/**
  4 + * 关锁回调接口实体
  5 + * @author mrz
  6 + */
  7 +public class LockFeedBack {
  8 + /**
  9 + * 二维码
  10 + */
  11 + public String barcode;
  12 + /**
  13 + * 施解封状态
  14 + */
  15 + public String feedbackcode;
  16 + /**
  17 + * 施解封描述
  18 + */
  19 + public String feedbackconten;
  20 + /**
  21 + * 关锁秘钥
  22 + */
  23 + public String secret;
  24 + /**
  25 + * 施解封时间
  26 + */
  27 + public String locktime;
  28 + /**
  29 + * 施解封类型 ,1 施封 2 解封
  30 + */
  31 + public String type;
  32 +}
  1 +package com.sy.model;
  2 +
  3 +/**
  4 + * 关锁通知响应实体
  5 + */
  6 +public class LockFeignResponse {
  7 + //接口成功失败标识
  8 + public boolean success;
  9 + //返回码 0 成功,-1失败
  10 + public Integer code;
  11 + //返回对象实体
  12 + public Object data;
  13 + //返回信息描述
  14 + public String message;
  15 +
  16 + public LockFeignResponse(boolean success, Integer code) {
  17 + this.success = success;
  18 + this.code = code;
  19 + }
  20 +
  21 + public LockFeignResponse() {
  22 + }
  23 +}
  1 +package com.sy.model;
  2 +
  3 +/**
  4 + * 关锁通知实体
  5 + */
  6 +public class NoticeLock {
  7 + //二维码
  8 + public String barcode;
  9 + //车牌号
  10 + public String vehicleNo;
  11 + //关锁号
  12 + public String lockNo;
  13 + //场站编号
  14 + public String areaId;
  15 + //通道编号
  16 + public String chnlNo;
  17 + //1 施封,2解封,施解封类型
  18 + public String type;
  19 +}
  1 +package com.sy.response;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import java.io.Serializable;
  6 +
  7 +/**
  8 + * @author 子诚
  9 + * Description:返回结果封装类
  10 + * 时间:2020/7/01 10:06
  11 + */
  12 +@Data
  13 +public class ResultJson<T> implements Serializable {
  14 +
  15 + private static final long serialVersionUID = 1L;
  16 +
  17 + /**
  18 + * 响应业务状态,默认为200
  19 + */
  20 + private String code;
  21 +
  22 + /**
  23 + * 响应消息
  24 + */
  25 + private String msg;
  26 +
  27 + /**
  28 + * 错误消息内容
  29 + */
  30 + private String error;
  31 +
  32 + /**
  33 + * 数据总条数
  34 + */
  35 + private Integer total;
  36 +
  37 + /**
  38 + * 响应数据
  39 + */
  40 + private T data;
  41 +
  42 + /**
  43 + * JWT令牌
  44 + */
  45 + private String jwtToken;
  46 +
  47 +
  48 + /**
  49 + * 无参,构造方法
  50 + */
  51 + public ResultJson()
  52 + {
  53 + }
  54 +
  55 +
  56 + /**
  57 + * 定义有参构造器
  58 + *
  59 + * @param code 响应状态
  60 + * @param msg 响应消息
  61 + */
  62 + public ResultJson(String code, String msg)
  63 + {
  64 + this.code = code;
  65 + this.msg = msg;
  66 + }
  67 +
  68 + /**
  69 + * 定义有参构造器
  70 + *
  71 + * @param code 响应状态
  72 + * @param msg 响应消息
  73 + * @param data 响应数据
  74 + */
  75 + public ResultJson(String code, String msg, T data)
  76 + {
  77 + this.code = code;
  78 + this.msg = msg;
  79 + this.data = data;
  80 + }
  81 +
  82 + public ResultJson(String code, String msg, String error)
  83 + {
  84 + this.code = code;
  85 + this.msg = msg;
  86 + this.error = error;
  87 + }
  88 +
  89 + public ResultJson(String code, String msg, T data, Integer total)
  90 + {
  91 + this.code = code;
  92 + this.msg = msg;
  93 + this.data = data;
  94 + this.total = total;
  95 + }
  96 +
  97 + /**
  98 + * 定义静态、成功方法(重载)
  99 + *
  100 + * @return 成功(没有响应数据)
  101 + */
  102 + public static ResultJson success()
  103 + {
  104 + return new ResultJson<>("200", "success");
  105 + }
  106 +
  107 + public static ResultJson success(String msg)
  108 + {
  109 + return new ResultJson<>("200", msg);
  110 + }
  111 +
  112 +
  113 + /**
  114 + * 定义静态、成功方法(重载)
  115 + *
  116 + * @return 成功(响应数据)
  117 + */
  118 + public static ResultJson success(Object data)
  119 + {
  120 + return new ResultJson<>("200", "success", data);
  121 + }
  122 +
  123 + /**
  124 + * 定义静态、成功方法(重载)
  125 + *
  126 + * @return 成功(响应数据)
  127 + */
  128 + public static ResultJson success(String message, Object data)
  129 + {
  130 + return new ResultJson<>("200", message, data);
  131 + }
  132 +}
  1 +package com.sy.service;
  2 +
  3 +import com.sy.model.GatherInfo;
  4 +
  5 +/**
  6 + * 关锁业务接口
  7 + * @author mrz
  8 + */
  9 +public interface CustomsLockService {
  10 +
  11 + /**
  12 + * 上关锁通知
  13 + */
  14 + void lockNotice();
  15 +
  16 + /**
  17 + * 解关锁通知
  18 + */
  19 + void unLockNotice();
  20 +
  21 + /**
  22 + * 关锁通知消息缓存
  23 + * key为二维码
  24 + * value 为GatherInfo
  25 + */
  26 + void cacheWrite(GatherInfo info);
  27 +
  28 + /**
  29 + * 读取关锁消息缓存
  30 + * 关锁回调处理
  31 + */
  32 + GatherInfo cacheRead(String barcode);
  33 +
  34 + /**
  35 + * 回调读取缓存,继续处理抬杆业务
  36 + */
  37 + void localGatherInfoHandle(GatherInfo info);
  38 +
  39 + /**
  40 + * 判断是否需要通知
  41 + * 判定要素
  42 + * 1. 流转申请携带关锁号-这个判定取消
  43 + * 2. 业务类型为分拨业务或者调拨业务
  44 + * 3. 场站含综保区不涉及关锁
  45 + * 4. 流转申请中的货物有单证又是多场站,多场站又不包含综保区必须为关锁业务
  46 + * 5. 顺丰上锁通知的问题
  47 + * @param info 车辆过卡信息
  48 + * @return true 需要通知,走关锁业务
  49 + */
  50 + boolean lockNoticeCheck(GatherInfo info);
  51 +
  52 + /**
  53 + * 是否上锁通知判定
  54 + * @return
  55 + */
  56 + boolean lockCheck(GatherInfo info);
  57 +
  58 + /**
  59 + * 是否解锁通知判定
  60 + * @param info
  61 + * @return
  62 + */
  63 + boolean unLockCheck(GatherInfo info);
  64 +}
@@ -45,4 +45,15 @@ public interface LandBusListService { @@ -45,4 +45,15 @@ public interface LandBusListService {
45 */ 45 */
46 LandBusinessTypeList getLandBusinessTypeListByGather(GatherInfo info); 46 LandBusinessTypeList getLandBusinessTypeListByGather(GatherInfo info);
47 47
  48 + List<LandBusinessTypeList> getLandBusinessTypeListsByGather(GatherInfo info);
  49 +
  50 + /**
  51 + * 首次离场查询
  52 + * @param barcode 二维码
  53 + * @param trailerFrameNo 车牌
  54 + * @param turnoverflag 进出标识
  55 + * @return 0 代表首次离场,大于0代表非首次离场已经产生过离场记录
  56 + */
  57 + int selectFirstLeave(String trailerFrameNo, String barcode, String turnoverflag);
  58 +
48 } 59 }
  1 +package com.sy.service.feigin;
  2 +
  3 +import com.sy.model.LockFeignResponse;
  4 +import com.sy.model.NoticeLock;
  5 +import feign.hystrix.FallbackFactory;
  6 +import lombok.extern.slf4j.Slf4j;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +/**
  10 + * @author mrz
  11 + */
  12 +@Component
  13 +@Slf4j
  14 +public class LockFeignFallBackFactory implements FallbackFactory<LockFeignService> {
  15 + @Override
  16 + public LockFeignService create(Throwable throwable) {
  17 + log.error("调用关锁通知接口异常",throwable);
  18 + return new LockFeignService() {
  19 + @Override
  20 + public LockFeignResponse noticeLock(NoticeLock noticeLock) {
  21 + return new LockFeignResponse(false,-1);
  22 + }
  23 + };
  24 + }
  25 +}
  1 +package com.sy.service.feigin;
  2 +
  3 +
  4 +import com.sy.model.LockFeignResponse;
  5 +import com.sy.model.NoticeLock;
  6 +import org.springframework.cloud.openfeign.FeignClient;
  7 +import org.springframework.stereotype.Component;
  8 +import org.springframework.web.bind.annotation.PostMapping;
  9 +import org.springframework.web.bind.annotation.RequestBody;
  10 +
  11 +import java.util.Map;
  12 +
  13 +/**
  14 + * 关锁通知接口
  15 + * @author mrz
  16 + */
  17 +@FeignClient(name = "LOCK-SERVER",url = "${interface.lock.url}",fallbackFactory = LockFeignFallBackFactory.class)
  18 +public interface LockFeignService {
  19 +
  20 + @PostMapping("/bizApi/noticeLock")
  21 + LockFeignResponse noticeLock(@RequestBody NoticeLock noticeLock);
  22 +}
  23 +
@@ -28,4 +28,8 @@ public class GatherInfoServiceImpl implements GatherInfoService { @@ -28,4 +28,8 @@ public class GatherInfoServiceImpl implements GatherInfoService {
28 28
29 } 29 }
30 30
  31 + @Override
  32 + public boolean haveLockNum(String barcode) {
  33 + return false;
  34 + }
31 } 35 }
@@ -10,6 +10,7 @@ import com.sy.service.RedisService; @@ -10,6 +10,7 @@ import com.sy.service.RedisService;
10 import lombok.extern.slf4j.Slf4j; 10 import lombok.extern.slf4j.Slf4j;
11 import org.apache.commons.lang.StringUtils; 11 import org.apache.commons.lang.StringUtils;
12 12
  13 +import org.apache.ibatis.annotations.Param;
13 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.stereotype.Service; 15 import org.springframework.stereotype.Service;
15 16
@@ -137,7 +138,7 @@ public class LandBusListServiceImpl implements LandBusListService { @@ -137,7 +138,7 @@ public class LandBusListServiceImpl implements LandBusListService {
137 /** 138 /**
138 * 通道对碰有了.二维码不一致怎么办? 139 * 通道对碰有了.二维码不一致怎么办?
139 */ 140 */
140 - if (item.getAisle().equals(gatherInfo.getChnlno())){ 141 + if (item.getBarcode().equals(gatherInfo.getBarcode()) && item.getAisle().equals(gatherInfo.getChnlno())){
141 if (item.getBarcode().equals(gatherInfo.getBarcode())){ 142 if (item.getBarcode().equals(gatherInfo.getBarcode())){
142 log.info("车辆-{}的申请缓存信息核碰成功,通道:{}",gatherInfo.getVename(),gatherInfo.getChnlno()); 143 log.info("车辆-{}的申请缓存信息核碰成功,通道:{}",gatherInfo.getVename(),gatherInfo.getChnlno());
143 return item; 144 return item;
@@ -160,4 +161,35 @@ public class LandBusListServiceImpl implements LandBusListService { @@ -160,4 +161,35 @@ public class LandBusListServiceImpl implements LandBusListService {
160 161
161 return null; 162 return null;
162 } 163 }
  164 +
  165 + @Override
  166 + public List<LandBusinessTypeList> getLandBusinessTypeListsByGather(GatherInfo gatherInfo){
  167 + try {
  168 + //通过车牌号,二维码,场站,通道号,进出类型查询进出场站申请列表
  169 + String landBusinessJson = redisService.get(gatherInfo.getVename());
  170 + List<LandBusinessTypeList> list = new ArrayList<>();
  171 + if (StringUtils.isNotEmpty(landBusinessJson)){
  172 + list = JSONArray.parseArray(landBusinessJson,LandBusinessTypeList.class);
  173 + //4. 若查询结果为null,返回无相对应进出场申请
  174 + if (list == null || list.isEmpty()) {
  175 + log.error(gatherInfo.getVename()+"无相对应进出场申请");
  176 + return null;
  177 + }
  178 + return list;
  179 + }else {
  180 + log.error("未找到车辆-{}的申请缓存信息",gatherInfo.getVename());
  181 + log.info("未找到车辆-{}的申请缓存信息,或者流转已超期失效",gatherInfo.getVename());
  182 + return null;
  183 + }
  184 + }catch (Exception e){
  185 + log.error("{}获取流转缓存异常",gatherInfo.getVename(),e);
  186 + return null;
  187 + }
  188 + }
  189 +
  190 + @Override
  191 + public int selectFirstLeave(String trailerFrameNo, String barcode, String turnoverflag){
  192 + return listMapper.selectFirstLeave(trailerFrameNo, barcode, turnoverflag);
  193 + }
  194 +
163 } 195 }
  1 +package com.sy.service.lock;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.sy.mapper.LandBusinessTypeListMapper;
  5 +import com.sy.mapper.LandListDao;
  6 +import com.sy.model.GatherInfo;
  7 +import com.sy.model.LAND_BUSINEESTYPE_LIST_INFO;
  8 +import com.sy.model.LandBusinessTypeList;
  9 +import com.sy.model.LandList;
  10 +import com.sy.service.CustomsLockService;
  11 +import com.sy.service.LandBusListService;
  12 +import com.sy.service.RedisService;
  13 +import com.sy.service.impl.GatherInfoHandle;
  14 +import lombok.extern.slf4j.Slf4j;
  15 +import org.apache.commons.lang.StringUtils;
  16 +import org.springframework.beans.factory.annotation.Autowired;
  17 +import org.springframework.stereotype.Service;
  18 +
  19 +import javax.annotation.Resource;
  20 +import java.util.List;
  21 +import java.util.stream.Collectors;
  22 +
  23 +/**
  24 + * 关锁业务处理
  25 + * @author mrz
  26 + */
  27 +@Slf4j
  28 +@Service
  29 +public class CustomsLockServiceImpl implements CustomsLockService {
  30 +
  31 + @Resource
  32 + private LandListDao landListDao;
  33 +
  34 + @Autowired
  35 + private RedisService redisService;
  36 +
  37 + @Autowired
  38 + private LandBusListService landBusListService;
  39 +
  40 + @Resource
  41 + private LandBusinessTypeListMapper landBusinessTypeListMapper;
  42 +
  43 + /**
  44 + * 缓存关锁相关前缀
  45 + */
  46 + private static String LOCK_PRE="LOCK-";
  47 +
  48 + @Override
  49 + public void lockNotice() {
  50 +
  51 + }
  52 +
  53 + @Override
  54 + public void unLockNotice() {
  55 +
  56 + }
  57 +
  58 + @Override
  59 + public void cacheWrite(GatherInfo info) {
  60 + redisService.set(LOCK_PRE+info.getBarcode(),
  61 + JSONObject.toJSONString(info),
  62 + 60*60*6);
  63 + }
  64 +
  65 + @Override
  66 + public GatherInfo cacheRead(String barcode) {
  67 + String jsonStr = redisService.get(LOCK_PRE+barcode);
  68 + if (StringUtils.isNotEmpty(jsonStr)){
  69 + GatherInfo gatherInfo = JSONObject.parseObject(jsonStr, GatherInfo.class);
  70 + return gatherInfo;
  71 + }
  72 + return null;
  73 + }
  74 +
  75 + @Override
  76 + public void localGatherInfoHandle(GatherInfo gatherInfo) {
  77 + GatherInfoHandle gatherInfoHandle = new GatherInfoHandle();
  78 + gatherInfoHandle.handel(gatherInfo);
  79 + }
  80 +
  81 + @Override
  82 + public boolean lockNoticeCheck(GatherInfo info) {
  83 + if (info!=null && StringUtils.isNotEmpty(info.getBarcode())) {
  84 + /**
  85 + * 申请业务类型检查
  86 + * 调拨业务及分拨业务装载货物为单证的,必须有关锁号
  87 + * 就算申请信息里面没关锁号也要通知
  88 + */
  89 + LandBusinessTypeList landBusinessTypeList = landBusListService.getLandBusinessTypeListByGather(info);
  90 + if (landBusinessTypeList!=null){
  91 + if ("调拨业务".equals(landBusinessTypeList.getBusinesstype()) || "分拨业务".equals(landBusinessTypeList.getBusinesstype())) {
  92 + //综保区场站及内三不通知
  93 + if ("4600329012".equals(landBusinessTypeList.getEndstation()) || "4612199001".equals(landBusinessTypeList.getEndstation())) {
  94 + log.info("[LOCK-CHECK]-综保区及内三场站不处理关锁业务,当前场站:{}",landBusinessTypeList.getEndstation());
  95 + return false;
  96 + //场站检查,todo:快邮场站特殊判定
  97 + }else {
  98 + return true;
  99 + /**
  100 + * 单证验证-取消
  101 + */
  102 +// List<LAND_BUSINEESTYPE_LIST_INFO> land_busineestype_list_infos = landBusinessTypeList.getLandBusineestypeListInfoList();
  103 +// if (!land_busineestype_list_infos.isEmpty()){
  104 +// LAND_BUSINEESTYPE_LIST_INFO list_info = land_busineestype_list_infos.stream().parallel()
  105 +// .filter(item -> "B".equals(item.getExt4()))
  106 +// .findAny().orElse(null);
  107 +//
  108 +// //包含单证
  109 +// if (list_info!=null){
  110 +// log.info("[LOCK-CHECK]-包含单证,开始关锁通知");
  111 +// return true;
  112 +// }
  113 +// }
  114 + }
  115 + }
  116 + }else {
  117 + log.info("[LOCK-CHECK]-无对应进出场申请");
  118 + return false;
  119 + }
  120 + }
  121 + return false;
  122 + }
  123 +
  124 + @Override
  125 + public boolean lockCheck(GatherInfo info) {
  126 + int e = landBusListService.selectFirstLeave(info.getVename(), info.getBarcode(), "E");
  127 + if (e==0){
  128 + //首次离场,通知关锁接口 上锁
  129 + log.info("[UNLOCK-NOTICE]-上锁通知");
  130 + return true;
  131 + }
  132 +
  133 + return false;
  134 + }
  135 +
  136 +
  137 +
  138 + @Override
  139 + public boolean unLockCheck(GatherInfo info){
  140 +
  141 + //从缓存获取通道流转列表信息
  142 + List<LandBusinessTypeList> landBusinessTypeListsByGather = landBusListService.getLandBusinessTypeListsByGather(info);
  143 + List<LandBusinessTypeList> temp = landBusinessTypeListsByGather;
  144 + //已经过场的记录
  145 + List<LandBusinessTypeList> landBusinessTypeLists = landBusinessTypeListMapper.selectHistory(info.getVename(), info.getBarcode());
  146 +
  147 + for (LandBusinessTypeList formItem : landBusinessTypeLists) {
  148 + List<LandBusinessTypeList> r = landBusinessTypeListsByGather.stream().filter(item -> {
  149 + if (item.getEndstation().equals(formItem.getEndstation())) {
  150 + log.info("[Lock-Stream-loop]-缓存元素场站:[{}],已出入记录场站:[{}]-核销判定对碰成功", item.getEndstation(), formItem.getEndstation());
  151 + return true;
  152 + } else {
  153 + return false;
  154 + }
  155 + }).collect(Collectors.toList());
  156 + temp.removeAll(r);
  157 + }
  158 +
  159 +
  160 + //筛选出未入场的申请
  161 + List<String> stationList = temp.stream().map(LandBusinessTypeList::getEndstation).distinct().collect(Collectors.toList());
  162 + log.info("[unLockCheck]-未走的流转申请:{}",temp.size());
  163 +
  164 + //判定是否还剩最后一个场站未入场
  165 + if (stationList.size() == 1){
  166 + //场站信息 与 当前GatherInfo信息又对的上
  167 + if (stationList.get(0).equals(info.getAreaid())) {
  168 + //通知解锁
  169 + log.info("[UNLOCK-NOTICE]-解锁通知");
  170 + return true;
  171 + }
  172 + }
  173 +
  174 + return false;
  175 + }
  176 +}
@@ -3,14 +3,14 @@ package com.sy.service.router; @@ -3,14 +3,14 @@ package com.sy.service.router;
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.sy.bwAnalysis.GatherInfoAnalysis; 4 import com.sy.bwAnalysis.GatherInfoAnalysis;
5 import com.sy.bwAssist.Message; 5 import com.sy.bwAssist.Message;
  6 +import com.sy.mapper.LandListDao;
6 import com.sy.mapper.LandRouterConfigDao; 7 import com.sy.mapper.LandRouterConfigDao;
7 -import com.sy.model.G2Bean;  
8 -import com.sy.model.GatherInfo;  
9 -import com.sy.model.LandBusinessTypeList;  
10 -import com.sy.model.LandRouterConfig; 8 +import com.sy.model.*;
11 import com.sy.service.CommandLogService; 9 import com.sy.service.CommandLogService;
  10 +import com.sy.service.CustomsLockService;
12 import com.sy.service.LandBusListService; 11 import com.sy.service.LandBusListService;
13 import com.sy.service.RedisService; 12 import com.sy.service.RedisService;
  13 +import com.sy.service.feigin.LockFeignService;
14 import com.sy.service.impl.GatherInfoHandle; 14 import com.sy.service.impl.GatherInfoHandle;
15 import com.sy.socket.CommandClient; 15 import com.sy.socket.CommandClient;
16 import lombok.extern.slf4j.Slf4j; 16 import lombok.extern.slf4j.Slf4j;
@@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.stereotype.Service; 19 import org.springframework.stereotype.Service;
20 20
21 import javax.annotation.Resource; 21 import javax.annotation.Resource;
  22 +import java.net.ConnectException;
22 import java.util.List; 23 import java.util.List;
23 24
24 /** 25 /**
@@ -49,6 +50,24 @@ public class MessageRouterX21 implements MessageRouter { @@ -49,6 +50,24 @@ public class MessageRouterX21 implements MessageRouter {
49 @Autowired 50 @Autowired
50 private CommandLogService commandLogService; 51 private CommandLogService commandLogService;
51 52
  53 + @Autowired
  54 + private CustomsLockService customsLockService;
  55 +
  56 + @Autowired
  57 + private LockFeignService lockFeignService;
  58 +
  59 + @Resource
  60 + private LandListDao landListDao;
  61 +
  62 + /**
  63 + * 入场标识
  64 + */
  65 + private static String IN_TYPE="I";
  66 + /**
  67 + * 离场标识
  68 + */
  69 + private static String OUT_TYPE="E";
  70 +
52 @Override 71 @Override
53 public void route(Message message) { 72 public void route(Message message) {
54 log.info("处理X21:gatherInfo,[switch]-G2开关状态:[{}]",g2Bean.getOnoff()); 73 log.info("处理X21:gatherInfo,[switch]-G2开关状态:[{}]",g2Bean.getOnoff());
@@ -202,14 +221,73 @@ public class MessageRouterX21 implements MessageRouter { @@ -202,14 +221,73 @@ public class MessageRouterX21 implements MessageRouter {
202 * 本地处理 221 * 本地处理
203 */ 222 */
204 private void X21Local(GatherInfo info){ 223 private void X21Local(GatherInfo info){
  224 + //先判定关锁业务
  225 + if (lockHandle(info)) {
  226 + log.info("[{}]-关锁通知,等待回调",info.getBarcode());
  227 + }else {
205 GatherInfoHandle gatherInfoHandle = new GatherInfoHandle(); 228 GatherInfoHandle gatherInfoHandle = new GatherInfoHandle();
206 gatherInfoHandle.handel(info); 229 gatherInfoHandle.handel(info);
207 } 230 }
208 231
  232 + }
  233 +
209 /** 234 /**
210 * 车辆过卡指令日志记录 235 * 车辆过卡指令日志记录
211 */ 236 */
212 private void record(GatherInfo info,boolean result,String reason,LandBusinessTypeList landBusinessTypeList){ 237 private void record(GatherInfo info,boolean result,String reason,LandBusinessTypeList landBusinessTypeList){
213 commandLogService.commandlog(info,result,reason,landBusinessTypeList,null,0.0,0.0,0.0,0.0); 238 commandLogService.commandlog(info,result,reason,landBusinessTypeList,null,0.0,0.0,0.0,0.0);
214 } 239 }
  240 +
  241 + //关锁施解封通知判定
  242 + private boolean lockHandle(GatherInfo info){
  243 + //需要关锁业务通知
  244 + if (customsLockService.lockNoticeCheck(info)){
  245 +
  246 + /**
  247 + * 关锁号申请检查
  248 + * 根据二维码查申请是否有关锁信息,没有查到实体返回null
  249 + */
  250 + LandList landList = landListDao.selectLockInfoByBarcode(info.getBarcode());
  251 + if (landList!=null && StringUtils.isNotEmpty(landList.getLockNum())) {
  252 + log.info("[LOCK-CHECK]-流转申请携带关锁,二维码:{}",info.getBarcode());
  253 +
  254 + NoticeLock noticeLock = new NoticeLock();
  255 + noticeLock.barcode = info.getBarcode();
  256 + noticeLock.areaId = info.getAreaid();
  257 + noticeLock.chnlNo = info.getChnlno();
  258 + noticeLock.vehicleNo = info.getVename();
  259 +
  260 + //1. 判定是上锁通知还是解锁通知
  261 + if (OUT_TYPE.equals(info.getIetype()) && customsLockService.lockCheck(info)) {
  262 + //写入缓存
  263 + customsLockService.cacheWrite(info);
  264 + //接口通知
  265 + noticeLock.lockNo =landList.getLockNum();
  266 + noticeLock.type = "1";
  267 + LockFeignResponse lockFeignResponse = lockFeignService.noticeLock(noticeLock);
  268 + log.info("[LOCK-API-RSP]-关锁通知接口返回,code:{},message:{},success:{}",lockFeignResponse.code,lockFeignResponse.message,lockFeignResponse.success);
  269 + record(info,false,"关锁施封通知中,等待下一步指令",null);
  270 + return true;
  271 + }else {
  272 + if (IN_TYPE.equals(info.getIetype()) && customsLockService.unLockCheck(info)) {
  273 + customsLockService.cacheWrite(info);
  274 +
  275 + //接口通知
  276 + noticeLock.lockNo =landList.getLockNum();
  277 + noticeLock.type = "2";
  278 + LockFeignResponse lockFeignResponse = lockFeignService.noticeLock(noticeLock);
  279 + log.info("[LOCK-API-RSP]-关锁通知接口返回,code:{},message:{},success:{}",lockFeignResponse.code,lockFeignResponse.message,lockFeignResponse.success);
  280 + record(info,false,"关锁解封通知中,等待下一步指令",null);
  281 + return true;
  282 + }
  283 + }
  284 + }else {
  285 + CommandClient.Client(info,"流转业务-未申请关锁号");
  286 + record(info,false,"业务异常:流转业务-未申请关锁号",null);
  287 + //这里需要返回true,是关锁业务,但是中断,不抬杆不放行,给予关锁业务异常通知
  288 + return true;
  289 + }
  290 + }
  291 + return false;
  292 + }
215 } 293 }
@@ -84,6 +84,25 @@ @@ -84,6 +84,25 @@
84 and TURNOVERFLAG = #{turnoverflag,jdbcType=VARCHAR} 84 and TURNOVERFLAG = #{turnoverflag,jdbcType=VARCHAR}
85 AND AISLEWT IS NOT NULL AND REMARK IS NOT NULL 85 AND AISLEWT IS NOT NULL AND REMARK IS NOT NULL
86 </select> 86 </select>
  87 + <select id="selectFirstLeave" parameterType="java.lang.String" resultType="java.lang.Integer">
  88 + select
  89 + count(BARCODE)
  90 + from land_businesstype_list
  91 + where
  92 + BARCODE = #{barcode,jdbcType=VARCHAR}
  93 + and TRAILER_FRAME_NO = #{trailerFrameNo,jdbcType=VARCHAR}
  94 + and TURNOVERFLAG = 'E'
  95 + and ISVALID = '1'
  96 + </select>
  97 + <select id="selectHistory" parameterType="java.lang.String" resultMap="BaseResultMap">
  98 + select
  99 + <include refid="Base_Column_List" />
  100 + from land_businesstype_list
  101 + where
  102 + BARCODE = #{barcode,jdbcType=VARCHAR}
  103 + and TRAILER_FRAME_NO = #{trailerFrameNo,jdbcType=VARCHAR}
  104 + and ISVALID = '1'
  105 + </select>
87 <update id="updateisvalid" parameterType="java.lang.String"> 106 <update id="updateisvalid" parameterType="java.lang.String">
88 update land_businesstype_list set ISVALID = '1' where 107 update land_businesstype_list set ISVALID = '1' where
89 TRAILER_FRAME_NO = #{trailerFrameNo,jdbcType=VARCHAR} 108 TRAILER_FRAME_NO = #{trailerFrameNo,jdbcType=VARCHAR}
@@ -44,6 +44,7 @@ @@ -44,6 +44,7 @@
44 <result column="ORGANIZATION_CODE" jdbcType="VARCHAR" property="organizationCode" /> 44 <result column="ORGANIZATION_CODE" jdbcType="VARCHAR" property="organizationCode" />
45 <result column="DECLARE_PERSONNEL_NUMBERS" jdbcType="VARCHAR" property="declarePersonnelNumbers" /> 45 <result column="DECLARE_PERSONNEL_NUMBERS" jdbcType="VARCHAR" property="declarePersonnelNumbers" />
46 <result column="MODE_TRANSPORTATION" jdbcType="VARCHAR" property="modeTransportation" /> 46 <result column="MODE_TRANSPORTATION" jdbcType="VARCHAR" property="modeTransportation" />
  47 + <result column="LOCK_NUM" jdbcType="VARCHAR" property="lockNum" />
47 </resultMap> 48 </resultMap>
48 <sql id="Base_Column_List"> 49 <sql id="Base_Column_List">
49 id, MASSAGE_ID, TRAILER_FRAME_NO, TRAILER_LICENSE_NO, MASTER_LIST, PRODECT_TIME, 50 id, MASSAGE_ID, TRAILER_FRAME_NO, TRAILER_LICENSE_NO, MASTER_LIST, PRODECT_TIME,
@@ -60,6 +61,13 @@ @@ -60,6 +61,13 @@
60 from land_list 61 from land_list
61 where id = #{id,jdbcType=VARCHAR} 62 where id = #{id,jdbcType=VARCHAR}
62 </select> 63 </select>
  64 + <select id="selectLockInfoByBarcode" parameterType="java.lang.String" resultMap="BaseResultMap">
  65 + select
  66 + LOCK_NUM
  67 + from land_list
  68 + where BARCODE = #{barcode,jdbcType=VARCHAR}
  69 + and ISVALID = '0'
  70 + </select>
63 <delete id="deleteByPrimaryKey" parameterType="java.lang.String"> 71 <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
64 delete from land_list 72 delete from land_list
65 where id = #{id,jdbcType=VARCHAR} 73 where id = #{id,jdbcType=VARCHAR}