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

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java |   71 ++++++++++++++++++++++++++++++++++-
 1 files changed, 69 insertions(+), 2 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..c650ff6 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
@@ -22,6 +22,8 @@
 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;
@@ -46,6 +48,8 @@
 
     private final RedisService redisService;
     private final LightReportDataService lightReportDataService;
+    private final PoleBindingService bindingService;
+    private final PoleService poleService;
 
     /**
      * 褰曞叆褰撳墠璁惧鐮佺殑璺伅鏁版嵁
@@ -83,7 +87,10 @@
      * @return 杩斿洖缁勫悎鏁版嵁dto
      */
     public List<LightBo> listLight(int pageNo, int pageSize, String keyword) {
-        Long clientId = SecurityUtils.getClientId();
+        Long clientId=null;
+        if(SecurityUtils.getClientId()!=null){
+            clientId = SecurityUtils.getClientId();
+        }
 
         PageHelper.startPage(pageNo, pageSize);
 
@@ -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,22 @@
         }
 
         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 +186,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 +194,37 @@
 
         return resultList;
     }
+
+    /**
+     * 鍗曠伅鑺傝兘鐜�
+     */
+    public List<Map<String, Object>> controlEnergySaving() {
+
+        List<LightBo> listLight = baseMapper.listLight(SecurityUtils.getUserId(), null);
+
+
+        return null;
+    }
+
+    /**
+     * 鐢ㄦ埛鎷ユ湁鐨勮矾鐏�
+     */
+    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<Light> lightList = new ArrayList<>();
+        for (String deviceCode : deviceCodeList) {
+            Light light = getLight(deviceCode);
+            lightList.add(light);
+        }
+        return lightList;
+    }
+
 }

--
Gitblit v1.9.3