管道基础大数据平台系统开发-【后端】-Server
13693261870
2023-06-10 e1d4efc4dba2849965bac02939592fe10d60d2c8
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.*;
@@ -236,12 +237,30 @@
        }
        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;
    }
    /**
@@ -328,7 +347,8 @@
        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null, null);
        if (null != old) {
            mf.setMsg("已存在");
            // mf.setMsg("已存在")
            setOldMeta(mf, old);
            file.delete();
            return 0;
        }
@@ -348,6 +368,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());
    }
    /**
@@ -397,7 +427,8 @@
        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null, null);
        if (null != old) {
            mf.setMsg("已存在");
            // mf.setMsg("已存在")
            setOldMeta(mf, old);
            FileHelper.deleteFiles(file);
            return;
        }