From cb502443ec3193181f587bdecc35cfdbc9827175 Mon Sep 17 00:00:00 2001
From: liuhaonan <konodioda2333@vip.qq.com>
Date: 星期二, 19 四月 2022 14:40:48 +0800
Subject: [PATCH] 首页
---
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java | 77 ++++++++++++++++++++++++++++++++++----
1 files changed, 68 insertions(+), 9 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 d966d0f..6469109 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());
}
}
);
@@ -119,6 +117,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) {
@@ -175,4 +190,48 @@
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() {
+ 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