ArriveMasterServiceImpl.java
11.7 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
package com.tianbo.analysis.service.imp;
import com.tianbo.analysis.dao.*;
import com.tianbo.analysis.model.*;
import com.tianbo.analysis.service.ArriveMasterService;
import com.tianbo.analysis.tools.WaybillTools;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@Service
@Slf4j
public class ArriveMasterServiceImpl implements ArriveMasterService {
@Resource
PREPAREMASTERMapper preparemasterMapper;
@Resource
PREPARESECONDARYMapper preparesecondaryMapper;
@Resource
ARRIVEDMASTERMapper arrivedmasterMapper;
@Resource
ARRIVEDSECONDARYMapper arrivedsecondaryMapper;
@Resource
SENDLOGMapper sendlogMapper;
@Override
public boolean arrivedAhead(AdvanceArrive carAndWayBill) {
try {
/**
* 根据运单列表,与预配核碰提前运抵货物。
*/
List<LAND_BUSINEESTYPE_LIST_INFO> waybillList = carAndWayBill.getMasterList();
if (!waybillList.isEmpty()){
log.info("接收到通知车辆{}拉货数据{}条",carAndWayBill.getVname(),carAndWayBill.getMasterList().size());
for (LAND_BUSINEESTYPE_LIST_INFO waybillmasterInfo : waybillList) {
String waybillmaster = waybillmasterInfo.getAwba();
log.info("开始核对运单{}",waybillmaster);
/**
* 校验运单格式,要为172-66666666,中间有减号的才行
* 校验不通过的属于17288888888这种格式的给他加个-号再处理
*/
if (!WaybillTools.checkWaybillFormat(waybillmaster)) {
log.info("处理{}运单格式",waybillmaster);
waybillmaster = WaybillTools.awbFormat(waybillmaster);
}
/**
* 找提前运抵预配
* 这里注意,同一个预配有可能多发,所以有重复。
* 这里目前只取回执状态为04以及提前运抵为Y的预配主单
*/
List<PREPAREMASTER> preparemasterList = preparemasterMapper.selectArrivedAheadByWaybillNo(waybillmaster);
/**
* 判断是否为空
* 有多个符合条件的预配只取最新的第一个
*/
if (!preparemasterList.isEmpty()) {
PREPAREMASTER preparemasterFirst = preparemasterList.get(0);
log.info("查到提前运抵运单:{}", preparemasterFirst.getWaybillnomaster());
importFromPreplan(preparemasterFirst);
}else {
log.info("运单{}不属于提前运抵运单", waybillmaster);
}
}
return true;
}
return false;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
@Override
public boolean importFromPreplan(@NotNull PREPAREMASTER preparemasterFirst) {
try {
//共用入库主键
String id = UUID.randomUUID().toString();
/**
* 根据主单号判断是否有预配分单。
*/
List<PREPARESECONDARY> preparesecondaryList = preparesecondaryMapper.selectByMasterKey(preparemasterFirst.getAutoid());
/**
* 根据预配生成运抵数据
* 生成规则,有运抵数据则不生,无运抵数据才生。
*/
if (preparesecondaryList.isEmpty()) {
log.info("运单{}预配没有分单,开始生成主单运抵",preparemasterFirst.getWaybillnomaster());
/**
* 预配没分单,直接生成主单运抵
*/
ARRIVEDMASTER arrivedmaster = new ARRIVEDMASTER();
arrivedmaster.setAutoid(id);
arrivedmaster.setArrivedAhead("Y");
arrivedmaster.setTcdName("Air Waybill");
arrivedmaster.setTcdTypecode("741");
arrivedmaster.setoName("ZHENGZHOU");
arrivedmaster.setGrossweightmeasureuc("KGM");
arrivedmaster.setTotalgrossweightmeasureuc("KGM");
arrivedmaster.setChargeableweightmeasureuc("KGM");
arrivedmaster.setTransportsplitdescription("T");
arrivedmaster.setStatus("01");
arrivedmaster.setCreatedate(new Date());
arrivedmaster.setWaybillnomaster(preparemasterFirst.getWaybillnomaster());
arrivedmaster.setFlightno(preparemasterFirst.getFlightno());
arrivedmaster.setFlightdate(preparemasterFirst.getFlightdate());
arrivedmaster.setCarrier(preparemasterFirst.getCarrier());
arrivedmaster.setOriginatingstation(preparemasterFirst.getOriginatingstation());
arrivedmaster.setDestinationstation(preparemasterFirst.getDestinationstation());
arrivedmaster.setArrivedtotalpiece(preparemasterFirst.getTotalpiece());
arrivedmaster.setTotalpiecequantity(preparemasterFirst.getTotalpiece());
arrivedmaster.setArrivedtotalweight(preparemasterFirst.getTotalweight());
arrivedmaster.setTotalgrossweightmeasure(preparemasterFirst.getTotalweight());
arrivedmaster.setChargeableweightmeasure(preparemasterFirst.getTotalweight());
arrivedmaster.setArriveddate(new Date());
arrivedmaster.setCustomscode(preparemasterFirst.getCustomscode());
arrivedmaster.setProductname(preparemasterFirst.getProductname());
//查重 根据运单号,有运抵数据则不插入也不更新了,说明已经产生过业务
List<ARRIVEDMASTER> arrivedmasterList = arrivedmasterMapper.selectByWaybillNo(preparemasterFirst.getWaybillnomaster());
if (arrivedmasterList.isEmpty()) {
int i = arrivedmasterMapper.insertSelective(arrivedmaster);
log.info("已插入提前运抵数据:{},运单号为{}", i, arrivedmaster.getWaybillnomaster());
}else {
log.info("运单{}已存在运抵数据,不再提前生成运抵信息",preparemasterFirst.getWaybillnomaster());
}
} else {
//根据分单预配生成分单运抵
for (PREPARESECONDARY preparesecondary : preparesecondaryList) {
log.info("运单{}预配含有分单,生成分单运抵",preparemasterFirst.getWaybillnomaster());
String id_slave = UUID.randomUUID().toString();
ARRIVEDSECONDARY arrivedsecondary = new ARRIVEDSECONDARY();
arrivedsecondary.setAutoid(id_slave);
arrivedsecondary.setWaybillnomaster(preparesecondary.getWaybillnomaster());
arrivedsecondary.setWaybillnosecondary(preparesecondary.getWaybillnosecondary());
arrivedsecondary.setCarrier(preparesecondary.getCarrier());
arrivedsecondary.setoId(preparesecondary.getOriginatingstation());
arrivedsecondary.setFdId(preparesecondary.getDestinationstation());
arrivedsecondary.setFlightno(preparesecondary.getFlightno());
arrivedsecondary.setFlightdate(preparesecondary.getFlightdate());
arrivedsecondary.setArrivedtotalpiece(preparesecondary.getTotalpiece());
arrivedsecondary.setArrivedtotalweight(preparesecondary.getTotalweight());
arrivedsecondary.setTotalpiecequantity(preparesecondary.getTotalpiece());
arrivedsecondary.setTotalgrossweightmeasure(preparesecondary.getTotalweight());
arrivedsecondary.setChargeableweightmeasure(preparesecondary.getTotalweight());
arrivedsecondary.setArriveddate(new Date());
arrivedsecondary.setCustomscode(preparesecondary.getCustomscode());
arrivedsecondary.setProductname(preparesecondary.getProductname());
arrivedsecondary.setCreatedate(new Date());
arrivedsecondary.setArrivedmasterid("");
arrivedsecondary.setStatus("01");
arrivedsecondary.setTcdName("Air Waybill");
arrivedsecondary.setTcdTypecode("741");
arrivedsecondary.setoName("ZHENGZHOU");
//查重 根据运单号,有运抵数据则不插入也不更新了,说明已经产生过业务
List<ARRIVEDSECONDARY> arrivedsecondaryList = arrivedsecondaryMapper.selectByWaybillNo(arrivedsecondary);
if (arrivedsecondaryList.isEmpty()) {
int i = arrivedsecondaryMapper.insertSelective(arrivedsecondary);
log.info("已插入提前运抵数据,插入数量:{},运单号为{}_{}", i, arrivedsecondary.getWaybillnomaster(), arrivedsecondary.getWaybillnosecondary());
/**
* 插入日志。
*/
if (i > 0) {
SENDLOG sendlog = new SENDLOG();
sendlog.setAutoid(id_slave);
sendlog.setCreatedate(new Date());
sendlog.setMessageautoid(id_slave);
sendlog.setOpauthor("提前运抵");
sendlog.setSendpeice(Long.parseLong(preparesecondary.getTotalpiece()));
sendlog.setSendweight(new BigDecimal(preparesecondary.getTotalweight()));
sendlog.setReceiption("SYSTEM 提前运抵生成");
sendlog.setMessagetype("MT3201");
sendlogMapper.insertSelective(sendlog);
log.info("分单生成日志已记录");
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
@Override
public int updatePremasterArrivedHeadStatus(AdvanceArrive preArrivedWaybillList) {
log.info("接收到来自卡口申请的拉货列表通知");
if (!preArrivedWaybillList.getMasterList().isEmpty()){
int m = 0;
for (LAND_BUSINEESTYPE_LIST_INFO waybillnomaster: preArrivedWaybillList.getMasterList() ) {
String waybillNo = waybillnomaster.getAwba();
log.info("开始处理列表中的运单号:[{}]",waybillNo);
if ("1".equals(waybillnomaster.getArrivedaheadtime())){
log.info("运单号{}识别为提前运抵业务,即将增加数据标识",waybillNo);
PREPAREMASTER preparemaster = new PREPAREMASTER();
preparemaster.setWaybillnomaster(waybillNo);
preparemaster.setArrivedAhead("Y");
int i = preparemasterMapper.updatePreArrivedBill(preparemaster);
if (i > 0) {
log.info("运单号{}的预配提前运抵标识增加成功", waybillNo);
} else {
log.info("ERROR :未找到相关预配信息, 运单号{}的预配提前运抵标识增加失败!!!", waybillNo);
}
m =+ i;
}
}
return m;
}
return 0;
}
}