chen_xi
2023-06-28 95a6e4392acc0f559b78c7300fdb3e5155e89795
screen-api/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java
@@ -32,6 +32,7 @@
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
@@ -103,7 +104,7 @@
    }
    @Override
    public List<Map<String, Object>> carTrajectory(Map<String, Object> params) {
    public List<Map<String, Object>> carTrajectory(Map<String, Object> params,boolean type) {
        params.put("dateFormat", "%Y-%m-%d %H:%i:%s");
        Map<String, Object> userInfo = (Map<String, Object>) TokenUtils.getUserInfo();
        Map<String, Object> orgInfo = (Map<String, Object>) userInfo.get("organization");
@@ -126,7 +127,12 @@
            if (lon < 70 || lon > 150 || lat < 20 || lat > 60) {
                return true;
            }
            o.putAll(value);
            if(type){
                o.putAll(value);
            }else {
            }
            return false;
        });
        /*for (Map<String, Object> map:data) {
@@ -142,7 +148,6 @@
        }*/
        return filterData(data);
    }
    @Override
    public SpecialDevice getSpecialDeviceMapByMac(String mac) {
        QueryWrapper<SpecialDevice> queryWrapper = new QueryWrapper();
@@ -182,7 +187,7 @@
        String time2 = params.get("time2").toString();
        String rsTime = getTime(time1, time2);
        list.add(rsTime);
        List<Map<String, Object>> maps = specialDeviceService.carTrajectory(params);
        List<Map<String, Object>> maps = specialDeviceService.carTrajectory(params,false);
        if (ObjectUtils.isEmpty(maps)){
            return null;
        }
@@ -194,7 +199,7 @@
            map.put("time1",time3);
            map.put("time2",time4);
            map.put("mac",mac);
            List<Map<String, Object>> maps1 = specialDeviceService.carTrajectory(map);
            List<Map<String, Object>> maps1 = specialDeviceService.carTrajectory(map,false);
            if (ObjectUtils.isEmpty(maps1)){
                return null;
            }
@@ -210,7 +215,7 @@
            map.put("time1",time5);
            map.put("time2",time6);
            map.put("mac",mac);
            List<Map<String, Object>> maps1 = specialDeviceService.carTrajectory(map);
            List<Map<String, Object>> maps1 = specialDeviceService.carTrajectory(map,false);
            if (ObjectUtils.isEmpty(maps1)){
                return null;
            }
@@ -495,6 +500,33 @@
                result.add(map);
            }
        }
        return result;
    }
    //范围取均值
    private List<Map<String, Object>> filterData(List<Map<String, Object>> data, List<Map<String, Object>> result) {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String,List<Object>> map = new HashMap<>();
        result.forEach(it->map.put(it.get(Constants.SENSOR_CODE_LON).toString()+ "_"+Constants.SENSOR_CODE_LAT.toString(),Arrays.asList(it)));
        // 坐标在50 以内分组
        for (Map<String, Object> mapData : data) {
            for (Map.Entry<String, List<Object>> entry : map.entrySet()) {
                double lng1 = Double.parseDouble(mapData.get(Constants.SENSOR_CODE_LON).toString());
                double lat1 = Double.parseDouble(mapData.get(Constants.SENSOR_CODE_LAT).toString());
                String[] mapKey = entry.getKey().split("_");
                List<Object> mapValue = entry.getValue();
                double lng2 = Double.parseDouble(mapKey[0]);
                double lat2 = Double.parseDouble(mapKey[1]);
                double distance = GeodesyUtils.getDistance(lat1, lng1, lat2, lng2);
                if (distance < dis) {
                    mapValue.add(mapData);
                }
            }
        }
        return list;
    }
}