PDAServiceImpl.java
14.7 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
package com.huaheng.api.erp.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.StringUtils;
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.inventory.InventoryHistoryDetail.domain.InventoryHistoryDetail;
import com.huaheng.pc.inventory.InventoryHistoryDetail.service.impl.InventoryHistoryDetailServiceImpl;
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.inventoryHistoryHeader.domain.InventoryHistoryHeader;
import com.huaheng.pc.inventory.inventoryHistoryHeader.service.impl.InventoryHistoryHeaderServiceImpl;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
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 org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author 游杰
*/
@Service
public class PDAServiceImpl implements PDAService {
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
private InventoryHistoryHeaderServiceImpl inventoryHistoryHeaderService;
@Resource
private InventoryHistoryDetailServiceImpl inventoryHistoryDetailService;
@Resource
private ShipmentHeaderService shipmentHeaderService;
@Resource
private ShipmentDetailService shipmentDetailService;
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private LocationService locationService;
@Resource
private ContainerService containerService;
@Override
public AjaxResult clearInventory(String warehouseCode, String locationCode) {
Location location = locationService.getLocationByCode(locationCode, warehouseCode);
int row = location.getIRow();
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(Location::getIRow, row)
.eq(Location::getArea, 5);
List<Location> locations = locationService.list(locationLambdaQueryWrapper);
if(locations.size() == 0) {
return AjaxResult.error("没有找到库位组");
}
List<Location> removeLocations = new ArrayList<>();
List<Container> containerList = new ArrayList<>();
for(Location location1 : locations) {
String containerCode = location1.getContainerCode();
if(StringUtils.isNotEmpty(containerCode)) {
Container container = containerService.
getContainerByCode(containerCode, warehouseCode);
containerList.add(container);
} else {
removeLocations.add(location1);
}
}
locations.removeAll(removeLocations);
if(locations.size() == 0) {
return AjaxResult.error("库位组上没有托盘");
}
List<String> locationCodeList = locations.stream().map(
Location::getCode).collect(Collectors.toList());
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryDetailLambdaQueryWrapper.in(InventoryDetail::getLocationCode, locationCodeList);
List<InventoryDetail> inventoryDetailList =
inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
if(inventoryDetailList.size() == 0) {
return AjaxResult.error("没有找到库存详情");
}
LambdaQueryWrapper<InventoryHeader> inventoryHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryHeaderLambdaQueryWrapper.in(InventoryHeader::getLocationCode, locationCodeList);
List<InventoryHeader> inventoryHeaderList =
inventoryHeaderService.list(inventoryHeaderLambdaQueryWrapper);
if(inventoryHeaderList.size() == 0) {
return AjaxResult.error("没有找到库存头");
}
List<String> receiptCodeList = inventoryDetailList.stream().
map(InventoryDetail::getReceiptCode).distinct().collect(Collectors.toList());
LambdaQueryWrapper<ReceiptHeader> receiptHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
receiptHeaderLambdaQueryWrapper.in(ReceiptHeader::getCode, receiptCodeList);
List<ReceiptHeader> receiptHeaderList = receiptHeaderService.list(receiptHeaderLambdaQueryWrapper);
List<String> shipmentCodeList = receiptHeaderList.stream().map(
ReceiptHeader::getShipmentCode).distinct().collect(Collectors.toList());
LambdaQueryWrapper<ShipmentHeader> shipmentHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
shipmentHeaderLambdaQueryWrapper.in(ShipmentHeader::getCode, shipmentCodeList);
List<ShipmentHeader> shipmentHeaderList =
shipmentHeaderService.list(shipmentHeaderLambdaQueryWrapper);
if(shipmentHeaderList == null) {
return AjaxResult.error("没有找到出库单头");
}
for(ShipmentHeader shipmentHeader : shipmentHeaderList) {
shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
}
boolean result = shipmentHeaderService.updateBatchById(shipmentHeaderList);
if(!result) {
throw new ServiceException("更新出库表单头失败");
}
List<Integer> shipmentHeaderIdList =
shipmentHeaderList.stream().map(ShipmentHeader::getId).collect(Collectors.toList());
LambdaQueryWrapper<ShipmentDetail> shipmentDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
shipmentDetailLambdaQueryWrapper.in(ShipmentDetail::getShipmentId, shipmentHeaderIdList);
List<ShipmentDetail> shipmentDetailList = shipmentDetailService.list(
shipmentDetailLambdaQueryWrapper);
for(ShipmentDetail shipmentDetail : shipmentDetailList) {
BigDecimal qty = shipmentDetail.getQty();
shipmentDetail.setTaskQty(qty);
}
result = shipmentDetailService.updateBatchById(shipmentDetailList);
if(!result) {
throw new ServiceException("更新出库表单详情头失败");
}
List<Integer> inventoryDetailIds = inventoryDetailList.stream().map(InventoryDetail::getId).
collect(Collectors.toList());
result = inventoryDetailService.removeByIds(inventoryDetailIds);
if(!result) {
throw new ServiceException("删除库存失败");
}
List<Integer> inventoryHeaderIds = inventoryHeaderList.stream().map(InventoryHeader::getId).
collect(Collectors.toList());
result = inventoryHeaderService.removeByIds(inventoryHeaderIds);
if(!result) {
throw new ServiceException("删除库存失败");
}
for(Container container : containerList) {
String containerCode = container.getCode();
containerService.updateLocationCodeAndStatus(containerCode,
"", QuantityConstant.STATUS_CONTAINER_EMPTY, warehouseCode);
}
for(Location location2 : locations) {
String locationCode2 = location2.getCode();
locationService.updateContainerCodeAndStatus(locationCode2,
"", QuantityConstant.STATUS_LOCATION_EMPTY, warehouseCode);
}
return AjaxResult.success("释放库存成功");
}
@Override
public AjaxResult createShipment(String platformCode, List<String> refereCodeList) {
LambdaQueryWrapper<ShipmentHeader> shipmentHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
shipmentHeaderLambdaQueryWrapper.in(ShipmentHeader::getReferCode, refereCodeList);
List<ShipmentHeader> shipmentHeaders = shipmentHeaderService.list(shipmentHeaderLambdaQueryWrapper);
if(!(shipmentHeaders != null && shipmentHeaders.size() > 0)) {
return AjaxResult.error("没有找到出库单");
}
for (ShipmentHeader shipmentHeader :shipmentHeaders){
int isCreated = shipmentHeader.getIsCreated();
if(isCreated == 1) {
return AjaxResult.error("出库单已经有创建单据");
}
LambdaQueryWrapper<ShipmentDetail> shipmentDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
shipmentDetailLambdaQueryWrapper.eq(ShipmentDetail::getShipmentCode, shipmentHeader.getCode());
List<ShipmentDetail> shipmentDetails = shipmentDetailService.list(shipmentDetailLambdaQueryWrapper);
if(shipmentDetails.size() == 0) {
return AjaxResult.error("没有找到出库单详情");
}
String warehouseCode = QuantityConstant.DEFAULT_WAREHOUSE;
String companyCode = QuantityConstant.DEFAULT_COMPANY;
ShipmentHeader shipmentHeader1 = new ShipmentHeader();
String code = shipmentHeaderService.createCode("SO");
shipmentHeader1.setCode(code);
shipmentHeader1.setWarehouseCode(warehouseCode);
shipmentHeader1.setCompanyCode(companyCode);
shipmentHeader1.setTotalQty(BigDecimal.ZERO);
shipmentHeader1.setTotalWeight(BigDecimal.ZERO);
shipmentHeader1.setTotalLines(0);
shipmentHeader1.setPriority(100);
shipmentHeader1.setFirstStatus(0);
shipmentHeader1.setLastStatus(0);
shipmentHeader1.setShipmentType("SO");
shipmentHeader1.setCreatedBy(QuantityConstant.PLATFORM_ERP);
shipmentHeaderService.save(shipmentHeader1);
for(ShipmentDetail shipmentDetail : shipmentDetails) {
shipmentDetail.setCreatedBy(QuantityConstant.PLATFORM_WMS);
shipmentDetail.setLastUpdatedBy(QuantityConstant.PLATFORM_WMS);
shipmentDetail.setSoEntryId(null);
shipmentDetail.setFHTZDetail(null);
shipmentDetail.setTaskQty(new BigDecimal(0));
shipmentDetail.setId(null);
shipmentDetail.setShipmentId(shipmentHeader1.getId());
shipmentDetail.setShipmentCode(shipmentHeader1.getCode());
}
shipmentDetailService.saveBatch(shipmentDetails);
shipmentHeader.setIsCreated(1);
shipmentHeaderService.updateById(shipmentHeader);
}
return AjaxResult.success("创建销售出库单成功");
}
private void addHistoryInventoryDetail(InventoryDetail inventoryDetail,
InventoryHistoryHeader inventoryHistoryHeader) {
InventoryHistoryDetail inventoryHistoryDetail = new InventoryHistoryDetail();
inventoryHistoryDetail.setInventoryHistoryHeaderId(inventoryHistoryHeader.getId());
inventoryHistoryDetail.setWarehouseCode(inventoryDetail.getWarehouseCode());
inventoryHistoryDetail.setZoneCode(inventoryDetail.getZoneCode());
inventoryHistoryDetail.setCompanyCode(inventoryDetail.getCompanyCode());
inventoryHistoryDetail.setLocationCode(inventoryDetail.getLocationCode());
inventoryHistoryDetail.setContainerCode(inventoryDetail.getContainerCode());
inventoryHistoryDetail.setMaterialCode(inventoryDetail.getMaterialCode());
inventoryHistoryDetail.setMaterialName(inventoryDetail.getMaterialName());
inventoryHistoryDetail.setMaterialSpec(inventoryDetail.getMaterialSpec());
inventoryHistoryDetail.setMaterialUnit(inventoryDetail.getMaterialUnit());
inventoryHistoryDetail.setBoxCode(inventoryDetail.getBoxCode());
inventoryHistoryDetail.setBoxPosition(inventoryDetail.getBoxPosition());
inventoryHistoryDetail.setChipCode(inventoryDetail.getChipCode());
inventoryHistoryDetail.setColor(inventoryDetail.getColor());
inventoryHistoryDetail.setLevel(inventoryDetail.getLevel());
inventoryHistoryDetail.setProductSchedule(inventoryDetail.getProductSchedule());
inventoryHistoryDetail.setProPackaing(inventoryDetail.getProPackaging());
inventoryHistoryDetail.setProductSize(inventoryDetail.getProductSize());
inventoryHistoryDetail.setQty(inventoryDetail.getQty());
inventoryHistoryDetail.setTaskQty(inventoryDetail.getTaskQty());
inventoryHistoryDetail.setInventorySts(inventoryDetail.getInventorySts());
inventoryHistoryDetail.setReferCode(inventoryDetail.getReferCode());
inventoryHistoryDetail.setReferDetailId(inventoryDetail.getReferDetailId());
inventoryHistoryDetail.setBatch(inventoryDetail.getBatch());
inventoryHistoryDetail.setLot(inventoryDetail.getLot());
inventoryHistoryDetail.setProjectNo(inventoryDetail.getProjectNo());;
inventoryHistoryDetail.setManufactureDate(inventoryDetail.getManufactureDate());
inventoryHistoryDetail.setExpirationDate(inventoryDetail.getExpirationDate());
inventoryHistoryDetail.setAgingDate(inventoryDetail.getAgingDate());
inventoryHistoryDetail.setAttribute1(inventoryDetail.getAttribute1());
inventoryHistoryDetail.setAttribute2(inventoryDetail.getAttribute2());
inventoryHistoryDetail.setAttribute3(inventoryDetail.getAttribute3());
inventoryHistoryDetail.setCreatedBy(QuantityConstant.PLATFORM_WMS);
inventoryHistoryDetail.setReceiptCode(inventoryDetail.getReceiptCode());
inventoryHistoryDetail.setReceiptDetailId(inventoryDetail.getReceiptDetailId());
inventoryHistoryHeader.setTotalLines(inventoryHistoryHeader.getTotalLines()+1);
if (!inventoryHistoryDetailService.save(inventoryHistoryDetail)) {
throw new ServiceException("保存库历史库存明细失败");
}
inventoryHistoryHeader.setTotalQty(inventoryHistoryHeader.getTotalQty().add(inventoryDetail.getQty()));
inventoryHistoryHeaderService.updateById(inventoryHistoryHeader);
}
}