MawbService.java
10.8 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
package com.erry.iclear.dateInterface.service;
import com.erry.iclear.dateInterface.enums.ErrorCodeEnum;
import com.erry.iclear.dateInterface.api.request.Mawb;
import com.erry.iclear.dateInterface.api.request.MawbDetail;
import com.erry.iclear.dateInterface.api.response.IClearCheckResponseResult;
import com.erry.iclear.dateInterface.api.response.ResultRS;
import com.erry.iclear.dateInterface.entity.ChmConsignment;
import com.erry.iclear.dateInterface.entity.ChmConsignmentDetail;
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.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;
/**
* 保存主单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 "";
}
/**
* 校验主单
* @param mawb
* @return
*/
public ResultRS checkMawb(Mawb mawb){
ResultRS result = new ResultRS(Boolean.FALSE,null,null);
try{
log.info("checkMawb start>>>>>>>>>> mawb:"+gson.toJson(mawb));
//1、将请求转换为运单
ChmConsignment chmConsignment=consignmentService.convertToChmConsignment(mawb,null,"IDE-ICLEAR-API");
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));
});
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);
IClearCheckResponseResult iclearCheckResponseResult = JsonToJava.parseJson(json, IClearCheckResponseResult.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);
//成交方式为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;
}
}