Переглянути джерело

运行记录1225-运行记录字符串保存优化

yuanchao 4 днів тому
батько
коміт
6422f0469d

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

@@ -362,9 +362,7 @@ public class IotOpeationFillController {
             Integer userId = allFillData.get(0).getUserId();
 
 
-            for (IotDeviceRunLogDO a:logDOList) {
-                System.out.println("设备数据-------------"+a);
-            }
+
             // 6. 批量保存日志(有则更新,无则插入)
             batchSaveLogs(logDOList);
 
@@ -409,9 +407,14 @@ public class IotOpeationFillController {
         Map<String, BigDecimal> unSumDataIndex = allFillData.stream()
                 .filter(fill -> 0 == fill.getIsSum() && fill.getDeviceCode() != null
                         && !fill.getDeviceCode().isEmpty())
+                .filter(fill -> {
+                    String content = String.valueOf(fill.getFillContent()).trim();
+                    // 排除空字符串和非数字(支持整数、小数,不支持文本)
+                    return !content.isEmpty() && content.matches("^[+-]?\\d+(\\.\\d+)?$");
+                })
                 .collect(Collectors.toMap(
                         fill -> fill.getDeviceId() + "_" + fill.getModelId(), // 构建索引键
-                        fill -> new BigDecimal(fill.getFillContent()), // 提前转换为BigDecimal
+                        fill -> new BigDecimal(String.valueOf(fill.getFillContent()).trim()), // 提前转换为BigDecimal
                         (v1, v2) -> v1.add(v2) // 同维度数据直接累加(根据业务调整,此处默认累加)
                 ));
 
@@ -539,14 +542,12 @@ public class IotOpeationFillController {
                 .map(fill -> {
                     IotDeviceRunLogDO deviceRunLogDO = new IotDeviceRunLogDO();
                     deviceRunLogDO.setDeviceId(fill.getDeviceId());
-                    System.out.println("deviceId----"+fill.getDeviceId());
                     deviceRunLogDO.setDeviceCode(fill.getDeviceCode());
                     deviceRunLogDO.setFillContent(fill.getFillContent());
                     deviceRunLogDO.setPointCode(fill.getModelAttr());
                     deviceRunLogDO.setDeptId(fill.getDeptId());
                     deviceRunLogDO.setCreateTime(LocalDateTime.of(fill.getCreateTime(), localTime));
                     deviceRunLogDO.setPointName(fill.getPointName());
-                    System.out.println("totalRunTime----"+fill.getTotalRunTime());
                     deviceRunLogDO.setTotalRunTime(fill.getTotalRunTime());
                     deviceRunLogDO.setIsSum(fill.getIsSum() != null ? fill.getIsSum() : 0);
                     return deviceRunLogDO;
@@ -629,18 +630,7 @@ public class IotOpeationFillController {
                         log -> log,
                         (v1, v2) -> v1 // 避免重复key(理论上不会有)
                 ));
-        System.out.println("=== existingLogMap 详细内容 ===");
-        existingLogMap.forEach((key, log) -> {
-            System.out.println("Key: " + key);
-            // 打印IotDeviceRunLogDO的属性(根据实际字段调整)
-            System.out.println("Value: " +
-                    "deviceId=" + log.getDeviceId() +
-                    ", pointName=" + log.getPointName() +
-                    ", createTime=" + log.getCreateTime() +
-                    ", value=" + log.getValue() // 补充你实际的字段
-            );
-            System.out.println("------------------------"); // 分隔符,方便阅读
-        });
+
 
         // 2. 拆分:待插入列表 + 待更新列表
         List<IotDeviceRunLogDO> insertList = new ArrayList<>();
@@ -664,52 +654,19 @@ public class IotOpeationFillController {
 
         // 3. 批量执行(MyBatis批量操作)
         if (!insertList.isEmpty()) {
-            System.out.println("执行了插入");
-            // 方式B:带索引遍历(方便定位第几个元素有问题)
-            System.out.println("===== insertList 详细元素(带索引) =====");
-            for (int i = 0; i < insertList.size(); i++) {
-                IotDeviceRunLogDO log = insertList.get(i);
-                System.out.printf("第 %d 个元素:deviceId=%s, pointName=%s, createTime=%s%n",
-                        i + 1,
-                        log.getDeviceId(),
-                        log.getPointName(),
-                        log.getCreateTime() // 若为Date类型,建议格式化:sdf.format(log.getCreateTime())
-                );
-            }
+
             TenantUtils.execute(1L, () -> {
                 iotOpeationFillService.batchInsertLogs(insertList); // 批量插入
             });
         }
         if (!updateList.isEmpty()) {
-            System.out.println("执行了更新");
-            // 方式B:带索引遍历(方便定位第几个元素有问题)
-            System.out.println("===== insertList 详细元素(带索引) =====");
-            for (int i = 0; i < updateList.size(); i++) {
-                IotDeviceRunLogDO log = updateList.get(i);
-                System.out.printf("第 %d 个元素:deviceId=%s, pointName=%s, createTime=%s%n",
-                        i + 1,
-                        log.getDeviceId(),
-                        log.getPointName(),
-                        log.getCreateTime() // 若为Date类型,建议格式化:sdf.format(log.getCreateTime())
-                );
-            }
+
             TenantUtils.execute(1L, () -> {
                 iotOpeationFillService.batchUpdateLogs(updateList); // 批量更新普通日志
             });
         }
         if (!updateSumList.isEmpty()) {
-            System.out.println("执行了累计更新");
-            // 方式B:带索引遍历(方便定位第几个元素有问题)
-            System.out.println("===== updateSumList 详细元素(带索引) =====");
-            for (int i = 0; i < updateSumList.size(); i++) {
-                IotDeviceRunLogDO log = updateSumList.get(i);
-                System.out.printf("第 %d 个元素:deviceId=%s, pointName=%s, createTime=%s%n",
-                        i + 1,
-                        log.getDeviceId(),
-                        log.getPointName(),
-                        log.getCreateTime() // 若为Date类型,建议格式化:sdf.format(log.getCreateTime())
-                );
-            }
+
             TenantUtils.execute(1L, () -> {
                 iotOpeationFillService.batchUpdateSumLogs(updateSumList); // 批量更新累计日志
             });