kuaidiController.java
5 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
package com.huaheng.api.WAYBILLNO.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huaheng.api.WAYBILLNO.service.KuaidiCallBackService;
import com.huaheng.api.WAYBILLNO.service.KuaidiService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.KDCertification.domain.KDCertification;
import com.huaheng.pc.config.KDCertification.service.KDCertificationService;
import com.huaheng.pc.shipment.kuaidiHeader.service.KuaidiHeaderService;
import io.swagger.annotations.ApiOperation;
import org.json.JSONArray;
import org.json.JSONTokener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
/**
* @ClassName kuaidiController
* @Description TODO
* @Author Administrator
* @Date 2020/2/2514:29
*/
@RestController
@RequestMapping("/api/kuaidi")
public class kuaidiController extends BaseController {
@Autowired
private KuaidiService kuaidiService;
@Autowired
private KDCertificationService kdCertificationService;
@Autowired
private KuaidiHeaderService
kuaidiHeaderService;
@Autowired
private KuaidiCallBackService kuaidiCallBackService;
private final static Logger logger = LoggerFactory.getLogger(kuaidiController.class);
@PostMapping("/confim")
@ApiOperation("kuaidi接口")
@ResponseBody
public AjaxResult confim() {
//整合快递信息
Map<String, String> data = new TreeMap<>();
data.put("recName", "张三");
data.put("recMobile", "12345678999");
data.put("recAddr", "湖南长沙岳麓区山水新城7栋701");
data.put("recCompany", "东睿有限公司");
data.put("sendName", "李四");
data.put("sendMobile", "18475748484");
data.put("sendAddr", "湖南省长沙市浏阳高新技术产业开发区鼎盛路21号");
data.put("sendCompany", "长沙华恒机器人");
data.put("kuaidiCom", "shunfeng");
data.put("orderNum", "202012050002");
String jsonObject = JSONObject.toJSONString(data);
KDCertification kdCertification = new KDCertification();
String accessToken = kdCertificationService.getOne(kdCertification).getAccessToken();
try {
String message = kuaidiService.send(accessToken, jsonObject);
System.out.println(message);
JSONObject object = JSONObject.parseObject(message);
String code = object.getString("status");
if (!"200".equals(code)) {
return AjaxResult.error(object.getString("message"));
}
} catch (Exception e) {
throw new ServiceException("快递信息send异常");
}
return AjaxResult.success("成功");
}
@GetMapping("/print")
@ApiOperation("kuaidi接口")
@ResponseBody
public String print() {
//整合快递信息
String message = null;
KDCertification kdCertification = new KDCertification();
String accessToken = kdCertificationService.getOne(kdCertification).getAccessToken();
try {
message = kuaidiService.quickPrint(accessToken, "202012050002");
System.out.println(message);
} catch (Exception e) {
throw new ServiceException("快递信息send异常");
}
return message;
}
@PostMapping("/test")
@ApiOperation("kuaidi接口")
@ResponseBody
@ApiLogger(apiName = "kuaidi接口", from = "KD")
public AjaxResult test(@RequestBody JSONObject body) throws Exception {
//快递100回传接口,更新快递单号
kuaidiCallBackService.kuaidiCallback(body, QuantityConstant.WAREHOUSE_KS);
logger.info("返回值:{}", "成功");
return AjaxResult.success("成功");
}
@PostMapping("/tests")
@ApiOperation("kuaidi接口")
@ResponseBody
public AjaxResult test(@RequestBody String json) throws Exception {
AjaxResult ajaxResult = JSON.parseObject(json, AjaxResult.class);
Object object = new JSONTokener(ajaxResult.getMsg()).nextValue();
if (object instanceof JSONObject) {
return AjaxResult.success(ajaxResult.getMsg());
} else if (object instanceof JSONArray) {
List<Map> list = JSON.parseObject(ajaxResult.getMsg(), ArrayList.class);
for (Map map : list) {
String code = map.get("Code").toString();
String irowno = map.get("irowno").toString();
String AutoID = map.get("AutoID").toString().substring(7, 10);
String ll = "";
}
}
return AjaxResult.success("成功");
}
}