From aebf1df56a02c71a5e6b4a9da395c12ed66edb1b Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期三, 14 九月 2022 14:13:12 +0800
Subject: [PATCH] changes

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java |   55 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java
index b4bdff6..7ffe4e2 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java
@@ -105,18 +105,24 @@
             throw new BusinessException("淇濆瓨璺伅浠诲姟澶辫触");
         }
         List<String> poleCodeList = new ArrayList<>();
-        if (CollectionUtil.isNotEmpty(param.getPoleIdList())) {
-            List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(param.getPoleIdList());
+        //浼犲叆鐨勭伅鏉唅d闆嗗悎
+        List<Long> poleIdList = new ArrayList<>();
+        //鍘婚噸
+        for (Long item : param.getPoleIdList()) {
+            if (!poleIdList.contains(item)) {
+                poleIdList.add(item);
+            }
+        }
+        if (CollectionUtil.isNotEmpty(poleIdList)) {
+            List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(poleIdList);
             if (CollectionUtil.isNotEmpty(poleList)) {
                 poleCodeList = poleList.stream().map(Pole::getDeviceCode).collect(Collectors.toList());
             }
         }
-        String content = "{浠诲姟ID锛�" + newLightTask.getTaskId() + "锛� 浠诲姟鍚嶏細" + newLightTask.getTaskName() + "}锛寋鍐呭抚鎸囦护" + newLightTask.getFramePayload() + "锛� 鐏潌ID锛�" + param.getPoleIdList().toString() + "锛� 鎺у埗鐨勭伅澶村湴鍧�锛�" + param.getLightAddress() + " }";
+        String content = "{浠诲姟ID锛�" + newLightTask.getTaskId() + "锛� 浠诲姟鍚嶏細" + newLightTask.getTaskName() + "}锛寋鍐呭抚鎸囦护" + newLightTask.getFramePayload() + "锛� 鐏潌ID锛�" + poleIdList.toString() + "锛� 鎺у埗鐨勭伅澶村湴鍧�锛�" + param.getLightAddress() + " }";
         StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "鏂板璺伅浠诲姟", content);
 
 
-        //浼犲叆鐨勭伅鏉唅d闆嗗悎
-        List<Long> poleIdList = param.getPoleIdList();
         //璁板綍杩欎簺鐏潌鍘熷厛鐨勪换鍔�
         List<LightTaskPoleRelation> oldLightTaskStatusAndPoles;
         if ("FFFF".equals(param.getLightAddress())) {
@@ -156,7 +162,7 @@
          * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍寮�濮�
          */
 
-        String content1 = "{浠诲姟ID锛�" + newLightTask.getTaskId() + "锛� 浠诲姟鍚嶏細" + newLightTask.getTaskName() + "}," + " 鐏潌ID锛�" + param.getPoleIdList().toString() + " }";
+        String content1 = "{浠诲姟ID锛�" + newLightTask.getTaskId() + "锛� 浠诲姟鍚嶏細" + newLightTask.getTaskName() + "}," + " 鐏潌ID锛�" + poleIdList.toString() + " }";
         StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "涓嬪彂璺伅浠诲姟", content1);
         /**
          * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍缁撴潫
@@ -172,7 +178,7 @@
             lightTaskPoleRelationService.saveBatch(all);
         }
 
-        if (!param.getPoleIdList().isEmpty() && num == newPoleMap.size()) {
+        if (!poleIdList.isEmpty() && num == newPoleMap.size()) {
             //鎵�鏈夌伅鏉嗛兘涓嬪彂澶辫触 鏂板鐨勪换鍔′笉淇濈暀
             removeById(newLightTask);
             throw new BusinessException("鎸囦护涓嬪彂澶辫触,璇锋鏌ョ伅鏉嗙姸鎬佸悗閲嶆柊鏂板浠诲姟");
@@ -217,7 +223,13 @@
 
 
         //缂栬緫鍚庣伅鏉咺D闆嗗悎
-        List<Long> poleIdList = param.getPoleIdList();
+        List<Long> poleIdList = new ArrayList<>();
+        //鍘婚噸
+        for (Long item : param.getPoleIdList()) {
+            if (!poleIdList.contains(item)) {
+                poleIdList.add(item);
+            }
+        }
         if (poleIdList.isEmpty()) {
             throw new BusinessException("缂栬緫浠诲姟鏃惰閫夋嫨鐏潌");
         }
@@ -225,12 +237,12 @@
         List<LightTaskStatusAndPole> oldLightTaskStatusAndPoles = lightTaskPoleRelationService.listPoleAndStatusIdByTaskId(taskId);
         List<Long> oldList = oldLightTaskStatusAndPoles.stream().map(LightTaskStatusAndPole::getId).collect(Collectors.toList());
 
-        //鍒ゆ柇param.getPoleIdList()涓槸鍚︽湁鏃х殑鐏潌ID    (鐩存帴涓嬪彂)
-        List<Long> newPoleIdList = param.getPoleIdList().stream().filter(poleId -> !oldList.contains(poleId)).collect(Collectors.toList());
-        //鍒ゆ柇param.getPoleIdList()涓槸鍚︽湁鏂扮殑鐏潌ID    (瑕嗙洊鎿嶄綔)
-        List<Long> oldPoleIdList = param.getPoleIdList().stream().filter(poleId -> oldList.contains(poleId)).collect(Collectors.toList());
-        //oldList涓湁鐨勭伅鏉咺D锛屼絾鏄痯aram.getPoleIdList()涓病鏈� (鍏崇伅鎿嶄綔)
-        List<Long> closeLight = oldList.stream().filter(poleId -> !param.getPoleIdList().contains(poleId)).collect(Collectors.toList());
+        //鍒ゆ柇poleIdList涓槸鍚︽湁鏃х殑鐏潌ID    (鐩存帴涓嬪彂)
+        List<Long> newPoleIdList = poleIdList.stream().filter(poleId -> !oldList.contains(poleId)).collect(Collectors.toList());
+        //鍒ゆ柇poleIdList涓槸鍚︽湁鏂扮殑鐏潌ID    (瑕嗙洊鎿嶄綔)
+        List<Long> oldPoleIdList = poleIdList.stream().filter(poleId -> oldList.contains(poleId)).collect(Collectors.toList());
+        //oldList涓湁鐨勭伅鏉咺D锛屼絾鏄痯oleIdList涓病鏈� (鍏崇伅鎿嶄綔)
+        List<Long> closeLight = oldList.stream().filter(poleId -> !poleIdList.contains(poleId)).collect(Collectors.toList());
 
 
         //鍙栧嚭瑕嗙洊鎿嶄綔鐨勫叧绯讳俊鎭�
@@ -317,13 +329,13 @@
          * 缂栬緫璺伅浠诲姟鏃ュ織璁板綍寮�濮�
          */
         List<String> poleCodeList = new ArrayList<>();
-        if (CollectionUtil.isNotEmpty(param.getPoleIdList())) {
-            List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(param.getPoleIdList());
+        if (CollectionUtil.isNotEmpty(poleIdList)) {
+            List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(poleIdList);
             if (CollectionUtil.isNotEmpty(poleList)) {
                 poleCodeList = poleList.stream().map(Pole::getDeviceCode).collect(Collectors.toList());
             }
         }
-        String content = "{浠诲姟ID锛�" + newLightTask.getTaskId() + "锛� 浠诲姟鍚嶏細" + newLightTask.getTaskName() + "}锛寋鍐呭抚鎸囦护" + newLightTask.getFramePayload() + "锛� 鐏潌ID锛�" + param.getPoleIdList().toString() + "锛� 鎺у埗鐨勭伅澶村湴鍧�锛�" + param.getLightAddress() + " }";
+        String content = "{浠诲姟ID锛�" + newLightTask.getTaskId() + "锛� 浠诲姟鍚嶏細" + newLightTask.getTaskName() + "}锛寋鍐呭抚鎸囦护" + newLightTask.getFramePayload() + "锛� 鐏潌ID锛�" + poleIdList.toString() + "锛� 鎺у埗鐨勭伅澶村湴鍧�锛�" + param.getLightAddress() + " }";
         StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "缂栬緫璺伅浠诲姟", content);
         /**
          * 缂栬緫璺伅浠诲姟鏃ュ織璁板綍缁撴潫
@@ -348,10 +360,9 @@
 
         List<LightTaskPoleRelation> all = new ArrayList<>();
         all.addAll(newPoleSuccess);
-        all.addAll(oldPoleFail);
         all.addAll(oldPoleSuccess);
-        all.addAll(oldPoleFail);
-        all.addAll(closePoleFail);
+//        all.addAll(oldPoleFail);
+//        all.addAll(closePoleFail);
 
 
         List<Long> allPoleId = new ArrayList<>();
@@ -378,7 +389,7 @@
         /**
          * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍寮�濮�
          */
-        String content1 = "{浠诲姟ID锛�" + newLightTask.getTaskId() + "锛� 浠诲姟鍚嶏細" + newLightTask.getTaskName() + "}," + " 鐏潌ID锛�" + param.getPoleIdList().toString() + " }";
+        String content1 = "{浠诲姟ID锛�" + newLightTask.getTaskId() + "锛� 浠诲姟鍚嶏細" + newLightTask.getTaskName() + "}," + " 鐏潌ID锛�" + poleCodeList.toString() + " }";
         StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "涓嬪彂璺伅浠诲姟", content1);
         /**
          * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍缁撴潫
@@ -390,7 +401,7 @@
             throw new BusinessException("缂栬緫澶辫触,璇锋鏌ュ師鏈夎澶囧拰缂栬緫鍚庣殑璁惧鏄惁鍦ㄧ嚎!");
         } else if (!closePoleFail.isEmpty() && !newPoleSuccess.isEmpty() && !oldPoleFail.isEmpty()) {
             return "鍘熶换鍔′腑瀛樺湪涓嬪彂寮傚父锛屽師浠诲姟淇濈暀锛屽垱寤烘柊浠诲姟杩涜淇濆瓨";
-        } else if (!newPoleFail.isEmpty() && !newPoleSuccess.isEmpty()) {
+        } else if (!newPoleFail.isEmpty()) {
             return "鏂颁换鍔′腑瀛樺湪涓嬪彂寮傚父锛屽拷鐣ュ紓甯告搷浣滅殑鐏潌";
         } else {
             return "鎿嶄綔寮傚父";

--
Gitblit v1.9.3