|
@@ -5,6 +5,7 @@ import com.fd.constant.MsgCode;
|
|
|
import com.fd.constant.TypeCode;
|
|
|
import com.fd.dto.PageDto;
|
|
|
import com.fd.entity.FileEntity;
|
|
|
+import com.fd.entity.OutputFileEntity;
|
|
|
import com.fd.server.CmdServer;
|
|
|
import com.fd.server.FileServer;
|
|
|
import com.fd.server.VectorServer;
|
|
@@ -56,25 +57,25 @@ public class VectorController {
|
|
|
// return fileServer.uploadFile(file, directoryName, TypeCode.FILE_TYPE_VECTOR);
|
|
|
// }
|
|
|
|
|
|
- @ApiOperation("上传矢量数据,只能上传zip文件,里面的文件名必须跟压缩包一致, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
|
|
|
- @PostMapping(value = "upload", consumes = { "multipart/form-data" })
|
|
|
- private R upload(@RequestParam("file") MultipartFile file,
|
|
|
- @RequestParam(value = "coord",required = false) String coord){
|
|
|
- log.info("run upload");
|
|
|
-
|
|
|
- // 文件名全名
|
|
|
- String fileName = file.getOriginalFilename();
|
|
|
- String s = StringUtils.substringAfterLast(fileName, ".");
|
|
|
-
|
|
|
- if (!"zip".equals(s)) {
|
|
|
- return new R(50007,MsgCode.E50007);
|
|
|
- }
|
|
|
-
|
|
|
- return vectorServer.uploadFile(file, coord);
|
|
|
- }
|
|
|
+// @ApiOperation("上传矢量数据,只能上传zip文件,里面的文件名必须跟压缩包一致, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
|
|
|
+// @PostMapping(value = "upload", consumes = { "multipart/form-data" })
|
|
|
+// private R upload(@RequestParam("file") MultipartFile file,
|
|
|
+// @RequestParam(value = "coord",required = false) String coord){
|
|
|
+// log.info("run upload");
|
|
|
+//
|
|
|
+// // 文件名全名
|
|
|
+// String fileName = file.getOriginalFilename();
|
|
|
+// String s = StringUtils.substringAfterLast(fileName, ".");
|
|
|
+//
|
|
|
+// if (!"zip".equals(s)) {
|
|
|
+// return new R(50007,MsgCode.E50007);
|
|
|
+// }
|
|
|
+//
|
|
|
+// return vectorServer.uploadFile(file, coord);
|
|
|
+// }
|
|
|
|
|
|
|
|
|
- @ApiOperation("上传矢量数据,里面的文件名必须跟压缩包一致, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
|
|
|
+ @ApiOperation("上传矢量数据, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
|
|
|
@PostMapping(value = "upload/{directoryName}/", consumes = { "multipart/form-data" })
|
|
|
private R upload(@RequestParam("file") MultipartFile file,
|
|
|
@PathVariable("directoryName") String directoryName,
|
|
@@ -85,62 +86,62 @@ public class VectorController {
|
|
|
|
|
|
|
|
|
|
|
|
- @ApiOperation("解压zip文件")
|
|
|
- @GetMapping("unzip/{fileId}/")
|
|
|
- private R fileUnzip(@PathVariable("fileId") Long fileId) {
|
|
|
- log.info("run fileUnzip: {}", fileId);
|
|
|
- FileEntity entity = fileServer.findById(fileId);
|
|
|
-
|
|
|
- boolean unzip = FileUtils.unzip(entity.getFileUrl(), INPUT_FILE_PATH);
|
|
|
-
|
|
|
- if (!unzip) {
|
|
|
- log.info("zip error: {}", MsgCode.E51001);
|
|
|
- return new R(51001, MsgCode.E51001);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
|
-
|
|
|
- // 判断文件内容是否跟目录名称一样
|
|
|
- String shpPath = INPUT_FILE_PATH + fileName + File.separator + fileName + ".shp";
|
|
|
- File file = new File(shpPath);
|
|
|
- if (!file.exists()) {
|
|
|
- log.info("zip error: {}", MsgCode.E51002);
|
|
|
- return new R(51002, MsgCode.E51002);
|
|
|
- }
|
|
|
-
|
|
|
- FileEntity fileEntity = new FileEntity();
|
|
|
-
|
|
|
- // 添加文件夹到数据库
|
|
|
- fileEntity.setFileName(fileName);
|
|
|
- fileEntity.setFileUrl(INPUT_FILE_PATH + fileName);
|
|
|
- fileEntity.setCreateTime(new Date());
|
|
|
- fileEntity.setUpdateTime(new Date());
|
|
|
- fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
- fileEntity.setCoord(entity.getCoord());
|
|
|
- fileEntity.setStatus(2);
|
|
|
-
|
|
|
- fileEntity = fileServer.save(fileEntity);
|
|
|
-
|
|
|
- // xxx.shp到数据库
|
|
|
-// String sName = StringUtils.substringAfter(fileName, "_");
|
|
|
-// sName = sName + ".shp";
|
|
|
- fileEntity = new FileEntity();
|
|
|
-// fileEntity.setFileName(sName);
|
|
|
-// fileEntity.setFileUrl(INPUT_FILE_PATH + fileName + File.separator + sName);
|
|
|
-
|
|
|
- fileEntity.setFileName(fileName + ".shp");
|
|
|
- fileEntity.setFileUrl(shpPath);
|
|
|
-
|
|
|
- fileEntity.setCreateTime(new Date());
|
|
|
- fileEntity.setUpdateTime(new Date());
|
|
|
- fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
- fileEntity.setCoord(entity.getCoord());
|
|
|
- fileEntity = fileServer.save(fileEntity);
|
|
|
-
|
|
|
- return new R(200, fileEntity);
|
|
|
- }
|
|
|
+// @ApiOperation("解压zip文件")
|
|
|
+// @GetMapping("unzip/{fileId}/")
|
|
|
+// private R fileUnzip(@PathVariable("fileId") Long fileId) {
|
|
|
+// log.info("run fileUnzip: {}", fileId);
|
|
|
+// FileEntity entity = fileServer.findById(fileId);
|
|
|
+//
|
|
|
+// boolean unzip = FileUtils.unzip(entity.getFileUrl(), INPUT_FILE_PATH);
|
|
|
+//
|
|
|
+// if (!unzip) {
|
|
|
+// log.info("zip error: {}", MsgCode.E51001);
|
|
|
+// return new R(51001, MsgCode.E51001);
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
|
+//
|
|
|
+// // 判断文件内容是否跟目录名称一样
|
|
|
+// String shpPath = INPUT_FILE_PATH + fileName + File.separator + fileName + ".shp";
|
|
|
+// File file = new File(shpPath);
|
|
|
+// if (!file.exists()) {
|
|
|
+// log.info("zip error: {}", MsgCode.E51002);
|
|
|
+// return new R(51002, MsgCode.E51002);
|
|
|
+// }
|
|
|
+//
|
|
|
+// FileEntity fileEntity = new FileEntity();
|
|
|
+//
|
|
|
+// // 添加文件夹到数据库
|
|
|
+// fileEntity.setFileName(fileName);
|
|
|
+// fileEntity.setFileUrl(INPUT_FILE_PATH + fileName);
|
|
|
+// fileEntity.setCreateTime(new Date());
|
|
|
+// fileEntity.setUpdateTime(new Date());
|
|
|
+// fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
+// fileEntity.setCoord(entity.getCoord());
|
|
|
+// fileEntity.setStatus(2);
|
|
|
+//
|
|
|
+// fileEntity = fileServer.save(fileEntity);
|
|
|
+//
|
|
|
+// // xxx.shp到数据库
|
|
|
+//// String sName = StringUtils.substringAfter(fileName, "_");
|
|
|
+//// sName = sName + ".shp";
|
|
|
+// fileEntity = new FileEntity();
|
|
|
+//// fileEntity.setFileName(sName);
|
|
|
+//// fileEntity.setFileUrl(INPUT_FILE_PATH + fileName + File.separator + sName);
|
|
|
+//
|
|
|
+// fileEntity.setFileName(fileName + ".shp");
|
|
|
+// fileEntity.setFileUrl(shpPath);
|
|
|
+//
|
|
|
+// fileEntity.setCreateTime(new Date());
|
|
|
+// fileEntity.setUpdateTime(new Date());
|
|
|
+// fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
+// fileEntity.setCoord(entity.getCoord());
|
|
|
+// fileEntity = fileServer.save(fileEntity);
|
|
|
+//
|
|
|
+// return new R(200, fileEntity);
|
|
|
+// }
|
|
|
|
|
|
|
|
|
|
|
@@ -150,7 +151,7 @@ public class VectorController {
|
|
|
private R list(@RequestBody PageDto param){
|
|
|
log.info("run list");
|
|
|
// return fileServer.findByType(TypeCode.FILE_TYPE_VECTOR, TypeCode.FILE_TYPE_VECTOR_SHP, param);
|
|
|
- return fileServer.findByType(TypeCode.FILE_TYPE_VECTOR, param);
|
|
|
+ return vectorServer.findByType(TypeCode.FILE_TYPE_VECTOR, param);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -169,29 +170,33 @@ public class VectorController {
|
|
|
@GetMapping("command/judge/coord/{fileId}/")
|
|
|
private R cmdJudgeCoord(@PathVariable("fileId") Long fileId) {
|
|
|
log.info("run cmdJudgeCoord: {}", fileId);
|
|
|
- FileEntity entity = fileServer.findById(fileId);
|
|
|
+// FileEntity entity = fileServer.findById(fileId);
|
|
|
+
|
|
|
+ OutputFileEntity entity = vectorServer.findById(fileId);
|
|
|
+
|
|
|
+
|
|
|
String coord = entity.getCoord();
|
|
|
log.info("coord: {}", coord);
|
|
|
|
|
|
// 判断是否需要坐标转换
|
|
|
String cmd = Command.VECTOR_JUDGE_COORD;
|
|
|
- cmd = cmd.replace("@inputFile", entity.getFileUrl());
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getUploadPath());
|
|
|
log.info("cmd: {}", cmd);
|
|
|
|
|
|
Integer isJudge = cmdServer.exeCmdJudgeCoord(cmd);
|
|
|
|
|
|
- FileEntity fileEntity = null;
|
|
|
+// FileEntity fileEntity = null;
|
|
|
// 转换坐标 普通坐标转换
|
|
|
if (isJudge == 1000){
|
|
|
// 普通坐标转换
|
|
|
log.info("need to general transform");
|
|
|
if (coord == null) {
|
|
|
// 没有坐标参数,执行普通坐标转换(ogrinfo)
|
|
|
- fileEntity = generalCoordTransform(entity, Command.VECTOR_TRANSFORM_GENERAL);
|
|
|
+ entity = generalCoordTransform(entity, Command.VECTOR_TRANSFORM_GENERAL);
|
|
|
|
|
|
} else {
|
|
|
// 有坐标参数,执行严格坐标转换(CGCS2000转wgs80)
|
|
|
- fileEntity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS80);
|
|
|
+ entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS80);
|
|
|
}
|
|
|
|
|
|
} else if (isJudge == 1001) {
|
|
@@ -201,35 +206,49 @@ public class VectorController {
|
|
|
log.info("error: {}", MsgCode.E50009);
|
|
|
return new R(50009, MsgCode.E50009);
|
|
|
}
|
|
|
- fileEntity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
|
|
|
+ entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
|
|
|
|
|
|
} else if (0 == isJudge){ // 不转换坐标
|
|
|
log.info("not to transform");
|
|
|
- fileEntity = entity;
|
|
|
+ entity = entity;
|
|
|
} else {
|
|
|
log.info("error exeCmd");
|
|
|
return new R(50005, MsgCode.E50005);
|
|
|
}
|
|
|
|
|
|
|
|
|
- return new R(200, fileEntity);
|
|
|
+ return new R(200, entity);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("矢量数据转geojson")
|
|
|
@GetMapping("command/geojson/{fileId}/")
|
|
|
private R cmdGeojson(@PathVariable("fileId") Long fileId) {
|
|
|
log.info("run cmdGeojson: {}", fileId);
|
|
|
- FileEntity entity = fileServer.findById(fileId);
|
|
|
+ OutputFileEntity entity = vectorServer.findById(fileId);
|
|
|
|
|
|
String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
|
- // 截取目录名称
|
|
|
- String fileUrl = entity.getFileUrl();
|
|
|
- String outputFile = StringUtils.substringBefore(fileUrl, ".");
|
|
|
- outputFile = outputFile + ".json";
|
|
|
+// // 截取目录名称
|
|
|
+// String fileUrl = entity.getUploadPath();
|
|
|
+// String outputFile = StringUtils.substringBefore(fileUrl, ".");
|
|
|
+// outputFile = outputFile + ".json";
|
|
|
+ String outPath = OUTPUT_FILE_PATH + "geojson";
|
|
|
+ FileUtils.createDir(outPath);
|
|
|
+ outPath = outPath +File.separator + fileName + ".json";
|
|
|
|
|
|
String cmd = Command.VECTOR_TO_GEOJSON;
|
|
|
- cmd = cmd.replace("@inputFile", fileUrl);
|
|
|
- cmd = cmd.replace("@outputFile", outputFile);
|
|
|
+ if (entity.getCoordStrictPath() != null) {
|
|
|
+ // 严格坐标转换
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
|
|
|
+ } else if (entity.getCoordStrictPath() == null && entity.getCoordGeneralPath() == null ) {
|
|
|
+ // 不需要坐标转换
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getUploadPath());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 普通坐标转换
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getCoordGeneralPath());
|
|
|
+ }
|
|
|
+
|
|
|
+ cmd = cmd.replace("@outputFile", outPath);
|
|
|
log.info("cmd: {}", cmd);
|
|
|
|
|
|
|
|
@@ -238,17 +257,21 @@ public class VectorController {
|
|
|
return new R(50005, MsgCode.E50005);
|
|
|
}
|
|
|
|
|
|
- FileEntity fileEntity = new FileEntity();
|
|
|
- fileEntity.setFileName(fileName + ".json");
|
|
|
- fileEntity.setFileUrl(outputFile);
|
|
|
- fileEntity.setCreateTime(new Date());
|
|
|
- fileEntity.setUpdateTime(new Date());
|
|
|
- fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
- fileEntity.setStatus(4);
|
|
|
+// FileEntity fileEntity = new FileEntity();
|
|
|
+// fileEntity.setFileName(fileName + ".json");
|
|
|
+// fileEntity.setFileUrl(outputFile);
|
|
|
+// fileEntity.setCreateTime(new Date());
|
|
|
+// fileEntity.setUpdateTime(new Date());
|
|
|
+// fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
+// fileEntity.setStatus(4);
|
|
|
|
|
|
- fileEntity = fileServer.save(fileEntity);
|
|
|
|
|
|
- return new R(200, fileEntity);
|
|
|
+ entity.setGeojsonPath(outPath);
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ entity.setStatus(4);
|
|
|
+ entity = vectorServer.save(entity);
|
|
|
+
|
|
|
+ return new R(200, entity);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -256,14 +279,19 @@ public class VectorController {
|
|
|
@GetMapping("command/slice/{fileId}/")
|
|
|
private R cmdSlice (@PathVariable("fileId") Long fileId) {
|
|
|
log.info("run cmdSlice: {}", fileId);
|
|
|
- FileEntity entity = fileServer.findById(fileId);
|
|
|
+// FileEntity entity = fileServer.findById(fileId);
|
|
|
+ OutputFileEntity entity = vectorServer.findById(fileId);
|
|
|
+
|
|
|
+ String fileName = StringUtils.substringBeforeLast(entity.getFileName(), ".");
|
|
|
+
|
|
|
+ String outPath = OUTPUT_FILE_PATH + "mbtiles";
|
|
|
+ FileUtils.createDir(outPath);
|
|
|
+ outPath = outPath +File.separator + fileName + ".mbtiles";
|
|
|
|
|
|
- String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
|
- String outputFile = OUTPUT_FILE_PATH + fileName + ".mbtiles";
|
|
|
|
|
|
String cmd = Command.VECTOR_SLICE_TIPPECANOE;
|
|
|
- cmd = cmd.replace("@inputFile", entity.getFileUrl());
|
|
|
- cmd = cmd.replace("@outputFile", outputFile);
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getGeojsonPath());
|
|
|
+ cmd = cmd.replace("@outputFile", outPath);
|
|
|
log.info("cmd: {}", cmd);
|
|
|
|
|
|
|
|
@@ -272,50 +300,55 @@ public class VectorController {
|
|
|
return new R(50005, MsgCode.E50005);
|
|
|
}
|
|
|
|
|
|
- FileEntity fileEntity = new FileEntity();
|
|
|
- fileEntity.setFileName(fileName + ".mbtiles");
|
|
|
- fileEntity.setFileUrl(outputFile);
|
|
|
- fileEntity.setCreateTime(new Date());
|
|
|
- fileEntity.setUpdateTime(new Date());
|
|
|
- fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
- fileEntity.setStatus(5);
|
|
|
-
|
|
|
- fileEntity = fileServer.save(fileEntity);
|
|
|
-
|
|
|
- return new R(200, fileEntity);
|
|
|
+// FileEntity fileEntity = new FileEntity();
|
|
|
+// fileEntity.setFileName(fileName + ".mbtiles");
|
|
|
+// fileEntity.setFileUrl(outputFile);
|
|
|
+// fileEntity.setCreateTime(new Date());
|
|
|
+// fileEntity.setUpdateTime(new Date());
|
|
|
+// fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
+// fileEntity.setStatus(5);
|
|
|
+//
|
|
|
+// fileEntity = fileServer.save(fileEntity);
|
|
|
+
|
|
|
+ entity.setSlicePath(outPath);
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ entity.setStatus(5);
|
|
|
+ entity = vectorServer.save(entity);
|
|
|
+
|
|
|
+ return new R(200, entity);
|
|
|
}
|
|
|
|
|
|
|
|
|
// 普通坐标转换
|
|
|
- private FileEntity generalCoordTransform(FileEntity entity, String cmd){
|
|
|
+ private OutputFileEntity generalCoordTransform(OutputFileEntity entity, String cmd){
|
|
|
|
|
|
String directory = createDirectory(entity);
|
|
|
directory = directory + File.separator + entity.getFileName();
|
|
|
|
|
|
- cmd = cmd.replace("@inputFile", entity.getFileUrl());
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getUploadPath());
|
|
|
cmd = cmd.replace("@outputFile", directory);
|
|
|
log.info("cmd: {}", cmd);
|
|
|
- return runCmd(cmd, entity, directory);
|
|
|
+ return runCmd(cmd, entity, directory, null);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 严格坐标转换
|
|
|
- private FileEntity strictCoordTransform(FileEntity entity, String cmd){
|
|
|
+ private OutputFileEntity strictCoordTransform(OutputFileEntity entity, String cmd){
|
|
|
|
|
|
String directory = createDirectory(entity);
|
|
|
directory = directory + File.separator + entity.getFileName();
|
|
|
|
|
|
cmd = cmd.replace("@coord", entity.getCoord());
|
|
|
- cmd = cmd.replace("@inputFile", entity.getFileUrl());
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getUploadPath());
|
|
|
cmd = cmd.replace("@outputFile", directory);
|
|
|
log.info("cmd: {}", cmd);
|
|
|
|
|
|
- return runCmd(cmd, entity, directory);
|
|
|
+ return runCmd(cmd, entity, null, directory);
|
|
|
}
|
|
|
|
|
|
// 创建目录
|
|
|
- private String createDirectory(FileEntity entity){
|
|
|
+ private String createDirectory(OutputFileEntity entity){
|
|
|
String fileName = StringUtils.substringBeforeLast(entity.getFileName(), ".");
|
|
|
String directory = INPUT_FILE_PATH + "transform" + File.separator + fileName;
|
|
|
FileUtils.createDir(directory);
|
|
@@ -323,23 +356,21 @@ public class VectorController {
|
|
|
}
|
|
|
|
|
|
// 执行命令,创建对象
|
|
|
- private FileEntity runCmd(String cmd, FileEntity entity, String filePath){
|
|
|
+ private OutputFileEntity runCmd(String cmd, OutputFileEntity entity, String generalPath, String strictPath){
|
|
|
Integer integer = cmdServer.exeCmdInt(cmd);
|
|
|
if (integer != 0) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- FileEntity fileEntity = new FileEntity();
|
|
|
- fileEntity.setFileName(entity.getFileName());
|
|
|
- fileEntity.setFileUrl(filePath);
|
|
|
- fileEntity.setCreateTime(new Date());
|
|
|
- fileEntity.setUpdateTime(new Date());
|
|
|
- fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
- fileEntity.setStatus(3);
|
|
|
+ entity.setFileName(entity.getFileName());
|
|
|
+ entity.setCoordGeneralPath(generalPath);
|
|
|
+ entity.setCoordStrictPath(strictPath);
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ entity.setStatus(3);
|
|
|
|
|
|
- fileEntity = fileServer.save(fileEntity);
|
|
|
+ entity = vectorServer.save(entity);
|
|
|
|
|
|
- return fileEntity;
|
|
|
+ return entity;
|
|
|
|
|
|
}
|
|
|
|