cjl
2023-09-27 dc1c8c974d9469591ead4dd1d774bbfb97a33331
screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java
@@ -2,12 +2,10 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.ISqlSegment;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.conditions.segments.NormalSegmentList;
import com.moral.api.config.mybatis.MybatisPlusConfig;
import com.moral.api.entity.*;
import com.moral.api.mapper.DeviceMapper;
import com.moral.api.mapper.HistoryFiveMinutelyMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.mapper.HistoryHourlyMapper;
@@ -24,6 +22,7 @@
import com.moral.constant.SeparateTableType;
import com.moral.util.DateUtils;
import com.moral.util.MybatisPLUSUtils;
import com.moral.util.RegionCodeUtils;
import io.lettuce.core.GeoCoordinates;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,8 +31,6 @@
import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
 * <p>
@@ -58,15 +55,30 @@
    HistoryHourlyMapper historyHourlyMapper;
    @Autowired
    DeviceService deviceService;
    @Autowired
    DeviceMapper deviceMapper;
    @Override
    public List<DeviceAndFiveMinuteDataDTO> queryDeviceAndFiveMinuteData(QueryDeviceAndFiveMinuteDataForm form) {
    public List<Map<String, Object>> queryDeviceAndFiveMinuteData(QueryDeviceAndFiveMinuteDataForm form) {
        //取参
        String times = DateUtils.dateToDateString(new Date(),DateUtils.yyyyMM_EN);
        Integer organizationId = form.getOrganizationId();
        Integer regionCode = form.getRegionCode();
        String sensorCode = form.getSensorCode();
        String type = "$."+ sensorCode;
        String region = null;
        String endHourlyTime = null;
        if (regionCode != null && organizationId!=24) {
            region = RegionCodeUtils.regionCodeConvertToName(regionCode);
        }
        if (form.getChooseTime().equals("true")) {
            endHourlyTime = form.getTime();
            Date time = DateUtils.convertDate(endHourlyTime);
            times = DateUtils.dateToDateString(time,DateUtils.yyyyMM_EN);
        }
        List<Map<String, Object>> listAll = deviceMapper.deviceList(organizationId,regionCode,region,type,sensorCode,times,endHourlyTime);
        //查询组织在对应地区下的站点以及设备
        List<MonitorPoint> monitorPoints = monitorPointService.queryByOrgIdAndRegionCode(new MonitorPointQueryForm(organizationId, regionCode));
        /*List<MonitorPoint> monitorPoints = monitorPointService.queryByOrgIdAndRegionCode(new MonitorPointQueryForm(organizationId, regionCode));
        List<Device> devices = new ArrayList<>();
        for (MonitorPoint monitorPoint : monitorPoints) {
            List<Device> monitorPointDevices = monitorPoint.getDevices();
@@ -78,8 +90,9 @@
                }
            }
        }
        }*/
        //查询所有设备对应的数据
        /*List<Device> devices = new ArrayList<>();
        List<DeviceAndFiveMinuteDataDTO> dtos = new ArrayList<>();
        if (form.getChooseTime().equals("true")) {
            String time = form.getTime();
@@ -101,10 +114,12 @@
            }
            return dtos;
        }
        //List<Map<String, Object>> sensorValuess = (List<Map<String, Object>>) redisTemplate.opsForValue().multiGet(Arrays.asList("data_five_minutes:p5dnd7a0245400","data_five_minutes:p5dnd7a0245412"));
        for (Device device : devices) {
            DeviceAndFiveMinuteDataDTO dto = new DeviceAndFiveMinuteDataDTO();
            String mac = device.getMac();
            Map<String, Object> sensorValues = queryLastDataByMac(mac);
            String dbDataStr = JSON.toJSONString(sensorValues);
            sensorValues = JSON.parseObject(dbDataStr, HashMap.class);
            Map<String, Object> sensorValue = new HashMap<>();
@@ -115,8 +130,8 @@
            dto.setDevice(device);
            dto.setSensorValue(sensorValue);
            dtos.add(dto);
        }
        return dtos;
        }*/
        return listAll;
    }
    @Override
@@ -186,6 +201,9 @@
            datas.put("dataTime", time);
        } else {
            datas = queryLastDataByMac(mac);
            if (ObjectUtils.isEmpty(datas)){
                return null;
            }
        }
        //构建返回对象
        Map<String, Object> result = new HashMap<>();
@@ -305,8 +323,6 @@
        List<Object> list = new ArrayList<>();
        List<Map<String, Object>> mapList = new ArrayList<>();
        for (WindData data : windData) {
            //经度
            Double longitude = data.getLongitude();
            //纬度
@@ -353,25 +369,23 @@
        laLaMap.put("minLo", lomi);
        laLaMap.put("maxLa", lama);
        laLaMap.put("minLa", lami);
        Double lo1 = lomi - length * 0.00001141;
//        Double lo1 = lomi - length * 0.000001141 * 2;
       //Double lo1 = lomi - length * 0.000001141 * 2;
        Double lo2 = loma + length * 0.00001141;
//        Double lo2 = loma + length * 0.000001141 * 2;
//        Double la2 = lami - length * 0.000000899 * 2;
       //Double lo2 = loma + length * 0.000001141 * 2;
       //Double la2 = lami - length * 0.000000899 * 2;
        Double la2 = lami - length * 0.00000899;
//        Double la1 = lama + length * 0.000000899 * 2;
        //Double la1 = lama + length * 0.000000899 * 2;
        Double la1 = lama + length * 0.00000899;
        double dx = 0.00001141 * perdlen;
        double dy = 0.00000899 * perdlen;
//        double dx = 0.000001141 * perdlen * 2;
//        double dy = 0.000000899 * perdlen * 2;
       //double dx = 0.000001141 * perdlen * 2;
       //double dy = 0.000000899 * perdlen * 2;
        int nx = (int) Math.floor((lo2 - lo1) / dx);
        int ny = (int) Math.floor((la1 - la2) / dy);
        List<Double> uList = new ArrayList<>();
        List<Double> vList = new ArrayList<>();
@@ -430,6 +444,7 @@
            }
        }
        String uData = "\"" + "data" + "\"" + ": " + uList;
        String vData = "\"" + "data" + "\"" + ": " + vList;
@@ -447,6 +462,7 @@
        String s1 = "[" + "{" + header1 + ", " + uData + "}" + ", " + "{" + header2 + ", " + vData + "}" + "]";
        //System.out.println(s1);
        JSONArray jsonArray = JSONArray.parseArray(s1);
        list.add(jsonArray);
@@ -489,13 +505,5 @@
        }
        MybatisPlusConfig.tableName.remove();
        return result;
    }
    public static void main(String[] args) {
        ArrayList<Double> objects = new ArrayList<>();
        for (int i = 0; i < 7949760L; i++) {
            objects.add(0.0d);
        }
        System.out.println(objects.size());
    }
}