IcsKuaidiService.java
4.67 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
package com.huaheng.pc.u8.service;
import com.alibaba.fastjson.JSON;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.pc.config.address.domain.Address;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.shipment.kuaidiHeader.domain.KuaidiHeader;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @ClassName icsKuaidiService
* @Description TODO
* @Author Administrator
* @Date 2021/5/3116:16
*/
@Service
public class IcsKuaidiService {
private static String param = "kd";
private static String tokenUrl = "https://api.yonyouup.com/system/token?from_account=huaheng2019&app_key=opa7271824ba6ce3541&app_secret=8425b85f0fea43bca6c14f149fe18b21";
@Resource
private AddressService addressService;
//获取token
public String getToken(){
String result = HttpUtils.sendGet(tokenUrl);
if(StringUtils.isEmpty(result)){
throw new ServiceException("U8系统接口地址错误或服务器连接不到或返回为空");
}
Map map = JSON.parseObject(result, HashMap.class);
String accessToken = map.get("token").toString();
Map hashMap = JSON.parseObject(accessToken, HashMap.class);
String token = hashMap.get("id").toString();
return token;
}
public String getUrl(){
//获取url
Address address = new Address();
address.setParam(param);
address.setWarehouseCode("KS0001");
address = addressService.selectEntity(address);
if(address == null){
throw new ServiceException("查询不到U8接口地址");
}
return address.getUrl();
}
//通过单号获取出库单信息
public List<Map<String,String>> getKDMeseeage(KuaidiHeader kuaidiHeader){
//获取url和获取token
String url = this.getUrl();
String token = this.getToken();
if(!StringUtils.isEmpty(kuaidiHeader.getOrderBill()) && StringUtils.isEmpty(kuaidiHeader.getFromCode())) {
if(kuaidiHeader.getOrderBill().substring(0,2).equals("AA")) {
url
= url + "token=" + token + "&ds_sequence=1&rows_per_page=1000&code_begin=" + kuaidiHeader.getOrderBill() + "&code_end=" + kuaidiHeader.getOrderBill();
}else {
url
= url + "token=" + token + "&ds_sequence=2&rows_per_page=1000&code_begin=" + kuaidiHeader.getOrderBill() + "&code_end=" + kuaidiHeader.getOrderBill();
}
}
if(!StringUtils.isEmpty(kuaidiHeader.getOrderBill()) && StringUtils.isNotEmpty(kuaidiHeader.getFromCode())) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String dateString = dateFormat.format(kuaidiHeader.getCreated());
if(kuaidiHeader.getOrderBill().substring(0,2).equals("AA")) {
url
= url + "token=" + token + "&ds_sequence=1&rows_per_page=1000&auditdate="+dateString;
}else {
url
= url + "token=" + token + "&ds_sequence=2&rows_per_page=1000&auditdate=" + dateString;
}
}
if(!StringUtils.isEmpty(kuaidiHeader.getSourceCode())) {
if(kuaidiHeader.getSourceCode().substring(0,2).equals("AH")) {
url
= url + "token=" + token + "&ds_sequence=1&rows_per_page=1000&subconsignmentcode=" + kuaidiHeader.getSourceCode();
}else{
url = url + "token=" + token + "&ds_sequence=2&rows_per_page=1000&subconsignmentcode=" + kuaidiHeader.getSourceCode();
}
}
//获取信息
String result = HttpUtils.sendGet(url);
if(StringUtils.isEmpty(result)){
throw new ServiceException("U8系统接口地址错误或服务器连接不到或返回为空");
}
Map map = JSON.parseObject(result, HashMap.class);
String code = map.get("errcode").toString();
if("0".equals(code)){
List<Map<String,String>> lists = new ArrayList<>();
if(StringUtils.isNull(map.get("saleoutlistall"))){
throw new ServiceException("获取的U8信息错误,为空");
}
String msg = map.get("saleoutlistall").toString();
lists = JSON.parseObject(msg,ArrayList.class);
return lists;
}else {
throw new ServiceException(map.get("errmsg").toString());
}
}
}