xiangpei
2025-02-17 3e881345e5e8753c0886407a98bff8da9ae54f76
还原
5个文件已修改
77 ■■■■■ 已修改文件
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysOssMapper.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/VideoPulSync.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/deleteSync.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysOssMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysOssMapper.java
@@ -19,5 +19,5 @@
    List<Long> getWillDeleted(@Param("maxTime") LocalDateTime maxTime);
    void deleteIds(@Param("ids") List<Long> ids);
    void deleteId(@Param("id") Long id);
}
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/VideoPulSync.java
@@ -50,28 +50,21 @@
    @Scheduled(cron = "0 0/1 * * * ?")
    public void get() throws IOException {
        log.error("同步上传");
        List<String> list = FtpApche.downloadList(ftpConfig);
        if(CollectionUtils.isEmpty(list)){
            log.error("no files in ftp");
        log.error("同步互联网文件");
        List<String> list = FtpApche.downloadList(this.ftpConfig);
        if (list.size() == 0)
            return;
        }
        log.error("ftp get all fileinfo:" + list.get(0));
        for (String str : list) {
            String password = str.substring(0, 6);
            String fileName = str.substring(6, str.length());
            InputStream input = FtpApche.downloadFileFromDailyDir(str);
            if (Objects.nonNull(input)) {
                byte[] fileBytesByName = FtpApche.getFileBytesByName(input);
                OssClient storage = OssFactory.instance();
                MockMultipartFile mockMultipartFile = new MockMultipartFile(fileName, fileName, fileName.substring(14, fileName.length()), input);
                UploadResult uploadResult = storage.uploadSuffix2(fileBytesByName, getPath(fileName), "multipart/form-data; charset=ISO-8859-1");
                buildResultEntity(fileName, fileName.substring(14, fileName.length()), "minio", uploadResult, (MultipartFile)mockMultipartFile, password, fileBytesByName);
                FtpApche.deleteFile(str);
            buildResultEntity(fileName, fileName.substring(14, fileName.length()), "minio", uploadResult, (MultipartFile)mockMultipartFile, password, fileBytesByName);
            }
        }
    }
    @NotNull
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/deleteSync.java
@@ -1,7 +1,11 @@
package org.dromara.system.sync;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.common.oss.core.OssClient;
import org.dromara.common.oss.factory.OssFactory;
import org.dromara.system.domain.SysOss;
@@ -33,42 +37,21 @@
    @Scheduled(cron = "0 */10 * * * ?")
    public void remove() throws IOException {
        log.error("同步删除......");
        List<Long> ids = baseMapper.getWillDeleted(LocalDateTime.now().minusDays(1));
        if (ids.size() == 0) {
        List<SysOss> list = new LambdaQueryChainWrapper<>(baseMapper)
            .le(SysOss::getCreateTime, LocalDateTime.now().minusDays(1L))
            .list();
        if (list.size() == 0)
            return;
        for (SysOss vo : list) {
            OssClient storage = OssFactory.instance(vo.getService());
            storage.delete(vo.getUrl());
            HttpResponse httpResponse = HttpUtils.sendDeleteRequest(this.boundary.getVideo() + "/resource/synchronization/delete",
                String.valueOf(vo.getOssId()));
            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                baseMapper.deleteId(vo.getOssId());
        }
        OssClient ossClient = OssFactory.instance();
        for (Long ossId : ids) {
            SysOss sysOss = baseMapper.selectById(ossId);
            if (Objects.nonNull(sysOss)) {
                ossClient.delete(sysOss.getFileName());
            }
            HttpUtils.sendDeleteRequest(boundary.getVideo() + "/resource/synchronization/delete",
                String.valueOf(ossId));
        }
    }
    /**
     * 每小时删除2天之前的文件信息,因为上面的同步删除并不能保证事务
     *
     * @throws IOException
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void removeOssTable() throws IOException {
        log.error("每小时定时删除超过2天的数据库文件信息......");
        List<Long> ids = baseMapper.getWillDeleted(LocalDateTime.now().minusDays(2));
        if (ids.size() == 0) {
            return;
        }
        // 删除对应文件
        OssClient ossClient = OssFactory.instance();
        for (Long ossId : ids) {
            SysOss sysOss = baseMapper.selectById(ossId);
            if (Objects.nonNull(sysOss)) {
                ossClient.delete(sysOss.getFileName());
            }
        }
        baseMapper.deleteIds(ids);
    }
}
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java
@@ -110,7 +110,7 @@
//     * @param parameter
     * @throws Exception
     */
    public static String sendDeleteRequest(String url, String ossId) throws IOException {
    public static HttpResponse sendDeleteRequest(String url, String ossId) throws IOException {
        org.apache.http.client.HttpClient httpClient = HttpClientBuilder.create().build();
        HttpPost httpPost = new HttpPost(url);
@@ -127,9 +127,8 @@
        httpPost.setEntity(multipart);
        HttpResponse response = httpClient.execute(httpPost);
        String responseBody = EntityUtils.toString(response.getEntity());
        System.out.println("Response: " + responseBody);
        return responseBody;
        return response;
    }
ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysOssMapper.xml
@@ -7,8 +7,8 @@
    </select>
    <delete id="deleteIds" parameterType="integer">
        DELETE FROM sys_oss WHERE oss_id IN <foreach collection="ids" open="(" separator="," close=")" item="id">#{id}</foreach>
    <delete id="deleteId" parameterType="long">
        DELETE FROM sys_oss WHERE oss_id = #{id}
    </delete>
</mapper>