MawbService.java
16.6 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
package com.erry.iclear.dateInterface.service;
import com.erry.iclear.dateInterface.api.request.FedexMawb;
import com.erry.iclear.dateInterface.api.request.FedexMawbDetail;
import com.erry.iclear.dateInterface.api.request.Mawb;
import com.erry.iclear.dateInterface.api.request.MawbDetail;
import com.erry.iclear.dateInterface.api.response.IClearCheckResult;
import com.erry.iclear.dateInterface.api.response.ResultRS;
import com.erry.iclear.dateInterface.common.Constant;
import com.erry.iclear.dateInterface.entity.ChmConsignment;
import com.erry.iclear.dateInterface.entity.ChmConsignmentDetail;
import com.erry.iclear.dateInterface.entity.DictionaryEntries;
import com.erry.iclear.dateInterface.enums.ErrorCodeEnum;
import com.erry.iclear.dateInterface.repository.DictionaryEntriesRepository;
import com.erry.iclear.dateInterface.repository.MawbRepository;
import com.erry.iclear.dateInterface.util.HttpUtils;
import com.erry.iclear.dateInterface.util.JsonToJava;
import com.erry.iclear.dateInterface.util.StringUtil;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* @author Administrator
*/
@Service
@Slf4j
public class MawbService {
private Gson gson = new Gson();
@Value("${api.address.iclear-check-url}")
String iclearCheckUrl;
@Autowired
private MawbRepository mawbRepository;
@Autowired
private ChmConsignmentService consignmentService;
@Autowired
private ChmConsignmentDetailService consignmentDetailService;
@Autowired
private DictionaryEntriesRepository dictionaryEntriesRepository;
/**
* 保存主单Request
* @param mawb
*/
public Map<String,String> saveMawb(Mawb mawb){
Map<String,String> map = new HashMap<>();
try{
log.info("saveMawb start>>>>>>>>>>>");
Mawb mawb1 = mawbRepository.save(mawb);
log.info("saveMawb end>>>>>>>>>>>");
map.put("success","true");
map.put("msg",mawb1.getMsgId().toString());
}catch (Exception e){
log.error("saveMawb() error:"+e.getMessage());
map.put("success","false");
map.put("msg",e.getMessage());
}
return map;
}
public String checkMawbBaseInfo(Mawb mawb){
if(StringUtil.isEmpty(mawb.getOverseasConsigneeEname())){
return "参数overseasConsigneeEname不能为空";
}
// if(StringUtil.isEmpty(mawb.getEntyPortCode())){
// return "参数entyPortCode不能为空";
// }
if(StringUtil.isEmpty(mawb.getOwnerCodeScc())){
return "参数ownerCodeScc不能为空";
}
if(StringUtil.isEmpty(mawb.getTradeCodeScc())){
return "参数tradeCodeScc不能为空";
}
if(StringUtil.isEmpty(mawb.getTransMode())){
return "参数transMode不能为空";
}
if(StringUtil.isEmpty(mawb.getWrapType())){
return "参数wrapType不能为空";
}
if(StringUtil.isEmpty(mawb.getTradeName())){
return "参数tradeName不能为空";
}
// if(StringUtil.isEmpty(mawb.getInsurCurr())){
// return "参数insurCurr不能为空";
// }
if(StringUtil.isEmpty(mawb.getIePort())){
return "参数iePort不能为空";
}
// if(StringUtil.isEmpty(mawb.getFeeMark())){
// return "参数feeMark不能为空";
// }
// if(StringUtil.isEmpty(mawb.getFeeCurr())){
// return "参数feeCurr不能为空";
// }
// if(StringUtil.isEmpty(mawb.getEdiId())){
// return "参数ediId不能为空";
// }
if(StringUtil.isEmpty(mawb.getDistinatePort())){
return "参数distinatePort不能为空";
}
// if(StringUtil.isEmpty(mawb.getDeclTrnRel())){
// return "参数declTrnRel不能为空";
// }
if(StringUtil.isEmpty(mawb.getCutMode())){
return "参数cutMode不能为空";
}
if(StringUtil.isEmpty(mawb.getCustomMaster())){
return "参数customMaster不能为空";
}
if(StringUtil.isEmpty(mawb.getBillNo())){
return "参数billNo不能为空";
}
if(StringUtil.isEmpty(mawb.getAgentName())){
return "参数agentName不能为空";
}
if(StringUtil.isEmpty(mawb.getAgentCode())){
return "参数agentCode不能为空";
}
List<MawbDetail> mawbDetailList = mawb.getMawbDetailList();
if(Objects.nonNull(mawbDetailList)){
for (int i = 0, maxi = mawbDetailList.size(); i < maxi; i++) {
MawbDetail mawbDetail = mawbDetailList.get(i);
if(StringUtil.isEmpty(mawbDetail.getDetailId())){
return "参数detailId不能为空";
}
if(StringUtil.isEmpty(mawbDetail.getCodeTS())){
return "参数codeTS不能为空";
}
if(StringUtil.isEmpty(mawbDetail.getDutyMode())){
return "参数dutyMode不能为空";
}
if(StringUtil.isEmpty(mawbDetail.getFirstUnit())){
return "参数firstUnit不能为空";
}
if(StringUtil.isEmpty(mawbDetail.getGunit())){
return "参数gunit不能为空";
}
if(StringUtil.isEmpty(mawbDetail.getGmodel())){
return "参数gmodel不能为空";
}
if(StringUtil.isEmpty(mawbDetail.getGname())){
return "参数gname不能为空";
}
if(StringUtil.isEmpty(mawbDetail.getGno())){
return "参数gno不能为空";
}
if(StringUtil.isEmpty(mawbDetail.getOriginCountry())){
return "参数originCountry不能为空";
}
if(StringUtil.isEmpty(mawbDetail.getTradeCurr())){
return "参数tradeCurr不能为空";
}
if(StringUtil.isEmpty(mawbDetail.getDestinationCountry())){
return "参数destinationCountry不能为空";
}
if(StringUtil.isEmpty(mawbDetail.getDistrictCode())){
return "参数districtCode不能为空";
}
}
}
return "";
}
/**
* 检查成交币制在系统中是否有效 Constant.CURRENCY_SYSTEM+ mawbDetail.getTradeCurr();
* 成交币制 TradeCurr
* 杂费币制 OtherCurr
* 运费币制 FeeCurr
* 保费币制 InsurCurr
*
*/
public ResultRS checkCurrency(Mawb mawb){
ResultRS result = new ResultRS(Boolean.TRUE,null,null,null);
String feeCurr = mawb.getFeeCurr();
DictionaryEntries feeCurrDict = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM + feeCurr);
String otherCurr = mawb.getOtherCurr();
DictionaryEntries otherCurrDict = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM + otherCurr);
String insurCurr = mawb.getInsurCurr();
DictionaryEntries insurCurrDict = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM + insurCurr);
//运费币制检查
if (StringUtils.isNotEmpty(feeCurr) && Objects.isNull(feeCurrDict) ){
result.setSuccess(Boolean.FALSE);
result.setCode(ErrorCodeEnum.ERROR_30106.getCode());
result.setMsg(ErrorCodeEnum.ERROR_30106.getName().replace("{columnName}","运费"));
return result;
}
//杂费币制检查
if (StringUtils.isNotEmpty(otherCurr) && Objects.isNull(otherCurrDict) ){
result.setSuccess(Boolean.FALSE);
result.setCode(ErrorCodeEnum.ERROR_30106.getCode());
result.setMsg(ErrorCodeEnum.ERROR_30106.getName().replace("{columnName}","杂费"));
return result;
}
//保费币制检查
if (StringUtils.isNotEmpty(insurCurr) && Objects.isNull(insurCurrDict) ){
result.setSuccess(Boolean.FALSE);
result.setCode(ErrorCodeEnum.ERROR_30106.getCode());
result.setMsg(ErrorCodeEnum.ERROR_30106.getName().replace("{columnName}","保费"));
return result;
}
//申报币制检查
List<MawbDetail> mawbDetailList = mawb.getMawbDetailList();
for (int i = 0, maxi = mawbDetailList.size(); i < maxi; i++) {
MawbDetail mawbDetail = mawbDetailList.get(i);
String tradeCurr = mawbDetail.getTradeCurr();
DictionaryEntries tradeCurrDict = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM + tradeCurr);
if((StringUtils.isNotEmpty(tradeCurr) && Objects.isNull(tradeCurrDict))){
result.setSuccess(Boolean.FALSE);
result.setCode(ErrorCodeEnum.ERROR_30106.getCode());
result.setMsg(ErrorCodeEnum.ERROR_30106.getName().replace("{columnName}",""));
break;
}
}
return result;
}
/**
* 检查成交币制在系统中是否有效 Constant.CURRENCY_SYSTEM+ mawbDetail.getTradeCurr();
* 成交币制 TradeCurr
* 杂费币制 OtherCurr
* 运费币制 FeeCurr
* 保费币制 InsurCurr
*
*/
public ResultRS checkCurrency(FedexMawb mawb){
ResultRS result = new ResultRS(Boolean.TRUE,null,null,null);
String feeCurr = mawb.getFeeCurr();
DictionaryEntries feeCurrDict = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM + feeCurr);
String otherCurr = mawb.getOtherCurr();
DictionaryEntries otherCurrDict = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM + otherCurr);
String insurCurr = mawb.getInsurCurr();
DictionaryEntries insurCurrDict = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM + insurCurr);
//运费币制检查
if (StringUtils.isNotEmpty(feeCurr) && Objects.isNull(feeCurrDict) ){
result.setSuccess(Boolean.FALSE);
result.setCode(ErrorCodeEnum.ERROR_30106.getCode());
result.setMsg(ErrorCodeEnum.ERROR_30106.getName().replace("{columnName}","运费"));
return result;
}
//杂费币制检查
if (StringUtils.isNotEmpty(otherCurr) && Objects.isNull(otherCurrDict) ){
result.setSuccess(Boolean.FALSE);
result.setCode(ErrorCodeEnum.ERROR_30106.getCode());
result.setMsg(ErrorCodeEnum.ERROR_30106.getName().replace("{columnName}","杂费"));
return result;
}
//保费币制检查
if (StringUtils.isNotEmpty(insurCurr) && Objects.isNull(insurCurrDict) ){
result.setSuccess(Boolean.FALSE);
result.setCode(ErrorCodeEnum.ERROR_30106.getCode());
result.setMsg(ErrorCodeEnum.ERROR_30106.getName().replace("{columnName}","保费"));
return result;
}
//申报币制检查
List<FedexMawbDetail> mawbDetailList = mawb.getMawbDetailList();
for (int i = 0, maxi = mawbDetailList.size(); i < maxi; i++) {
FedexMawbDetail mawbDetail = mawbDetailList.get(i);
String tradeCurr = mawbDetail.getTradeCurr();
DictionaryEntries tradeCurrDict = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM + tradeCurr);
if((StringUtils.isNotEmpty(tradeCurr) && Objects.isNull(tradeCurrDict))){
result.setSuccess(Boolean.FALSE);
result.setCode(ErrorCodeEnum.ERROR_30106.getCode());
result.setMsg(ErrorCodeEnum.ERROR_30106.getName().replace("{columnName}",""));
break;
}
}
return result;
}
/**
* 校验主单
* @param mawb
* @return
*/
public ResultRS checkMawb(Mawb mawb,String appId){
ResultRS result = new ResultRS(Boolean.FALSE,null,null,null);
try{
log.info("checkMawb start>>>>>>>>>> mawb:"+gson.toJson(mawb));
//1、将请求转换为运单
ChmConsignment chmConsignment=consignmentService.convertToChmConsignment(mawb,null,appId);
if(Objects.equals(chmConsignment,null)){
result.setCode(ErrorCodeEnum.ERROR_30001.getCode());
result.setMsg(ErrorCodeEnum.ERROR_30001.getName());
return result;
}
//校验成交方式 成交方式为CIF时 '参数feeCurr不能为空','参数feeMark不能为空'',参数feeRate不能为空','参数insurCurr不能为空', '参数insurRate不能为空'
result = this.notBlankCheck(mawb,chmConsignment.getDealMode());
if(!result.getSuccess()){
return result;
}
List<ChmConsignmentDetail> chmConsignmentDetailList = new ArrayList<>();
mawb.getMawbDetailList().forEach(detail ->{
chmConsignmentDetailList.add(consignmentDetailService.convertToChmConsignmentDetail(detail,chmConsignment,Boolean.TRUE));
});
chmConsignment.setChmConsignmentDetailList(chmConsignmentDetailList);
//调用IClear接口进行运单数据校验
String objJson = JsonToJava.toJson(chmConsignment);
// Header[] headers = HttpHeader.custom()
// .other("Content-Type", "application/json")
// .build();
// log.info("******************* : " + this.iclearCheckUrl);
// //推送海关回执数据
// HttpConfig config = HttpConfig.custom()
// .headers(headers)
// .url(this.iclearCheckUrl)
// .encoding("utf-8")
// .json(objJson);
// String json = HttpClientUtil.post(config);
Map<String,String> headerMap = new HashMap<>();
headerMap.put("Content-Type", "application/json");
String json = HttpUtils.doPost(this.iclearCheckUrl,objJson,headerMap);
IClearCheckResult iclearCheckResponseResult = JsonToJava.parseJson(json, IClearCheckResult.class);
result.setSuccess(iclearCheckResponseResult.getSuccess());
result.setCode(iclearCheckResponseResult.getCode());
result.setMsg(iclearCheckResponseResult.getMessage());
log.info("<<<<<<<< checkMawb start >>>>>>>>>> mawb:"+gson.toJson(mawb) +" result :" +result.getSuccess() +" iclear check response : " + json + " status : " + result.getSuccess());
}catch (Exception e){
log.error("checkMawb() error:" + e.getMessage());
}
return result;
}
/**
* 校验成交方式 成交方式为CIF时 '参数feeCurr不能为空','参数feeMark不能为空'',参数feeRate不能为空','参数insurCurr不能为空', '参数insurRate不能为空'
* @param mawb
* @param dealMode 转换过的成交方式
* @return
*/
private ResultRS notBlankCheck(Mawb mawb,String dealMode) {
ResultRS result = new ResultRS(Boolean.TRUE, null, null,null);
//成交方式为CIF时 '参数feeCurr不能为空','参数feeMark不能为空'',参数feeRate不能为空','参数insurCurr不能为空', '参数insurRate不能为空'
if(dealMode.equals("CIF、CIP、DDP、DDU、DAP")){
if(StringUtil.isEmpty(mawb.getFeeCurr())){
result.setSuccess(false);
result.setCode(ErrorCodeEnum.ERROR_30002.getCode());
result.setMsg("运费币制不能为空");
}else if(StringUtil.isEmpty(mawb.getFeeMark())){
result.setSuccess(false);
result.setCode(ErrorCodeEnum.ERROR_30002.getCode());
result.setMsg("运费标记不能为空");
}else if(mawb.getFeeRate() == null){
result.setSuccess(false);
result.setCode(ErrorCodeEnum.ERROR_30002.getCode());
result.setMsg("运费/率不能为空");
}else if(StringUtil.isEmpty(mawb.getInsurCurr())){
result.setSuccess(false);
result.setCode(ErrorCodeEnum.ERROR_30002.getCode());
result.setMsg("保险费币制不能为空");
}else if(mawb.getInsurRate() == null){
result.setSuccess(false);
result.setCode(ErrorCodeEnum.ERROR_30002.getCode());
result.setMsg("保险费/率不能为空");
}
}
return result;
}
}