瀏覽代碼

"设备指标同步"

yangjunfeng 1 月之前
父節點
當前提交
81482d1c69
共有 1 個文件被更改,包括 12 次插入5 次删除
  1. 12 5
      ylsw-scada/src/main/java/com/tofly/scada/service/impl/ScadaServiceImpl.java

+ 12 - 5
ylsw-scada/src/main/java/com/tofly/scada/service/impl/ScadaServiceImpl.java

@@ -1764,7 +1764,7 @@ public class ScadaServiceImpl extends ServiceImpl<ScadaMapper, Scada> implements
         List<DeviceArchiveManage> manages = deviceArchiveManageService.list();
         // 存储设备和指标数据
         List<Allocation> parameterList = new ArrayList<>();
-        List<Allocation> parameters = allocationService.list();
+        List<Allocation> parameters = allocationMapper.selectList(new QueryWrapper<>());
         for (DeviceArchiveManage deviceArchiveManage : manages) {
             List<Allocation> parametersFinal = new ArrayList<>();
             if (CollUtil.isNotEmpty(parameters)) {
@@ -1777,14 +1777,21 @@ public class ScadaServiceImpl extends ServiceImpl<ScadaMapper, Scada> implements
         if (CollUtil.isNotEmpty(parameterList)) {
             parameterList = parameterList.stream().collect(Collectors.collectingAndThen(Collectors
                     .toCollection(() -> new TreeSet<>(Comparator.comparing(Allocation::getVariableCode))), ArrayList::new));
-            parameterList.forEach(allocationService::save);
+            List<String> codeFilterList = parameters.stream().map(Allocation::getVariableCode).collect(Collectors.toList());
+            parameterList.forEach(info -> {
+                if (codeFilterList.contains(info.getVariableCode())) {
+                    allocationMapper.update(info, new QueryWrapper<Allocation>().lambda().eq(Allocation::getVariableCode, info.getVariableCode()));
+                } else {
+                    allocationMapper.insert(info);
+                }
+            });
         }
         List<String> monitorCodeList = scadaMonitorService.list().stream().map(ScadaMonitor::getCode).collect(Collectors.toList());
-        List<Allocation> parameterAll = allocationService.list();
+        List<Allocation> parameterAll = allocationMapper.selectList(new QueryWrapper<>());
         List<Allocation> parameterPart = parameterAll.stream().filter(e -> !monitorCodeList.contains(e.getVariableCode())).collect(Collectors.toList());
         if (CollUtil.isNotEmpty(parameterPart)) {
             if (parameterPart.size() <= 500) {
-                allocationService.remove(new QueryWrapper<Allocation>().lambda().in(Allocation::getVariableCode, parameterPart.stream().map(Allocation::getVariableCode).collect(Collectors.toList())));
+                allocationMapper.delete(new QueryWrapper<Allocation>().lambda().in(Allocation::getVariableCode, parameterPart.stream().map(Allocation::getVariableCode).collect(Collectors.toList())));
             } else {
                 int times = parameterPart.size() / 500;
                 for (int i = 0; i <= times; i++) {
@@ -1792,7 +1799,7 @@ public class ScadaServiceImpl extends ServiceImpl<ScadaMapper, Scada> implements
                     if (CollUtil.isEmpty(allocationListFinal)) {
                         continue;
                     }
-                    allocationService.remove(new QueryWrapper<Allocation>().lambda().in(Allocation::getVariableCode, allocationListFinal.stream().map(Allocation::getVariableCode).collect(Collectors.toList())));
+                    allocationMapper.delete(new QueryWrapper<Allocation>().lambda().in(Allocation::getVariableCode, allocationListFinal.stream().map(Allocation::getVariableCode).collect(Collectors.toList())));
                 }
             }
         }