ShipmentQuickService.java
13.9 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
package com.huaheng.pc.task.taskHeader.service;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.huaheng.api.general.service.ShipmentApiService;
import com.huaheng.common.support.Convert;
import com.huaheng.pc.shipment.shippingCombination.service.ShippingCombinationService;
import com.huaheng.pc.shipment.wave.domain.Wave;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
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.huaheng.api.general.domain.ShipmentDomain;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
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.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.materialWarnning.service.IMaterialWarningService;
import com.huaheng.pc.config.shipmentPreference.service.ShipmentPreferenceService;
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.service.StationService;
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.inventory.inventoryTransaction.domain.InventoryTransaction;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
import com.huaheng.pc.shipment.shipmentContainerDetail.domain.ShipmentContainerDetail;
import com.huaheng.pc.shipment.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentCombinationModel;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.system.dict.service.IDictDataService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.ShipmentTaskCreateModel;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
/**
* 入库任务创建和完成
*
* @author mahua
* @date 2020/7/14
*/
@Service
public class ShipmentQuickService {
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
ShipmentContainerHeaderService shipmentContainerHeaderService;
@Resource
ShipmentApiService shipmentApiService;
/**
* 整盘出库
* @param inventoryHeader
* @return
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult shipmentInventoryHeader(InventoryHeader inventoryHeader) {
if (StringUtils.isNull(inventoryHeader)) {
return AjaxResult.error("批量快速出库,所选库存头为空");
}
if(StringUtils.isNull(inventoryHeader.getId())){
return AjaxResult.error("批量快速出库,库存ID为空");
}
InventoryHeader inventoryHeader1=inventoryHeaderService.getById(inventoryHeader.getId());
String toPortCode = inventoryHeader.getPort();
if (StringUtils.isEmpty(toPortCode)) {
// return AjaxResult.error("批量快速出库,出库站台编码为空");
}
String warehouseCode=inventoryHeader1.getWarehouseCode();
LambdaQueryWrapper<InventoryDetail> lambdaQueryWrapper2 = Wrappers.lambdaQuery();
lambdaQueryWrapper2.eq(InventoryDetail::getWarehouseCode, warehouseCode)
.eq(InventoryDetail::getInventoryHeaderId, inventoryHeader1.getId());
List<InventoryDetail> inventoryDetails = inventoryDetailService.list(lambdaQueryWrapper2);
if (StringUtils.isEmpty(inventoryDetails)) {
return AjaxResult.error("批量快速出库, 排除锁定库存后没有可出库存详情");
}
//调用出库单接口创建出库单
ShipmentDomain shipmentDomain=new ShipmentDomain();
List<ShipmentDetail> shipmentDetails=new ArrayList<>();
String companyCode = inventoryDetails.get(0).getCompanyCode();
for (InventoryDetail inventoryDetail:inventoryDetails){
ShipmentDetail shipmentDetail=new ShipmentDetail();
shipmentDetail.setCompanyCode(companyCode);
shipmentDetail.setWarehouseCode(warehouseCode);
shipmentDetail.setMaterialCode(inventoryDetail.getMaterialCode());
shipmentDetail.setMaterialName(inventoryDetail.getMaterialName());
shipmentDetail.setMaterialSpec(inventoryDetail.getMaterialSpec());
shipmentDetail.setQty(inventoryDetail.getQty());
shipmentDetail.setMoCode(inventoryDetail.getMoCode());
shipmentDetail.setInventorySts(inventoryDetail.getInventorySts());
shipmentDetail.setUserDef1(inventoryDetail.getId().toString());
shipmentDetails.add(shipmentDetail);
}
ShipmentHeader shipmentHeader = new ShipmentHeader();
shipmentHeader.setWarehouseCode(warehouseCode);
shipmentHeader.setCompanyCode(companyCode);
shipmentHeader.setShipmentType(QuantityConstant.SHIPMENT_TYPE_PO);
// shipmentHeader.setReferCode(inventoryHeader.get);
shipmentHeader.setRemark("快速出库");
shipmentDomain.setShipmentHeader(shipmentHeader);
shipmentDomain.setShipmentDetails(shipmentDetails);
AjaxResult result = shipmentApiService.shipment(shipmentDomain);
if (result.hasErr()) {
throw new ServiceException("批量快速出库,创建出库单失败:".concat(result.getMsg()));
}
// String shipmentCode=(String)result.getData();
// 进行手动出库组盘
for (ShipmentDetail shipmentDetail:shipmentDetails){
ShipmentCombinationModel shipmentCombinationModel = new ShipmentCombinationModel();
shipmentCombinationModel.setShipmentDetailId(shipmentDetail.getId());
shipmentCombinationModel.setShipQty(shipmentDetail.getQty());
shipmentCombinationModel.setInventoryDetailId(Integer.valueOf(shipmentDetail.getUserDef1()));
ShipmentContainerHeader shipmentContainerHeader = shipmentContainerHeaderService.combination(shipmentCombinationModel);
}
LambdaQueryWrapper<ShipmentContainerHeader> shipmentContainerHeader = Wrappers.lambdaQuery();
shipmentContainerHeader.eq(ShipmentContainerHeader::getStatus, QuantityConstant.SHIPMENT_CONTAINER_BUILD);
shipmentContainerHeader.eq(ShipmentContainerHeader::getContainerCode, inventoryHeader1.getContainerCode());
List<ShipmentContainerHeader> shipmentContainerHeaders = shipmentContainerHeaderService.list(shipmentContainerHeader);
for (ShipmentContainerHeader item : shipmentContainerHeaders) {
List<Integer> idList = Arrays.asList(Convert.toIntArray(item.getId().toString()));
AjaxResult ajaxResults = shipmentContainerHeaderService.createTask(idList);
if (ajaxResults.hasErr()) {
throw new ServiceException("任务生成失败:" + ajaxResults.getMsg());
}
// 查询出库任务
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getAllocationHeadId, item.getId());
TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
if (taskHeader == null){
throw new RuntimeException("创建出库任务失败!");
}
if(StringUtils.isNotEmpty(toPortCode)){
TaskHeader taskHeaderTemp = new TaskHeader();
taskHeaderTemp.setId(taskHeader.getId());
taskHeaderTemp.setPickingCartPos(toPortCode);
// 修改任务出库口
if(taskHeader.getZoneCode().equals("JLK")){
taskHeaderTemp.setPort(QuantityConstant.JIJIA_PORT);
}
taskHeaderService.updateById(taskHeaderTemp);
}
}
return AjaxResult.success("批量快速出库成功");
}
/**
* 分拣出库
* @param inventoryDetaillist
* @return
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult shipmentInventoryDetail(List<InventoryDetail> inventoryDetaillist) {
if (StringUtils.isNull(inventoryDetaillist)) {
return AjaxResult.error("批量快速出库,所选数据为空");
}
List<Integer> ids= inventoryDetaillist.stream().map(InventoryDetail::getId).collect(Collectors.toList());
LambdaQueryWrapper<InventoryDetail> lambdaQueryWrapper2 = Wrappers.lambdaQuery();
lambdaQueryWrapper2.in(InventoryDetail::getId, ids);
List<InventoryDetail> inventoryDetails = inventoryDetailService.list(lambdaQueryWrapper2);
if (StringUtils.isEmpty(inventoryDetails)) {
return AjaxResult.error("批量快速出库, 排除锁定库存后没有可出库存详情");
}
InventoryHeader inventoryHeader=inventoryHeaderService.getById(inventoryDetails.get(0).getInventoryHeaderId());
String warehouseCode=inventoryDetails.get(0).getWarehouseCode();
//调用出库单接口创建出库单
ShipmentDomain shipmentDomain=new ShipmentDomain();
List<ShipmentDetail> shipmentDetails=new ArrayList<>();
String companyCode = inventoryDetails.get(0).getCompanyCode();
for (InventoryDetail inventoryDetail:inventoryDetails){
ShipmentDetail shipmentDetail=new ShipmentDetail();
shipmentDetail.setCompanyCode(companyCode);
shipmentDetail.setWarehouseCode(warehouseCode);
shipmentDetail.setMaterialCode(inventoryDetail.getMaterialCode());
shipmentDetail.setMaterialName(inventoryDetail.getMaterialName());
shipmentDetail.setMaterialSpec(inventoryDetail.getMaterialSpec());
shipmentDetail.setQty(inventoryDetail.getQty());
shipmentDetail.setMoCode(inventoryDetail.getMoCode());
shipmentDetail.setInventorySts(inventoryDetail.getInventorySts());
shipmentDetail.setUserDef1(inventoryDetail.getId().toString());
shipmentDetails.add(shipmentDetail);
}
ShipmentHeader shipmentHeader = new ShipmentHeader();
shipmentHeader.setWarehouseCode(warehouseCode);
shipmentHeader.setCompanyCode(companyCode);
shipmentHeader.setShipmentType(QuantityConstant.SHIPMENT_TYPE_PO);
// shipmentHeader.setReferCode(inventoryHeader.get);
shipmentHeader.setRemark("快速出库");
shipmentDomain.setShipmentHeader(shipmentHeader);
shipmentDomain.setShipmentDetails(shipmentDetails);
AjaxResult result = shipmentApiService.shipment(shipmentDomain);
if (result.hasErr()) {
throw new ServiceException("批量快速出库,创建出库单失败:".concat(result.getMsg()));
}
// String shipmentCode=(String)result.getData();
// 进行手动出库组盘
for (ShipmentDetail shipmentDetail:shipmentDetails){
ShipmentCombinationModel shipmentCombinationModel = new ShipmentCombinationModel();
shipmentCombinationModel.setShipmentDetailId(shipmentDetail.getId());
shipmentCombinationModel.setShipQty(shipmentDetail.getQty());
shipmentCombinationModel.setInventoryDetailId(Integer.valueOf(shipmentDetail.getUserDef1()));
ShipmentContainerHeader shipmentContainerHeader = shipmentContainerHeaderService.combination(shipmentCombinationModel);
}
LambdaQueryWrapper<ShipmentContainerHeader> shipmentContainerHeader = Wrappers.lambdaQuery();
shipmentContainerHeader.eq(ShipmentContainerHeader::getStatus, QuantityConstant.SHIPMENT_CONTAINER_BUILD);
shipmentContainerHeader.eq(ShipmentContainerHeader::getContainerCode, inventoryHeader.getContainerCode());
List<ShipmentContainerHeader> shipmentContainerHeaders = shipmentContainerHeaderService.list(shipmentContainerHeader);
for (ShipmentContainerHeader item : shipmentContainerHeaders) {
List<Integer> idList = Arrays.asList(Convert.toIntArray(item.getId().toString()));
AjaxResult ajaxResults = shipmentContainerHeaderService.createTask(idList);
if (ajaxResults.hasErr()) {
throw new ServiceException("任务生成失败:" + ajaxResults.getMsg());
}
// 查询出库任务
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getAllocationHeadId, item.getId());
TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
if (taskHeader == null){
throw new RuntimeException("创建出库任务失败!");
}
}
return AjaxResult.success("批量快速出库成功");
}
}