From 6b8209671b4ee8296c01f9f6a70b3f9444a48e71 Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Tue, 28 Sep 2021 17:00:20 +0800
Subject: [PATCH] 修改bug

---
 screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
index 23efdd1..1c1b45b 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
@@ -1,5 +1,6 @@
 package com.moral.api.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.moral.api.entity.Device;
 import com.moral.api.entity.Sensor;
@@ -13,6 +14,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
+import org.springframework.util.ObjectUtils;
 
 import java.util.ArrayList;
 
@@ -84,7 +86,6 @@
         queryWrapper.select("mac", "name").in("mac", macs);
         List<Device> devices = deviceMapper.selectList(queryWrapper);
 
-
         //������������
         List<String> times = (List<String>) params.remove("times");
         //������code
@@ -98,7 +99,8 @@
         for (String start : times) {
             if ("hour".equals(type)) {
                 end = DateUtils.getDateAddDay(start, 1);
-                timeUnits = "hourly";
+                String yearAndMonth = DateUtils.dateToDateString(DateUtils.getDate(start, DateUtils.yyyy_MM_dd_EN), DateUtils.yyyyMM_EN);
+                timeUnits = "hourly_" + yearAndMonth;
                 dateFormat = "%Y-%m-%d %H";
             } else if ("day".equals(type)) {
                 end = DateUtils.getDateAddMonth(start, 1);
@@ -142,5 +144,30 @@
         return result;
     }
 
+    @Override
+    public Device getDeviceByMac(String mac) {
+        Map<String, Object> deviceMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DEVICE, mac);
+        Device device = JSON.parseObject(JSON.toJSONString(deviceMap), Device.class);
+        //���map������organizationId���monitorPointId������versionId
+        Map<String, Object> organizationMap = (Map<String, Object>) deviceMap.get("organization");
+        Map<String, Object> monitorPointMap = (Map<String, Object>) deviceMap.get("monitorPoint");
+        Map<String, Object> versionMap = (Map<String, Object>) deviceMap.get("version");
+        device.setDeviceVersionId((Integer) versionMap.get("id"));
+        device.setOrganizationId((Integer) organizationMap.get("id"));
+        device.setMonitorPointId((Integer) monitorPointMap.get("id"));
+        //������������������������������������
+        if (ObjectUtils.isEmpty(device)) {
+            return getDeviceByMacFromDB(mac);
+        }
+        return device;
+    }
+
+    private Device getDeviceByMacFromDB(String mac) {
+        QueryWrapper<Device> wrapper = new QueryWrapper<>();
+        wrapper.eq("mac", mac);
+        wrapper.eq("is_delete", Constants.NOT_DELETE);
+        return deviceMapper.selectOne(wrapper);
+    }
+
 
 }

--
Gitblit v1.8.0