From 42ccfe035ad34b2166cf457d37294ebe614ba241 Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期二, 19 四月 2022 17:55:39 +0800
Subject: [PATCH] 充电桩fix

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java |   67 ++++++++++++++++++++++++++++-----
 1 files changed, 57 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 fa7e706..32cacdf 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,7 @@
 package com.sandu.ximon.admin.service;
 
 import cn.hutool.core.collection.CollectionUtil;
+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;
@@ -30,10 +31,7 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -100,12 +98,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());
                             }
                         }
                 );
@@ -123,6 +121,7 @@
 
     /**
      * 鑾峰彇鍗曚釜璺伅淇℃伅
+     *
      * @param deviceCode 璁惧鐮�
      * @return
      */
@@ -131,7 +130,7 @@
         Object o = redisService.get(LightKey.REPORT_MAC.key(deviceCode));
         if (o != null) {
             one.setOnlineStatus(1);
-        }else {
+        } else {
             one.setOnlineStatus(0);
         }
         return one;
@@ -191,4 +190,52 @@
 
         return resultList;
     }
+
+    /**
+     * 鍗曠伅鑺傝兘鐜�
+     *
+     * @return
+     */
+    public Map controlEnergySaving() {
+        Long clientId = SecurityUtils.getClientId();
+        List<LightBo> listLight = baseMapper.listLight(clientId, null);
+        List<String> deviceCodeList = listLight.stream().map(LightBo::getDeviceCode).collect(Collectors.toList());
+
+        //鑾峰彇鐢ㄦ埛鏈�杩�7澶╃殑鍗曠伅鏁版嵁
+        List<LightReportData> reportDataList = lightReportDataService.list(Wrappers.<LightReportData>lambdaQuery()
+                .in(LightReportData::getDeviceCode, deviceCodeList)
+                .ge(LightReportData::getCreateTime, DateUtil.offsetDay(new Date(), -7))
+                .orderByDesc(LightReportData::getCreateTime));
+
+
+        if (CollectionUtil.isEmpty(reportDataList)) {
+            throw new BusinessException("娌℃湁璺伅鏁版嵁");
+        }
+        Map map = new HashMap();
+        map.put("7", reportDataList);
+
+
+        return map;
+    }
+
+    /**
+     * 鐢ㄦ埛鎷ユ湁鐨勮矾鐏�
+     *
+     * @return
+     */
+    public List<Light> listLight() {
+        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 (LightBo bean : listLight) {
+            Light light = getLight(bean.getDeviceCode());
+            lightList.add(light);
+        }
+        return lightList;
+    }
+
 }

--
Gitblit v1.9.3