From 109af646c863e5c6a2ac2fa5eefdffa9fe86d252 Mon Sep 17 00:00:00 2001
From: liuhaonan <konodioda2333@vip.qq.com>
Date: 星期三, 20 四月 2022 14:19:10 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java |  108 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 86 insertions(+), 22 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 c650ff6..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
@@ -8,6 +8,8 @@
 import com.sandu.common.execption.BusinessException;
 import com.sandu.common.redis.RedisService;
 import com.sandu.common.service.impl.BaseServiceImpl;
+import com.sandu.common.util.SpringContextHolder;
+import com.sandu.ximon.admin.dto.LightTaskDto;
 import com.sandu.ximon.admin.manager.iot.frame.A5Frame;
 import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightHeartbeatReportInnerFrame;
 import com.sandu.ximon.admin.manager.iot.frame.inner.request.A5LightBrightnessReqInnerFrame;
@@ -19,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;
@@ -30,6 +33,7 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -87,10 +91,7 @@
      * @return 杩斿洖缁勫悎鏁版嵁dto
      */
     public List<LightBo> listLight(int pageNo, int pageSize, String keyword) {
-        Long clientId=null;
-        if(SecurityUtils.getClientId()!=null){
-            clientId = SecurityUtils.getClientId();
-        }
+        Long clientId = SecurityUtils.getClientId();
 
         PageHelper.startPage(pageNo, pageSize);
 
@@ -103,12 +104,12 @@
             for (LightBo lightBo : listLight) {
                 deviceCodeList.forEach(code -> {
                             PoleBinding bind = bindingService.getPoleIdByMac(code);
-                            if (bind != null&&lightBo.getDeviceCode().equals(bind.getDeviceCode())) {
+                            if (bind != null && lightBo.getDeviceCode().equals(bind.getDeviceCode())) {
                                 Long poleId = bind.getPoleId();
-                                    Pole pole = poleService.getById(poleId);
-                                    lightBo.setPoleId(pole.getId());
-                                    lightBo.setPoleCode(pole.getDeviceCode());
-                                    lightBo.setPoleName(pole.getPoleName());
+                                Pole pole = poleService.getById(poleId);
+                                lightBo.setPoleId(pole.getId());
+                                lightBo.setPoleCode(pole.getDeviceCode());
+                                lightBo.setPoleName(pole.getPoleName());
                             }
                         }
                 );
@@ -126,6 +127,7 @@
 
     /**
      * 鑾峰彇鍗曚釜璺伅淇℃伅
+     *
      * @param deviceCode 璁惧鐮�
      * @return
      */
@@ -134,7 +136,7 @@
         Object o = redisService.get(LightKey.REPORT_MAC.key(deviceCode));
         if (o != null) {
             one.setOnlineStatus(1);
-        }else {
+        } else {
             one.setOnlineStatus(0);
         }
         return one;
@@ -197,31 +199,93 @@
 
     /**
      * 鍗曠伅鑺傝兘鐜�
+     *
+     * @return
      */
-    public List<Map<String, Object>> controlEnergySaving() {
+    public List<LightReportData> controlEnergySaving() {
+        Long clientId = SecurityUtils.getClientId();
+//        List<LightBo> listLight = baseMapper.listLight(clientId, null);
+//        List<String> deviceCodeList = listLight.stream().map(LightBo::getDeviceCode).collect(Collectors.toList());
 
-        List<LightBo> listLight = baseMapper.listLight(SecurityUtils.getUserId(), null);
+        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;
     }
 
     /**
+     * 瑙f瀽寮�鍏崇伅鎸囦护
+     */
+    public ControlLightCommandVO parseSwitchLightCommand(String command) {
+        char[] chars = command.toCharArray();
+        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);
+    }
+
+    /**
      * 鐢ㄦ埛鎷ユ湁鐨勮矾鐏�
+     *
+     * @return
      */
     public List<Light> listLight() {
-        List<LightBo> listLight = baseMapper.listLight(SecurityUtils.getUserId(), null);
-        if (CollectionUtil.isEmpty(listLight)) {
-            throw new BusinessException("娌℃湁璺伅鏁版嵁");
-        }
-        List<String> deviceCodeList = listLight.stream().map(LightBo::getDeviceCode).collect(Collectors.toList());
-        List<LightReportData> reportDataList = lightReportDataService.list(Wrappers.<LightReportData>lambdaQuery().in(LightReportData::getDeviceCode, deviceCodeList));
-        if (CollectionUtil.isEmpty(reportDataList)) {
-            throw new BusinessException("娌℃湁璺伅鏁版嵁");
+        List<LightBo> listLight;
+        if (SecurityUtils.getClientId() != null) {
+            listLight = baseMapper.listLight(SecurityUtils.getUserId(), null);
+        } else {
+            listLight = baseMapper.listLight(null, null);
         }
         List<Light> lightList = new ArrayList<>();
-        for (String deviceCode : deviceCodeList) {
-            Light light = getLight(deviceCode);
+        for (LightBo bean : listLight) {
+            Light light = getLight(bean.getDeviceCode());
             lightList.add(light);
         }
         return lightList;

--
Gitblit v1.9.3