From 3e881345e5e8753c0886407a98bff8da9ae54f76 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期一, 17 二月 2025 09:55:13 +0800
Subject: [PATCH] 还原

---
 ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysOssMapper.xml         |    4 +-
 ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/deleteSync.java     |   49 ++++++++----------------
 ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/VideoPulSync.java   |   25 ++++--------
 ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java     |    7 +--
 ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysOssMapper.java |    2 
 5 files changed, 31 insertions(+), 56 deletions(-)

diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysOssMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysOssMapper.java
index 3907fae..2557aa5 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysOssMapper.java
+++ b/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);
 }
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/VideoPulSync.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/VideoPulSync.java
index 3a0db25..e57afd1 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/VideoPulSync.java
+++ b/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);
-            }
+            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");
+            FtpApche.deleteFile(str);
+            buildResultEntity(fileName, fileName.substring(14, fileName.length()), "minio", uploadResult, (MultipartFile)mockMultipartFile, password, fileBytesByName);
         }
-
     }
 
     @NotNull
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/deleteSync.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/deleteSync.java
index fb42703..7068fbf 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/deleteSync.java
+++ b/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;
-        }
-        OssClient ossClient = OssFactory.instance();
-        for (Long ossId : ids) {
-            SysOss sysOss = baseMapper.selectById(ossId);
-            if (Objects.nonNull(sysOss)) {
-                ossClient.delete(sysOss.getFileName());
+
+        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());
             }
-            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);
-    }
 }
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java
index df3f77b..6b10a39 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java
+++ b/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;
+
     }
 
 
diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysOssMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysOssMapper.xml
index eb2672d..336b02f 100644
--- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysOssMapper.xml
+++ b/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>

--
Gitblit v1.8.0