Bläddra i källkod

运行记录1219-运行记录日报设备查询优化

yuanchao 1 vecka sedan
förälder
incheckning
1814e3fe12

+ 3 - 3
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotopeationfill/IotOpeationFillController.java

@@ -1087,7 +1087,7 @@ public class IotOpeationFillController {
         }
 
         // 批量查询reportList和reportList1(一次查询,避免循环)
-        List<IotOpeationFillDO> reportList = iotOpeationFillService.reportList(fillDO2);
+        List<IotOpeationFillDO> reportList = iotOpeationFillService.reportList2(fillDO2);
         List<IotOpeationFillDO> reportList1 = iotOpeationFillService.reportList1(fillDO2);
 
         // 构建属性名到数据的映射(提前分组,避免重复stream过滤)
@@ -1108,12 +1108,12 @@ public class IotOpeationFillController {
         });
 
         // 批量查询runLog数据(一次查询,替代循环查询)
-        Map<Long, String> runLogFillContentMap = new HashMap<>();
+        Map<String, String> runLogFillContentMap = new HashMap<>();
         if (!runLogQueries.isEmpty()) {
             List<IotDeviceRunLogDO> runLogList = iotOpeationFillService.batchReportData(runLogQueries);
             runLogFillContentMap = runLogList.stream()
                     .collect(Collectors.toMap(
-                            logDO -> logDO.getDeviceId(), // orgName
+                            logDO -> logDO.getPointName(), // orgName
                             logDO -> logDO.getFillContent() != null ? logDO.getFillContent() : "",
                             (v1, v2) -> v1 // 冲突时取第一个
                     ));

+ 3 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotopeationfill/IotOpeationFillMapper.java

@@ -277,6 +277,9 @@ public interface IotOpeationFillMapper extends BaseMapperX<IotOpeationFillDO> {
     @TenantIgnore
     List<IotOpeationFillDO> reportList(IotOpeationFillDO fillDO);
 
+    @TenantIgnore
+    List<IotOpeationFillDO> reportList2(IotOpeationFillDO fillDO);
+
 
     @TenantIgnore
     List<IotModelTemplateAttrsDO> getAttrsById(IotModelTemplateAttrsRespVO vo);

+ 2 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotopeationfill/IotOpeationFillService.java

@@ -223,4 +223,6 @@ public interface IotOpeationFillService {
 
     Map<Long, IotOpeationFillDO> batchGetOrderDO(List<IotOpeationFillDO> queries);
 
+    List<IotOpeationFillDO> reportList2(IotOpeationFillDO fillDO);
+
 }

+ 6 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotopeationfill/IotOpeationFillServiceImpl.java

@@ -547,7 +547,7 @@ public class IotOpeationFillServiceImpl implements IotOpeationFillService {
                 // 第一个参数:Map 的 Key(取自 DO 的 Long 字段)
                 // 第二个参数:Map 的 Value(DO 本身)
                 .collect(Collectors.toMap(
-                        IotOpeationFillDO::getId,  // 示例:用 id 作为 Key,替换为实际字段(如 getOrderId())
+                        IotOpeationFillDO::getDeviceId,  // 示例:用 id 作为 Key,替换为实际字段(如 getOrderId())
                         Function.identity(),       // Value:DO本身(简化写法)
                         (oldValue, newValue) -> oldValue  // 重复Key时保留旧值(核心修复点)
                         // 可选:如需保留新值,改为 (oldValue, newValue) -> newValue           // Value 直接是 DO 实例(可简化为 Function.identity())
@@ -555,4 +555,9 @@ public class IotOpeationFillServiceImpl implements IotOpeationFillService {
         return fillDOMap;
     }
 
+    @Override
+    public List<IotOpeationFillDO> reportList2(IotOpeationFillDO fillDO) {
+        return iotOpeationFillMapper.reportList2(fillDO);
+    }
+
 }

+ 46 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotOpeationFillMapper.xml

@@ -1317,10 +1317,12 @@
     <select id="batchGetOrderDO" parameterType="java.util.List"
             resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
         select
+            device_id,
             order_id
         from(
         -- 内层查询:批量匹配条件 + 去重(同一 deviceId+日期 取最新记录)
         SELECT
+        device_id,
         order_id
         FROM
         rq_iot_opeation_fill
@@ -1400,6 +1402,50 @@
           and a.device_code != ''
     </select>
 
+
+
+    <select id="reportList2" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
+            resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
+        SELECT DISTINCT
+            a.device_id,
+            a.device_code,
+            a.device_name,
+            a.create_time,
+            b.name AS org_name
+        FROM
+            rq_iot_opeation_fill a
+                INNER JOIN
+            rq_iot_model_template_attrs b
+            ON
+                a.device_category_id = b.device_category_id
+        WHERE
+            a.order_id = #{orderId}
+          AND (
+            -- 第一个查询的条件
+                (a.is_report = 1 AND b.daily_report = 0
+                    AND b.name NOT IN (
+                        SELECT
+                            DISTINCT
+                            b2.name
+                        FROM
+                            rq_iot_opeation_fill a2
+                                INNER JOIN
+                            rq_iot_model_template_attrs b2
+                            ON
+                                a2.device_category_id = b2.device_category_id
+                        WHERE
+                            a2.order_id =  #{orderId}
+                          AND
+                            a2.is_report = 0
+                          AND
+                            b2.daily_report = 1
+                    ))
+                -- 第二个查询的条件(通过OR代替UNION)
+                OR (a.is_report is null AND b.daily_report = 1)
+            )
+    </select>
+
+
     <select id="reportList1" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"
             resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
         SELECT DISTINCT