|
@@ -0,0 +1,234 @@
|
|
|
+package com.base.biz.service;
|
|
|
+
|
|
|
+import com.base.biz.mapper.SceneBasisTargetMapper;
|
|
|
+import com.base.biz.mapper.SceneTargetPointMapper;
|
|
|
+import com.base.biz.model.PointDTO;
|
|
|
+import com.base.biz.model.dto.request.QueryTargetRelationAddDTO;
|
|
|
+import com.base.biz.model.dto.request.QueryTargetRelationPointAddDTO;
|
|
|
+import com.base.biz.model.entity.SceneBasisTarget;
|
|
|
+import com.base.orbit.domain.AjaxResult;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @program: server
|
|
|
+ * @description: 创建目标业务逻辑类
|
|
|
+ * @author: JoJo
|
|
|
+ * @create: 2025-02-14 14:48
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class CreateTargetService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TargetDemandService targetDemandService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ SceneBasisTargetMapper sceneBasisTargetMapper;
|
|
|
+
|
|
|
+ private static final double MIN_LATITUDE = -90.0;
|
|
|
+
|
|
|
+ private static final double MAX_LATITUDE = 90.0;
|
|
|
+
|
|
|
+ private static final double MIN_LONGITUDE = -180.0;
|
|
|
+
|
|
|
+ private static final double MAX_LONGITUDE = 180.0;
|
|
|
+
|
|
|
+ // 最大距离(度)
|
|
|
+ private static final double MAX_DISTANCE = 0.5;
|
|
|
+
|
|
|
+
|
|
|
+ public AjaxResult createPointTarget() {
|
|
|
+ List<QueryTargetRelationPointAddDTO> queryTargetRelationPointAddDTOList = new ArrayList<>();
|
|
|
+ queryTargetRelationPointAddDTOList = generatePointLocations(400);
|
|
|
+ List<QueryTargetRelationAddDTO> target = targetDemandService.createTarget(queryTargetRelationPointAddDTOList);
|
|
|
+ return AjaxResult.success(target);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<QueryTargetRelationPointAddDTO> generatePointLocations(int count) {
|
|
|
+ List<QueryTargetRelationPointAddDTO> locations = new ArrayList<>();
|
|
|
+ Random random = new Random();
|
|
|
+
|
|
|
+ // 定义热点地区的经纬度范围 (可以根据需要添加更多)
|
|
|
+ double[][] hotZones = {
|
|
|
+ {20, 40, 30, 60}, // 中东 (lat_min, lon_min, lat_max, lon_max)
|
|
|
+ {45, 25, 65, 50}, // 俄乌地区
|
|
|
+ {35, -10, 60, 40}, // 欧洲
|
|
|
+ {25, -125, 50, -65}, // 美洲
|
|
|
+ {30, 120, 45, 145}, // 朝韩日本
|
|
|
+ {-45, 110, -10, 160} // 澳大利亚
|
|
|
+ // 可以添加更多区域
|
|
|
+ };
|
|
|
+
|
|
|
+ while (locations.size() < count) {
|
|
|
+ // 随机选择一个热点地区
|
|
|
+ int zoneIndex = random.nextInt(hotZones.length);
|
|
|
+ double latMin = hotZones[zoneIndex][0];
|
|
|
+ double lonMin = hotZones[zoneIndex][1];
|
|
|
+ double latMax = hotZones[zoneIndex][2];
|
|
|
+ double lonMax = hotZones[zoneIndex][3];
|
|
|
+
|
|
|
+ // 在该热点地区内生成随机经纬度
|
|
|
+ double latitude = latMin + (latMax - latMin) * random.nextDouble();
|
|
|
+ double longitude = lonMin + (lonMax - lonMin) * random.nextDouble();
|
|
|
+
|
|
|
+ // 排除中国区域 (大致范围,可以根据需要调整)
|
|
|
+ if (isInsideChina(latitude, longitude)) {
|
|
|
+ String areaName = "";
|
|
|
+ areaName = getAreaNameByZoneIndex(zoneIndex);
|
|
|
+ ArrayList<PointDTO> pointDTOS = new ArrayList<>();
|
|
|
+ PointDTO pointDTO = new PointDTO();
|
|
|
+ pointDTO.setLat(latitude);
|
|
|
+ pointDTO.setLng(longitude);
|
|
|
+ pointDTO.setSequence(1);
|
|
|
+ pointDTOS.add(pointDTO);
|
|
|
+ QueryTargetRelationPointAddDTO queryTargetRelationPointAddDTO = new QueryTargetRelationPointAddDTO();
|
|
|
+ queryTargetRelationPointAddDTO.setParentId("250214_XQCH_10001_M00" + (locations.size() + 1));
|
|
|
+ queryTargetRelationPointAddDTO.setCountryName(areaName);
|
|
|
+ queryTargetRelationPointAddDTO.setTargetName("0214点目标" + (locations.size() + 1));
|
|
|
+ queryTargetRelationPointAddDTO.setPointDTOList(pointDTOS);
|
|
|
+ queryTargetRelationPointAddDTO.setType(0);
|
|
|
+ queryTargetRelationPointAddDTO.setTargetLevel(3);
|
|
|
+ locations.add(queryTargetRelationPointAddDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return locations;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getAreaNameByZoneIndex(int zoneIndex) {
|
|
|
+ String areaName;
|
|
|
+ switch (zoneIndex) {
|
|
|
+ case 0:
|
|
|
+ // 中东
|
|
|
+ areaName = "中东";
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ // 俄乌地区
|
|
|
+ areaName = "俄乌地区";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ // 欧洲
|
|
|
+ areaName = "欧洲";
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ // 美洲
|
|
|
+ areaName = "美洲";
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ // 朝韩日本
|
|
|
+ areaName = "朝韩日本";
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ // 澳大利亚
|
|
|
+ areaName = "澳大利亚";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ areaName = "未知区域";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return areaName;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断是否在中国区域内 (简单判断,可以根据实际情况调整)
|
|
|
+ private boolean isInsideChina(double latitude, double longitude) {
|
|
|
+ return (!(latitude >= 18.0) || !(latitude <= 54.0) || !(longitude >= 73.0) || !(longitude <= 135.0));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public AjaxResult createMobileTarget() {
|
|
|
+ List<QueryTargetRelationPointAddDTO> queryTargetRelationPointAddDTOS = generateMobileTargets(300);
|
|
|
+ List<QueryTargetRelationAddDTO> target = targetDemandService.createTarget(queryTargetRelationPointAddDTOS);
|
|
|
+ return AjaxResult.success(target);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<QueryTargetRelationPointAddDTO> generateMobileTargets(int targetCount){
|
|
|
+ List<QueryTargetRelationPointAddDTO> targets = new ArrayList<>();
|
|
|
+
|
|
|
+ Random random = new Random();
|
|
|
+
|
|
|
+ // 定义热点地区的经纬度范围 (可以根据需要添加更多)
|
|
|
+ double[][] hotZones = {
|
|
|
+ {20, 40, 30, 60}, // 中东 (lat_min, lon_min, lat_max, lon_max)
|
|
|
+ {45, 25, 65, 50}, // 俄乌地区
|
|
|
+ {35, -10, 60, 40}, // 欧洲
|
|
|
+ {25, -125, 50, -65}, // 美洲
|
|
|
+ {30, 120, 45, 145}, // 朝韩日本
|
|
|
+ {-45, 110, -10, 160} // 澳大利亚
|
|
|
+ // 可以添加更多区域
|
|
|
+ };
|
|
|
+
|
|
|
+ while (targets.size() < targetCount) {
|
|
|
+ // 随机选择一个热点地区
|
|
|
+ int zoneIndex = random.nextInt(hotZones.length);
|
|
|
+ double latMin = hotZones[zoneIndex][0];
|
|
|
+ double lonMin = hotZones[zoneIndex][1];
|
|
|
+ double latMax = hotZones[zoneIndex][2];
|
|
|
+ double lonMax = hotZones[zoneIndex][3];
|
|
|
+
|
|
|
+ String areaName = getAreaNameByZoneIndex(zoneIndex);
|
|
|
+
|
|
|
+ // 生成基础经纬度
|
|
|
+ double baseLatitude = latMin + (latMax - latMin) * random.nextDouble();
|
|
|
+ double baseLongitude = lonMin + (lonMax - lonMin) * random.nextDouble();
|
|
|
+
|
|
|
+ // 排除中国区域
|
|
|
+ if (isInsideChina(baseLatitude, baseLongitude)) {
|
|
|
+ // 确定目标的点数(3-5个)
|
|
|
+ int pointCount = random.nextInt(3) + 3; // 3, 4, or 5
|
|
|
+
|
|
|
+ List<PointDTO> pointDTOS = new ArrayList<>();
|
|
|
+ for (int i = 0; i < pointCount; i++) {
|
|
|
+ PointDTO pointDTO = new PointDTO();
|
|
|
+ // 在基础点附近生成其他点
|
|
|
+ double latitude = baseLatitude + (random.nextDouble() * 2 - 1) * MAX_DISTANCE;
|
|
|
+ double longitude = baseLongitude + (random.nextDouble() * 2 - 1) * MAX_DISTANCE;
|
|
|
+
|
|
|
+ // 确保生成的点在有效经纬度范围内
|
|
|
+ latitude = Math.max(MIN_LATITUDE, Math.min(MAX_LATITUDE, latitude));
|
|
|
+ longitude = Math.max(MIN_LONGITUDE, Math.min(MAX_LONGITUDE, longitude));
|
|
|
+
|
|
|
+ pointDTO.setLat(latitude);
|
|
|
+ pointDTO.setLng(longitude);
|
|
|
+ pointDTO.setSequence(i + 1);
|
|
|
+ pointDTOS.add(pointDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryTargetRelationPointAddDTO queryTargetRelationPointAddDTO = new QueryTargetRelationPointAddDTO();
|
|
|
+ queryTargetRelationPointAddDTO.setParentId("250214_XQCH_10001_M0" + (300 + targets.size() + 1));
|
|
|
+ queryTargetRelationPointAddDTO.setCountryName(areaName);
|
|
|
+ queryTargetRelationPointAddDTO.setTargetName("0214移动目标" + (targets.size() + 1));
|
|
|
+ queryTargetRelationPointAddDTO.setPointDTOList(pointDTOS);
|
|
|
+ queryTargetRelationPointAddDTO.setType(1);
|
|
|
+ queryTargetRelationPointAddDTO.setTargetLevel(3);
|
|
|
+ targets.add(queryTargetRelationPointAddDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return targets;
|
|
|
+ }
|
|
|
+
|
|
|
+ public AjaxResult createTargetDemandRelationData() {
|
|
|
+ List<SceneBasisTarget> sceneBasisTargetList = sceneBasisTargetMapper.findTargetDemandRelationData();
|
|
|
+
|
|
|
+ String baseParentId = "250214_XQCH_10000_0";
|
|
|
+ List<QueryTargetRelationAddDTO> queryTargetRelationAddDTOS = new ArrayList<>();
|
|
|
+ for (int i = 0; i < sceneBasisTargetList.size(); i++) {
|
|
|
+ String parentId = baseParentId + (i + 1);
|
|
|
+ SceneBasisTarget sceneBasisTarget = sceneBasisTargetList.get(i);
|
|
|
+ QueryTargetRelationAddDTO queryTargetRelationAddDTO = new QueryTargetRelationAddDTO();
|
|
|
+ queryTargetRelationAddDTO.setId(sceneBasisTarget.getId());
|
|
|
+ queryTargetRelationAddDTO.setParentId(parentId);
|
|
|
+ queryTargetRelationAddDTOS.add(queryTargetRelationAddDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ Boolean b = targetDemandService.addList(queryTargetRelationAddDTOS);
|
|
|
+ if (b) {
|
|
|
+ return AjaxResult.success("添加成功");
|
|
|
+ }
|
|
|
+ return AjaxResult.error("添加失败");
|
|
|
+ }
|
|
|
+}
|