| | |
| | | continue; |
| | | } |
| | | |
| | | // 找到产品大类 |
| | | Product parent = product.getParentId() == null |
| | | ? product |
| | | : productMap.get(product.getParentId()); |
| | | // 找到产品库根节点(产品大类) |
| | | Product rootProduct = findRootProduct(product, productMap); |
| | | |
| | | if (parent == null) { |
| | | continue; |
| | | } |
| | | String categoryTitle = resolveProductCategory(rootProduct.getProductName()); |
| | | |
| | | switch (parent.getProductName()) { |
| | | case "原材料": |
| | | if ("原材料".equals(categoryTitle)) { |
| | | rawMaterialCount = rawMaterialCount.add(quantity); |
| | | break; |
| | | case "半成品": |
| | | } else if ("半成品".equals(categoryTitle)) { |
| | | semiFinishedCount = semiFinishedCount.add(quantity); |
| | | break; |
| | | case "成品": |
| | | } else if ("成品".equals(categoryTitle)) { |
| | | finishedCount = finishedCount.add(quantity); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | // 组装明细 |
| | | NonComplianceWarningDto.Item child = new NonComplianceWarningDto.Item(); |
| | | // child.setProductTitle(item.getProductName()); |
| | | child.setParentProductTitle(parent.getProductName()); |
| | | child.setParentProductTitle(categoryTitle); |
| | | child.setProductTitle(item.getProductName()); |
| | | child.setDescription(item.getDefectivePhenomena()); |
| | | child.setDate(formatDate(item.getCheckTime())); |
| | |
| | | return dto; |
| | | } |
| | | |
| | | /** |
| | | * 向上查找产品库根节点(产品大类) |
| | | */ |
| | | private Product findRootProduct(Product product, Map<Long, Product> productMap) { |
| | | Product current = product; |
| | | int depth = 0; |
| | | while (current.getParentId() != null && depth++ < 20) { |
| | | Product parent = productMap.get(current.getParentId()); |
| | | if (parent == null) { |
| | | break; |
| | | } |
| | | current = parent; |
| | | } |
| | | return current; |
| | | } |
| | | |
| | | /** |
| | | * 根据产品库根节点名称识别产品大类:原材料/半成品/成品 |
| | | * 注意先判断半成品,避免被成品包含 |
| | | */ |
| | | private String resolveProductCategory(String rootName) { |
| | | if (rootName == null) { |
| | | return ""; |
| | | } |
| | | if (rootName.contains("半成品")) { |
| | | return "半成品"; |
| | | } |
| | | if (rootName.contains("成品")) { |
| | | return "成品"; |
| | | } |
| | | if (rootName.contains("原材料")) { |
| | | return "原材料"; |
| | | } |
| | | return rootName; |
| | | } |
| | | |
| | | private BigDecimal calcRate(BigDecimal part, BigDecimal total) { |
| | | if (total == null || total.compareTo(BigDecimal.ZERO) == 0) { |
| | | return BigDecimal.ZERO.setScale(2); |