TaskCancelServiceImpl.java
4.79 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
package com.huaheng.api.wcs.service.taskCancel;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.common.constant.HttpConstant;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.common.utils.http.OkHttpUtils;
import com.huaheng.common.utils.restful.RestUtil;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.domain.AjaxResultWCS;
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
@Service
public class TaskCancelServiceImpl implements TaskCancelService {
@Autowired
private AddressService addressService;
@Resource
private ConfigService configService;
@Resource
private ZoneService zoneService;
/**取消任务
* 1、判断参数是否为空
* 2、转换实体
* 3、发送数据
* @param id
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult cancelTask(String id, String warehouseCode, String area) {
//1、判断参数是否为空
if(id == null){
throw new ServiceException("任务号为空");
}
//2、转换实体
WcsTask wcsTask = new WcsTask();
wcsTask.setTaskNo(id);
//3、发送数据
String value = configService.getKey(QuantityConstant.RULE_CONNECT_WCS,warehouseCode);
int connectWCS = Integer.parseInt(value);
if(connectWCS == QuantityConstant.RULE_WCS_CONNECT) {
String url = addressService.selectAddress(QuantityConstant.ADDRESS_WCS_TASK_ASSIGN, warehouseCode, area);
String jsonParam = JSON.toJSONString(wcsTask);
url=url+"TaskCancel";
String result = OkHttpUtils.bodypost(url, jsonParam,warehouseCode);
if(StringUtils.isEmpty(result)) {
throw new ServiceException("接口地址错误或返回为空");
}
AjaxResultWCS ajaxResult = JSON.parseObject(result, AjaxResultWCS.class);
if(ajaxResult.getCode() != HttpConstant.OK) {
return AjaxResult.error(ajaxResult.getMsg());
}
return AjaxResult.success("取消任务成功");
} else {
return AjaxResult.success("取消任务成功");
}
}
/**取消任务
* 1、判断参数是否为空
* 2、转换实体
* 3、发送数据
* @param id
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult cancelTaskZone(String id, String warehouseCode, String zoneCode) {
//1、判断参数是否为空
if(id == null){
throw new ServiceException("任务号为空");
}
LambdaQueryWrapper<Zone> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Zone::getWarehouseCode, warehouseCode);
queryWrapper.eq(Zone::getCode, zoneCode);
Zone zone = zoneService.getOne(queryWrapper);
String area=zone.getArea();
//2、转换实体
WcsTask wcsTask = new WcsTask();
wcsTask.setTaskNo(id);
//3、发送数据
String value = configService.getKey(QuantityConstant.RULE_CONNECT_WCS,warehouseCode);
int connectWCS = Integer.parseInt(value);
if(connectWCS == QuantityConstant.RULE_WCS_CONNECT) {
String url = addressService.selectAddress(QuantityConstant.ADDRESS_WCS_TASK_ASSIGN, warehouseCode, area);
String jsonParam = JSON.toJSONString(wcsTask);
url=url+"TaskCancel";
String result = OkHttpUtils.bodypost(url, jsonParam,warehouseCode);
if(StringUtils.isEmpty(result)) {
throw new ServiceException("接口地址错误或返回为空");
}
AjaxResultWCS ajaxResult = JSON.parseObject(result, AjaxResultWCS.class);
if(ajaxResult.getCode() != HttpConstant.OK) {
return AjaxResult.error(ajaxResult.getMsg());
}
return AjaxResult.success("取消任务成功");
} else {
return AjaxResult.success("取消任务成功");
}
}
}