GatherInfoHandleImpl.java
21.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
package com.sy.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sy.crossDomain.buildBarCode;
import com.sy.logic.LiftBar;
import com.sy.model.*;
import com.sy.service.*;
import com.sy.socket.CommandClient;
import com.sy.utils.FileTool;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import static com.sy.service.impl.ResMessageServiceImpl.toStrArry;
@Service("GatherInfoHandle")
public class GatherInfoHandleImpl implements GatherInfoService {
private static final Logger logger = LoggerFactory.getLogger(LiftBar.class);
//逻辑判断后的返回信息定义
private static String PERMITTHOUGH = "直接放行";
private static String GROWSSEXCETION = "禁止通行,重量不在可控范围";
private static String NORECORD = "车辆未备案或者识别错误,车牌号:";
private static String NO_CHEPAI = "未识别到车牌号:";
private static String INPUTSTATION = "此车辆未做进站申请";
private static String ENTERSTATION = "此车辆未做出站申请";
private static String ISVALID = "二维码数据异常,请使用正确的二维码数据";
private static String ERRORWT = "出起始场站的重量和进目的场站的重量不一致";
private static String IEPORSE = "无相对应进出场申请";
private static String FANGXING= "有运单未放行";
private static String FENBO = "装载运单的分拨申请舱单未通过校验";
private static String NOGrossWt = "过磅重量异常";
private static String BLACKLIST= "此车辆已被拉进黑名单,不允许出区";
@Autowired
FeignService feignService;
@Autowired
NmmsService nmmsService;
/**
* 车辆信息备案表
*/
@Autowired
LandRoadVeService veService;
@Autowired
RedisService redisService;
@Autowired
BusnesslistinfoService busnesslistinfoService;
/**
* 进出场申请表
*/
@Autowired
LandBusListService listService;
/**
* 重量校验算法
*/
@Autowired
WeightCheckHandleService weightCheckHandleService;
/**
* 查询运单放行表
*/
@Autowired
ResMessageService resMessageService;
@Autowired
CommandLogService commandLogService;
/**
* 车辆过卡信息
*/
private GatherInfo info;
/**
* 车辆流转申请表头信息
*/
private LandBusinessTypeList landBusinessTypeList;
private List<LandBusinessTypeList> landBusinessTypeListList;
/**
* 车辆申请表体信息
*/
private List<LAND_BUSINEESTYPE_LIST_INFO> listinfos;
/**
* 过磅重量
*/
private double growssWt=0.0;
/**
* 车牌号
*/
private String vaName;
/**
* 车辆备案重量
*/
private double selfWt=0.0;
/**
* 初始化装载货物重量
*/
private double goodsWt=0.0;
/**
* 车辆入场时的重量
*/
private double inWt=0.0;
/**
* 计算后的车辆进出场差值
*/
private double diffVal=0.0;
@Override
public int save(GatherInfo info) {
return 0;
}
@Override
public void handel(GatherInfo gatherInfo) {
this.info = gatherInfo;
//获取过磅重量
growssWt = info.getGrosswt().doubleValue();
//取车牌号,判定卡口是否取到车牌号
vaName = info.getVename();
}
/**
* 一.
* 场站白名单
* @return 白名单 true. 其他走校验
*/
private boolean areaWhiteListCheck(){
if(FileTool.readProperties("stationsf").equals(info.getAreaid())) {
return true;
}
return false;
}
/**
* 1. 车牌信息校验
*/
private boolean veNameCheck(String veName){
//1. 若无车牌号,返回未识别错误
if (StringUtils.isEmpty(vaName)) {
logger.error(NO_CHEPAI+vaName);
sendBw(info,false,NO_CHEPAI + vaName,new LandBusinessTypeList(),listinfos);
//CommandClient.Client(info, NO_CHEPAI + vaName);
return false;
}
return true;
}
/**
* 2. 车辆备案信息校验
*/
private boolean veRecordCheck(){
//2. 校验车辆是否备案
LandRoadVe ve = veService.selectByFrameNo(vaName);
//若无备案信息或者黑名单,返回车辆未备案或者识别错误,
if (ve == null && !veBlackListCheck(ve)) {
logger.error(NORECORD+vaName);
sendBw(info,false,NORECORD + vaName,new LandBusinessTypeList(),listinfos);
//CommandClient.Client(info, NORECORD + vaName);
return false;
}
//车辆备案重量
selfWt=Double.parseDouble(ve.getSelfWt());
return true;
}
/**
* 3. 车辆黑名单校验
*/
private boolean veBlackListCheck(LandRoadVe ve){
if("Y".equals(ve.getVeState())){
sendBw(info,false,BLACKLIST + vaName,new LandBusinessTypeList(),listinfos);
return false;
}
return true;
}
/**
* 4. 车辆进出场流转申请单信息校验
* 二维码不用校验了,二维码失效会删除redis缓存
* @return
*/
private boolean LandBusinessFormCheck(){
try {
//通过车牌号,二维码,场站,通道号,进出类型查询进出场站申请列表
String landBusinessJson = redisService.get(info.getVename());
List<LandBusinessTypeList> list = new ArrayList<>();
if (StringUtils.isNotEmpty(landBusinessJson)){
list = (List<LandBusinessTypeList>) JSON.parseObject(landBusinessJson,List.class);
landBusinessTypeListList = list;
//4. 若查询结果为null,返回无相对应进出场申请
if (list == null || list.isEmpty()) {
logger.error(vaName+IEPORSE);
sendBw(info,false,vaName+IEPORSE,null,listinfos);
return false;
}
list.stream()
.filter( item->{
if (item.getAisle().equals(info.getChnlno()) && item.getBarcode().equals(info.getBarcode())){
landBusinessTypeList = item;
//离场装载货物重量
goodsWt = Double.parseDouble(landBusinessTypeList.getRemark());
return true;
}else {
return false;
}
});
}else {
logger.error("未找到车辆-{}的申请缓存信息",info.getVename());
logger.info("未找到车辆-{}的申请缓存信息,或者流转已超期失效",info.getVename());
}
}catch (Exception e){
return false;
}
return true;
}
/**
* 流转申请-货物类型白名单,白名单的货物类型目前直接放行
* @return
*/
private boolean goodsWhiteListCheck(){
if(!"普通货物".equals(landBusinessTypeList.getCocode())
&& !"转关货物".equals(landBusinessTypeList.getCocode())
&& !"退库货物".equals(landBusinessTypeList.getCocode()) ) {
//todo:比如货物类型为快件货物,只走重量校验,不走放行信息等校验.
//todo:退库货物可以关联货运系统,得到退库信息进行比对
//todo:查验货物走查验信息比对
//todo:快件暂不校验直接放行,不过得录单
//todo:换单货物校验逻辑待定
//todo:未来取消货物类型判定.
logger.info("车辆装载货物为:" + landBusinessTypeList.getCocode());
return true;
}
return false;
}
/**
* 5. 车辆过磅重量校验
* @return true 通过 false 不通过
*/
private boolean weightCheck(GatherInfo info){
if(info.getGrosswt().compareTo(BigDecimal.ZERO) > 0){
logger.info("过磅重量校验通过,过磅重量大于0");
}else{
sendBw(info,false,NOGrossWt + growssWt,new LandBusinessTypeList(),listinfos);
return false;
}
return true;
}
/**
* 离场时需要获取的车辆进场信息,入场重量,进出场差值
*/
private void inStationInfo(){
List<LandBusinessTypeList> stationInChanleInfo= listService.selectwt(info.getVename(),info.getBarcode(),info.getAreaid(),"I");
if (stationInChanleInfo.isEmpty()){
logger.info("未查询到车辆:{}的入场信息",info.getVename());
}else {
for(LandBusinessTypeList typeList:stationInChanleInfo){
if(typeList.getAislewt()!=null){
//对应场站进场过磅重量
inWt=typeList.getAislewt();
}
diffVal = inWt- growssWt;
}
//TODO:进场校验 增加 车辆备案重量要 <= 进场过磅重量 ,要有误差判定
}
}
/**
* 此通道对应的流转申请货物重量.
*/
private void setGoodsWt(LandBusinessTypeList list){
}
/**
* todo:通道及金二路由判定,是金二通道的话,等金二X22
* 目前宽进严出策略,本地判定
*
*/
private boolean chanelInCheck(){
if ("I".equals(info.getIetype())){
return true;
}else {
return false;
}
}
/**
* 设置表体全局变量
*/
private void setListinfos(){
//查询运单列表
listinfos=busnesslistinfoService.selectmanilist(info.getBarcode());
}
/**
* 出区抬杆放行判定
* @return
*/
private boolean checkRelease(){
logger.info("[进出场申请]-业务类型为:"+landBusinessTypeList.getCocode()+landBusinessTypeList.getBusinesstype());
switch (landBusinessTypeList.getBusinesstype()){
case "空车业务":
if(weightCheckHandleService.checkEmpty(growssWt,selfWt)){
return true;
}else{
logger.error("[空车业务]-出场重量未通过校验:"+GROWSSEXCETION);
sendBw(info,false,GROWSSEXCETION,landBusinessTypeList,listinfos);
return false;
}
case "出口转关":
case "出口送货":
if (weightCheckHandleService.checkExportDownLoading(growssWt, selfWt, goodsWt,inWt)){
return true;
}else{
logger.error("[出口送货]-出场重量未通过校验:"+GROWSSEXCETION);
sendBw(info,false,GROWSSEXCETION,landBusinessTypeList,listinfos);
return false;
}
case "进口转关":
case "进口提货":
if (weightCheckHandleService.checkImportDlv(growssWt, selfWt, goodsWt,inWt)){
if ("退库货物".equals(landBusinessTypeList.getCocode())){
/**
* 退库货物不校验运单放行.
*/
logger.info("[退库业务]-重量核验通过.");
}else{
//检查运单放行
if (resMessageService.checkManifestRelease(info,listinfos)){
return true;
}else {
//有运单未放行
logger.error("[进口提货]-出场未通过校验:"+FANGXING+landBusinessTypeList.getMasterList());
sendBw(info,false,FANGXING+landBusinessTypeList.getMasterList(),landBusinessTypeList,listinfos);
return false;
}
}
//todo:装载运单历史数据累加超重判定
}else{
logger.error("[进口提货]-出场重量未通过校验:"+GROWSSEXCETION);
sendBw(info,false,GROWSSEXCETION,landBusinessTypeList,listinfos);
return false;
}
break;
case "分拨业务":
if (weightCheckHandleService.checkAllocateOrDispatch(growssWt, selfWt, goodsWt,inWt)){
//todo:检查分拨申请
boolean allocatCheck = checkNmmsAllocate(landBusinessTypeList.getMasterList());
if(!allocatCheck){
logger.error("[分拨业务]-分拨申请舱单未通过校验:"+FENBO);
sendBw(info,false,FENBO,landBusinessTypeList,listinfos);
return false;
}
return true;
//todo:分拨运抵通知,重车入场视为运抵
}else{
logger.error("[分拨业务]-出场重量未通过校验:"+GROWSSEXCETION);
sendBw(info,false,GROWSSEXCETION,landBusinessTypeList,listinfos);
return false;
}
case "调拨业务":
if (weightCheckHandleService.checkAllocateOrDispatch(growssWt, selfWt, goodsWt,inWt)){
//检查运单放行
if (resMessageService.checkManifestRelease(info,listinfos)){
return true;
}else {
//有运单未放行
logger.error("[调拨业务]-出场未通过校验:"+FANGXING+landBusinessTypeList.getMasterList());
sendBw(info,false,FANGXING,landBusinessTypeList,listinfos);
return false;
}
//todo:检查ULD放行.
}else{
logger.error("[调拨业务]-出场未通过校验:"+GROWSSEXCETION);
sendBw(info,false,GROWSSEXCETION,landBusinessTypeList,listinfos);
return false;
}
default:
logger.error("[未知业务类型]-出场未通过校验");
break;
}
return false;
}
/**
* 记录进出区信息
*/
private void record(){
if ("I".equals(info.getIetype())){
landBusinessTypeList.setAislewt(info.getGrosswt().doubleValue());
landBusinessTypeList.setUpdateDate(new Date());
landBusinessTypeList.setRemark(String.format("%.1f", goodsWt));
//车辆备案重量
landBusinessTypeList.setRemark2(String.valueOf(selfWt));
landBusinessTypeList.setContrastflag("已进站");
}else {
landBusinessTypeList.setAislewt(info.getGrosswt().doubleValue());
landBusinessTypeList.setUpdateDate(new Date());
//装载货物总重量
landBusinessTypeList.setRemark(String.format("%.1f", goodsWt));
//进出差值
landBusinessTypeList.setRemark1(String.format("%.1f", diffVal));
landBusinessTypeList.setRemark2(String.valueOf(selfWt));
landBusinessTypeList.setContrastflag("已出站");
}
//todo:判定放行后,插入数据库,出入区记录
landBusinessTypeList.setId(UUID.randomUUID().toString());
landBusinessTypeList.setIsvalid("1");
//todo:这里SEQN也要入库
listService.saveList(landBusinessTypeList);
}
/**
* 流转申请是否核销判定
*/
private void releaseFormCheck(){
//二维码已出区的记录
List<LandBusinessTypeList> havenCrossList = listService.selectByBarcodeWithE(info.getBarcode());
//申请核销判定
for (LandBusinessTypeList businessTypeList : havenCrossList) {
List<LandBusinessTypeList> r = landBusinessTypeListList.stream().filter(item ->{
if(item.getEndstation().equals(businessTypeList.getEndstation())) {
landBusinessTypeListList.remove(item);
return true;
}else {
return false;
}
})
.collect(Collectors.toList());
}
if (landBusinessTypeListList.isEmpty()){
//todo:流转申请状态核销
//二维码核销
releaseBarCode();
}
}
/**
* 二维码失效核销->判定及失效通知.
*/
private void releaseBarCode(){
//二维码判定
int count=listService.selectlaststation(info.getVename(),info.getBarcode());
//二维码失效通知,已进入场站的与缓存比较.
if(count==0){
//todo:测试注释掉,二维码释放
logger.info("[进出场申请]-二维码释放:"+vaName);
buildBarCode.cancleBarCode(vaName);
}
}
/**
* todo:车单关系绑定报文
*/
/**
* 发送X22指令
* @param info
* @param check
* @param reason
* @param land
* @param list_infos
* @return
*/
public boolean sendBw(GatherInfo info, boolean check, String reason, LandBusinessTypeList land, List<LAND_BUSINEESTYPE_LIST_INFO> list_infos) {
logger.info(String.format("开始发送指令:车牌%s,场站%s,通道%s,重量%s",info.getVename(),info.getAreaid(),info.getChnlno(),info.getGrosswt()));
boolean flag = false;
if (check) {
CommandClient.Client(info, PERMITTHOUGH);
logger.info("=============>>>>>>>>放行报文发送成功<<<<<<<<<==============");
flag = true;
} else {
CommandClient.Client(info, reason);
logger.info("=============>>>>>>>>重量异常报文发送成功<<<<<<<<<==============");
}
commandlog(info,check,reason,land,list_infos);
return flag;
}
/**
* 放行日志记录
* @param info
* @param check
* @param reason
* @param land
* @param list_infos
*/
public void commandlog(GatherInfo info,boolean check,String reason,LandBusinessTypeList land,List<LAND_BUSINEESTYPE_LIST_INFO> list_infos){
String flag="",type="";
commandLog command=new commandLog();
command.setId(UUID.randomUUID().toString());
command.setBarcode(info.getBarcode());
if(land!=null){
command.setBarcode(land.getBarcode());
command.setBusnessType(land.getBusinesstype());
}
command.setAreaId(info.getAreaid());
command.setChnlNo(info.getChnlno());
if (check){
flag = "00";
} else{
flag = "11";
}
if("I".equals(info.getIetype())){
type="000000200000000000";
}else{
type="000000100000000000";
}
command.setReasonCode(flag+type);
command.setReasonText(reason);
command.setVeName(info.getVename());
command.setVeWeight(selfWt);
command.setIeType(info.getIetype());
command.setExitGrossWeight(info.getGrosswt().doubleValue());
command.setInGrossWeight(inWt);
command.setGoodsWeight(goodsWt);
command.setActualGoodsWeight(diffVal);
if(list_infos.size()>0){
command.setMasterList(Arrays.toString(toStrArry(list_infos)));
}
commandLogService.insert(command);
}
/**
* 新舱单分拨申请数据查询
* @param waybill 查询的运单号
* @return
*/
private Map nmmsAllocate(@NotNull String waybill){
logger.info("新舱单查询分拨申请数据开始");
Feign_Allocate_Search feignAllocateSearch = new Feign_Allocate_Search(waybill,0,10);
Map map = nmmsService.getAllocate(feignAllocateSearch);
logger.info(""+map);
return map;
}
/**
* 分拨申请查询
* @param waybill
* @return
*/
private boolean checkNmmsAllocate(String waybill){
if (waybill.length() < 1) {
return false;
}
waybill = waybill.replace("-", "");
//中文逗号替换
waybill = waybill.replace(",", ",");
String[] maifest = waybill.split(",");
logger.info("运单列表:" + waybill);
boolean flag = false;
for (String awb : maifest) {
Map map= nmmsAllocate(awb);
if (map.containsKey("reslut")){
String result = map.get("reslut").toString();
JSONObject jsonObject = JSON.parseObject(result);
if (jsonObject.containsKey("ds")) {
JSONArray ds = jsonObject.getJSONArray("ds");
JSONObject awbinfo = ds.getJSONObject(0);
if (awbinfo.containsKey("RECEIPTINFORMATION")){
if (awbinfo.getString("RECEIPTINFORMATION").contains("39301") || awbinfo.getString("RECEIPTINFORMATION").contains("39103")){
logger.info("运单:{},分拨回执查询结果:{}",awb,awbinfo.getString("RECEIPTINFORMATION"));
}else {
logger.info("运单{}分拨申请回执不正常:{}",awb,awbinfo.getString("RECEIPTINFORMATION"));
return false;
}
}
}else {
logger.info("运单:{}分拨申请回执未查询到,或未进行分拨申请",awb);
return false;
}
}else{
logger.info("运单:{}分拨申请回执未查询到,或未进行分拨申请",awb);
return false;
}
}
return true;
}
}