管道基础大数据平台系统开发-【后端】-Server
13693261870
2023-06-12 4ca77edbe07508f1bd4a878c7c00d7b7fbf0abb5
src/main/java/com/lf/server/service/data/UploadService.java
@@ -1,5 +1,6 @@
package com.lf.server.service.data;
import com.google.common.collect.Lists;
import com.lf.server.entity.all.BaseEntity;
import com.lf.server.entity.all.StaticData;
import com.lf.server.entity.data.*;
@@ -95,11 +96,22 @@
                mf.setMsg("文件丢失");
            }
            MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
            MetaEntity old = metaService.selectByGuid(mf.getGuid(), getDirCode(mf), null);
            if (null != old) {
                mf.setMsg("已存在");
            }
        }
    }
    /**
     * 获取目录编码
     */
    private String getDirCode(MetaFileEntity mf) {
        if (StringHelper.isEmpty(mf.getDircode())) {
            return null;
        }
        return StringHelper.getRightLike(mf.getDircode().substring(0, 2));
    }
    /**
@@ -208,7 +220,7 @@
            return;
        }
        MetaEntity old = metaService.selectByGuid(mf.getGuid(), tabName);
        MetaEntity old = metaService.selectByGuid(mf.getGuid(), getDirCode(mf), tabName);
        if (null != old) {
            mf.setMsg("已存在");
            return;
@@ -223,14 +235,33 @@
        if (null == list || list.isEmpty()) {
            return;
        }
        mf.setRecords(list.size());
        setCreateInfo(list, mf);
        int rows = basicMapper.insertBatch(list);
        int rows = batchInserts(basicMapper, list);
        if (rows > 0) {
            mf.setEntity(mf.getTab());
            mf.setTab(tabName);
            mf.setRows(rows);
        }
    }
    /**
     * 批量插入
     */
    private <T>  int batchInserts(BasicMapper basicMapper, List<T> list) {
        int rows = 0;
        //int count = (int) Math.ceil(list.size() / StaticData.D100)
        List<List<T>> subLists = Lists.partition(list, StaticData.I50);
        for (List<T> sub : subLists) {
            try {
                rows += basicMapper.insertBatch(sub);
            } catch (Exception ex) {
                log.error(ex);
            }
        }
        return rows;
    }
    /**
@@ -315,9 +346,10 @@
            return -1;
        }
        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null, null);
        if (null != old) {
            mf.setMsg("已存在");
            // mf.setMsg("已存在")
            setOldMeta(mf, old);
            file.delete();
            return 0;
        }
@@ -337,6 +369,16 @@
        mf.setPath(subPath);
        return 1;
    }
    /**
     * 设置旧元数据信息
     */
    private void setOldMeta(MetaFileEntity mf, MetaEntity old) {
        mf.setPath(old.getPath());
        mf.setTab(old.getTab());
        mf.setRows(old.getRows());
        mf.setEntity(old.getEventid());
    }
    /**
@@ -384,9 +426,10 @@
            return;
        }
        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null, null);
        if (null != old) {
            mf.setMsg("已存在");
            // mf.setMsg("已存在")
            setOldMeta(mf, old);
            FileHelper.deleteFiles(file);
            return;
        }
@@ -448,8 +491,8 @@
            MetaEntity me = createMeta(mf, metaId);
            metaService.insert(me);
            mf.setMsg(me.getId() > 0 ? "成功" : "失败");
            String err = mf.getRows() < mf.getRecords() ? "(" + (mf.getRecords() - mf.getRows()) + " 条失败)" : "";
            mf.setMsg(me.getId() > 0 ? String.format("成功%s", err) : "失败");
        }
    }