AcsCSService.java
15.1 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
package com.huaheng.api.acs.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.api.acs.domain.AcsWeightHeight;
import com.huaheng.api.acs.domain.AgvTaskCS;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.warecellAllocation.WarecellAllocationService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import static com.huaheng.common.constant.QuantityConstant.*;
/**
* @ClassName AcsServiceImpl
* @Description TODO
* @Author Administrator
* @Date 2019/12/2615:38
*/
@Service
public class AcsCSService {
private static final Logger logger = LoggerFactory.getLogger(AcsCSService.class);
@Resource
private AgvTaskCSService agvTaskService;
@Resource
private AddressService addressService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private ContainerService containerService;
@Resource
private WarecellAllocationService warecellAllocationService;
@Resource
private ConfigService configService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
private LocationService locationService;
@Resource
private AgvPortService agvPortService;
/**
* 更新AGV状态
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult notifyAGVTask(String taskNo, String carNo, int status, String updateBy) {
AgvTaskCS agvTask = agvTaskService.getById(taskNo);
if (agvTask == null) {
return AjaxResult.error("没有找到对应AGV任务,任务号为" + taskNo);
}
if (agvTask.getStatus() < QuantityConstant.AGV_TASK_STATUS_RELEASE) {
// return AjaxResult.success("该任务状态还未下发,任务号为" + taskNo);
}
if (StringUtils.isEmpty(agvTask.getFromPort())||StringUtils.isEmpty(agvTask.getToPort())) {
return AjaxResult.success("该任务无agv起点和终点信息:id=" + taskNo);
}
if (agvTask.getStatus() == status) {
return AjaxResult.success("该任务状态已更新,任务号为" + taskNo);
}
if(StringUtils.isNotNull(agvTask.getPreTaskNo())){
AgvTaskCS agvTaskPre = agvTaskService.getById(agvTask.getPreTaskNo());
if(agvTaskPre!=null&&agvTaskPre.getStatus()<100){
return AjaxResult.success("该任务状态已更新,任务号为" + taskNo+"的前置任务号还未完成,请先完成出库任务");
}
}
agvTask.setStatus(status);
agvTask.setCarNo(carNo);
agvTask.setUpdatedBy(updateBy);
boolean result = agvTaskService.updateById(agvTask);
if (!result) {
return AjaxResult.error("更新任务信息失败 ");
}
//当status为100时,则完成任务
//补充入库:先出库 agvtaskid2 状态400,后入库 agvtaskid 状态300
//分拣出库:先出库 agvtaskid 状态400,后入库 agvtaskid2 状态300
if (status == 100) {
TaskHeader taskHeader = taskHeaderService.getOne(new LambdaQueryWrapper<TaskHeader>().eq(TaskHeader::getId, agvTask.getTaskHeaderId()));
String[] weight = new String[]{"0"};
if (taskHeader != null) {
switch (taskHeader.getTaskType()) {
case QuantityConstant.TASK_TYPE_WHOLERECEIPT:
case QuantityConstant.TASK_TYPE_WHOLESHIPMENT:
case QuantityConstant.TASK_TYPE_EMPTYRECEIPT:
case QuantityConstant.TASK_TYPE_EMPTYSHIPMENT:
if(!agvTask.getTaskType().equals(AGV_TYPE_MOVE)){
return taskHeaderService.completeTaskByWMS(Convert.toIntArray(String.valueOf(taskHeader.getId())), weight);
}
break;
case QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT:
case QuantityConstant.TASK_TYPE_SORTINGSHIPMENT:
case QuantityConstant.TASK_TYPE_VIEW:
//agv入库任务时则完成任务
if (agvTask.getTaskType().equals(QuantityConstant.AGV_TYPE_TAKE)) {
return taskHeaderService.completeTaskByWMS(Convert.toIntArray(String.valueOf(taskHeader.getId())), weight);
}
break;
case QuantityConstant.TASK_TYPE_OVER_STATION:
if (agvTask.getTaskType().equals(AGV_TYPE_MOVE)) {
return taskHeaderService.completeTaskByWMS(Convert.toIntArray(String.valueOf(taskHeader.getId())), weight);
}
break;
default:
break;
}
}
}
if(agvTask.getZoneCode().equals("LK")){
if(status==100){
agvPortService.updateStatus(agvTask.getToPort(), QuantityConstant.STATUS_POSITION_EMPTY);
}
}
return AjaxResult.success("更新任务信息成功");
}
/**
* 1、保存重量高度,查找任务,根据重量高度分配库位,任务库位
* 2、入库更新任务主表站点
* 3、更新agv任务表起点和终点
*
* @param acsWeightHeight
* @return
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult weightAndHeightByContainer(AcsWeightHeight acsWeightHeight) {
//检验参数
Container container = checkParams(acsWeightHeight);
//根据托盘号查找未完成任务
TaskHeader taskHeader = getTaskHeader(acsWeightHeight);
if(taskHeader==null){
return AjaxResult.error("找不到该托盘的任务");
}
//更新agv起点终点
AgvTaskCS agvTask=null;
//补充入库:先出库 agvtaskid2 状态400,后入库 agvtaskid 状态300
//分拣出库:先出库 agvtaskid 状态400,后入库 agvtaskid2 状态300
switch (taskHeader.getTaskType()) {
case QuantityConstant.TASK_TYPE_WHOLESHIPMENT:
case QuantityConstant.TASK_TYPE_EMPTYSHIPMENT:
return AjaxResult.success(acsWeightHeight.getContainerCode() + ",该任务是出库任务,不需要请求库位");
case QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT:
case QuantityConstant.TASK_TYPE_SORTINGSHIPMENT:
case QuantityConstant.TASK_TYPE_VIEW:
//需要回库的任务,判断是否完成agv出库任务
AgvTaskCS agvTaskShip = agvTaskService.getAgvTaskByHeaderId(taskHeader, AGV_TYPE_RELEASE);
if(agvTaskShip!=null&&agvTaskShip.getStatus()<100){
return AjaxResult.success(acsWeightHeight.getContainerCode() + ",该任务出库任务还未完成");
}
break;
}
agvTask = agvTaskService.getAgvTaskByHeaderId(taskHeader, AGV_TYPE_TAKE);
if(agvTask==null){
return AjaxResult.error( "找不到agv入库任务");
}
if (agvTask.getStatus() >= QuantityConstant.AGV_TASK_STATUS_RELEASE) {
return AjaxResult.success(agvTask.getId() + "agv回库任务已下发,任务已有起点中终点");
}
switch (taskHeader.getTaskType()) {
case QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT:
case TASK_TYPE_SORTINGSHIPMENT:
case TASK_TYPE_VIEW:
//整盘入库、补充入库、空托盘入库,没有库位可分配,直接完成任务
TaskHeader taskHeader1 = new TaskHeader();
taskHeader1.setId(taskHeader.getId());
taskHeader1.setToLocation(taskHeader.getFromLocation());
taskHeaderService.updateById(taskHeader1);
if (agvTask != null) {
agvTask.setToPort(taskHeader.getToLocation());
agvTask.setFromPort(acsWeightHeight.getFormPort());
agvTaskService.updateById(agvTask);
}
return AjaxResult.success().setData(taskHeader.getToLocation());
default:
break;
}
container.setWeight(acsWeightHeight.getWeight());
container.setHigh(acsWeightHeight.getHeight());
containerService.updateById(container);
//分配库位,更新任务表库位,巷道信息
taskHeader = updateTaskHeaderLocation(taskHeader, acsWeightHeight);
//更新agv起点终点
if (agvTask != null) {
agvTask.setToPort(taskHeader.getToLocation());
agvTask.setFromPort(acsWeightHeight.getFormPort());
agvTaskService.updateById(agvTask);
}
return AjaxResult.success().setData(taskHeader.getToLocation());
}
/**
* 根据托盘号查找未完成任务
*/
public TaskHeader getTaskHeader(AcsWeightHeight acsWeightHeight) {
List<TaskHeader> taskHeaders = taskHeaderService.list(new LambdaQueryWrapper<TaskHeader>()
.eq(TaskHeader::getContainerCode, acsWeightHeight.getContainerCode())
//生成任务
.lt(TaskHeader::getStatus, TASK_STATUS_COMPLETED)
//整盘入库、补充入库、出库查询
// .in(TaskHeader::getTaskType, TASK_TYPE_WHOLERECEIPT, TASK_TYPE_SUPPLEMENTRECEIPT, TASK_TYPE_VIEW, TASK_TYPE_SORTINGSHIPMENT)
.orderByDesc(TaskHeader::getId));
if (taskHeaders == null || taskHeaders.size() == 0){
throw new ServiceException("传递AGV托盘重量高度接口," + acsWeightHeight.getContainerCode() + "该托盘在任务中找不到,请先生成任务");
}
TaskHeader taskHeader = taskHeaders.get(0);
//更新任务主表站点
taskHeader.setPort(acsWeightHeight.getFormPort());
taskHeader.setWeight(acsWeightHeight.getWeight().toString());
taskHeaderService.updateById(taskHeader);
return taskHeader;
}
/**
* 分配库位,更新任务表库位,巷道信息
*/
public TaskHeader updateTaskHeaderLocation(TaskHeader taskHeader, AcsWeightHeight acsWeightHeight) {
// if (taskHeader.getTaskType() == QuantityConstant.TASK_TYPE_WHOLERECEIPT) {
WcsTask wcsTask = createWcsTask(taskHeader.getId().toString(), acsWeightHeight.getHeight(), acsWeightHeight.getWeight());
AjaxResult ajaxResult = warecellAllocationService.warecellAllocation(wcsTask);
if (ajaxResult.hasErr()) {
throw new ServiceException("传递AGV托盘重量高度,请求库位时:" + ajaxResult.getMsg());
}
WcsTask wcsTask1 = (WcsTask) ajaxResult.getData();
taskHeader.setRoadway(wcsTask1.getRoadWay());
taskHeader.setToLocation(wcsTask1.getToLocationCode());
// } else {
// Location location = locationService.getLocationByCode(taskHeader.getToLocation());
// taskHeader.setRoadway(location.getRoadway());
// }
return taskHeader;
}
/**
* 检验参数
*/
public Container checkParams(AcsWeightHeight acsWeightHeight) {
if (acsWeightHeight == null) {
throw new ServiceException("传递AGV托盘重量高度,对象为空");
}
if (StringUtils.isEmpty(acsWeightHeight.getWarehouseCode())) {
throw new ServiceException("传递AGV托盘重量高度,仓库为空");
}
BigDecimal weight = acsWeightHeight.getWeight();
if (weight == null) {
throw new ServiceException("传递AGV托盘重量高度,重量为空");
}
// String weight_config = configService.getKey(QuantityConstant.CONFIG_WEGHT,acsWeightHeight.getWarehouseCode());//容器重量
// BigDecimal weight_bigdecimal = new BigDecimal(weight_config);
// if (weight.compareTo(weight_bigdecimal) > 0) {
// throw new ServiceException("传递AGV托盘重量高度," + weight + "重量超过单个托盘限定重量");
// }
BigDecimal height = acsWeightHeight.getHeight();
if (height == null) {
throw new ServiceException("传递AGV托盘重量高度,高度为空");
}
/*String height_config = configService.getKey(QuantityConstant.CONFIG_HEIGHT);//容器高度
BigDecimal height_bigdecimal=new BigDecimal(height_config);
if(height.compareTo(height_bigdecimal)>0){
throw new ServiceException("传递AGV托盘重量高度,"+height+"高度超过单个托盘限定高度");
}*/
String containerCode = acsWeightHeight.getContainerCode();
if (StringUtils.isEmpty(containerCode)) {
throw new ServiceException("传递AGV托盘重量高度,托盘号为空");
}
String fromPort = acsWeightHeight.getFormPort();
if (StringUtils.isEmpty(fromPort)) {
throw new ServiceException("传递AGV托盘重量高度,起点为空");
}
//log.info(containerCode);
Container container = containerService.getContainerByCode(containerCode, acsWeightHeight.getWarehouseCode());
//log.info(container.toString());
if (container == null) {
throw new ServiceException("传递AGV托盘重量高度," + containerCode + "容器在容器管理中找不到");
}
return container;
}
public WcsTask createWcsTask(String taskNo, BigDecimal height, BigDecimal weight) {
WcsTask wcsTask = new WcsTask();
wcsTask.setTaskNo(taskNo);
wcsTask.setWarehouseCode("CS0001");
wcsTask.setArea("9");
wcsTask.setRoadWay("1");
wcsTask.setLength("100");
//String height_config = configService.getKey(QuantityConstant.CONFIG_AGV_HEIGHT);//容器重量
//判断高低库位,1.4以下低库位,1.4-1。5高库位
/*if(height.compareTo(new BigDecimal(height_config))>=0){
wcsTask.setHeight("2");
}else{
wcsTask.setHeight("1");
}*/
wcsTask.setHeight(String.valueOf(height.intValue()));
wcsTask.setWidth("1000");
wcsTask.setWeight(weight.toString());
return wcsTask;
}
}