管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-02-05 a61cf0deb3e42fb1fdc249be2f81b26c8662b0db
1
已修改4个文件
70 ■■■■ 文件已修改
src/main/java/com/lf/server/mapper/sys/AttachMapper.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/all/UploadAttachService.java 51 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/sys/AttachService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/sys/AttachMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/mapper/sys/AttachMapper.java
@@ -55,6 +55,16 @@
    public AttachEntity selectByGuid(String guid);
    /**
     * 根据表名和GUID查询
     *
     * @param tab
     * @param tabGuid
     * @param guid
     * @return
     */
    public AttachEntity selectByTabAndGuid(String tab, String tabGuid, String guid);
    /**
     * 根据表和GUID查询
     *
     * @param tab
src/main/java/com/lf/server/service/all/UploadAttachService.java
@@ -275,7 +275,8 @@
            }
            BaseEntity be = (BaseEntity) obj;
            rows += insertXlsAnnex(ue, be, files, file);
            rows += insertXlsAnnex(ue, meta, be, file);
            files.remove(file);
        }
        return rows;
@@ -356,26 +357,46 @@
    /**
     * 插入Excel附件
     */
    private int insertXlsAnnex(UserEntity ue, BaseEntity be, List<String> files, String file) {
    private int insertXlsAnnex(UserEntity ue, MetaEntity meta, BaseEntity be, String file) {
        File f = new File(file);
        if (!f.exists() || f.isDirectory()) {
            return 0;
        }
        String md5 = FileHelper.getFileMd5(file);
        AttachEntity old = attachService.selectByTabAndGuid(meta.getTab(), be.getEventid(), md5);
        if (null != old) {
            f.delete();
            return 0;
        }
        files.remove(file);
        String fileName = FileHelper.getFileName(file);
        double sizes = FileHelper.sizeToMb(f.length());
        return 1;
        AttachEntity ae = getAttachEntity(ue, meta.getTab(), be.getEventid(), fileName, md5, sizes);
        String targetPath = pathHelper.getConfig().getUploadPath() + File.separator + ae.getPath();
        f.renameTo(new File(targetPath));
        int rows = attachService.insert(ae);
        return rows > 0 ? 1 : 0;
    }
    private AttachEntity getAttachEntity(UserEntity ue, String file) {
    /**
     * 获取附件实体类
     */
    protected AttachEntity getAttachEntity(UserEntity ue, String tabName, String eventid, String fileName, String md5, double sizes) {
        AttachEntity entity = new AttachEntity();
//        entity.setTab(tabName);
//        entity.setTabGuid(eventid);
//        entity.setName(fileName);
//        entity.setGuid(md5);
//        String subPath = PathHelper.getUploadPath() + File.separator + md5+ FileHelper.getExtension(fileName);
//        entity.setPath(subPath);
//        entity.setSizes(sizes);
//        if (ue != null) {
//            entity.setCreateUser(ue.getId());
//        }
        entity.setTab(tabName);
        entity.setTabGuid(eventid);
        entity.setName(fileName);
        entity.setGuid(md5);
        String subPath = PathHelper.getUploadPath() + File.separator + md5 + FileHelper.getExtension(fileName);
        entity.setPath(subPath);
        entity.setSizes(sizes);
        if (ue != null) {
            entity.setCreateUser(ue.getId());
        }
        return entity;
    }
src/main/java/com/lf/server/service/sys/AttachService.java
@@ -47,6 +47,11 @@
    }
    @Override
    public AttachEntity selectByTabAndGuid(String tab, String tabGuid, String guid) {
        return attachMapper.selectByTabAndGuid(tab, tabGuid, guid);
    }
    @Override
    public List<AttachEntity> selectByTab(String tab, String guid) {
        return attachMapper.selectByTab(tab, guid);
    }
src/main/resources/mapper/sys/AttachMapper.xml
@@ -33,6 +33,10 @@
        select * from lf.sys_attach where guid = #{guid} limit 1
    </select>
    <select id="selectByTabAndGuid" resultType="com.lf.server.entity.sys.AttachEntity">
        select * from lf.sys_attach where tab = #{tab} and tab_guid = #{tabGuid} and guid = #{guid} limit 1
    </select>
    <select id="selectByTab" resultType="com.lf.server.entity.sys.AttachEntity">
        select * from lf.sys_attach where tab = #{tab} and tab_guid = #{guid}
    </select>