From e11aff139734ce34e4f7468170ebf0f62ccbb50b Mon Sep 17 00:00:00 2001
From: liuhaonan <konodioda2333@vip.qq.com>
Date: 星期二, 19 四月 2022 16:07:11 +0800
Subject: [PATCH] 首页

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java |   98 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 97 insertions(+), 1 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 65aeaad..4e88284 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,6 +1,8 @@
 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;
@@ -22,12 +24,15 @@
 import com.sandu.ximon.dao.bo.LightBo;
 import com.sandu.ximon.dao.domain.Light;
 import com.sandu.ximon.dao.domain.LightReportData;
+import com.sandu.ximon.dao.domain.Pole;
+import com.sandu.ximon.dao.domain.PoleBinding;
 import com.sandu.ximon.dao.enums.DeviceRespStatusEnums;
 import com.sandu.ximon.dao.mapper.LightMapper;
 import lombok.AllArgsConstructor;
 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;
@@ -46,6 +51,8 @@
 
     private final RedisService redisService;
     private final LightReportDataService lightReportDataService;
+    private final PoleBindingService bindingService;
+    private final PoleService poleService;
 
     /**
      * 褰曞叆褰撳墠璁惧鐮佺殑璺伅鏁版嵁
@@ -94,6 +101,17 @@
         if (CollectionUtil.isNotEmpty(deviceCodeList)) {
             List<LightReportData> reportDataList = lightReportDataService.getNewestReportByDeviceCode(deviceCodeList);
             for (LightBo lightBo : listLight) {
+                deviceCodeList.forEach(code -> {
+                            PoleBinding bind = bindingService.getPoleIdByMac(code);
+                            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());
+                            }
+                        }
+                );
                 for (LightReportData lightReportData : reportDataList) {
                     if (StrUtil.equals(lightBo.getDeviceCode(), lightReportData.getDeviceCode())) {
                         lightBo.setReportTime(lightReportData.getCreateTime());
@@ -104,6 +122,23 @@
         }
 
         return listLight;
+    }
+
+    /**
+     * 鑾峰彇鍗曚釜璺伅淇℃伅
+     *
+     * @param deviceCode 璁惧鐮�
+     * @return
+     */
+    public Light getLight(String deviceCode) {
+        Light one = getOne(Wrappers.<Light>lambdaQuery().eq(Light::getDeviceCode, deviceCode));
+        Object o = redisService.get(LightKey.REPORT_MAC.key(deviceCode));
+        if (o != null) {
+            one.setOnlineStatus(1);
+        } else {
+            one.setOnlineStatus(0);
+        }
+        return one;
     }
 
     public boolean addRemark(LightRemarkParam param) {
@@ -152,7 +187,7 @@
                     light.setLightPercent(param.getBrightness());
                     update(light, Wrappers.lambdaUpdate(Light.class).eq(Light::getDeviceCode, param.getDeviceCode()));
                 }
-            }catch (BusinessException e){
+            } catch (BusinessException e) {
                 map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                 resultList.add(map);
             }
@@ -160,4 +195,65 @@
 
         return resultList;
     }
+
+    /**
+     * 鍗曠伅鑺傝兘鐜�
+     *
+     * @return
+     */
+    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<String> deviceCodeList = new ArrayList<>();
+        deviceCodeList.add("32313243305005ffa633ffff");
+//        DateTime startDate = DateUtil.date();
+//        DateTime endDate = DateUtil.offsetDay(startDate, 3);
+//        if (CollectionUtil.isNotEmpty(deviceCodeList)) {
+//
+//            List<LightReportDataBo> reportDataList = lightReportDataService.reportDataList(deviceCodeList, startDate,  endDate);
+//        }
+
+        //鑾峰彇鐢ㄦ埛鏈�杩�7澶╃殑鍗曠伅鏁版嵁
+        List<LightReportData> reportDataList = lightReportDataService.list(Wrappers.<LightReportData>lambdaQuery()
+                .in(LightReportData::getDeviceCode, deviceCodeList)
+                .ge(LightReportData::getCreateTime, DateUtil.offsetDay(DateUtil.yesterday(), -7))
+                .orderByDesc(LightReportData::getCreateTime));
+
+
+        LocalDateTime dateTime = LocalDateTime.now();
+        dateTime.plusDays(7L);
+        reportDataList.forEach(
+                reportData -> {
+                    LocalDateTime createTime = reportData.getCreateTime();
+                    if(dateTime.plusDays(-1L).getDayOfMonth()==createTime.getDayOfMonth()){
+
+                    }
+                }
+        );
+
+
+        Map map = new HashMap();
+        map.put("-1", null);
+
+
+        return reportDataList;
+    }
+
+    /**
+     * 鐢ㄦ埛鎷ユ湁鐨勮矾鐏�
+     *
+     * @return
+     */
+    public List<Light> listLight() {
+        Long clientId = SecurityUtils.getClientId();
+        List<LightBo> listLight = baseMapper.listLight(clientId, null);
+        List<Light> lightList = new ArrayList<>();
+        for (LightBo bean : listLight) {
+            Light light = getLight(bean.getDeviceCode());
+            lightList.add(light);
+        }
+        return lightList;
+    }
+
 }

--
Gitblit v1.9.3