From 4e53338c0c6859a43693f3f690f0c05da888a02e Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 12 八月 2022 11:48:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/VnnoxService.java |  401 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 364 insertions(+), 37 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 f64b1b9..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
@@ -1,24 +1,33 @@
 package com.sandu.ximon.admin.service;
 
 import com.sandu.common.execption.BusinessException;
+import com.sandu.common.util.SpringContextHolder;
 import com.sandu.ximon.admin.config.VnnoxConstant;
+import com.sandu.ximon.admin.dto.nova.AirDataProgram;
+import com.sandu.ximon.admin.dto.nova.PlayerLayout;
+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;
+import com.sandu.ximon.admin.utils.VnnoxProgramAPIUtil;
 import com.sandu.ximon.admin.utils.request.VnnoxScreenStatusType;
 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;
+import com.sandu.ximon.dao.enums.PoleBindingEnums;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.net.URISyntaxException;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -30,12 +39,14 @@
 @AllArgsConstructor
 public class VnnoxService {
 
-   // @Autowired
+
     private VnnoxAPIUtil vnnoxAPIUtil;
-   // @Autowired
+
     private RedisUtils redisUtils;
-   // @Autowired
+
     private LedPlayerEntityService ledPlayerEntityService;
+
+    private VnnoxProgramAPIUtil vnnoxProgramAPIUtil;
 
     /**
      * 璁惧鏍¢獙娉ㄥ唽
@@ -44,7 +55,7 @@
      * @return
      */
     @Transactional(rollbackFor = Exception.class)
-    public LedV2RegisterResultEntity validateSN(String name,String sn) throws URISyntaxException {
+    public LedV2RegisterResultEntity validateSN(String name, String sn) throws URISyntaxException {
         LedV2RegisterResultEntity ledV2RegisterResultEntity = new LedV2RegisterResultEntity();
 
         //  鍒ゆ柇鏁版嵁搴撴槸鍚﹀瓨鍦紝鑻ヤ笉瀛樺湪锛屽垽鏂槸鍚﹀凡缁忔敞鍐屽埌Vnnox鏈嶅姟鍣�
@@ -61,13 +72,13 @@
         Integer limit = 100;
         List<VnnoxPlayerResponse> playerList;
         //  鑾峰彇Vnnox鏈嶅姟鍣ㄥ垪琛�
-        VnnoxPlayerListResponse response = vnnoxAPIUtil.getPlayerList(limit, page,name);
+        VnnoxPlayerListResponse response = vnnoxAPIUtil.getPlayerList(limit, page, name);
         playerList = response.getRows();
         Integer total = response.getTotal() - limit;
         while (total > 0) {
             page = page + 1;
             total = total - limit;
-            response = vnnoxAPIUtil.getPlayerList(limit, page,name);
+            response = vnnoxAPIUtil.getPlayerList(limit, page, name);
             playerList.addAll(response.getRows());
         }
         ledPlayerEntity = new LedPlayerEntity();
@@ -97,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;
@@ -105,42 +124,125 @@
             type = VnnoxScreenStatusType.OPEN;
         }
 
-        VnnoxResult vnnoxResult = vnnoxAPIUtil.screenStatus(
-                playerList.stream().map(item -> item.getPlayerId()).collect(Collectors.toList()),
-                type
-        );
+        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) {
-        VnnoxResult vnnoxResult = vnnoxAPIUtil.volChange(
-                playerList.stream().map(item -> item.getPlayerId()).collect(Collectors.toList()),
-                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) {
-        VnnoxResult vnnoxResult = vnnoxAPIUtil.brightnessChange(
-                playerList.stream().map(item -> item.getPlayerId()).collect(Collectors.toList()),
-                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;
 
     }
 
+    //鎴睆
     public Map<String, String> getScreenShotUrl(Integer id) {
         Map<String, String> map = new HashMap();
 
@@ -182,25 +284,250 @@
         return map;
     }
 
+//    //閲嶅惎
+//    public VnnoxResult reboot(List<LedPlayerEntity> playerList) {
+//        return vnnoxAPIUtil.reboot(
+//                playerList.stream().map(
+//                        item -> item.getPlayerId()
+//                ).collect(Collectors.toList())
+//        );
+//    }
 
-    public VnnoxResult reboot(List<LedPlayerEntity> playerList) {
-        return vnnoxAPIUtil.reboot(
-                playerList.stream().map(
-                        item -> item.getPlayerId()
-                ).collect(Collectors.toList())
-        );
+    //閲嶅惎
+    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;
     }
 
-    public boolean updateDataName(Long  id, String name){
+    /**
+     * 鍚屾鎾斁
+     *
+     * @param
+     * @return
+     */
+    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;
+    }
+
+    /**
+     * 瀵规椂
+     *
+     * @param
+     * @return
+     */
+    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;
+    }
+
+
+    public boolean updateDataName(Long id, String name) {
         LedPlayerEntity byId = ledPlayerEntityService.getById(id);
-        if(byId==null){
+        if (byId == null) {
             throw new BusinessException("鏈壘鍒拌璁惧");
         }
-        LedPlayerEntity led=new LedPlayerEntity();
+        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);
         led.setName(name);
+        /**
+         * 璇虹摝璁惧缂栬緫 鏃ュ織璁板綍寮�濮�
+         */
+        List<String> listCode = new ArrayList<>(1);
+        listCode.add(byId.getSn());
+        String content = "{ 璁惧id:" + led.getId() + "璁惧code锛�" + byId.getSn() + "璇虹摝playId:" + led.getPlayerId() + "璇虹摝璁惧鍘熷悕:" + byId.getName() + "璇虹摝璁惧鏇存敼鍚庣殑鍚嶇О:" + led.getName() + "}";
+
+        StoreOperationRecordsUtils.storeOperationData(listCode, null, "璇虹摝璁惧缂栬緫", content);
+        /**
+         * 璇虹摝璁惧缂栬緫 鏃ュ織璁板綍缁撴潫
+         */
         return ledPlayerEntityService.updateById(led);
     }
 
+    /**
+     * 鑾峰彇缂撳瓨鏁版嵁
+     *
+     * @param list
+     * @return
+     */
+    public List<LedPlayerEntity> setCacheInfo(List<LedPlayerEntity> list) {
+        for (LedPlayerEntity playerEntity : list) {
+            String playerId = playerEntity.getPlayerId();
+            LedPlayerInfoEntity cache = new LedPlayerInfoEntity();
+            //  璁剧疆灞忓箷鐘舵��
+            String result = redisUtils.get(VnnoxConstant.REDIS_SCREEN_STATUS + playerId);
+            Integer screenStatus = 1;
+            if (null != result) {
+                screenStatus = Integer.parseInt(result);
+            }
+            cache.setScreenStatus(screenStatus);
+            //  璁剧疆灞忓箷闊抽噺
+            result = redisUtils.get(VnnoxConstant.REDIS_VOL + playerId);
+            Integer vol = 0;
+            if (null != result) {
+                vol = Integer.parseInt(result);
+            }
+            cache.setVol(vol);
+            //  璁剧疆灞忓箷浜害
+            result = redisUtils.get(VnnoxConstant.REDIS_BRIGHTNESS + playerId);
+            Integer brightness = 0;
+            if (null != result) {
+                brightness = Integer.parseInt(result);
+            }
+            cache.setBrightness(brightness);
+
+            //  璁剧疆缂╃暐鍥捐闂矾寰�
+            result = redisUtils.get(VnnoxConstant.REDIS_SCREEN_SHOT + playerId);
+            if (null != result) {
+                playerEntity.setScreenShotUrl(result);
+            } else {
+                playerEntity.setScreenShotUrl("");
+            }
+
+            playerEntity.setPlayerInfo(cache);
+        }
+        return list;
+    }
+
+
+    public VnnoxResult publishWaterData(String playerId, A5AtmosphereHeartbeatReportInnerFrame.HeartBeatDataPackage poleSensorEntity) {
+        List<String> playerIds = new ArrayList<>();
+        playerIds.add(playerId);
+        AirDataProgram playerProgram = new AirDataProgram();
+        playerProgram.setPlayerIds(playerIds);
+        PlayerPage playerPage = new PlayerPage();
+        playerPage.setName("AirData page");
+        List<PlayerWidget> widgetList = generateWaterAndSensorWidget(poleSensorEntity);
+        playerPage.setWidgets(widgetList);
+        List<PlayerPage> list = new ArrayList<>();
+        list.add(playerPage);
+        playerProgram.setPages(list);
+        playerProgram.setNoticeUrl(VnnoxConstant.NOTIFY_URL);
+        /**
+         * 璇虹摝鎺ㄩ�佸ぇ姘旀暟鎹� 鏃ュ織璁板綍寮�濮�
+         ////         */
+//        String content = "{璇虹摝playerId锛�" + playerId + ",鑺傜洰鍐呭锛�" + JSON.toJSONString(playerProgram) + " }";
+//        StoreOperationRecordsUtils.storeOperationData(null, null, "澶ф皵鏁版嵁鎺ㄩ�佸埌璇虹摝", content);
+        /**
+         * 璇虹摝鎺ㄩ�佸ぇ姘旀暟鎹� 鏃ュ織璁板綍缁撴潫
+         */
+
+        return vnnoxProgramAPIUtil.normalProgram(playerProgram).getData();
+    }
+
+
+    private List<PlayerWidget> generateWaterAndSensorWidget(A5AtmosphereHeartbeatReportInnerFrame.HeartBeatDataPackage poleSensorEntity) {
+        //TODO
+        List widgetList = new ArrayList<>();
+        List<String> list = new ArrayList<>();
+        if (Objects.nonNull(poleSensorEntity)) {
+            list.add("鐜鐩戞祴锛�");
+            list.add("娓╁害锛�" + poleSensorEntity.getTemperature() + "掳");
+            list.add("婀垮害锛�" + poleSensorEntity.getHumidity() + "%");
+            list.add("pm25锛�" + poleSensorEntity.getPm25() + "渭g/m鲁");
+            list.add("pm10锛�" + poleSensorEntity.getPm10() + "渭g/m鲁");
+            list.add("鐢查啗锛�" + poleSensorEntity.getEch2o() + "渭g/m鲁");
+            list.add("CO2锛�" + poleSensorEntity.getCo2() + "ppm");
+        }
+
+        widgetList.add(new PlayerWidget().generateScrollUpTextWidget("weather", 1, 100000L, list, "#FFFFFF", 15, new PlayerLayout("0%", "5%", "100%", "100%")));
+
+        return widgetList;
+    }
 
 }

--
Gitblit v1.9.3