|
@@ -10,11 +10,9 @@ import com.fd.dto.ConfigJsonDto;
|
|
|
import com.fd.dto.PageDto;
|
|
|
import com.fd.dto.StyleDto;
|
|
|
import com.fd.entity.FileEntity;
|
|
|
-//import com.fd.entity.LayerEntity;
|
|
|
import com.fd.entity.OutputFileEntity;
|
|
|
import com.fd.entity.StyleEntity;
|
|
|
import com.fd.repository.FileRepository;
|
|
|
-//import com.fd.repository.LayerRepository;
|
|
|
import com.fd.repository.OutputFileRepository;
|
|
|
import com.fd.repository.StyleRepository;
|
|
|
import com.fd.server.CmdServer;
|
|
@@ -32,7 +30,6 @@ import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import javax.transaction.Transactional;
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
@@ -46,7 +43,7 @@ import java.util.*;
|
|
|
*/
|
|
|
@Log4j2
|
|
|
@Service
|
|
|
-@Transactional
|
|
|
+//@Transactional
|
|
|
public class VectorServerImpl implements VectorServer {
|
|
|
|
|
|
@Value("${input.file.path.vector}")
|
|
@@ -147,23 +144,39 @@ public class VectorServerImpl implements VectorServer {
|
|
|
|
|
|
// 文件类型
|
|
|
if (entity.getGeojsonPath() != null) {
|
|
|
+ log.info("test file geojson");
|
|
|
String path = entity.getGeojsonPath();
|
|
|
deleteFolder(path, entity);
|
|
|
}
|
|
|
|
|
|
if (entity.getSlicePath() != null) {
|
|
|
- FileUtils.delFolder(entity.getSlicePath());
|
|
|
+ log.info("test file getSlicePath");
|
|
|
+ File file = new File(entity.getSlicePath());
|
|
|
+ if (file.exists()) {
|
|
|
+ log.info("test file ");
|
|
|
+ FileUtils.delFolder(entity.getSlicePath());
|
|
|
+ }
|
|
|
+ log.info("test file getSlicePath ok");
|
|
|
}
|
|
|
|
|
|
// 目录类型
|
|
|
if (entity.getServicePath() != null) {
|
|
|
- FileUtils.delFolder(entity.getServicePath());
|
|
|
+ log.info("test file getServicePath");
|
|
|
+
|
|
|
+ File file = new File(entity.getServicePath());
|
|
|
+ if (file.exists()) {
|
|
|
+ log.info("test file ");
|
|
|
+ FileUtils.delFolder(entity.getServicePath());
|
|
|
+ }
|
|
|
+ log.info("test file getServicePath ok");
|
|
|
}
|
|
|
|
|
|
|
|
|
// 删除配置文件config.json制定行
|
|
|
StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(fileId);
|
|
|
- deleteRowConfigJson(styleEntity);
|
|
|
+ if (styleEntity != null) {
|
|
|
+ deleteRowConfigJson(styleEntity);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// 删除数据库记录
|
|
@@ -177,11 +190,12 @@ public class VectorServerImpl implements VectorServer {
|
|
|
|
|
|
|
|
|
// 以目录形式删除
|
|
|
- private void deleteFolder(String path, OutputFileEntity entity){
|
|
|
+ private void deleteFolder(String path, OutputFileEntity entity) {
|
|
|
String directory = entity.getDirectory();
|
|
|
int length = directory.length();
|
|
|
- path = path.substring(0, path.lastIndexOf(directory)+length);
|
|
|
+ path = path.substring(0, path.lastIndexOf(directory) + length);
|
|
|
log.warn("delete vector file: {}", path);
|
|
|
+
|
|
|
FileUtils.delFolder(path);
|
|
|
}
|
|
|
|
|
@@ -247,7 +261,7 @@ public class VectorServerImpl implements VectorServer {
|
|
|
|
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
- log.info("end uploadBigFile, total time: {} s", (end - start)/1000);
|
|
|
+ log.info("end uploadBigFile, total time: {} s", (end - start) / 1000);
|
|
|
return new R(200, outputFile);
|
|
|
}
|
|
|
|
|
@@ -259,7 +273,7 @@ public class VectorServerImpl implements VectorServer {
|
|
|
|
|
|
// 判断目录重名
|
|
|
List<FileEntity> en = fileRepository.findByDirectory(directoryName);
|
|
|
- if (en.size() > 0){
|
|
|
+ if (en.size() > 0) {
|
|
|
return new R(51007, MsgCode.E51007);
|
|
|
}
|
|
|
|
|
@@ -271,58 +285,87 @@ public class VectorServerImpl implements VectorServer {
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ // 检查文件名、格式
|
|
|
+ int suffixCheckInt = 0;
|
|
|
+ HashSet<Object> setPrefix = new HashSet<>();
|
|
|
+
|
|
|
+ // 记录shp 信息
|
|
|
+ boolean shpFlag = false;
|
|
|
String shpName = "";
|
|
|
|
|
|
if (files != null && files.length > 0) {
|
|
|
- for (MultipartFile f: files) {
|
|
|
+ for (MultipartFile f : files) {
|
|
|
String filename = f.getOriginalFilename();
|
|
|
|
|
|
// 文件是否包含中文字符
|
|
|
- if (RegexUtils.regexChinese(filename)) {
|
|
|
- return new R(51005, MsgCode.E51005);
|
|
|
- }
|
|
|
+ if (RegexUtils.regexChinese(filename)) {
|
|
|
+ return new R(51005, MsgCode.E51005);
|
|
|
+ }
|
|
|
|
|
|
log.info("fileName : {}", filename);
|
|
|
String s = StringUtils.substringAfterLast(filename, ".");
|
|
|
- if ("shp".equals(s)){
|
|
|
- shpName = filename;
|
|
|
- entity.setDirectory(directoryName);
|
|
|
- entity.setFileUrl(filePath + filename);
|
|
|
- entity.setCreateTime(new Date());
|
|
|
- entity.setUpdateTime(new Date());
|
|
|
- entity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
- entity.setCoord(coord);
|
|
|
- entity = fileRepository.save(entity);
|
|
|
|
|
|
+ // 判断后缀名,需要包含这以下四个
|
|
|
+ String [] suffixCheck = {"dbf","shp","shx","prj"};
|
|
|
+ if (Arrays.asList(suffixCheck).contains(s)) {
|
|
|
+ suffixCheckInt += 1;
|
|
|
}
|
|
|
+
|
|
|
+ // 判断前缀名字是否一致
|
|
|
+ String prefix = StringUtils.substringBeforeLast(filename, ".");
|
|
|
+ setPrefix.add(prefix);
|
|
|
+
|
|
|
+ if ("shp".equals(s)) {
|
|
|
+ shpFlag = true;
|
|
|
+ shpName = filename;
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
- FileUtils.bigFileWrite(f.getInputStream(), filePath + filename);
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ FileUtils.bigFileWrite(f.getInputStream(), filePath + filename);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
sb.append(filename).append(",");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- entity.setFileName(sb.toString());
|
|
|
- entity.setUpdateTime(new Date());
|
|
|
- entity = fileRepository.save(entity);
|
|
|
+ // 上传文件名是否一致
|
|
|
+ if (setPrefix.size() > 1) {
|
|
|
|
|
|
- OutputFileEntity outputFile = new OutputFileEntity();
|
|
|
+ log.info("文件名前缀不一致");
|
|
|
+ return new R(51008, MsgCode.E51008);
|
|
|
+ }
|
|
|
|
|
|
- outputFile = new OutputFileEntity();
|
|
|
- outputFile.setUploadId(entity.getId());
|
|
|
- outputFile.setUploadPath(entity.getFileUrl());
|
|
|
- outputFile.setDirectory(entity.getDirectory());
|
|
|
- outputFile.setFileName(shpName);
|
|
|
- outputFile.setStatus(2);
|
|
|
- outputFile.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
- outputFile.setCoord(entity.getCoord());
|
|
|
- outputFile.setCreateTime(new Date());
|
|
|
- outputFile.setUpdateTime(new Date());
|
|
|
+ // 上传文件格式有误
|
|
|
+ if (suffixCheckInt != 4) {
|
|
|
+ log.info("文件后缀名有误");
|
|
|
+ return new R(51008, MsgCode.E51008);
|
|
|
+ }
|
|
|
|
|
|
- outputFile = outputFileRepository.save(outputFile);
|
|
|
+ OutputFileEntity outputFile = new OutputFileEntity();
|
|
|
+ if (shpFlag) {
|
|
|
+ entity.setDirectory(directoryName);
|
|
|
+ entity.setFileName(sb.toString());
|
|
|
+ entity.setFileUrl(filePath + shpName);
|
|
|
+ entity.setCreateTime(new Date());
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ entity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
+ entity.setCoord(coord);
|
|
|
+ entity = fileRepository.save(entity);
|
|
|
|
|
|
+ outputFile.setUploadId(entity.getId());
|
|
|
+ outputFile.setUploadPath(entity.getFileUrl());
|
|
|
+ outputFile.setDirectory(entity.getDirectory());
|
|
|
+ outputFile.setFileName(shpName);
|
|
|
+ outputFile.setStatus(2);
|
|
|
+ outputFile.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
+ outputFile.setCoord(entity.getCoord());
|
|
|
+ outputFile.setCreateTime(new Date());
|
|
|
+ outputFile.setUpdateTime(new Date());
|
|
|
+ outputFile = outputFileRepository.save(outputFile);
|
|
|
+ }
|
|
|
return new R(200, outputFile);
|
|
|
}
|
|
|
|
|
@@ -393,98 +436,181 @@ public class VectorServerImpl implements VectorServer {
|
|
|
|
|
|
@Override
|
|
|
public Map cmdJudgeCoord(String commandStr) {
|
|
|
- // 命令运行结果 1:失败, 0:成功
|
|
|
- Integer isCmd = null;
|
|
|
+ // 命令运行结果 1:失败, 0:成功
|
|
|
+ Integer isCmd = null;
|
|
|
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- StringBuffer errorStr = new StringBuffer();
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ StringBuffer errorStr = new StringBuffer();
|
|
|
|
|
|
- Map map = null;
|
|
|
- try {
|
|
|
- String[] cmd = new String[]{"/bin/sh", "-c", commandStr};
|
|
|
- Process ps = Runtime.getRuntime().exec(cmd);
|
|
|
+ Map map = null;
|
|
|
+ try {
|
|
|
+ String[] cmd = new String[]{"/bin/sh", "-c", commandStr};
|
|
|
+ Process ps = Runtime.getRuntime().exec(cmd);
|
|
|
|
|
|
- BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
|
|
|
- BufferedReader errorBuf = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
|
|
|
+ BufferedReader errorBuf = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
|
|
|
|
|
|
- // error : 坑, 控制台信息是从errorBuf这里出来的
|
|
|
- String errorLine;
|
|
|
- while ((errorLine = errorBuf.readLine()) != null) {
|
|
|
- errorStr.append(errorLine).append("\n");
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(errorStr)){
|
|
|
- log.info("error result: {}", errorStr.toString());
|
|
|
- }
|
|
|
+ // error : 坑, 控制台信息是从errorBuf这里出来的
|
|
|
+ String errorLine;
|
|
|
+ while ((errorLine = errorBuf.readLine()) != null) {
|
|
|
+ errorStr.append(errorLine).append("\n");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(errorStr)) {
|
|
|
+ log.info("error result: {}", errorStr.toString());
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- // success ,没有获取到信息
|
|
|
- String line;
|
|
|
- while ((line = br.readLine()) != null) {
|
|
|
- //执行结果加上回车
|
|
|
- sb.append(line).append("\n");
|
|
|
- // 获取经纬度
|
|
|
+ // success ,没有获取到信息
|
|
|
+ String line;
|
|
|
+ while ((line = br.readLine()) != null) {
|
|
|
+ //执行结果加上回车
|
|
|
+ sb.append(line).append("\n");
|
|
|
+ // 获取经纬度
|
|
|
|
|
|
- if (line.contains("Extent: (")){
|
|
|
- log.info("extent: {}", line);
|
|
|
- map = getExtent(line);
|
|
|
- }
|
|
|
+ if (line.contains("Extent: (")) {
|
|
|
+ log.info("extent: {}", line);
|
|
|
+ map = getExtent(line);
|
|
|
}
|
|
|
- log.info("result: {}", sb.toString());
|
|
|
+ }
|
|
|
+ log.info("result: {}", sb.toString());
|
|
|
+
|
|
|
+ // 结束命令行
|
|
|
+ isCmd = ps.waitFor();
|
|
|
|
|
|
- // 结束命令行
|
|
|
- isCmd = ps.waitFor();
|
|
|
|
|
|
+ // 关闭流
|
|
|
+ br.close();
|
|
|
+ errorBuf.close();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
|
|
|
- // 关闭流
|
|
|
- br.close();
|
|
|
- errorBuf.close();
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ if (isCmd == 0) {
|
|
|
+ log.info("end exeCmd : {}", isCmd);
|
|
|
+ // 判断坐标
|
|
|
+ if (sb.toString().contains("GEOGCS[\"China Geodetic Coordinate System 2000\"")) {
|
|
|
+ // 需要普通坐标转换
|
|
|
+ isCmd = 1000;
|
|
|
+ map.put("code", isCmd);
|
|
|
+ log.info("需要坐标转换code:{}, GEOGCS[\"China Geodetic Coordinate System 2000\"", isCmd);
|
|
|
}
|
|
|
|
|
|
+ if (sb.toString().contains("GEOGCS[\"Xian 1980\"")) {
|
|
|
+ // 需要严格坐标转换
|
|
|
+ isCmd = 1001;
|
|
|
+ map.put("code", isCmd);
|
|
|
+ log.info("需要严格坐标转换code:{}, GEOGCS[\"Xian 1980\"", isCmd);
|
|
|
+ }
|
|
|
|
|
|
- if (isCmd == 0) {
|
|
|
- log.info("end exeCmd : {}", isCmd);
|
|
|
- // 判断坐标
|
|
|
- if (sb.toString().contains("GEOGCS[\"China Geodetic Coordinate System 2000\"")) {
|
|
|
- // 需要普通坐标转换
|
|
|
- isCmd = 1000;
|
|
|
- map.put("code", isCmd);
|
|
|
- log.info("需要坐标转换code:{}, GEOGCS[\"China Geodetic Coordinate System 2000\"", isCmd);
|
|
|
- }
|
|
|
+ if (sb.toString().contains("GEOGCS[\"WGS 84\"")) {
|
|
|
+ // 不需要坐标转换
|
|
|
+ isCmd = 0;
|
|
|
+ map.put("code", isCmd);
|
|
|
+ log.info("不需要坐标转换code:{}, GEOGCS[\"WGS 84\"", isCmd);
|
|
|
+ }
|
|
|
|
|
|
- if (sb.toString().contains("GEOGCS[\"Xian 1980\"")) {
|
|
|
- // 需要严格坐标转换
|
|
|
- isCmd = 1001;
|
|
|
- map.put("code", isCmd);
|
|
|
- log.info("需要严格坐标转换code:{}, GEOGCS[\"Xian 1980\"", isCmd);
|
|
|
- }
|
|
|
|
|
|
- if (sb.toString().contains("GEOGCS[\"WGS 84\"")) {
|
|
|
- // 不需要坐标转换
|
|
|
- isCmd = 0;
|
|
|
- map.put("code", isCmd);
|
|
|
- log.info("不需要坐标转换code:{}, GEOGCS[\"WGS 84\"", isCmd);
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ map.put("code", isCmd);
|
|
|
+ log.info("error exeCmd wsitFore: {}", isCmd);
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
- map.put("code", isCmd);
|
|
|
- log.info("error exeCmd wsitFore: {}", isCmd);
|
|
|
+ /**
|
|
|
+ * 这个进度输出是从getErrorStream 输出
|
|
|
+ * @param commandStr
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Integer cmdSlice(String commandStr, OutputFileEntity entity) {
|
|
|
+ log.info("run vector cmdSlice");
|
|
|
+ // 命令运行结果 1:失败, 0:成功
|
|
|
+ Integer isCmd = null;
|
|
|
+ try {
|
|
|
+ String[] cmd = new String[]{"/bin/sh", "-c", commandStr};
|
|
|
+ Process ps = Runtime.getRuntime().exec(cmd);
|
|
|
+
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
|
|
|
+ BufferedReader errorBuf = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
|
|
|
+
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ StringBuffer errorStr = new StringBuffer();
|
|
|
+ // error : 坑, 控制台信息是从errorBuf这里出来的
|
|
|
+ String errorLine;
|
|
|
+ while ((errorLine = errorBuf.readLine()) != null) {
|
|
|
+ errorStr.append(errorLine).append("\n");
|
|
|
+ log.info("error: {}", errorLine);
|
|
|
+
|
|
|
+ // 获取进度
|
|
|
+ if (errorLine.contains("%")) {
|
|
|
+ String s = StringUtils.substringBefore(errorLine, "%");
|
|
|
+ // 去除空白字符串
|
|
|
+ s = StringUtils.deleteWhitespace(s);
|
|
|
+
|
|
|
+ // 只有是数字的
|
|
|
+ if (RegexUtils.regexInt(s)) {
|
|
|
+
|
|
|
+ Integer round = (int) Math.round(Double.valueOf(s));
|
|
|
+ log.info("round: {}", round);
|
|
|
+ if (round % 5 == 0 ) {
|
|
|
+ log.info("round1: {}", round);
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ entity.setProgress(round - 1);
|
|
|
+ if (s.equals("99.9")) {
|
|
|
+ entity.setProgress(100);
|
|
|
+ }
|
|
|
+ outputFileRepository.save(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(errorStr)){
|
|
|
+ log.info("error result: {}", errorStr.toString());
|
|
|
+ }
|
|
|
+ // success ,没有获取到信息
|
|
|
+ String line;
|
|
|
+ while ((line = br.readLine()) != null) {
|
|
|
+ //执行结果加上回车
|
|
|
+ sb.append(line).append("\n");
|
|
|
+ log.info("data: {}", line);
|
|
|
}
|
|
|
+ log.info("result: {}", sb.toString());
|
|
|
+ // 结束命令行
|
|
|
+ isCmd = ps.waitFor();
|
|
|
|
|
|
- return map;
|
|
|
+ // 关闭流
|
|
|
+ br.close();
|
|
|
+ errorBuf.close();
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isCmd == 0) {
|
|
|
+ log.info("end exeCmd : {}", isCmd);
|
|
|
+ } else {
|
|
|
+ log.info("wsitFore cmd run error : {}", isCmd);
|
|
|
+ }
|
|
|
+ return isCmd;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取经纬度平均值
|
|
|
+ *
|
|
|
* @param str 传入参数
|
|
|
* @return map
|
|
|
*/
|
|
|
- private Map getExtent(String str){
|
|
|
+ private Map getExtent(String str) {
|
|
|
|
|
|
str = str.replace("Extent: (", "");
|
|
|
str = str.replaceAll("\\(", "");
|
|
@@ -585,7 +711,7 @@ public class VectorServerImpl implements VectorServer {
|
|
|
/**
|
|
|
* 删除指定行的config.json 数据
|
|
|
*/
|
|
|
- private void deleteRowConfigJson(StyleEntity entity){
|
|
|
+ private void deleteRowConfigJson(StyleEntity entity) {
|
|
|
String s = FileUtils.readFile(CONFIG_JSON_PATH);
|
|
|
JSONObject original = JSON.parseObject(s);
|
|
|
log.info("original: {}", s);
|
|
@@ -618,7 +744,7 @@ public class VectorServerImpl implements VectorServer {
|
|
|
* 编辑样式,指定行的config.json 数据
|
|
|
* 添加样式
|
|
|
*/
|
|
|
- private void editStyleConfigJson(StyleEntity entity){
|
|
|
+ private void editStyleConfigJson(StyleEntity entity) {
|
|
|
String s = FileUtils.readFile(CONFIG_JSON_PATH);
|
|
|
JSONObject original = JSON.parseObject(s);
|
|
|
log.info("original: {}", s);
|
|
@@ -630,7 +756,7 @@ public class VectorServerImpl implements VectorServer {
|
|
|
if (o.getString("name").equals(entity.getName())) {
|
|
|
log.warn("old sytle: {}", o.toJSONString());
|
|
|
//修改样式
|
|
|
- o.put("style",JSON.parse(entity.getContent()));
|
|
|
+ o.put("style", JSON.parse(entity.getContent()));
|
|
|
}
|
|
|
}
|
|
|
log.warn("update sytle: {}", layers.toJSONString());
|