监控设备经纬度偏移

develop
hanrenchun 10 months ago
parent ad134f2b7d
commit 67dddb4769

@ -0,0 +1,69 @@
package com.ssf.mysqloracletest.task;
import com.ssf.mysqloracletest.domain.DevopsVideoInfo0;
import com.ssf.mysqloracletest.service.DevopsVideoInfoService0;
import com.ssf.mysqloracletest.utils.ConfigParam;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@RequiredArgsConstructor
public class DevopsVideoInfoTask {
private static final Logger logger = LoggerFactory.getLogger(DevopsVideoInfoTask.class);
private final DevopsVideoInfoService0 videoInfoService0;
//偏移量
Double offset = 0.0001;
//查找用偏移量
Double offset1 = 0.00005;
//视频设备经纬度偏移
@Scheduled(initialDelay = 100, fixedDelay = 3000)
public void videoPosition(){
if (!"true".equals(ConfigParam.videoPositionSwitch)) {
return;
}
//找出经纬度正常的设备
List<DevopsVideoInfo0> list = videoInfoService0.lambdaQuery()
.ne(DevopsVideoInfo0::getLongitude,0.000000)
.ne(DevopsVideoInfo0::getLatitude,0.000000)
.list();
for (DevopsVideoInfo0 devopsVideoInfo0 : list){
Double latitude = devopsVideoInfo0.getLatitude();
Double longitude = devopsVideoInfo0.getLongitude();
//根据一个设备的经纬度,找出该设备偏移范围内的所有设备
List<DevopsVideoInfo0> videoInfo0List = videoInfoService0.lambdaQuery()
// .ne(DevopsVideoInfo0::getGbsChannelNo,devopsVideoInfo0.getGbsChannelNo())
.between(DevopsVideoInfo0::getLatitude, latitude - offset1, latitude + offset1)
.between(DevopsVideoInfo0::getLongitude, longitude - offset1, longitude + offset1)
.list();
if (!videoInfo0List.isEmpty()) {
double angleOffset = 360.0 / videoInfo0List.size();
for (int i = 0; i < videoInfo0List.size(); i++) {
double angle = i * angleOffset;
DevopsVideoInfo0 videoInfo0 = videoInfo0List.get(i);
// 将极坐标转换为直角坐标
double newLatitude = videoInfo0.getLatitude() + (offset * Math.cos(Math.toRadians(angle)));
double newLongitude = videoInfo0.getLongitude() + (offset * Math.sin(Math.toRadians(angle)));
videoInfo0.setLatitude(newLatitude);
videoInfo0.setLongitude(newLongitude);
boolean update = videoInfoService0.lambdaUpdate()
.eq(DevopsVideoInfo0::getGbsChannelNo, videoInfo0.getGbsChannelNo())
.update(videoInfo0);
if (update){
logger.info("修改成功");
}
}
}
}
}
}
Loading…
Cancel
Save