Commit 0fe2b8f0a1d7de1ce0e9a2f61e23ab459802deef
1 parent
2c5c9172
feat: 查询已出库部分的库存接口
Showing
2 changed files
with
69 additions
and
2 deletions
src/main/java/com/huaheng/api/mes/controller/MesReceiptController.java
@@ -53,11 +53,13 @@ import org.springframework.web.bind.annotation.*; | @@ -53,11 +53,13 @@ import org.springframework.web.bind.annotation.*; | ||
53 | 53 | ||
54 | import javax.annotation.Resource; | 54 | import javax.annotation.Resource; |
55 | import java.io.UnsupportedEncodingException; | 55 | import java.io.UnsupportedEncodingException; |
56 | +import java.math.BigDecimal; | ||
56 | import java.sql.ResultSet; | 57 | import java.sql.ResultSet; |
57 | import java.sql.SQLException; | 58 | import java.sql.SQLException; |
58 | import java.time.LocalDateTime; | 59 | import java.time.LocalDateTime; |
59 | import java.time.format.DateTimeFormatter; | 60 | import java.time.format.DateTimeFormatter; |
60 | import java.util.*; | 61 | import java.util.*; |
62 | +import java.util.stream.Collectors; | ||
61 | 63 | ||
62 | 64 | ||
63 | @RestController | 65 | @RestController |
@@ -280,7 +282,6 @@ public class MesReceiptController extends BaseController { | @@ -280,7 +282,6 @@ public class MesReceiptController extends BaseController { | ||
280 | */ | 282 | */ |
281 | @PostMapping("/searchInventory") | 283 | @PostMapping("/searchInventory") |
282 | @ApiLogger(apiName = "查询库存", from = "ROBOT") | 284 | @ApiLogger(apiName = "查询库存", from = "ROBOT") |
283 | - @ApiOperation("查询库存") | ||
284 | public AjaxResult searchInventory(@RequestBody Detail detailed) { | 285 | public AjaxResult searchInventory(@RequestBody Detail detailed) { |
285 | 286 | ||
286 | 287 | ||
@@ -323,7 +324,70 @@ public class MesReceiptController extends BaseController { | @@ -323,7 +324,70 @@ public class MesReceiptController extends BaseController { | ||
323 | detailList.forEach(detail -> { | 324 | detailList.forEach(detail -> { |
324 | InventoryVO inventoryVO = new InventoryVO(); | 325 | InventoryVO inventoryVO = new InventoryVO(); |
325 | BeanUtils.copyProperties(detail, inventoryVO); | 326 | BeanUtils.copyProperties(detail, inventoryVO); |
326 | - inventoryVO.setWarehouse("035"); | 327 | + if (StringUtils.isBlank(detail.getWarehouse())) { |
328 | + inventoryVO.setWarehouse("035"); | ||
329 | + } else { | ||
330 | + inventoryVO.setWarehouse(detail.getWarehouse()); | ||
331 | + } | ||
332 | + inventoryVOList.add(inventoryVO); | ||
333 | + }); | ||
334 | + | ||
335 | + return AjaxResult.success(inventoryVOList); | ||
336 | + | ||
337 | + } | ||
338 | + | ||
339 | + | ||
340 | + /** | ||
341 | + * 查询已出库部分的库存 | ||
342 | + * 物料编码、物料名称、已出数量、仓库编码(warehouse) | ||
343 | + */ | ||
344 | + @PostMapping("/queryOutboundInventory") | ||
345 | + @ApiLogger(apiName = "查询已出库部分的库存", from = "ROBOT") | ||
346 | + public AjaxResult queryOutboundInventory(@RequestBody Detail detailed) { | ||
347 | + | ||
348 | + // 查询符合条件的 ShipmentHeader 集合 | ||
349 | + List<ShipmentHeader> shipmentHeaders = shipmentHeaderService.list(new LambdaQueryWrapper<ShipmentHeader>() | ||
350 | + .ne(ShipmentHeader::getFirstStatus, QuantityConstant.RECEIPT_HEADER_RETURN) | ||
351 | + .ne(ShipmentHeader::getDeleted, true)); | ||
352 | + List<ShipmentDetail> shipmentDetailList = new ArrayList<>(); | ||
353 | + // 查询符合条件的 ShipmentDetail 集合 | ||
354 | + for (ShipmentHeader shipmentHeader : shipmentHeaders) { | ||
355 | + List<ShipmentDetail> shipmentDetails = shipmentDetailService.list(new LambdaQueryWrapper<ShipmentDetail>() | ||
356 | + .ne(ShipmentDetail::getTaskQty, 0) | ||
357 | + .eq(ShipmentDetail::getShipmentId, shipmentHeader.getId())); | ||
358 | + shipmentDetailList.addAll(shipmentDetails); | ||
359 | + } | ||
360 | + | ||
361 | + //查询符合条件的 库存交易 集合 | ||
362 | + List<InventoryTransaction> its = new ArrayList<>(); | ||
363 | + for (ShipmentDetail shipmentDetail : shipmentDetailList) { | ||
364 | + List<InventoryTransaction> inventoryTransactions = inventoryTransactionService.list(new LambdaQueryWrapper<InventoryTransaction>() | ||
365 | + .eq(InventoryTransaction::getTransactionType, 20) | ||
366 | + .eq(InventoryTransaction::getBillDetailId, shipmentDetail.getShipmentId())); | ||
367 | + if (inventoryTransactions.size() > 1) { | ||
368 | + // 如果查出多条数据,将taskQty字段由负数转为正数,并将taskQty的值全部累加放入第一个InventoryTransaction对象中 | ||
369 | + InventoryTransaction firstTransaction = inventoryTransactions.get(0); | ||
370 | + BigDecimal totalTaskQty = BigDecimal.ZERO; | ||
371 | + for (int i = 1; i < inventoryTransactions.size(); i++) { | ||
372 | + InventoryTransaction transaction = inventoryTransactions.get(i); | ||
373 | + BigDecimal positiveTaskQty = transaction.getTaskQty().abs(); | ||
374 | + totalTaskQty = totalTaskQty.add(positiveTaskQty); | ||
375 | + } | ||
376 | + firstTransaction.setTaskQty(totalTaskQty); | ||
377 | + its.add(firstTransaction); | ||
378 | + } else if (!inventoryTransactions.isEmpty()) { | ||
379 | + its.add(inventoryTransactions.get(0)); | ||
380 | + } | ||
381 | + } | ||
382 | + List<InventoryVO> inventoryVOList = new ArrayList<>(); | ||
383 | + its.forEach(detail -> { | ||
384 | + InventoryVO inventoryVO = new InventoryVO(); | ||
385 | + BeanUtils.copyProperties(detail, inventoryVO); | ||
386 | + if (StringUtils.isBlank(detail.getWarehouse())) { | ||
387 | + inventoryVO.setWarehouse("035"); | ||
388 | + } else { | ||
389 | + inventoryVO.setWarehouse(detail.getWarehouse()); | ||
390 | + } | ||
327 | inventoryVOList.add(inventoryVO); | 391 | inventoryVOList.add(inventoryVO); |
328 | }); | 392 | }); |
329 | 393 | ||
@@ -331,6 +395,7 @@ public class MesReceiptController extends BaseController { | @@ -331,6 +395,7 @@ public class MesReceiptController extends BaseController { | ||
331 | 395 | ||
332 | } | 396 | } |
333 | 397 | ||
398 | + | ||
334 | /** | 399 | /** |
335 | * 获取出入库单明细记录 | 400 | * 获取出入库单明细记录 |
336 | * | 401 | * |
src/main/java/com/huaheng/pc/task/taskHeader/service/ShipmentTaskService.java
@@ -393,6 +393,8 @@ public class ShipmentTaskService { | @@ -393,6 +393,8 @@ public class ShipmentTaskService { | ||
393 | inventoryTransaction.setMaterialName(inventoryDetail.getMaterialName()); | 393 | inventoryTransaction.setMaterialName(inventoryDetail.getMaterialName()); |
394 | inventoryTransaction.setMaterialSpec(inventoryDetail.getMaterialSpec()); | 394 | inventoryTransaction.setMaterialSpec(inventoryDetail.getMaterialSpec()); |
395 | inventoryTransaction.setMaterialUnit(inventoryDetail.getMaterialUnit()); | 395 | inventoryTransaction.setMaterialUnit(inventoryDetail.getMaterialUnit()); |
396 | + inventoryTransaction.setWarehouse(inventoryDetail.getWarehouse()); | ||
397 | + inventoryTransaction.setWarehouseName(inventoryDetail.getWarehouseName()); | ||
396 | inventoryTransaction.setBillCode(taskDetail.getBillCode()); | 398 | inventoryTransaction.setBillCode(taskDetail.getBillCode()); |
397 | inventoryTransaction.setRecordCode(taskDetail.getRecordCode()); | 399 | inventoryTransaction.setRecordCode(taskDetail.getRecordCode()); |
398 | //取出子单据 | 400 | //取出子单据 |