CoustomAnalysisServiceImp.java
7.1 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
package com.tianbo.analysis.service.imp;
import com.tianbo.analysis.dao.CUSTOM_RESPONSEMapper;
import com.tianbo.analysis.model.CUSTOM_RESPONSE;
import com.tianbo.analysis.model.CustomReception;
import com.tianbo.analysis.service.CoustomAnalysisService;
import com.tianbo.util.Date.DateUtil;
import com.tianbo.util.regular.RegularUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.UUID;
@Service
@Slf4j
public class CoustomAnalysisServiceImp implements CoustomAnalysisService {
@Autowired
CUSTOM_RESPONSEMapper custom_responseMapper;
@Override
public int insertRecept(CustomReception cus, String errorCodes, String errorTexts) throws ParseException {
RegularUtil regularUtil = new RegularUtil();
CUSTOM_RESPONSE custom_response = new CUSTOM_RESPONSE();
custom_response.setId(UUID.randomUUID().toString());
String awb = "";
String awbh = "";
if (cus.getWayBillMaster()!=null && cus.getWayBillMaster().length()>0){
StringBuffer stringBuffer = new StringBuffer(cus.getWayBillMaster());
StringBuffer insert = stringBuffer.insert(3, "-");
String s = insert.toString();
//设置 主单号
awb = s;
}
if (cus.getWayBillSecond()!=null && cus.getWayBillSecond().length()>0){
//取分单号
String[] awbhArr = cus.getWayBillSecond().split("_");
awbh = awbhArr[1];
}
// 主单号
custom_response.setAwbano(awb);
// 分单号
custom_response.setAwbhno(awbh);
// 判断日期是否为空
String flightDate = cus.getFlightDate();
if (!StringUtils.isEmpty(flightDate)){
Date date = DateUtil.formatByyyyyMMdd(flightDate);
// 航班日期
custom_response.setFlightdate(date);
}
String flightNo = cus.getFlightNo();
if (!StringUtils.isEmpty(flightNo)){
// 承运人代码
custom_response.setCarrier(flightNo.substring(0, 2));
// 航班号
custom_response.setFlightno(flightNo.substring(2));
}
// 报文发送序号
custom_response.setCusmsgid(cus.getMessageID());
// 回执发送者id
custom_response.setCussenderid(cus.getSenderID());
// 回执接受这id
custom_response.setCusreciverid(cus.getReceiverID());
// 报文版本
custom_response.setCusversion(cus.getVersion());
// 对应海关的functioncode业务代码
custom_response.setCusfunctioncode(cus.getFunctionCode());
// 报文类型
custom_response.setBustype(cus.getMessageType());
// 设置时区
// SimpleDateFormat bjSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// bjSdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
// String format = bjSdf.format(new Date());
// 回执接受时间
custom_response.setCusresrcvtime(new Date());
// 业务发生时间
custom_response.setBusdate(new Date());
// 判断日期是否为空
String sendTime = cus.getSendTime();
if (!StringUtils.isEmpty(sendTime)){
Date date = DateUtil.fromatByyyMMdd_hhmmssSSS(sendTime);
// 回执报文 海关发送时间
custom_response.setCusressendtime(date);
}
// 回执Code代码
String responseCode = cus.getResponseCode();
// 回执内容
String responseText = cus.getResponseText();
// 判断是否为空
if (responseText != null && responseCode != null){
// 回执状态
String cusText = regularUtil.cusText(responseText);
custom_response.setCusresstatus(cusText);
// 回执Code代码
custom_response.setCusrescode(responseCode);
// 回执内容
custom_response.setCusrestext(responseText);
}else {
// 回执状态
String substring = errorTexts.substring(0, 5);
custom_response.setCusresstatus(substring);
// 回执Code代码
custom_response.setCusrescode(errorCodes);
// 回执内容
custom_response.setCusrestext(errorTexts);
}
// 添加
int insert = custom_responseMapper.insert(custom_response);
if (insert > 0){
return 1;
}else {
return 0;
}
}
// @Override
// public int insertRecept(CustomReception customReception){
//
// String awbA = customReception.getWayBillMaster();
// String awbH = customReception.getWayBillSecond();
// // 回执内容
// String reception = customReception.getResponseText();
// String flightDateStr = customReception.getFlightDate();
//
// // 实体
// CUSTOM_RESPONSE custom_response = new CUSTOM_RESPONSE();
// // 判断日期是否为空
// if (!StringUtils.isEmpty(flightDateStr)){
//
// Date flightDate = DateUtil.formatByyyyyMMdd(flightDateStr);
//
// //处理主单格式,将海关回执的主单号58019316861,变为580-19316861
// if (awbA!=null && awbA.length()>0){
// StringBuffer stringBuffer = new StringBuffer(awbA);
// stringBuffer.insert(3,"-");
// awbA = stringBuffer.toString();
// }
//
//
// // 查询是否存在 先用messageId查询
//
// // 单号 航班号 航班日期
//
//
// //有分单号 更新分单
// if(awbA!=null && awbA.length()>0 && awbH!=null && awbH.length()> 0){
//
// // 取分单号
// String[] awbhArr = awbH.split("_");
// String awbh = awbhArr[1];
// // 分单号 赋值
// custom_response.setAwbhno(awbh);
// // 回执内容
// custom_response.setCusrestext(reception);
//
// //更新分单回执
// int i = custom_responseMapper.updateAwbhReceiption(custom_response);
//
// if (i > 0){
// return 1;
// }
//
// return 0;
// }
//
//
// if (awbA!=null && awbA.length()>0){
//
// // 设置主单回执、航班号、航班日期
// custom_response.setCusrestext(reception);
// custom_response.setFlightno(customReception.getFlightNo());
// custom_response.setFlightdate(flightDate);
//
// //更新主单回执
// int i = custom_responseMapper.updateAwbReceiption(custom_response);
//
// if (i > 0){
// return 1;
// }
// return 0;
// }
//
// }
// //未进入主分单解析 返回0 失败
// return 0;
// }
}