From 6307624c52e8528fd13fadea144f37a62cff5edb Mon Sep 17 00:00:00 2001
From: qirong <2032486488@qq.com>
Date: 星期三, 22 十一月 2023 18:10:58 +0800
Subject: [PATCH] 修改

---
 ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java              |    2 
 ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java                             |   61 ++++++++++++++++++++----------
 ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SynchronizationController.java |   11 ++---
 3 files changed, 46 insertions(+), 28 deletions(-)

diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SynchronizationController.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SynchronizationController.java
index ae02446..65f34a9 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SynchronizationController.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SynchronizationController.java
@@ -51,14 +51,11 @@
     /**
      * 鍒犻櫎鍚屾
      *
-     * @param ossIds OSS瀵硅薄ID涓�
+     * @param ossId OSS瀵硅薄ID涓�
      */
-    @SaCheckPermission("system:oss:remove")
-    @Log(title = "OSS瀵硅薄瀛樺偍", businessType = BusinessType.DELETE)
-    @DeleteMapping("/{ossIds}")
-    public R<Void> remove(@NotEmpty(message = "涓婚敭涓嶈兘涓虹┖")
-                          @PathVariable String ossIds) throws Exception {
-        return ossService.deleteWithValidByIds(List.of(convert(ossIds)), true,"000000") ? R.ok() : R.fail("鎻愬彇鐮侀敊璇紒");
+    @PostMapping(value = "/delete")
+    public R<Void> remove(String ossId) throws Exception {
+        return ossService.deleteWithValidByIds(List.of(convert(ossId)), true,"000000") ? R.ok() : R.fail("鎻愬彇鐮侀敊璇紒");
     }
 
     public static Long[] convert(String input) {
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java
index f4ba4b7..c698890 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java
@@ -251,7 +251,7 @@
             storage.delete(sysOss.getUrl());
             if(sysOss.getPassword().equals(password) || password.equals("000000")){
                 baseMapper.deleteById(sysOss.getOssId());
-                HttpUtils.sendDeleteRequest("http://192.168.3.43/resource/synchronization",String.valueOf(sysOss.getOssId()));
+                HttpUtils.sendDeleteRequest("http://192.168.3.43/resource/synchronization/delete",String.valueOf(sysOss.getOssId()));
                 return true;
             }
             return false;
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 aa6ecee..78e5ad3 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
@@ -151,30 +151,51 @@
 //     * @param parameter
      * @throws Exception
      */
-    public static void sendDeleteRequest(String url, String parameter) throws Exception {
-        // 鎷兼帴URL鍜屽弬鏁�
-        String deleteUrl = url + "/" + parameter;
+//    public static void sendDeleteRequest(String url, String parameter) throws Exception {
+//        // 鎷兼帴URL鍜屽弬鏁�
+//        String deleteUrl = url + "/" + parameter;
+//
+//        // 鍒涘缓URL瀵硅薄鍜孒ttpURLConnection瀵硅薄
+//        URL obj = new URL(deleteUrl);
+//        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
+//
+//        // 璁剧疆璇锋眰鏂规硶涓篋ELETE
+//        con.setRequestMethod("DELETE");
+//
+//        // 鍙戦�佽姹傚苟鑾峰彇鍝嶅簲
+//        int responseCode = con.getResponseCode();
+//        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
+//        String inputLine;
+//        StringBuffer response = new StringBuffer();
+//        while ((inputLine = in.readLine()) != null) {
+//            response.append(inputLine);
+//        }
+//        in.close();
+//
+//        // 鎵撳嵃鍝嶅簲缁撴灉
+//        System.out.println("Response Code : " + responseCode);
+//        System.out.println("Response : " + response.toString());
+//    }
+    public static String sendDeleteRequest(String url, String ossId) throws IOException {
+        org.apache.http.client.HttpClient httpClient = HttpClientBuilder.create().build();
+        HttpPost httpPost = new HttpPost(url);
 
-        // 鍒涘缓URL瀵硅薄鍜孒ttpURLConnection瀵硅薄
-        URL obj = new URL(deleteUrl);
-        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
+        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
 
-        // 璁剧疆璇锋眰鏂规硶涓篋ELETE
-        con.setRequestMethod("DELETE");
+        // 娣诲姞MultipartFile鍙傛暟
+//        builder.addBinaryBody("file", entity.getFile().getBytes(), ContentType.MULTIPART_FORM_DATA, entity.getFile().getOriginalFilename());
 
-        // 鍙戦�佽姹傚苟鑾峰彇鍝嶅簲
-        int responseCode = con.getResponseCode();
-        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
-        String inputLine;
-        StringBuffer response = new StringBuffer();
-        while ((inputLine = in.readLine()) != null) {
-            response.append(inputLine);
-        }
-        in.close();
+        // 娣诲姞String鍙傛暟
+        builder.addTextBody("ossId", ossId, ContentType.TEXT_PLAIN);
 
-        // 鎵撳嵃鍝嶅簲缁撴灉
-        System.out.println("Response Code : " + responseCode);
-        System.out.println("Response : " + response.toString());
+        HttpEntity multipart = builder.build();
+        httpPost.setEntity(multipart);
+
+        HttpResponse response = httpClient.execute(httpPost);
+        String responseBody = EntityUtils.toString(response.getEntity());
+        System.out.println("Response: " + responseBody);
+        return responseBody;
     }
 }
 

--
Gitblit v1.8.0