BasfDataInterface.java
4.64 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
package com.erry.iclear.dateInterface.api;
import com.erry.iclear.dateInterface.api.request.Basfc;
import com.erry.iclear.dateInterface.api.request.Mawb;
import com.erry.iclear.dateInterface.api.response.ResultRS;
import com.erry.iclear.dateInterface.entity.IClearApiLog;
import com.erry.iclear.dateInterface.service.BasfService;
import com.erry.iclear.dateInterface.service.IClearApiLogService;
import com.erry.iclear.dateInterface.service.MawbService;
import com.google.gson.Gson;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StopWatch;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Objects;
@RestController
@RequestMapping("/basf")
@Slf4j
public class BasfDataInterface {
private Gson gson = new Gson();
@Autowired
private BasfService basfService;
@Autowired
private IClearApiLogService iClearApiLogService;
@ApiOperation(value = "BASF推送运单数据", httpMethod = "POST", notes = "ex: http://192.168.1.75:8080/customs/sendMawbBasf")
@PostMapping("/sendMawbBasf")
@ResponseBody
public ResultRS sendMawbBasf(HttpServletRequest request
, @Validated @RequestBody Basfc basfc) {
log.info("接收到请求数据consignmentCode:"+basfc.getConsignmentCode()+" data:" + gson.toJson(basfc));
ResultRS result = new ResultRS(Boolean.FALSE,"","");
if(Objects.equals(basfc,null)){
result.setCode("-7");
result.setMsg("请求信息不能为空");
return result;
}
//1、保存请求信息,保存到iClear的 SQLServer
StopWatch sw = new StopWatch("receice mawbBasf");
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.convertToIClearApiLogC(basfc,appId,appKey,new Date(Long.valueOf(timeStamp))));
basfc.setAppId(appId);
Mawb saveMawbBasfResult = null;
if(!Objects.equals(saveIClearApiLogResult,null)){
log.info("请求保存成功,msgId:"+saveIClearApiLogResult.getMsgId());
basfc.setMsgId(saveIClearApiLogResult.getMsgId());
basfc.getBasfcDetailList().forEach(d->{
d.setMsgId(saveIClearApiLogResult.getMsgId());
});
saveMawbBasfResult = basfService.saveMawbBasf(basfc);
if(!Objects.equals(saveMawbBasfResult,null)){
log.info("请求数据运单号"+basfc.getConsignmentCode()+"保存成功,msgId:"+saveMawbBasfResult.getMsgId());
}else{
log.info("请求数据运单号"+basfc.getConsignmentCode()+"保存失败,msgId:"+saveMawbBasfResult.getMsgId());
}
}else{
log.info("请求日志保存失败,consignmentCode:"+basfc.getConsignmentCode());
}
sw.stop();
//2、TODO 校验主单
/* sw.start("checkMawb");
result=mawbService.checkMawb(mawb);
if(!result.getSuccess()){
return result;
}
sw.stop();*/
// //3、TODO 校验子单
// sw.start("checkMawbDetail");
// result=mawbDetailServicel.checkMawbDetail(mawb);
// if(!result.getSuccess()){
// return result;
// }
// sw.stop();
//4、保存运单到iclear中
sw.start("processChmConsignment");
result = chmConsignmentService.processChmConsignment(saveMawbBasfResult, 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("请求数据consignmentCode:"+basfc.getConsignmentCode() +" 接收结束");
sw.stop();
log.info(sw.prettyPrint());
//6、return result
result.setSuccess(Boolean.TRUE);
result.setCode("0");
return result;
}
}