From 22c064d0eb1964263f24f09c30931ff93d60f23a Mon Sep 17 00:00:00 2001
From: liuhaonan <konodioda2333@vip.qq.com>
Date: 星期三, 20 四月 2022 14:18:46 +0800
Subject: [PATCH] 首页

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java |   58 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java
index 4903e14..4be81cb 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java
@@ -1,8 +1,6 @@
 package com.sandu.ximon.admin.service;
 
 import cn.hutool.core.collection.CollectionUtil;
-import cn.hutool.core.date.DateTime;
-import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.HexUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -23,6 +21,7 @@
 import com.sandu.ximon.admin.param.LightRemarkParam;
 import com.sandu.ximon.admin.redis.LightKey;
 import com.sandu.ximon.admin.security.SecurityUtils;
+import com.sandu.ximon.admin.vo.ControlLightCommandVO;
 import com.sandu.ximon.dao.bo.LightBo;
 import com.sandu.ximon.dao.domain.Light;
 import com.sandu.ximon.dao.domain.LightReportData;
@@ -209,12 +208,16 @@
 //        List<String> deviceCodeList = listLight.stream().map(LightBo::getDeviceCode).collect(Collectors.toList());
 
         List<LightTaskDto> lightTaskDtos = SpringContextHolder.getBean(LightTaskService.class).listLightTask(null, null);
+        LocalDateTime now = LocalDateTime.now();
         lightTaskDtos.forEach(Task -> {
+            ControlLightCommandVO startTime = parseSwitchLightCommand(Task.getOpenOrder());
+            if(Task.getControlOrder()!=null){
+                List<ControlLightCommandVO> controlLightCommandVOS = parseControlLightCommand(Task.getControlOrder());
+            }
+            ControlLightCommandVO endTime = parseSwitchLightCommand(Task.getCloseOrder());
 
 
-                });
-
-
+        });
 
 
         return null;
@@ -223,14 +226,49 @@
     /**
      * 瑙f瀽寮�鍏崇伅鎸囦护
      */
-    public void parseSwitchLightCommand(String command) {
+    public ControlLightCommandVO parseSwitchLightCommand(String command) {
         char[] chars = command.toCharArray();
-        if(chars.length==7){
-            int hour = Integer.valueOf(command.substring(0,2));
-            int min = Integer.valueOf(command.substring(2,4));
-            int brightness = Integer.valueOf(command.substring(4,7));
+        ControlLightCommandVO vo = new ControlLightCommandVO();
+        if (chars.length == 7) {
+            int hour = Integer.valueOf(command.substring(0, 2));
+            int min = Integer.valueOf(command.substring(2, 4));
+            int brightness = Integer.valueOf(command.substring(4, 7));
+            vo.setHour(hour);
+            vo.setMin(min);
+            vo.setBrightness(brightness);
         }
+        return vo;
+    }
 
+    /**
+     * 瑙f瀽鎺х伅鎸囦护
+     */
+    public List<ControlLightCommandVO> parseControlLightCommand(String command) {
+        char[] chars = command.toCharArray();
+        int i = chars.length / 7;
+
+        List<ControlLightCommandVO> list = new ArrayList<>();
+
+        for (int j = 0; j < i; j++) {
+            int hour = Integer.valueOf(command.substring(0 + (j * 7), 2 + (j * 7)));
+            int min = Integer.valueOf(command.substring(2 + (j * 7), 4 + (j * 7)));
+            int brightness = Integer.valueOf(command.substring(4 + (j * 7), 7 + (j * 7)));
+            ControlLightCommandVO vo = new ControlLightCommandVO();
+            vo.setHour(hour);
+            vo.setMin(min);
+            vo.setBrightness(brightness);
+            list.add(vo);
+        }
+        return list;
+    }
+
+    //璁$畻鑺傝兘鐜�
+    public void calculateEnergySaving(ControlLightCommandVO v1,ControlLightCommandVO v2){
+      int hour = v2.getHour()- v1.getHour();
+      int min = (v2.getMin()- v1.getMin());
+      int brightness = v2.getBrightness()- v1.getBrightness();
+      int totalTime=(hour*60+min)*60;
+      Double energySaving = (1-(v1.getBrightness()/100.0))*totalTime/(36*24);
     }
 
     /**

--
Gitblit v1.9.3