BusinessService.java
19.8 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
package com.huaheng.api.xinyi.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.huaheng.api.xinyi.constant.ResultStatus;
import com.huaheng.api.xinyi.constant.XinYiConstant;
import com.huaheng.api.xinyi.domian.*;
import com.huaheng.common.exception.BusinessException;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.DataUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 信义ERP业务数据接口
* @author Enzo Cotter
* @date 2019/12/24
*/
@Service
public class BusinessService {
@Resource
private TokenService tokenService;
@Resource
private ApiTokenService apiTokenService;
/**
* 送货单查询接口
* @param organizationId 组织id
* @param deliverHeaderId 送货单Id
* @param bout 查询次数
* @return
*/
public List<DeliverOrder> getDeliverOrder(String organizationId, String deliverHeaderId, int bout){
TokenEntity tokenEntity = tokenService.findOneByAll();
Map<String, Object> map = new HashMap<>();
map.put("organizationId", organizationId);
map.put("deliverHeaderId", deliverHeaderId);
map.put("wmsCode", "BH_HH01");
String url = XinYiConstant.XINYI_HOST+XinYiConstant.PROJECT_NAME+"/aliWmsBusinessData/getDeliverOrder";
String result = HttpUtils.sendGet(url, tokenEntity, DataUtils.sendGetFormat(map));
ResultEntityList<DeliverOrder> resultEntity = JSON.parseObject(result, new TypeReference<ResultEntityList<DeliverOrder>>(){});
if (ResultStatus.EXPIRED.equals(resultEntity.getStatus())){
if (bout != 1) {
apiTokenService.apiToken();
bout = 1;
this.getDeliverOrder(organizationId, deliverHeaderId, bout);
} else {
throw new BusinessException("token过期,重新请求token失败");
}
} else if(!ResultStatus.SUCCESS.equals(resultEntity.getCode())){
throw new ServiceException("服务器处理失败");
} else if (!resultEntity.getOk()) {
throw new ServiceException("服务器响应错误");
} else {
return resultEntity.getData();
}
return null;
}
/**
* 电子单据验证接口
* @param organizationId 组织id
* @param eslipNumber 单据号码
* @param bout 查询次数
* @return
*/
public List<EslipStatus> getEslipStatus(String organizationId, String eslipNumber, int bout){
TokenEntity tokenEntity = tokenService.findOneByAll();
String url = XinYiConstant.XINYI_HOST+XinYiConstant.PROJECT_NAME+"/aliWmsBusinessData/getEslipStatus/"+organizationId+"/"+eslipNumber;
String result = HttpUtils.sendGet(url, tokenEntity, null);
ResultEntityList<EslipStatus> resultEntity = JSON.parseObject(result, new TypeReference<ResultEntityList<EslipStatus>>(){});
if (ResultStatus.EXPIRED.equals(resultEntity.getStatus())){
if (bout != 1) {
apiTokenService.apiToken();
bout = 1;
this.getEslipStatus(organizationId, eslipNumber, bout);
} else {
throw new BusinessException("token过期,重新请求token失败");
}
} else if(!ResultStatus.SUCCESS.equals(resultEntity.getCode())){
throw new ServiceException("服务器处理失败");
} else if (!resultEntity.getOk()) {
throw new ServiceException("服务器响应错误");
} else {
return resultEntity.getData();
}
return null;
}
/**
* 电子单据出入库查询接口
* @param organizationId 组织id
* @param actionType 类型 IN或OUT
* @param dateFrom 最后更新日期从(YYYY-MM-DD)
* @param dateTo 最后更新日期至(YYYY-MM-DD)
* @param headerId 单据id
* @param bout 查询次数
* @return
*/
public List<EslipTransactions> getEslipTransactions(Integer organizationId, String actionType, String dateFrom, String dateTo, Integer headerId, int bout) {
TokenEntity tokenEntity = tokenService.getTokenEntity();
Map<String, Object> map = new HashMap<>();
map.put("organizationId", organizationId);
map.put("actionType",actionType);
if (StringUtils.isNotNull(dateFrom)){
map.put("dateFrom", dateFrom);
}
if (StringUtils.isNotNull(dateTo)) {
map.put("dateTo", dateTo);
}
map.put("headerId", headerId);
map.put("wmsCode", "BH_HH01");
String url = XinYiConstant.XINYI_HOST+XinYiConstant.PROJECT_NAME+"/aliWmsBusinessData/getEslipTransactions";
String result = HttpUtils.sendGet(url, tokenEntity, DataUtils.sendGetFormat(map));
ResultEntityList<EslipTransactions> resultEntity = JSON.parseObject(result, new TypeReference<ResultEntityList<EslipTransactions>>(){});
if (ResultStatus.EXPIRED.equals(resultEntity.getStatus())){
if (bout != 1) {
apiTokenService.apiToken();
bout = 1;
this.getEslipTransactions(organizationId, actionType, dateFrom, dateTo, headerId, bout);
} else {
throw new BusinessException("token过期,重新请求token失败");
}
} else if(!ResultStatus.SUCCESS.equals(resultEntity.getCode())){
throw new ServiceException("服务器处理失败");
} else if (!resultEntity.getOk()) {
throw new ServiceException("服务器响应错误");
} else {
return resultEntity.getData();
}
return null;
}
/**
* 组织间调拨接收
* @param organizationId 组织id
* @param shipmentNumber 发运单号
* @param orderBy 数据排序
* @param pageNum 当前页
* @param pageSize 每页行数
* @param count 查询总行数标识
* @param bout 查询次数
* @return
*/
public List<OrganizationTransferIn> getOrganizationTransferIn(String organizationId, String shipmentNumber, String orderBy, Integer pageNum, Integer pageSize, boolean count, int bout){
TokenEntity tokenEntity = tokenService.getTokenEntity();
Map<String, Object> map = new HashMap<>();
map.put("organizationId", organizationId);
map.put("shipmentNumber",shipmentNumber);
map.put("orderBy", orderBy);
map.put("pageNum", pageNum);
map.put("pageSize", pageSize);
map.put("count", count);
map.put("wmsCode", "BH_HH01");
String url = XinYiConstant.XINYI_HOST+XinYiConstant.PROJECT_NAME+"/aliWmsBusinessData/getOrganizationTransferIn";
String result = HttpUtils.sendGet(url, tokenEntity, DataUtils.sendGetFormat(map));
ResultEntityList<OrganizationTransferIn> resultEntity = JSON.parseObject(result, new TypeReference<ResultEntityList<OrganizationTransferIn>>(){});
if (ResultStatus.EXPIRED.equals(resultEntity.getCode())){
if (bout != 1) {
apiTokenService.apiToken();
bout = 1;
this.getOrganizationTransferIn(organizationId, shipmentNumber, orderBy, pageNum, pageSize, count, bout);
} else {
throw new BusinessException("token过期,重新请求token失败");
}
} else if(!ResultStatus.SUCCESS.equals(resultEntity.getCode())){
throw new ServiceException("服务器处理失败");
} else if (!resultEntity.getOk()) {
throw new ServiceException("服务器响应错误");
} else {
return resultEntity.getData();
}
return null;
}
/**
* 组织间调拨发出
* @param organizationId 组织id
* @param shipmentNumber 发运单号
* @param dateFrom 起始日期
* @param dateTo 结束日期
* @param orderBy 数据排序
* @param pageNum 当前页
* @param pageSize 每页行数
* @param count 查询总行数标识
* @param bout 查询次数
* @return
*/
public List<OrganizationTransferOut> getOrganizationTransferOut(String organizationId, String shipmentNumber,
String dateFrom, String dateTo, String orderBy, Integer pageNum, Integer pageSize, boolean count, int bout){
TokenEntity tokenEntity = tokenService.getTokenEntity();
Map<String, Object> map = new HashMap<>();
map.put("organizationId", organizationId);
map.put("shipmentNumber",shipmentNumber);
map.put("dateFrom", dateFrom);
map.put("dateTo", dateTo);
map.put("orderBy", orderBy);
map.put("pageNum", pageNum);
map.put("pageSize", pageSize);
map.put("count", count);
map.put("wmsCode", "BH_HH01");
String url = XinYiConstant.XINYI_HOST+XinYiConstant.PROJECT_NAME+"/aliWmsBusinessData/getOrganizationTransferOut";
String result = HttpUtils.sendGet(url, tokenEntity, DataUtils.sendGetFormat(map));
ResultEntityList<OrganizationTransferOut> resultEntity = JSON.parseObject(result, new TypeReference<ResultEntityList<OrganizationTransferOut>>(){});
if (ResultStatus.EXPIRED.equals(resultEntity.getCode())){
if (bout != 1) {
apiTokenService.apiToken();
bout = 1;
this.getOrganizationTransferOut(organizationId, shipmentNumber, dateFrom, dateTo, orderBy, pageNum, pageSize, count, bout);
} else {
throw new BusinessException("token过期,重新请求token失败");
}
} else if(!ResultStatus.SUCCESS.equals(resultEntity.getCode())){
throw new ServiceException("服务器处理失败");
} else if (!resultEntity.getOk()) {
throw new ServiceException("服务器响应错误");
} else {
return resultEntity.getData();
}
return null;
}
/**
* 采购单查询接口
* @param organizationId 组织id
* @param poHeaderId 采购单id
* @param bout 查询次数
* @return
*/
public List<PoOrder> getPoOrder(String organizationId, String poHeaderId, int bout){
TokenEntity tokenEntity = tokenService.getTokenEntity();
Map<String, Object> map = new HashMap<>();
map.put("organizationId", organizationId);
map.put("poHeaderId", poHeaderId);
String url = XinYiConstant.XINYI_HOST+XinYiConstant.PROJECT_NAME+"/aliWmsBusinessData/getPoOrder";
String result = HttpUtils.sendGet(url, tokenEntity, DataUtils.sendGetFormat(map));
ResultEntityList<PoOrder> resultEntity = JSON.parseObject(result, new TypeReference<ResultEntityList<PoOrder>>(){});
if (ResultStatus.EXPIRED.equals(resultEntity.getCode())){
if (bout != 1) {
apiTokenService.apiToken();
bout = 1;
this.getPoOrder(organizationId, poHeaderId, bout);
} else {
throw new BusinessException("token过期,重新请求token失败");
}
} else if(!ResultStatus.SUCCESS.equals(resultEntity.getCode())){
throw new ServiceException("服务器处理失败");
} else if (!resultEntity.getOk()) {
throw new ServiceException("服务器响应错误");
} else {
return resultEntity.getData();
}
return null;
}
/**
* 采购退货的查询(抓退货至接收的状态)
* @param organizationId 组织id
* @param poHeaderId 采购单id
* @param shipmentHeaderId 接收单id
* @param dateFrom 起始日期
* @param dateTo 结束日期
* @param orderBy 数据排序
* @param pageNum 当前页
* @param pageSize 每页行数
* @param count 查询总行数标识
* @param bout 查询次数
* @return
*/
public List<PurchasingReturns> getPurchasingReturns(String organizationId, String poHeaderId, String shipmentHeaderId,
String dateFrom, String dateTo, String orderBy, String pageNum, String pageSize, boolean count, int bout){
TokenEntity tokenEntity = tokenService.getTokenEntity();
Map<String, Object> map = new HashMap<>();
map.put("organizationId", organizationId);
map.put("poHeaderId", poHeaderId);
map.put("shipmentHeaderId", shipmentHeaderId);
map.put("dateFrom", dateFrom);
map.put("dateTo", dateTo);
map.put("orderBy", orderBy);
map.put("pageNum", pageNum);
map.put("pageSize", pageSize);
map.put("count", count);
map.put("wmsCode", "BH_HH01");
String url = XinYiConstant.XINYI_HOST+XinYiConstant.PROJECT_NAME+"/aliWmsBusinessData/getPurchasingReturns";
String result = HttpUtils.sendGet(url, tokenEntity, DataUtils.sendGetFormat(map));
ResultEntityList<PurchasingReturns> resultEntity = JSON.parseObject(result, new TypeReference<ResultEntityList<PurchasingReturns>>(){});
if (ResultStatus.EXPIRED.equals(resultEntity.getCode())){
if (bout != 1) {
apiTokenService.apiToken();
bout = 1;
this.getPurchasingReturns(organizationId, poHeaderId, shipmentHeaderId, dateFrom, dateTo, orderBy, pageNum, pageSize, count, bout);
} else {
throw new BusinessException("token过期,重新请求token失败");
}
} else if(!ResultStatus.SUCCESS.equals(resultEntity.getCode())){
throw new ServiceException("服务器处理失败");
} else if (!resultEntity.getOk()) {
throw new ServiceException("服务器响应错误");
} else {
return resultEntity.getData();
}
return null;
}
/**
* 采购接收单查询接口
* @param organizationId 库存组织id
* @param shipmentHeaderId 送货单头id
* @param bout 查询次数
* @return
*/
public List<RcvShipment> getRcvShipment(String organizationId, String shipmentHeaderId, int bout){
TokenEntity tokenEntity = tokenService.getTokenEntity();
Map<String, Object> map = new HashMap<>();
map.put("organizationId", organizationId);
map.put("shipmentHeaderId", shipmentHeaderId);
String url = XinYiConstant.XINYI_HOST+XinYiConstant.PROJECT_NAME+"/aliWmsBusinessData/getRcvShipment";
String result = HttpUtils.sendGet(url, tokenEntity, DataUtils.sendGetFormat(map));
ResultEntityList<RcvShipment> resultEntity = JSON.parseObject(result, new TypeReference<ResultEntityList<RcvShipment>>(){});
if (ResultStatus.EXPIRED.equals(resultEntity.getCode())){
if (bout != 1) {
apiTokenService.apiToken();
bout = 1;
this.getRcvShipment(organizationId, shipmentHeaderId, bout);
} else {
throw new BusinessException("token过期,重新请求token失败");
}
} else if(!ResultStatus.SUCCESS.equals(resultEntity.getCode())){
throw new ServiceException("服务器处理失败");
} else if (!resultEntity.getOk()) {
throw new ServiceException("服务器响应错误");
} else {
return resultEntity.getData();
}
return null;
}
/**
* 送货验证接口
* @param organizationId 库存组织id
* @param deliverNumber 采购单号
* @param bout 查询次数
* @return
*/
public List<ValidateDeliver> validateDeliver(String organizationId, String deliverNumber, int bout){
TokenEntity tokenEntity = tokenService.getTokenEntity();
Map<String, Object> map = new HashMap<>();
map.put("organizationId", organizationId);
map.put("deliverNumber", deliverNumber);
String url = XinYiConstant.XINYI_HOST+XinYiConstant.PROJECT_NAME+"/aliWmsBusinessData/validateDeliver";
String result = HttpUtils.sendGet(url, tokenEntity, DataUtils.sendGetFormat(map));
ResultEntityList<ValidateDeliver> resultEntity = JSON.parseObject(result, new TypeReference<ResultEntityList<ValidateDeliver>>(){});
if (ResultStatus.EXPIRED.equals(resultEntity.getCode())){
if (bout != 1) {
apiTokenService.apiToken();
bout = 1;
this.validateDeliver(organizationId, deliverNumber, bout);
} else {
throw new BusinessException("token过期,重新请求token失败");
}
} else if(!ResultStatus.SUCCESS.equals(resultEntity.getCode())){
throw new ServiceException("服务器处理失败");
} else if (!resultEntity.getOk()) {
throw new ServiceException("服务器响应错误");
} else {
return resultEntity.getData();
}
return null;
}
/**
* 采购单验证接口
* @param organizationId 库存组织id
* @param poNumber 采购单号
* @param bout 查询次数
* @return
*/
public List<ValidatePo> validatePo(String organizationId, String poNumber, int bout){
TokenEntity tokenEntity = tokenService.getTokenEntity();
Map<String, Object> map = new HashMap<>();
map.put("organizationId", organizationId);
map.put("poNumber", poNumber);
String url = XinYiConstant.XINYI_HOST+XinYiConstant.PROJECT_NAME+"/aliWmsBusinessData/validatePo";
String result = HttpUtils.sendGet(url, tokenEntity, DataUtils.sendGetFormat(map));
ResultEntityList<ValidatePo> resultEntity = JSON.parseObject(result, new TypeReference<ResultEntityList<ValidatePo>>(){});
if (ResultStatus.EXPIRED.equals(resultEntity.getCode())){
if (bout != 1) {
apiTokenService.apiToken();
bout = 1;
this.validatePo(organizationId, poNumber, bout);
} else {
throw new BusinessException("token过期,重新请求token失败");
}
} else if(!ResultStatus.SUCCESS.equals(resultEntity.getCode())){
throw new ServiceException("服务器处理失败");
} else if (!resultEntity.getOk()) {
throw new ServiceException("服务器响应错误");
} else {
return resultEntity.getData();
}
return null;
}
/**
* 接收单验证接口
* @param organizationId 库存组织id
* @param receiptNum 接收单号
* @param bout 查询次数
* @return
*/
public List<ValidateRcvShipment> validateRcvShipment(String organizationId, String receiptNum, int bout){
TokenEntity tokenEntity = tokenService.getTokenEntity();
Map<String, Object> map = new HashMap<>();
map.put("organizationId", organizationId);
map.put("receiptNum", receiptNum);
map.put("wmsCode", "BH_HH01");
String url = XinYiConstant.XINYI_HOST+XinYiConstant.PROJECT_NAME+"/aliWmsBusinessData/validateRcvShipment";
String result = HttpUtils.sendGet(url, tokenEntity, DataUtils.sendGetFormat(map));
ResultEntityList<ValidateRcvShipment> resultEntity = JSON.parseObject(result, new TypeReference<ResultEntityList<ValidateRcvShipment>>(){});
if (ResultStatus.EXPIRED.equals(resultEntity.getCode())){
if (bout != 1) {
apiTokenService.apiToken();
bout = 1;
this.validateRcvShipment(organizationId, receiptNum, bout);
} else {
throw new BusinessException("token过期,重新请求token失败");
}
} else if(!ResultStatus.SUCCESS.equals(resultEntity.getCode())){
throw new ServiceException("服务器处理失败");
} else if (!resultEntity.getOk()) {
throw new ServiceException("服务器响应错误");
} else {
return resultEntity.getData();
}
return null;
}
}