CustomsDataInterface.java
5.25 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
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.IClearApiLogService;
import com.erry.iclear.dateInterface.service.MawbDetailService;
import com.erry.iclear.dateInterface.service.MawbService;
import com.erry.iclear.dateInterface.util.MD5Util;
import com.google.gson.Gson;
import io.swagger.annotations.Api;
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.http.HttpRequest;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Objects;
/**
* @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;
@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("接收到主单数据:" + gson.toJson(mawb));
ResultRS result = new ResultRS();
result.setSuccess(Boolean.FALSE);
if(Objects.equals(mawb,null)){
result.setCode("-7");
result.setMsg("主单信息不能为空");
return result;
}
//0、保存请求信息,保存到iClear的 SQLServer
String appId=(String) request.getHeader("Appid");
String appkey=(String) request.getHeader("Appkey");
IClearApiLog saveIClearApiLogResult = iClearApiLogService.saveIClearApiLog(iClearApiLogService.convertToIClearApiLog(mawb,appId,appkey));
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("请求主单数据保存成功,msgId:"+saveMawbResult.getMsgId());
}else{
log.info("请求主单数据保存失败,msgId:"+saveMawbResult.getMsgId());
}
}else{
log.info("请求保存失败,msgId:"+saveIClearApiLogResult.getMsgId());
}
//1、TODO 校验用户名密码
result=this.checkAppSecret(request, result);
//2、TODO 校验主单
if(result.getSuccess()==true){
result.setSuccess(mawbService.checkMawb(mawb));
}
//3、TODO 校验子单
if(result.getSuccess()==true){
}
//4、TODO 保存主单
if(result.getSuccess()==true){
}
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("TimeStamp 不能为空");
return result;
}
HashMap<String,String> secretMap = Constant.appIdSecurity.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 md5Str= MD5Util.md5(appId+appkey+secretInSys+timeStamp);
if(!token.equals(md5Str)){
result.setCode("-4");
result.setMsg("Token验证失败");
return result;
}
result.setSuccess(true);
return result;
}
}