| | |
| | | |
| | | return new ArrayList<>(resultData.values()); |
| | | } |
| | | |
| | | @Override |
| | | public SolidWasteCoreIndicatorsDto coreIndicators(productionStatisticsDto dto) { |
| | | if (dto == null) { |
| | | dto = new productionStatisticsDto(); |
| | | dto.setDateType(1); |
| | | } |
| | | |
| | | LocalDate now = LocalDate.now(); |
| | | LocalDate startDate = null; |
| | | if (dto.getDateType() != null && dto.getDateType() == 1) { // æ¬æè³ä» |
| | | startDate = now.withDayOfMonth(1); |
| | | } else { // æ¬å¹´è³ä» |
| | | startDate = now.withDayOfYear(1); |
| | | } |
| | | |
| | | // 累计æ¶çº³éä»2022-01-01å¼å§ |
| | | LocalDate cumulativeStartDate = LocalDate.of(2022, 1, 1); |
| | | // æ¥è¯¢ä»2022-01-01è³ä»çæææ¥å·¥æ°æ® |
| | | List<ProductionProductMain> mainList = productionProductMainService.list(Wrappers.<ProductionProductMain>lambdaQuery() |
| | | .ge(ProductionProductMain::getReportingTime, cumulativeStartDate.atStartOfDay())); |
| | | if (CollectionUtils.isEmpty(mainList)) return new SolidWasteCoreIndicatorsDto(); |
| | | |
| | | List<Long> mainIds = mainList.stream().map(ProductionProductMain::getId).collect(Collectors.toList()); |
| | | Map<Long, ProductionProductMain> mainMap = mainList.stream().collect(Collectors.toMap(ProductionProductMain::getId, m -> m)); |
| | | |
| | | // è·åæå
¥æç» |
| | | List<ProductionProductInput> allInputs = productionProductInputService.list(Wrappers.<ProductionProductInput>lambdaQuery() |
| | | .in(ProductionProductInput::getProductMainId, mainIds)); |
| | | if (CollectionUtils.isEmpty(allInputs)) return new SolidWasteCoreIndicatorsDto(); |
| | | |
| | | // è·åè§æ ¼åç©æåç§° |
| | | Set<Long> skuIds = allInputs.stream().map(ProductionProductInput::getProductId).filter(Objects::nonNull).collect(Collectors.toSet()); |
| | | Map<Long, String> skuToMaterialNameMap = new HashMap<>(); |
| | | if (!skuIds.isEmpty()) { |
| | | List<ProductMaterialSku> skus = productMaterialSkuService.listByIds(skuIds); |
| | | Set<Long> productIds = skus.stream().map(ProductMaterialSku::getProductId).filter(Objects::nonNull).collect(Collectors.toSet()); |
| | | Map<Long, String> materialNameMap = productMaterialService.listByIds(productIds).stream() |
| | | .collect(Collectors.toMap(ProductMaterial::getId, ProductMaterial::getProductName)); |
| | | skuToMaterialNameMap = skus.stream() |
| | | .filter(s -> s.getProductId() != null && materialNameMap.containsKey(s.getProductId())) |
| | | .collect(Collectors.toMap(ProductMaterialSku::getId, s -> materialNameMap.get(s.getProductId()))); |
| | | } |
| | | |
| | | BigDecimal totalAmount = BigDecimal.ZERO; |
| | | BigDecimal cumulativeAmount = BigDecimal.ZERO; |
| | | |
| | | Set<String> targetMaterials = new HashSet<>(Arrays.asList("ç²ç
¤ç°", "ç³è", "ç³ç°")); |
| | | |
| | | for (ProductionProductInput input : allInputs) { |
| | | String materialName = skuToMaterialNameMap.get(input.getProductId()); |
| | | if (materialName == null || !targetMaterials.contains(materialName)) continue; |
| | | |
| | | ProductionProductMain main = mainMap.get(input.getProductMainId()); |
| | | if (main == null || main.getReportingTime() == null) continue; |
| | | |
| | | BigDecimal qty = UnitUtils.convertValueToTon(input.getQuantity(), input.getUnit()); |
| | | // ç´¯å 累计æ¶çº³é |
| | | cumulativeAmount = cumulativeAmount.add(qty); |
| | | |
| | | if (!main.getReportingTime().toLocalDate().isBefore(startDate)) { |
| | | totalAmount = totalAmount.add(qty); |
| | | } |
| | | } |
| | | |
| | | SolidWasteCoreIndicatorsDto result = new SolidWasteCoreIndicatorsDto(); |
| | | result.setTotalAmount(totalAmount.setScale(2, RoundingMode.HALF_UP)); |
| | | result.setCumulativeAmount(cumulativeAmount.setScale(2, RoundingMode.HALF_UP)); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<SolidWasteStatisticsDto> trends(productionStatisticsDto dto) { |
| | | return solidWaste(dto); |
| | | } |
| | | |
| | | @Override |
| | | public List<MapDto> typeDistribution(productionStatisticsDto dto) { |
| | | if (dto == null) { |
| | | dto = new productionStatisticsDto(); |
| | | dto.setDateType(1); |
| | | } |
| | | |
| | | LocalDate now = LocalDate.now(); |
| | | LocalDate startDate = null; |
| | | if (dto.getDateType() != null && dto.getDateType() == 1) { // æ¬æè³ä» |
| | | startDate = now.withDayOfMonth(1); |
| | | } else { // æ¬å¹´è³ä» |
| | | startDate = now.withDayOfYear(1); |
| | | } |
| | | |
| | | // æ¥è¯¢æ¥å·¥ä¸»è¡¨ |
| | | List<ProductionProductMain> mainList = productionProductMainService.list(Wrappers.<ProductionProductMain>lambdaQuery() |
| | | .ge(ProductionProductMain::getReportingTime, startDate.atStartOfDay())); |
| | | if (CollectionUtils.isEmpty(mainList)) return new ArrayList<>(); |
| | | |
| | | List<Long> mainIds = mainList.stream().map(ProductionProductMain::getId).collect(Collectors.toList()); |
| | | |
| | | // è·åæå
¥æç» |
| | | List<ProductionProductInput> allInputs = productionProductInputService.list(Wrappers.<ProductionProductInput>lambdaQuery() |
| | | .in(ProductionProductInput::getProductMainId, mainIds)); |
| | | if (CollectionUtils.isEmpty(allInputs)) return new ArrayList<>(); |
| | | |
| | | // è·åè§æ ¼åç©æåç§° |
| | | Set<Long> skuIds = allInputs.stream().map(ProductionProductInput::getProductId).filter(Objects::nonNull).collect(Collectors.toSet()); |
| | | Map<Long, String> skuToMaterialNameMap = new HashMap<>(); |
| | | if (!skuIds.isEmpty()) { |
| | | List<ProductMaterialSku> skus = productMaterialSkuService.listByIds(skuIds); |
| | | Set<Long> productIds = skus.stream().map(ProductMaterialSku::getProductId).filter(Objects::nonNull).collect(Collectors.toSet()); |
| | | Map<Long, String> materialNameMap = productMaterialService.listByIds(productIds).stream() |
| | | .collect(Collectors.toMap(ProductMaterial::getId, ProductMaterial::getProductName)); |
| | | skuToMaterialNameMap = skus.stream() |
| | | .filter(s -> s.getProductId() != null && materialNameMap.containsKey(s.getProductId())) |
| | | .collect(Collectors.toMap(ProductMaterialSku::getId, s -> materialNameMap.get(s.getProductId()))); |
| | | } |
| | | |
| | | Map<String, BigDecimal> countMap = new HashMap<>(); |
| | | countMap.put("ç²ç
¤ç°", BigDecimal.ZERO); |
| | | countMap.put("ç³è", BigDecimal.ZERO); |
| | | countMap.put("ç³ç°", BigDecimal.ZERO); |
| | | |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | |
| | | for (ProductionProductInput input : allInputs) { |
| | | String materialName = skuToMaterialNameMap.get(input.getProductId()); |
| | | if (materialName == null || !countMap.containsKey(materialName)) continue; |
| | | |
| | | BigDecimal qty = UnitUtils.convertValueToTon(input.getQuantity(), input.getUnit()); |
| | | countMap.put(materialName, countMap.get(materialName).add(qty)); |
| | | total = total.add(qty); |
| | | } |
| | | |
| | | List<MapDto> result = new ArrayList<>(); |
| | | for (Map.Entry<String, BigDecimal> entry : countMap.entrySet()) { |
| | | MapDto mapDto = new MapDto(); |
| | | mapDto.setName(entry.getKey()); |
| | | BigDecimal value = entry.getValue().setScale(2, RoundingMode.HALF_UP); |
| | | mapDto.setValue(value.toString()); |
| | | |
| | | if (total.compareTo(BigDecimal.ZERO) > 0) { |
| | | BigDecimal rate = entry.getValue().divide(total, 4, RoundingMode.HALF_UP) |
| | | .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP); |
| | | mapDto.setRate(rate.toString()); |
| | | } else { |
| | | mapDto.setRate("0.00"); |
| | | } |
| | | result.add(mapDto); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | } |