CustomsDataInterface.java
6.65 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
package com.erry.iclear.dateInterface.api;
import com.erry.iclear.dateInterface.api.request.Mawb;
import com.erry.iclear.dateInterface.api.response.ResultRS;
import com.erry.iclear.dateInterface.common.Constant;
import com.erry.iclear.dateInterface.entity.IClearApiLog;
import com.erry.iclear.dateInterface.service.*;
import com.erry.iclear.dateInterface.util.DateUtils;
import com.erry.iclear.dateInterface.util.SHA256Util;
import com.google.gson.Gson;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
/**
* @author Administrator
*/
@RestController
@RequestMapping("/customs")
@Slf4j
public class CustomsDataInterface {
private Gson gson = new Gson();
@Autowired
private MawbService mawbService;
@Autowired
private MawbDetailService mawbDetailServicel;
@Autowired
private IClearApiLogService iClearApiLogService;
@Autowired
private ChmConsignmentService chmConsignmentService;
@Autowired
private ChmConsignmentDetailService chmConsignmentDetailService;
@ApiOperation(value = "推送主单数据", httpMethod = "POST", notes = "ex: http://192.168.1.75:8080/customs/sendMawb")
@PostMapping("/sendMawb")
@ResponseBody
public ResultRS sendMawb(HttpServletRequest request
, @RequestBody Mawb mawb) {
log.info("接收到请求数据billNo:"+mawb.getBillNo()+" data:" + gson.toJson(mawb));
ResultRS result = new ResultRS(Boolean.FALSE,"","");
if(Objects.equals(mawb,null)){
result.setCode("-7");
result.setMsg("请求信息不能为空");
return result;
}
//0、保存请求信息,保存到iClear的 SQLServer
StopWatch sw = new StopWatch("receice mawb");
sw.start("save log");
String appId=(String) request.getHeader("Appid");
String appKey=(String) request.getHeader("Appkey");
String timeStamp=(String) request.getHeader("TimeStamp");
IClearApiLog saveIClearApiLogResult = iClearApiLogService.saveIClearApiLog(iClearApiLogService.convertToIClearApiLog(mawb,appId,appKey,new Date(Long.valueOf(timeStamp))));
if(!Objects.equals(saveIClearApiLogResult,null)){
log.info("请求保存成功,msgId:"+saveIClearApiLogResult.getMsgId());
mawb.setMsgId(saveIClearApiLogResult.getMsgId());
mawb.getMawbDetailList().forEach(d->{
d.setMsgId(saveIClearApiLogResult.getMsgId());
});
Mawb saveMawbResult= mawbService.saveMawb(mawb);
if(!Objects.equals(saveMawbResult,null)){
log.info("请求数据主单号"+mawb.getBillNo()+"保存成功,msgId:"+saveMawbResult.getMsgId());
}else{
log.info("请求数据主单号"+mawb.getBillNo()+"保存失败,msgId:"+saveMawbResult.getMsgId());
}
}else{
log.info("请求日志保存失败,BillNo:"+mawb.getBillNo());
}
sw.stop();
//1、校验用户名密码
// sw.start("checkAppSecret");
// result=this.checkAppSecret(request, result);
// sw.stop();
//2、TODO 校验主单
sw.start("checkMawb");
if(result.getSuccess()){
//result.setSuccess(mawbService.checkMawb(mawb));
}
sw.stop();
//3、TODO 校验子单
sw.start("checkMawbDetail");
if(result.getSuccess()){
}
sw.stop();
//4、保存运单到iclear中
sw.start("processChmConsignment");
//if(result.getSuccess()){
//TODO 等待校验逻辑完善后,由result.getSuccess() 判断
if(true){
result = chmConsignmentService.processChmConsignment(mawb, timeStamp,appId);
if(!result.getSuccess()){
return result;
}
}
sw.stop();
//5、更新日志
sw.start("updateIClearApiLog");
if(!Objects.equals(saveIClearApiLogResult,null)){
saveIClearApiLogResult.setReceiveResult(result.getSuccess().toString());
saveIClearApiLogResult.setErrorCode(result.getCode());
saveIClearApiLogResult.setResponseTime(new Date());
saveIClearApiLogResult.setSpendTime(sw.getTotalTimeMillis());
iClearApiLogService.updateIClearApiLog(saveIClearApiLogResult);
}
log.info("请求数据billNo:"+mawb.getBillNo() +" 接收结束");
sw.stop();
log.info(sw.prettyPrint());
//6、return result
result.setSuccess(Boolean.TRUE);
result.setCode("0");
return result;
}
/**
* 校验用户
* @param request
* @param result
private ResultRS checkAppSecret(HttpServletRequest request, ResultRS result) {
String appId=(String) request.getHeader("Appid");
String appkey=(String) request.getHeader("Appkey");
String timeStamp=(String) request.getHeader("TimeStamp");
String token= (String) request.getHeader("token");
if(StringUtils.isBlank(appId)){
result.setCode("-1");
result.setMsg("Appid 不能为空");
return result;
}
if(StringUtils.isBlank(appkey)){
result.setCode("-2");
result.setMsg("Appkey 不能为空");
return result;
}
if(StringUtils.isBlank(timeStamp)){
result.setCode("-6");
result.setMsg("TimeStamp 不能为空");
return result;
}
if(StringUtils.isBlank(token)){
result.setCode("-4");
result.setMsg("token 不能为空");
return result;
}
HashMap<String,String> secretMap = Constant.appIdSecurityCache.get(appId);
if(secretMap==null){
result.setCode("-100");
result.setMsg("系统异常,该appId没有注册");
return result;
}
String secretInSys = secretMap.get(appkey);
if (StringUtils.isBlank(secretInSys)) {
result.setCode("-101");
result.setMsg("系统异常,该appId没有权限/密码");
return result;
}
String sha256Str = SHA256Util.getSHA256String(appId+appkey+secretInSys+timeStamp);
if(!token.equals(sha256Str)){
result.setCode("-4");
result.setMsg("Token验证失败");
return result;
}
result.setSuccess(true);
return result;
}
*/
}