管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-02-04 0ff3a661acf8c36b5fe7bec4f00dea71cf5ed4a5
src/main/java/com/lf/server/service/data/UploadService.java
@@ -57,11 +57,13 @@
    /**
     * 插入文件
     */
    public List<MetaEntity> insertFiles(UserEntity ue, List<MetaFileEntity> list, HttpServletRequest req) {
    public void insertFiles(UserEntity ue, List<MetaFileEntity> list, HttpServletRequest req) {
        checkMetaFiles(ue, list);
        excelLoader(list, req);
        return dataLoader(list);
        loadData(list);
        copyFiles(list);
        publishFiles(list);
        insertMetas(list);
    }
    /**
@@ -76,6 +78,7 @@
            mf.setCreateTime(createTime);
            mf.setDepid(ue.getDepid());
            mf.setPath(tempPath + File.separator + mf.getPath());
            mf.setMsg(null);
            File f = new File(mf.getPath());
            if (!f.exists()) {
@@ -84,7 +87,7 @@
            MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
            if (null != old) {
                mf.setMsg("文件已入库");
                mf.setMsg("已入库");
            }
        }
    }
@@ -118,7 +121,6 @@
            if (null != mf.getMsg()) {
                continue;
            }
            if (StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName())) {
                xlsList.add(mf);
            }
@@ -201,19 +203,9 @@
    /**
     * 加载数据
     */
    private List<MetaEntity> dataLoader(List<MetaFileEntity> list) {
        loadData(list);
        copyFiles(list);
        return insertMetas(list);
    }
    /**
     * 加载数据
     */
    private void loadData(List<MetaFileEntity> list) {
        for (MetaFileEntity mf : list) {
            if (StringHelper.isEmpty(mf.getEntity())) {
            if (null != mf.getMsg() || StringHelper.isEmpty(mf.getEntity())) {
                continue;
            }
            if (StaticData.SHP.equals(mf.getExtName()) || StaticData.GDB.equals(mf.getExtName())) {
@@ -238,9 +230,15 @@
            return;
        }
        File file = new File(mf.getPath());
        if (!file.exists()) {
            mf.setMsg("文件丢失");
            return;
        }
        MetaEntity old = metaService.selectByGuid(mf.getGuid(), tabName);
        if (old != null) {
            mf.setMsg("文件已入库");
        if (null != old) {
            mf.setMsg("已入库");
            return;
        }
@@ -293,6 +291,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);
@@ -340,10 +342,7 @@
        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
        if (null != old) {
            mf.setPath(old.getPath());
            mf.setTab(old.getTab());
            mf.setEntity(old.getLayer());
            mf.setRows(old.getRows());
            mf.setMsg("已入库");
            file.delete();
            return 0;
        }
@@ -370,7 +369,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++) {
@@ -413,7 +411,7 @@
        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
        if (null != old) {
            mf.setPath(old.getPath());
            mf.setMsg("已入库");
            FileHelper.deleteFiles(file);
            return;
        }
@@ -456,22 +454,74 @@
    }
    /**
     * 插入元数据
     * 发布文件
     */
    private List<MetaEntity> insertMetas(List<MetaFileEntity> list) {
        List<MetaEntity> metas = new ArrayList<>();
    private void publishFiles(List<MetaFileEntity> list) {
        for (MetaFileEntity mf : list) {
            if (StringHelper.isEmpty(mf.getMsg())) {
                metas.add(createMeta(mf));
            if (null != mf.getMsg()) {
                continue;
            }
            switch (mf.getExtName()) {
                case StaticData.MPT:
                    linkFiles(mf, StaticData.MPT_EXT, pathHelper.getConfig().getPublishMptPath());
                    break;
                case StaticData.D3DML:
                    linkFiles(mf, null, pathHelper.getConfig().getPublish3dmlPath());
                    break;
                default:
                    break;
            }
        }
        if (metas.isEmpty()) {
            return null;
    }
    /**
     * 链接文件
     */
    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;
        }
        int rows = metaService.inserts(metas);
        createFileLink(source, target);
        if (null == exts) {
            return;
        }
        return rows > 0 ? metas : null;
        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) {
        for (MetaFileEntity mf : list) {
            if (null != mf.getMsg()) {
                continue;
            }
            MetaEntity me = createMeta(mf);
            metaService.insert(me);
            mf.setMsg(me.getId() > 0 ? "成功" : "失败");
        }
    }
    /**