AcsByCSWXFService.java
5.94 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
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 org.springframework.transaction.annotation.Transactional;
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.task.agvTask.domain.AgvTask;
import com.huaheng.pc.task.agvTask.service.AgvTaskService;
import com.huaheng.pc.task.agvTaskCS.domain.AgvTaskCsDomain;
/**
* 长沙agv交互接口:维修房的长沙agv接口,用的agvTask表
*/
@Service
public class AcsByCSWXFService {
private static final Logger logger = LoggerFactory.getLogger(AcsByCSWXFService.class);
@Resource
private AgvTaskService agvTaskService;
@Resource
private AddressService addressService;
@Resource
private AcsTaskAndCSService acsTaskAndCSService;
/**
* 下发任务给ACS
*/
public AjaxResult createAGVTask(AgvTask agvTask, String area) {
AgvTaskCsDomain agvTaskCsDomain = acsTaskAndCSService.getAgvCsByTask(agvTask);
String url = addressService.selectAddress("AGV", QuantityConstant.WAREHOUSECODE, area, 0) + "createAGVTask";
String JsonParam = JSON.toJSONString(agvTaskCsDomain);
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()) {
agvTask.setRemark(ajaxResult.getMsg());
agvTaskService.updateById(agvTask);
return AjaxResult.error(ajaxResult.getMessage());
} else {
agvTask.setRemark(ajaxResult.getMsg());
agvTaskService.updateById(agvTask);
}
// 下发成功
agvTask.setState(QuantityConstant.AGV_TASK_STATUS_RELEASE);
agvTaskService.updateById(agvTask);
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);
AgvTask agvTaskCs = agvTaskService.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;
}
agvTaskService.removeById(agvTaskCs.getTaskNo());
return AjaxResult.success();
}
/**
* 调整优先级
*/
public AjaxResult updateAGVTask(Integer taskNo, Integer priority) {
String url = addressService.selectAddress("AGV_CS", QuantityConstant.WAREHOUSECODE, null, 0) + "updateAGVTask";
AgvTask agvTaskCs = agvTaskService.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);
map.put("priority", priority);
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;
}
agvTaskCs.setTaskLevel(priority);
agvTaskService.updateById(agvTaskCs);
return AjaxResult.success();
}
@Transactional(rollbackFor = Exception.class)
public AjaxResult notifyAGVTask(String taskNo, String carNo, Integer status, String updateBy) {
AgvTask agvTask = agvTaskService.getById(taskNo);
if (agvTask == null) {
return AjaxResult.error("没有找到对应AGV任务,任务号为" + taskNo);
}
if (agvTask.getState() < QuantityConstant.AGV_TASK_STATUS_RELEASE) {
return AjaxResult.success("该任务状态还未下发,任务号为" + taskNo);
}
if (agvTask.getState() == status) {
return AjaxResult.success("该任务状态已更新,任务号为" + taskNo);
}
agvTask.setState(status);
agvTask.setAgvNo(carNo);
agvTask.setLastUpdatedBy(updateBy);
boolean result = agvTaskService.updateById(agvTask);
if (!result) {
return AjaxResult.error("更新任务信息失败 ");
}
if (status == 100) {
// 更新库存
}
return AjaxResult.success("更新叉车库任务信息成功");
}
}