Commit bbf4dbe9 by chamberone

feat: 添加区块中心点配置

1 parent bd18c64a
......@@ -10,4 +10,8 @@ public interface MapBlockInfoMPDao extends BaseMapper<MapBlockInfo> {
@Select("select * from map_block_info where block_id=#{blockId}")
MapBlockInfo getByBlockId(String blockId);
@Select("select * from map_block_info where team_id=#{teamId} and layer_id=#{layerId}")
MapBlockInfo getByTeamIdAndLayerId(String teamId,String layerId);
}
......@@ -12,6 +12,7 @@ import com.dituhui.pea.order.dto.BusinessServerBlocksRespDTO;
import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.feign.ISaaSRemoteService;
import com.dituhui.pea.order.service.BusinessBlockService;
import com.dituhui.pea.order.utils.RegionUtils;
import com.dituhui.pea.order.utils.TypeUtils;
import lombok.extern.slf4j.Slf4j;
......@@ -45,6 +46,9 @@ public class BusinessBlockServiceImpl implements BusinessBlockService {
@Autowired
private ISaaSRemoteService saasRemoteService;
@Autowired
private OrgGroupDao orgGroupDao;
@Value("${SaaS.ak}")
String ak;
......@@ -146,10 +150,17 @@ public class BusinessBlockServiceImpl implements BusinessBlockService {
if (team == null) {
throw new BusinessException("关联小队不存在");
}
// 重复检查layerId+teamId
MapBlockInfo existBlock = mapBlockInfoMPDao.getByTeamIdAndLayerId(teamId, layerId);
if (null != existBlock) {
return Result.failure("区块已存在");
}
// 同步到saas,返回blockId
// 获取小队出发点,初始化区块 TODO
String region = "{points:[{\"x\":1.3720127240270969E7,\"y\":3692634.103416302},{\"x\":1.37245800199027E7,\"y\":3692634.103416302},{\"x\":1.3720127240270969E7,\"y\":3744947.448648849},{\"x\":1.3720127240270969E7,\"y\":3692634.103416302}]}";
// 获取小队出发点,初始化区块
OrgGroupEntity group = orgGroupDao.getByGroupId(team.getGroupId());
String region = RegionUtils.constructRegion(group.getX(),group.getY());
String result = saasRemoteService.addArea(ak, team.getTeamName(), layerId, region, "gcj02mc");
log.info("params:{} {} {} result:{}", team.getTeamName(), layerId, region, result);
Result<String> saasResult = TypeUtils.<String>convertResult(result);
......
package com.dituhui.pea.order.utils;
import com.dituhui.pea.pojo.PointBase;
import com.dituhui.pea.pojo.RegionDTO;
import com.google.gson.Gson;
public class RegionUtils {
private final static Gson gson = new Gson();
public static String constructRegion(String x, String y) {
double xx = Double.parseDouble(x);
double yy = Double.parseDouble(y);
RegionDTO region = convertXyToRegion(xx, yy);
return gson.toJson(region);
}
public static RegionDTO convertXyToRegion(double x, double y) {
// 经纬度转墨卡托坐标
double xx = gcj02LngToMercator(x);
double yy = gcj02LatToMercator(y);
// 构造正方形
PointBase point1 = new PointBase();
point1.setX(xx);
point1.setY(yy);
PointBase point2 = new PointBase();
point2.setX(xx + 100);
point2.setY(yy);
PointBase point3 = new PointBase();
point3.setX(xx + 100);
point3.setY(yy + 100);
PointBase point4 = new PointBase();
point4.setX(xx);
point4.setY(yy + 100);
PointBase[] points = new PointBase[] { point1, point2, point3, point4, point1 };
RegionDTO region = new RegionDTO();
region.setPoints(points);
return region;
}
private static double gcj02LngToMercator(double x) {
double mx = x / 180.0D * 2.0037508342789244E7D;
return mx;
}
private static double gcj02LatToMercator(double y) {
double my = Math.log(Math.tan((90.0D + y) * 3.141592653589793D / 360.0D)) / 0.017453292519943295D;
my = my / 180.0D * 2.0037508342789244E7D;
return my;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!