Commit 513d43f848fe94e591ac42d7cc4316c887df7062
1 parent
351fb9c0
feat: 库存监控相同库位code和物料code合并qty显示
Showing
1 changed file
with
42 additions
and
4 deletions
src/main/java/com/huaheng/pc/config/location/controller/LocationController.java
@@ -41,13 +41,10 @@ import org.springframework.stereotype.Controller; | @@ -41,13 +41,10 @@ import org.springframework.stereotype.Controller; | ||
41 | import org.springframework.ui.ModelMap; | 41 | import org.springframework.ui.ModelMap; |
42 | import org.springframework.web.bind.annotation.*; | 42 | import org.springframework.web.bind.annotation.*; |
43 | 43 | ||
44 | +import java.util.*; | ||
44 | import javax.annotation.Resource; | 45 | import javax.annotation.Resource; |
45 | import javax.sql.DataSource; | 46 | import javax.sql.DataSource; |
46 | import java.math.BigDecimal; | 47 | import java.math.BigDecimal; |
47 | -import java.util.ArrayList; | ||
48 | -import java.util.HashMap; | ||
49 | -import java.util.List; | ||
50 | -import java.util.Map; | ||
51 | import java.util.stream.Collectors; | 48 | import java.util.stream.Collectors; |
52 | 49 | ||
53 | @Api(tags = {"库位操作类"}) | 50 | @Api(tags = {"库位操作类"}) |
@@ -314,6 +311,8 @@ public class LocationController extends BaseController { | @@ -314,6 +311,8 @@ public class LocationController extends BaseController { | ||
314 | List<Location> locations = locationService.list(locationLambdaQueryWrapper); | 311 | List<Location> locations = locationService.list(locationLambdaQueryWrapper); |
315 | List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(); | 312 | List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(); |
316 | 313 | ||
314 | + inventoryDetailList = mergeAndSumQuantities(inventoryDetailList); | ||
315 | + | ||
317 | for (Location location1 : locations) { | 316 | for (Location location1 : locations) { |
318 | InventoryDetail inventoryDetail = null; | 317 | InventoryDetail inventoryDetail = null; |
319 | for (InventoryDetail inventoryDetail2 : inventoryDetailList) { | 318 | for (InventoryDetail inventoryDetail2 : inventoryDetailList) { |
@@ -391,6 +390,45 @@ public class LocationController extends BaseController { | @@ -391,6 +390,45 @@ public class LocationController extends BaseController { | ||
391 | } | 390 | } |
392 | 391 | ||
393 | 392 | ||
393 | + // 库位和物料code相同的合并 | ||
394 | + public static List<InventoryDetail> mergeAndSumQuantities(List<InventoryDetail> inventoryDetailList) { | ||
395 | + // 创建一个 HashMap 用于存储相同 MaterialCode 和 LocationCode 的总数量 | ||
396 | + Map<String, BigDecimal> mergedQuantities = new HashMap<>(); | ||
397 | + | ||
398 | + // 遍历列表,将相同 MaterialCode 和 LocationCode 的数量进行累加 | ||
399 | + for (InventoryDetail detail : inventoryDetailList) { | ||
400 | + String key = detail.getMaterialCode() + "-" + detail.getLocationCode(); | ||
401 | + BigDecimal qty = detail.getQty(); | ||
402 | + | ||
403 | + // 如果 HashMap 中已存在相同的 key,则将数量累加起来,否则将新的 key-value 添加到 HashMap 中 | ||
404 | + mergedQuantities.merge(key, qty, BigDecimal::add); | ||
405 | + } | ||
406 | + | ||
407 | + // 创建一个新的列表来存储合并后的数量 | ||
408 | + List<InventoryDetail> mergedList = new ArrayList<>(); | ||
409 | + // 创建一个集合用于跟踪已处理的 key | ||
410 | + Set<String> processedKeys = new HashSet<>(); | ||
411 | + | ||
412 | + // 遍历原始列表,并将每个 MaterialCode 和 LocationCode 的第一个出现的项添加到合并列表中 | ||
413 | + for (InventoryDetail detail : inventoryDetailList) { | ||
414 | + String key = detail.getMaterialCode() + "-" + detail.getLocationCode(); | ||
415 | + | ||
416 | + // 检查是否已处理过该 key,如果是则跳过 | ||
417 | + if (processedKeys.contains(key)) { | ||
418 | + continue; | ||
419 | + } | ||
420 | + | ||
421 | + // 设置合并后的数量,并将其添加到合并列表中 | ||
422 | + detail.setQty(mergedQuantities.get(key)); | ||
423 | + mergedList.add(detail); | ||
424 | + | ||
425 | + // 标记该 key 已处理 | ||
426 | + processedKeys.add(key); | ||
427 | + } | ||
428 | + | ||
429 | + return mergedList; | ||
430 | + } | ||
431 | + | ||
394 | @Log(title = "配置-库存资料-库位条码", operating = "库位条码打印", action = BusinessType.OTHER) | 432 | @Log(title = "配置-库存资料-库位条码", operating = "库位条码打印", action = BusinessType.OTHER) |
395 | // @ResponseBody // 错误1ajax是json数据而没有添加该注解返回值不为json所以不能够返回common.ajaxSetup.textStatus= "parsererror"报错 | 433 | // @ResponseBody // 错误1ajax是json数据而没有添加该注解返回值不为json所以不能够返回common.ajaxSetup.textStatus= "parsererror"报错 |
396 | @GetMapping("/print/{ids}") | 434 | @GetMapping("/print/{ids}") |