|
@@ -6,12 +6,10 @@ import com.onemap.common.core.domain.UploadZipDTO;
|
|
|
import com.onemap.common.core.domain.WordToPdfDTO;
|
|
|
import com.onemap.common.core.utils.StringUtils;
|
|
|
import com.onemap.common.core.web.domain.RequestResult;
|
|
|
-import com.onemap.file.domain.ShpFileDTO;
|
|
|
-import com.onemap.file.domain.ZhxzFileDTO;
|
|
|
-import com.onemap.file.mapper.ZhxzFileMapper;
|
|
|
import com.onemap.file.service.ISysFileService;
|
|
|
+import com.onemap.file.service.SaveFileService;
|
|
|
import com.onemap.file.utils.*;
|
|
|
-import com.onemap.system.api.domain.GhtgCl;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
@@ -19,10 +17,12 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -39,11 +39,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
@Value("${file.prefix}")
|
|
|
public String localFilePrefix;
|
|
|
private TgclTypeDTO tgclTypeDTO = new TgclTypeDTO();
|
|
|
- /**
|
|
|
- * 智慧选址压缩包
|
|
|
- */
|
|
|
- @Resource
|
|
|
- private ZhxzFileMapper zhxzFileMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 域名或本机访问地址
|
|
|
*/
|
|
@@ -71,9 +67,12 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
*/
|
|
|
@Value("${businessType.shp}")
|
|
|
private String shpLocalFilePath;
|
|
|
- //文件上传后的转发路径配置
|
|
|
+ // 文件上传后的转发路径配置
|
|
|
private Map<String, String> businessFilter = ImmutableMap.of("tgcl", "调规");
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SaveFileService saveFileService;
|
|
|
+
|
|
|
/**
|
|
|
* 本地文件上传接口
|
|
|
*
|
|
@@ -108,11 +107,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
* @throws IOException ioexception
|
|
|
*/
|
|
|
@Override
|
|
|
- public String splitFileUpload(@RequestParam("file") MultipartFile file,
|
|
|
- @RequestParam("chunk") int chunk,
|
|
|
- @RequestParam("chunks") int chunks,
|
|
|
- @RequestParam("name") String name,
|
|
|
- @RequestParam("md5") String md5) {
|
|
|
+ public String splitFileUpload(@RequestParam("file") MultipartFile file, @RequestParam("chunk") int chunk, @RequestParam("chunks") int chunks, @RequestParam("name") String name, @RequestParam("md5") String md5) {
|
|
|
String folder = localFilePath + "\\" + md5 + "\\";
|
|
|
File dir = new File(folder);
|
|
|
if (!dir.exists()) {
|
|
@@ -171,7 +166,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
*/
|
|
|
public WordToPdfDTO uploadWordFileToPdf(MultipartFile file, String businessType) throws Exception {
|
|
|
WordToPdfDTO pdf = new WordToPdfDTO();
|
|
|
- String filepath = localFilePath;//9082打开
|
|
|
+ String filepath = localFilePath;// 9082打开
|
|
|
if ("tgcl".equals(businessType)) {
|
|
|
filepath = tgclLocalFilePath;
|
|
|
}
|
|
@@ -195,137 +190,139 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public RequestResult uploadShpZip(MultipartFile file) {
|
|
|
- //获得文件名称
|
|
|
+ public RequestResult uploadShpZip(MultipartFile file) throws Exception {
|
|
|
+ // 获得文件名称
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
- //获得文件后缀名
|
|
|
+ // 获得文件后缀名
|
|
|
String type = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
- //判断上传的是否是压缩包
|
|
|
+ // 判断上传的是否是压缩包
|
|
|
if (!type.equals("zip") && !type.equals("rar")) {
|
|
|
return RequestResult.error("请上传压缩包", null);
|
|
|
}
|
|
|
+
|
|
|
File dest = new File(shpLocalFilePath + "/" + fileName);
|
|
|
- //获得上级目录
|
|
|
+ // 获得上级目录
|
|
|
File dir = dest.getParentFile();
|
|
|
if (!dir.exists()) {
|
|
|
dir.mkdirs();
|
|
|
}
|
|
|
- //获取当前时间的时间戳
|
|
|
+ // 获取当前时间的时间戳
|
|
|
long timeMillis = System.currentTimeMillis();
|
|
|
String shpPath = "";
|
|
|
- try {
|
|
|
- //上传文件
|
|
|
- file.transferTo(dest);
|
|
|
- //解压zip格式
|
|
|
- if (type.equals("zip")) {
|
|
|
- new UnPackageUtils().unPackZip(dest, shpLocalFilePath + "/" + timeMillis);
|
|
|
- } else {
|
|
|
- //解压rar格式
|
|
|
- new UnPackageUtils().unPackRar(dest, shpLocalFilePath + "/" + timeMillis);
|
|
|
- }
|
|
|
- File[] files = new File(shpLocalFilePath + "/" + timeMillis).listFiles();
|
|
|
- for (File file1 : files) {
|
|
|
- if (file1.getAbsolutePath().substring(file1.getAbsolutePath().lastIndexOf(".") + 1).equals("shp")) {
|
|
|
- shpPath = file1.getAbsolutePath();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!"".equals(shpPath)) {
|
|
|
- ShpFileDTO res = new ShpFileDTO();
|
|
|
- res.setFilepath(shpPath);
|
|
|
- res.setGeojson(getShpGeoJson(shpPath));
|
|
|
- res.setZippath(dest.getAbsolutePath());
|
|
|
- return RequestResult.success("上传成功", res);
|
|
|
- } else {
|
|
|
- return RequestResult.error("未检索到shp文件");
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return RequestResult.error("上传失败");
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public RequestResult uploadZhxzZip(MultipartFile file) {
|
|
|
- //获得文件名称
|
|
|
- String fileName = file.getOriginalFilename();
|
|
|
- //获得文件后缀名
|
|
|
- String type = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
- //判断上传的是否是压缩包
|
|
|
- if (!type.equals("zip") && !type.equals("rar")) {
|
|
|
- return RequestResult.error("请上传压缩包", null);
|
|
|
- }
|
|
|
- File dest = new File(shpLocalFilePath + "/" + fileName);
|
|
|
- //获得上级目录
|
|
|
- File dir = dest.getParentFile();
|
|
|
- if (!dir.exists()) {
|
|
|
- dir.mkdirs();
|
|
|
+ // 上传文件
|
|
|
+ File newFile = new File(dest.getAbsolutePath());
|
|
|
+ file.transferTo(newFile);
|
|
|
+ // 解压zip格式
|
|
|
+ if (type.equals("zip")) {
|
|
|
+ new UnPackageUtils().unPackZip(dest, shpLocalFilePath + "/" + timeMillis);
|
|
|
+ } else {
|
|
|
+ // 解压rar格式
|
|
|
+ new UnPackageUtils().unPackRar(dest, shpLocalFilePath + "/" + timeMillis);
|
|
|
}
|
|
|
- //获取当前时间的时间戳
|
|
|
- long timeMillis = System.currentTimeMillis();
|
|
|
- String shpPath = "";
|
|
|
- try {
|
|
|
- //上传文件
|
|
|
- file.transferTo(dest);
|
|
|
- //解压zip格式
|
|
|
- if (type.equals("zip")) {
|
|
|
- new UnPackageUtils().unPackZip(dest, shpLocalFilePath + "/" + timeMillis);
|
|
|
- } else {
|
|
|
- //解压rar格式
|
|
|
- new UnPackageUtils().unPackRar(dest, shpLocalFilePath + "/" + timeMillis);
|
|
|
- }
|
|
|
- File[] files = new File(shpLocalFilePath + "/" + timeMillis).listFiles();
|
|
|
- for (File file1 : files) {
|
|
|
- if (file1.getAbsolutePath().substring(file1.getAbsolutePath().lastIndexOf(".") + 1).equals("shp")) {
|
|
|
- shpPath = file1.getAbsolutePath();
|
|
|
- break;
|
|
|
- }
|
|
|
+ File[] files = new File(shpLocalFilePath + "/" + timeMillis).listFiles();
|
|
|
+ for (File file1 : files) {
|
|
|
+ List<File> shpFiles = new ArrayList<>();
|
|
|
+ FileUtils.findShpFiles(file1, shpFiles);
|
|
|
+ if (shpFiles.size() != 0) {
|
|
|
+ shpPath = shpFiles.get(0).getPath();
|
|
|
}
|
|
|
- if (!"".equals(shpPath)) {
|
|
|
- String uuid = StringUtils.getUUID();
|
|
|
- ZhxzFileDTO insertDto = new ZhxzFileDTO();
|
|
|
- insertDto.setBsm(uuid);
|
|
|
- insertDto.setWj(shpPath);
|
|
|
- insertDto.setYswj(dest.getAbsolutePath());
|
|
|
- zhxzFileMapper.insert(insertDto);
|
|
|
- return RequestResult.success("上传成功", uuid);
|
|
|
- } else {
|
|
|
- return RequestResult.error("未检索到shp文件");
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return RequestResult.error("上传失败");
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public GhtgCl uploadTgcl(MultipartFile file, Integer type) throws Exception {
|
|
|
- GhtgCl cl = new GhtgCl();
|
|
|
- cl.setBsm(StringUtils.getUUID());
|
|
|
- cl.setWjdx((double) file.getSize());
|
|
|
- String filename = file.getOriginalFilename();
|
|
|
- cl.setFjmc(filename);
|
|
|
- String kzmc = PublicTools.getFileKzmx(filename);
|
|
|
- cl.setFjlx(type);
|
|
|
- if (type == tgclTypeDTO.getShp()) {
|
|
|
- RequestResult shpzip = uploadShpZip(file);
|
|
|
- ShpFileDTO shpzipinfo = (ShpFileDTO) shpzip.get("data");
|
|
|
- cl.setWjlj(shpzipinfo.getZippath());
|
|
|
- cl.setYshp(shpzipinfo.getFilepath());
|
|
|
- cl.setGeojson(shpzipinfo.getGeojson());
|
|
|
- cl.setKzmc(kzmc);
|
|
|
- cl.setYwj(shpzipinfo.getZippath());
|
|
|
- return cl;
|
|
|
- } else if (type == tgclTypeDTO.getTgcl()) {
|
|
|
- WordToPdfDTO pdf = uploadWordFileToPdf(file, "tgcl");
|
|
|
- cl.setWjlj(pdf.getPdfpath());
|
|
|
- cl.setKzmc(pdf.getKzmc());
|
|
|
- cl.setYwj(pdf.getFilepath());
|
|
|
- return cl;
|
|
|
+ if (!"".equals(shpPath)) {
|
|
|
+ String id = saveFileService.saveShpFile(shpPath, dest.getPath());
|
|
|
+ // ShpFileDTO res = new ShpFileDTO();
|
|
|
+ // res.setFilepath(shpPath);
|
|
|
+ // res.setGeojson(getShpGeoJson(shpPath));
|
|
|
+ // res.setZippath(dest.getAbsolutePath());
|
|
|
+ Map<String, String> res = new HashMap<>();
|
|
|
+ res.put("id", id);
|
|
|
+ return RequestResult.success("上传成功", res);
|
|
|
+ } else {
|
|
|
+ return RequestResult.error("未检索到shp文件");
|
|
|
}
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
+ // @Override
|
|
|
+ // public RequestResult uploadZhxzZip(MultipartFile file) {
|
|
|
+ // // 获得文件名称
|
|
|
+ // String fileName = file.getOriginalFilename();
|
|
|
+ // // 获得文件后缀名
|
|
|
+ // String type = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
+ // // 判断上传的是否是压缩包
|
|
|
+ // if (!type.equals("zip") && !type.equals("rar")) {
|
|
|
+ // return RequestResult.error("请上传压缩包", null);
|
|
|
+ // }
|
|
|
+ // File dest = new File(shpLocalFilePath + "/" + fileName);
|
|
|
+ // // 获得上级目录
|
|
|
+ // File dir = dest.getParentFile();
|
|
|
+ // if (!dir.exists()) {
|
|
|
+ // dir.mkdirs();
|
|
|
+ // }
|
|
|
+ // // 获取当前时间的时间戳
|
|
|
+ // long timeMillis = System.currentTimeMillis();
|
|
|
+ // String shpPath = "";
|
|
|
+ // try {
|
|
|
+ // // 上传文件
|
|
|
+ // file.transferTo(dest);
|
|
|
+ // // 解压zip格式
|
|
|
+ // if (type.equals("zip")) {
|
|
|
+ // new UnPackageUtils().unPackZip(dest, shpLocalFilePath + "/" + timeMillis);
|
|
|
+ // } else {
|
|
|
+ // // 解压rar格式
|
|
|
+ // new UnPackageUtils().unPackRar(dest, shpLocalFilePath + "/" + timeMillis);
|
|
|
+ // }
|
|
|
+ // File[] files = new File(shpLocalFilePath + "/" + timeMillis).listFiles();
|
|
|
+ // for (File file1 : files) {
|
|
|
+ // if (file1.getAbsolutePath().substring(file1.getAbsolutePath().lastIndexOf(".") + 1).equals("shp")) {
|
|
|
+ // shpPath = file1.getAbsolutePath();
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if (!"".equals(shpPath)) {
|
|
|
+ // String uuid = StringUtils.getUUID();
|
|
|
+ // ZhxzFileDTO insertDto = new ZhxzFileDTO();
|
|
|
+ // insertDto.setBsm(uuid);
|
|
|
+ // insertDto.setWj(shpPath);
|
|
|
+ // insertDto.setYswj(dest.getAbsolutePath());
|
|
|
+ // zhxzFileMapper.insert(insertDto);
|
|
|
+ // return RequestResult.success("上传成功", uuid);
|
|
|
+ // } else {
|
|
|
+ // return RequestResult.error("未检索到shp文件");
|
|
|
+ // }
|
|
|
+ // } catch (IOException e) {
|
|
|
+ // e.printStackTrace();
|
|
|
+ // return RequestResult.error("上传失败");
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // @Override
|
|
|
+ // public GhtgCl uploadTgcl(MultipartFile file, Integer type) throws Exception {
|
|
|
+ // GhtgCl cl = new GhtgCl();
|
|
|
+ // cl.setBsm(StringUtils.getUUID());
|
|
|
+ // cl.setWjdx((double) file.getSize());
|
|
|
+ // String filename = file.getOriginalFilename();
|
|
|
+ // cl.setFjmc(filename);
|
|
|
+ // String kzmc = PublicTools.getFileKzmx(filename);
|
|
|
+ // cl.setFjlx(type);
|
|
|
+ // if (type == tgclTypeDTO.getShp()) {
|
|
|
+ // RequestResult shpzip = uploadShpZip(file);
|
|
|
+ // ShpFileDTO shpzipinfo = (ShpFileDTO) shpzip.get("data");
|
|
|
+ // cl.setWjlj(shpzipinfo.getZippath());
|
|
|
+ // cl.setYshp(shpzipinfo.getFilepath());
|
|
|
+ // cl.setGeojson(shpzipinfo.getGeojson());
|
|
|
+ // cl.setKzmc(kzmc);
|
|
|
+ // cl.setYwj(shpzipinfo.getZippath());
|
|
|
+ // return cl;
|
|
|
+ // } else if (type == tgclTypeDTO.getTgcl()) {
|
|
|
+ // WordToPdfDTO pdf = uploadWordFileToPdf(file, "tgcl");
|
|
|
+ // cl.setWjlj(pdf.getPdfpath());
|
|
|
+ // cl.setKzmc(pdf.getKzmc());
|
|
|
+ // cl.setYwj(pdf.getFilepath());
|
|
|
+ // return cl;
|
|
|
+ // }
|
|
|
+ // return null;
|
|
|
+ // }
|
|
|
+
|
|
|
/**
|
|
|
* 通过shp路径转换esrijson并返回相应json文件路径
|
|
|
*
|
|
@@ -340,11 +337,11 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
String geojsonPath = publicpath + "_" + uuid + "_" + "geojson.json";
|
|
|
String geojson = ParsingShpFileUtils.shape2Geojson(shppath, geojsonPath);
|
|
|
String esrijson = EsriGeoJsonJsUtils.geo2ersi(geojson, "", shppath);
|
|
|
- //写入文件
|
|
|
+ // 写入文件
|
|
|
FileOutputStream fos = null;
|
|
|
try {
|
|
|
fos = new FileOutputStream(esrijsonpath, false);
|
|
|
- //true表示在文件末尾追加
|
|
|
+ // true表示在文件末尾追加
|
|
|
fos.write(esrijson.toString().getBytes());
|
|
|
fos.close();
|
|
|
} catch (IOException e) {
|
|
@@ -369,34 +366,29 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
return geojson;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public String getShpWkt(String shppath) {
|
|
|
- return "";
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public UploadZipDTO uploadZip(MultipartFile file) {
|
|
|
- //获得文件名称
|
|
|
+ // 获得文件名称
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
- //获得文件后缀名
|
|
|
+ // 获得文件后缀名
|
|
|
String type = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
String path = shpLocalFilePath + "/" + fileName;
|
|
|
File dest = new File(path);
|
|
|
- //获得上级目录
|
|
|
+ // 获得上级目录
|
|
|
File dir = dest.getParentFile();
|
|
|
if (!dir.exists()) {
|
|
|
dir.mkdirs();
|
|
|
}
|
|
|
- //获取当前时间的时间戳
|
|
|
+ // 获取当前时间的时间戳
|
|
|
long timeMillis = System.currentTimeMillis();
|
|
|
String unzippath = shpLocalFilePath + "/" + timeMillis;
|
|
|
try {
|
|
|
- //上传文件
|
|
|
+ // 上传文件
|
|
|
file.transferTo(dest);
|
|
|
if (type.equals("zip")) {
|
|
|
new UnPackageUtils().unPackZip(dest, unzippath);
|
|
|
} else if (type.equals("rar")) {
|
|
|
- //解压rar格式
|
|
|
+ // 解压rar格式
|
|
|
new UnPackageUtils().unPackRar(dest, unzippath);
|
|
|
}
|
|
|
UploadZipDTO dto = new UploadZipDTO();
|