TaskHeaderRytaskService.java
15.8 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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
package com.huaheng.pc.task.taskHeader.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.api.acs.domain.AgvTask;
import com.huaheng.api.acs.service.AcsService;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
import com.huaheng.common.constant.HttpConstant;
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.common.utils.restful.RestUtil;
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.cycleCountPreference.domain.CycleCountPreference;
import com.huaheng.pc.config.cycleCountPreference.service.CycleCountPreferenceService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.points.domain.Points;
import com.huaheng.pc.config.points.service.PointsService;
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.service.StationService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.cycleCountDetail.domain.CycleCountDetail;
import com.huaheng.pc.inventory.cycleCountDetail.service.CycleCountDetailService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.receipt.receiving.service.ReceivingService;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import com.huaheng.pc.task.agvTask.controller.AgvTaskController;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.MobileTask;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.mapper.TaskHeaderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class TaskHeaderRytaskService extends ServiceImpl<TaskHeaderMapper, TaskHeader> {
@Resource
private LocationService locationService;
@Resource
private TaskAssignService taskAssignService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private PointsService pointsService;
@Resource
private ZoneService zoneService;
@Resource
private StationService stationService;
@Resource
private WorkTaskService workTaskService;
/**展厅移库演示*/
public AjaxResult transferTask(String roadWay){
try {
String s=null;
if(roadWay.equals("1")){
s="M";
}else if(roadWay.equals("2")){
s="S";
}
final int t = getUnCompleteTaskList(s);
if(t>3){
return AjaxResult.error();
}
final Location location = locationService.getLocationOfRule(Integer.valueOf(roadWay));
if(StringUtils.isNull(location)){
return AjaxResult.error();
}
final AjaxResult ajax =createTransferTask(location.getCode());
TaskHeader data = (TaskHeader) ajax.getData();
taskAssignService.wcsTaskAssign(data);
return AjaxResult.success();
}catch (Exception e){
e.printStackTrace();
return AjaxResult.error();
}
}
private int getUnCompleteTaskList(String contianerCode) {
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getTaskType, 800);
taskHeaderLambdaQueryWrapper.lt(TaskHeader::getStatus, 100);
taskHeaderLambdaQueryWrapper.likeRight(StringUtils.isNotEmpty(contianerCode),TaskHeader::getContainerCode, contianerCode);
int taskHeaderList = this.count(taskHeaderLambdaQueryWrapper);
return taskHeaderList;
}
@Transactional
public AjaxResult createTransferTask(String sourceLocation) {
String warehouseCode="CS0001";
Location temp1 = new Location();
temp1.setCode(sourceLocation);
temp1.setWarehouseCode(warehouseCode);
Location location = locationService.selectFirstEntity(temp1);
if(location==null){
return AjaxResult.error("源库位:"+sourceLocation+"未找到");
}
if(!location.getStatus().equals("empty")){
return AjaxResult.error("源库位:"+sourceLocation+"状态非空闲");
}
if(StringUtils.isEmpty(location.getContainerCode())){
return AjaxResult.error("源库位:"+sourceLocation+"不存在托盘");
}
if(!location.getZoneCode().equals("LK")){
return AjaxResult.error("该库位:"+sourceLocation+"不是立库库位");
}
if(location.getZoneCode().equals("LK")){
TaskHeader task =new TaskHeader();
task.setContainerCode(location.getContainerCode());
task.setStatus(10);
task =this.selectFirstEntity(task);
if(task!=null){
return AjaxResult.error(location.getContainerCode()+"该容器已有任务");
}
}
//这里增加组盘校验,如果此托盘存在未完成的组盘数据,则不能移库
//校验入库组盘
int count1 = inventoryHeaderService.getUncompleteReceiptContainer(sourceLocation,warehouseCode);
if(count1>0){
return AjaxResult.error("源库位:"+sourceLocation+"存在入库组盘,不能移库");
}
int count2 = inventoryHeaderService.getUncompleteShipmentContainer(sourceLocation,warehouseCode);
if(count2>0){
return AjaxResult.error("源库位:"+sourceLocation+"存在出库组盘,不能移库");
}
Location loc=new Location();
loc.setCode(sourceLocation);
loc.setRoadway("3");
int line;
int layer=(int)(Math.random()*10);
if (location.getContainerCode().startsWith("L")||location.getContainerCode().startsWith("B")) {
if(location.getIColumn()<=8){
line=(int)(Math.random()*9+8);
}else {
line=(int)(Math.random()*8);
}
loc.setIColumn(line);
loc.setILayer(layer);
loc.setStatus("empty");
loc = locationService.selectFirstEntity(loc);
}
if(loc ==null){
if(location.getContainerCode().startsWith("S")){
loc = locationService.getLocationOfRule(2);
}else if(location.getContainerCode().startsWith("M")){
loc = locationService.getLocationOfRule(1);
}else {
loc = locationService.getLocationOfRule(3);
}
}
if(loc == null){
return AjaxResult.error("立库库位已用完,无法移库");
}
TaskHeader task=new TaskHeader();
task.setTaskType(800);
task.setZoneCode(location.getZoneCode());
task.setContainerCode(location.getContainerCode());
task.setFromLocation(sourceLocation);
task.setToLocation(loc.getCode());
task.setCreatedBy("ck");
task=createTask(warehouseCode,task);
//更新货位状态为预定
location.setStatus("lock");
loc.setStatus("lock");
loc.setUserDef1("0");
locationService.updateById(location);
locationService.updateById(loc);
return AjaxResult.success(task);
}
private TaskHeader selectFirstEntity( TaskHeader task){
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getStatus, 10);
taskHeaderLambdaQueryWrapper.eq(StringUtils.isNotEmpty(task.getContainerCode()),TaskHeader::getContainerCode, task.getContainerCode());
taskHeaderLambdaQueryWrapper.last("limit 1");
return this.getOne(taskHeaderLambdaQueryWrapper);
}
/**库存监控出库查看*/
@Transactional
public AjaxResult checkLocationCode(String locationCode){
String warehouseCode="CS0001";
Location location = new Location();
location.setCode(locationCode);
location.setWarehouseCode("CS0001");
location.setDeleted(false);
Location loc = locationService.selectFirstEntity(location);
if(!loc.getStatus().equals("empty")){
return AjaxResult.error(locationCode+"状态非空闲,操作失败");
}
if(StringUtils.isEmpty(loc.getContainerCode())){
return AjaxResult.error(locationCode+"没有托盘,操作失败");
}
//生成出库查看任务
TaskHeader task=new TaskHeader();
task.setPort("1");
if(loc.getLocationType().equals("A")) {
task.setZoneCode("AGV");
}else if(loc.getLocationType().equals("L")){
task.setZoneCode("LK");
}
task.setRoadway(loc.getRoadway());
task.setContainerCode(loc.getContainerCode());
if(loc.getContainerCode().startsWith("S")){
task.setPort("P1004");
}else if(loc.getContainerCode().startsWith("L")||loc.getContainerCode().startsWith("B")){
task.setPort("P1002");
}
task.setTaskType(900);
task.setFromLocation(loc.getCode());
task.setToLocation(loc.getCode());
task.setCreatedBy("admin");
task=createTask(warehouseCode,task);
//如果是AGV的需要下发agv任务
if(loc.getLocationType().equals("A")) {
AgvTask model = new AgvTask();
String containerCode = loc.getContainerCode();
Points points = new Points();
points.setGoodsShelfNo(containerCode.substring(0, 4));
points.setWarehouseCode("CS0001");
points = pointsService.selectEntity(points);
if (points != null && points.getIsLocked()!=1) {
model.setTaskHeaderId(task.getId());
model.setTaskDetailId(task.getId());
model.setTaskType("pick");
model.setShelfNo(points.getGoodsShelfNo());
model.setStation("ws01");
model.setFromLocationNo("");
model.setToLocationNo("");
if (containerCode.substring(5, 7).equals("1")) {
model.setOrientation("A");
} else {
model.setOrientation("C");
}
// if (!acsService.TaskAssign(model).hasErr()) {
// points.setIsLocked(1);
// pointsService.updateById(points);
// model.setWarehouseCode(task.getWarehouseCode());
// model.setCompanyCode(task.getCompanyCode());
// agvTaskMapper.insertModel(model);
// }
}
}
//出库时先锁库位状态
loc.setStatus("lock");
locationService.updateById(loc);
return AjaxResult.success(task.getId());
}
private TaskHeader createTask(String warehouseCode,TaskHeader task){
task.setWarehouseCode(warehouseCode);
task.setWarehouseCode("CS0001");
task.setCompanyCode("cshuahengweld");
//这里默认一个0
task.setPriority(0);
task.setPort(null);
task.setStatus(1);
task.setCreated(new Date());
this.save(task);
return task;
}
public void innerAutoPush(String[] areas) {
String warehouseCode = "CS0001";
for(String area : areas) {
Zone zone = zoneService.getZoneByArea(area);
LambdaQueryWrapper<InventoryHeader> inventoryHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryHeaderLambdaQueryWrapper.eq(InventoryHeader::getZoneCode, zone.getCode());
List<InventoryHeader> inventoryHeaderList = inventoryHeaderService.list(inventoryHeaderLambdaQueryWrapper);
List<InventoryHeader> removeInventoryHeaderList = new ArrayList<>();
for(InventoryHeader inventoryHeader : inventoryHeaderList) {
String locationCode = inventoryHeader.getLocationCode();
Location location = locationService.getLocationByCode(locationCode, warehouseCode);
if(location.getStatus().equals(QuantityConstant.STATUS_LOCATION_LOCK)) {
removeInventoryHeaderList.add(inventoryHeader);
}
}
inventoryHeaderList.removeAll(removeInventoryHeaderList);
int size = inventoryHeaderList.size();
int index = 0;
LambdaQueryWrapper<Station> stationLambdaQueryWrapper = Wrappers.lambdaQuery();
stationLambdaQueryWrapper.eq(Station::getArea, area)
.eq(Station::getType, QuantityConstant.STATION_PICK);
List<Station> stationList = stationService.list(stationLambdaQueryWrapper);
List<Station> removeStation = new ArrayList<>();
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getZoneCode, zone.getCode())
.eq(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_VIEW)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
for(Station station : stationList) {
String port = station.getCode();
for(TaskHeader taskHeader : taskHeaderList) {
if(port.equals(taskHeader.getPort())) {
removeStation.add(station);
break;
}
}
}
stationList.removeAll(removeStation);
for(int i=0; i < stationList.size(); i++) {
Station station = stationList.get(i);
InventoryHeader inventoryHeader = inventoryHeaderList.get(i);
List<Integer> ids = new ArrayList<>();
ids.add(inventoryHeader.getId());
workTaskService.createCheckOutTaskByIds(ids, station.getCode());
}
}
}
}