From 55621908416cd328d013d2e23d0d7c2dcfb1f9b1 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Tue, 28 Dec 2021 13:16:11 +0800
Subject: [PATCH] 行业贡献率

---
 screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java  |  213 ++++++------
 screen-api/src/main/java/com/moral/api/service/HistoryMonthlyService.java          |    7 
 screen-api/src/main/java/com/moral/api/service/HistoryDailyService.java            |    7 
 screen-api/src/main/java/com/moral/api/service/impl/ProfessionServiceImpl.java     |  519 +++++++++++++++++++++-----------
 screen-api/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java   |  119 ++++---
 screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java             |    3 
 screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java           |   11 
 screen-api/src/main/java/com/moral/api/service/impl/HistoryMonthlyServiceImpl.java |    9 
 screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml                       |   20 -
 9 files changed, 540 insertions(+), 368 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java b/screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java
index 17ca271..71102bf 100644
--- a/screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java
+++ b/screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java
@@ -21,7 +21,4 @@
 
     List<Map<String,Object>> selectDataByMacsAndTime(@Param("timeUnits") String timeUnits, @Param("list")List list, @Param("time")String time);
 
-    Double getSensorSumByMacs(@Param("sensorCode") String sensorCode, @Param("macs") List<String> macs, @Param("time") String time, @Param("timeUnits") String timeUnits);
-
-    Double getSensorAvgByMacs(@Param("sensorCode") String sensorCode, @Param("macs") List<String> macs, @Param("time") String time, @Param("timeUnits") String timeUnits);
 }
diff --git a/screen-api/src/main/java/com/moral/api/service/HistoryDailyService.java b/screen-api/src/main/java/com/moral/api/service/HistoryDailyService.java
index 3fc008a..ad3d9e9 100644
--- a/screen-api/src/main/java/com/moral/api/service/HistoryDailyService.java
+++ b/screen-api/src/main/java/com/moral/api/service/HistoryDailyService.java
@@ -65,4 +65,11 @@
      **/
     List<Map<String, Object>> getThermodynamicDiagramDataByOrgIdSensorCodeTimeSlot(Map<String, Object> map);
 
+    /**
+     * @description: ������������������������������������
+     * @param macs List<String>
+     * @param time String ������2021-12
+     * */
+    List<HistoryDaily> getValueByMacs(List<String> macs, String time);
+
 }
diff --git a/screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java b/screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java
index 5e7f78a..79473a3 100644
--- a/screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java
+++ b/screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java
@@ -64,10 +64,11 @@
      */
     List<HistoryHourly> getValueByMacAndTime(String mac, Date startDate, Date endDate);
 
-    //���������������������������������������������������
-    Double getSensorSumByMacs(String sensorCode, List macs, String time);
-
-    //���������������������������������������������������
-    Double getSensorAvgByMacs(String sensorCode, List macs, String time);
+    /**
+     * @description: ���������������������������������������
+     * @param macs List<String>
+     * @param time String ������2021-12-23
+     * */
+    List<HistoryHourly> getValueByMacs(List<String> macs, String time);
 
 }
diff --git a/screen-api/src/main/java/com/moral/api/service/HistoryMonthlyService.java b/screen-api/src/main/java/com/moral/api/service/HistoryMonthlyService.java
index 44d574e..dba3ab6 100644
--- a/screen-api/src/main/java/com/moral/api/service/HistoryMonthlyService.java
+++ b/screen-api/src/main/java/com/moral/api/service/HistoryMonthlyService.java
@@ -52,4 +52,11 @@
      *@Date: 2021/12/16 15:16
      **/
     List<Map<String, Object>> getThermodynamicDiagramDataByOrgIdSensorCodeTimeSlot(Map<String, Object> map);
+
+    /**
+     * @description: ������������������������������������
+     * @param macs List<String>
+     * @param time String ������2021
+     * */
+    List<HistoryMonthly> getValueByMacs(List<String> macs, String time);
 }
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java
index b23ca13..d6fe2f6 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java
@@ -14,8 +14,8 @@
 import com.moral.api.utils.GetCenterPointFromListOfCoordinates;
 import com.moral.constant.Constants;
 import com.moral.util.DateUtils;
-
 import com.moral.util.PollutantUtils;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
@@ -62,10 +62,10 @@
     @Override
     public HistoryDaily getHistoryDailyByMacAndDate(String mac, Date date) {
         QueryWrapper<HistoryDaily> wrapper = new QueryWrapper<>();
-        wrapper.eq("mac",mac);
-        wrapper.eq("time",date);
+        wrapper.eq("mac", mac);
+        wrapper.eq("time", date);
         List<HistoryDaily> historyDailies = historyDailyMapper.selectList(wrapper);
-        if(ObjectUtils.isEmpty(historyDailies))
+        if (ObjectUtils.isEmpty(historyDailies))
             return null;
         return historyDailies.get(0);
     }
@@ -74,12 +74,12 @@
     @Override
     public Map<String, HistoryDaily> getHistoryDailyByMacsAndDate(List<String> mac, Date date) {
         QueryWrapper<HistoryDaily> wrapper = new QueryWrapper<>();
-        wrapper.in("mac",mac);
-        wrapper.eq("time",date);
+        wrapper.in("mac", mac);
+        wrapper.eq("time", date);
         List<HistoryDaily> historyDailies = historyDailyMapper.selectList(wrapper);
-        Map<String,HistoryDaily> map = new HashMap<>();
+        Map<String, HistoryDaily> map = new HashMap<>();
         for (HistoryDaily historyDaily : historyDailies) {
-            map.put(historyDaily.getMac(),historyDaily);
+            map.put(historyDaily.getMac(), historyDaily);
         }
         return map;
     }
@@ -87,8 +87,8 @@
     @Override
     public List<HistoryDaily> getHistoryDailyByMacAndTimeSlot(String mac, Date startDate, Date endDate) {
         QueryWrapper<HistoryDaily> wrapper = new QueryWrapper<>();
-        wrapper.in("mac",mac);
-        wrapper.between("time",startDate,endDate);
+        wrapper.in("mac", mac);
+        wrapper.between("time", startDate, endDate);
         List<HistoryDaily> historyDailies = historyDailyMapper.selectList(wrapper);
         return historyDailies;
     }
@@ -103,8 +103,8 @@
         //������������
         //���������������
         List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
-        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
-            for (Organization organization:allChildrenOrganization) {
+        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1) {
+            for (Organization organization : allChildrenOrganization) {
                 allOrgId.add(organization.getId());
             }
         }
@@ -113,38 +113,38 @@
         //������������list���������������mac
         List<String> deviceMacList = new ArrayList<>();
         //������������map���Mac������key���device������value
-        Map<String,Device> deviceMap = new HashMap<>();
+        Map<String, Device> deviceMap = new HashMap<>();
         List<Double> longitudeList = new ArrayList<>();
         List<Double> latitudeList = new ArrayList<>();
-        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
+        for (Integer orgIdWithoutDuplicates : allOrgIdWithoutDuplicates) {
             //������id������������������
             QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
-            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
+            wrapper_device.eq("is_delete", Constants.NOT_DELETE).eq("organization_id", orgIdWithoutDuplicates);
             List<Device> devices = new ArrayList<>();
             devices = deviceMapper.selectList(wrapper_device);
-            if (devices.size()>0){
-                for (Device device:devices) {
+            if (devices.size() > 0) {
+                for (Device device : devices) {
                     String mac = device.getMac();
                     deviceMacList.add(mac);
-                    deviceMap.put(mac,device);
+                    deviceMap.put(mac, device);
                     double longitude = device.getLongitude();
                     double latitude = device.getLatitude();
                     longitudeList.add(longitude);
                     latitudeList.add(latitude);
                 }
-            }else {
+            } else {
                 continue;
             }
         }
         //������������
-        String time = parameters.get("time").toString().substring(0,10)+" 00:00:00";
-        resultMap.put("time",time);
+        String time = parameters.get("time").toString().substring(0, 10) + " 00:00:00";
+        resultMap.put("time", time);
         QueryWrapper<HistoryDaily> historyDailyQueryWrapper = new QueryWrapper<>();
-        historyDailyQueryWrapper.eq("time",time);
+        historyDailyQueryWrapper.eq("time", time);
         historyDailyQueryWrapper.in("mac", deviceMacList);
         List<HistoryDaily> historyDailies = historyDailyMapper.selectList(historyDailyQueryWrapper);
         List<Object> list = new ArrayList<>();
-        for (HistoryDaily historyDailyData:historyDailies) {
+        for (HistoryDaily historyDailyData : historyDailies) {
             List<Object> list1 = new ArrayList<>();
             String mac = historyDailyData.getMac();
             Device device = deviceMap.get(mac);
@@ -158,17 +158,17 @@
             list1.add(level);
             list.add(list1);
         }
-        resultMap.put("list",list);
-        double latitudeMin = Collections.min(latitudeList)-0.0018;
-        double latitudeMax = Collections.max(latitudeList)+0.0018;
-        double longitudeMin = Collections.min(longitudeList)-0.2/(111*Math.cos(latitudeMin));
-        double longitudeMax = Collections.max(longitudeList)+0.2/(111*Math.cos(latitudeMin));
+        resultMap.put("list", list);
+        double latitudeMin = Collections.min(latitudeList) - 0.0018;
+        double latitudeMax = Collections.max(latitudeList) + 0.0018;
+        double longitudeMin = Collections.min(longitudeList) - 0.2 / (111 * Math.cos(latitudeMin));
+        double longitudeMax = Collections.max(longitudeList) + 0.2 / (111 * Math.cos(latitudeMin));
         List<Double> bound = new ArrayList<>();
         bound.add(longitudeMin);
         bound.add(latitudeMin);
         bound.add(longitudeMax);
         bound.add(latitudeMax);
-        resultMap.put("bound",bound);
+        resultMap.put("bound", bound);
         List<List> bound1 = new ArrayList<>();
         List<Double> left_up = new ArrayList<>();
         left_up.add(latitudeMax);
@@ -187,7 +187,7 @@
         bound1.add(right_down);
         bound1.add(left_down);
         List<GeoCoordinate> geoCoordinates = new ArrayList<>();
-        for (List bo:bound1) {
+        for (List bo : bound1) {
             GeoCoordinate g = new GeoCoordinate();
             g.setLatitude(Double.parseDouble(bo.get(0).toString()));
             g.setLongitude(Double.parseDouble(bo.get(1).toString()));
@@ -197,7 +197,7 @@
         List centerPoint = new ArrayList();
         centerPoint.add(centerPoint400.getLongitude());
         centerPoint.add(centerPoint400.getLatitude());
-        resultMap.put("centerPoint",centerPoint);
+        resultMap.put("centerPoint", centerPoint);
         return resultMap;
     }
 
@@ -210,8 +210,8 @@
         //������������
         //���������������
         List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
-        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
-            for (Organization organization:allChildrenOrganization) {
+        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1) {
+            for (Organization organization : allChildrenOrganization) {
                 allOrgId.add(organization.getId());
             }
         }
@@ -220,33 +220,33 @@
         //������������list���������������mac
         List<String> deviceMacList = new ArrayList<>();
         //������������map���Mac������key���device������value
-        Map<String,Device> deviceMap = new HashMap<>();
+        Map<String, Device> deviceMap = new HashMap<>();
         List<Double> longitudeList = new ArrayList<>();
         List<Double> latitudeList = new ArrayList<>();
-        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
+        for (Integer orgIdWithoutDuplicates : allOrgIdWithoutDuplicates) {
             //������id������������������
             QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
-            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
+            wrapper_device.eq("is_delete", Constants.NOT_DELETE).eq("organization_id", orgIdWithoutDuplicates);
             List<Device> devices = new ArrayList<>();
             devices = deviceMapper.selectList(wrapper_device);
-            if (devices.size()>0){
-                for (Device device:devices) {
+            if (devices.size() > 0) {
+                for (Device device : devices) {
                     String mac = device.getMac();
                     deviceMacList.add(mac);
-                    deviceMap.put(mac,device);
+                    deviceMap.put(mac, device);
                     double longitude = device.getLongitude();
                     double latitude = device.getLatitude();
                     longitudeList.add(longitude);
                     latitudeList.add(latitude);
                 }
-            }else {
+            } else {
                 continue;
             }
         }
-        double latitudeMin = Collections.min(latitudeList)-0.0018;
-        double latitudeMax = Collections.max(latitudeList)+0.0018;
-        double longitudeMin = Collections.min(longitudeList)-0.2/(111*Math.cos(latitudeMin));
-        double longitudeMax = Collections.max(longitudeList)+0.2/(111*Math.cos(latitudeMin));
+        double latitudeMin = Collections.min(latitudeList) - 0.0018;
+        double latitudeMax = Collections.max(latitudeList) + 0.0018;
+        double longitudeMin = Collections.min(longitudeList) - 0.2 / (111 * Math.cos(latitudeMin));
+        double longitudeMax = Collections.max(longitudeList) + 0.2 / (111 * Math.cos(latitudeMin));
         List<Double> bound = new ArrayList<>();
         bound.add(longitudeMin);
         bound.add(latitudeMin);
@@ -270,7 +270,7 @@
         bound1.add(right_down);
         bound1.add(left_down);
         List<GeoCoordinate> geoCoordinates = new ArrayList<>();
-        for (List bo:bound1) {
+        for (List bo : bound1) {
             GeoCoordinate g = new GeoCoordinate();
             g.setLatitude(Double.parseDouble(bo.get(0).toString()));
             g.setLongitude(Double.parseDouble(bo.get(1).toString()));
@@ -282,16 +282,16 @@
         centerPoint.add(centerPoint400.getLatitude());
         List<Map<String, Object>> resultList = new ArrayList<>();
         //������������
-        String endTime = parameters.get("endTime").toString().substring(0,10)+" 00:00:00";
+        String endTime = parameters.get("endTime").toString().substring(0, 10) + " 00:00:00";
         //������������
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
         int days = Integer.parseInt(parameters.get("days").toString());
         Date newEndTime = new Date();
-        for (int i=days;i>=0;i--){
+        for (int i = days; i >= 0; i--) {
             Map<String, Object> resultMap = new HashMap<>();
             //������������������������������
-            resultMap.put("centerPoint",centerPoint);
-            resultMap.put("bound",bound);
+            resultMap.put("centerPoint", centerPoint);
+            resultMap.put("bound", bound);
             Calendar calendar = Calendar.getInstance();
             try {
                 newEndTime = df.parse(endTime);
@@ -299,16 +299,16 @@
                 e.printStackTrace();
             }
             calendar.setTime(newEndTime);
-            calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)-i);
-            String time = df.format(calendar.getTime())+" 00:00:00";
+            calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - i);
+            String time = df.format(calendar.getTime()) + " 00:00:00";
             //������������
-            resultMap.put("time",time);
+            resultMap.put("time", time);
             QueryWrapper<HistoryDaily> historyDailyQueryWrapper = new QueryWrapper<>();
-            historyDailyQueryWrapper.eq("time",time);
+            historyDailyQueryWrapper.eq("time", time);
             historyDailyQueryWrapper.in("mac", deviceMacList);
             List<HistoryDaily> historyDailies = historyDailyMapper.selectList(historyDailyQueryWrapper);
             List<Object> list = new ArrayList<>();
-            for (HistoryDaily historyDailyData:historyDailies) {
+            for (HistoryDaily historyDailyData : historyDailies) {
                 List<Object> list1 = new ArrayList<>();
                 String mac = historyDailyData.getMac();
                 Device device = deviceMap.get(mac);
@@ -322,11 +322,20 @@
                 list1.add(level);
                 list.add(list1);
             }
-            resultMap.put("list",list);
+            resultMap.put("list", list);
             resultList.add(resultMap);
         }
         return resultList;
     }
 
+    @Override
+    public List<HistoryDaily> getValueByMacs(List<String> macs, String time) {
+        QueryWrapper<HistoryDaily> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("time", "value")
+                .likeRight("time", time)
+                .in("mac", macs);
+        return historyDailyMapper.selectList(queryWrapper);
+    }
+
 
 }
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
index e842633..c60183b 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
@@ -14,9 +14,9 @@
 import com.moral.pojo.AQI;
 import com.moral.util.AQIUtils;
 import com.moral.util.DateUtils;
-
 import com.moral.util.MybatisPLUSUtils;
 import com.moral.util.PollutantUtils;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
@@ -68,11 +68,11 @@
     }
 
     /**
-     *@Description: ������������id������������������������������������������
-     *@Param: [map]
-     *@return: java.util.Map<java.lang.String,java.lang.Object>
-     *@Author: lizijie
-     *@Date: 2021/12/7 10:07
+     * @Description: ������������id������������������������������������������
+     * @Param: [map]
+     * @return: java.util.Map<java.lang.String, java.lang.Object>
+     * @Author: lizijie
+     * @Date: 2021/12/7 10:07
      **/
     @Override
     public Map<String, Object> getLastHourDataByOrgIdAndSensorCode(Map parameters) {
@@ -84,8 +84,8 @@
         //������������
         //���������������
         List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
-        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
-            for (Organization organization:allChildrenOrganization) {
+        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1) {
+            for (Organization organization : allChildrenOrganization) {
                 allOrgId.add(organization.getId());
             }
         }
@@ -94,36 +94,36 @@
         //������������list���������������mac
         List<String> deviceMacList = new ArrayList<>();
         //������������map���Mac������key���device������value
-        Map<String,Device> deviceMap = new HashMap<>();
-        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
+        Map<String, Device> deviceMap = new HashMap<>();
+        for (Integer orgIdWithoutDuplicates : allOrgIdWithoutDuplicates) {
             //������id������������������
             QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
-            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
+            wrapper_device.eq("is_delete", Constants.NOT_DELETE).eq("organization_id", orgIdWithoutDuplicates);
             List<Device> devices = new ArrayList<>();
             devices = deviceMapper.selectList(wrapper_device);
-            if (devices.size()>0){
-                for (Device device:devices) {
+            if (devices.size() > 0) {
+                for (Device device : devices) {
                     String mac = device.getMac();
                     deviceMacList.add(mac);
-                    deviceMap.put(mac,device);
+                    deviceMap.put(mac, device);
                 }
-            }else {
+            } else {
                 continue;
             }
         }
         //������������
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH");
         Calendar calendar = Calendar.getInstance();
-        calendar.set(Calendar.HOUR_OF_DAY,calendar.get(Calendar.HOUR_OF_DAY)-1);
-        String time = df.format(calendar.getTime())+":00:00";
-        resultMap.put("time",time);
-        String timeUnits =  DateUtils.dateToDateString(calendar.getTime(), DateUtils.yyyyMM_EN);
-        List<Map<String,Object>> historyHourlyDatas = new ArrayList<>();
+        calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);
+        String time = df.format(calendar.getTime()) + ":00:00";
+        resultMap.put("time", time);
+        String timeUnits = DateUtils.dateToDateString(calendar.getTime(), DateUtils.yyyyMM_EN);
+        List<Map<String, Object>> historyHourlyDatas = new ArrayList<>();
         historyHourlyDatas = historyHourlyMapper.selectDataByMacsAndTime(timeUnits, deviceMacList, time);
         List<Object> list = new ArrayList<>();
         List<Double> longitudeList = new ArrayList<>();
         List<Double> latitudeList = new ArrayList<>();
-        for (Map historyHourlyData:historyHourlyDatas) {
+        for (Map historyHourlyData : historyHourlyDatas) {
             List<Object> list1 = new ArrayList<>();
             String mac = historyHourlyData.get("mac").toString();
             Device device = deviceMap.get(mac);
@@ -139,17 +139,17 @@
             list1.add(level);
             list.add(list1);
         }
-        resultMap.put("list",list);
-        double latitudeMin = Collections.min(latitudeList)-0.0018;
-        double latitudeMax = Collections.max(latitudeList)+0.0018;
-        double longitudeMin = Collections.min(longitudeList)-0.2/(111*Math.cos(latitudeMin));
-        double longitudeMax = Collections.max(longitudeList)+0.2/(111*Math.cos(latitudeMin));
+        resultMap.put("list", list);
+        double latitudeMin = Collections.min(latitudeList) - 0.0018;
+        double latitudeMax = Collections.max(latitudeList) + 0.0018;
+        double longitudeMin = Collections.min(longitudeList) - 0.2 / (111 * Math.cos(latitudeMin));
+        double longitudeMax = Collections.max(longitudeList) + 0.2 / (111 * Math.cos(latitudeMin));
         List<Double> bound = new ArrayList<>();
         bound.add(longitudeMin);
         bound.add(latitudeMax);
         bound.add(longitudeMax);
         bound.add(latitudeMin);
-        resultMap.put("bound",bound);
+        resultMap.put("bound", bound);
         List<List> bound1 = new ArrayList<>();
         List<Double> left_up = new ArrayList<>();
         left_up.add(latitudeMax);
@@ -168,7 +168,7 @@
         bound1.add(right_down);
         bound1.add(left_down);
         List<GeoCoordinate> geoCoordinates = new ArrayList<>();
-        for (List bo:bound1) {
+        for (List bo : bound1) {
             GeoCoordinate g = new GeoCoordinate();
             g.setLatitude(Double.parseDouble(bo.get(0).toString()));
             g.setLongitude(Double.parseDouble(bo.get(1).toString()));
@@ -178,7 +178,7 @@
         List centerPoint = new ArrayList();
         centerPoint.add(centerPoint400.getLongitude());
         centerPoint.add(centerPoint400.getLatitude());
-        resultMap.put("centerPoint",centerPoint);
+        resultMap.put("centerPoint", centerPoint);
         return resultMap;
     }
 
@@ -192,8 +192,8 @@
         //������������
         //���������������
         List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
-        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
-            for (Organization organization:allChildrenOrganization) {
+        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1) {
+            for (Organization organization : allChildrenOrganization) {
                 allOrgId.add(organization.getId());
             }
         }
@@ -202,41 +202,41 @@
         //������������list���������������mac
         List<String> deviceMacList = new ArrayList<>();
         //������������map���Mac������key���device������value
-        Map<String,Device> deviceMap = new HashMap<>();
+        Map<String, Device> deviceMap = new HashMap<>();
         List<Double> longitudeList = new ArrayList<>();
         List<Double> latitudeList = new ArrayList<>();
-        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
+        for (Integer orgIdWithoutDuplicates : allOrgIdWithoutDuplicates) {
             //������id������������������
             QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
-            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
+            wrapper_device.eq("is_delete", Constants.NOT_DELETE).eq("organization_id", orgIdWithoutDuplicates);
             List<Device> devices = new ArrayList<>();
             devices = deviceMapper.selectList(wrapper_device);
-            if (devices.size()>0){
-                for (Device device:devices) {
+            if (devices.size() > 0) {
+                for (Device device : devices) {
                     String mac = device.getMac();
                     deviceMacList.add(mac);
-                    deviceMap.put(mac,device);
+                    deviceMap.put(mac, device);
                     double longitude = device.getLongitude();
                     double latitude = device.getLatitude();
                     longitudeList.add(longitude);
                     latitudeList.add(latitude);
                 }
-            }else {
+            } else {
                 continue;
             }
         }
         List<Object> list = new ArrayList<>();
         //������������
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH");
-        for (int i=12;i>0;i--){
+        for (int i = 12; i > 0; i--) {
             Calendar calendar = Calendar.getInstance();
-            calendar.set(Calendar.HOUR_OF_DAY,calendar.get(Calendar.HOUR_OF_DAY)-i);
-            String time = df.format(calendar.getTime())+":00:00";
-            String timeUnits =  DateUtils.dateToDateString(calendar.getTime(), DateUtils.yyyyMM_EN);
-            List<Map<String,Object>> historyHourlyDatas = new ArrayList<>();
+            calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - i);
+            String time = df.format(calendar.getTime()) + ":00:00";
+            String timeUnits = DateUtils.dateToDateString(calendar.getTime(), DateUtils.yyyyMM_EN);
+            List<Map<String, Object>> historyHourlyDatas = new ArrayList<>();
             historyHourlyDatas = historyHourlyMapper.selectDataByMacsAndTime(timeUnits, deviceMacList, time);
             List<Object> oneHourlyList = new ArrayList<>();
-            for (Map historyHourlyData:historyHourlyDatas) {
+            for (Map historyHourlyData : historyHourlyDatas) {
                 List<Object> list1 = new ArrayList<>();
                 String mac = historyHourlyData.get("mac").toString();
                 Device device = deviceMap.get(mac);
@@ -252,17 +252,17 @@
             }
             list.add(oneHourlyList);
         }
-        resultMap.put("list",list);
-        double latitudeMin = Collections.min(latitudeList)-0.0018;
-        double latitudeMax = Collections.max(latitudeList)+0.0018;
-        double longitudeMin = Collections.min(longitudeList)-0.2/(111*Math.cos(latitudeMin));
-        double longitudeMax = Collections.max(longitudeList)+0.2/(111*Math.cos(latitudeMin));
+        resultMap.put("list", list);
+        double latitudeMin = Collections.min(latitudeList) - 0.0018;
+        double latitudeMax = Collections.max(latitudeList) + 0.0018;
+        double longitudeMin = Collections.min(longitudeList) - 0.2 / (111 * Math.cos(latitudeMin));
+        double longitudeMax = Collections.max(longitudeList) + 0.2 / (111 * Math.cos(latitudeMin));
         List<Double> bound = new ArrayList<>();
         bound.add(latitudeMax);
         bound.add(longitudeMax);
         bound.add(latitudeMin);
         bound.add(longitudeMin);
-        resultMap.put("bound",bound);
+        resultMap.put("bound", bound);
         List<List> bound1 = new ArrayList<>();
         List<Double> left_up = new ArrayList<>();
         left_up.add(latitudeMax);
@@ -281,7 +281,7 @@
         bound1.add(right_down);
         bound1.add(left_down);
         List<GeoCoordinate> geoCoordinates = new ArrayList<>();
-        for (List bo:bound1) {
+        for (List bo : bound1) {
             GeoCoordinate g = new GeoCoordinate();
             g.setLatitude(Double.parseDouble(bo.get(0).toString()));
             g.setLongitude(Double.parseDouble(bo.get(1).toString()));
@@ -291,7 +291,7 @@
         List centerPoint = new ArrayList();
         centerPoint.add(centerPoint400.getLongitude());
         centerPoint.add(centerPoint400.getLatitude());
-        resultMap.put("centerPoint",centerPoint);
+        resultMap.put("centerPoint", centerPoint);
         return resultMap;
     }
 
@@ -305,8 +305,8 @@
         //������������
         //���������������
         List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
-        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
-            for (Organization organization:allChildrenOrganization) {
+        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1) {
+            for (Organization organization : allChildrenOrganization) {
                 allOrgId.add(organization.getId());
             }
         }
@@ -315,37 +315,37 @@
         //������������list���������������mac
         List<String> deviceMacList = new ArrayList<>();
         //������������map���Mac������key���device������value
-        Map<String,Device> deviceMap = new HashMap<>();
+        Map<String, Device> deviceMap = new HashMap<>();
         List<Double> longitudeList = new ArrayList<>();
         List<Double> latitudeList = new ArrayList<>();
-        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
+        for (Integer orgIdWithoutDuplicates : allOrgIdWithoutDuplicates) {
             //������id������������������
             QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
-            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
+            wrapper_device.eq("is_delete", Constants.NOT_DELETE).eq("organization_id", orgIdWithoutDuplicates);
             List<Device> devices = new ArrayList<>();
             devices = deviceMapper.selectList(wrapper_device);
-            if (devices.size()>0){
-                for (Device device:devices) {
+            if (devices.size() > 0) {
+                for (Device device : devices) {
                     String mac = device.getMac();
                     deviceMacList.add(mac);
-                    deviceMap.put(mac,device);
+                    deviceMap.put(mac, device);
                     double longitude = device.getLongitude();
                     double latitude = device.getLatitude();
                     longitudeList.add(longitude);
                     latitudeList.add(latitude);
                 }
-            }else {
+            } else {
                 continue;
             }
         }
         //������������
-        String time = parameters.get("time").toString().substring(0,13)+":00:00";
-        resultMap.put("time",time);
-        String timeUnits =  DateUtils.stringToDateString(time, DateUtils.yyyy_MM_dd_HH_mm_ss_EN, DateUtils.yyyyMM_EN);
-        List<Map<String,Object>> historyHourlyDatas = new ArrayList<>();
+        String time = parameters.get("time").toString().substring(0, 13) + ":00:00";
+        resultMap.put("time", time);
+        String timeUnits = DateUtils.stringToDateString(time, DateUtils.yyyy_MM_dd_HH_mm_ss_EN, DateUtils.yyyyMM_EN);
+        List<Map<String, Object>> historyHourlyDatas = new ArrayList<>();
         historyHourlyDatas = historyHourlyMapper.selectDataByMacsAndTime(timeUnits, deviceMacList, time);
         List<Object> list = new ArrayList<>();
-        for (Map historyHourlyData:historyHourlyDatas) {
+        for (Map historyHourlyData : historyHourlyDatas) {
             List<Object> list1 = new ArrayList<>();
             String mac = historyHourlyData.get("mac").toString();
             Device device = deviceMap.get(mac);
@@ -359,17 +359,17 @@
             list1.add(level);
             list.add(list1);
         }
-        resultMap.put("list",list);
-        double latitudeMin = Collections.min(latitudeList)-0.0018;
-        double latitudeMax = Collections.max(latitudeList)+0.0018;
-        double longitudeMin = Collections.min(longitudeList)-0.2/(111*Math.cos(latitudeMin));
-        double longitudeMax = Collections.max(longitudeList)+0.2/(111*Math.cos(latitudeMin));
+        resultMap.put("list", list);
+        double latitudeMin = Collections.min(latitudeList) - 0.0018;
+        double latitudeMax = Collections.max(latitudeList) + 0.0018;
+        double longitudeMin = Collections.min(longitudeList) - 0.2 / (111 * Math.cos(latitudeMin));
+        double longitudeMax = Collections.max(longitudeList) + 0.2 / (111 * Math.cos(latitudeMin));
         List<Double> bound = new ArrayList<>();
         bound.add(longitudeMin);
         bound.add(latitudeMin);
         bound.add(longitudeMax);
         bound.add(latitudeMax);
-        resultMap.put("bound",bound);
+        resultMap.put("bound", bound);
         List<List> bound1 = new ArrayList<>();
         List<Double> left_up = new ArrayList<>();
         left_up.add(latitudeMax);
@@ -388,7 +388,7 @@
         bound1.add(right_down);
         bound1.add(left_down);
         List<GeoCoordinate> geoCoordinates = new ArrayList<>();
-        for (List bo:bound1) {
+        for (List bo : bound1) {
             GeoCoordinate g = new GeoCoordinate();
             g.setLatitude(Double.parseDouble(bo.get(0).toString()));
             g.setLongitude(Double.parseDouble(bo.get(1).toString()));
@@ -398,7 +398,7 @@
         List centerPoint = new ArrayList();
         centerPoint.add(centerPoint400.getLongitude());
         centerPoint.add(centerPoint400.getLatitude());
-        resultMap.put("centerPoint",centerPoint);
+        resultMap.put("centerPoint", centerPoint);
         return resultMap;
     }
 
@@ -411,8 +411,8 @@
         //������������
         //���������������
         List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
-        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
-            for (Organization organization:allChildrenOrganization) {
+        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1) {
+            for (Organization organization : allChildrenOrganization) {
                 allOrgId.add(organization.getId());
             }
         }
@@ -421,33 +421,33 @@
         //������������list���������������mac
         List<String> deviceMacList = new ArrayList<>();
         //������������map���Mac������key���device������value
-        Map<String,Device> deviceMap = new HashMap<>();
+        Map<String, Device> deviceMap = new HashMap<>();
         List<Double> longitudeList = new ArrayList<>();
         List<Double> latitudeList = new ArrayList<>();
-        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
+        for (Integer orgIdWithoutDuplicates : allOrgIdWithoutDuplicates) {
             //������id������������������
             QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
-            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
+            wrapper_device.eq("is_delete", Constants.NOT_DELETE).eq("organization_id", orgIdWithoutDuplicates);
             List<Device> devices = new ArrayList<>();
             devices = deviceMapper.selectList(wrapper_device);
-            if (devices.size()>0){
-                for (Device device:devices) {
+            if (devices.size() > 0) {
+                for (Device device : devices) {
                     String mac = device.getMac();
                     deviceMacList.add(mac);
-                    deviceMap.put(mac,device);
+                    deviceMap.put(mac, device);
                     double longitude = device.getLongitude();
                     double latitude = device.getLatitude();
                     longitudeList.add(longitude);
                     latitudeList.add(latitude);
                 }
-            }else {
+            } else {
                 continue;
             }
         }
-        double latitudeMin = Collections.min(latitudeList)-0.0018;
-        double latitudeMax = Collections.max(latitudeList)+0.0018;
-        double longitudeMin = Collections.min(longitudeList)-0.2/(111*Math.cos(latitudeMin));
-        double longitudeMax = Collections.max(longitudeList)+0.2/(111*Math.cos(latitudeMin));
+        double latitudeMin = Collections.min(latitudeList) - 0.0018;
+        double latitudeMax = Collections.max(latitudeList) + 0.0018;
+        double longitudeMin = Collections.min(longitudeList) - 0.2 / (111 * Math.cos(latitudeMin));
+        double longitudeMax = Collections.max(longitudeList) + 0.2 / (111 * Math.cos(latitudeMin));
         List<Double> bound = new ArrayList<>();
         bound.add(longitudeMin);
         bound.add(latitudeMin);
@@ -471,7 +471,7 @@
         bound1.add(right_down);
         bound1.add(left_down);
         List<GeoCoordinate> geoCoordinates = new ArrayList<>();
-        for (List bo:bound1) {
+        for (List bo : bound1) {
             GeoCoordinate g = new GeoCoordinate();
             g.setLatitude(Double.parseDouble(bo.get(0).toString()));
             g.setLongitude(Double.parseDouble(bo.get(1).toString()));
@@ -487,11 +487,11 @@
         String endTime = parameters.get("endTime").toString();
         int hour = Integer.parseInt(parameters.get("hour").toString());
         Date newEndTime = new Date();
-        for (int i=hour;i>=0;i--){
+        for (int i = hour; i >= 0; i--) {
             Map<String, Object> resultMap = new HashMap<>();
             //������������������������������
-            resultMap.put("centerPoint",centerPoint);
-            resultMap.put("bound",bound);
+            resultMap.put("centerPoint", centerPoint);
+            resultMap.put("bound", bound);
             Calendar calendar = Calendar.getInstance();
             try {
                 newEndTime = df.parse(endTime);
@@ -499,15 +499,15 @@
                 e.printStackTrace();
             }
             calendar.setTime(newEndTime);
-            calendar.set(Calendar.HOUR_OF_DAY,calendar.get(Calendar.HOUR_OF_DAY)-i);
-            String time = df.format(calendar.getTime())+":00:00";
+            calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - i);
+            String time = df.format(calendar.getTime()) + ":00:00";
             //������������
-            resultMap.put("time",time);
-            String timeUnits =  DateUtils.dateToDateString(calendar.getTime(), DateUtils.yyyyMM_EN);
-            List<Map<String,Object>> historyHourlyDatas = new ArrayList<>();
+            resultMap.put("time", time);
+            String timeUnits = DateUtils.dateToDateString(calendar.getTime(), DateUtils.yyyyMM_EN);
+            List<Map<String, Object>> historyHourlyDatas = new ArrayList<>();
             historyHourlyDatas = historyHourlyMapper.selectDataByMacsAndTime(timeUnits, deviceMacList, time);
             List<Object> oneHourlyList = new ArrayList<>();
-            for (Map historyHourlyData:historyHourlyDatas) {
+            for (Map historyHourlyData : historyHourlyDatas) {
                 List<Object> list1 = new ArrayList<>();
                 String mac = historyHourlyData.get("mac").toString();
                 Device device = deviceMap.get(mac);
@@ -521,7 +521,7 @@
                 list1.add(level);
                 oneHourlyList.add(list1);
             }
-            resultMap.put("list",oneHourlyList);
+            resultMap.put("list", oneHourlyList);
             list.add(resultMap);
         }
         return list;
@@ -545,15 +545,14 @@
     }
 
     @Override
-    public Double getSensorSumByMacs(String sensorCode, List macs, String time) {
-        String timeUnits = time.substring(0, 7).replace("-", "");
-        return historyHourlyMapper.getSensorSumByMacs(sensorCode, macs, time, timeUnits);
-    }
-
-    @Override
-    public Double getSensorAvgByMacs(String sensorCode, List macs, String time) {
-        String timeUnits = time.substring(0, 7).replace("-", "");
-        return historyHourlyMapper.getSensorAvgByMacs(sensorCode, macs, time, timeUnits);
+    public List<HistoryHourly> getValueByMacs(List<String> macs, String time) {
+        QueryWrapper<HistoryHourly> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("time", "value")
+                .likeRight("time", time)
+                .in("mac", macs);
+        Date date = DateUtils.getDate(time, DateUtils.yyyy_MM_dd_EN);
+        List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(date, date, SeparateTableType.MONTH);
+        return multiTableQuery(queryWrapper, tableNames);
     }
 
     /**
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/HistoryMonthlyServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/HistoryMonthlyServiceImpl.java
index 33e7c6e..946fd43 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/HistoryMonthlyServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/HistoryMonthlyServiceImpl.java
@@ -298,4 +298,13 @@
         }
         return resultList;
     }
+
+    @Override
+    public List<HistoryMonthly> getValueByMacs(List<String> macs, String time) {
+        QueryWrapper<HistoryMonthly> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("time", "value")
+                .likeRight("time", time)
+                .in("mac", macs);
+        return historyMonthlyMapper.selectList(queryWrapper);
+    }
 }
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/ProfessionServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/ProfessionServiceImpl.java
index fa708b8..1bad56a 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/ProfessionServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/ProfessionServiceImpl.java
@@ -13,16 +13,23 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.OptionalDouble;
 import java.util.Set;
+import java.util.function.Supplier;
 import java.util.stream.Collectors;
+import java.util.stream.DoubleStream;
+import java.util.stream.Stream;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.moral.api.entity.CityAqi;
 import com.moral.api.entity.CityAqiDaily;
 import com.moral.api.entity.CityAqiMonthly;
 import com.moral.api.entity.Device;
 import com.moral.api.entity.HistoryDaily;
+import com.moral.api.entity.HistoryHourly;
 import com.moral.api.entity.HistoryMonthly;
+import com.moral.api.entity.Organization;
 import com.moral.api.entity.Sensor;
 import com.moral.api.service.CityAqiDailyService;
 import com.moral.api.service.CityAqiMonthlyService;
@@ -169,90 +176,109 @@
     private List<Map<String, Object>> professionContributionOfYear(Integer orgId, List<String> professions, String time, String sensorCode) {
         List<Map<String, Object>> result = new ArrayList<>();
 
+        //������������������������������
+        QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>();
+        organizationQueryWrapper.select("location_level_code")
+                .eq("id", orgId);
+        Integer locationLevelCode = organizationService.getOne(organizationQueryWrapper).getLocationLevelCode();
+
         //���������������������������
         List allMacs = getMacsByOrgId(orgId);
 
         List<String> timeLag = DateUtils.getTimeLag(time);
+
+        //������������������������
+        QueryWrapper<CityAqiMonthly> cityAqiMonthlyQueryWrapper = new QueryWrapper<>();
+        cityAqiMonthlyQueryWrapper.select("time", "value")
+                .eq("city_code", locationLevelCode)
+                .likeRight("time", time);
+        List<Map<String, Object>> cityAqis = cityAqiMonthlyService.listMaps(cityAqiMonthlyQueryWrapper);
+        Map<String, Object> cityAqiMap = new HashMap<>();
+        if (!ObjectUtils.isEmpty(cityAqis)) {
+            for (Map<String, Object> cityAqi : cityAqis) {
+                cityAqiMap.put(cityAqi.get("time").toString().substring(0, 7), cityAqi.get("value"));
+            }
+        }
+
+
+        //���������������������������������
+        List<HistoryMonthly> allDeviceData = historyMonthlyService.getValueByMacs(allMacs, time);
+        //���time������
+        Map<String, List<HistoryMonthly>> allDeviceDataMap = allDeviceData.stream()
+                .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 7)));
+
+
         for (String yearMonth : timeLag) {
             Map<String, Object> resultMap = new HashMap<>();
-            resultMap.put("time", yearMonth.split("-")[1]);
-            yearMonth = yearMonth + "-01 00:00:00";
+            resultMap.put("time", yearMonth);
 
 
             //������������������������������
             Double allDeviceSum = null;
-            QueryWrapper<HistoryMonthly> historyMonthlyQueryWrapper = new QueryWrapper<>();
-            historyMonthlyQueryWrapper.select("SUM(`value`->'$." + sensorCode + "') AS result")
-                    .eq("time", yearMonth)
-                    .in("mac", allMacs);
-            Map<String, Object> allDeviceSumMap = historyMonthlyService.getMap(historyMonthlyQueryWrapper);
-            if (!ObjectUtils.isEmpty(allDeviceSumMap)) {
-                allDeviceSum = (Double) allDeviceSumMap.get("result");
+            List<HistoryMonthly> historyMonthlyList = allDeviceDataMap.get(yearMonth);
+            if (!ObjectUtils.isEmpty(historyMonthlyList)) {
+                allDeviceSum = historyMonthlyList.stream().flatMapToDouble(v -> {
+                    Map<String, Object> dataValue = JSONObject.parseObject(v.getValue(), Map.class);
+                    Object o = dataValue.get(sensorCode);
+                    if (o == null) {
+                        return null;
+                    }
+                    double aDouble = Double.parseDouble(o.toString());
+                    return DoubleStream.of(aDouble);
+                }).sum();
             }
+            resultMap.put("allDeviceSum", allDeviceSum);
 
 
-            //������������
+            //���������
             Double cityValue = null;
-            //������������������������������
-            Integer locationLevelCode = organizationService.getById(orgId).getLocationLevelCode();
-            QueryWrapper<CityAqiMonthly> cityAqiMonthlyQueryWrapper = new QueryWrapper<>();
-            cityAqiMonthlyQueryWrapper.select("`value`->'$." + sensorCode + "' AS result")
-                    .eq("city_code", locationLevelCode)
-                    .eq("time", yearMonth);
-            Map<String, Object> cityValueMap = cityAqiMonthlyService.getMap(cityAqiMonthlyQueryWrapper);
-            if (!ObjectUtils.isEmpty(cityValueMap)) {
-                cityValue = (Double) cityValueMap.get("result");
+            if (cityAqiMap.get(yearMonth) != null) {
+                Map<String, Object> dataValue = JSONObject.parseObject(cityAqiMap.get(yearMonth).toString(), Map.class);
+                Object o = dataValue.get(sensorCode);
+                if (o != null) {
+                    cityValue = (Double) o;
+                }
             }
             resultMap.put("cityValue", cityValue);
-
-
-            for (String profession : professions) {
-                Map<String, Object> professionMap = new HashMap<>();
-
-                //���������������������
-                List<Device> devices = getDevicesOfProfessions(orgId, Collections.singletonList(profession));
-                List<String> professionMacs = devices.stream().map(Device::getMac).collect(Collectors.toList());
-
-
-                //������������������
-                Double professionSum = null;
-                historyMonthlyQueryWrapper.clear();
-                historyMonthlyQueryWrapper.select("SUM(`value`->'$." + sensorCode + "') AS result")
-                        .eq("time", yearMonth)
-                        .in("mac", professionMacs);
-                Map<String, Object> professionSumMap = historyMonthlyService.getMap(historyMonthlyQueryWrapper);
-                if (!ObjectUtils.isEmpty(professionSumMap)) {
-                    professionSum = (Double) professionSumMap.get("result");
-                }
-
-
-                //������������������
-                Double professionAvg = null;
-                historyMonthlyQueryWrapper.clear();
-                historyMonthlyQueryWrapper.select("AVG(`value`->'$." + sensorCode + "') AS result")
-                        .eq("time", yearMonth)
-                        .in("mac", professionMacs);
-                Map<String, Object> professionAvgMap = historyMonthlyService.getMap(historyMonthlyQueryWrapper);
-                if (!ObjectUtils.isEmpty(professionAvgMap)) {
-                    professionAvg = (Double) professionAvgMap.get("result");
-                }
-
-                //���������������������
-                String contributionRate = null;
-                NumberFormat numberFormat = NumberFormat.getInstance();
-                numberFormat.setMaximumFractionDigits(2);
-                if (professionSum != null && allDeviceSum != null) {
-                    contributionRate = numberFormat.format(professionSum / allDeviceSum * 100) + "%";
-                }
-
-                //������������
-                professionMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0));
-                //���������������
-                professionMap.put("contributionRate", contributionRate);
-
-                resultMap.put(profession, professionMap);
-            }
             result.add(resultMap);
+        }
+
+        for (String profession : professions) {
+            //���������������������
+            List<Device> professionDevices = getDevicesOfProfessions(orgId, Collections.singletonList(profession));
+            List<String> professionMacs = professionDevices.stream().map(Device::getMac).collect(Collectors.toList());
+
+
+            //���������������������������������
+            List<HistoryMonthly> professionDeviceData = historyMonthlyService.getValueByMacs(professionMacs, time);
+            //���time������
+            Map<String, List<HistoryMonthly>> professionDataMap = professionDeviceData.stream()
+                    .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 7)));
+
+
+            for (Map<String, Object> map : result) {
+                Object allDeviceSum = map.remove("allDeviceSum");
+                String resultTime = map.get("time").toString();
+                List<HistoryMonthly> historyMonthlyList = professionDataMap.get(resultTime);
+                //���������
+                String contributionRate = null;
+                Double professionAvg = null;
+                if (!ObjectUtils.isEmpty(historyMonthlyList)) {
+                    Supplier<Stream<HistoryMonthly>> streamSupplier = historyMonthlyList::stream;
+                    professionAvg = calculatedValueOfYear(streamSupplier, sensorCode, "avg");
+                    Double professionSum = calculatedValueOfYear(streamSupplier, sensorCode, "sum");
+                    //���������������������
+                    NumberFormat numberFormat = NumberFormat.getInstance();
+                    numberFormat.setMaximumFractionDigits(2);
+                    if (allDeviceSum != null) {
+                        contributionRate = numberFormat.format(professionSum / ((Double) allDeviceSum) * 100) + "%";
+                    }
+                }
+                Map<String, Object> professionMap = new HashMap<>();
+                professionMap.put("contributionRate", contributionRate);
+                professionMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0));
+                map.put(profession, professionMap);
+            }
         }
         return result;
     }
@@ -261,92 +287,110 @@
     private List<Map<String, Object>> professionContributionOfMonth(Integer orgId, List<String> professions, String time, String sensorCode) {
         List<Map<String, Object>> result = new ArrayList<>();
 
+        //������������������������������
+        QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>();
+        organizationQueryWrapper.select("location_level_code")
+                .eq("id", orgId);
+        Integer locationLevelCode = organizationService.getOne(organizationQueryWrapper).getLocationLevelCode();
+
         //���������������������������
         List allMacs = getMacsByOrgId(orgId);
 
+        //������������
         List<String> timeLag = DateUtils.getTimeLag(time);
+
+
+        //������������������������
+        QueryWrapper<CityAqiDaily> cityAqiDailyQueryWrapper = new QueryWrapper<>();
+        cityAqiDailyQueryWrapper.select("time", "value")
+                .eq("city_code", locationLevelCode)
+                .likeRight("time", time);
+        List<Map<String, Object>> cityAqis = cityAqiDailyService.listMaps(cityAqiDailyQueryWrapper);
+        Map<String, Object> cityAqiMap = new HashMap<>();
+        if (!ObjectUtils.isEmpty(cityAqis)) {
+            for (Map<String, Object> cityAqi : cityAqis) {
+                cityAqiMap.put(cityAqi.get("time").toString().substring(0, 10), cityAqi.get("value"));
+            }
+        }
+
+
+        //������������������������
+        List<HistoryDaily> allDeviceData = historyDailyService.getValueByMacs(allMacs, time);
+        //���time������
+        Map<String, List<HistoryDaily>> allDeviceDataMap = allDeviceData.stream()
+                .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 10)));
+
+
         for (String yearMonthDay : timeLag) {
             Map<String, Object> resultMap = new HashMap<>();
-            resultMap.put("time", yearMonthDay.split("-")[2]);
-            yearMonthDay = yearMonthDay + " 00:00:00";
-
+            resultMap.put("time", yearMonthDay);
 
             //������������������������������
             Double allDeviceSum = null;
-            QueryWrapper<HistoryDaily> historyDailyQueryWrapper = new QueryWrapper<>();
-            historyDailyQueryWrapper.select("SUM(`value`->'$." + sensorCode + "') AS result")
-                    .eq("time", yearMonthDay)
-                    .in("mac", allMacs);
-            Map<String, Object> allDeviceSumMap = historyDailyService.getMap(historyDailyQueryWrapper);
-            if (!ObjectUtils.isEmpty(allDeviceSumMap)) {
-                allDeviceSum = (Double) allDeviceSumMap.get("result");
+            List<HistoryDaily> historyDailyList = allDeviceDataMap.get(yearMonthDay);
+            if (!ObjectUtils.isEmpty(historyDailyList)) {
+                allDeviceSum = historyDailyList.stream().flatMapToDouble(v -> {
+                    Map<String, Object> dataValue = JSONObject.parseObject(v.getValue(), Map.class);
+                    Object o = dataValue.get(sensorCode);
+                    if (o == null) {
+                        return null;
+                    }
+                    double aDouble = Double.parseDouble(o.toString());
+                    return DoubleStream.of(aDouble);
+                }).sum();
             }
+            resultMap.put("allDeviceSum", allDeviceSum);
 
 
-            //������������
+            //���������
             Double cityValue = null;
-            //������������������������������
-            Integer locationLevelCode = organizationService.getById(orgId).getLocationLevelCode();
-            QueryWrapper<CityAqiDaily> cityAqiDailyQueryWrapper = new QueryWrapper<>();
-            cityAqiDailyQueryWrapper.select("`value`->'$." + sensorCode + "' AS result")
-                    .eq("city_code", locationLevelCode)
-                    .eq("time", yearMonthDay);
-            Map<String, Object> cityValueMap = cityAqiDailyService.getMap(cityAqiDailyQueryWrapper);
-            if (!ObjectUtils.isEmpty(cityValueMap)) {
-                cityValue = (Double) cityValueMap.get("result");
+            if (cityAqiMap.get(yearMonthDay) != null) {
+                Map<String, Object> dataValue = JSONObject.parseObject(cityAqiMap.get(yearMonthDay).toString(), Map.class);
+                Object o = dataValue.get(sensorCode);
+                if (o != null) {
+                    cityValue = (Double) o;
+                }
             }
             resultMap.put("cityValue", cityValue);
-
-
-
-            for (String profession : professions) {
-                Map<String, Object> professionMap = new HashMap<>();
-
-                //���������������������
-                List<Device> devices = getDevicesOfProfessions(orgId, Collections.singletonList(profession));
-                List<String> professionMacs = devices.stream().map(Device::getMac).collect(Collectors.toList());
-
-
-                //������������������
-                Double professionSum = null;
-                historyDailyQueryWrapper.clear();
-                historyDailyQueryWrapper.select("SUM(`value`->'$." + sensorCode + "') AS result")
-                        .eq("time", yearMonthDay)
-                        .in("mac", professionMacs);
-                Map<String, Object> professionSumMap = historyDailyService.getMap(historyDailyQueryWrapper);
-                if (!ObjectUtils.isEmpty(professionSumMap)) {
-                    professionSum = (Double) professionSumMap.get("result");
-                }
-
-
-                //������������������
-                Double professionAvg = null;
-                historyDailyQueryWrapper.clear();
-                historyDailyQueryWrapper.select("AVG(`value`->'$." + sensorCode + "') AS result")
-                        .eq("time", yearMonthDay)
-                        .in("mac", professionMacs);
-                Map<String, Object> professionAvgMap = historyDailyService.getMap(historyDailyQueryWrapper);
-                if (!ObjectUtils.isEmpty(professionAvgMap)) {
-                    professionAvg = (Double) professionAvgMap.get("result");
-                }
-
-
-                //���������������������
-                String contributionRate = null;
-                NumberFormat numberFormat = NumberFormat.getInstance();
-                numberFormat.setMaximumFractionDigits(2);
-                if (professionSum != null && allDeviceSum != null) {
-                    contributionRate = numberFormat.format(professionSum / allDeviceSum * 100) + "%";
-                }
-
-                //������������
-                professionMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0));
-                //���������������
-                professionMap.put("contributionRate", contributionRate);
-
-                resultMap.put(profession, professionMap);
-            }
             result.add(resultMap);
+        }
+
+        for (String profession : professions) {
+            //���������������������
+            List<Device> professionDevices = getDevicesOfProfessions(orgId, Collections.singletonList(profession));
+            List<String> professionMacs = professionDevices.stream().map(Device::getMac).collect(Collectors.toList());
+
+
+            //���������������������������������
+            List<HistoryDaily> professionDeviceData = historyDailyService.getValueByMacs(professionMacs, time);
+            //���time������
+            Map<String, List<HistoryDaily>> professionDataMap = professionDeviceData.stream()
+                    .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 10)));
+
+
+            for (Map<String, Object> map : result) {
+                Object allDeviceSum = map.remove("allDeviceSum");
+                String resultTime = map.get("time").toString();
+                List<HistoryDaily> historyDailyList = professionDataMap.get(resultTime);
+                //���������
+                String contributionRate = null;
+                Double professionAvg = null;
+                if (!ObjectUtils.isEmpty(historyDailyList)) {
+                    Supplier<Stream<HistoryDaily>> streamSupplier = historyDailyList::stream;
+                    professionAvg = calculatedValueOfMonth(streamSupplier, sensorCode, "avg");
+                    Double professionSum = calculatedValueOfMonth(streamSupplier, sensorCode, "sum");
+                    //���������������������
+                    NumberFormat numberFormat = NumberFormat.getInstance();
+                    numberFormat.setMaximumFractionDigits(2);
+                    if (allDeviceSum != null) {
+                        contributionRate = numberFormat.format(professionSum / ((Double) allDeviceSum) * 100) + "%";
+                    }
+                }
+                Map<String, Object> professionMap = new HashMap<>();
+                professionMap.put("contributionRate", contributionRate);
+                professionMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0));
+                map.put(profession, professionMap);
+            }
         }
         return result;
     }
@@ -354,62 +398,111 @@
     private List<Map<String, Object>> professionContributionOfDay(Integer orgId, List<String> professions, String time, String sensorCode) {
         List<Map<String, Object>> result = new ArrayList<>();
 
+        //������������������������������
+        QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>();
+        organizationQueryWrapper.select("location_level_code")
+                .eq("id", orgId);
+        Integer locationLevelCode = organizationService.getOne(organizationQueryWrapper).getLocationLevelCode();
+
         //���������������������������
         List allMacs = getMacsByOrgId(orgId);
 
+        //���������������
         List<String> timeLag = DateUtils.getTimeLag(time);
+
+
+        //������������������������������
+        QueryWrapper<CityAqi> cityAqiQueryWrapper = new QueryWrapper<>();
+        cityAqiQueryWrapper.select("time", "value")
+                .eq("city_code", locationLevelCode)
+                .likeRight("time", time);
+        List<Map<String, Object>> cityAqis = cityAqiService.listMaps(cityAqiQueryWrapper);
+        Map<String, Object> cityAqiMap = new HashMap<>();
+        if (!ObjectUtils.isEmpty(cityAqis)) {
+            for (Map<String, Object> cityAqi : cityAqis) {
+                cityAqiMap.put(cityAqi.get("time").toString().substring(0, 13), cityAqi.get("value"));
+            }
+        }
+
+
+        //������������������������������
+        List<HistoryHourly> allDeviceData = historyHourlyService.getValueByMacs(allMacs, time);
+        //���time������
+        Map<String, List<HistoryHourly>> allDeviceDataMap = allDeviceData.stream()
+                .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 13)));
+
+
         for (String yearMonthDayHour : timeLag) {
             Map<String, Object> resultMap = new HashMap<>();
-            resultMap.put("time", yearMonthDayHour.split(" ")[1]);
-            yearMonthDayHour = yearMonthDayHour + ":00:00";
+            resultMap.put("time", yearMonthDayHour);
 
 
             //������������������������������
-            Double allDeviceSum = historyHourlyService.getSensorSumByMacs(sensorCode, allMacs, yearMonthDayHour);
+            Double allDeviceSum = null;
+            List<HistoryHourly> historyHourlyList = allDeviceDataMap.get(yearMonthDayHour);
+            if (!ObjectUtils.isEmpty(historyHourlyList)) {
+                allDeviceSum = historyHourlyList.stream().flatMapToDouble(v -> {
+                    Map<String, Object> dataValue = JSONObject.parseObject(v.getValue(), Map.class);
+                    Object o = dataValue.get(sensorCode);
+                    if (o == null) {
+                        return null;
+                    }
+                    double aDouble = Double.parseDouble(o.toString());
+                    return DoubleStream.of(aDouble);
+                }).sum();
+            }
+            resultMap.put("allDeviceSum", allDeviceSum);
 
 
-            //������������
+            //���������
             Double cityValue = null;
-            //������������������������������
-            Integer locationLevelCode = organizationService.getById(orgId).getLocationLevelCode();
-            QueryWrapper<CityAqi> cityAqiQueryWrapper = new QueryWrapper<>();
-            cityAqiQueryWrapper.select("`value`->'$." + sensorCode + "' AS result")
-                    .eq("city_code", locationLevelCode)
-                    .eq("time", yearMonthDayHour);
-            Map<String, Object> cityValueMap = cityAqiService.getMap(cityAqiQueryWrapper);
-            if (!ObjectUtils.isEmpty(cityValueMap)) {
-                cityValue = (Double) cityValueMap.get("result");
+            if (cityAqiMap.get(yearMonthDayHour) != null) {
+                Map<String, Object> dataValue = JSONObject.parseObject(cityAqiMap.get(yearMonthDayHour).toString(), Map.class);
+                Object o = dataValue.get(sensorCode);
+                if (o != null) {
+                    cityValue = (Double) o;
+                }
             }
             resultMap.put("cityValue", cityValue);
-
-
-            for (String profession : professions) {
-                Map<String, Object> professionMap = new HashMap<>();
-
-                //���������������������
-                List<Device> devices = getDevicesOfProfessions(orgId, Collections.singletonList(profession));
-                List<String> professionMacs = devices.stream().map(Device::getMac).collect(Collectors.toList());
-
-                //���������������������������������������������������
-                Double professionAvg = historyHourlyService.getSensorAvgByMacs(sensorCode, professionMacs, yearMonthDayHour);
-                Double professionSum = historyHourlyService.getSensorSumByMacs(sensorCode, professionMacs, yearMonthDayHour);
-
-                //���������������������
-                String contributionRate = null;
-                NumberFormat numberFormat = NumberFormat.getInstance();
-                numberFormat.setMaximumFractionDigits(2);
-                if (professionSum != null && allDeviceSum != null) {
-                    contributionRate = numberFormat.format(professionSum / allDeviceSum * 100) + "%";
-                }
-
-                //������������
-                professionMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0));
-                //���������������
-                professionMap.put("contributionRate", contributionRate);
-
-                resultMap.put(profession, professionMap);
-            }
             result.add(resultMap);
+        }
+
+        for (String profession : professions) {
+            //���������������������
+            List<Device> professionDevices = getDevicesOfProfessions(orgId, Collections.singletonList(profession));
+            List<String> professionMacs = professionDevices.stream().map(Device::getMac).collect(Collectors.toList());
+
+
+            //���������������������������������
+            List<HistoryHourly> professionDeviceData = historyHourlyService.getValueByMacs(professionMacs, time);
+            //���time������
+            Map<String, List<HistoryHourly>> professionDataMap = professionDeviceData.stream()
+                    .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 13)));
+
+
+            for (Map<String, Object> map : result) {
+                Object allDeviceSum = map.remove("allDeviceSum");
+                String resultTime = map.get("time").toString();
+                List<HistoryHourly> historyHourlyList = professionDataMap.get(resultTime);
+                //���������
+                String contributionRate = null;
+                Double professionAvg = null;
+                if (!ObjectUtils.isEmpty(historyHourlyList)) {
+                    Supplier<Stream<HistoryHourly>> streamSupplier = historyHourlyList::stream;
+                    professionAvg = calculatedValueOfDay(streamSupplier, sensorCode, "avg");
+                    Double professionSum = calculatedValueOfDay(streamSupplier, sensorCode, "sum");
+                    //���������������������
+                    NumberFormat numberFormat = NumberFormat.getInstance();
+                    numberFormat.setMaximumFractionDigits(2);
+                    if (allDeviceSum != null) {
+                        contributionRate = numberFormat.format(professionSum / ((Double) allDeviceSum) * 100) + "%";
+                    }
+                }
+                Map<String, Object> professionMap = new HashMap<>();
+                professionMap.put("contributionRate", contributionRate);
+                professionMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0));
+                map.put(profession, professionMap);
+            }
         }
         return result;
     }
@@ -424,5 +517,75 @@
         return deviceService.listObjs(deviceQueryWrapper);
     }
 
+    //������������������������������
+    private Double calculatedValueOfDay(Supplier<Stream<HistoryHourly>> supplier, String sensorCode, String type) {
+        DoubleStream doubleStream = supplier.get()
+                .flatMapToDouble(v -> {
+                    Map<String, Object> dataValue = JSONObject.parseObject(v.getValue(), Map.class);
+                    Object sensorValue = dataValue.get(sensorCode);
+                    if (ObjectUtils.isEmpty(sensorValue)) {
+                        return null;
+                    }
+                    double aDouble = Double.parseDouble(sensorValue.toString());
+                    return DoubleStream.of(aDouble);
+                });
+        Double result = null;
+        if ("avg".equals(type)) {
+            OptionalDouble optionalDouble = doubleStream.average();
+            if (optionalDouble.isPresent()) {
+                result = optionalDouble.getAsDouble();
+            }
+        } else if ("sum".equals(type)) {
+            result = doubleStream.sum();
+        }
+        return result;
+    }
 
+    //������������������������������
+    private Double calculatedValueOfMonth(Supplier<Stream<HistoryDaily>> supplier, String sensorCode, String type) {
+        DoubleStream doubleStream = supplier.get()
+                .flatMapToDouble(v -> {
+                    Map<String, Object> dataValue = JSONObject.parseObject(v.getValue(), Map.class);
+                    Object sensorValue = dataValue.get(sensorCode);
+                    if (ObjectUtils.isEmpty(sensorValue)) {
+                        return null;
+                    }
+                    double aDouble = Double.parseDouble(sensorValue.toString());
+                    return DoubleStream.of(aDouble);
+                });
+        Double result = null;
+        if ("avg".equals(type)) {
+            OptionalDouble optionalDouble = doubleStream.average();
+            if (optionalDouble.isPresent()) {
+                result = optionalDouble.getAsDouble();
+            }
+        } else if ("sum".equals(type)) {
+            result = doubleStream.sum();
+        }
+        return result;
+    }
+
+    //������������������������������
+    private Double calculatedValueOfYear(Supplier<Stream<HistoryMonthly>> supplier, String sensorCode, String type) {
+        DoubleStream doubleStream = supplier.get()
+                .flatMapToDouble(v -> {
+                    Map<String, Object> dataValue = JSONObject.parseObject(v.getValue(), Map.class);
+                    Object sensorValue = dataValue.get(sensorCode);
+                    if (ObjectUtils.isEmpty(sensorValue)) {
+                        return null;
+                    }
+                    double aDouble = Double.parseDouble(sensorValue.toString());
+                    return DoubleStream.of(aDouble);
+                });
+        Double result = null;
+        if ("avg".equals(type)) {
+            OptionalDouble optionalDouble = doubleStream.average();
+            if (optionalDouble.isPresent()) {
+                result = optionalDouble.getAsDouble();
+            }
+        } else if ("sum".equals(type)) {
+            result = doubleStream.sum();
+        }
+        return result;
+    }
 }
diff --git a/screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml b/screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml
index 426f142..a392166 100644
--- a/screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml
+++ b/screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -14,24 +14,4 @@
         </foreach>
         and `time` = #{time}
     </select>
-
-    <select id="getSensorSumByMacs" resultType="java.lang.Double">
-        SELECT SUM(`value`->'$.${sensorCode}')
-        FROM history_hourly_${timeUnits}
-        WHERE `time` = #{time}
-        AND mac IN
-        <foreach collection="macs" item="mac" index="index" open="(" close=")" separator=",">
-            #{mac}
-        </foreach>
-    </select>
-
-    <select id="getSensorAvgByMacs" resultType="java.lang.Double">
-        SELECT AVG(`value`->'$.${sensorCode}')
-        FROM history_hourly_${timeUnits}
-        WHERE `time` = #{time}
-        AND mac IN
-        <foreach collection="macs" item="mac" index="index" open="(" close=")" separator=",">
-            #{mac}
-        </foreach>
-    </select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.8.0