RcsServiceImpl.java
9.19 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
package com.huaheng.api.rcs.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.api.acs.domain.AgvTaskCS;
import com.huaheng.api.acs.service.AgvTaskCSService;
import com.huaheng.api.mes.domain.MesTask;
import com.huaheng.api.mes.service.MesService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.framework.web.domain.AjaxResult;
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.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.sendMail.service.MailService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
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.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
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 org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;
/**
* RCS实现层
* @author xcq
*/
@Service
public class RcsServiceImpl implements RcsService{
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
private RcsService rcsService;
@Resource
private ContainerService containerService;
@Resource
private LocationService locationService;
@Resource
private AgvTaskCSService agvTaskCSService;
@Override
@Transactional
public AjaxResult receiptTaskComplete(AgvTaskCS agvTaskCS) {
// 查询入库单
LambdaQueryWrapper<ReceiptHeader> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(ReceiptHeader::getCode, agvTaskCS.getFromUserDef1());
ReceiptHeader receiptHeader = receiptHeaderService.getOne(queryWrapper);
if (receiptHeader == null){
return AjaxResult.error("查询入库单失败!");
}
LambdaQueryWrapper<ReceiptDetail> query = Wrappers.lambdaQuery();
query.eq(ReceiptDetail::getReceiptId, receiptHeader.getId());
ReceiptDetail receiptDetail = receiptDetailService.getOne(query);
if (receiptDetail == null){
return AjaxResult.error("查询入库单详情失败!");
}
// 获取可用容器编码
Container container = rcsService.getContainer(QuantityConstant.GT_RECEIPT_TYPE);
if (container == null){
return AjaxResult.error("无可用托盘码!");
}
// 获取入库库位
Location location = locationService.getLocationByCode(agvTaskCS.getToPort(), QuantityConstant.WAREHOUSE_KS);
if (location == null){
return AjaxResult.error("根据库位编码"+agvTaskCS.getToPort()+"查询入库库位失败!");
}
// 添加库存
AjaxResult result = rcsService.addInventory(receiptDetail, container.getCode(), location.getCode(), location.getZoneCode());
if (result.hasErr()){
return result;
}
Location locationTemp = new Location();
locationTemp.setId(location.getId());
locationTemp.setContainerCode(container.getCode());
locationTemp.setStatus(QuantityConstant.STATUS_LOCATION_EMPTY);
if (!locationService.updateById(locationTemp)){
throw new RuntimeException("更新库位数据失败!");
}
Container containerTemp = new Container();
containerTemp.setId(container.getId());
containerTemp.setLocationCode(location.getCode());
containerTemp.setStatus(QuantityConstant.STATUS_CONTAINER_SOME);
if (!containerService.updateById(containerTemp)){
throw new RuntimeException("更新容器状态失败!");
}
AgvTaskCS agvTaskCSTemp = new AgvTaskCS();
agvTaskCSTemp.setId(agvTaskCS.getId());
agvTaskCSTemp.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
if (!agvTaskCSService.updateById(agvTaskCSTemp)){
throw new RuntimeException("更新任务状态失败!");
}
ReceiptHeader receiptHeaderTemp = new ReceiptHeader();
receiptHeaderTemp.setId(receiptHeader.getId());
receiptHeaderTemp.setLastStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
receiptHeaderTemp.setFirstStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
if (!receiptHeaderService.updateById(receiptHeaderTemp)){
throw new RuntimeException("更新入库单头表失败!");
}
return AjaxResult.success("任务状态更新成功!");
}
@Override
public AjaxResult addInventory(ReceiptDetail receiptDetail,String containerCode, String locationCode, String zoneCode) {
// 添加库存头
InventoryHeader inventoryHeader = new InventoryHeader();
inventoryHeader.setCreatedBy(QuantityConstant.PLATFORM_MES);
inventoryHeader.setLocationCode(locationCode);
inventoryHeader.setContainerCode(containerCode);
inventoryHeader.setWarehouseCode(QuantityConstant.WAREHOUSE_KS);
inventoryHeader.setCompanyCode(QuantityConstant.COMPANY_GT);
inventoryHeader.setContainerStatus(QuantityConstant.STATUS_CONTAINER_SOME);
inventoryHeader.setTotalQty(receiptDetail.getQty());
inventoryHeader.setTotalLines(1);
inventoryHeader.setZoneCode(zoneCode);
inventoryHeader.setLastUpdatedBy(QuantityConstant.PLATFORM_MES);
if (!inventoryHeaderService.save(inventoryHeader)){
throw new RuntimeException("新增库存头失败!");
}
InventoryDetail inventoryDetail = new InventoryDetail();
inventoryDetail.setInventoryHeaderId(inventoryHeader.getId());
inventoryDetail.setWarehouseCode(inventoryHeader.getWarehouseCode());
inventoryDetail.setCompanyCode(inventoryHeader.getCompanyCode());
inventoryDetail.setLocationCode(locationCode);
inventoryDetail.setContainerCode(containerCode);
inventoryDetail.setMaterialName(receiptDetail.getMaterialName());
inventoryDetail.setMaterialCode(receiptDetail.getMaterialCode());
inventoryDetail.setMaterialSpec(receiptDetail.getMaterialSpec());
inventoryDetail.setMaterialUnit(receiptDetail.getMaterialUnit());
inventoryDetail.setQty(receiptDetail.getQty());
inventoryDetail.setTaskQty(BigDecimal.ZERO);
inventoryDetail.setReceiptCode(receiptDetail.getReceiptCode());
inventoryDetail.setReceiptDetailId(receiptDetail.getId());
inventoryDetail.setInventorySts(QuantityConstant.GOOD);
inventoryDetail.setZoneCode(zoneCode);
inventoryDetail.setCreatedBy(inventoryHeader.getCreatedBy());
inventoryDetail.setLastUpdatedBy(QuantityConstant.PLATFORM_MES);
inventoryDetail.setReferCode(receiptDetail.getReferCode());
if (!inventoryDetailService.save(inventoryDetail)){
throw new RuntimeException("新增库存详情失败!");
}
return AjaxResult.success("库存添加成功!");
}
@Override
public Container getContainer(String containerType) {
LambdaQueryWrapper<Container> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(Container::getContainerType, containerType)
.eq(Container::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
.eq(Container::getLocationCode, "").last("LIMIT 1");
return containerService.getOne(queryWrapper);
}
@Resource
private ZoneService zoneService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private MesService mesService;
@Override
public void autoCreateGTAgvTaskService() {
LambdaQueryWrapper<TaskHeader> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.lt(TaskHeader::getStatus, QuantityConstant.AGV_TASK_STATUS_RELEASE)
.eq(TaskHeader::getZoneCode, QuantityConstant.GT_RECEIPT_TYPE);
List<TaskHeader> taskHeaderList = taskHeaderService.list(queryWrapper);
if (taskHeaderList != null && taskHeaderList.size() > 0){
for (TaskHeader taskHeader : taskHeaderList){
// 向光腾RCS下发任务
mesService.sendTaskToAcs(taskHeader);
}
}
}
}