AcsServiceImpl.java
9.2 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
package com.huaheng.api.acs.service;
import com.alibaba.fastjson.JSON;
import com.huaheng.api.acs.domain.StateInfoUploadModel;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.address.domain.Address;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.points.domain.Points;
import com.huaheng.pc.config.points.service.PointsService;
import com.huaheng.pc.config.pointsRecord.domain.PointsRecord;
import com.huaheng.pc.config.pointsRecord.service.PointsRecordService;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
import com.huaheng.pc.system.user.service.UserServiceImpl;
import com.huaheng.pc.task.agvTask.domain.AgvTask;
import com.huaheng.pc.task.agvTask.service.IAgvTaskService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderAgvService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* @ClassName AcsServiceImpl
* @Description TODO
* @Author Administrator
* @Date 2019/12/2615:38
*/
@Service
public class AcsServiceImpl implements AcsService {
private static final Logger logger = LoggerFactory.getLogger(AcsServiceImpl.class);
@Autowired
private AddressService addressService;
@Autowired
private PointsService pointsService;
@Autowired
private IUserService userService;
@Autowired
private TaskHeaderService taskHeaderService;
@Autowired
private PointsRecordService pointsRecordService;
@Autowired
private IAgvTaskService agvTaskService;
@Autowired
private TaskHeaderAgvService taskHeaderAgvService;
final String interactionId = "6EAB7794-CFD7-449A-A754-FFDB98CE44C7";
@Override
public AjaxResult StateInfoUpload(StateInfoUploadModel model) {
return null;
}
@Override
public AjaxResult TaskConfirm(AgvTask agvTask) {
return null;
}
private String getUrl(){
Address address =new Address();
address.setParam("AGV");
address.setWarehouseCode(ShiroUtils.getWarehouseCode());
String url=addressService.selectEntity(address).getUrl();
return url;
}
/**
* AGV 任务取消
*/
@Override
public AjaxResult taskCancel(String message)
{
Map<String, Object> map = new HashMap<>();
map.put("interactionId", interactionId);
map.put("reason", message);
String JsonParam = JSON.toJSONString(map);
String url= this.getUrl()+"TaskCancel";
String result = HttpUtils.sendPost(url, JsonParam);
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
return ajaxResult;
}
/**
* AGV 旋转方向
*/
@Override
public AjaxResult TurnOriention(String carNo,String orientation)
{
Map<String, String> map = new HashMap<>();
map.put("carNo", carNo);
map.put("orientation", orientation);
String JsonParam = JSON.toJSONString(map);
String url= this.getUrl()+"TurnOriention";
String result = HttpUtils.sendPost(url, JsonParam);
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
return ajaxResult;
}
//手动叫车
@Transactional
@Override
public AjaxResult ManualCalling(String station,String shelfNo){
AgvTask model = new AgvTask();
model.setTaskHeaderId(666);
model.setTaskDetailId(666);
model.setWarehouseCode(ShiroUtils.getWarehouseCode());
model.setCompanyId(ShiroUtils.getCompanyIdList().get(0));
model.setCompanyCode(ShiroUtils.getCompanyCodeList().get(0));
model.setTaskType("pick");
model.setShelfNo(shelfNo);
model.setStation(station);
model.setStatus(20);
Points points=new Points();
points.setWarehouseCode(ShiroUtils.getWarehouseCode());
points.setGoodsShelfNo(shelfNo);
AjaxResult ajaxResult=new AjaxResult();
points=pointsService.selectEntity(points);
if(points==null){
throw new ServiceException("没有此货架");
}
if(points.getIsLocked()!=1 && points.getIsLocked()!=2) {
model.setFromLocationNo("");
model.setToLocationNo("");
model.setOrientation("A");
ajaxResult = this.TaskAssign(model);
if (!ajaxResult.hasErr()) {
points.setIsLocked(1);
points.setStation(station);
points.setOIntX(points.getIntX());
points.setOIntY(points.getIntY());
pointsService.updateById(points);
}
}else {
throw new ServiceException("该货架已出库");
}
return ajaxResult;
}
/**
* AGV 任务下发
*/
public AjaxResult TaskAssign(AgvTask model)
{
model.setInteractionId(interactionId);
User user = userService.selectUserByLoginName(ShiroUtils.getLoginName());
if(user == null){
model.setPlatform("wms");
}else {
model.setPlatform(user.getUserName());
}
String url = this.getUrl()+"TaskAssign";
String JsonParam = JSON.toJSONString(model);
logger.info("任务下发:{}",JsonParam);
String result = HttpUtils.sendPost(url, JsonParam);
if(StringUtils.isEmpty(result)){
throw new ServiceException("ACS接口地址错误或服务器连接不到或返回为空");
}
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
return ajaxResult;
}
/**
* 设置agv下发任务的实体
*
*/
@Transactional
@Override
public AjaxResult TaskModel(String station,Integer id){
AjaxResult ajaxResult=new AjaxResult();
AgvTask model=new AgvTask();
//通过id查找任务
TaskHeader task= taskHeaderService.getById(id);
if(task==null){
return AjaxResult.error("任务不存在");
}
String containerCode=task.getContainerCode();
String code=containerCode.substring(0,4);
Points points=new Points();
points.setWarehouseCode(ShiroUtils.getWarehouseCode());
points.setGoodsShelfNo(code);
points=pointsService.selectEntity(points);
//任务下发实体
model.setTaskHeaderId(task.getId());
model.setTaskDetailId(task.getId());
model.setTaskType("pick");
model.setStation(station);
model.setWarehouseId(task.getWarehouseId());
model.setWarehouseCode(task.getWarehouseCode());
model.setCompanyId(task.getCompanyId());
model.setCompanyCode(task.getCompanyCode());
model.setStatus(10);
if(containerCode.substring(5,6).equals("1")) {
model.setOrientation("A");
}else {
model.setOrientation("C");
}
//判断货架是否处于1阶段,1阶段为pick阶段。
if (points == null) {
throw new ServiceException("货架不存在!");
}
String ids=id.toString();
if((points.getIsLocked()!=1 && points.getIsLocked()!=2) || !station.equals(points.getStation())){
model.setShelfNo(points.getGoodsShelfNo());
model.setFromLocationNo("");
model.setToLocationNo("");
ajaxResult=this.TaskAssign(model);
if(!ajaxResult.hasErr()){
//修改points表,设为出库状态,修改出库前位置
points.setIsLocked(1);
points.setOIntX(points.getIntX());
points.setOIntY(points.getIntY());
points.setStation(station);
pointsService.updateById(points);
if(!agvTaskService.save(model)){
throw new ServiceException("agv任务下发失败");
}
if(taskHeaderAgvService.sendTaskToAGV(Convert.toIntArray(ids),station).hasErr()){
throw new ServiceException("执行任务失败");
}
PointsRecord pointsRecord = new PointsRecord();
pointsRecord.setCode(points.getGoodsShelfNo());
pointsRecord.setStation(station);
pointsRecord.setCreated(new Date());
pointsRecord.setCreatedby(ShiroUtils.getLoginName());
pointsRecordService.save(pointsRecord);
}else{
return ajaxResult;
}
}else{
if(taskHeaderAgvService.sendTaskToAGV(Convert.toIntArray(ids),station).hasErr()){
throw new ServiceException("执行任务失败");
}
return AjaxResult.success("任务执行成功,该货架已出库");
}
return ajaxResult;
}
}