From 681d31e1de290eebd5f5ecb0a0e07a2a66cd01ae Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期四, 04 八月 2022 17:56:17 +0800
Subject: [PATCH] changes

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java |  169 ++++++++++++++------------------------------------------
 1 files changed, 42 insertions(+), 127 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java
index 2c4297d..c400470 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java
@@ -11,9 +11,9 @@
 import com.sandu.ximon.admin.dto.PlanDto;
 import com.sandu.ximon.admin.dto.SchedulesDTO;
 import com.sandu.ximon.admin.dto.nova.*;
-import com.sandu.ximon.admin.entity.Plans;
 import com.sandu.ximon.admin.param.PlayPlanParam;
 import com.sandu.ximon.admin.security.SecurityUtils;
+import com.sandu.ximon.admin.utils.LogUtils;
 import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
 import com.sandu.ximon.admin.utils.VnnoxAPIUtil;
 import com.sandu.ximon.admin.utils.VnnoxProgramAPIUtil;
@@ -24,6 +24,7 @@
 import com.sandu.ximon.dao.domain.*;
 import com.sandu.ximon.dao.mapper.PlayPlanNvMapper;
 import lombok.AllArgsConstructor;
+import org.aspectj.weaver.ast.Var;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
@@ -167,6 +168,7 @@
 
     /**
      * 鎺ㄩ�佸畾鏃惰妭鐩�
+     *
      * @param planId
      * @param nova
      * @return
@@ -194,18 +196,20 @@
         //鑾峰彇鑺傜洰瀹炰綋
 
 
-        List<ProgramDto> programDtos = JSON.parseArray(pushToLed.getPages(), ProgramDto.class);
+        List<PlayerPage> programDtos = JSON.parseArray(pushToLed.getPages(), PlayerPage.class);
         programDtos.forEach(
                 programDto -> {
                     programDto.getWidgets().forEach(
                             widget -> {
-                                String url = widget.getUrl();
-                                LEDProgramFile one = fileService.getOne(Wrappers.lambdaQuery(LEDProgramFile.class).eq(LEDProgramFile::getFileUrl, url));
-                                if (one == null) {
-                                    throw new BusinessException("鑺傜洰鏂囦欢宸插け鏁�");
+                                if (!PlayerWidgetType.WEATHER.equals(widget.getType())) {
+                                    String url = widget.getUrl();
+                                    LEDProgramFile one = fileService.getOne(Wrappers.lambdaQuery(LEDProgramFile.class).eq(LEDProgramFile::getFileUrl, url));
+                                    if (one == null) {
+                                        throw new BusinessException("鑺傜洰鏂囦欢宸插け鏁�");
+                                    }
+                                    widget.setMd5(one.getMd5());
+                                    widget.setSize(Long.parseLong(one.getSize()));
                                 }
-                                widget.setMd5(one.getMd5());
-                                widget.setSize(one.getSize());
                             }
                     );
                 }
@@ -214,20 +218,21 @@
         program.setPages(programDtos);
 
         //鑾峰彇鑺傜洰瀹氭椂瀹炰綋
-        program.setSchedule((JSON.parseObject(pushToLed.getSchedule(), Map.class)));
-        Map map = JSON.parseObject(pushToLed.getSchedule(), Map.class);
-        map.get("plans");
-        List<Plans> plans = JSON.parseArray(map.get("plans").toString(), Plans.class);
-        plans.forEach(p -> {
-            //鍒犻櫎鍚庝袱浣嶅瓧绗︿覆
-            p.setStartTime(p.getStartTime().substring(0, p.getStartTime().length() - 3));
-            p.setEndTime(p.getEndTime().substring(0, p.getEndTime().length() - 3));
-        });
-        System.out.println(plans + "plans11111");
-        map.put("plans", plans);
-        program.setSchedule(map);
+        PlayerSchedule playerSchedule = JSON.parseObject(pushToLed.getSchedule(), PlayerSchedule.class);
+        //鍒犻櫎鏃堕棿鐨勫悗涓変綅
+        List<PlayerSchedulePlans> plans = playerSchedule.getPlans();
+        plans.forEach(
+                plan -> {
+                    plan.setStartTime(plan.getStartTime().substring(0, plan.getStartTime().length() - 3));
+                    plan.setEndTime(plan.getEndTime().substring(0, plan.getEndTime().length() - 3));
+                }
+        );
+        program.setSchedule(playerSchedule);
+
+
 
         program.setNoticeUrl(VnnoxConstant.NOTIFY_URL);
+        LogUtils.error("鑺傜洰鍐呭+++++++++++" + JSON.toJSONString(program));
         VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.normalProgram(program);
         vnnoxAPIUtil.volChange(playerIds, Integer.valueOf(pushToLed.getVolume()).intValue());
 
@@ -428,30 +433,38 @@
             playerIds.add(n.getPlayerId());
         });
 
-        ProgramPush program = new ProgramPush();
-        List<ProgramDto> programDtos = JSON.parseArray(pages, ProgramDto.class);
+        PlayerProgram program = new PlayerProgram();
+        List<PlayerPage> programDtos = JSON.parseArray(pages, PlayerPage.class);
         programDtos.forEach(
                 programDto -> {
                     programDto.getWidgets().forEach(
                             widget -> {
-                                String url = widget.getUrl();
-                                LEDProgramFile one = fileService.getOne(Wrappers.lambdaQuery(LEDProgramFile.class).eq(LEDProgramFile::getFileUrl, url));
-                                if (one == null) {
-                                    throw new BusinessException("鑺傜洰鏂囦欢宸插け鏁�");
+                                if (!PlayerWidgetType.WEATHER.equals(widget.getType())) {
+                                    String url = widget.getUrl();
+                                    LEDProgramFile one = fileService.getOne(Wrappers.lambdaQuery(LEDProgramFile.class).eq(LEDProgramFile::getFileUrl, url));
+                                    if (one == null) {
+                                        throw new BusinessException("鑺傜洰鏂囦欢宸插け鏁�");
+                                    }
+                                    widget.setMd5(one.getMd5());
+                                    widget.setSize(Long.parseLong(one.getSize()));
+                                }else {
+                                    //WratherPage
+                                    System.out.println(widget+"widget");
                                 }
-                                widget.setMd5(one.getMd5());
-                                widget.setSize(one.getSize());
                             }
                     );
                 }
         );
-
         program.setPlayerIds(playerIds);
         //鑾峰彇鑺傜洰瀹炰綋
         program.setPages(programDtos);
 
         program.setNoticeUrl(VnnoxConstant.NOTIFY_URL);
         VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.pushProgram(program);
+
+        if (vnnoxResultResponse == null || vnnoxResultResponse.getData() == null) {
+            throw new BusinessException("鎺ㄩ�佸け璐�");
+        }
 
         List<String> success = new ArrayList<>();
         List<String> fail = new ArrayList<>();
@@ -499,103 +512,5 @@
         return result;
     }
 
-
-
-    /**
-     * 瀹氭椂鎺ㄩ�佸ぉ姘�
-     * @param planId
-     * @param nova
-     * @return
-     */
-    public Map<String, Object> pushWeatherToLed(Long planId, List<NovaPushResultVO> nova) {
-        if (nova == null) {
-            throw new BusinessException("璇烽�夋嫨姝g‘鐨凩ED灞�");
-        }
-        PushToLed pushToLed = playPlanMapper.pushToLed(planId);
-        if (pushToLed.getPages() == null) {
-            throw new BusinessException("鑺傜洰鍐呭涓㈠け");
-        }
-        PlayPlanNv byId = getById(planId);
-        if (pushToLed == null) {
-            throw new BusinessException("鏈壘鍒拌鎾斁璁″垝");
-        }
-        List<String> playerIds = new ArrayList<>();
-        nova.forEach(n -> {
-            playerIds.add(n.getPlayerId());
-        });
-
-        WeatherProgram program = new WeatherProgram();
-        program.setPlayerIds(playerIds);
-
-        //鑾峰彇鑺傜洰瀹炰綋
-
-
-        List<WeatherDto> programDtos = JSON.parseArray(pushToLed.getPages(), WeatherDto.class);
-
-
-        program.setPages(programDtos);
-
-        //鑾峰彇鑺傜洰瀹氭椂瀹炰綋
-        program.setSchedule((JSON.parseObject(pushToLed.getSchedule(), Map.class)));
-        Map map = JSON.parseObject(pushToLed.getSchedule(), Map.class);
-        map.get("plans");
-        List<Plans> plans = JSON.parseArray(map.get("plans").toString(), Plans.class);
-        plans.forEach(p -> {
-            //鍒犻櫎鍚庝袱浣嶅瓧绗︿覆
-            p.setStartTime(p.getStartTime().substring(0, p.getStartTime().length() - 3));
-            p.setEndTime(p.getEndTime().substring(0, p.getEndTime().length() - 3));
-        });
-        map.put("plans", plans);
-        program.setSchedule(map);
-
-        program.setNoticeUrl(VnnoxConstant.NOTIFY_URL);
-        VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.pushWeather(program);
-        vnnoxAPIUtil.volChange(playerIds, Integer.valueOf(pushToLed.getVolume()).intValue());
-
-        List<String> success = new ArrayList<>();
-        List<String> fail = new ArrayList<>();
-        if (vnnoxResultResponse.getData() != null) {
-            success = vnnoxResultResponse.getData().getSuccess();
-            fail = vnnoxResultResponse.getData().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);
-
-        /**
-         * 璇虹摝鎺ㄩ�佽妭鐩棩蹇楄褰曞紑濮�
-         */
-        List<LedPlayerEntity> list = SpringContextHolder.getBean(LedPlayerEntityService.class)
-                .list(Wrappers.lambdaQuery(LedPlayerEntity.class).in(LedPlayerEntity::getId, nova.stream().map(NovaPushResultVO::getPlayerId).toArray()));
-        List<String> listCode = new ArrayList<>();
-        for (LedPlayerEntity temp : list) {
-            listCode.add(temp.getSn());
-        }
-
-        String content = "{鑺傜洰ID锛�" + planId
-                + "锛� 鑺傜洰鍚嶇О锛�" + byId.getName()
-                + "}," + " 鎺ㄩ�佺粨鏋滐細" + result
-                + " }";
-        StoreOperationRecordsUtils.storeOperationData(listCode, null, "璇虹摝鎺ㄩ�佹挱鏀捐鍒�", content);
-        /**
-         * 璇虹摝鎺ㄩ�佽妭鐩棩蹇楄褰曠粨鏉�
-         */
-
-        return result;
-    }
 
 }

--
Gitblit v1.9.3