AgvTaskCSCreateService.java
7.44 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
package com.huaheng.api.acs.service;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.api.acs.domain.AgvPort;
import com.huaheng.api.acs.domain.AgvTaskCS;
import com.huaheng.api.acs.domain.ToAgvTask;
import com.huaheng.api.acs.mapper.AgvTaskCsMapper;
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.http.OkHttpUtils;
import com.huaheng.common.utils.security.ShiroUtils;
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.containerType.domain.ContainerType;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.service.StationService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
@Service
public class AgvTaskCSCreateService {
@Resource
private AgvTaskCSService agvTaskCSService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private ContainerService containerService;
@Resource
private StationService stationService;
/**
* 机加立库创建agv任务
* 查找taskheader表,JLK库区的未完成任务,根据Taskheader任务创建agv任务
*/
public void createAgvTaskForJLK(){
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getWarehouseCode, QuantityConstant.WAREHOUSE_KS);
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getZoneCode, "JLK");
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_BUILD);
taskHeaderLambdaQueryWrapper.apply("(pickingCartPos is not null and pickingCartPos != '') ");
// taskHeaderLambdaQueryWrapper.in(TaskHeader::getInternalTaskType, QuantityConstant.TASK_INTENERTYPE_RECEIPT,QuantityConstant.TASK_INTENERTYPE_SHIPMENT);
taskHeaderLambdaQueryWrapper.last("order by id asc");
List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
//查找机加库入库。出库任务
for (TaskHeader taskHeader : taskHeaderList) {
try {
taskHeaderService.sendTaskToWcs(Convert.toIntArray(taskHeader.getId().toString()));
// createAgvTaskForJLKTask(taskHeader);
} catch(Exception e){
}
}
}
public void createAgvTaskForJLKTask(TaskHeader taskHeader ){
if (StringUtils.isNotEmpty(taskHeader.getPickingCartPos())) {
String[] pickingCartPos = taskHeader.getPickingCartPos().split(",");
AgvTaskCS agvTask = new AgvTaskCS();
switch (taskHeader.getTaskType()) {
case QuantityConstant.TASK_TYPE_WHOLERECEIPT:
case QuantityConstant.TASK_TYPE_EMPTYRECEIPT:
agvTask.setTaskType(QuantityConstant.AGV_TYPE_TAKE);
agvTask.setFromPort(taskHeader.getPickingCartPos());
agvTask.setToPort(taskHeader.getPort());
break;
case QuantityConstant.TASK_TYPE_WHOLESHIPMENT:
case QuantityConstant.TASK_TYPE_EMPTYSHIPMENT:
// agvTask.setTaskType(QuantityConstant.AGV_TYPE_RELEASE);
// agvTask.setFromPort(taskHeader.getPort());
// agvTask.setToPort(taskHeader.getPickingCartPos());
break;
case QuantityConstant.TASK_TYPE_OVER_STATION:
agvTask.setTaskType(QuantityConstant.AGV_TYPE_TAKE);
agvTask.setFromPort(taskHeader.getFromLocation());
agvTask.setToPort(taskHeader.getPort());
break;
default:
return;
}
AgvTaskCS taskCS=agvTaskCSService.getAgvTaskByHeaderId(taskHeader,agvTask.getTaskType());
if(taskCS!=null){
//有agv任务则不重新生成
return;
}
agvTask.setPriority(100);
agvTask.setTaskHeaderId(taskHeader.getId());
agvTask.setTaskHeaderType(taskHeader.getTaskType());
agvTask.setInternalTaskType(taskHeader.getInternalTaskType());
agvTask.setContainerCode(taskHeader.getContainerCode());
Container container=containerService.getContainerByCode(taskHeader.getContainerCode(),taskHeader.getWarehouseCode());
agvTask.setZoneCode(taskHeader.getZoneCode());
agvTask.setNumber(container.getNumber());
agvTask.setWarehouseCode(taskHeader.getWarehouseCode());
agvTask.setStatus(QuantityConstant.AGV_TASK_STATUS_BUILD);
agvTask.setCreatedTime(new Date());
agvTask.setCreatedBy(taskHeader.getCreatedBy());
if (!agvTaskCSService.save(agvTask)) {
throw new ServiceException("保存AGV任务失败");
}
}
}
/**
* 新建线程更改taskheader表
* @param task
*/
@Transactional(rollbackFor = Exception.class)
public void autoSaveAgvTaskBySimpleAgvB(TaskHeader task){
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("使用匿名内部类,实例Runnable接口作为构造参数");
autoSaveAgvTaskBySimpleAgv(task);
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getId, task.getId());
TaskHeader taskHeader1 = new TaskHeader();
taskHeader1.setAutoCreateAgv(2);
taskHeaderService.update(taskHeader1, taskHeaderLambdaQueryWrapper);
}
});
thread.start();
}
/**
* 长沙立库和昆山机加库出库任务,创建agv任务
* @param taskHeader
*/
public void autoSaveAgvTaskBySimpleAgv(TaskHeader taskHeader){
TaskHeader task=taskHeaderService.getById(taskHeader.getId());
if(task.getStatus()!=100){
return;
}
switch (task.getTaskType()){
case QuantityConstant.TASK_TYPE_WHOLESHIPMENT:
case QuantityConstant.TASK_TYPE_EMPTYSHIPMENT:
break;
default:
return;
}
if(StringUtils.isEmpty(task.getToPort())){
return;
}
AgvTaskCS agvTask2=agvTaskCSService.saveAgvTaskBySimpleAgv(task,null);
}
}