jinpengyong
2021-12-27 c363540ce0469e6754329c1be5e56a63ec1d344f
行业贡献率
8 files modified
528 ■■■■ changed files
screen-api/src/main/java/com/moral/api/controller/ProfessionController.java 26 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java 3 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java 66 ●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/ProfessionService.java 4 ●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java 44 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/ProfessionServiceImpl.java 362 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/UserServiceImpl.java 3 ●●●● patch | view | raw | blame | history
screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml 20 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/ProfessionController.java
@@ -1,6 +1,8 @@
package com.moral.api.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -53,4 +55,28 @@
        Set<Map<String, Object>> response = professionService.getSensorByProfessionsAndOrganizationId(params);
        return ResultMessage.ok(response);
    }
    @ApiOperation(value = "行业贡献率", notes = "行业贡献率")
    @GetMapping("professionContribution")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "organizationId", value = "组织id", required = true, paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "profession", value = "行业key,多个逗号隔开", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "类型,月(2021-12),日(2021-12-24)", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time", value = "时间", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sensorCode", value = "传感器code", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage professionContribution(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (ObjectUtils.isEmpty(params.get("organizationId"))
                ||ObjectUtils.isEmpty(params.get("professions"))
                || ObjectUtils.isEmpty(params.get("type"))
                || ObjectUtils.isEmpty(params.get("time"))
                || ObjectUtils.isEmpty(params.get("sensorCode"))) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<Map<String, Object>> response = professionService.professionContribution(params);
        return ResultMessage.ok(response);
    }
}
screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java
@@ -21,4 +21,7 @@
    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);
}
screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java
@@ -14,54 +14,60 @@
 * @author moral
 * @since 2021-07-14
 */
public interface HistoryHourlyService{
public interface HistoryHourlyService {
    //根据mac获取小时AQI
    Map<String,Object> getHourlyAqiByMac(String mac);
    Map<String, Object> getHourlyAqiByMac(String mac);
    /**
     *@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
     **/
    Map<String, Object> getLastHourDataByOrgIdAndSensorCode(Map map);
    /**
      *@Description: 通过组织id和因子编码获取最近12小时数据层
      *@Param: [map]
      *@return: java.util.Map<java.lang.String,java.lang.Object>
      *@Author: lizijie
      *@Date: 2021/12/10 14:57
     * @Description: 通过组织id和因子编码获取最近12小时数据层
     * @Param: [map]
     * @return: java.util.Map<java.lang.String, java.lang.Object>
     * @Author: lizijie
     * @Date: 2021/12/10 14:57
     **/
    Map<String, Object> getLastTwelveHourDataByOrgIdAndSensorCode(Map map);
    /**
      *@Description: 通过组织id、因子编码和时间获取小时数据
      *@Param: [map]
      *@return: java.util.Map<java.lang.String,java.lang.Object>
      *@Author: lizijie
      *@Date: 2021/12/15 15:16
     * @Description: 通过组织id、因子编码和时间获取小时数据
     * @Param: [map]
     * @return: java.util.Map<java.lang.String, java.lang.Object>
     * @Author: lizijie
     * @Date: 2021/12/15 15:16
     **/
    Map<String, Object> getThermodynamicDiagramDataByOrgIdSensorCodeTime(Map<String, Object> map);
    /**
     *@Description: 通过组织id、因子编码和时间段获取小时数据
     *@Param: [map]
     *@return: java.util.Map<java.lang.String,java.lang.Object>
     *@Author: lizijie
     *@Date: 2021/12/16 15:16
     * @Description: 通过组织id、因子编码和时间段获取小时数据
     * @Param: [map]
     * @return: java.util.Map<java.lang.String, java.lang.Object>
     * @Author: lizijie
     * @Date: 2021/12/16 15:16
     **/
    List<Map<String, Object>> getThermodynamicDiagramDataByOrgIdSensorCodeTimeslot(Map<String, Object> map);
    /**
    * @Description: 根据mac和时间获取小时值
            * @Param: [mac, startDate, endDate]
            * @return: java.util.List<com.moral.api.entity.HistoryHourly>
            * @Author: 陈凯裕
            * @Date: 2021/9/28
            */
     * @Description: 根据mac和时间获取小时值
     * @Param: [mac, startDate, endDate]
     * @return: java.util.List<com.moral.api.entity.HistoryHourly>
     * @Author: 陈凯裕
     * @Date: 2021/9/28
     */
    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);
}
screen-api/src/main/java/com/moral/api/service/ProfessionService.java
@@ -1,5 +1,6 @@
package com.moral.api.service;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -10,4 +11,7 @@
    //根据组织和行业获取传感器列表
    Set<Map<String, Object>> getSensorByProfessionsAndOrganizationId(Map<String, Object> params);
    //行业贡献率
    List<Map<String, Object>> professionContribution(Map<String, Object> params);
}
screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
@@ -528,30 +528,42 @@
    }
    /**
    * @Description: 查询一段时间内某一mac的数据
            * @Param: [mac, startDate, endDate]
            * @return: java.util.List<com.moral.api.entity.HistoryHourly>
            * @Author: 陈凯裕
            * @Date: 2021/9/23
            */
     * @Description: 查询一段时间内某一mac的数据
     * @Param: [mac, startDate, endDate]
     * @return: java.util.List<com.moral.api.entity.HistoryHourly>
     * @Author: 陈凯裕
     * @Date: 2021/9/23
     */
    @Override
    public List<HistoryHourly> getValueByMacAndTime(String mac,Date startDate,Date endDate){
    public List<HistoryHourly> getValueByMacAndTime(String mac, Date startDate, Date endDate) {
        QueryWrapper<HistoryHourly> wrapper = new QueryWrapper<>();
        wrapper.eq("mac",mac);
        wrapper.between("time",startDate,endDate);
        wrapper.eq("mac", mac);
        wrapper.between("time", startDate, endDate);
        List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(startDate, endDate, SeparateTableType.MONTH);
        List<HistoryHourly> datas = multiTableQuery(wrapper, tableNames);
        return datas;
    }
    @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);
    }
    /**
    * @Description: 多表查询,传入表名集合,以及条件wrapper,返回数据
            * @Param: [wrapper, tableNames]
            * @return: java.util.List<com.moral.api.entity.HistoryHourly>
            * @Author: 陈凯裕
            * @Date: 2021/9/23
            */
    private List<HistoryHourly> multiTableQuery(QueryWrapper<HistoryHourly> wrapper,List<String> tableNames){
     * @Description: 多表查询,传入表名集合,以及条件wrapper,返回数据
     * @Param: [wrapper, tableNames]
     * @return: java.util.List<com.moral.api.entity.HistoryHourly>
     * @Author: 陈凯裕
     * @Date: 2021/9/23
     */
    private List<HistoryHourly> multiTableQuery(QueryWrapper<HistoryHourly> wrapper, List<String> tableNames) {
        List<HistoryHourly> result = new ArrayList<>();
        for (String tableName : tableNames) {
            MybatisPlusConfig.tableName.set(tableName);
screen-api/src/main/java/com/moral/api/service/impl/ProfessionServiceImpl.java
@@ -3,8 +3,12 @@
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.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -13,12 +17,28 @@
import java.util.stream.Collectors;
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.HistoryMonthly;
import com.moral.api.entity.Sensor;
import com.moral.api.service.CityAqiDailyService;
import com.moral.api.service.CityAqiMonthlyService;
import com.moral.api.service.CityAqiService;
import com.moral.api.service.DeviceService;
import com.moral.api.service.HistoryDailyService;
import com.moral.api.service.HistoryHourlyService;
import com.moral.api.service.HistoryMonthlyService;
import com.moral.api.service.OrganizationService;
import com.moral.api.service.ProfessionService;
import com.moral.constant.Constants;
import com.moral.constant.RedisConstants;
import com.moral.util.AmendUtils;
import com.moral.util.DateUtils;
/**
 * <p>
@@ -36,6 +56,38 @@
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private HistoryMonthlyService historyMonthlyService;
    @Autowired
    private HistoryDailyService historyDailyService;
    @Autowired
    private HistoryHourlyService historyHourlyService;
    @Autowired
    private CityAqiMonthlyService cityAqiMonthlyService;
    @Autowired
    private CityAqiDailyService cityAqiDailyService;
    @Autowired
    private CityAqiService cityAqiService;
    @Autowired
    private OrganizationService organizationService;
    private static Map<String, String> senorMap = new HashMap<>();
    static {
        senorMap.put(Constants.SENSOR_CODE_PM25, "PM2_5");
        senorMap.put(Constants.SENSOR_CODE_PM10, "PM10");
        senorMap.put(Constants.SENSOR_CODE_SO2, "SO2");
        senorMap.put(Constants.SENSOR_CODE_NO2, "NO2");
        senorMap.put(Constants.SENSOR_CODE_CO, "CO");
        senorMap.put(Constants.SENSOR_CODE_O3, "O3");
    }
    @Override
    public Set<Map<String, Object>> getProfessionsByOrganizationId(Integer organizationId) {
@@ -55,6 +107,22 @@
        //获取属于该行业所有设备
        Integer orgId = Integer.parseInt(params.get("organizationId").toString());
        List<String> professions = Arrays.asList(params.get("professions").toString().split(","));
        List<Device> devices = getDevicesOfProfessions(orgId, professions);
        //从redis获取设备详细信息
        for (Device device : devices) {
            device = (Device) redisTemplate.opsForHash().get(RedisConstants.DEVICE_INFO, device.getMac());
            List<Sensor> sensors = device.getVersion().getSensors();
            for (Sensor sensor : sensors) {
                Map<String, Object> sensorMap = new HashMap<>();
                sensorMap.put("sensorCode", sensor.getCode());
                sensorMap.put("sensorName", sensor.getName());
                result.add(sensorMap);
            }
        }
        return result;
    }
    private List<Device> getDevicesOfProfessions(Integer orgId, List<String> professions) {
        QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("mac", "profession")
                .eq("organization_id", orgId)
@@ -69,18 +137,292 @@
            }
            return false;
        }).collect(Collectors.toList());
        return devices;
    }
        //从redis获取设备详细信息
        for (Device device : devices) {
            device = (Device) redisTemplate.opsForHash().get(RedisConstants.DEVICE_INFO, device.getMac());
            List<Sensor> sensors = device.getVersion().getSensors();
            for (Sensor sensor : sensors) {
                Map<String, Object> sensorMap = new HashMap<>();
                sensorMap.put("sensorCode", sensor.getCode());
                sensorMap.put("sensorName", sensor.getName());
                result.add(sensorMap);
            }
    @Override
    public List<Map<String, Object>> professionContribution(Map<String, Object> params) {
        int orgId = Integer.parseInt(params.get("organizationId").toString());
        List<String> professions = Arrays.asList(params.get("professions").toString().split(","));
        String type = params.get("type").toString();
        String time = params.get("time").toString();
        String sensorCode = params.get("sensorCode").toString();
        List<Map<String, Object>> result = new ArrayList<>();
        switch (type) {
            case "year":
                result = professionContributionOfYear(orgId, professions, time, sensorCode);
                break;
            case "month":
                result = professionContributionOfMonth(orgId, professions, time, sensorCode);
                break;
            case "day":
                result = professionContributionOfDay(orgId, professions, time, sensorCode);
                break;
            default:
                break;
        }
        return result;
    }
    //贡献率,年
    private List<Map<String, Object>> professionContributionOfYear(Integer orgId, List<String> professions, String time, String sensorCode) {
        List<Map<String, Object>> result = new ArrayList<>();
        //该组织所有设备信息
        List allMacs = getMacsByOrgId(orgId);
        List<String> timeLag = DateUtils.getTimeLag(time);
        for (String yearMonth : timeLag) {
            Map<String, Object> resultMap = new HashMap<>();
            resultMap.put("time", yearMonth.split("-")[1]);
            yearMonth = yearMonth + "-01 00:00:00";
            //所有设备该因子累加值
            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");
            }
            //本市数据
            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");
            }
            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);
        }
        return result;
    }
    //贡献率,月
    private List<Map<String, Object>> professionContributionOfMonth(Integer orgId, List<String> professions, String time, String sensorCode) {
        List<Map<String, Object>> result = new ArrayList<>();
        //该组织所有设备信息
        List allMacs = getMacsByOrgId(orgId);
        List<String> timeLag = DateUtils.getTimeLag(time);
        for (String yearMonthDay : timeLag) {
            Map<String, Object> resultMap = new HashMap<>();
            resultMap.put("time", yearMonthDay.split("-")[2]);
            yearMonthDay = yearMonthDay + " 00:00:00";
            //所有设备该因子累加值
            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");
            }
            //本市数据
            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");
            }
            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);
        }
        return result;
    }
    private List<Map<String, Object>> professionContributionOfDay(Integer orgId, List<String> professions, String time, String sensorCode) {
        List<Map<String, Object>> result = new ArrayList<>();
        //该组织所有设备信息
        List allMacs = getMacsByOrgId(orgId);
        List<String> timeLag = DateUtils.getTimeLag(time);
        for (String yearMonthDayHour : timeLag) {
            Map<String, Object> resultMap = new HashMap<>();
            resultMap.put("time", yearMonthDayHour.split(" ")[1]);
            yearMonthDayHour = yearMonthDayHour + ":00:00";
            //所有设备该因子累加值
            Double allDeviceSum = historyHourlyService.getSensorSumByMacs(sensorCode, allMacs, yearMonthDayHour);
            //本市数据
            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");
            }
            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);
        }
        return result;
    }
    //根据组织id获取设备macs
    private List getMacsByOrgId(Integer orgId) {
        //该组织所有设备信息
        QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
        deviceQueryWrapper.select("mac")
                .eq("organization_id", orgId)
                .eq("is_delete", Constants.NOT_DELETE);
        return deviceService.listObjs(deviceQueryWrapper);
    }
}
screen-api/src/main/java/com/moral/api/service/impl/UserServiceImpl.java
@@ -119,7 +119,7 @@
        //封装用户信息
        Map<String, Object> userInfo = new LinkedHashMap<>();
        //用户in西
        //用户信息
        userInfo.put("userId", userBo.getId());
        userInfo.put("account", userBo.getAccount());
        userInfo.put("userName", userBo.getUserName());
@@ -219,6 +219,7 @@
        //筛选出下一级菜单信息
        List<Menu> nextLevelMenus = menus.stream()
                .filter(o -> o.getParentId().equals(menu.getId()))
                .sorted(Comparator.comparing(Menu::getOrder))
                .collect(Collectors.toList());
        List<Map<String, Object>> list = new ArrayList<>();
        if (nextLevelMenus.size() > 0) {
screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -14,4 +14,24 @@
        </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>