cjl
2024-04-23 65b70cf13a2ec91013d876771be878c165cae3a4
screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java
@@ -1,17 +1,17 @@
package com.moral.api.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.moral.api.config.Interceptor.UserHelper;
import com.moral.api.dto.MonitoringStationDTO;
import com.moral.api.entity.*;
import com.moral.api.mapper.DeviceMapper;
import com.moral.api.mapper.HistoryMonthlyMapper;
import com.moral.api.mapper.MonitorPointMapper;
import com.moral.api.mapper.SensorMapper;
import com.moral.api.pojo.form.device.MonitorPointQueryForm;
import com.moral.api.pojo.vo.user.QxUser;
import com.moral.api.service.DeviceService;
import com.moral.api.service.HistoryDailyService;
import com.moral.api.service.HistoryHourlyService;
@@ -20,14 +20,16 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.service.OrganizationService;
import com.moral.constant.Constants;
import com.moral.util.ComprehensiveIndexUtils;
import com.moral.util.DateUtils;
import com.moral.util.RegionCodeUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import springfox.documentation.schema.Entry;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.util.*;
import java.util.stream.Collectors;
@@ -79,18 +81,19 @@
//            region = RegionCodeUtils.regionCodeConvertToName(regionCode);
//        }
        //查询子组织
       /* //查询子组织
        List<Organization> childrenOrganization = organizationService.getChildrenOrganizationsById(organizationId);
        List<Integer> organizationIds = new ArrayList<>();
        for (Organization organization : childrenOrganization) {
            organizationIds.add(organization.getId());
        }
        organizationIds.add(organizationId);
        organizationIds.add(organizationId);*/
        //查询站点
        QueryWrapper<MonitorPoint> queryMonitorPointsWrapper = new QueryWrapper<>();
        //如果region不为空,就查询当前组织,所选城市下所有站点及设备信息
        //如果region为空,则查询当前组织下所有的站点和设备
        List<Integer> organizationIds = deviceMapper.deviceOrgIdList(organizationId);
        if (region != null){
            queryMonitorPointsWrapper.eq(region, regionCode);
        }
@@ -266,7 +269,7 @@
                        if(map.containsKey(k)){
                            Object o = map.get(k).get(sensor);
                            timeValueMap.put(c,Objects.nonNull(o)?Double.valueOf(o.toString()):0);
                            if(Objects.nonNull(o)){
                            if(Objects.nonNull(o)&& (!Double.valueOf(o.toString()).equals(0d))){
                                doubleArrayList.add(Double.valueOf(o.toString()));
                            }
                        }else {
@@ -395,7 +398,7 @@
                        if(map.containsKey(k)){
                            Object o = map.get(k).get(sensor);
                            num = Objects.nonNull(o)?Double.valueOf(o.toString()):0d;
                            if(Objects.nonNull(num)){
                            if(Objects.nonNull(num)&& !num.equals(0d)){
                                ArrayList<Double> doubleArrayList = Objects.isNull(listMap.get(numCount+"_"+sensorMap.get(sensor)))?new ArrayList<>():listMap.get(numCount+"_"+sensorMap.get(sensor));
                                doubleArrayList.add(num);
                                listMap.put(numCount+"_"+sensorMap.get(sensor),doubleArrayList);
@@ -414,8 +417,14 @@
                    double rsAvg = 0L;
                    String son = numCount+"_"+sensorMap.get(sensorsList.get(z));
                    if(listMap.containsKey(numCount+"_"+sensorMap.get(sensorsList.get(z)))){
                        Double ListAvg = listMap.get(numCount+"_"+sensorMap.get(sensorsList.get(z))).stream().collect(Collectors.averagingDouble(Double::doubleValue));
                        rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
                        if(son.contains("臭氧")){
                            rsAvg = percentile(listMap.get(numCount+"_"+sensorMap.get(sensorsList.get(z))),90d);
                        }else if(son.contains("一氧化碳")){
                            rsAvg = percentile(listMap.get(numCount+"_"+sensorMap.get(sensorsList.get(z))),95d);
                        }else {
                            Double ListAvg = listMap.get(numCount+"_"+sensorMap.get(sensorsList.get(z))).stream().collect(Collectors.averagingDouble(Double::doubleValue));
                            rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
                        }
                    }
                    timeValueMap.put(sensorMap.get(sensorsList.get(z)),rsAvg);
                }
@@ -476,9 +485,351 @@
        }
        return resultList;
    }
    @Override
    public List<MonitoringStationDTO> listMonitoringStationDTO(Map<String, Object> params, int reportType, String startTime, String endTime) {
       // List<String> macs = Arrays.asList(mac.split(","));
        List<String> macs = (List<String>) params.remove("mac");
        List<MonitoringStationDTO> resultList = new ArrayList<>();
        if(reportType == 1||reportType == 4){
            Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_EN);
            Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_EN);
            List<HistoryDaily> historyDailyByMacAndTimeSlot = historyDailyService.getHistoryDailyByMacAndTimeSlot(macs, startDate, endDate);
            resultList = resultList(historyDailyByMacAndTimeSlot);
        }else if(reportType == 2){
            Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_EN);
            Date endDate = DateUtils.addDays(startDate,6);
            List<HistoryDaily> historyDailyByMacAndTimeSlot = historyDailyService.getHistoryDailyByMacAndTimeSlot(macs, startDate, endDate);
            resultList = resultList(historyDailyByMacAndTimeSlot);
        }else if(reportType == 3){
            Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_EN);
            Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_EN);
            QueryWrapper<HistoryMonthly> HistoryMonthlyWrapper = new QueryWrapper<>();
            HistoryMonthlyWrapper.in("mac",macs);
            HistoryMonthlyWrapper.between("time",startDate,endDate);
            List<HistoryMonthly> historyMonthlyList = historyMonthlyMapper.selectList(HistoryMonthlyWrapper);
            List<HistoryDaily> historyDailies = new ArrayList<>();
            for(HistoryMonthly h : historyMonthlyList) {
                HistoryDaily historyDaily = new HistoryDaily();
                historyDaily.setMac(h.getMac());
                historyDaily.setTime(h.getTime());
                historyDaily.setValue(h.getValue());
                historyDailies.add(historyDaily);
            }
            resultList = resultList(historyDailies);
        }
        return resultList;
    }
    /**
     * 根据用户查询站点
     *
     * @return
     */
    @Override
    public List<MonitorPoint> getOrganizations() {
        QueryWrapper<MonitorPoint> wrapper = new QueryWrapper<>();
        wrapper.select("id","name");
        QxUser user = UserHelper.getCurrentUser();
        Integer organizationId = user.getOrganizationId();
        List<Integer> monitorPointiIds = monitorPointMapper.getMonitorPointiId(organizationId);
        if (organizationId!=24){
            wrapper.in("id",monitorPointiIds);
        }
        wrapper.eq("is_delete",Constants.NOT_DELETE);
        List<MonitorPoint> monitorPoints = monitorPointMapper.selectList(wrapper);
        for (int i = 0; i < monitorPoints.size(); i++) {
            List<Device> organizationDevice = deviceService.getOrganizationDevice(monitorPoints.get(i).getId());
            if (ObjectUtils.isEmpty(organizationDevice)){
                monitorPoints.remove(i);
                i--;
            }
        }
        return monitorPoints;
    }
    private Map<String,Map<String,Object>> resultMap(List<HistoryDaily> list ,List<HistoryMonthly> historyMonthlyList){
    private List<MonitoringStationDTO> resultList(List<HistoryDaily> historyDailyByMacAndTimeSlot){
        List<MonitoringStationDTO> list = new ArrayList<>();
        if(CollectionUtils.isEmpty(historyDailyByMacAndTimeSlot)){
            return list;
        }
        //海城分组均值  海州 p5dnd7a0000001 -响堂 p5dnd7a0000002 -兴海 p5dnd7a0000003
        List<String> hzRoad = Arrays.asList("p5dnd7a0245491","p5dnd7a0392159","p5dnd7a0243605","p5dnd7a0392176");
        List<String> xtRoad = Arrays.asList("p5dnd7a0243603","p5dnd7a0391986","p5dnd7a0392003","p5dnd7a0392144","p5dnd7a0392167","p5dnd7a0391990");
        List<String> xhRoad = Arrays.asList("p5dnd7a0392158","p5dnd7a0392173","p5dnd7a0391975","p5dnd7a0392153","p5dnd7a0391961","p5dnd7a0243608","p5dnd7a0243618");
        List<HistoryDaily> hcHz= new ArrayList<>();
        List<HistoryDaily> xtHz= new ArrayList<>();
        List<HistoryDaily> xhHz= new ArrayList<>();
        for(HistoryDaily h : historyDailyByMacAndTimeSlot) {
            HistoryDaily historyDaily = new HistoryDaily();
            historyDaily.setTime( h.getTime());
            historyDaily.setValue(h.getValue());
            if(hzRoad.contains(h.getMac())){
                historyDaily.setMac("p5dnd7a0000001");
                hcHz.add(historyDaily);
            }else if(xtRoad.contains(h.getMac())){
                historyDaily.setMac("p5dnd7a0000002");
                xtHz.add(historyDaily);
            }else if(xhRoad.contains(h.getMac())){
                historyDaily.setMac("p5dnd7a0000003");
                xhHz.add(historyDaily);
            }
        }
        if(CollectionUtils.isNotEmpty(hcHz)){
            historyDailyByMacAndTimeSlot.addAll(hcHz);
        }
        if(CollectionUtils.isNotEmpty(xtHz)){
            historyDailyByMacAndTimeSlot.addAll(xtHz);
        }
        if(CollectionUtils.isNotEmpty(xhHz)){
            historyDailyByMacAndTimeSlot.addAll(xhHz);
        }
        Map<String,Map<String,ArrayList<Double>>> resultMap = new HashMap<>();
        for(HistoryDaily h : historyDailyByMacAndTimeSlot) {
            JSONObject jsonObject = JSONObject.parseObject(h.getValue());
            Map<String, Object> map = jsonObject.getInnerMap();
            Map<String,ArrayList<Double>> maps = Objects.nonNull(resultMap.get(h.getMac()))?resultMap.get(h.getMac()):new HashMap<>();
            if(Objects.nonNull(map.get("a34004"))){
                ArrayList<Double> numResult = Objects.nonNull(maps.get("PM2_5"))?maps.get("PM2_5"):new ArrayList<>();
                numResult.add(Double.parseDouble(map.get("a34004").toString()));
                maps.put("PM2_5",numResult);
            }
            if(Objects.nonNull(map.get("a05024"))){
                ArrayList<Double> numResult = Objects.nonNull(maps.get("O3"))?maps.get("O3"):new ArrayList<>();
                numResult.add(Double.parseDouble(map.get("a05024").toString()));
                maps.put("O3",numResult);
            }
            if(Objects.nonNull(map.get("a34002"))){
                ArrayList<Double> numResult = Objects.nonNull(maps.get("PM10"))?maps.get("PM10"):new ArrayList<>();
                numResult.add(Double.parseDouble(map.get("a34002").toString()));
                maps.put("PM10",numResult);
            }
            if(Objects.nonNull(map.get("a21026"))){
                ArrayList<Double> numResult = Objects.nonNull(maps.get("SO2"))?maps.get("SO2"):new ArrayList<>();
                numResult.add(Double.parseDouble(map.get("a21026").toString()));
                maps.put("SO2",numResult);
            }
            if(Objects.nonNull(map.get("a21004"))){
                ArrayList<Double> numResult = Objects.nonNull(maps.get("NO2"))?maps.get("NO2"):new ArrayList<>();
                numResult.add(Double.parseDouble(map.get("a21004").toString()));
                maps.put("NO2",numResult);
            }
            if(Objects.nonNull(map.get("a21005"))){
                ArrayList<Double> numResult = Objects.nonNull(maps.get("CO"))?maps.get("CO"):new ArrayList<>();
                numResult.add(Double.parseDouble(map.get("a21005").toString()));
                maps.put("CO",numResult);
            }
            if(Objects.nonNull(map.get("a99054"))){
                ArrayList<Double> numResult = Objects.nonNull(maps.get("TVOC"))?maps.get("TVOC"):new ArrayList<>();
                numResult.add(Double.parseDouble(map.get("a99054").toString()));
                maps.put("TVOC",numResult);
            }
            resultMap.put(h.getMac(),maps);
        }
        for(Map.Entry entry : resultMap.entrySet()){
            boolean dimension = false;
            String mapKey = (String) entry.getKey();
            Map<String,ArrayList<Double>> mapValue = (Map<String,ArrayList<Double>>)entry.getValue();
            Map<String, Object> data = new HashMap<>();
            if(mapValue.containsKey("PM2_5")){
                Double ListAvg = mapValue.get("PM2_5").stream().collect(Collectors.averagingDouble(Double::doubleValue));
                double rsAvg = new BigDecimal(ListAvg).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                data.put("PM2_5",rsAvg);
            }else {
                data.put("PM2_5",0);
                dimension = true;
            }
            if(mapValue.containsKey("PM10")){
                Double ListAvg = mapValue.get("PM10").stream().collect(Collectors.averagingDouble(Double::doubleValue));
                double rsAvg = new BigDecimal(ListAvg).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
                data.put("PM10",rsAvg);
            }else {
                data.put("PM10",0);
                dimension = true;
            }
            if(mapValue.containsKey("SO2")){
                Double ListAvg = mapValue.get("SO2").stream().collect(Collectors.averagingDouble(Double::doubleValue));
                double rsAvg = new BigDecimal(ListAvg).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
                data.put("SO2",rsAvg);
            }else {
                data.put("SO2",0);
                dimension = true;
            }
            if(mapValue.containsKey("NO2")){
                Double ListAvg = mapValue.get("NO2").stream().collect(Collectors.averagingDouble(Double::doubleValue));
                double rsAvg = new BigDecimal(ListAvg).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
                data.put("NO2",rsAvg);
            }else {
                data.put("NO2",0);
                dimension = true;
            }
            if(mapValue.containsKey("CO")){
                Double ListAvg = percentile(mapValue.get("CO"),95d);
                double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
                data.put("CO",rsAvg);
            }else {
                data.put("CO",0);
                dimension = true;
            }
            if(mapValue.containsKey("O3")){
                Double ListAvg = percentile(mapValue.get("O3"),90d);
                double rsAvg = new BigDecimal(ListAvg).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
                data.put("O3",rsAvg);
            }else {
                data.put("O3",0);
                dimension = true;
            }
            if(mapValue.containsKey("TVOC")){
                Double ListAvg = mapValue.get("TVOC").stream().collect(Collectors.averagingDouble(Double::doubleValue));
                double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
                data.put("TVOC",rsAvg);
            }else {
                data.put("TVOC",0);
                dimension = true;
            }
            Double resultNum = ComprehensiveIndexUtils.dailyData(data);
            if(dimension){
                resultNum = 0d;
            }
            MonitoringStationDTO monitoringStationDTO = new MonitoringStationDTO();
            monitoringStationDTO.setPM25(BigDecimal.valueOf(Double.parseDouble(data.get("PM2_5").toString())));
            monitoringStationDTO.setO3(BigDecimal.valueOf(Double.parseDouble(data.get("O3").toString())));
            monitoringStationDTO.setTovc(BigDecimal.valueOf(Double.parseDouble(data.get("TVOC").toString())));
            monitoringStationDTO.setComposite(BigDecimal.valueOf(resultNum));
            monitoringStationDTO.setSO2(BigDecimal.valueOf(Double.parseDouble(data.get("SO2").toString())));
            monitoringStationDTO.setNO2(BigDecimal.valueOf(Double.parseDouble(data.get("NO2").toString())));
            monitoringStationDTO.setPM10(BigDecimal.valueOf(Double.parseDouble(data.get("PM10").toString())));
            monitoringStationDTO.setCO(BigDecimal.valueOf(Double.parseDouble(data.get("CO").toString())));
            monitoringStationDTO.setMac(mapKey);
            list.add(monitoringStationDTO);
        }
        List<MonitoringStationDTO> compositeListResult = fun3(list,0);
        List<MonitoringStationDTO> compositeList = fun3(list,1);
        List<MonitoringStationDTO> pM25List = fun3(list,2);
        List<MonitoringStationDTO> o3List = fun3(list,3);
        List<MonitoringStationDTO> tovcList = fun3(list,4);
        List<MonitoringStationDTO> SO2List = fun3(list,5);
        List<MonitoringStationDTO> NO2cList = fun3(list,6);
        List<MonitoringStationDTO> PM10List = fun3(list,7);
        List<MonitoringStationDTO> COList = fun3(list,8);
        List<MonitoringStationDTO> resultList = new ArrayList<>();
        LambdaQueryChainWrapper<Device> wrapper = deviceService.lambdaQuery();
        wrapper.eq(Device::getIsDelete,0);
        Map<String,String> deviceMap =  new HashMap<>();
        wrapper.list().forEach(it->deviceMap.put(it.getMac(),it.getName()));
        deviceMap.put("p5dnd7a0000001","海州街道均值");
        deviceMap.put("p5dnd7a0000002","响堂街道均值");
        deviceMap.put("p5dnd7a0000003","兴海街道均值");
        for (MonitoringStationDTO m :compositeListResult ){
            MonitoringStationDTO monit = new MonitoringStationDTO();
            String mac = m.getMac();
            monit.setMac(mac);
            monit.setName(deviceMap.get(mac));
            List<String> listComposite = compositeList.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
            monit.setComposite(listComposite.indexOf(mac) == -1?BigDecimal.ZERO:compositeList.get(listComposite.indexOf(mac)).getComposite());
            monit.setCompositeNum(listComposite.indexOf(mac) == -1?0:compositeList.get(listComposite.indexOf(mac)).getCompositeNum());
            List<String> listPM25 = pM25List.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
            List<String> listO3 = o3List.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
            List<String> listTovc = tovcList.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
            monit.setO3(listO3.indexOf(mac) == -1?BigDecimal.ZERO:o3List.get(listO3.indexOf(mac)).getO3());
            monit.setO3Num(listO3.indexOf(mac) == -1?0:o3List.get(listO3.indexOf(mac)).getO3Num());
            monit.setPM25(listPM25.indexOf(mac) == -1?BigDecimal.ZERO:pM25List.get(listPM25.indexOf(mac)).getPM25());
            monit.setPM25Num(listPM25.indexOf(mac) == -1?0:pM25List.get(listPM25.indexOf(mac)).getPM25Num());
            monit.setTovc(listTovc.indexOf(mac) == -1?BigDecimal.ZERO:tovcList.get(listTovc.indexOf(mac)).getTovc());
            monit.setTOVCNum(listTovc.indexOf(mac) == -1?0:tovcList.get(listTovc.indexOf(mac)).getTOVCNum());
            List<String> listSO2 = SO2List.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
            monit.setSO2(listSO2.indexOf(mac) == -1?BigDecimal.ZERO:SO2List.get(listSO2.indexOf(mac)).getSO2());
            monit.setSO2Num(listSO2.indexOf(mac) == -1?0:SO2List.get(listSO2.indexOf(mac)).getSO2Num());
            List<String> listNO2 = NO2cList.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
            monit.setNO2(listNO2.indexOf(mac) == -1?BigDecimal.ZERO:NO2cList.get(listNO2.indexOf(mac)).getNO2());
            monit.setNO2Num(listNO2.indexOf(mac) == -1?0:NO2cList.get(listNO2.indexOf(mac)).getNO2Num());
            List<String> listPM10 = PM10List.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
            monit.setPM10(listPM10.indexOf(mac) == -1?BigDecimal.ZERO:PM10List.get(listPM10.indexOf(mac)).getPM10());
            monit.setPM10Num(listPM10.indexOf(mac) == -1?0:PM10List.get(listPM10.indexOf(mac)).getPM10Num());
            List<String> listCO = COList.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
            monit.setCO(listCO.indexOf(mac) == -1?BigDecimal.ZERO:COList.get(listCO.indexOf(mac)).getCO());
            monit.setCONum(listCO.indexOf(mac) == -1?0:COList.get(listCO.indexOf(mac)).getCONum());
            resultList.add(monit);
        }
        return resultList;
    }
    public List<MonitoringStationDTO> fun3(List<MonitoringStationDTO> monList,int type) {
        List<MonitoringStationDTO> resultList = new ArrayList<>();
        List<MonitoringStationDTO> compositeList = new ArrayList<>();
        Map<BigDecimal,List<MonitoringStationDTO>> map1 = new HashMap<>();
        if(type == 1){
            compositeList = monList.stream().filter(it->it.getComposite().compareTo(BigDecimal.ZERO)!=0).sorted(Comparator.comparing(MonitoringStationDTO::getComposite)).collect(Collectors.toList());
            map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getComposite,LinkedHashMap::new,Collectors.toList()));
        }else if(type == 0){
            compositeList = monList.stream().sorted(Comparator.comparing(MonitoringStationDTO::getComposite)).collect(Collectors.toList());
            map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getComposite,LinkedHashMap::new,Collectors.toList()));
        }else if(type == 2){
            compositeList = monList.stream().filter(it->it.getPM25().compareTo(BigDecimal.ZERO)!=0).sorted(Comparator.comparing(MonitoringStationDTO::getPM25)).collect(Collectors.toList());
            map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getPM25,LinkedHashMap::new,Collectors.toList()));
        }else if(type == 3){
            compositeList = monList.stream().filter(it->it.getO3().compareTo(BigDecimal.ZERO)!=0).sorted(Comparator.comparing(MonitoringStationDTO::getO3)).collect(Collectors.toList());
            map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getO3,LinkedHashMap::new,Collectors.toList()));
        }else if(type == 4){
            compositeList = monList.stream().filter(it->it.getTovc().compareTo(BigDecimal.ZERO)!=0).sorted(Comparator.comparing(MonitoringStationDTO::getTovc)).collect(Collectors.toList());
            map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getTovc,LinkedHashMap::new,Collectors.toList()));
        }else if(type == 5){
            compositeList = monList.stream().filter(it->it.getSO2().compareTo(BigDecimal.ZERO)!=0).sorted(Comparator.comparing(MonitoringStationDTO::getSO2)).collect(Collectors.toList());
            map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getSO2,LinkedHashMap::new,Collectors.toList()));
        }else if(type == 6){
            compositeList = monList.stream().filter(it->it.getNO2().compareTo(BigDecimal.ZERO)!=0).sorted(Comparator.comparing(MonitoringStationDTO::getNO2)).collect(Collectors.toList());
            map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getNO2,LinkedHashMap::new,Collectors.toList()));
        }else if(type == 7){
            compositeList = monList.stream().filter(it->it.getPM10().compareTo(BigDecimal.ZERO)!=0).sorted(Comparator.comparing(MonitoringStationDTO::getPM10)).collect(Collectors.toList());
            map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getPM10,LinkedHashMap::new,Collectors.toList()));
        }else if(type == 8){
            compositeList = monList.stream().filter(it->it.getCO().compareTo(BigDecimal.ZERO)!=0).sorted(Comparator.comparing(MonitoringStationDTO::getCO)).collect(Collectors.toList());
            map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getCO,LinkedHashMap::new,Collectors.toList()));
        }
        int index = 1;
        for (Map.Entry entry : map1.entrySet()) {
            List<MonitoringStationDTO> mapValue = (List<MonitoringStationDTO>)entry.getValue();
            for(MonitoringStationDTO m : mapValue){
                MonitoringStationDTO stationDTO = new MonitoringStationDTO();
                stationDTO.setMac(m.getMac());
                if(type == 1){
                    stationDTO.setComposite(m.getComposite());
                    stationDTO.setCompositeNum(index);
                }else if(type == 0){
                    stationDTO.setComposite(m.getComposite());
                    stationDTO.setCompositeNum(index);
                }else if(type == 2){
                    stationDTO.setPM25(m.getPM25());
                    stationDTO.setPM25Num(index);
                }else if(type == 3){
                    stationDTO.setO3(m.getO3());
                    stationDTO.setO3Num(index);
                }else if(type == 4){
                    stationDTO.setTovc(m.getTovc());
                    stationDTO.setTOVCNum(index);
                }else if(type == 5){
                    stationDTO.setSO2(m.getSO2());
                    stationDTO.setSO2Num(index);
                }else if(type == 6){
                    stationDTO.setNO2(m.getNO2());
                    stationDTO.setNO2Num(index);
                }else if(type == 7){
                    stationDTO.setPM10(m.getPM10());
                    stationDTO.setPM10Num(index);
                }else if(type == 8){
                    stationDTO.setCO(m.getCO());
                    stationDTO.setCONum(index);
                }
                resultList.add(stationDTO);
            }
            index = index +mapValue.size();
        }
        return resultList;
    }
    private Map<String,Map<String,Object>> resultMap(List<HistoryDaily> list , List<HistoryMonthly> historyMonthlyList){
        Map<String,Map<String,Object>> map = new HashMap<>();
        for(HistoryDaily h : list){
            String dateStr = DateUtils.dateToDateString( h.getTime(), "yyyy-MM-dd")+"_"+h.getMac();
@@ -526,6 +877,21 @@
        monitorPointMapper.selectList(monitorPointQueryWrapper).forEach(it->map.put(it.getId(),it.getName()));
        return map;
    }
    private Double percentile(List<Double> date,double num){
        if(CollectionUtils.isNotEmpty(date)&&date.size() == 1){
            return date.get(0);
        }
        Collections.sort(date);
        double position = (num / 100) * (date.size() - 1);
        int index = (int) position;
        // 获取小数部分的位置索引
        double fraction = position - index;
        // 获取百分位值
        double percentileValue = date.get(index) + fraction * (date.get(index + 1) - date.get(index));
        return new BigDecimal(percentileValue).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
}