From f29c8786807015d78b9be8a33397f69478d92a76 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期六, 12 七月 2025 16:52:27 +0800
Subject: [PATCH] 1.设备优化 2.配煤计算器

---
 main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java
index 2f162a7..01c3e54 100644
--- a/main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java
+++ b/main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java
@@ -19,6 +19,7 @@
 import com.ruoyi.business.service.SalesRecordService;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.system.mapper.SysUserMapper;
 import lombok.RequiredArgsConstructor;
@@ -67,6 +68,29 @@
     public IPage<SalesRecordDto> selectSalesRecordList(Page<SalesRecord> page, SalesRecordDto salesRecordDto) {
         // 1. 鍒涘缓鏌ヨ鏉′欢锛屾寜鍒涘缓鏃堕棿鍊掑簭鎺掑簭
         LambdaQueryWrapper<SalesRecord> queryWrapper = new LambdaQueryWrapper<>();
+
+        // 鎸夋棩鏈熸煡璇�
+        if (salesRecordDto.getSaleDate() != null) {
+            queryWrapper.eq(SalesRecord::getSaleDate, salesRecordDto.getSaleDate());
+        }
+
+        // 鎸夌叅绉嶅悕绉版煡璇�
+        if (StringUtils.isNotBlank(salesRecordDto.getCoal())) {
+            LambdaQueryWrapper<CoalInfo> coalQueryWrapper = new LambdaQueryWrapper<>();
+            coalQueryWrapper.like(CoalInfo::getCoal, salesRecordDto.getCoal());
+            List<CoalInfo> coalInfos = coalInfoMapper.selectList(coalQueryWrapper);
+
+            if (!coalInfos.isEmpty()) {
+                List<Long> coalIds = coalInfos.stream()
+                        .map(CoalInfo::getId)
+                        .collect(Collectors.toList());
+                queryWrapper.in(SalesRecord::getCoalId, coalIds);
+            } else {
+                // 濡傛灉娌℃湁鍖归厤鐨勭叅绉嶏紝鐩存帴杩斿洖绌虹粨鏋�
+                queryWrapper.eq(SalesRecord::getCoalId, -1L); // 浣跨敤涓嶅彲鑳藉瓨鍦ㄧ殑ID
+            }
+        }
+
         queryWrapper.orderByDesc(SalesRecord::getCreateTime);
 
         // 2. 鑾峰彇鍒嗛〉鐨勯攢鍞褰�
@@ -482,7 +506,7 @@
 
         // 4. 鎵归噺鏌ヨ鐓ょ淇℃伅骞跺~鍏呭埌缁撴灉涓�
         if (!coalIds.isEmpty()) {
-            List<CoalInfo> coalInfos = coalInfoMapper.selectBatchIds(coalIds);
+            List<CoalInfo> coalInfos = coalInfoMapper.selectByIds(coalIds);
             for (CoalInfo coalInfo : coalInfos) {
                 Map<String, Object> record = resultMap.get(coalInfo.getId());
                 if (record != null) {
@@ -491,8 +515,33 @@
             }
         }
 
-        // 鏈�缁堢粨鏋滄槸涓�涓狶ist<Map>锛屾瘡涓狹ap鍖呭惈鍚堝苟鍚庣殑閿�鍞暟鎹拰瀵瑰簲鐨勭叅绉嶄俊鎭�
         List<Map<String, Object>> results = new ArrayList<>(resultMap.values());
+
+        //鏈堝害鏁版嵁
+        //鏌ヨ鎵�鏈夌叅绉嶄俊鎭�
+        List<CoalInfo> allCoalTypes = coalInfoMapper.selectList(
+                new QueryWrapper<CoalInfo>().orderByAsc("id")
+        );
+        //棰勮绠楅攢閲忥細鎸塩oalId鍒嗙粍缁熻鎬婚攢閲�
+        Map<Long, BigDecimal> salesByCoalId = salesRecords.stream()
+                .collect(Collectors.groupingBy(
+                        SalesRecord::getCoalId,
+                        Collectors.reducing(
+                                BigDecimal.ZERO,
+                                SalesRecord::getSaleQuantity,
+                                BigDecimal::add
+                        )
+                ));
+
+        // 2. 鍒涘缓 resultMouth锛屽瓨鍌ㄧ叅绉嶅強鍏堕攢閲忥紙Map 缁撴瀯锛�
+        Map<String, BigDecimal> resultMouthMap = new LinkedHashMap<>();
+        for (CoalInfo coal : allCoalTypes) {
+            resultMouthMap.put(
+                    coal.getCoal(),  // 鐓ょ鍚嶇О锛堝 "鏃犵儫鐓�"锛�
+                    salesByCoalId.getOrDefault(coal.getId(), BigDecimal.valueOf(0)) // 閿�閲�
+            );
+        }
+
         result.put("revenueAmount", revenueAmount.setScale(2, RoundingMode.HALF_UP));
         result.put("changeRate", changeRate);
         result.put("trend", trend);
@@ -501,6 +550,7 @@
         result.put("trendQuantity", trendQuantity);
         result.put("revenueDistribution", revenueDistribution);
         result.put("salesResults", results);
+        result.put("resultMouth", resultMouthMap);
 
         return result;
     }

--
Gitblit v1.9.3