ShipmentContainerAdviceService.java
18.6 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
package com.huaheng.pc.shipment.shipmentContainerAdvice.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.domain.RetCode;
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.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
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.shipment.shipmentContainerAdvice.domain.ShipmentContainerAdvice;
import com.huaheng.pc.shipment.shipmentContainerAdvice.mapper.ShipmentContainerAdviceMapper;
import com.huaheng.pc.shipment.shipmentContainerDetail.domain.ShipmentContainerDetail;
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.service.ShipmentHeaderService;
import com.huaheng.pc.system.config.domain.Config;
import com.huaheng.pc.system.dict.service.IDictDataService;
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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class ShipmentContainerAdviceService extends ServiceImpl<ShipmentContainerAdviceMapper, ShipmentContainerAdvice> {
private static final Logger logger = LoggerFactory.getLogger(ShipmentContainerAdviceService.class);
@Resource
private ShipmentContainerHeaderService shipmentContainerHeaderService;
@Resource
private LocationService locationService;
@Resource
private ContainerService containerService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private ShipmentDetailService shipmentDetailService;
@Resource
private MaterialService materialService;
@Resource
private IDictDataService dictDataService;
@Resource
private ShipmentHeaderService shipmentHeaderService;
public boolean updateStatusById(int status, int id) {
ShipmentContainerAdvice shipmentContainerAdvice = new ShipmentContainerAdvice();
shipmentContainerAdvice.setStatus(status);
shipmentContainerAdvice.setId(id);
boolean success = updateById(shipmentContainerAdvice);
return success;
}
public boolean updateTaskQtyById(BigDecimal qty, int id) {
ShipmentContainerAdvice shipmentContainerAdvice = new ShipmentContainerAdvice();
shipmentContainerAdvice.setTaskQty(qty);
shipmentContainerAdvice.setId(id);
shipmentContainerAdvice.setStatus(QuantityConstant.SHIPMENT_CONTAINER_TASK);
boolean success = updateById(shipmentContainerAdvice);
return success;
}
public List<ShipmentContainerAdvice> getShipmentContainerAdviceListHeaderId(Integer id) {
LambdaQueryWrapper<ShipmentContainerAdvice> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShipmentContainerAdvice::getShipmentContainerId, id);
List<ShipmentContainerAdvice> list = this.list(wrapper);
return list;
}
public Boolean deleteShipmentContainerAdviceListHeaderId(Integer id) {
LambdaQueryWrapper<ShipmentContainerAdvice> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShipmentContainerAdvice::getShipmentContainerId, id);
Boolean tag = this.remove(wrapper);
return tag;
}
public List<ShipmentContainerAdvice> getShipmentContainerAdviceListByShipmentCode(String shipmentCode, String warehouseCode) {
LambdaQueryWrapper<ShipmentContainerAdvice> shipmentContainerAdviceLambdaQueryWrapper = Wrappers.lambdaQuery();
shipmentContainerAdviceLambdaQueryWrapper.eq(ShipmentContainerAdvice::getShipmentCode, shipmentCode)
.eq(ShipmentContainerAdvice::getWarehouseCode, warehouseCode).lt(ShipmentContainerAdvice::getStatus, QuantityConstant.SHIPMENT_CONTAINER_FINISHED);
List<ShipmentContainerAdvice> shipmentContainerAdviceList = list(shipmentContainerAdviceLambdaQueryWrapper);
return shipmentContainerAdviceList;
}
@Transactional(rollbackFor = Exception.class)
public AjaxResult createCallShipmentTask(ShipmentContainerHeader shipmentContainerHeader, String warehouseCode, long shipmentOrder, int sequence,
int sequenceNumber) {
Integer preTaskNo = 0;
if (shipmentContainerHeader == null) {
return AjaxResult.error("生成出库任务时, 出库组盘头" + "未找到,操作中止");
}
shipmentContainerHeader = shipmentContainerHeaderService.getById(shipmentContainerHeader.getId());
if (shipmentContainerHeader.getStatus() >= QuantityConstant.SHIPMENT_CONTAINER_TASK) {
return AjaxResult.error("生成出库任务时, 出库组盘头" + shipmentContainerHeader.getId() + "已经生成任务,请不要重复生成,操作中止");
}
if (!shipmentContainerHeader.getWarehouseCode().equals(warehouseCode)) {
return AjaxResult.error("生成出库任务时, 出库组盘头" + shipmentContainerHeader.getId() + "仓库编码和登录的仓库编码不一致");
}
String fromLocationCode = shipmentContainerHeader.getLocationCode();
String containerCode = shipmentContainerHeader.getContainerCode();
if (StringUtils.isEmpty(fromLocationCode)) {
return AjaxResult.error("生成出库任务时, 出库组盘头没有起始库位号");
}
Location location = locationService.getLocationByCode(fromLocationCode, warehouseCode);
if (location == null) {
return AjaxResult.error("生成出库任务时, 库位号" + fromLocationCode + "没有找到库位");
}
if (location.getRowFlag() == QuantityConstant.ROW_OUT) {
Location location1 = locationService.getNear(location);
if (location1 != null) {
String locationCode = location1.getCode();
TaskHeader taskHeader = taskHeaderService.getUnCompleteTaskByToLocationCode(locationCode, warehouseCode);
if (taskHeader != null) {
preTaskNo = taskHeader.getPreTaskNo();
}
}
}
Container container = containerService.getContainerByCode(containerCode, warehouseCode);
if (container == null) {
return AjaxResult.error("生成出库任务时, 托盘不存在" + containerCode);
}
if (container.getStatus().equals(QuantityConstant.STATUS_CONTAINER_LOCK)) {
return AjaxResult.error("生成出库任务时, 托盘已经锁定,containerCode:" + containerCode);
}
container.setStatus(QuantityConstant.STATUS_CONTAINER_LOCK);
boolean success = containerService.updateById(container);
if (!success) {
throw new ServiceException("生成出库任务时, 更新容器失败,containerCode:" + containerCode);
}
locationService.updateStatus(fromLocationCode, QuantityConstant.STATUS_LOCATION_LOCK, warehouseCode);
if (!success) {
throw new ServiceException("生成出库任务时, 更新库位失败,fromLocationCode:" + fromLocationCode);
}
int taskType = QuantityConstant.TASK_TYPE_SORTINGSHIPMENT;
String zoneCode = location.getZoneCode();
TaskHeader taskHeader = new TaskHeader();
taskHeader.setCompanyCode(shipmentContainerHeader.getCompanyCode());
taskHeader.setPreTaskNo(preTaskNo);
taskHeader.setTaskType(taskType);
taskHeader.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_SHIPMENT);
taskHeader.setZoneCode(zoneCode);
taskHeader.setAdvice(1);
taskHeader.setWarehouseCode(warehouseCode);
taskHeader.setStatus(QuantityConstant.TASK_STATUS_BUILD);
taskHeader.setContainerCode(containerCode);
taskHeader.setFromLocation(fromLocationCode);
String value = dictDataService.getDictValueByLabel(QuantityConstant.RULE_SHIPMENT_TASK, taskHeader.getZoneCode(), taskHeader.getWarehouseCode());
int shipmentTaskRule = Integer.parseInt(value);
//整盘出库
if(shipmentTaskRule == QuantityConstant.RULE_TASK_WHOLE_SHIPMENT) {
}else{
taskHeader.setToLocation(fromLocationCode);
}
taskHeader.setAllocationHeadId(shipmentContainerHeader.getId());
success = taskHeaderService.save(taskHeader);
if (!success) {
throw new ServiceException("生成出库任务时, 创建任务失败");
}
ShipmentContainerHeader shipmentContainerHeader1 = new ShipmentContainerHeader();
shipmentContainerHeader1.setId(shipmentContainerHeader.getId());
shipmentContainerHeader1.setTaskType(taskType);
shipmentContainerHeader1.setStatus(QuantityConstant.SHIPMENT_CONTAINER_TASK);
success = shipmentContainerHeaderService.updateById(shipmentContainerHeader1);
if (!success) {
throw new ServiceException("生成出库任务时, 更新出库组盘头失败");
}
success = this.updateInventoryContainerStatusByContainerCode(containerCode, warehouseCode);
if (!success) {
throw new ServiceException("生成出库任务时, 更新库存头失败");
}
return AjaxResult.success("生成出库任务成功", taskHeader);
}
@Transactional
public boolean updateInventoryContainerStatusByContainerCode(String containerCode, String warehouseCode) {
Container container = containerService.getContainerByCode(containerCode, warehouseCode);
if (container == null) {
return false;
}
InventoryHeader inventoryHeader = inventoryHeaderService.getInventoryHeaderByContainerCode(containerCode, warehouseCode);
if (inventoryHeader == null) {
return true;
}
if (!inventoryHeaderService.updateContainerStatusById(container.getStatus(), inventoryHeader.getId())) {
throw new ServiceException("更新库存头表状态失败");
}
List<InventoryDetail> inventoryDetailList = inventoryDetailService.getInventoryDetailListByContainerCode(containerCode, warehouseCode);
List<InventoryDetail> updateInventoryDetailList = new ArrayList<>();
if (inventoryDetailList.size() > 0) {
for (InventoryDetail inventoryDetail : inventoryDetailList) {
InventoryDetail updateInventoryDetail = new InventoryDetail();
updateInventoryDetail.setId(inventoryDetail.getId());
updateInventoryDetailList.add(updateInventoryDetail);
}
if (!inventoryDetailService.updateBatchById(updateInventoryDetailList)) {
throw new ServiceException("更新库存明细表状态失败");
}
}
return true;
}
public boolean updateQtyById(BigDecimal qty, int id) {
ShipmentContainerAdvice shipmentContainerAdvice = new ShipmentContainerAdvice();
shipmentContainerAdvice.setQty(qty);
shipmentContainerAdvice.setId(id);
boolean success = updateById(shipmentContainerAdvice);
return success;
}
@Transactional(rollbackFor = Exception.class)
public ShipmentContainerAdvice addShipmentContainerAdvice(ShipmentContainerHeader shipmentContainerHeader, ShipmentCombinationModel combinationModel) {
boolean success = false;
BigDecimal shipmentQty = combinationModel.getShipQty();
Integer shipmentDetailId = combinationModel.getShipmentDetailId();
Integer inventoryDetailId = combinationModel.getInventoryDetailId();
ShipmentDetail shipmentDetail = shipmentDetailService.getById(shipmentDetailId);
InventoryDetail inventoryDetail = inventoryDetailService.getById(inventoryDetailId);
ShipmentContainerAdvice shipmentContainerAdvice=new ShipmentContainerAdvice();
String warehouseCode = inventoryDetail.getWarehouseCode();
String materialCode = inventoryDetail.getMaterialCode();
Material material = materialService.getMaterialByCode(materialCode);
if (material == null) {
throw new ServiceException("出库单(" + shipmentDetail.getShipmentCode() + ")的物料(" + materialCode + ")不存在!");
}
shipmentContainerAdvice = new ShipmentContainerAdvice();
shipmentContainerAdvice.setWarehouseCode(shipmentContainerHeader.getWarehouseCode());
shipmentContainerAdvice.setCompanyCode(shipmentDetail.getCompanyCode());
shipmentContainerAdvice.setContainerCode(shipmentContainerHeader.getContainerCode());
// shipmentContainerAdvice.setInventoryDetailId(inventoryDetail.getId());
shipmentContainerAdvice.setShipmentCode(shipmentDetail.getShipmentCode());
shipmentContainerAdvice.setShipmentId(shipmentDetail.getShipmentId());
shipmentContainerAdvice.setShipmentDetailId(shipmentDetail.getId());
shipmentContainerAdvice.setShipmentContainerId(shipmentContainerHeader.getId());
shipmentContainerAdvice.setMaterialCode(shipmentDetail.getMaterialCode());
shipmentContainerAdvice.setMaterialName(shipmentDetail.getMaterialName());
shipmentContainerAdvice.setMaterialSpec(shipmentDetail.getMaterialSpec());
shipmentContainerAdvice.setMaterialUnit(shipmentDetail.getMaterialUnit());
shipmentContainerAdvice.setQty(shipmentQty);
shipmentContainerAdvice.setInventoryDetailId(inventoryDetailId);
shipmentContainerAdvice.setBatch(shipmentDetail.getBatch());
shipmentContainerAdvice.setStatus(QuantityConstant.SHIPMENT_CONTAINER_BUILD);
shipmentContainerAdvice.setCreatedBy(shipmentDetail.getCreatedBy());
shipmentContainerAdvice.setCreated(new Date());
success = this.save(shipmentContainerAdvice);
if (!success) {
throw new ServiceException("新建预配盘明细失败,sql错误");
}
return shipmentContainerAdvice;
}
/**
* 取消预配盘
*
* @return
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult cancelCombinationAdvice(Integer shipmentContainerHeaderId,ShipmentContainerHeader shipmentContainerHeader) {
List<ShipmentContainerAdvice> list=this.getShipmentContainerAdviceListHeaderId(shipmentContainerHeaderId);
for (ShipmentContainerAdvice shipmentContainerAdvice : list) {
//获取头
if(shipmentContainerAdvice.getStatus()>0){
throw new ServiceException("容器" + shipmentContainerHeader.getContainerCode() + "已出库扣减库存,不允许取消明细");
}
if (shipmentContainerHeader.getStatus() >= QuantityConstant.SHIPMENT_CONTAINER_TASK) {
// throw new ServiceException("容器" + shipmentContainerHeader.getContainerCode() + "非新建状态,不允许取消明细");
}
//恢复占用库存
InventoryDetail inventoryDetail = inventoryDetailService.getById(shipmentContainerAdvice.getInventoryDetailId());
if (inventoryDetail != null) {
InventoryDetail inventoryDetail1 = new InventoryDetail();
inventoryDetail1.setId(inventoryDetail.getId());
inventoryDetail1.setTaskQty(inventoryDetail.getTaskQty().subtract(shipmentContainerAdvice.getQty()));
inventoryDetailService.updateById(inventoryDetail1);
logger.info("扣减库存::" + inventoryDetail.getId() + "容器:" + inventoryDetail.getContainerCode() + "物料code:" + inventoryDetail.getMaterialCode() + "数量:" + inventoryDetail.getTaskQty() + "组盘数量:" + shipmentContainerAdvice.getQty());
}
//恢复单据发货数量
ShipmentDetail shipmentDetail = shipmentDetailService.getById(shipmentContainerAdvice.getShipmentDetailId());
shipmentDetail.setTaskQty(shipmentDetail.getTaskQty().subtract(shipmentContainerAdvice.getQty()));
if (shipmentDetail.getTaskQty().compareTo(BigDecimal.ZERO) != 0) {
shipmentDetail.setStatus(QuantityConstant.SHIPMENT_HEADER_WAVE);//明细状态恢复,如果删除后还有以出数量就是波次
} else {
shipmentDetail.setStatus(QuantityConstant.SHIPMENT_HEADER_POOL);//明细状态
}
shipmentDetailService.saveOrUpdate(shipmentDetail);
//删除这个配盘明细
this.removeById(shipmentContainerAdvice.getId());
//查询头表下还有没有明细,如果没有,则删了这个头表
ShipmentContainerDetail condition = new ShipmentContainerDetail();
condition.setShippingContainerId(shipmentContainerAdvice.getShipmentContainerId());
List<ShipmentContainerAdvice> list1= this.getShipmentContainerAdviceListHeaderId(shipmentContainerHeaderId);
if (list1 == null || list1.size() == 0) {
shipmentContainerHeaderService.removeById(shipmentContainerHeader.getId());
locationService.updateStatus(shipmentContainerHeader.getLocationCode(),
QuantityConstant.STATUS_LOCATION_EMPTY);
}
//更新单据状态
shipmentHeaderService.updateShipmentStatus(shipmentDetail.getShipmentId());
}
return AjaxResult.success("");
}
}