|
@@ -5,12 +5,14 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fd.constant.MsgCode;
|
|
|
import com.fd.constant.TypeCode;
|
|
|
+import com.fd.dto.ConfigJsonDto;
|
|
|
import com.fd.dto.PageDto;
|
|
|
import com.fd.entity.FileEntity;
|
|
|
import com.fd.entity.OutputFileEntity;
|
|
|
+import com.fd.entity.StyleEntity;
|
|
|
import com.fd.repository.FileRepository;
|
|
|
-import com.fd.repository.IBaseRepository;
|
|
|
import com.fd.repository.OutputFileRepository;
|
|
|
+import com.fd.repository.StyleRepository;
|
|
|
import com.fd.server.ModelServer;
|
|
|
import com.fd.util.FileUtils;
|
|
|
import com.fd.util.R;
|
|
@@ -25,7 +27,6 @@ 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.util.Date;
|
|
@@ -63,6 +64,9 @@ public class ModelServerImpl implements ModelServer {
|
|
|
@Autowired
|
|
|
private OutputFileRepository outputFileRepository;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StyleRepository styleRepository;
|
|
|
+
|
|
|
@Override
|
|
|
public R deleteById(Long fileId) {
|
|
|
// 删除服务器文件
|
|
@@ -71,6 +75,18 @@ public class ModelServerImpl implements ModelServer {
|
|
|
return new R(50002, MsgCode.E50002);
|
|
|
}
|
|
|
OutputFileEntity fileEntity = e.get();
|
|
|
+
|
|
|
+ // 删除配置文件config.json制定行
|
|
|
+ StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(fileId);
|
|
|
+ if (styleEntity != null) {
|
|
|
+ deleteRowConfigJson(styleEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除数据库记录
|
|
|
+ outputFileRepository.deleteById(fileId);
|
|
|
+ fileRepository.deleteById(fileEntity.getUploadId());
|
|
|
+ styleRepository.deleteByOutputFileId(fileId);
|
|
|
+
|
|
|
// 文件
|
|
|
if (fileEntity.getUploadPath() != null) {
|
|
|
FileUtils.delFolder(fileEntity.getUploadPath());
|
|
@@ -97,13 +113,43 @@ public class ModelServerImpl implements ModelServer {
|
|
|
}
|
|
|
|
|
|
|
|
|
- // 删除数据库记录
|
|
|
- outputFileRepository.deleteById(fileId);
|
|
|
- fileRepository.deleteById(fileEntity.getUploadId());
|
|
|
+
|
|
|
|
|
|
return new R(200, MsgCode.SUCCESS);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除指定行的config.json 数据
|
|
|
+ */
|
|
|
+ private void deleteRowConfigJson(StyleEntity entity) {
|
|
|
+ String s = FileUtils.readFile(CONFIG_JSON_PATH);
|
|
|
+ JSONObject original = JSON.parseObject(s);
|
|
|
+ log.info("original: {}", s);
|
|
|
+
|
|
|
+ JSONArray layers = JSON.parseArray(original.getString("layers"));
|
|
|
+
|
|
|
+ for (int i = 0; i < layers.size(); i++) {
|
|
|
+ JSONObject o = (JSONObject) layers.get(i);
|
|
|
+ if (o.getString("name").equals(entity.getName())) {
|
|
|
+ // 删除对象
|
|
|
+ layers.remove(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新json
|
|
|
+ original.put("layers", layers);
|
|
|
+ log.info("original update: {}", original.toJSONString());
|
|
|
+
|
|
|
+ // 更新config.json
|
|
|
+ try {
|
|
|
+ FileUtils.fileWriter(JSON.toJSONString(original), CONFIG_JSON_PATH);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<FileEntity> findByFileName(String fileName) {
|
|
|
|
|
@@ -185,7 +231,7 @@ public class ModelServerImpl implements ModelServer {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public R moveFileToServer(Long fileId) {
|
|
|
+ public R moveFileToServer(Long fileId, ConfigJsonDto param) {
|
|
|
Optional<OutputFileEntity> o = outputFileRepository.findById(fileId);
|
|
|
if (!o.isPresent()) {
|
|
|
log.info("id:{} 不存在", fileId);
|
|
@@ -198,7 +244,7 @@ public class ModelServerImpl implements ModelServer {
|
|
|
try {
|
|
|
// org.apache.commons.io.FileUtils.copyDirectoryToDirectory(new File(entity.getSlicePath()), new File(MOVE_FILE_TO_SERVER));
|
|
|
// 修改前端的config.json 文件
|
|
|
- writeJsonFile();
|
|
|
+ writeJsonFile(param, entity);
|
|
|
|
|
|
// 成功,状态
|
|
|
entity.setStatus(8);
|
|
@@ -318,21 +364,74 @@ public class ModelServerImpl implements ModelServer {
|
|
|
/**
|
|
|
* 修改config.json 文件
|
|
|
*/
|
|
|
- public void writeJsonFile(){
|
|
|
+// public void writeJsonFile(){
|
|
|
+//
|
|
|
+// String s = FileUtils.readFile(CONFIG_JSON_PATH);
|
|
|
+//
|
|
|
+// JSONObject original = JSON.parseObject(s);
|
|
|
+// // 修改tileset value
|
|
|
+// original.put("tileset", CONFIG_TILESET);
|
|
|
+// log.info(original.toJSONString());
|
|
|
+//
|
|
|
+// try {
|
|
|
+// FileUtils.fileWriter(JSON.toJSONString(original), CONFIG_JSON_PATH);
|
|
|
+// } catch (IOException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
+
|
|
|
+ private void writeJsonFile(ConfigJsonDto param, OutputFileEntity entity) {
|
|
|
String s = FileUtils.readFile(CONFIG_JSON_PATH);
|
|
|
|
|
|
+ StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(entity.getId());
|
|
|
+ if (styleEntity == null) {
|
|
|
+ styleEntity = new StyleEntity();
|
|
|
+ styleEntity.setOutputFileId(entity.getId());
|
|
|
+ styleEntity.setCreateTime(new Date());
|
|
|
+ styleEntity.setResStatus(0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
JSONObject original = JSON.parseObject(s);
|
|
|
- // 修改tileset value
|
|
|
- original.put("tileset", CONFIG_TILESET);
|
|
|
- log.info(original.toJSONString());
|
|
|
|
|
|
+ log.info("original: {}", s);
|
|
|
+
|
|
|
+ JSONArray layers = JSON.parseArray(original.getString("layers"));
|
|
|
+
|
|
|
+ JSONObject subJson = new JSONObject();
|
|
|
+ long cu = System.currentTimeMillis();
|
|
|
+ // 需要唯一
|
|
|
+ String name = "model_" + cu;
|
|
|
+ subJson.put("name", name);
|
|
|
+ subJson.put("text", param.getText());
|
|
|
+ // raster 就用这个类型
|
|
|
+ subJson.put("type", "tileset");
|
|
|
+ subJson.put("checked", false);
|
|
|
+ subJson.put("show", true);
|
|
|
+
|
|
|
+ String slicePath = entity.getSlicePath();
|
|
|
+ slicePath = slicePath.replace("/root/gis/cesium", "");
|
|
|
+ subJson.put("url", slicePath);
|
|
|
+
|
|
|
+ layers.add(subJson);
|
|
|
+
|
|
|
+ original.put("layers", layers);
|
|
|
+
|
|
|
+ log.info("original update: {}", original.toJSONString());
|
|
|
try {
|
|
|
FileUtils.fileWriter(JSON.toJSONString(original), CONFIG_JSON_PATH);
|
|
|
+
|
|
|
+ // 将图层信息保存到db
|
|
|
+ // 前端需要layer信息
|
|
|
+ styleEntity.setLayer(subJson.toJSONString());
|
|
|
+ styleEntity.setUpdateTime(new Date());
|
|
|
+ styleEntity.setName(name);
|
|
|
+ styleRepository.save(styleEntity);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|