qirong
2023-11-22 6307624c52e8528fd13fadea144f37a62cff5edb
修改
3个文件已修改
74 ■■■■■ 已修改文件
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SynchronizationController.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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) {
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;
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对象和HttpURLConnection对象
//        URL obj = new URL(deleteUrl);
//        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//
//        // 设置请求方法为DELETE
//        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对象和HttpURLConnection对象
        URL obj = new URL(deleteUrl);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        // 设置请求方法为DELETE
        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;
    }
}