From 7e6836f99b10cde552d2f403009bf66082535d94 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 02 四月 2026 11:58:33 +0800
Subject: [PATCH] fix: 生产统计看板能耗统计单位
---
src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java | 190 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 189 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
index bf4f2bf..1df045f 100644
--- a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
+++ b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -58,8 +58,10 @@
import com.ruoyi.staff.mapper.StaffOnJobMapper;
import com.ruoyi.staff.pojo.StaffOnJob;
import com.ruoyi.stock.mapper.StockInventoryMapper;
-import com.ruoyi.energy.mapper.EnergyConsumptionDetailMapper;
+import com.ruoyi.energy.mapper.EnergyMapper;
+import com.ruoyi.energy.pojo.Energy;
import com.ruoyi.energy.dto.EnergyCostDto;
+import com.ruoyi.energy.mapper.EnergyConsumptionDetailMapper;
import com.ruoyi.energy.vo.EnergyStatisticsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -158,6 +160,10 @@
@Autowired
private SalesDeliveryMapper salesDeliveryMapper;
+
+ @Autowired
+ private EnergyMapper energyMapper;
+
@Override
public HomeBusinessDto business() {
@@ -3405,6 +3411,13 @@
}
if (!CollectionUtils.isEmpty(costDtos)) {
+ // 鑾峰彇鍗曚綅
+ List<Energy> energies = energyMapper.selectList(Wrappers.<Energy>lambdaQuery()
+ .in(Energy::getEnergyTyep, Arrays.asList("姘�", "鐢�", "姘�")));
+ String waterUnit = energies.stream().filter(e -> "姘�".equals(e.getEnergyTyep())).map(Energy::getUnit).findFirst().orElse("");
+ String electricityUnit = energies.stream().filter(e -> "鐢�".equals(e.getEnergyTyep())).map(Energy::getUnit).findFirst().orElse("");
+ String steamUnit = energies.stream().filter(e -> "姘�".equals(e.getEnergyTyep())).map(Energy::getUnit).findFirst().orElse("");
+
for (EnergyCostDto costDto : costDtos) {
String dateStr = costDto.getMeterReadingDate();
String label = "";
@@ -3427,10 +3440,185 @@
dayDto.setWater(water);
dayDto.setElectricity(electricity);
dayDto.setSteam(steam);
+ dayDto.setWaterUnit(waterUnit);
+ dayDto.setElectricityUnit(electricityUnit);
+ dayDto.setSteamUnit(steamUnit);
}
}
}
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;
+ }
+
+ @Override
+ public Map<String, Long> manage() {
+ Map<String, Long> map = new HashMap<>();
+ //鐢熶骇璁㈠崟鎬绘暟
+ Long total = productOrderMapper.selectCount(new QueryWrapper<ProductOrder>().ne("status", 4));
+ map.put("total", total);
+ //宸插畬鎴愯鍗曟暟
+ Long completed = productOrderMapper.selectCount(new QueryWrapper<ProductOrder>().eq("status", 3));
+ map.put("completed", completed);
+ //鏈畬鎴愯鍗曟暟
+ Long uncompleted = productOrderMapper.selectCount(new QueryWrapper<ProductOrder>().eq("status", 1));
+ map.put("uncompleted", uncompleted);
+ //閮ㄥ垎瀹屾垚璁㈠崟鏁�
+ Long partialCompleted = productOrderMapper.selectCount(new QueryWrapper<ProductOrder>().eq("status", 2));
+ map.put("partialCompleted", partialCompleted);
+ //鏉ユ枡妫�鎬绘暟
+ Long materialInspection = qualityInspectMapper.selectCount(new QueryWrapper<QualityInspect>().eq("inspect_type", 0));
+ map.put("materialInspection", materialInspection);
+ return map;
+ }
}
--
Gitblit v1.9.3