|
@@ -10,9 +10,11 @@ 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;
|
|
@@ -31,8 +33,11 @@ import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
@@ -72,6 +77,9 @@ public class VectorServerImpl implements VectorServer {
|
|
|
@Autowired
|
|
|
private StyleRepository styleRepository;
|
|
|
|
|
|
+// @Autowired
|
|
|
+// private LayerRepository layerRepository;
|
|
|
+
|
|
|
@Override
|
|
|
public R moveFileToServer(Long fileId, ConfigJsonDto param) {
|
|
|
Optional<OutputFileEntity> o = outputFileRepository.findById(fileId);
|
|
@@ -85,7 +93,7 @@ public class VectorServerImpl implements VectorServer {
|
|
|
try {
|
|
|
org.apache.commons.io.FileUtils.copyDirectoryToDirectory(new File(entity.getSlicePath()), new File(MOVE_FILE_TO_SERVER));
|
|
|
// 修改前端的config.json 文件
|
|
|
- writeJsonFile(param, entity.getDirectory());
|
|
|
+ writeJsonFile(param, entity.getDirectory(), entity);
|
|
|
|
|
|
//修改linux 文件权限
|
|
|
String cmd = Command.CMD_CHOMD_755;
|
|
@@ -330,20 +338,153 @@ public class VectorServerImpl implements VectorServer {
|
|
|
|
|
|
@Override
|
|
|
public R saveStyle(StyleDto entity) {
|
|
|
- StyleEntity styleEntity = new StyleEntity();
|
|
|
- BeanUtils.copyProperties(entity, styleEntity);
|
|
|
- styleEntity.setCreateTime(new Date());
|
|
|
+// StyleEntity styleEntity = new StyleEntity();
|
|
|
+ StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(entity.getOutputFileId());
|
|
|
+
|
|
|
+
|
|
|
+// BeanUtils.copyProperties(entity, styleEntity);
|
|
|
styleEntity.setUpdateTime(new Date());
|
|
|
+ styleEntity.setContent(entity.getContent());
|
|
|
StyleEntity save = styleRepository.save(styleEntity);
|
|
|
return new R(200, save.getOutputFileId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public StyleEntity saveStyle(StyleEntity entity) {
|
|
|
+ return styleRepository.save(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public R getStyle(Long id) {
|
|
|
return new R(200, styleRepository.findByOutputFileIdTop(id));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public Map cmdJudgeCoord(String commandStr) {
|
|
|
+ // 命令运行结果 1:失败, 0:成功
|
|
|
+ Integer isCmd = null;
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // success ,没有获取到信息
|
|
|
+ String line;
|
|
|
+ while ((line = br.readLine()) != null) {
|
|
|
+ //执行结果加上回车
|
|
|
+ sb.append(line).append("\n");
|
|
|
+ // 获取经纬度
|
|
|
+
|
|
|
+ if (line.contains("Extent: (")){
|
|
|
+ log.info("extent: {}", line);
|
|
|
+ map = getExtent(line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("result: {}", sb.toString());
|
|
|
+
|
|
|
+ // 结束命令行
|
|
|
+ isCmd = ps.waitFor();
|
|
|
+ map.put("code", isCmd);
|
|
|
+
|
|
|
+ // 关闭流
|
|
|
+ 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;
|
|
|
+ log.info("需要坐标转换code:{}, GEOGCS[\"China Geodetic Coordinate System 2000\"", isCmd);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (sb.toString().contains("GEOGCS[\"Xian 1980\"")) {
|
|
|
+ // 需要严格坐标转换
|
|
|
+ isCmd = 1001;
|
|
|
+ log.info("需要严格坐标转换code:{}, GEOGCS[\"Xian 1980\"", isCmd);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (sb.toString().contains("GEOGCS[\"WGS 84\"")) {
|
|
|
+ // 不需要坐标转换
|
|
|
+ isCmd = 0;
|
|
|
+ log.info("不需要坐标转换code:{}, GEOGCS[\"WGS 84\"", isCmd);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 获取经纬度
|
|
|
+ if (sb.toString().contains("Extent: (")) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ log.info("error exeCmd wsitFore: {}", isCmd);
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取经纬度平均值
|
|
|
+ * @param str 传入参数
|
|
|
+ * @return map
|
|
|
+ */
|
|
|
+ private Map getExtent(String str){
|
|
|
+
|
|
|
+ str = str.replace("Extent: (", "");
|
|
|
+ str = str.replaceAll("\\(", "");
|
|
|
+ str = str.replaceAll("\\)", "");
|
|
|
+ str = str.replaceAll(" -", ",");
|
|
|
+
|
|
|
+ // 去除所有空白字符
|
|
|
+ str = StringUtils.deleteWhitespace(str);
|
|
|
+ String[] strArray = str.split(",");
|
|
|
+ List<String> list = Arrays.asList(strArray);
|
|
|
+ log.info("extent list: {}", Arrays.asList(strArray));
|
|
|
+
|
|
|
+ BigDecimal b0 = new BigDecimal(list.get(0));
|
|
|
+ BigDecimal b1 = new BigDecimal(list.get(1));
|
|
|
+ BigDecimal b2 = new BigDecimal(list.get(2));
|
|
|
+ BigDecimal b3 = new BigDecimal(list.get(3));
|
|
|
+
|
|
|
+ // 经度
|
|
|
+ BigDecimal longitude = b0.add(b2);
|
|
|
+ longitude = longitude.divide(new BigDecimal(2), 6, BigDecimal.ROUND_HALF_UP);
|
|
|
+ // 纬度
|
|
|
+ BigDecimal latitude = b1.add(b3);
|
|
|
+ latitude = latitude.divide(new BigDecimal(2), 6, BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+ HashMap<Object, Object> map = new HashMap<>();
|
|
|
+ map.put("longitude", longitude);
|
|
|
+ map.put("latitude", latitude);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public OutputFileEntity findById(Long fileId) {
|
|
|
Optional<OutputFileEntity> o = outputFileRepository.findById(fileId);
|
|
|
if (o.isPresent()) {
|
|
@@ -361,7 +502,7 @@ public class VectorServerImpl implements VectorServer {
|
|
|
/**
|
|
|
* 修改config.json
|
|
|
*/
|
|
|
- private void writeJsonFile(ConfigJsonDto param, String lastName) {
|
|
|
+ private void writeJsonFile(ConfigJsonDto param, String lastName, OutputFileEntity entity) {
|
|
|
String s = FileUtils.readFile(CONFIG_JSON_PATH);
|
|
|
|
|
|
JSONObject original = JSON.parseObject(s);
|
|
@@ -372,20 +513,32 @@ public class VectorServerImpl implements VectorServer {
|
|
|
|
|
|
JSONObject subJson = new JSONObject();
|
|
|
long cu = System.currentTimeMillis();
|
|
|
- subJson.put("name", "vector_" + cu); // 需要唯一
|
|
|
+ // 需要唯一
|
|
|
+ subJson.put("name", "vector_" + cu);
|
|
|
+
|
|
|
subJson.put("text", param.getText());
|
|
|
- subJson.put("type", "geodata"); // vector 就用这个类型geodata
|
|
|
+ // vector 就用这个类型geodata
|
|
|
+ subJson.put("type", "geodata");
|
|
|
subJson.put("checked", false);
|
|
|
subJson.put("show", true);
|
|
|
subJson.put("url", "../data/" + lastName);
|
|
|
-
|
|
|
layers.add(subJson);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
original.put("layers", layers);
|
|
|
|
|
|
log.info("original update: {}", original.toJSONString());
|
|
|
try {
|
|
|
FileUtils.fileWriter(JSON.toJSONString(original), CONFIG_JSON_PATH);
|
|
|
+
|
|
|
+ // 将图层信息保存到db
|
|
|
+
|
|
|
+ StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(entity.getId());
|
|
|
+ styleEntity.setLayer(subJson.toJSONString());
|
|
|
+ styleEntity.setUpdateTime(new Date());
|
|
|
+ styleRepository.save(styleEntity);
|
|
|
+
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|