add:第一版测试版本,第二次联调。
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package org.nl.map.controller;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.nl.logging.annotation.Log;
|
||||
import org.nl.map.service.MapService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2025/12/18
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/mapinfo")
|
||||
public class MapInfoController {
|
||||
|
||||
@Resource
|
||||
private MapService mapService;
|
||||
|
||||
@GetMapping("/queryCurrentMapInfo")
|
||||
@Log("获取当前地图信息")
|
||||
public ResponseEntity<Object> queryCurrentMapInfo() {
|
||||
return new ResponseEntity<>(mapService.queryCurrentMapInfo(), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
51
nl-business-map/src/main/java/org/nl/map/entity/MapInfo.java
Normal file
51
nl-business-map/src/main/java/org/nl/map/entity/MapInfo.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package org.nl.map.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2025/12/18
|
||||
*/
|
||||
@Data
|
||||
@TableName("map_info")
|
||||
public class MapInfo {
|
||||
|
||||
/**
|
||||
* 地图编号
|
||||
*/
|
||||
@TableId
|
||||
private String mapCode;
|
||||
|
||||
/**
|
||||
* 地图名称
|
||||
*/
|
||||
private String mapName;
|
||||
|
||||
/**
|
||||
* 地图图片地址
|
||||
*/
|
||||
private String mapImageAddress;
|
||||
|
||||
|
||||
/**
|
||||
* 点云图像素比例
|
||||
*/
|
||||
private Double resolution;
|
||||
|
||||
/**
|
||||
* 左下角x坐标
|
||||
*/
|
||||
private Double x;
|
||||
|
||||
/**
|
||||
* 左下角y坐标
|
||||
*/
|
||||
private Double y;
|
||||
|
||||
/**
|
||||
* 左下角 角度
|
||||
*/
|
||||
private Double angle;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.nl.map.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.nl.map.entity.MapInfo;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2025/12/18
|
||||
*/
|
||||
@Mapper
|
||||
public interface MapInfoMapper extends BaseMapper<MapInfo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.nl.map.service;
|
||||
|
||||
import org.nl.response.WebResponse;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2025/12/18
|
||||
*/
|
||||
public interface MapService {
|
||||
WebResponse queryCurrentMapInfo();
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package org.nl.map.service.impl;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.map.entity.MapInfo;
|
||||
import org.nl.map.mapper.MapInfoMapper;
|
||||
import org.nl.map.service.MapService;
|
||||
import org.nl.map.station.entity.Station;
|
||||
import org.nl.map.station.mapper.StationMapper;
|
||||
import org.nl.response.WebResponse;
|
||||
import org.nl.util.FileProperties;
|
||||
import org.nl.util.URLConstant;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2025/12/18
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MapServiceImpl implements MapService {
|
||||
|
||||
@Resource
|
||||
private StationMapper stationMapper;
|
||||
|
||||
@Resource
|
||||
private MapInfoMapper mapInfoMapper;
|
||||
|
||||
@Resource
|
||||
private FileProperties properties;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
getCurrentMapInfo();
|
||||
downloadImage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载图片并保存
|
||||
*/
|
||||
public void downloadImage() {
|
||||
String filename = "currentMapImage.png";
|
||||
Path filePath = Paths.get(properties.getPath().getPath(), filename);
|
||||
|
||||
try {
|
||||
// 确保目录存在
|
||||
createDirectoryIfNotExists();
|
||||
|
||||
// 发送请求
|
||||
HttpResponse response = HttpRequest.get("http://"+ URLConstant.SCHEDULE_IP_PORT+"/maps/current/image/file")
|
||||
.header("Accept", "image/png")
|
||||
.header("User-Agent", "Hutool-HTTP")
|
||||
.timeout(30000)
|
||||
.execute();
|
||||
|
||||
if (response.getStatus() != HttpStatus.HTTP_OK) {
|
||||
throw new RuntimeException("HTTP请求失败,状态码: " + response.getStatus());
|
||||
}
|
||||
|
||||
// 获取 Content-Type 验证
|
||||
String contentType = response.header("Content-Type");
|
||||
log.info("Content-Type: {}", contentType);
|
||||
|
||||
// 保存文件
|
||||
byte[] bytes = response.bodyBytes();
|
||||
Files.write(filePath, bytes);
|
||||
|
||||
log.info("图片下载成功: {}, 大小: {} bytes",
|
||||
filePath.toAbsolutePath(), bytes.length);
|
||||
|
||||
mapInfoMapper.delete(new LambdaQueryWrapper<>());
|
||||
|
||||
MapInfo mapInfo = new MapInfo();
|
||||
mapInfo.setMapCode(filename);
|
||||
mapInfo.setMapName(filename);
|
||||
mapInfo.setMapImageAddress("/file/" + filename);
|
||||
mapInfoMapper.insert(mapInfo);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("下载图片失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建下载目录
|
||||
*/
|
||||
private void createDirectoryIfNotExists() throws IOException {
|
||||
Path dirPath = Paths.get(properties.getPath().getPath());
|
||||
if (!Files.exists(dirPath)) {
|
||||
Files.createDirectories(dirPath);
|
||||
log.info("创建下载目录: {}", dirPath.toAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
public void getCurrentMapInfo(){
|
||||
try {
|
||||
|
||||
// 发送请求
|
||||
HttpResponse response = HttpRequest
|
||||
.get("http://"+ URLConstant.SCHEDULE_IP_PORT+"/maps/current")
|
||||
.execute();
|
||||
|
||||
if (response.getStatus() != HttpStatus.HTTP_OK) {
|
||||
throw new RuntimeException("HTTP请求失败,状态码: " + response.getStatus());
|
||||
}
|
||||
|
||||
// 清除站点数据
|
||||
stationMapper.delete(new LambdaQueryWrapper<>());
|
||||
|
||||
JSONArray pois = JSONArray.parseArray(JSONObject.parseObject(response.body()).getString("pois"));
|
||||
for (int i = 0; i < pois.size(); i++) {
|
||||
JSONObject poi = pois.getJSONObject(i);
|
||||
Station station = new Station();
|
||||
station.setStation_id(poi.getString("id"));
|
||||
station.setStation_code(poi.getString("name"));
|
||||
station.setStation_name(poi.getString("name"));
|
||||
station.setStation_type("Normal");
|
||||
JSONObject pose = poi.getJSONObject("pose");
|
||||
station.setX(pose.getDouble("x"));
|
||||
station.setY(pose.getDouble("y"));
|
||||
station.setAngle(pose.getDouble("yaw"));
|
||||
stationMapper.insert(station);
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.info("获取当前地图信息失败:{}",e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebResponse queryCurrentMapInfo() {
|
||||
|
||||
MapInfo mapInfo = mapInfoMapper.selectOne(new LambdaQueryWrapper<>(MapInfo.class)
|
||||
.eq(MapInfo::getMapCode, "currentMapImage.png")
|
||||
);
|
||||
return WebResponse.requestParamOk(mapInfo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.nl.map.station.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2025/12/18
|
||||
*/
|
||||
@Data
|
||||
@TableName("station")
|
||||
public class Station {
|
||||
|
||||
@TableId
|
||||
private String station_id;
|
||||
|
||||
/**
|
||||
* 站点编码 对应地图上站点
|
||||
*/
|
||||
private String station_code;
|
||||
|
||||
/**
|
||||
* 站点别名
|
||||
*/
|
||||
private String station_name;
|
||||
|
||||
/**
|
||||
* 站点类型 (Normal 普通站点)
|
||||
*/
|
||||
private String station_type;
|
||||
|
||||
/**
|
||||
* x坐标
|
||||
*/
|
||||
private Double x;
|
||||
|
||||
/**
|
||||
* y坐标
|
||||
*/
|
||||
private Double y;
|
||||
|
||||
/**
|
||||
* 角度
|
||||
*/
|
||||
private Double angle;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.nl.map.station.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.nl.map.station.entity.Station;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2025/12/18
|
||||
*/
|
||||
@Mapper
|
||||
public interface StationMapper extends BaseMapper<Station> {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user