From cd0fa3261b49dbab89bb01dfa94dc3ebdb08dec4 Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期四, 07 七月 2022 16:32:11 +0800
Subject: [PATCH] changes

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java |  124 +++++++++++++++++++++++++++++------------
 1 files changed, 87 insertions(+), 37 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 e23b57f..022c9c3 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
@@ -6,6 +6,7 @@
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.sandu.common.execption.BusinessException;
 import com.sandu.common.service.impl.BaseServiceImpl;
+import com.sandu.common.util.SpringContextHolder;
 import com.sandu.ximon.admin.config.VnnoxConstant;
 import com.sandu.ximon.admin.dto.PlanDto;
 import com.sandu.ximon.admin.dto.SchedulesDTO;
@@ -14,6 +15,7 @@
 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.StoreOperationRecordsUtils;
 import com.sandu.ximon.admin.utils.VnnoxAPIUtil;
 import com.sandu.ximon.admin.utils.VnnoxProgramAPIUtil;
 import com.sandu.ximon.admin.utils.response.VnnoxResultResponse;
@@ -21,6 +23,7 @@
 import com.sandu.ximon.admin.vo.NovaPushResultVO;
 import com.sandu.ximon.admin.vo.PlansVO;
 import com.sandu.ximon.dao.domain.LEDProgram;
+import com.sandu.ximon.dao.domain.LedPlayerEntity;
 import com.sandu.ximon.dao.domain.PlayPlanNv;
 import com.sandu.ximon.dao.domain.PushToLed;
 import com.sandu.ximon.dao.mapper.PlayPlanNvMapper;
@@ -82,7 +85,6 @@
             SchedulesDTO openDto = new SchedulesDTO();
 
 
-
             SchedulesDTO closeDto = new SchedulesDTO();
 
             openDto.setStartDate(schedule.get("startDate").toString());
@@ -93,13 +95,13 @@
             /**
              * 鍒ゆ柇鏃堕棿鐨勫厛鍚�
              */
-            String startTime = openDto.getStartDate()+" " +plans.get(i).getStartTime();
-            String endTime =openDto.getEndDate()+ " " +plans.get(i).getEndTime();
+            String startTime = openDto.getStartDate() + " " + plans.get(i).getStartTime();
+            String endTime = openDto.getEndDate() + " " + plans.get(i).getEndTime();
 
             //杞崲鎴愭椂闂存埑
             long startTimeStamp = DateUtil.parse(startTime, DatePattern.NORM_DATETIME_PATTERN).getTime();
             long endTimeStamp = DateUtil.parse(endTime, DatePattern.NORM_DATETIME_PATTERN).getTime();
-            if(startTimeStamp>endTimeStamp){
+            if (startTimeStamp > endTimeStamp) {
                 throw new BusinessException("寮�濮嬫椂闂翠笉鑳藉ぇ浜庣粨鏉熸椂闂�");
             }
 
@@ -119,8 +121,29 @@
         playPlan.setEndTime(playPlanParam.getEndTime());
         //  BeanUtils.copyProperties(playPlanParam, playPlan);
 
+        /**
+         * 璇虹摝瀹氭椂浠诲姟/鎾斁璁″垝鏂板鏃ュ織璁板綍寮�濮�
+         */
+        boolean save = save(playPlan);
+        String content = "{鎾斁璁″垝锛�" + playPlan.getId()
+                + "锛� 鑺傜洰鍚嶇О锛�" + byId.getName()
+                + "锛� 鎾斁璁″垝璁″垝鍚嶇О锛�"
+                + playPlan.getName()
+                + "锛� 鎾斁璁″垝璁″垝鍐呭锛�"
+                + JSON.toJSONString(playPlan)
+                + "锛� 瀹氭椂浠诲姟鍐呭锛�" + playPlan.getSchedules()
+                + "}," + " 鎺ㄩ�佺粨鏋滐細" + save
+                + " }";
+        if (playPlanParam.getId() == null) {
+            StoreOperationRecordsUtils.storeOperationData(null, null, "璇虹摝瀹氭椂浠诲姟/鎾斁璁″垝鏂板", content);
+        } else {
+            StoreOperationRecordsUtils.storeOperationData(null, null, "璇虹摝瀹氭椂浠诲姟/鎾斁璁″垝淇敼", content);
+        }
+        /**
+         * 璇虹摝瀹氭椂浠诲姟/鎾斁璁″垝鏂板鏃ュ織璁板綍缁撴潫
+         */
 
-        return save(playPlan);
+        return save;
 
     }
 
@@ -130,6 +153,7 @@
             throw new BusinessException("鎿嶄綔瀵硅薄涓嶅瓨鍦�");
         }
         if (removeById(id)) {
+            playPlanParam.setId(id);
             return addPlan(playPlanParam);
         }
 
@@ -148,18 +172,15 @@
     }
 
     public Map<String, Object> pushToLed(Long planId, List<NovaPushResultVO> nova) {
-//    public PlayerProgram pushToLed(Long planId){
         PushToLed pushToLed = playPlanMapper.pushToLed(planId);
-        PlayPlanNv one = getOne(Wrappers.lambdaQuery(PlayPlanNv.class).eq(PlayPlanNv::getId, planId));
+        PlayPlanNv byId = getById(planId);
         if (pushToLed == null) {
             throw new BusinessException("鏈壘鍒拌鎾斁璁″垝");
         }
         List<String> playerIds = new ArrayList<>();
-        nova.forEach(
-                n -> {
-                    playerIds.add(n.getPlayerId());
-                }
-        );
+        nova.forEach(n -> {
+            playerIds.add(n.getPlayerId());
+        });
 
         PlayerProgram program = new PlayerProgram();
         program.setPlayerIds(playerIds);
@@ -173,26 +194,18 @@
         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));
-                }
-        );
+        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);
-        //鑾峰彇瀹氭椂寮�鍏冲睆骞�
-//        program.setSchedules((JSON.parseArray(pushToLed.getSchedule(), SchedulesDTO.class)));
-
-
-        // Map map = JSON.parseObject(pushToLed.getSchedule(), Map.class);
 
         program.setNoticeUrl(VnnoxConstant.NOTIFY_URL);
-//        VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.timeProgram(program);
         VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.normalProgram(program);
-        vnnoxAPIUtil.volChange(playerIds, Integer.valueOf(one.getVolume()).intValue());
+        vnnoxAPIUtil.volChange(playerIds, Integer.valueOf(pushToLed.getVolume()).intValue());
 
         List<String> success = new ArrayList<>();
         List<String> fail = new ArrayList<>();
@@ -207,28 +220,46 @@
         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);
-                    }
-                }
-
-        );
+        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;
-        // return program;
     }
 
 
     //鎺ㄩ�佸畾鏃跺埌LED
     public Map<String, Object> pushSchedule(Long planId, List<NovaPushResultVO> nova) {
         PlayPlanNv one = getOne(Wrappers.lambdaQuery(PlayPlanNv.class).eq(PlayPlanNv::getId, planId));
+        if (one == null) {
+            throw new BusinessException("鏈壘鍒拌妭鐩�");
+        }
         List<SchedulesDTO> schedulesDTOS = JSON.parseArray(one.getSchedules(), SchedulesDTO.class);
         ProgramSchedule programSchedule = new ProgramSchedule();
         programSchedule.setSchedules(schedulesDTOS);
@@ -267,6 +298,25 @@
 
         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锛�" + one.getId()
+                + "锛� 鑺傜洰鍚嶇О锛�" + one.getName()
+                + "}," + " 鎺ㄩ�佺粨鏋滐細" + result
+                + " }";
+        StoreOperationRecordsUtils.storeOperationData(listCode, null, "璇虹摝鎺ㄩ�佸畾鏃跺紑鍏冲睆", content);
+        /**
+         * 璇虹摝鎺ㄩ�佸畾鏃舵棩蹇楄褰曠粨鏉�
+         */
         return result;
     }
 

--
Gitblit v1.9.3