From 2ed500595e8e56431d9ddefb19c30a566f416e55 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 02 四月 2026 15:42:44 +0800
Subject: [PATCH] fix: 首页趋势换成周、月、年

---
 src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java |  122 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 120 insertions(+), 2 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 79d9102..996cd1c 100644
--- a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
+++ b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -36,6 +36,8 @@
 import com.ruoyi.productionPlan.enums.AddressRegionEnum;
 import com.ruoyi.productionPlan.mapper.SalesDeliveryMapper;
 import com.ruoyi.productionPlan.pojo.SalesDelivery;
+import com.ruoyi.productionPlan.pojo.ProductionPlan;
+import com.ruoyi.productionPlan.service.ProductionPlanService;
 import com.ruoyi.project.system.domain.SysDept;
 import com.ruoyi.project.system.domain.SysDictData;
 import com.ruoyi.project.system.mapper.SysDeptMapper;
@@ -58,8 +60,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 +162,10 @@
 
     @Autowired
     private SalesDeliveryMapper salesDeliveryMapper;
+
+    @Autowired
+    private EnergyMapper energyMapper;
+
 
     @Override
     public HomeBusinessDto business() {
@@ -3405,6 +3413,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,6 +3442,9 @@
                     dayDto.setWater(water);
                     dayDto.setElectricity(electricity);
                     dayDto.setSteam(steam);
+                    dayDto.setWaterUnit(waterUnit);
+                    dayDto.setElectricityUnit(electricityUnit);
+                    dayDto.setSteamUnit(steamUnit);
                 }
             }
         }
@@ -3530,7 +3548,7 @@
         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));
@@ -3584,4 +3602,104 @@
 
         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;
+    }
+
+    @Autowired
+    private ProductionPlanService productionPlanService;
+
+    @Override
+    public List<PlanTrendsDto> planTrends(Integer type) {
+        LocalDate now = LocalDate.now();
+        LocalDate startDate;
+        DateTimeFormatter formatter;
+        int points;
+
+        if (type == null) type = 1;
+
+        if (type == 1) { // 鍛�
+            startDate = now.with(DayOfWeek.MONDAY);
+            points = (int) ChronoUnit.DAYS.between(startDate, now) + 1;
+            formatter = DateTimeFormatter.ofPattern("MM-dd");
+        } else if (type == 2) { // 鏈�
+            startDate = now.with(TemporalAdjusters.firstDayOfMonth());
+            points = now.getDayOfMonth();
+            formatter = DateTimeFormatter.ofPattern("MM-dd");
+        } else { // 骞�
+            startDate = now.with(TemporalAdjusters.firstDayOfYear());
+            points = now.getMonthValue();
+            formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+        }
+
+        Map<String, PlanTrendsDto> resultMap = new LinkedHashMap<>();
+        for (int i = 0; i < points; i++) {
+            String label = (type == 3) 
+                ? startDate.plusMonths(i).format(formatter) 
+                : startDate.plusDays(i).format(formatter);
+            PlanTrendsDto dto = new PlanTrendsDto();
+            dto.setDateStr(label);
+            dto.setPlannedVolume(BigDecimal.ZERO);
+            dto.setLowerVolume(BigDecimal.ZERO);
+            dto.setCompletionVolume(BigDecimal.ZERO);
+            resultMap.put(label, dto);
+        }
+        //  缁熻璁″垝閲�   
+        List<ProductionPlan> plans = productionPlanService.list(Wrappers.<ProductionPlan>lambdaQuery()
+                .ge(ProductionPlan::getStartDate, Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant())));
+        for (ProductionPlan plan : plans) {
+            if (plan.getStartDate() == null || plan.getVolume() == null) continue;
+            LocalDate d = plan.getStartDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+            String label = d.format(formatter);
+            if (resultMap.containsKey(label)) {
+                PlanTrendsDto dto = resultMap.get(label);
+                dto.setPlannedVolume(dto.getPlannedVolume().add(plan.getVolume()));
+            }
+        }
+        //  缁熻涓嬪彂閲�
+        List<ProductOrder> orders = productOrderMapper.selectList(Wrappers.<ProductOrder>lambdaQuery()
+                .ge(ProductOrder::getStartTime, startDate.atStartOfDay()));
+        for (ProductOrder order : orders) {
+            if (order.getStartTime() == null || order.getQuantity() == null) continue;
+            LocalDate d = order.getStartTime().toLocalDate();
+            String label = d.format(formatter);
+            if (resultMap.containsKey(label)) {
+                PlanTrendsDto dto = resultMap.get(label);
+                dto.setLowerVolume(dto.getLowerVolume().add(order.getQuantity()));
+            }
+        }
+        //  缁熻瀹屾垚閲�
+        List<ProductionProductOutput> outputs = productionProductOutputMapper.selectList(Wrappers.<ProductionProductOutput>lambdaQuery()
+                .ge(ProductionProductOutput::getCreateTime, startDate.atStartOfDay()));
+        for (ProductionProductOutput output : outputs) {
+            if (output.getCreateTime() == null || output.getQuantity() == null) continue;
+            LocalDate d = output.getCreateTime().toLocalDate();
+            String label = d.format(formatter);
+            if (resultMap.containsKey(label)) {
+                PlanTrendsDto dto = resultMap.get(label);
+                dto.setCompletionVolume(dto.getCompletionVolume().add(output.getQuantity()));
+            }
+        }
+
+        return new ArrayList<>(resultMap.values());
+    }
+
 }

--
Gitblit v1.9.3