|
@@ -9,11 +9,9 @@ import com.fd.dto.PageDto;
|
|
import com.fd.entity.FileEntity;
|
|
import com.fd.entity.FileEntity;
|
|
import com.fd.entity.OutputFileEntity;
|
|
import com.fd.entity.OutputFileEntity;
|
|
import com.fd.server.CmdServer;
|
|
import com.fd.server.CmdServer;
|
|
-import com.fd.server.FileServer;
|
|
|
|
import com.fd.server.VectorServer;
|
|
import com.fd.server.VectorServer;
|
|
import com.fd.util.FileUtils;
|
|
import com.fd.util.FileUtils;
|
|
import com.fd.util.R;
|
|
import com.fd.util.R;
|
|
-import com.fd.util.RegexUtils;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.extern.log4j.Log4j2;
|
|
import lombok.extern.log4j.Log4j2;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -21,12 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
-import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.PostConstruct;
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
-import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.concurrent.BlockingQueue;
|
|
import java.util.concurrent.BlockingQueue;
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
@@ -42,16 +37,13 @@ import java.util.concurrent.TimeUnit;
|
|
@RestController
|
|
@RestController
|
|
public class VectorController {
|
|
public class VectorController {
|
|
|
|
|
|
- @Value("${input.file.path}")
|
|
|
|
|
|
+ @Value("${input.file.path.vector}")
|
|
private String INPUT_FILE_PATH;
|
|
private String INPUT_FILE_PATH;
|
|
|
|
|
|
- @Value("${output.file.path}")
|
|
|
|
|
|
+ @Value("${output.file.path.vector}")
|
|
private String OUTPUT_FILE_PATH;
|
|
private String OUTPUT_FILE_PATH;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private FileServer fileServer;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
private VectorServer vectorServer;
|
|
private VectorServer vectorServer;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -77,129 +69,45 @@ public class VectorController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-// @ApiOperation("上传矢量数据,coord:坐标, directoryName:目录名称")
|
|
|
|
|
|
+// @ApiOperation("上传矢量数据, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
|
|
// @PostMapping(value = "upload/{directoryName}/", consumes = { "multipart/form-data" })
|
|
// @PostMapping(value = "upload/{directoryName}/", consumes = { "multipart/form-data" })
|
|
-// private R upload(@RequestParam("file") MultipartFile file, @PathVariable("directoryName") String directoryName,
|
|
|
|
-// @RequestParam(value = "coord",required = false) String coord){
|
|
|
|
-// log.info("run upload");
|
|
|
|
-// 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,
|
|
// 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, ".");
|
|
|
|
|
|
+// @PathVariable("directoryName") String directoryName,
|
|
|
|
+// @RequestParam(value = "coord",required = false) String coord){
|
|
|
|
+// log.info("run uploadVector");
|
|
|
|
+// log.info("coord: {}", coord);
|
|
//
|
|
//
|
|
-// if (!"zip".equals(s)) {
|
|
|
|
-// return new R(50007,MsgCode.E50007);
|
|
|
|
|
|
+// // 文件是否包含中文字符
|
|
|
|
+// if (RegexUtils.regexChinese(file.getOriginalFilename())) {
|
|
|
|
+// return new R(51005, MsgCode.E51005);
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
-// return vectorServer.uploadFile(file, coord);
|
|
|
|
|
|
+//// FileEntity en = vectorServer.findByDirectory(directoryName);
|
|
|
|
+//// if (en != null){
|
|
|
|
+//// return new R(51006, MsgCode.E51006);
|
|
|
|
+//// }
|
|
|
|
+//
|
|
|
|
+// return vectorServer.uploadDirectoryFile(file, directoryName, 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,
|
|
|
|
- @RequestParam(value = "coord",required = false) String coord){
|
|
|
|
- log.info("run uploadVector");
|
|
|
|
|
|
+ @PostMapping(value = "uploadMult/{directoryName}", consumes = { "multipart/form-data" })
|
|
|
|
+ private R uploadMult(@RequestParam("file") MultipartFile[] file,
|
|
|
|
+ @PathVariable("directoryName") String directoryName,
|
|
|
|
+ @RequestParam(value = "coord",required = false) String coord){
|
|
|
|
+ log.info("run uploadMult");
|
|
log.info("coord: {}", coord);
|
|
log.info("coord: {}", coord);
|
|
|
|
|
|
- // 文件是否包含中文字符
|
|
|
|
- if (RegexUtils.regexChinese(file.getOriginalFilename())) {
|
|
|
|
- return new R(51005, MsgCode.E51005);
|
|
|
|
- }
|
|
|
|
|
|
|
|
-// FileEntity en = vectorServer.findByDirectory(directoryName);
|
|
|
|
-// if (en != null){
|
|
|
|
-// return new R(51006, MsgCode.E51006);
|
|
|
|
-// }
|
|
|
|
|
|
|
|
- return vectorServer.uploadDirectoryFile(file, directoryName, coord);
|
|
|
|
|
|
+ return vectorServer.uploadDirectoryFileMul(file, directoryName, coord);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-// @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,
|
|
|
|
-// @RequestParam(value = "coord",required = false) String coord){
|
|
|
|
-// log.info("run uploadVector");
|
|
|
|
-// log.info("coord: {}", coord);
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-// return vectorServer.uploadDirectoryFileMul(file, directoryName, coord);
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// @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("获取矢量数据列表")
|
|
@ApiOperation("获取矢量数据列表")
|
|
@PostMapping(value = "list")
|
|
@PostMapping(value = "list")
|
|
private R list(@RequestBody PageDto param){
|
|
private R list(@RequestBody PageDto param){
|
|
@@ -247,7 +155,8 @@ public class VectorController {
|
|
try {
|
|
try {
|
|
vectorCoordQueue.offer(data, 1, TimeUnit.SECONDS);
|
|
vectorCoordQueue.offer(data, 1, TimeUnit.SECONDS);
|
|
log.info("入队成功");
|
|
log.info("入队成功");
|
|
- } catch (InterruptedException e) {
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("error vector producer queue cmdJudgeCoord: {}", e);
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -256,6 +165,11 @@ public class VectorController {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 坐标判断消费队列
|
|
* 坐标判断消费队列
|
|
|
|
+ *
|
|
|
|
+ * 矢量数据转坐标只转一次就成功了。
|
|
|
|
+ * 所以转换的成功的路径都放到strictCoordTransform 路径
|
|
|
|
+ * 文件都放transform 目录
|
|
|
|
+ *
|
|
*/
|
|
*/
|
|
public class VectorJudgeCoordConsumerThread implements Runnable{
|
|
public class VectorJudgeCoordConsumerThread implements Runnable{
|
|
|
|
|
|
@@ -270,13 +184,14 @@ public class VectorController {
|
|
public void run() {
|
|
public void run() {
|
|
log.info("run VectorJudgeCoordConsumerThread 出队");
|
|
log.info("run VectorJudgeCoordConsumerThread 出队");
|
|
while (true) {
|
|
while (true) {
|
|
|
|
+ OutputFileEntity entity = null;
|
|
try {
|
|
try {
|
|
MyQueue data = queue.poll(2, TimeUnit.SECONDS);
|
|
MyQueue data = queue.poll(2, TimeUnit.SECONDS);
|
|
if (data != null) {
|
|
if (data != null) {
|
|
log.info("消费者,拿到队列中的数据data: " + data.toString());
|
|
log.info("消费者,拿到队列中的数据data: " + data.toString());
|
|
|
|
|
|
Integer isJudge = cmdServer.exeCmdJudgeCoord(data.getStr());
|
|
Integer isJudge = cmdServer.exeCmdJudgeCoord(data.getStr());
|
|
- OutputFileEntity entity = data.getOutputFile();
|
|
|
|
|
|
+ entity = data.getOutputFile();
|
|
|
|
|
|
// 转换坐标 普通坐标转换
|
|
// 转换坐标 普通坐标转换
|
|
if (isJudge == 1000){
|
|
if (isJudge == 1000){
|
|
@@ -307,8 +222,26 @@ public class VectorController {
|
|
entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
|
|
entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
|
|
}
|
|
}
|
|
|
|
|
|
- } else if (0 == isJudge){ // 不转换坐标
|
|
|
|
|
|
+ } else if (0 == isJudge){
|
|
|
|
+ // 不转换坐标 把文件信息移动到CoordStrictPath 这路径下
|
|
log.info("not to transform");
|
|
log.info("not to transform");
|
|
|
|
+
|
|
|
|
+ // 若果改成用一张表,这里需要修改
|
|
|
|
+// FileEntity fileEntity = vectorServer.findByFileName(entity.getFileName());
|
|
|
|
+//
|
|
|
|
+// String shpPath = OUTPUT_FILE_PATH + "transform" + File.separator + fileEntity.getDirectory();
|
|
|
|
+// FileUtils.createDir(shpPath);
|
|
|
|
+// shpPath = shpPath + "transform" + File.separator + entity.getFileName();
|
|
|
|
+// entity.setCoordStrictPath(shpPath);
|
|
|
|
+//
|
|
|
|
+// try {
|
|
|
|
+// String uploadPath = entity.getUploadPath();
|
|
|
|
+// uploadPath= StringUtils.substringBeforeLast(uploadPath, "/");
|
|
|
|
+// org.apache.commons.io.FileUtils.copyDirectoryToDirectory(new File(uploadPath), new File(OUTPUT_FILE_PATH + "transform"));
|
|
|
|
+// } catch (IOException e) {
|
|
|
|
+// e.printStackTrace();
|
|
|
|
+// }
|
|
|
|
+ entity.setCoordStrictPath(entity.getUploadPath());
|
|
entity.setUpdateTime(new Date());
|
|
entity.setUpdateTime(new Date());
|
|
entity.setStatus(3);
|
|
entity.setStatus(3);
|
|
vectorServer.save(entity);
|
|
vectorServer.save(entity);
|
|
@@ -320,9 +253,16 @@ public class VectorController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Thread.sleep(4000);
|
|
// Thread.sleep(4000);
|
|
- } catch (InterruptedException e) {
|
|
|
|
-// isRun = false;
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ //出现异常了,修改修改状态
|
|
|
|
+ entity.setStatus(7);
|
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
|
+ vectorServer.save(entity);
|
|
|
|
+
|
|
|
|
+ log.error("error vector consume queue VectorJudgeCoordConsumerThread: {}", e);
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -337,21 +277,14 @@ public class VectorController {
|
|
String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
// // 截取目录名称
|
|
// // 截取目录名称
|
|
|
|
|
|
- String outPath = OUTPUT_FILE_PATH + "geojson";
|
|
|
|
|
|
+ String outPath = OUTPUT_FILE_PATH + "geojson" + File.separator + entity.getDirectory();
|
|
FileUtils.createDir(outPath);
|
|
FileUtils.createDir(outPath);
|
|
outPath = outPath +File.separator + fileName + ".json";
|
|
outPath = outPath +File.separator + fileName + ".json";
|
|
|
|
|
|
String cmd = Command.VECTOR_TO_GEOJSON;
|
|
String cmd = Command.VECTOR_TO_GEOJSON;
|
|
if (entity.getCoordStrictPath() != null) {
|
|
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("@inputFile", entity.getCoordStrictPath());
|
|
}
|
|
}
|
|
|
|
|
|
cmd = cmd.replace("@outputFile", outPath);
|
|
cmd = cmd.replace("@outputFile", outPath);
|
|
@@ -376,18 +309,11 @@ public class VectorController {
|
|
@GetMapping("command/slice/{fileId}/")
|
|
@GetMapping("command/slice/{fileId}/")
|
|
private R cmdSlice (@PathVariable("fileId") Long fileId) {
|
|
private R cmdSlice (@PathVariable("fileId") Long fileId) {
|
|
log.info("run cmdSlice: {}", fileId);
|
|
log.info("run cmdSlice: {}", fileId);
|
|
-// FileEntity entity = fileServer.findById(fileId);
|
|
|
|
- OutputFileEntity entity = vectorServer.findById(fileId);
|
|
|
|
|
|
|
|
- String fileName = StringUtils.substringBeforeLast(entity.getFileName(), ".");
|
|
|
|
|
|
+ OutputFileEntity entity = vectorServer.findById(fileId);
|
|
|
|
|
|
- // 如果是全局修改输出目录,这里要注意修改
|
|
|
|
- String outPath = OUTPUT_FILE_PATH + "vector/slice";
|
|
|
|
-// String outPath = OUTPUT_FILE_PATH + "mbtiles";
|
|
|
|
|
|
+ String outPath = OUTPUT_FILE_PATH + "slice" + File.separator + entity.getDirectory();
|
|
FileUtils.createDir(outPath);
|
|
FileUtils.createDir(outPath);
|
|
-// outPath = outPath +File.separator + fileName + ".mbtiles";
|
|
|
|
- outPath = outPath +File.separator + fileName;
|
|
|
|
-
|
|
|
|
|
|
|
|
String cmd = Command.VECTOR_SLICE_TIPPECANOE;
|
|
String cmd = Command.VECTOR_SLICE_TIPPECANOE;
|
|
cmd = cmd.replace("@inputFile", entity.getGeojsonPath());
|
|
cmd = cmd.replace("@inputFile", entity.getGeojsonPath());
|
|
@@ -425,7 +351,8 @@ public class VectorController {
|
|
cmd = cmd.replace("@inputFile", entity.getUploadPath());
|
|
cmd = cmd.replace("@inputFile", entity.getUploadPath());
|
|
cmd = cmd.replace("@outputFile", directory);
|
|
cmd = cmd.replace("@outputFile", directory);
|
|
log.info("cmd: {}", cmd);
|
|
log.info("cmd: {}", cmd);
|
|
- return runCmd(cmd, entity, directory, null);
|
|
|
|
|
|
+// return runCmd(cmd, entity, directory, null);
|
|
|
|
+ return runCmd(cmd, entity, null, directory);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -446,9 +373,7 @@ public class VectorController {
|
|
|
|
|
|
// 创建目录
|
|
// 创建目录
|
|
private String createDirectory(OutputFileEntity entity){
|
|
private String createDirectory(OutputFileEntity entity){
|
|
- String fileName = StringUtils.substringBeforeLast(entity.getFileName(), ".");
|
|
|
|
-// String directory = INPUT_FILE_PATH + "transform" + File.separator + fileName;
|
|
|
|
- String directory = OUTPUT_FILE_PATH + "transform" + File.separator + fileName;
|
|
|
|
|
|
+ String directory = OUTPUT_FILE_PATH + "transform" + File.separator + entity.getDirectory();
|
|
FileUtils.createDir(directory);
|
|
FileUtils.createDir(directory);
|
|
return directory;
|
|
return directory;
|
|
}
|
|
}
|