From edbb2fe4eabbb7c526fb2f7313bead37d38928e2 Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期一, 15 八月 2022 14:57:16 +0800
Subject: [PATCH] 充电桩上电请求

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/VnnoxService.java |  242 ++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 214 insertions(+), 28 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/VnnoxService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/VnnoxService.java
index c798cd6..c7e54af 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/VnnoxService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/VnnoxService.java
@@ -8,6 +8,7 @@
 import com.sandu.ximon.admin.dto.nova.PlayerPage;
 import com.sandu.ximon.admin.dto.nova.PlayerWidget;
 import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereHeartbeatReportInnerFrame;
+import com.sandu.ximon.admin.security.SecurityUtils;
 import com.sandu.ximon.admin.utils.RedisUtils;
 import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
 import com.sandu.ximon.admin.utils.VnnoxAPIUtil;
@@ -16,6 +17,7 @@
 import com.sandu.ximon.admin.utils.response.VnnoxPlayerListResponse;
 import com.sandu.ximon.admin.utils.response.VnnoxPlayerResponse;
 import com.sandu.ximon.admin.utils.response.VnnoxResult;
+import com.sandu.ximon.admin.vo.NovaPushResultVO;
 import com.sandu.ximon.dao.domain.LedPlayerEntity;
 import com.sandu.ximon.dao.domain.LedPlayerInfoEntity;
 import com.sandu.ximon.dao.domain.LedV2RegisterResultEntity;
@@ -106,7 +108,15 @@
      * @param screenStatus
      * @return
      */
-    public VnnoxResult screenStatusChange(List<LedPlayerEntity> playerList, Integer screenStatus) {
+    public Map<String, Object> screenStatusChange(List<LedPlayerEntity> playerList, Integer screenStatus) {
+        playerList.forEach(item -> {
+            if (item.getName() == null || item.getPlayerId() == null) {
+                throw new BusinessException("playerId鎴杙layerName涓虹┖");
+            }
+            if (item.getPlayerId().isEmpty() || item.getName().isEmpty()) {
+                throw new BusinessException("playerId鎴杙layerName涓虹┖");
+            }
+        });
         VnnoxScreenStatusType type;
         if (screenStatus.equals(0)) {
             type = VnnoxScreenStatusType.CLOSE;
@@ -115,29 +125,120 @@
         }
 
         VnnoxResult vnnoxResult = vnnoxAPIUtil.screenStatus(playerList.stream().map(item -> item.getPlayerId()).collect(Collectors.toList()), type);
+
+
+        List<String> success = vnnoxResult.getSuccess();
+        List<String> fail = vnnoxResult.getFail();
+        //鎷兼帴鎴愬姛澶辫触鐨勭粨鏋�
+        Map<String, Object> result = new HashMap<>();
+        List<NovaPushResultVO> successList = new ArrayList<>();
+        List<NovaPushResultVO> faileList = new ArrayList<>();
+        List<String> finalSuccess = success;
+        List<String> finalFail = fail;
+        playerList.forEach(n -> {
+            if (finalSuccess.contains(n.getPlayerId())) {
+                NovaPushResultVO vo = new NovaPushResultVO();
+                vo.setName(n.getName());
+                vo.setPlayerId(n.getPlayerId());
+                successList.add(vo);
+            } else if (finalFail.contains(n.getPlayerId())) {
+                NovaPushResultVO vo = new NovaPushResultVO();
+                vo.setName(n.getName());
+                vo.setPlayerId(n.getPlayerId());
+                faileList.add(vo);
+            }
+        });
+
+        result.put("success", successList);
+        result.put("fail", faileList);
+
         //  鏍规嵁灞忓箷鐘舵�佽皟鏁碦EDIS鏍囪瘑浣�
         for (String playerId : vnnoxResult.getSuccess()) {
             redisUtils.set(VnnoxConstant.REDIS_SCREEN_STATUS + playerId, screenStatus, VnnoxConstant.REDIS_MAX_SAVE_TIME);
         }
-        return vnnoxResult;
+        return result;
     }
 
-    public VnnoxResult volChange(List<LedPlayerEntity> playerList, Integer vol) {
+    public Map<String, Object> volChange(List<LedPlayerEntity> playerList, Integer vol) {
+        playerList.forEach(item -> {
+            if (item.getName() == null || item.getPlayerId() == null) {
+                throw new BusinessException("playerId鎴杙layerName涓虹┖");
+            }
+            if (item.getPlayerId().isEmpty() || item.getName().isEmpty()) {
+                throw new BusinessException("playerId鎴杙layerName涓虹┖");
+            }
+        });
         VnnoxResult vnnoxResult = vnnoxAPIUtil.volChange(playerList.stream().map(item -> item.getPlayerId()).collect(Collectors.toList()), vol);
         //  鏍规嵁闊抽噺璋冩暣REDIS鏍囪瘑浣�
         for (String playerId : vnnoxResult.getSuccess()) {
             redisUtils.set(VnnoxConstant.REDIS_VOL + playerId, vol, VnnoxConstant.REDIS_MAX_SAVE_TIME);
         }
-        return vnnoxResult;
+        List<String> success = vnnoxResult.getSuccess();
+        List<String> fail = vnnoxResult.getFail();
+        //鎷兼帴鎴愬姛澶辫触鐨勭粨鏋�
+        Map<String, Object> result = new HashMap<>();
+        List<NovaPushResultVO> successList = new ArrayList<>();
+        List<NovaPushResultVO> faileList = new ArrayList<>();
+        List<String> finalSuccess = success;
+        List<String> finalFail = fail;
+        playerList.forEach(n -> {
+            if (finalSuccess.contains(n.getPlayerId())) {
+                NovaPushResultVO vo = new NovaPushResultVO();
+                vo.setName(n.getName());
+                vo.setPlayerId(n.getPlayerId());
+                successList.add(vo);
+            } else if (finalFail.contains(n.getPlayerId())) {
+                NovaPushResultVO vo = new NovaPushResultVO();
+                vo.setName(n.getName());
+                vo.setPlayerId(n.getPlayerId());
+                faileList.add(vo);
+            }
+        });
+
+        result.put("success", successList);
+        result.put("fail", faileList);
+        return result;
     }
 
-    public VnnoxResult brightnessChange(List<LedPlayerEntity> playerList, Integer brightness) {
+    public Map<String, Object> brightnessChange(List<LedPlayerEntity> playerList, Integer brightness) {
+        playerList.forEach(item -> {
+            if (item.getName() == null || item.getPlayerId() == null) {
+                throw new BusinessException("playerId鎴杙layerName涓虹┖");
+            }
+            if (item.getPlayerId().isEmpty() || item.getName().isEmpty()) {
+                throw new BusinessException("playerId鎴杙layerName涓虹┖");
+            }
+        });
         VnnoxResult vnnoxResult = vnnoxAPIUtil.brightnessChange(playerList.stream().map(item -> item.getPlayerId()).collect(Collectors.toList()), brightness);
         //  鏍规嵁浜害璋冩暣REDIS鏍囪瘑浣�
         for (String playerId : vnnoxResult.getSuccess()) {
             redisUtils.set(VnnoxConstant.REDIS_BRIGHTNESS + playerId, brightness, VnnoxConstant.REDIS_MAX_SAVE_TIME);
         }
-        return vnnoxResult;
+        List<String> success = vnnoxResult.getSuccess();
+        List<String> fail = vnnoxResult.getFail();
+        //鎷兼帴鎴愬姛澶辫触鐨勭粨鏋�
+        Map<String, Object> result = new HashMap<>();
+        List<NovaPushResultVO> successList = new ArrayList<>();
+        List<NovaPushResultVO> faileList = new ArrayList<>();
+        List<String> finalSuccess = success;
+        List<String> finalFail = fail;
+        playerList.forEach(n -> {
+            if (finalSuccess.contains(n.getPlayerId())) {
+                NovaPushResultVO vo = new NovaPushResultVO();
+                vo.setName(n.getName());
+                vo.setPlayerId(n.getPlayerId());
+                successList.add(vo);
+            } else if (finalFail.contains(n.getPlayerId())) {
+                NovaPushResultVO vo = new NovaPushResultVO();
+                vo.setName(n.getName());
+                vo.setPlayerId(n.getPlayerId());
+                faileList.add(vo);
+            }
+        });
+
+        result.put("success", successList);
+        result.put("fail", faileList);
+        return result;
 
     }
 
@@ -193,8 +294,40 @@
 //    }
 
     //閲嶅惎
-    public VnnoxResult reboot(List<String> playerList) {
-        return vnnoxAPIUtil.reboot(playerList);
+    public Map<String, Object> reboot(List<NovaPushResultVO> nova) {
+        List<String> playerIds = new ArrayList<>();
+        nova.forEach(item -> {
+            if (item.getName() == null || item.getPlayerId() == null) {
+                throw new BusinessException("playerId鎴杙layerName涓虹┖");
+            }
+            if (item.getPlayerId().isEmpty() || item.getName().isEmpty()) {
+                throw new BusinessException("playerId鎴杙layerName涓虹┖");
+            }
+            playerIds.add(item.getPlayerId());
+        });
+
+        VnnoxResult reboot = vnnoxAPIUtil.reboot(playerIds);
+
+
+        List<String> success = reboot.getSuccess();
+        List<String> fail = reboot.getFail();
+        //鎷兼帴鎴愬姛澶辫触鐨勭粨鏋�
+        Map<String, Object> result = new HashMap<>();
+        List<NovaPushResultVO> successList = new ArrayList<>();
+        List<NovaPushResultVO> faileList = new ArrayList<>();
+        List<String> finalSuccess = success;
+        List<String> finalFail = fail;
+        nova.forEach(n -> {
+            if (finalSuccess.contains(n.getPlayerId())) {
+                successList.add(n);
+            } else if (finalFail.contains(n.getPlayerId())) {
+                faileList.add(n);
+            }
+        });
+
+        result.put("success", successList);
+        result.put("fail", faileList);
+        return result;
     }
 
     /**
@@ -203,8 +336,38 @@
      * @param
      * @return
      */
-    public VnnoxResult syncPlay(List<String> playerList, Integer option) {
-        return vnnoxAPIUtil.syncPlay(playerList, option);
+    public Map<String, Object> syncPlay(List<NovaPushResultVO> nova, Integer option) {
+        List<String> playerIds = new ArrayList<>();
+        nova.forEach(item -> {
+            if (item.getName() == null || item.getPlayerId() == null) {
+                throw new BusinessException("playerId鎴杙layerName涓虹┖");
+            }
+            if (item.getPlayerId().isEmpty() || item.getName().isEmpty()) {
+                throw new BusinessException("playerId鎴杙layerName涓虹┖");
+            }
+            playerIds.add(item.getPlayerId());
+        });
+        VnnoxResult vnnoxResult = vnnoxAPIUtil.syncPlay(playerIds, option);
+
+        List<String> success = vnnoxResult.getSuccess();
+        List<String> fail = vnnoxResult.getFail();
+        //鎷兼帴鎴愬姛澶辫触鐨勭粨鏋�
+        Map<String, Object> result = new HashMap<>();
+        List<NovaPushResultVO> successList = new ArrayList<>();
+        List<NovaPushResultVO> faileList = new ArrayList<>();
+        List<String> finalSuccess = success;
+        List<String> finalFail = fail;
+        nova.forEach(n -> {
+            if (finalSuccess.contains(n.getPlayerId())) {
+                successList.add(n);
+            } else if (finalFail.contains(n.getPlayerId())) {
+                faileList.add(n);
+            }
+        });
+
+        result.put("success", successList);
+        result.put("fail", faileList);
+        return result;
     }
 
     /**
@@ -213,8 +376,38 @@
      * @param
      * @return
      */
-    public VnnoxResult ntpSync(List<String> playerList, boolean enable) {
-        return vnnoxAPIUtil.ntpSync(playerList, enable);
+    public Map<String, Object> ntpSync(List<NovaPushResultVO> nova, boolean enable) {
+        List<String> playerIds = new ArrayList<>();
+        nova.forEach(item -> {
+            if (item.getName() == null || item.getPlayerId() == null) {
+                throw new BusinessException("playerId鎴杙layerName涓虹┖");
+            }
+            if (item.getPlayerId().isEmpty() || item.getName().isEmpty()) {
+                throw new BusinessException("playerId鎴杙layerName涓虹┖");
+            }
+            playerIds.add(item.getPlayerId());
+        });
+        VnnoxResult vnnoxResult = vnnoxAPIUtil.ntpSync(playerIds, enable);
+
+        List<String> success = vnnoxResult.getSuccess();
+        List<String> fail = vnnoxResult.getFail();
+        //鎷兼帴鎴愬姛澶辫触鐨勭粨鏋�
+        Map<String, Object> result = new HashMap<>();
+        List<NovaPushResultVO> successList = new ArrayList<>();
+        List<NovaPushResultVO> faileList = new ArrayList<>();
+        List<String> finalSuccess = success;
+        List<String> finalFail = fail;
+        nova.forEach(n -> {
+            if (finalSuccess.contains(n.getPlayerId())) {
+                successList.add(n);
+            } else if (finalFail.contains(n.getPlayerId())) {
+                faileList.add(n);
+            }
+        });
+
+        result.put("success", successList);
+        result.put("fail", faileList);
+        return result;
     }
 
 
@@ -223,9 +416,11 @@
         if (byId == null) {
             throw new BusinessException("鏈壘鍒拌璁惧");
         }
-        boolean belong = SpringContextHolder.getBean(PoleBindingService.class).isBelong(byId.getSn(), PoleBindingEnums.VONNOX);
-        if (!belong) {
-            throw new BusinessException("璇ヨ澶囦笉灞炰簬鎮�,涓嶈兘淇敼璁惧淇℃伅");
+        if (SecurityUtils.getClientId() != null) {
+            boolean belong = SpringContextHolder.getBean(PoleBindingService.class).isBelong(byId.getSn(), PoleBindingEnums.VONNOX);
+            if (!belong) {
+                throw new BusinessException("璇ヨ澶囦笉灞炰簬鎮�,涓嶈兘淇敼璁惧淇℃伅");
+            }
         }
         LedPlayerEntity led = new LedPlayerEntity();
         led.setId(id);
@@ -234,8 +429,8 @@
          * 璇虹摝璁惧缂栬緫 鏃ュ織璁板綍寮�濮�
          */
         List<String> listCode = new ArrayList<>(1);
-        listCode.add(led.getSn());
-        String content = "{ 璁惧id:" + led.getId() + "璁惧code锛�" + led.getSn() + "璇虹摝playId:" + led.getPlayerId() + "璇虹摝璁惧鍘熷悕:" + byId.getName() + "璇虹摝璁惧鏇存敼鍚庣殑鍚嶇О:" + led.getName() + "}";
+        listCode.add(byId.getSn());
+        String content = "{ 璁惧id:" + led.getId() + "璁惧code锛�" + byId.getSn() + "璇虹摝playId:" + led.getPlayerId() + "璇虹摝璁惧鍘熷悕:" + byId.getName() + "璇虹摝璁惧鏇存敼鍚庣殑鍚嶇О:" + led.getName() + "}";
 
         StoreOperationRecordsUtils.storeOperationData(listCode, null, "璇虹摝璁惧缂栬緫", content);
         /**
@@ -278,7 +473,6 @@
 
             //  璁剧疆缂╃暐鍥捐闂矾寰�
             result = redisUtils.get(VnnoxConstant.REDIS_SCREEN_SHOT + playerId);
-            System.out.println(playerId + "鐨勮矾寰勭粨鏋�:-----------------------------" + result);
             if (null != result) {
                 playerEntity.setScreenShotUrl(result);
             } else {
@@ -304,8 +498,6 @@
         list.add(playerPage);
         playerProgram.setPages(list);
         playerProgram.setNoticeUrl(VnnoxConstant.NOTIFY_URL);
-
-
         /**
          * 璇虹摝鎺ㄩ�佸ぇ姘旀暟鎹� 鏃ュ織璁板綍寮�濮�
          ////         */
@@ -320,17 +512,11 @@
 
 
     private List<PlayerWidget> generateWaterAndSensorWidget(A5AtmosphereHeartbeatReportInnerFrame.HeartBeatDataPackage poleSensorEntity) {
+        //TODO
         List widgetList = new ArrayList<>();
         List<String> list = new ArrayList<>();
-//        if (Objects.nonNull(waterDataEntity)) {
-//            list.add("姘磋川鐜鐩戞祴瀹炴椂鏁版嵁锛�");
-//            list.add("ph锛�"+waterDataEntity.getPh());
-//            list.add("婧惰В姘э細"+waterDataEntity.getDoData() + "(mg/L)");
-//            list.add("鐢靛鐜囷細"+waterDataEntity.getEc() + "(10^(-6)S)");
-//            list.add("娴婂害锛�"+waterDataEntity.getNtu() + "NTU");
-//        }
         if (Objects.nonNull(poleSensorEntity)) {
-//            list.add("鐜鐩戞祴锛�");
+            list.add("鐜鐩戞祴锛�");
             list.add("娓╁害锛�" + poleSensorEntity.getTemperature() + "掳");
             list.add("婀垮害锛�" + poleSensorEntity.getHumidity() + "%");
             list.add("pm25锛�" + poleSensorEntity.getPm25() + "渭g/m鲁");

--
Gitblit v1.9.3