管道基础大数据平台系统开发-【后端】-Server
1.5
13693261870
2023-01-05 e5f61db766b3eaa28506835e3581cbd2fdc8533d
src/main/java/com/lf/server/service/show/MarkService.java
@@ -2,6 +2,7 @@
import com.lf.server.entity.ctrl.MarkJsonEntity;
import com.lf.server.entity.data.DownloadEntity;
import com.lf.server.entity.data.MetaEntity;
import com.lf.server.entity.show.MarkEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.*;
@@ -14,6 +15,7 @@
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@@ -92,7 +94,7 @@
     * @throws Exception 异常
     */
    public String downloadShp(UserEntity ue, List<MarkJsonEntity> list, HttpServletRequest req, HttpServletResponse res) throws Exception {
        String parent = pathHelper.getTempPath(ue.getId());
        String parent = pathHelper.getTempPath();
        String path = createShapeFiles(ue, list, parent);
        File[] files = new File(path).listFiles();
@@ -121,15 +123,15 @@
        List<MarkJsonEntity> points = getMarkByType(list, "POINT");
        if (points.size() > 0) {
            String pointFile = GdalHelper.createShp(points, path, "POINT");
            String pointFile = ShpHelper.createShp(points, path, "POINT");
        }
        List<MarkJsonEntity> lines = getMarkByType(list, "LINESTRING");
        if (lines.size() > 0) {
            String lineFile = GdalHelper.createShp(lines, path, "LINESTRING");
            String lineFile = ShpHelper.createShp(lines, path, "LINESTRING");
        }
        List<MarkJsonEntity> polygons = getMarkByType(list, "POLYGON");
        if (polygons.size() > 0) {
            String polygonFile = GdalHelper.createShp(polygons, path, "POLYGON");
            String polygonFile = ShpHelper.createShp(polygons, path, "POLYGON");
        }
        return path;
@@ -161,7 +163,7 @@
    }
    private String getZip() {
        String path = pathHelper.getDownloadFullPath() + File.separator + WebHelper.getRandomInt(100000, 1000000) + ".zip";
        String path = pathHelper.getDownloadFullPath() + File.separator + StringHelper.YMDHMS2_FORMAT.format(new Date()) + ".zip";
        File file = new File(path);
        if (file.exists() && !file.isDirectory()) {
@@ -175,11 +177,12 @@
        DownloadEntity de = new DownloadEntity();
        de.setName(FileHelper.getFileName(file));
        de.setType(1);
        de.setSizes(FileHelper.sizeToMb(new File(file).length()));
        de.setDepid(ue.getDepid());
        de.setDcount(0);
        // de.setPwd(null)
        de.setUrl(FileHelper.getRelativePath(file));
        de.setDescr("下载ShapeFile文件");
        de.setDescr("ShapeFile文件");
        de.setGuid(FileHelper.getFileMd5(file));
        de.setCreateUser(ue.getId());
        // de.setGeom(null)
@@ -196,4 +199,28 @@
    public String getDownloadFilePath(DownloadEntity de) {
        return pathHelper.getConfig().getDownloadPath() + File.separator + de.getUrl();
    }
    /**
     * 读取ShapeFile文件获取Mark实体类
     *
     * @param list ShapeFile文件列表
     * @return Mark实体类集合
     */
    public List<MarkJsonEntity> readShpForMarks(List<MetaEntity> list) {
        String fileName = null;
        for (MetaEntity mf : list) {
            if (mf.getName().toLowerCase().indexOf(".shp") > -1) {
                fileName = mf.getPath();
                break;
            }
        }
        if (StringHelper.isEmpty(fileName)) {
            return null;
        }
        List<MarkJsonEntity> mjeList = ShpHelper.readShpForMarks(fileName);
        FileHelper.deleteFiles(list);
        return mjeList;
    }
}