管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-03-18 a55fb5ff1c9901568e618df44e67912961a0d705
src/main/java/com/lf/server/service/data/UploadService.java
@@ -9,6 +9,7 @@
import com.lf.server.mapper.data.UploadMapper;
import com.lf.server.service.all.BaseQueryService;
import com.lf.server.service.all.BaseUploadService;
import com.lf.server.service.sys.DepService;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -33,6 +34,12 @@
    @Autowired
    MetaService metaService;
    @Autowired
    DepService depService;
    @Autowired
    DirService dirService;
    @Override
    public List<CoordEntity> selectCoords(String zoning) {
@@ -62,6 +69,7 @@
        excelLoader(list, req);
        loadData(list);
        copyFiles(list);
        // publishFiles(list)
        insertMetas(list);
    }
@@ -75,7 +83,7 @@
        for (MetaFileEntity mf : list) {
            mf.setCreateUser(ue.getId());
            mf.setCreateTime(createTime);
            mf.setDepid(ue.getDepid());
            mf.setDepcode(ue.getDepcode());
            mf.setPath(tempPath + File.separator + mf.getPath());
            mf.setMsg(null);
@@ -143,18 +151,19 @@
            String path = copyXlsFile(xlsBasePath, i, mf);
            if (null != path) {
                pathList.add(path);
                dirList.add(mf.getDirid() + "");
                dirList.add(mf.getDircode());
                pidList.add(mf.getEventid());
            }
        }
        MetaFileEntity first = xlsList.get(0);
        MetaFileEntity meta = new MetaFileEntity();
        meta.setPath(StringHelper.join(pathList, ","));
        meta.setEpsgCode(xlsList.get(0).getEpsgCode());
        meta.setEpsgCode(first.getEpsgCode());
        meta.setName(StringHelper.join(dirList, ";"));
        meta.setDepid(xlsList.get(0).getDepid());
        meta.setVerid(xlsList.get(0).getVerid());
        meta.setCreateUser(xlsList.get(0).getCreateUser());
        meta.setDepcode(first.getDepcode());
        meta.setVerid(first.getVerid());
        meta.setCreateUser(first.getCreateUser());
        meta.setEventid(StringHelper.join(pidList, ";"));
        return meta;
@@ -216,7 +225,7 @@
    /**
     * 加载空间数据
     */
    private void loadSpatialData(MetaFileEntity mf) {
    public void loadSpatialData(MetaFileEntity mf) {
        BasicMapper basicMapper = ClassHelper.getBasicMapper(mf.getEntity());
        if (null == basicMapper) {
            return;
@@ -273,8 +282,8 @@
                BaseEntity be = (BaseEntity) t;
                be.setEventid(StringHelper.getGuid());
                be.setParentid(mf.getEventid());
                be.setDirid(mf.getDirid());
                be.setDepid(mf.getDepid());
                be.setDirid(mf.getDircode());
                be.setDepid(mf.getDepcode());
                be.setVerid(mf.getVerid());
                be.setCreateuser(mf.getCreateUser());
                be.setCreatetime(mf.getCreateTime());
@@ -290,6 +299,10 @@
    private void copyFiles(List<MetaFileEntity> list) {
        List<String> gdbList = new ArrayList<>();
        for (MetaFileEntity mf : list) {
            if (null != mf.getMsg()) {
                continue;
            }
            switch (mf.getExtName()) {
                case StaticData.MPT:
                    copyMultiFile(mf, StaticData.MPT_EXT);
@@ -364,7 +377,6 @@
     */
    private void copyMultiFile(MetaFileEntity mf, List<String> extList) {
        String path = mf.getPath();
        int status = copySingleFile(mf);
        if (status < 1) {
            for (int i = 0, c = extList.size(); i < c; i++) {
@@ -450,15 +462,71 @@
    }
    /**
     * 发布文件
     */
    private void publishFiles(List<MetaFileEntity> list) {
        for (MetaFileEntity mf : list) {
            if (null != mf.getMsg()) {
                continue;
            }
            switch (mf.getExtName()) {
                case StaticData.MPT:
                    linkFiles(mf, StaticData.MPT_EXT, pathHelper.getConfig().getUploadPath() + File.separator + "SG");
                    break;
                case StaticData.D3DML:
                    linkFiles(mf, null, pathHelper.getConfig().getUploadPath() + File.separator + "SG");
                    break;
                default:
                    break;
            }
        }
    }
    /**
     * 链接文件
     */
    private void linkFiles(MetaFileEntity mf, List<String> exts, String publishPath) {
        String uploadPath = pathHelper.getConfig().getUploadPath();
        String source = uploadPath + File.separator + mf.getPath();
        String target = publishPath + File.separator + mf.getName();
        File sourceFile = new File(source);
        if (!sourceFile.exists() || sourceFile.isDirectory()) {
            return;
        }
        createFileLink(source, target);
        if (null == exts) {
            return;
        }
        for (String ext : exts) {
            File f = new File(source.replace(mf.getExtName(), ext));
            if (f.exists() && !f.isDirectory()) {
                createFileLink(source.replace(mf.getExtName(), ext), target.replace(mf.getExtName(), ext));
            }
        }
    }
    /**
     * 创建文件链接
     */
    private void createFileLink(String source, String target) {
        String cmd = String.format("cmd /c mklink \"%s\" \"%s\"", target, source);
        WebHelper.exec(cmd);
    }
    /**
     * 插入元数据
     */
    private void insertMetas(List<MetaFileEntity> list) {
        int metaId = insertParentMeta(list);
        for (MetaFileEntity mf : list) {
            if (null != mf.getMsg()) {
                continue;
            }
            MetaEntity me = createMeta(mf);
            MetaEntity me = createMeta(mf, metaId);
            metaService.insert(me);
            mf.setMsg(me.getId() > 0 ? "成功" : "失败");
@@ -468,11 +536,12 @@
    /**
     * 创建元数据
     */
    private MetaEntity createMeta(MetaFileEntity mf) {
    private MetaEntity createMeta(MetaFileEntity mf, int metaId) {
        MetaEntity me = new MetaEntity();
        me.setMetaid(metaId);
        me.setEventid(mf.getEventid());
        me.setDirid(mf.getDirid());
        me.setDepid(mf.getDepid());
        me.setDircode(mf.getDircode());
        me.setDepcode(mf.getDepcode());
        me.setVerid(mf.getVerid());
        me.setName(mf.getName());
        me.setType(mf.getType());
@@ -491,4 +560,24 @@
        return me;
    }
    /**
     * 插入父元数据
     */
    private int insertParentMeta(List<MetaFileEntity> list) {
        for (MetaFileEntity mf : list) {
            if (null != mf.getMsg() || !mf.getIsMeta()) {
                continue;
            }
            MetaEntity me = createMeta(mf, 0);
            me.setIsmeta((short) 1);
            metaService.insert(me);
            mf.setMsg(me.getId() > 0 ? "成功" : "失败");
            return me.getId();
        }
        return 0;
    }
}