AcsByCSService.java
4.62 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
package com.huaheng.api.acs.service;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
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.OkHttpUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.points.service.AgvPointService;
import com.huaheng.pc.task.agvTaskCS.domain.AgvTaskCs;
import com.huaheng.pc.task.agvTaskCS.service.AgvTaskCsService;
/**
* 长沙agv交互接口
*/
@Service
public class AcsByCSService {
private static final Logger logger = LoggerFactory.getLogger(AcsByCSService.class);
@Resource
private AgvTaskCsService agvTaskCsService;
@Resource
private AddressService addressService;
@Resource
private AgvPointService agvPointService;
/**
* 下发任务给ACS
*/
public AjaxResult createAGVTask(AgvTaskCs agvTaskCs) {
String url = addressService.selectAddress("AGV_CS", QuantityConstant.WAREHOUSECODE, null, 0) + "createAGVTask";
String JsonParam = JSON.toJSONString(agvTaskCs);
logger.info("任务下发:{}", JsonParam);
String result = OkHttpUtils.bodypost(url, JsonParam, "", "AGV-CS下发任务");
if (StringUtils.isEmpty(result)) {
throw new ServiceException("ACS接口地址错误或服务器连接不到或返回为空");
}
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
if (ajaxResult.hasErr()) {
agvTaskCs.setMsg(ajaxResult.getMsg());
agvTaskCsService.updateById(agvTaskCs);
return AjaxResult.error(ajaxResult.getMessage());
} else {
agvTaskCs.setMsg(ajaxResult.getMsg());
agvTaskCsService.updateById(agvTaskCs);
}
// 下发成功
agvTaskCs.setState(QuantityConstant.AGV_TASK_STATUS_RELEASE);
agvTaskCsService.updateById(agvTaskCs);
return AjaxResult.success(ajaxResult.getMsg()).setData(ajaxResult.getData());
}
/**
* 下发任务给ACS
*/
public AjaxResult cancelAGVTask(Integer taskNo) {
String url = addressService.selectAddress("AGV_CS", QuantityConstant.WAREHOUSECODE, null, 0) + "cancelAGVTask";
Map<String, Object> map = new HashMap<>();
map.put("TaskNo", taskNo);
String JsonParam = JSON.toJSONString(map);
logger.info("任务下发:{}", JsonParam);
AgvTaskCs agvTaskCs = agvTaskCsService.getById(taskNo);
if (agvTaskCs == null) {
return AjaxResult.error("任务不存在");
}
if (agvTaskCs.getState() >= 100) {
return AjaxResult.success("任务已完成,不能取消");
}
String result = OkHttpUtils.bodypost(url, JsonParam, "", "AGV-CS取消任务");
if (StringUtils.isEmpty(result)) {
throw new ServiceException("ACS接口地址错误或服务器连接不到或返回为空");
}
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
if (ajaxResult.hasErr()) {
return ajaxResult;
}
agvTaskCsService.removeById(agvTaskCs.getTaskNo());
return AjaxResult.success();
}
/**
* 调整优先级
*/
public AjaxResult updateAGVTask(Integer taskNo, Integer priority) {
String url = addressService.selectAddress("AGV_CS", QuantityConstant.WAREHOUSECODE, null, 0) + "updateAGVTask";
AgvTaskCs agvTaskCs = agvTaskCsService.getById(taskNo);
if (agvTaskCs == null) {
return AjaxResult.error("任务不存在");
}
if (agvTaskCs.getState() >= 100) {
return AjaxResult.success("任务已完成,不能取消");
}
Map<String, Object> map = new HashMap<>();
map.put("TaskNo", taskNo);
String JsonParam = JSON.toJSONString(map);
logger.info("任务下发:{}", JsonParam);
String result = OkHttpUtils.bodypost(url, JsonParam, "", "AGV-CS取消任务");
if (StringUtils.isEmpty(result)) {
throw new ServiceException("ACS接口地址错误或服务器连接不到或返回为空");
}
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
if (ajaxResult.hasErr()) {
return ajaxResult;
}
agvTaskCsService.removeById(agvTaskCs.getTaskNo());
return AjaxResult.success();
}
}