|
@@ -14,6 +14,7 @@ import com.fd.repository.OutputFileRepository;
|
|
|
import com.fd.server.VectorServer;
|
|
|
import com.fd.util.FileUtils;
|
|
|
import com.fd.util.R;
|
|
|
+import com.fd.util.RegexUtils;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -26,9 +27,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Base64;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -81,7 +80,9 @@ public class VectorServerImpl implements VectorServer {
|
|
|
}
|
|
|
|
|
|
// 修改前端的config.json 文件
|
|
|
- writeJsonFile(param);
|
|
|
+ String lastName = StringUtils.substringAfterLast(entity.getSlicePath(), "/");
|
|
|
+ log.info("lastName: {}", lastName);
|
|
|
+ writeJsonFile(param, lastName);
|
|
|
|
|
|
|
|
|
entity.setStatus(8);
|
|
@@ -97,14 +98,8 @@ public class VectorServerImpl implements VectorServer {
|
|
|
return new R(50002, MsgCode.E50002);
|
|
|
}
|
|
|
OutputFileEntity fileEntity = e.get();
|
|
|
- String fileName = fileEntity.getFileName();
|
|
|
// 文件
|
|
|
- if (fileName.contains(".")) {
|
|
|
-// File file = new File(fileEntity.getGeojsonPath());
|
|
|
-// file.delete();
|
|
|
- } else { // 目录
|
|
|
-// FileUtils.delAllFile(fileEntity.getSlicePath());
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
// 删除数据库记录
|
|
|
outputFileRepository.deleteById(fileId);
|
|
@@ -188,6 +183,7 @@ public class VectorServerImpl implements VectorServer {
|
|
|
// 保存信息到db
|
|
|
FileEntity entity = new FileEntity();
|
|
|
entity.setFileName(fullFileName);
|
|
|
+ entity.setDirectory(directoryName);
|
|
|
entity.setFileUrl(filePath);
|
|
|
entity.setCreateTime(new Date());
|
|
|
entity.setUpdateTime(new Date());
|
|
@@ -220,11 +216,107 @@ public class VectorServerImpl implements VectorServer {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public R uploadDirectoryFileMul(MultipartFile[] files, String directoryName, String coord) {
|
|
|
+
|
|
|
+ log.warn("run uploadDirectoryFileMul");
|
|
|
+// if (file.isEmpty() || file.getSize() <= 0) {
|
|
|
+// log.info("文件为空");
|
|
|
+// return new R(50001, MsgCode.E50001);
|
|
|
+// }
|
|
|
+
|
|
|
+ // 判断目录重名
|
|
|
+ List<FileEntity> en = fileRepository.findByDirectory(directoryName);
|
|
|
+ if (en.size() > 0){
|
|
|
+ return new R(51006, MsgCode.E51006);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建目录路径
|
|
|
+ String filePath = INPUT_FILE_PATH + directoryName + File.separator;
|
|
|
+ FileUtils.createDir(filePath);
|
|
|
+
|
|
|
+ FileEntity entity = new FileEntity();
|
|
|
+
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+
|
|
|
+ String shpName = "";
|
|
|
+
|
|
|
+ if (files != null && files.length > 0) {
|
|
|
+ for (MultipartFile f: files) {
|
|
|
+ String filename = f.getOriginalFilename();
|
|
|
+
|
|
|
+ // 文件是否包含中文字符
|
|
|
+ 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.setFileName(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.setStatus(2);
|
|
|
+ entity = fileRepository.save(entity);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ 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);
|
|
|
+
|
|
|
+ OutputFileEntity outputFile = new OutputFileEntity();
|
|
|
+
|
|
|
+ outputFile = new OutputFileEntity();
|
|
|
+ outputFile.setUploadId(entity.getId());
|
|
|
+ outputFile.setUploadPath(entity.getFileUrl());
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public R findByType(String type, PageDto pageDto) {
|
|
|
Page<OutputFileEntity> page = outputFileRepository.findByType(type, PageRequest.of(pageDto.getPageNum(), pageDto.getPageSize(), Sort.by("createTime").descending()));
|
|
|
return new R(200, page);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FileEntity findByFileName(String fileName) {
|
|
|
+
|
|
|
+ return fileRepository.findByFileName(fileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FileEntity> findByDirectory(String directory) {
|
|
|
+
|
|
|
+ return fileRepository.findByDirectory(directory);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public OutputFileEntity findById(Long fileId) {
|
|
|
Optional<OutputFileEntity> o = outputFileRepository.findById(fileId);
|
|
@@ -243,7 +335,7 @@ public class VectorServerImpl implements VectorServer {
|
|
|
/**
|
|
|
* 修改config.json
|
|
|
*/
|
|
|
- private void writeJsonFile(ConfigJsonDto param) {
|
|
|
+ private void writeJsonFile(ConfigJsonDto param, String lastName) {
|
|
|
String s = FileUtils.readFile(CONFIG_JSON_PATH);
|
|
|
|
|
|
JSONObject original = JSON.parseObject(s);
|
|
@@ -259,7 +351,7 @@ public class VectorServerImpl implements VectorServer {
|
|
|
subJson.put("type", "geodata"); // vector 就用这个类型geodata
|
|
|
subJson.put("checked", false);
|
|
|
subJson.put("show", true);
|
|
|
- subJson.put("url", param.getUrl());
|
|
|
+ subJson.put("url", "../data/" + lastName);
|
|
|
|
|
|
layers.add(subJson);
|
|
|
|