From e55c8b0a92eb9715edd90c31dfd4de51a47b588b Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 04 十一月 2022 17:40:08 +0800
Subject: [PATCH] changes

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/utils/VnnoxAPIUtil.java |  214 ++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 155 insertions(+), 59 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/utils/VnnoxAPIUtil.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/utils/VnnoxAPIUtil.java
index 70034c0..d966cd4 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/utils/VnnoxAPIUtil.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/utils/VnnoxAPIUtil.java
@@ -12,10 +12,13 @@
 import org.springframework.stereotype.Component;
 
 import java.net.URISyntaxException;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 @Component("VnnoxAPIUtil")
 @AllArgsConstructor
@@ -24,6 +27,8 @@
     //@Autowired
     private RedisUtils redisUtils;
 
+    private CountDownLatchUtil countDownLatchUtil;
+
     public static VnnoxAPIUtil getBean() {
         return (VnnoxAPIUtil) SpringContextUtil.getBean("VnnoxAPIUtil");
     }
@@ -31,39 +36,32 @@
     /**
      * 鑾峰彇token
      */
-    public void getToken () {
-        String result = VnnoxRequestUtil.PostWithHeader(
-                VnnoxUrl.getUrl(VnnoxUrl.GET_TOKEN),
-                new VnnoxGetTokenRequest().toJson(),
-                new CommonHeader(CommonHeader.FORM, false)
-        );
+    public void getToken() {
+        String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.GET_TOKEN), new VnnoxGetTokenRequest().toJson(), new CommonHeader(CommonHeader.FORM, false));
 
-        CommonResponse commonResponse = JSON.parseObject(result,CommonResponse.class);
+        CommonResponse commonResponse = JSON.parseObject(result, CommonResponse.class);
         VnnoxGetTokenResponse response = new VnnoxGetTokenResponse().parse(commonResponse);
         //  灏唗oken淇濆瓨鍒皉edis缂撳瓨涓�
-        redisUtils.set(VnnoxConstant.REDIS_TOKEN_NAME,response.getToken(),(long)(response.getExpire()-30));
+        redisUtils.set(VnnoxConstant.REDIS_TOKEN_NAME, response.getToken(), (long) (response.getExpire() - 30));
     }
 
 
     /**
      * 鑾峰彇鎾斁鍣ㄥ垪琛�
+     *
      * @param count 姣忔璇诲彇鏁伴噺锛岄粯璁�20锛屽彇鍊艰寖鍥达細1~100
      * @param start 浠庣鍑犳潯璁板綍寮�濮嬭鍙栵紝榛樿0
      * @return
      */
-    public VnnoxPlayerListResponse getPlayerList(Integer count, Integer start,String name) throws URISyntaxException {
+    public VnnoxPlayerListResponse getPlayerList(Integer count, Integer start, String name) throws URISyntaxException {
 
         List<NameValuePair> urlParameters = new ArrayList<>();
-        urlParameters.add(new BasicNameValuePair("count",count.toString()));
-        urlParameters.add(new BasicNameValuePair("start",start.toString()));
-        urlParameters.add(new BasicNameValuePair("name",name));
+        urlParameters.add(new BasicNameValuePair("count", count.toString()));
+        urlParameters.add(new BasicNameValuePair("start", start.toString()));
+        urlParameters.add(new BasicNameValuePair("name", name));
 
-        String result = VnnoxRequestUtil.GetWithHeader(
-                VnnoxUrl.getUrl(VnnoxUrl.GET_PLAYER_LIST),
-                urlParameters,
-                new CommonHeader(CommonHeader.JSON, true)
-        );
-        return new VnnoxPlayerListResponse().parse(JSON.parseObject(result,CommonResponse.class));
+        String result = VnnoxRequestUtil.GetWithHeader(VnnoxUrl.getUrl(VnnoxUrl.GET_PLAYER_LIST), urlParameters, new CommonHeader(CommonHeader.JSON, true));
+        return new VnnoxPlayerListResponse().parse(JSON.parseObject(result, CommonResponse.class));
     }
 
     /**
@@ -74,6 +72,9 @@
      */
     public List<LedPlayerEntity> syncCurrentInfo(List<LedPlayerEntity> list) {
         List<String> playerIds = new ArrayList<>();
+        if (list.isEmpty()) {
+            return list;
+        }
 
         for (LedPlayerEntity playerEntity : list) {
             playerIds.add(playerEntity.getPlayerId());
@@ -82,11 +83,7 @@
         VnnoxSyncCurrentInfoRequest vnnoxSyncCurrentInfoRequest = new VnnoxSyncCurrentInfoRequest();
         vnnoxSyncCurrentInfoRequest.setPlayerIds(playerIds);
 
-        String result = VnnoxRequestUtil.PostWithHeader(
-                VnnoxUrl.getUrl(VnnoxUrl.SYNC_CURRENT_INFO),
-                vnnoxSyncCurrentInfoRequest.toJson(),
-                new CommonHeader(CommonHeader.JSON, true)
-        );
+        String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.SYNC_CURRENT_INFO), vnnoxSyncCurrentInfoRequest.toJson(), new CommonHeader(CommonHeader.JSON, true));
 
         VnnoxSyncCurrentInfoResponse response = JSON.parseObject(result, VnnoxSyncCurrentInfoResponse.class);
 
@@ -120,11 +117,7 @@
         vnnoxScreenStatusRequest.setPlayerIds(playerIds);
         vnnoxScreenStatusRequest.setStatus(type);
 
-        String result = VnnoxRequestUtil.PostWithHeader(
-                VnnoxUrl.getUrl(VnnoxUrl.SCREEN_STATUS),
-                vnnoxScreenStatusRequest.toJson(),
-                new CommonHeader(CommonHeader.JSON, true)
-        );
+        String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.SCREEN_STATUS), vnnoxScreenStatusRequest.toJson(), new CommonHeader(CommonHeader.JSON, true));
 
         VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
 
@@ -145,11 +138,7 @@
         request.setPlayerIds(playerIds);
         request.setValue(vol);
 
-        String result = VnnoxRequestUtil.PostWithHeader(
-                VnnoxUrl.getUrl(VnnoxUrl.CHANGE_VOL),
-                request.toJson(),
-                new CommonHeader(CommonHeader.JSON, true)
-        );
+        String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.CHANGE_VOL), request.toJson(), new CommonHeader(CommonHeader.JSON, true));
         VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
 
         return response.getData();
@@ -168,11 +157,7 @@
         request.setPlayerIds(playerIds);
         request.setValue(brightness);
 
-        String result = VnnoxRequestUtil.PostWithHeader(
-                VnnoxUrl.getUrl(VnnoxUrl.CHANGE_BRIGHTNESS),
-                request.toJson(),
-                new CommonHeader(CommonHeader.JSON, true)
-        );
+        String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.CHANGE_BRIGHTNESS), request.toJson(), new CommonHeader(CommonHeader.JSON, true));
         VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
 
         return response.getData();
@@ -191,14 +176,42 @@
         request.setPlayerIds(players);
         request.setNoticeUrl(VnnoxConstant.SCREEN_SHOT_NOTIFY_URL);
 
-        String result = VnnoxRequestUtil.PostWithHeader(
-                VnnoxUrl.getUrl(VnnoxUrl.SCREEN_SHOT),
-                request.toJson(),
-                new CommonHeader(CommonHeader.JSON, true)
-        );
+        String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.SCREEN_SHOT), request.toJson(), new CommonHeader(CommonHeader.JSON, true));
         VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
 
         return response.getData();
+    }
+
+
+    /**
+     * 鎵归噺灞忓箷鎴浘
+     *
+     * @param players
+     * @return
+     */
+    public VnnoxResult screenShot(List<String> players) {
+        VnnoxBaseRequest request = new VnnoxBaseRequest();
+        request.setPlayerIds(players);
+        request.setNoticeUrl(VnnoxConstant.SCREEN_SHOT_NOTIFY_URL);
+
+        String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.SCREEN_SHOT), request.toJson(), new CommonHeader(CommonHeader.JSON, true));
+
+        if (result.startsWith("{") && result.endsWith("}")) {
+            VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
+            if (response.getStatus() == 0) {
+                return response.getData();
+            } else {
+                System.out.println(response.getErrmsg());
+                VnnoxResult vnnoxResult = new VnnoxResult();
+                vnnoxResult.getFail().addAll(players);
+                return vnnoxResult;
+            }
+        } else {
+            System.out.println("鏁版嵁瑙f瀽寮傚父!");
+            VnnoxResult vnnoxResult = new VnnoxResult();
+            vnnoxResult.getFail().addAll(players);
+            return vnnoxResult;
+        }
     }
 
     /**
@@ -212,11 +225,7 @@
         request.setPlayerIds(playerIdList);
         request.setNoticeUrl(VnnoxConstant.SCREEN_SHOT_NOTIFY_URL);
 
-        String result = VnnoxRequestUtil.PostWithHeader(
-                VnnoxUrl.getUrl(VnnoxUrl.REBOOT),
-                request.toJson(),
-                new CommonHeader(CommonHeader.JSON, true)
-        );
+        String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.REBOOT), request.toJson(), new CommonHeader(CommonHeader.JSON, true));
         VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
 
         return response.getData();
@@ -224,7 +233,6 @@
 
     /**
      * 鍚屾鎾斁
-     *
      */
     public VnnoxResult syncPlay(List<String> playerId, Integer option) {
         VnnoxBaseRequest request = new VnnoxBaseRequest();
@@ -232,11 +240,7 @@
         request.setOption(option);
         request.setNoticeUrl(VnnoxConstant.SCREEN_SHOT_NOTIFY_URL);
 
-        String result = VnnoxRequestUtil.PostWithHeader(
-                VnnoxUrl.getUrl(VnnoxUrl.SIMU_LCAST),
-                request.toJson(),
-                new CommonHeader(CommonHeader.JSON, true)
-        );
+        String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.SIMU_LCAST), request.toJson(), new CommonHeader(CommonHeader.JSON, true));
         VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
 
         return response.getData();
@@ -257,14 +261,106 @@
         map.put("noticeUrl", VnnoxConstant.SCREEN_SHOT_NOTIFY_URL);
         map.put("playerIds", playerId);
         String s = JSON.toJSONString(map);
-        String result = VnnoxRequestUtil.PostWithHeader(
-                VnnoxUrl.getUrl(VnnoxUrl.NTP_SYNC),
-                s,
-                new CommonHeader(CommonHeader.JSON, true)
-        );
+        String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.NTP_SYNC), s, new CommonHeader(CommonHeader.JSON, true));
         VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
 
         return response.getData();
     }
 
+
+    public List<LedPlayerEntity> saveCurrentInfo(List<LedPlayerEntity> list) {
+        List<String> playerIds = new ArrayList<>();
+        if (list.isEmpty()) {
+            return null;
+        }
+
+        for (LedPlayerEntity playerEntity : list) {
+            playerIds.add(playerEntity.getPlayerId());
+        }
+
+        VnnoxSyncCurrentInfoRequest vnnoxSyncCurrentInfoRequest = new VnnoxSyncCurrentInfoRequest();
+        vnnoxSyncCurrentInfoRequest.setPlayerIds(playerIds);
+
+        String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.SYNC_CURRENT_INFO), vnnoxSyncCurrentInfoRequest.toJson(), new CommonHeader(CommonHeader.JSON, true));
+
+        VnnoxSyncCurrentInfoResponse response = JSON.parseObject(result, VnnoxSyncCurrentInfoResponse.class);
+
+        for (LedPlayerEntity playerEntity : list) {
+            for (VnnoxPlayerInfoResponse res : response.getData()) {
+                if (res.getPlayerId().equals(playerEntity.getPlayerId())) {
+                    playerEntity.setResolution(res.getWidth() + " * " + res.getHeight());
+                    break;
+                }
+            }
+        }
+        return list;
+    }
+
+
+    /**
+     * 鑾峰彇闊抽噺,浜害
+     */
+    public VnnoxResultResponse asyncStatus(List<String> playerId) {
+        List<String> commands = new ArrayList<>();
+        commands.add("volumeValue");
+        commands.add("brightnessValue");
+        commands.add("screenPowerStatus");
+        VnnoxBaseRequest request = new VnnoxBaseRequest();
+        request.setPlayerIds(playerId);
+        request.setCommands(commands);
+        request.setNoticeUrl(VnnoxConstant.STATUS_NOTIFY_URL);
+        System.out.println(LocalDateTime.now() + "璇锋眰鍓�");
+        String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.ASYNCURRENTSTATUS), request.toJson(), new CommonHeader(CommonHeader.JSON, true));
+        VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
+        System.out.println(LocalDateTime.now() + "璇锋眰鍚�");
+        System.out.println(response.toString());
+        int size = response.getData().getSuccess().size();
+        CountDownLatch countDownLatch = new CountDownLatch(size * 2);
+        countDownLatchUtil.push(response.getLogid(), countDownLatch);
+        try {
+            countDownLatch.await(3000, TimeUnit.MILLISECONDS);
+            countDownLatchUtil.remove(response.getLogid());
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+        System.out.println(LocalDateTime.now() + "杩斿洖鍓�");
+        return response;
+    }
+
+    /**
+     * 鑾峰彇灞忓箷淇℃伅
+     */
+    public VnnoxResultResponse getAsyncStatus(List<String> playerId, String statusValue) {
+        List<String> commands = new ArrayList<>();
+        if ("all".equals(statusValue)) {
+            commands.add("volumeValue");
+            commands.add("brightnessValue");
+            commands.add("videoSourceValue");
+            commands.add("timeValue");
+            commands.add("screenPowerStatus");
+            commands.add("syncPlayStatus");
+        } else {
+            commands.add(statusValue);
+        }
+        VnnoxBaseRequest request = new VnnoxBaseRequest();
+        request.setPlayerIds(playerId);
+        request.setCommands(commands);
+        request.setNoticeUrl(VnnoxConstant.STATUS_NOTIFY_URL);
+        System.out.println(LocalDateTime.now() + "璇锋眰鍓�");
+        String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.ASYNCURRENTSTATUS), request.toJson(), new CommonHeader(CommonHeader.JSON, true));
+        VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
+        System.out.println(LocalDateTime.now() + "璇锋眰鍚�");
+        System.out.println(response.toString());
+        int size = response.getData().getSuccess().size();
+        CountDownLatch countDownLatch = new CountDownLatch(size * commands.size());
+        countDownLatchUtil.push(response.getLogid(), countDownLatch);
+        try {
+            countDownLatch.await(10000, TimeUnit.MILLISECONDS);
+            countDownLatchUtil.remove(response.getLogid());
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+        System.out.println(LocalDateTime.now() + "杩斿洖鍓�");
+        return response;
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3