KuaidiHeaderDataService.java
12.3 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package com.huaheng.pc.shipment.kuaidiHeader.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.DataUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.bean.BeanUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.token.TokenService;
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.config.company.domain.Company;
import com.huaheng.pc.config.token.domain.Token;
import com.huaheng.pc.config.token.service.ITokensService;
import com.huaheng.pc.shipment.kuaidiHeader.domain.KuaidiHeader;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.u8.domain.ICSShipmentHeader;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* 【请填写功能名称】 服务层实现
*
* @author huaheng
* @date 2022-09-07
*/
@Service
public class KuaidiHeaderDataService {
@Resource
private KuaidiHeaderService kuaidiHeaderService;
@Resource
private ITokensService tokens;
@Resource
private KuaidiSendService kuaidiSendService;
@Resource
private KDCertificationService kdCertificationService;
public String createCode(String shipmentType)
{
String code = null;
Date now = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
String maxCode =null;
KuaidiHeader kuaidiHeader1=new KuaidiHeader();
kuaidiHeader1.setType(shipmentType);
KuaidiHeader kuaidiHeader=getByOrderBill(kuaidiHeader1);
if(kuaidiHeader!=null){
maxCode=kuaidiHeader.getCode();
}
if (maxCode != null && maxCode.length() > 13 && maxCode.substring(maxCode.length() - 13, maxCode.length() - 5).equals(df.format(now)))
{
Integer Count = Integer.valueOf(maxCode.substring(maxCode.length() - 5, maxCode.length()));
code = shipmentType + df.format(now) + String.format("%05d", Count + 1);
}
else
{
code = shipmentType + df.format(now) + "00001";
}
return code;
}
public KuaidiHeader getByOrderBill(KuaidiHeader kuaidiHeader){
LambdaQueryWrapper<KuaidiHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(KuaidiHeader::getDeleted,false);
lambdaQueryWrapper.eq(StringUtils.isNotEmpty(kuaidiHeader.getOrderBill()),KuaidiHeader::getOrderBill,kuaidiHeader.getOrderBill());
lambdaQueryWrapper.eq(StringUtils.isNotEmpty(kuaidiHeader.getType()),KuaidiHeader::getType,kuaidiHeader.getType());
lambdaQueryWrapper.orderByDesc(KuaidiHeader::getId);
lambdaQueryWrapper.last("limit 1");
return kuaidiHeaderService.getOne(lambdaQueryWrapper);
}
/**
* 根据出库单
*
* @param shipmentHeader
* @return
*/
public KuaidiHeader getModelByShipment(ShipmentHeader shipmentHeader) {
KuaidiHeader kuaidiHeader = new KuaidiHeader();
kuaidiHeader.setRecName(shipmentHeader.getRecName());
kuaidiHeader.setRecMobile(shipmentHeader.getRecMobile());
kuaidiHeader.setRecAddr(shipmentHeader.getRecAddr());
kuaidiHeader.setRecCompany(shipmentHeader.getRecCompany());
kuaidiHeader.setSendName(shipmentHeader.getSendName());
kuaidiHeader.setSendMobile(shipmentHeader.getSendMobile());
kuaidiHeader.setSendAddr(shipmentHeader.getSendAddr());
kuaidiHeader.setSendCompany(shipmentHeader.getSendCompany());
kuaidiHeader.setUWarehouseCode(shipmentHeader.getUWarehouseCode());
kuaidiHeader.setCode(shipmentHeader.getCode());
// kuaidiHeader.setWarehouseId(shipmentHeader.getWarehouseId());
kuaidiHeader.setWarehouseCode(shipmentHeader.getWarehouseCode());
// kuaidiHeader.setCompanyId(shipmentHeader.getCompanyId());
kuaidiHeader.setCompanyCode(shipmentHeader.getCompanyCode());
kuaidiHeader.setSourceCode(shipmentHeader.getSourceCode());
kuaidiHeader.setType(shipmentHeader.getShipmentType());
kuaidiHeader.setRemark(shipmentHeader.getRemark());
kuaidiHeader.setCreated(new Date());
kuaidiHeader.setCDepName(shipmentHeader.getCDepName());
kuaidiHeader.setCreatedBy(shipmentHeader.getCreatedBy());
kuaidiHeader.setEnable(shipmentHeader.getEnable());
kuaidiHeader.setDeleted(shipmentHeader.getDeleted());
return kuaidiHeader;
}
public KuaidiHeader getModelByICSShipment(ICSShipmentHeader icsShipmentHeader) {
KuaidiHeader kuaidiHeader = new KuaidiHeader();
kuaidiHeader.setType("CO");
String code = this.createCode(kuaidiHeader.getType());
kuaidiHeader.setRecName(icsShipmentHeader.getRecName());
kuaidiHeader.setRecMobile(icsShipmentHeader.getRecMobile());
kuaidiHeader.setRecAddr(icsShipmentHeader.getRecAddr());
kuaidiHeader.setRecCompany(icsShipmentHeader.getRecCompany());
kuaidiHeader.setSendName(icsShipmentHeader.getSendName());
kuaidiHeader.setSendMobile(icsShipmentHeader.getSendMobile());
kuaidiHeader.setSendAddr(icsShipmentHeader.getSendAddr());
kuaidiHeader.setSendCompany(icsShipmentHeader.getSendCompany());
kuaidiHeader.setCode(code);
kuaidiHeader.setWarehouseId(1);
kuaidiHeader.setWarehouseCode("CS0001");
kuaidiHeader.setSourceCode(icsShipmentHeader.getCDLCode());
kuaidiHeader.setCreated(new Date());
kuaidiHeader.setCreatedBy(icsShipmentHeader.getCMaker());
kuaidiHeader.setCDepName(icsShipmentHeader.getCDepName());
kuaidiHeader.setEnable(0);
kuaidiHeader.setDeleted(false);
return kuaidiHeader;
}
public void checkImport(KuaidiHeader map){
if(StringUtils.isNull(map.getSendName())) {
throw new ServiceException("发件人信息为空");
}
if(StringUtils.isNull(map.getSendMobile())) {
throw new ServiceException("发件人号码信息为空");
}
if(StringUtils.isNull(map.getSendAddr())) {
throw new ServiceException("发件人地址信息为空");
}
if(StringUtils.isNull(map.getSendCompany())) {
throw new ServiceException("发件人公司信息为空");
}
if(StringUtils.isNull(map.getRecName())) {
throw new ServiceException("收件人信息为空");
}
if(StringUtils.isNull(map.getRecMobile())) {
throw new ServiceException("收件人号码信息为空");
}
if(StringUtils.isNull(map.getRecAddr())) {
throw new ServiceException("收件人地址信息为空");
}
if(StringUtils.isNull(map.getRecCompany())) {
throw new ServiceException("收件人公司信息为空");
}
if(StringUtils.isNull(map.getCompanyId())) {
throw new ServiceException("公司ID信息为空");
}
if(StringUtils.isNull(map.getCDepName())) {
throw new ServiceException("部门信息为空");
}
if(StringUtils.isNull(map.getSourceCode())) {
throw new ServiceException("发货单号为空");
}
if(StringUtils.isNull(map.getOrderBill())) {
throw new ServiceException("出库单号为空");
}
}
public KuaidiHeader createHeaderByImport(KuaidiHeader kuaidiHeader,KuaidiHeader map,Company company){
// BeanUtils.copyBeanProp(user, obj);
map.setType(kuaidiHeader.getType());
map.setCompanyCode(company.getCode());
/* kuaidiHeader.setRecName(map.get("收件人").toString());
kuaidiHeader.setRecMobile(map.get("收件人号码").toString());
kuaidiHeader.setRecAddr(map.get("收件人地址").toString());
kuaidiHeader.setRecCompany(map.get("收件人公司").toString());
kuaidiHeader.setSendName(map.get("发件人").toString());
kuaidiHeader.setSendMobile(map.get("发件人号码").toString());
kuaidiHeader.setSendAddr(map.get("发件人地址").toString());
kuaidiHeader.setSendCompany(map.get("发件人公司").toString());
kuaidiHeader.setSourceCode(map.get("发货单号").toString());
kuaidiHeader.setOrderBill(map.get("出库单号").toString());
kuaidiHeader.setCompanyId(DataUtils.getInteger(map.get("公司ID")));
kuaidiHeader.setCompanyCode(company.getCode());
kuaidiHeader.setCDepName(map.get("部门").toString());
if(StringUtils.isNotNull(map.get("备注"))) {
kuaidiHeader.setRemark(map.get("备注").toString());
}*/
return map;
}
public AjaxResult sendKD(KuaidiHeader kuaidiHeader) {
//查出销售单的快递信息
KuaidiHeader condition =kuaidiHeaderService.getById(kuaidiHeader.getId());
if(condition == null){
return AjaxResult.error("快递单无法查到,是否被删除");
}
String orderNum =null;
if(StringUtils.isEmpty(condition.getKuaidiNum())){
orderNum = condition.getCode()+condition.getId()+"1";
condition.setKuaidiNum(orderNum);
}else {
orderNum =condition.getKuaidiNum()+"1";
condition.setKuaidiNum(orderNum);
}
condition.setKuaidiCom(kuaidiHeader.getKuaidiCom());
//整合快递信息
Map<String, String> data = new TreeMap<>();
data.put("recName", condition.getRecName());
data.put("recMobile", condition.getRecMobile());
data.put("recAddr", condition.getRecAddr());
data.put("recCompany", condition.getRecCompany());
data.put("sendName", condition.getSendName());
data.put("sendMobile", condition.getSendMobile());
data.put("sendAddr", condition.getSendAddr());
data.put("sendCompany", condition.getSendCompany());
data.put("kuaidiCom",condition.getKuaidiCom());
data.put("orderNum",orderNum);
data.put("cargo","机械配件");
String comment = "";
if(StringUtils.isNotEmpty(condition.getSourceCode())){
comment = "发货单:"+ condition.getSourceCode()+";";
}
if(StringUtils.isNotEmpty(condition.getOrderBill())){
comment = comment +"出货单:"+ condition.getOrderBill();
}
data.put("comment",comment);
String jsonObject = JSONObject.toJSONString(data);
/*Token token =new Token();
token.setType("kd");
String accessToken = tokens.getTokenByParam(token).getAccesstoken();*/
KDCertification kdCertification =new KDCertification();
String accessToken = kdCertificationService.getOne(kdCertification).getAccessToken();
try {
String message = kuaidiSendService.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异常");
}
kuaidiHeaderService.updateById(condition);
return AjaxResult.success("成功");
}
//快递打印
public AjaxResult printKD(String kuaidiNum) {
if(StringUtils.isEmpty(kuaidiNum)){
return AjaxResult.error("没有导入快递信息");
}
//整合快递信息
String message =null;
/*Token token =new Token();
token.setType("kd");
String accessToken = tokens.getTokenByParam(token).getAccesstoken();*/
KDCertification kdCertification =new KDCertification();
String accessToken = kdCertificationService.getOne(kdCertification).getAccessToken();
try {
message = kuaidiSendService.quickPrint(accessToken,kuaidiNum);
System.out.println(message);
}catch (Exception e){
throw new ServiceException("快递信息send异常");
}
return AjaxResult.success(message);
}
}