From ac2873bd37eeb496b0e9dd62d66e9fc4b38ef39b Mon Sep 17 00:00:00 2001
From: qirong <2032486488@qq.com>
Date: 星期五, 22 十二月 2023 13:38:26 +0800
Subject: [PATCH] ftp摆渡
---
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/properties/FtpConfig.java | 24
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/FtpApche.java | 193 ++++
ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/entity/SynchronousRequest2.java | 25
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/deleteSync.java | 43 +
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java | 52
ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/BoundedQueueController.java | 184 ++--
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/VideoPulSync.java | 117 +++
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/FTPUtil.java | 547 ++++++++++++++
ruoyi-admin/src/main/java/org/dromara/web/service/SysRegisterService.java | 2
ruoyi-admin/src/main/resources/application-prod.yml | 23
ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/config/RedisConfig.java | 2
ruoyi-modules/ruoyi-system/pom.xml | 15
ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/PriorityQueueController.java | 178 ++--
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java | 162 +--
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysOssService.java | 2
ruoyi-admin/src/main/java/org/dromara/DromaraApplication.java | 4
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SynchronizationController.java | 115 ++
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/runner/SystemApplicationRunner.java | 55
ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/QueueUtils.java | 464 +++++-----
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysOssController.java | 89 +
20 files changed, 1,676 insertions(+), 620 deletions(-)
diff --git a/ruoyi-admin/src/main/java/org/dromara/DromaraApplication.java b/ruoyi-admin/src/main/java/org/dromara/DromaraApplication.java
index 8ef33fe..57e792c 100644
--- a/ruoyi-admin/src/main/java/org/dromara/DromaraApplication.java
+++ b/ruoyi-admin/src/main/java/org/dromara/DromaraApplication.java
@@ -3,6 +3,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
+import org.springframework.scheduling.annotation.EnableScheduling;
/**
* 鍚姩绋嬪簭
@@ -10,6 +11,7 @@
* @author Lion Li
*/
+@EnableScheduling
@SpringBootApplication
public class DromaraApplication {
@@ -17,7 +19,7 @@
SpringApplication application = new SpringApplication(DromaraApplication.class);
application.setApplicationStartup(new BufferingApplicationStartup(2048));
application.run(args);
- System.out.println("(鈾モ棤鈥库棤)锞夛緸 RuoYi-Vue-Plus鍚姩鎴愬姛 醿�(麓凇`醿�)锞�");
+ System.out.println("(鈾モ棤鈥库棤)锞夛緸 Vue-Plus鍚姩鎴愬姛 醿�(麓凇`醿�)锞�");
}
}
diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/SysRegisterService.java b/ruoyi-admin/src/main/java/org/dromara/web/service/SysRegisterService.java
index e0ef425..45810dd 100644
--- a/ruoyi-admin/src/main/java/org/dromara/web/service/SysRegisterService.java
+++ b/ruoyi-admin/src/main/java/org/dromara/web/service/SysRegisterService.java
@@ -78,7 +78,7 @@
SysUserVo sysUserVo = userMapper.selectUserByUserName(username);
SysUserRole userRole = new SysUserRole();
userRole.setUserId(sysUserVo.getUserId());
- userRole.setRoleId(Long.valueOf(RoleType.VIDEO.getType()));
+ userRole.setRoleId(Long.valueOf(RoleType.POLICE.getType()));
userRoleMapper.insert(userRole);
recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.register.success"));
}
diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml
index 2d96cc0..a2cb46f 100644
--- a/ruoyi-admin/src/main/resources/application-prod.yml
+++ b/ruoyi-admin/src/main/resources/application-prod.yml
@@ -43,12 +43,12 @@
driverClassName: com.mysql.cj.jdbc.Driver
# jdbc 鎵�鏈夊弬鏁伴厤缃弬鑰� https://lionli.blog.csdn.net/article/details/122018562
# rewriteBatchedStatements=true 鎵瑰鐞嗕紭鍖� 澶у箙鎻愬崌鎵归噺鎻掑叆鏇存柊鍒犻櫎鎬ц兘(瀵规暟鎹簱鏈夋�ц兘鎹熻�� 浣跨敤鎵归噺鎿嶄綔搴旇�冭檻鎬ц兘闂)
- url: jdbc:mysql://123.207.71.245:13306/qysp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
- username: root
- password: 234#Wersdf!
-# url: jdbc:mysql://80.36.32.176:3306/qysp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
+# url: jdbc:mysql://123.207.71.245:13306/qysp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
# username: root
# password: 234#Wersdf!
+ url: jdbc:mysql://80.36.32.176:3306/qysp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
+ username: root
+ password: 234#Wersdf!
# url: jdbc:mysql://51.9.57.211:3306/qysp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
# username: root
# password: 234#Wersdf!
@@ -105,9 +105,9 @@
spring.data:
redis:
# 鍦板潃
- host: 162.14.79.111
+ host: 80.36.32.176
# 绔彛锛岄粯璁や负6379
- port: 16379
+ port: 6379
password: 234#Wersdf!
# 鏁版嵁搴撶储寮�
database: 0
@@ -136,7 +136,7 @@
# 杩炴帴绌洪棽瓒呮椂锛屽崟浣嶏細姣
idleConnectionTimeout: 10000
# 鍛戒护绛夊緟瓒呮椂锛屽崟浣嶏細姣
- timeout: 3000
+ timeout: 10000
# 鍙戝竷鍜岃闃呰繛鎺ユ睜澶у皬
subscriptionConnectionPoolSize: 50
@@ -262,6 +262,13 @@
--- #杈圭晫
police:
- localhost: http://192.168.3.228:8801 #娴嬭瘯
+ localhost: http://127.0.0.1:8080 #娴嬭瘯
chief: http://10.248.255.130:18080 #鏀垮姟浜�
video: http://51.9.1.41:18080 #瑙嗛缃�
+
+--- #ftp
+ftp:
+ url: 51.9.57.211
+ username: admin #鏈満锛歠tpup
+ passwd: 234#Wersdf!
+ path: /
diff --git a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/entity/SynchronousRequest2.java b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/entity/SynchronousRequest2.java
new file mode 100644
index 0000000..33416fa
--- /dev/null
+++ b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/entity/SynchronousRequest2.java
@@ -0,0 +1,25 @@
+package org.dromara.common.oss.entity;
+
+import lombok.Data;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.InputStream;
+
+@Data
+public class SynchronousRequest2 {
+
+ //InputStream 娴�
+ private InputStream input;
+ //minio璺緞
+ private String path;
+ //ossId
+ private String ossId;
+ //鍒涘缓鏃堕棿
+ private String createTime;
+ //鍒涘缓浜�
+ private String createBy;
+ //瀵嗙爜
+ private String password;
+ //鏂囦欢鍚嶇О
+ private String fileName;
+}
diff --git a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/config/RedisConfig.java b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/config/RedisConfig.java
index 0ee947d..549d049 100644
--- a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/config/RedisConfig.java
+++ b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/config/RedisConfig.java
@@ -62,7 +62,7 @@
.setSubscriptionConnectionPoolSize(singleServerConfig.getSubscriptionConnectionPoolSize())
.setConnectionMinimumIdleSize(singleServerConfig.getConnectionMinimumIdleSize())
.setConnectionPoolSize(singleServerConfig.getConnectionPoolSize())
- .setSubscriptionsPerConnection(5000);
+ .setSubscriptionsPerConnection(60 * 10000);
}
// 闆嗙兢閰嶇疆鏂瑰紡 鍙傝�冧笅鏂规敞閲�
RedissonProperties.ClusterServersConfig clusterServersConfig = redissonProperties.getClusterServersConfig();
diff --git a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/QueueUtils.java b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/QueueUtils.java
index 67ce552..47c9176 100644
--- a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/QueueUtils.java
+++ b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/QueueUtils.java
@@ -1,232 +1,232 @@
-package org.dromara.common.redis.utils;
-
-import org.dromara.common.core.utils.SpringUtils;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.redisson.api.*;
-
-import java.util.concurrent.TimeUnit;
-import java.util.function.Consumer;
-
-/**
- * 鍒嗗竷寮忛槦鍒楀伐鍏�
- * 杞婚噺绾ч槦鍒� 閲嶉噺绾ф暟鎹噺 璇蜂娇鐢� MQ
- * 瑕佹眰 redis 5.X 浠ヤ笂
- *
- * @author Lion Li
- * @version 3.6.0 鏂板
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public class QueueUtils {
-
- private static final RedissonClient CLIENT = SpringUtils.getBean(RedissonClient.class);
-
-
- /**
- * 鑾峰彇瀹㈡埛绔疄渚�
- */
- public static RedissonClient getClient() {
- return CLIENT;
- }
-
- /**
- * 娣诲姞鏅�氶槦鍒楁暟鎹�
- *
- * @param queueName 闃熷垪鍚�
- * @param data 鏁版嵁
- */
- public static <T> boolean addQueueObject(String queueName, T data) {
- RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
- return queue.offer(data);
- }
-
- /**
- * 閫氱敤鑾峰彇涓�涓槦鍒楁暟鎹� 娌℃湁鏁版嵁杩斿洖 null(涓嶆敮鎸佸欢杩熼槦鍒�)
- *
- * @param queueName 闃熷垪鍚�
- */
- public static <T> T getQueueObject(String queueName) {
- RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
- return queue.poll();
- }
-
- /**
- * 閫氱敤鍒犻櫎闃熷垪鏁版嵁(涓嶆敮鎸佸欢杩熼槦鍒�)
- */
- public static <T> boolean removeQueueObject(String queueName, T data) {
- RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
- return queue.remove(data);
- }
-
- /**
- * 閫氱敤閿�姣侀槦鍒� 鎵�鏈夐樆濉炵洃鍚� 鎶ラ敊(涓嶆敮鎸佸欢杩熼槦鍒�)
- */
- public static <T> boolean destroyQueue(String queueName) {
- RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
- return queue.delete();
- }
-
- /**
- * 娣诲姞寤惰繜闃熷垪鏁版嵁 榛樿姣
- *
- * @param queueName 闃熷垪鍚�
- * @param data 鏁版嵁
- * @param time 寤惰繜鏃堕棿
- */
- public static <T> void addDelayedQueueObject(String queueName, T data, long time) {
- addDelayedQueueObject(queueName, data, time, TimeUnit.MILLISECONDS);
- }
-
- /**
- * 娣诲姞寤惰繜闃熷垪鏁版嵁
- *
- * @param queueName 闃熷垪鍚�
- * @param data 鏁版嵁
- * @param time 寤惰繜鏃堕棿
- * @param timeUnit 鍗曚綅
- */
- public static <T> void addDelayedQueueObject(String queueName, T data, long time, TimeUnit timeUnit) {
- RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
- RDelayedQueue<T> delayedQueue = CLIENT.getDelayedQueue(queue);
- delayedQueue.offer(data, time, timeUnit);
- }
-
- /**
- * 鑾峰彇涓�涓欢杩熼槦鍒楁暟鎹� 娌℃湁鏁版嵁杩斿洖 null
- *
- * @param queueName 闃熷垪鍚�
- */
- public static <T> T getDelayedQueueObject(String queueName) {
- RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
- RDelayedQueue<T> delayedQueue = CLIENT.getDelayedQueue(queue);
- return delayedQueue.poll();
- }
-
- /**
- * 鍒犻櫎寤惰繜闃熷垪鏁版嵁
- */
- public static <T> boolean removeDelayedQueueObject(String queueName, T data) {
- RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
- RDelayedQueue<T> delayedQueue = CLIENT.getDelayedQueue(queue);
- return delayedQueue.remove(data);
- }
-
- /**
- * 閿�姣佸欢杩熼槦鍒� 鎵�鏈夐樆濉炵洃鍚� 鎶ラ敊
- */
- public static <T> void destroyDelayedQueue(String queueName) {
- RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
- RDelayedQueue<T> delayedQueue = CLIENT.getDelayedQueue(queue);
- delayedQueue.destroy();
- }
-
- /**
- * 娣诲姞浼樺厛闃熷垪鏁版嵁
- *
- * @param queueName 闃熷垪鍚�
- * @param data 鏁版嵁
- */
- public static <T> boolean addPriorityQueueObject(String queueName, T data) {
- RPriorityBlockingQueue<T> priorityBlockingQueue = CLIENT.getPriorityBlockingQueue(queueName);
- return priorityBlockingQueue.offer(data);
- }
-
- /**
- * 浼樺厛闃熷垪鑾峰彇涓�涓槦鍒楁暟鎹� 娌℃湁鏁版嵁杩斿洖 null(涓嶆敮鎸佸欢杩熼槦鍒�)
- *
- * @param queueName 闃熷垪鍚�
- */
- public static <T> T getPriorityQueueObject(String queueName) {
- RPriorityBlockingQueue<T> queue = CLIENT.getPriorityBlockingQueue(queueName);
- return queue.poll();
- }
-
- /**
- * 浼樺厛闃熷垪鍒犻櫎闃熷垪鏁版嵁(涓嶆敮鎸佸欢杩熼槦鍒�)
- */
- public static <T> boolean removePriorityQueueObject(String queueName, T data) {
- RPriorityBlockingQueue<T> queue = CLIENT.getPriorityBlockingQueue(queueName);
- return queue.remove(data);
- }
-
- /**
- * 浼樺厛闃熷垪閿�姣侀槦鍒� 鎵�鏈夐樆濉炵洃鍚� 鎶ラ敊(涓嶆敮鎸佸欢杩熼槦鍒�)
- */
- public static <T> boolean destroyPriorityQueue(String queueName) {
- RPriorityBlockingQueue<T> queue = CLIENT.getPriorityBlockingQueue(queueName);
- return queue.delete();
- }
-
- /**
- * 灏濊瘯璁剧疆 鏈夌晫闃熷垪 瀹归噺 鐢ㄤ簬闄愬埗鏁伴噺
- *
- * @param queueName 闃熷垪鍚�
- * @param capacity 瀹归噺
- */
- public static <T> boolean trySetBoundedQueueCapacity(String queueName, int capacity) {
- RBoundedBlockingQueue<T> boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName);
- return boundedBlockingQueue.trySetCapacity(capacity);
- }
-
- /**
- * 灏濊瘯璁剧疆 鏈夌晫闃熷垪 瀹归噺 鐢ㄤ簬闄愬埗鏁伴噺
- *
- * @param queueName 闃熷垪鍚�
- * @param capacity 瀹归噺
- * @param destroy 宸插瓨鍦ㄦ槸鍚﹂攢姣�
- */
- public static <T> boolean trySetBoundedQueueCapacity(String queueName, int capacity, boolean destroy) {
- RBoundedBlockingQueue<T> boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName);
- if (boundedBlockingQueue.isExists() && destroy) {
- destroyQueue(queueName);
- }
- return boundedBlockingQueue.trySetCapacity(capacity);
- }
-
- /**
- * 娣诲姞鏈夌晫闃熷垪鏁版嵁
- *
- * @param queueName 闃熷垪鍚�
- * @param data 鏁版嵁
- * @return 娣诲姞鎴愬姛 true 宸茶揪鍒扮晫闄� false
- */
- public static <T> boolean addBoundedQueueObject(String queueName, T data) {
- RBoundedBlockingQueue<T> boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName);
- return boundedBlockingQueue.offer(data);
- }
-
- /**
- * 鏈夌晫闃熷垪鑾峰彇涓�涓槦鍒楁暟鎹� 娌℃湁鏁版嵁杩斿洖 null(涓嶆敮鎸佸欢杩熼槦鍒�)
- *
- * @param queueName 闃熷垪鍚�
- */
- public static <T> T getBoundedQueueObject(String queueName) {
- RBoundedBlockingQueue<T> queue = CLIENT.getBoundedBlockingQueue(queueName);
- return queue.poll();
- }
-
- /**
- * 鏈夌晫闃熷垪鍒犻櫎闃熷垪鏁版嵁(涓嶆敮鎸佸欢杩熼槦鍒�)
- */
- public static <T> boolean removeBoundedQueueObject(String queueName, T data) {
- RBoundedBlockingQueue<T> queue = CLIENT.getBoundedBlockingQueue(queueName);
- return queue.remove(data);
- }
-
- /**
- * 鏈夌晫闃熷垪閿�姣侀槦鍒� 鎵�鏈夐樆濉炵洃鍚� 鎶ラ敊(涓嶆敮鎸佸欢杩熼槦鍒�)
- */
- public static <T> boolean destroyBoundedQueue(String queueName) {
- RBoundedBlockingQueue<T> queue = CLIENT.getBoundedBlockingQueue(queueName);
- return queue.delete();
- }
-
- /**
- * 璁㈤槄闃诲闃熷垪(鍙闃呮墍鏈夊疄鐜扮被 渚嬪: 寤惰繜 浼樺厛 鏈夌晫 绛�)
- */
- public static <T> void subscribeBlockingQueue(String queueName, Consumer<T> consumer) {
- RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
- queue.subscribeOnElements(consumer);
- }
-
-}
+//package org.dromara.common.redis.utils;
+//
+//import org.dromara.common.core.utils.SpringUtils;
+//import lombok.AccessLevel;
+//import lombok.NoArgsConstructor;
+//import org.redisson.api.*;
+//
+//import java.util.concurrent.TimeUnit;
+//import java.util.function.Consumer;
+//
+///**
+// * 鍒嗗竷寮忛槦鍒楀伐鍏�
+// * 杞婚噺绾ч槦鍒� 閲嶉噺绾ф暟鎹噺 璇蜂娇鐢� MQ
+// * 瑕佹眰 redis 5.X 浠ヤ笂
+// *
+// * @author Lion Li
+// * @version 3.6.0 鏂板
+// */
+//@NoArgsConstructor(access = AccessLevel.PRIVATE)
+//public class QueueUtils {
+//
+// private static final RedissonClient CLIENT = SpringUtils.getBean(RedissonClient.class);
+//
+//
+// /**
+// * 鑾峰彇瀹㈡埛绔疄渚�
+// */
+// public static RedissonClient getClient() {
+// return CLIENT;
+// }
+//
+// /**
+// * 娣诲姞鏅�氶槦鍒楁暟鎹�
+// *
+// * @param queueName 闃熷垪鍚�
+// * @param data 鏁版嵁
+// */
+// public static <T> boolean addQueueObject(String queueName, T data) {
+// RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
+// return queue.offer(data);
+// }
+//
+// /**
+// * 閫氱敤鑾峰彇涓�涓槦鍒楁暟鎹� 娌℃湁鏁版嵁杩斿洖 null(涓嶆敮鎸佸欢杩熼槦鍒�)
+// *
+// * @param queueName 闃熷垪鍚�
+// */
+// public static <T> T getQueueObject(String queueName) {
+// RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
+// return queue.poll();
+// }
+//
+// /**
+// * 閫氱敤鍒犻櫎闃熷垪鏁版嵁(涓嶆敮鎸佸欢杩熼槦鍒�)
+// */
+// public static <T> boolean removeQueueObject(String queueName, T data) {
+// RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
+// return queue.remove(data);
+// }
+//
+// /**
+// * 閫氱敤閿�姣侀槦鍒� 鎵�鏈夐樆濉炵洃鍚� 鎶ラ敊(涓嶆敮鎸佸欢杩熼槦鍒�)
+// */
+// public static <T> boolean destroyQueue(String queueName) {
+// RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
+// return queue.delete();
+// }
+//
+// /**
+// * 娣诲姞寤惰繜闃熷垪鏁版嵁 榛樿姣
+// *
+// * @param queueName 闃熷垪鍚�
+// * @param data 鏁版嵁
+// * @param time 寤惰繜鏃堕棿
+// */
+// public static <T> void addDelayedQueueObject(String queueName, T data, long time) {
+// addDelayedQueueObject(queueName, data, time, TimeUnit.MILLISECONDS);
+// }
+//
+// /**
+// * 娣诲姞寤惰繜闃熷垪鏁版嵁
+// *
+// * @param queueName 闃熷垪鍚�
+// * @param data 鏁版嵁
+// * @param time 寤惰繜鏃堕棿
+// * @param timeUnit 鍗曚綅
+// */
+// public static <T> void addDelayedQueueObject(String queueName, T data, long time, TimeUnit timeUnit) {
+// RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
+// RDelayedQueue<T> delayedQueue = CLIENT.getDelayedQueue(queue);
+// delayedQueue.offer(data, time, timeUnit);
+// }
+//
+// /**
+// * 鑾峰彇涓�涓欢杩熼槦鍒楁暟鎹� 娌℃湁鏁版嵁杩斿洖 null
+// *
+// * @param queueName 闃熷垪鍚�
+// */
+// public static <T> T getDelayedQueueObject(String queueName) {
+// RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
+// RDelayedQueue<T> delayedQueue = CLIENT.getDelayedQueue(queue);
+// return delayedQueue.poll();
+// }
+//
+// /**
+// * 鍒犻櫎寤惰繜闃熷垪鏁版嵁
+// */
+// public static <T> boolean removeDelayedQueueObject(String queueName, T data) {
+// RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
+// RDelayedQueue<T> delayedQueue = CLIENT.getDelayedQueue(queue);
+// return delayedQueue.remove(data);
+// }
+//
+// /**
+// * 閿�姣佸欢杩熼槦鍒� 鎵�鏈夐樆濉炵洃鍚� 鎶ラ敊
+// */
+// public static <T> void destroyDelayedQueue(String queueName) {
+// RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
+// RDelayedQueue<T> delayedQueue = CLIENT.getDelayedQueue(queue);
+// delayedQueue.destroy();
+// }
+//
+// /**
+// * 娣诲姞浼樺厛闃熷垪鏁版嵁
+// *
+// * @param queueName 闃熷垪鍚�
+// * @param data 鏁版嵁
+// */
+// public static <T> boolean addPriorityQueueObject(String queueName, T data) {
+// RPriorityBlockingQueue<T> priorityBlockingQueue = CLIENT.getPriorityBlockingQueue(queueName);
+// return priorityBlockingQueue.offer(data);
+// }
+//
+// /**
+// * 浼樺厛闃熷垪鑾峰彇涓�涓槦鍒楁暟鎹� 娌℃湁鏁版嵁杩斿洖 null(涓嶆敮鎸佸欢杩熼槦鍒�)
+// *
+// * @param queueName 闃熷垪鍚�
+// */
+// public static <T> T getPriorityQueueObject(String queueName) {
+// RPriorityBlockingQueue<T> queue = CLIENT.getPriorityBlockingQueue(queueName);
+// return queue.poll();
+// }
+//
+// /**
+// * 浼樺厛闃熷垪鍒犻櫎闃熷垪鏁版嵁(涓嶆敮鎸佸欢杩熼槦鍒�)
+// */
+// public static <T> boolean removePriorityQueueObject(String queueName, T data) {
+// RPriorityBlockingQueue<T> queue = CLIENT.getPriorityBlockingQueue(queueName);
+// return queue.remove(data);
+// }
+//
+// /**
+// * 浼樺厛闃熷垪閿�姣侀槦鍒� 鎵�鏈夐樆濉炵洃鍚� 鎶ラ敊(涓嶆敮鎸佸欢杩熼槦鍒�)
+// */
+// public static <T> boolean destroyPriorityQueue(String queueName) {
+// RPriorityBlockingQueue<T> queue = CLIENT.getPriorityBlockingQueue(queueName);
+// return queue.delete();
+// }
+//
+// /**
+// * 灏濊瘯璁剧疆 鏈夌晫闃熷垪 瀹归噺 鐢ㄤ簬闄愬埗鏁伴噺
+// *
+// * @param queueName 闃熷垪鍚�
+// * @param capacity 瀹归噺
+// */
+// public static <T> boolean trySetBoundedQueueCapacity(String queueName, int capacity) {
+// RBoundedBlockingQueue<T> boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName);
+// return boundedBlockingQueue.trySetCapacity(capacity);
+// }
+//
+// /**
+// * 灏濊瘯璁剧疆 鏈夌晫闃熷垪 瀹归噺 鐢ㄤ簬闄愬埗鏁伴噺
+// *
+// * @param queueName 闃熷垪鍚�
+// * @param capacity 瀹归噺
+// * @param destroy 宸插瓨鍦ㄦ槸鍚﹂攢姣�
+// */
+// public static <T> boolean trySetBoundedQueueCapacity(String queueName, int capacity, boolean destroy) {
+// RBoundedBlockingQueue<T> boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName);
+// if (boundedBlockingQueue.isExists() && destroy) {
+// destroyQueue(queueName);
+// }
+// return boundedBlockingQueue.trySetCapacity(capacity);
+// }
+//
+// /**
+// * 娣诲姞鏈夌晫闃熷垪鏁版嵁
+// *
+// * @param queueName 闃熷垪鍚�
+// * @param data 鏁版嵁
+// * @return 娣诲姞鎴愬姛 true 宸茶揪鍒扮晫闄� false
+// */
+// public static <T> boolean addBoundedQueueObject(String queueName, T data) {
+// RBoundedBlockingQueue<T> boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName);
+// return boundedBlockingQueue.offer(data);
+// }
+//
+// /**
+// * 鏈夌晫闃熷垪鑾峰彇涓�涓槦鍒楁暟鎹� 娌℃湁鏁版嵁杩斿洖 null(涓嶆敮鎸佸欢杩熼槦鍒�)
+// *
+// * @param queueName 闃熷垪鍚�
+// */
+// public static <T> T getBoundedQueueObject(String queueName) {
+// RBoundedBlockingQueue<T> queue = CLIENT.getBoundedBlockingQueue(queueName);
+// return queue.poll();
+// }
+//
+// /**
+// * 鏈夌晫闃熷垪鍒犻櫎闃熷垪鏁版嵁(涓嶆敮鎸佸欢杩熼槦鍒�)
+// */
+// public static <T> boolean removeBoundedQueueObject(String queueName, T data) {
+// RBoundedBlockingQueue<T> queue = CLIENT.getBoundedBlockingQueue(queueName);
+// return queue.remove(data);
+// }
+//
+// /**
+// * 鏈夌晫闃熷垪閿�姣侀槦鍒� 鎵�鏈夐樆濉炵洃鍚� 鎶ラ敊(涓嶆敮鎸佸欢杩熼槦鍒�)
+// */
+// public static <T> boolean destroyBoundedQueue(String queueName) {
+// RBoundedBlockingQueue<T> queue = CLIENT.getBoundedBlockingQueue(queueName);
+// return queue.delete();
+// }
+//
+// /**
+// * 璁㈤槄闃诲闃熷垪(鍙闃呮墍鏈夊疄鐜扮被 渚嬪: 寤惰繜 浼樺厛 鏈夌晫 绛�)
+// */
+// public static <T> void subscribeBlockingQueue(String queueName, Consumer<T> consumer) {
+// RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName);
+// queue.subscribeOnElements(consumer);
+// }
+//
+//}
diff --git a/ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/BoundedQueueController.java b/ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/BoundedQueueController.java
index 30ec27f..c03aa6e 100644
--- a/ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/BoundedQueueController.java
+++ b/ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/BoundedQueueController.java
@@ -1,92 +1,92 @@
-package org.dromara.demo.controller.queue;
-
-import cn.dev33.satoken.annotation.SaIgnore;
-import org.dromara.common.core.domain.R;
-import org.dromara.common.redis.utils.QueueUtils;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.redisson.api.RBoundedBlockingQueue;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 鏈夌晫闃熷垪 婕旂ず妗堜緥
- * <p>
- * 杞婚噺绾ч槦鍒� 閲嶉噺绾ф暟鎹噺 璇蜂娇鐢� MQ
- * <p>
- * 闆嗙兢娴嬭瘯閫氳繃 鍚屼竴涓暟鎹彧浼氳娑堣垂涓�娆� 鍋氬ソ浜嬪姟琛ュ伩
- * 闆嗙兢娴嬭瘯娴佺▼ 鍦ㄥ叾涓竴鍙板彂閫佹暟鎹� 涓ょ鍒嗗埆璋冪敤鑾峰彇鎺ュ彛 涓�娆¤幏鍙栦竴鏉�
- *
- * @author Lion Li
- * @version 3.6.0
- */
-@Slf4j
-@RequiredArgsConstructor
-@RestController
-@RequestMapping("/demo/queue/bounded")
-public class BoundedQueueController {
-
-
- /**
- * 娣诲姞闃熷垪鏁版嵁
- *
- * @param queueName 闃熷垪鍚�
- * @param capacity 瀹归噺
- */
- @GetMapping("/add")
- public R<Void> add(String queueName, int capacity) {
- // 鐢ㄥ畬浜嗕竴瀹氳閿�姣� 鍚﹀垯浼氫竴鐩村瓨鍦�
- boolean b = QueueUtils.destroyBoundedQueue(queueName);
- log.info("閫氶亾: {} , 鍒犻櫎: {}", queueName, b);
- // 鍒濆鍖栬缃竴娆″嵆鍙�
- if (QueueUtils.trySetBoundedQueueCapacity(queueName, capacity)) {
- log.info("閫氶亾: {} , 璁剧疆瀹归噺: {}", queueName, capacity);
- } else {
- log.info("閫氶亾: {} , 璁剧疆瀹归噺澶辫触", queueName);
- return R.fail("鎿嶄綔澶辫触");
- }
- for (int i = 0; i < 11; i++) {
- String data = "data-" + i;
- boolean flag = QueueUtils.addBoundedQueueObject(queueName, data);
- if (flag == false) {
- log.info("閫氶亾: {} , 鍙戦�佹暟鎹�: {} 澶辫触, 閫氶亾宸叉弧", queueName, data);
- } else {
- log.info("閫氶亾: {} , 鍙戦�佹暟鎹�: {}", queueName, data);
- }
- }
- return R.ok("鎿嶄綔鎴愬姛");
- }
-
- /**
- * 鍒犻櫎闃熷垪鏁版嵁
- *
- * @param queueName 闃熷垪鍚�
- */
- @GetMapping("/remove")
- public R<Void> remove(String queueName) {
- String data = "data-" + 5;
- if (QueueUtils.removeBoundedQueueObject(queueName, data)) {
- log.info("閫氶亾: {} , 鍒犻櫎鏁版嵁: {}", queueName, data);
- } else {
- return R.fail("鎿嶄綔澶辫触");
- }
- return R.ok("鎿嶄綔鎴愬姛");
- }
-
- /**
- * 鑾峰彇闃熷垪鏁版嵁
- *
- * @param queueName 闃熷垪鍚�
- */
- @GetMapping("/get")
- public R<Void> get(String queueName) {
- String data;
- do {
- data = QueueUtils.getBoundedQueueObject(queueName);
- log.info("閫氶亾: {} , 鑾峰彇鏁版嵁: {}", queueName, data);
- } while (data != null);
- return R.ok("鎿嶄綔鎴愬姛");
- }
-
-}
+//package org.dromara.demo.controller.queue;
+//
+//import cn.dev33.satoken.annotation.SaIgnore;
+//import org.dromara.common.core.domain.R;
+//import org.dromara.common.redis.utils.QueueUtils;
+//import lombok.RequiredArgsConstructor;
+//import lombok.extern.slf4j.Slf4j;
+//import org.redisson.api.RBoundedBlockingQueue;
+//import org.springframework.web.bind.annotation.GetMapping;
+//import org.springframework.web.bind.annotation.RequestMapping;
+//import org.springframework.web.bind.annotation.RestController;
+//
+///**
+// * 鏈夌晫闃熷垪 婕旂ず妗堜緥
+// * <p>
+// * 杞婚噺绾ч槦鍒� 閲嶉噺绾ф暟鎹噺 璇蜂娇鐢� MQ
+// * <p>
+// * 闆嗙兢娴嬭瘯閫氳繃 鍚屼竴涓暟鎹彧浼氳娑堣垂涓�娆� 鍋氬ソ浜嬪姟琛ュ伩
+// * 闆嗙兢娴嬭瘯娴佺▼ 鍦ㄥ叾涓竴鍙板彂閫佹暟鎹� 涓ょ鍒嗗埆璋冪敤鑾峰彇鎺ュ彛 涓�娆¤幏鍙栦竴鏉�
+// *
+// * @author Lion Li
+// * @version 3.6.0
+// */
+//@Slf4j
+//@RequiredArgsConstructor
+//@RestController
+//@RequestMapping("/demo/queue/bounded")
+//public class BoundedQueueController {
+//
+//
+// /**
+// * 娣诲姞闃熷垪鏁版嵁
+// *
+// * @param queueName 闃熷垪鍚�
+// * @param capacity 瀹归噺
+// */
+// @GetMapping("/add")
+// public R<Void> add(String queueName, int capacity) {
+// // 鐢ㄥ畬浜嗕竴瀹氳閿�姣� 鍚﹀垯浼氫竴鐩村瓨鍦�
+// boolean b = QueueUtils.destroyBoundedQueue(queueName);
+// log.info("閫氶亾: {} , 鍒犻櫎: {}", queueName, b);
+// // 鍒濆鍖栬缃竴娆″嵆鍙�
+// if (QueueUtils.trySetBoundedQueueCapacity(queueName, capacity)) {
+// log.info("閫氶亾: {} , 璁剧疆瀹归噺: {}", queueName, capacity);
+// } else {
+// log.info("閫氶亾: {} , 璁剧疆瀹归噺澶辫触", queueName);
+// return R.fail("鎿嶄綔澶辫触");
+// }
+// for (int i = 0; i < 11; i++) {
+// String data = "data-" + i;
+// boolean flag = QueueUtils.addBoundedQueueObject(queueName, data);
+// if (flag == false) {
+// log.info("閫氶亾: {} , 鍙戦�佹暟鎹�: {} 澶辫触, 閫氶亾宸叉弧", queueName, data);
+// } else {
+// log.info("閫氶亾: {} , 鍙戦�佹暟鎹�: {}", queueName, data);
+// }
+// }
+// return R.ok("鎿嶄綔鎴愬姛");
+// }
+//
+// /**
+// * 鍒犻櫎闃熷垪鏁版嵁
+// *
+// * @param queueName 闃熷垪鍚�
+// */
+// @GetMapping("/remove")
+// public R<Void> remove(String queueName) {
+// String data = "data-" + 5;
+// if (QueueUtils.removeBoundedQueueObject(queueName, data)) {
+// log.info("閫氶亾: {} , 鍒犻櫎鏁版嵁: {}", queueName, data);
+// } else {
+// return R.fail("鎿嶄綔澶辫触");
+// }
+// return R.ok("鎿嶄綔鎴愬姛");
+// }
+//
+// /**
+// * 鑾峰彇闃熷垪鏁版嵁
+// *
+// * @param queueName 闃熷垪鍚�
+// */
+// @GetMapping("/get")
+// public R<Void> get(String queueName) {
+// String data;
+// do {
+// data = QueueUtils.getBoundedQueueObject(queueName);
+// log.info("閫氶亾: {} , 鑾峰彇鏁版嵁: {}", queueName, data);
+// } while (data != null);
+// return R.ok("鎿嶄綔鎴愬姛");
+// }
+//
+//}
diff --git a/ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/PriorityQueueController.java b/ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/PriorityQueueController.java
index 02c7396..fd637ff 100644
--- a/ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/PriorityQueueController.java
+++ b/ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/PriorityQueueController.java
@@ -1,89 +1,89 @@
-package org.dromara.demo.controller.queue;
-
-import cn.hutool.core.util.RandomUtil;
-import org.dromara.common.core.domain.R;
-import org.dromara.common.redis.utils.QueueUtils;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 浼樺厛闃熷垪 婕旂ず妗堜緥
- * <p>
- * 杞婚噺绾ч槦鍒� 閲嶉噺绾ф暟鎹噺 璇蜂娇鐢� MQ
- * <p>
- * 闆嗙兢娴嬭瘯閫氳繃 鍚屼竴涓秷鎭彧浼氳娑堣垂涓�娆� 鍋氬ソ浜嬪姟琛ュ伩
- * 闆嗙兢娴嬭瘯娴佺▼ 鍦ㄥ叾涓竴鍙板彂閫佹暟鎹� 涓ょ鍒嗗埆璋冪敤鑾峰彇鎺ュ彛 涓�娆¤幏鍙栦竴鏉�
- *
- * @author Lion Li
- * @version 3.6.0
- */
-@Slf4j
-@RequiredArgsConstructor
-@RestController
-@RequestMapping("/demo/queue/priority")
-public class PriorityQueueController {
-
- /**
- * 娣诲姞闃熷垪鏁版嵁
- *
- * @param queueName 闃熷垪鍚�
- */
- @GetMapping("/add")
- public R<Void> add(String queueName) {
- // 鐢ㄥ畬浜嗕竴瀹氳閿�姣� 鍚﹀垯浼氫竴鐩村瓨鍦�
- boolean b = QueueUtils.destroyPriorityQueue(queueName);
- log.info("閫氶亾: {} , 鍒犻櫎: {}", queueName, b);
-
- for (int i = 0; i < 10; i++) {
- int randomNum = RandomUtil.randomInt(10);
- PriorityDemo data = new PriorityDemo();
- data.setName("data-" + i);
- data.setOrderNum(randomNum);
- if (QueueUtils.addPriorityQueueObject(queueName, data)) {
- log.info("閫氶亾: {} , 鍙戦�佹暟鎹�: {}", queueName, data);
- } else {
- log.info("閫氶亾: {} , 鍙戦�佹暟鎹�: {}, 鍙戦�佸け璐�", queueName, data);
- }
- }
- return R.ok("鎿嶄綔鎴愬姛");
- }
-
- /**
- * 鍒犻櫎闃熷垪鏁版嵁
- *
- * @param queueName 闃熷垪鍚�
- * @param name 瀵硅薄鍚�
- * @param orderNum 鎺掑簭鍙�
- */
- @GetMapping("/remove")
- public R<Void> remove(String queueName, String name, Integer orderNum) {
- PriorityDemo data = new PriorityDemo();
- data.setName(name);
- data.setOrderNum(orderNum);
- if (QueueUtils.removePriorityQueueObject(queueName, data)) {
- log.info("閫氶亾: {} , 鍒犻櫎鏁版嵁: {}", queueName, data);
- } else {
- return R.fail("鎿嶄綔澶辫触");
- }
- return R.ok("鎿嶄綔鎴愬姛");
- }
-
- /**
- * 鑾峰彇闃熷垪鏁版嵁
- *
- * @param queueName 闃熷垪鍚�
- */
- @GetMapping("/get")
- public R<Void> get(String queueName) {
- PriorityDemo data;
- do {
- data = QueueUtils.getPriorityQueueObject(queueName);
- log.info("閫氶亾: {} , 鑾峰彇鏁版嵁: {}", queueName, data);
- } while (data != null);
- return R.ok("鎿嶄綔鎴愬姛");
- }
-
-}
+//package org.dromara.demo.controller.queue;
+//
+//import cn.hutool.core.util.RandomUtil;
+//import org.dromara.common.core.domain.R;
+//import org.dromara.common.redis.utils.QueueUtils;
+//import lombok.RequiredArgsConstructor;
+//import lombok.extern.slf4j.Slf4j;
+//import org.springframework.web.bind.annotation.GetMapping;
+//import org.springframework.web.bind.annotation.RequestMapping;
+//import org.springframework.web.bind.annotation.RestController;
+//
+///**
+// * 浼樺厛闃熷垪 婕旂ず妗堜緥
+// * <p>
+// * 杞婚噺绾ч槦鍒� 閲嶉噺绾ф暟鎹噺 璇蜂娇鐢� MQ
+// * <p>
+// * 闆嗙兢娴嬭瘯閫氳繃 鍚屼竴涓秷鎭彧浼氳娑堣垂涓�娆� 鍋氬ソ浜嬪姟琛ュ伩
+// * 闆嗙兢娴嬭瘯娴佺▼ 鍦ㄥ叾涓竴鍙板彂閫佹暟鎹� 涓ょ鍒嗗埆璋冪敤鑾峰彇鎺ュ彛 涓�娆¤幏鍙栦竴鏉�
+// *
+// * @author Lion Li
+// * @version 3.6.0
+// */
+//@Slf4j
+//@RequiredArgsConstructor
+//@RestController
+//@RequestMapping("/demo/queue/priority")
+//public class PriorityQueueController {
+//
+// /**
+// * 娣诲姞闃熷垪鏁版嵁
+// *
+// * @param queueName 闃熷垪鍚�
+// */
+// @GetMapping("/add")
+// public R<Void> add(String queueName) {
+// // 鐢ㄥ畬浜嗕竴瀹氳閿�姣� 鍚﹀垯浼氫竴鐩村瓨鍦�
+// boolean b = QueueUtils.destroyPriorityQueue(queueName);
+// log.info("閫氶亾: {} , 鍒犻櫎: {}", queueName, b);
+//
+// for (int i = 0; i < 10; i++) {
+// int randomNum = RandomUtil.randomInt(10);
+// PriorityDemo data = new PriorityDemo();
+// data.setName("data-" + i);
+// data.setOrderNum(randomNum);
+// if (QueueUtils.addPriorityQueueObject(queueName, data)) {
+// log.info("閫氶亾: {} , 鍙戦�佹暟鎹�: {}", queueName, data);
+// } else {
+// log.info("閫氶亾: {} , 鍙戦�佹暟鎹�: {}, 鍙戦�佸け璐�", queueName, data);
+// }
+// }
+// return R.ok("鎿嶄綔鎴愬姛");
+// }
+//
+// /**
+// * 鍒犻櫎闃熷垪鏁版嵁
+// *
+// * @param queueName 闃熷垪鍚�
+// * @param name 瀵硅薄鍚�
+// * @param orderNum 鎺掑簭鍙�
+// */
+// @GetMapping("/remove")
+// public R<Void> remove(String queueName, String name, Integer orderNum) {
+// PriorityDemo data = new PriorityDemo();
+// data.setName(name);
+// data.setOrderNum(orderNum);
+// if (QueueUtils.removePriorityQueueObject(queueName, data)) {
+// log.info("閫氶亾: {} , 鍒犻櫎鏁版嵁: {}", queueName, data);
+// } else {
+// return R.fail("鎿嶄綔澶辫触");
+// }
+// return R.ok("鎿嶄綔鎴愬姛");
+// }
+//
+// /**
+// * 鑾峰彇闃熷垪鏁版嵁
+// *
+// * @param queueName 闃熷垪鍚�
+// */
+// @GetMapping("/get")
+// public R<Void> get(String queueName) {
+// PriorityDemo data;
+// do {
+// data = QueueUtils.getPriorityQueueObject(queueName);
+// log.info("閫氶亾: {} , 鑾峰彇鏁版嵁: {}", queueName, data);
+// } while (data != null);
+// return R.ok("鎿嶄綔鎴愬姛");
+// }
+//
+//}
diff --git a/ruoyi-modules/ruoyi-system/pom.xml b/ruoyi-modules/ruoyi-system/pom.xml
index d1f1a2d..fdafe1d 100644
--- a/ruoyi-modules/ruoyi-system/pom.xml
+++ b/ruoyi-modules/ruoyi-system/pom.xml
@@ -96,6 +96,21 @@
<version>3.1</version>
</dependency>
+<!-- ftp鏈嶅姟-->
+ <dependency>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
+ <version>3.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ </dependency>
+ <!-- <dependency>-->
+<!-- <groupId>org.springframework</groupId>-->
+<!-- <artifactId>spring-test</artifactId>-->
+<!-- </dependency>-->
+
</dependencies>
</project>
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 b1138ac..99cdb16 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
@@ -2,6 +2,7 @@
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
+import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@@ -9,23 +10,38 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
+import org.dromara.common.core.utils.DateUtils;
+import org.dromara.common.core.utils.MapstructUtils;
+import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
+import org.dromara.common.oss.core.OssClient;
import org.dromara.common.oss.entity.SynchronousRequest;
+import org.dromara.common.oss.entity.SynchronousRequest2;
+import org.dromara.common.oss.entity.UploadResult;
import org.dromara.common.oss.entity.VideoRequest;
-import org.dromara.common.redis.utils.QueueUtils;
+import org.dromara.common.oss.factory.OssFactory;
+import org.dromara.system.domain.SysOss;
import org.dromara.system.domain.properties.Boundary;
+import org.dromara.system.domain.properties.FtpConfig;
import org.dromara.system.domain.vo.SysOssUploadVo;
import org.dromara.system.domain.vo.SysOssVo;
+import org.dromara.system.mapper.SysOssMapper;
import org.dromara.system.service.ISysOssService;
+import org.dromara.system.uitil.FtpApche;
import org.dromara.system.uitil.HttpUtils;
+import org.dromara.system.uitil.PasswordUtil;
+import org.jetbrains.annotations.NotNull;
import org.springframework.http.MediaType;
+
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
+import java.io.InputStream;
import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -38,25 +54,23 @@
@RequestMapping("/resource/synchronization")
public class SynchronizationController {
-
+ private final FtpConfig ftpConfig;
private final ISysOssService ossService;
+ private final SysOssMapper baseMapper;
+
/**
* 涓婁紶鍚屾 瑙嗛涓撶綉
+ *
* @param
* @return
*/
@PostMapping(value = "/upload")
- public R synchronization(SynchronousRequest request) throws ParseException {
+ public R synchronization(SynchronousRequest request) throws IOException, ParseException {
if (ObjectUtil.isNull(request.getFile())) {
return R.fail("涓婁紶鏂囦欢涓嶈兘涓虹┖");
}
- log.info("ossId:{},path:{}",request.getOssId(),request.getPath());
- SysOssVo oss = ossService.upload2(request);
-
- //娣诲姞闃熷垪鏁版嵁
- QueueUtils.addDelayedQueueObject("OSS", oss.getOssId().toString(), 1, TimeUnit.HOURS);
- log.info("閫氶亾: {} , 鍙戦�佹暟鎹�: {}", "OSS", oss.getOssId());
+ ossService.upload2(request);
return R.ok();
}
@@ -66,9 +80,8 @@
return R.fail("涓婁紶鏂囦欢涓嶈兘涓虹┖");
}
SysOssVo oss = ossService.upload3(request1);
-
//娣诲姞闃熷垪鏁版嵁
- QueueUtils.addDelayedQueueObject("OSS", oss.getOssId().toString(), 1, TimeUnit.DAYS);
+// QueueUtils.addDelayedQueueObject("OSS", oss.getOssId().toString(), 1, TimeUnit.DAYS);
log.info("閫氶亾: {} , 鍙戦�佹暟鎹�: {}", "OSS", oss.getOssId());
SysOssUploadVo uploadVo = new SysOssUploadVo();
uploadVo.setUrl(oss.getUrl());
@@ -85,8 +98,74 @@
*/
@PostMapping(value = "/delete")
public R<Void> remove(String ossId) throws Exception {
- return ossService.deleteWithValidByIds(List.of(convert(ossId)), true,"000000") ? R.ok() : R.fail("鎻愬彇鐮侀敊璇紒");
+ return ossService.deleteWithValidByIds(List.of(convert(ossId)), true, "000000") ? R.ok() : R.fail("鎻愬彇鐮侀敊璇紒");
}
+
+ /**
+ * 涓婁紶鍚屾 鍏畨鍐呯綉
+ *
+ * @param request
+ */
+ @PostMapping(value = "/uploadByFileName")
+ public R<Void> uploadByFileName(VideoRequest request) throws Exception {
+ if (ObjectUtil.isNull(request.getFile())) {
+ return R.fail("涓婁紶鏂囦欢涓嶈兘涓虹┖");
+ }
+ SysOssVo oss = ossService.upload3(request);
+
+ InputStream input = request.getFile().getInputStream();
+ String fileName = request.getFileName();
+ OssClient storage = OssFactory.instance();
+ UploadResult uploadResult = storage.upload(input,getPath(fileName),
+ fileName.substring(14,fileName.length()));
+ buildResultEntity1(fileName, fileName.substring(14,fileName.length()), "minio", uploadResult);
+ return R.ok();
+ }
+
+ public String getPath(String suffix) {
+ return DateUtils.datePath() + "/" + suffix;
+ }
+
+ @NotNull
+ private void buildResultEntity1(String originalfileName, String suffix, String configKey, UploadResult uploadResult) {
+ SysOss oss = new SysOss();
+ oss.setUrl(uploadResult.getUrl());
+ oss.setFileSuffix(suffix);
+ oss.setFileName(uploadResult.getFilename());
+ oss.setOriginalName(originalfileName);
+ oss.setService(configKey);
+ oss.setPassword(PasswordUtil.randomPassword(6));
+ baseMapper.insert(oss);
+ }
+
+ @NotNull
+ private void buildResultEntity(String originalfileName, String suffix, String configKey, UploadResult uploadResult
+ ,MultipartFile file) {
+ SysOss oss = new SysOss();
+ oss.setUrl(uploadResult.getUrl());
+ oss.setFileSuffix(suffix);
+ oss.setFileName(uploadResult.getFilename());
+ oss.setOriginalName(originalfileName);
+ oss.setService(configKey);
+ oss.setPassword(PasswordUtil.randomPassword(6));
+ baseMapper.insert(oss);
+
+ //鎷兼帴鍚屾淇℃伅
+
+
+// SynchronousRequest request = new SynchronousRequest();
+// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+// request.setFile(file);
+// request.setFileName(oss.getOriginalName()+"1");
+// request.setPath(uploadResult.getFilename());
+// request.setCreateTime(format.format(oss.getCreateTime()));
+// request.setPassword(oss.getPassword());
+// request.setCreateBy("1731588854831022081");
+// request.setOssId(String.valueOf(oss.getOssId()));
+// request.setOssId("123890");
+// post(request);
+ }
+
public static Long[] convert(String input) {
String[] stringArray = input.split(",");
@@ -99,4 +178,16 @@
return longArray;
}
+ @NotNull
+ private void buildResultEntity2(String originalfileName, String suffix, String configKey, UploadResult uploadResult
+ , String password) throws IOException {
+ SysOss oss = new SysOss();
+ oss.setUrl(uploadResult.getUrl());
+ oss.setFileSuffix(suffix);
+ oss.setFileName(uploadResult.getFilename());
+ oss.setOriginalName(originalfileName);
+ oss.setService(configKey);
+ oss.setPassword(password);
+ baseMapper.insert(oss);
+ }
}
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysOssController.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysOssController.java
index 276429f..ceed063 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysOssController.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysOssController.java
@@ -5,16 +5,19 @@
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONArray;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.core.domain.R;
+import org.dromara.common.core.utils.StringUtils;
+import org.dromara.common.core.utils.file.FileUtils;
import org.dromara.common.core.validate.QueryGroup;
import org.dromara.common.oss.entity.SynchronousRequest;
import org.dromara.common.oss.entity.VideoRequest;
import org.dromara.common.redis.utils.CacheUtils;
-import org.dromara.common.redis.utils.QueueUtils;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
@@ -23,6 +26,7 @@
import org.dromara.system.domain.SysOss;
import org.dromara.system.domain.bo.SysOssBo;
import org.dromara.system.domain.properties.Boundary;
+import org.dromara.system.domain.properties.FtpConfig;
import org.dromara.system.domain.vo.SysOssUploadVo;
import org.dromara.system.domain.vo.SysOssVo;
import org.dromara.system.mapper.SysOssMapper;
@@ -30,7 +34,10 @@
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor;
+import org.dromara.system.uitil.FTPUtil;
+import org.dromara.system.uitil.FtpApche;
import org.dromara.system.uitil.HttpUtils;
+import org.dromara.system.uitil.PasswordUtil;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -55,9 +62,11 @@
@RequestMapping("/resource/oss")
public class SysOssController extends BaseController {
+ private final FtpConfig ftpConfig;
private final Boundary boundary;
private final ISysOssService ossService;
private final SysOssMapper ossMapper;
+
/**
* 鏌ヨOSS瀵硅薄瀛樺偍鍒楄〃
*/
@@ -89,23 +98,18 @@
@Log(title = "OSS瀵硅薄瀛樺偍", businessType = BusinessType.INSERT)
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<SysOssUploadVo> upload(@RequestPart("file") MultipartFile file) throws IOException {
+
if (ObjectUtil.isNull(file)) {
return R.fail("涓婁紶鏂囦欢涓嶈兘涓虹┖");
}
SysOssVo oss = ossService.upload(file);
- SynchronousRequest request = new SynchronousRequest();
- request.setFile(file);
-
-
- //娣诲姞闃熷垪鏁版嵁
- QueueUtils.addDelayedQueueObject("OSS", oss.getOssId().toString(), 1, TimeUnit.DAYS);
- log.info("閫氶亾: {} , 鍙戦�佹暟鎹�: {}", "OSS", oss.getOssId());
SysOssUploadVo uploadVo = new SysOssUploadVo();
uploadVo.setUrl(oss.getUrl());
uploadVo.setFileName(oss.getOriginalName());
uploadVo.setOssId(oss.getOssId().toString());
uploadVo.setPassword(oss.getPassword());
+
return R.ok(uploadVo);
}
@@ -118,20 +122,17 @@
// @Log(title = "OSS瀵硅薄瀛樺偍", businessType = BusinessType.INSERT)
// @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
// public R<String> upload(@RequestPart("file") MultipartFile file) throws IOException {
-// if (ObjectUtil.isNull(file)) {
-// return R.fail("涓婁紶鏂囦欢涓嶈兘涓虹┖");
-// }
-// VideoRequest request = new VideoRequest();
-// request.setFile(file);
-// request.setFileName(file.getOriginalFilename());
-// String post = post(request);
-// String password = post.substring(post.indexOf("password\":\"") + 9, post.indexOf("\"}"));
+// String originalfileName = file.getOriginalFilename();
+// long l = System.currentTimeMillis();
+// String password = PasswordUtil.randomPassword(6);
+// String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
+// FtpApche.uploadFile(ftpConfig, file, password + String.valueOf(l) + suffix);
// return R.ok(password);
// }
private String post(VideoRequest request) throws IOException {
HashMap<String, String> headers = new HashMap<>(3);
- String requestUrl = boundary.getChief() + "/resource/synchronization/uploadTwo";
+ String requestUrl = boundary.getChief() + "/resource/synchronization/uploadTwo";
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
headers.put("content-type", "application/json");
@@ -150,11 +151,23 @@
@SaCheckPermission("system:oss:download")
@GetMapping("/download/{ossId}/{password}")
public R<String> download(@PathVariable Long ossId, @PathVariable String password, HttpServletResponse response) throws IOException {
- SysOss oss = ossMapper.selectById(ossId);
- if(!oss.getPassword().equals(password)){
- return R.fail("鎻愬彇鐮侀敊璇紒");
+ if (String.valueOf(ossId).equals("12345678")) {
+ SysOssVo sysOssVo = ossMapper.selectVoOne(new LambdaQueryWrapper<SysOss>()
+ .eq(SysOss::getPassword, password));
+ if (sysOssVo == null) {
+ return R.fail("鎻愬彇鐮侀敊璇紒");
+ }
+ ossService.download(sysOssVo.getOssId(), response);
+ } else {
+ SysOss oss = ossMapper.selectById(ossId);
+
+ if (!oss.getPassword().equals(password)) {
+ return R.fail("鎻愬彇鐮侀敊璇紒");
+ }
+ ossService.download(ossId, response);
}
- ossService.download(ossId, response);
+
+
return R.ok();
}
@@ -169,7 +182,7 @@
public R<Void> remove(@NotEmpty(message = "涓婚敭涓嶈兘涓虹┖")
@PathVariable Long[] ossIds,
@PathVariable String password) throws Exception {
- return ossService.deleteWithValidByIds(List.of(ossIds), true,password) ? R.ok() : R.fail("鎻愬彇鐮侀敊璇紒");
+ return ossService.deleteWithValidByIds(List.of(ossIds), true, password) ? R.ok() : R.fail("鎻愬彇鐮侀敊璇紒");
}
/**
@@ -183,22 +196,22 @@
return ossService.viewPasswordById(ossId);
}
- /**
- * 璁㈤槄闃熷垪(鐩戝惉)
- *
- * @param queueName 闃熷垪鍚�
- */
- @GetMapping("/subscribe")
- public R<Void> subscribe(String queueName) {
- log.info("閫氶亾: {} 鐩戝惉涓�......", queueName);
- // 椤圭洰鍒濆鍖栬缃竴娆″嵆鍙�
- QueueUtils.subscribeBlockingQueue(queueName, (String ossId) -> {
- // 瑙傚療鎺ユ敹鏃堕棿
- log.info("閫氶亾: {}, 鏀跺埌鏁版嵁: {}", queueName, ossId);
-// ossMapper.deleteById(Long.valueOf(ossId));
- });
- return R.ok("鎿嶄綔鎴愬姛");
- }
+// /**
+// * 璁㈤槄闃熷垪(鐩戝惉)
+// *
+// * @param queueName 闃熷垪鍚�
+// */
+// @GetMapping("/subscribe")
+// public R<Void> subscribe(String queueName) {
+// log.info("閫氶亾: {} 鐩戝惉涓�......", queueName);
+// // 椤圭洰鍒濆鍖栬缃竴娆″嵆鍙�
+// QueueUtils.subscribeBlockingQueue(queueName, (String ossId) -> {
+// // 瑙傚療鎺ユ敹鏃堕棿
+// log.info("閫氶亾: {}, 鏀跺埌鏁版嵁: {}", queueName, ossId);
+//// ossMapper.deleteById(Long.valueOf(ossId));
+// });
+// return R.ok("鎿嶄綔鎴愬姛");
+// }
}
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/properties/FtpConfig.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/properties/FtpConfig.java
new file mode 100644
index 0000000..5b45451
--- /dev/null
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/properties/FtpConfig.java
@@ -0,0 +1,24 @@
+package org.dromara.system.domain.properties;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * ftp瀹炰綋绫�
+ */
+@Data
+@Component
+@ConfigurationProperties(prefix = "ftp")
+public class FtpConfig {
+
+ private String url;
+
+ private String port;
+
+ private String username;
+
+ private String passwd;
+
+ private String path;
+}
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/runner/SystemApplicationRunner.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/runner/SystemApplicationRunner.java
index d5ee534..0aaa2b2 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/runner/SystemApplicationRunner.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/runner/SystemApplicationRunner.java
@@ -1,14 +1,15 @@
package org.dromara.system.runner;
+import cn.hutool.extra.ftp.Ftp;
import com.amazonaws.services.s3.AmazonS3;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.oss.core.OssClient;
import org.dromara.common.oss.factory.OssFactory;
import org.dromara.common.oss.properties.OssProperties;
-import org.dromara.common.redis.utils.QueueUtils;
import org.dromara.system.convert.SysOssConfigClassConvert;
import org.dromara.system.domain.SysOssConfig;
import org.dromara.system.domain.properties.Boundary;
+import org.dromara.system.domain.properties.FtpConfig;
import org.dromara.system.domain.vo.SysOssVo;
import org.dromara.system.mapper.SysOssConfigMapper;
import org.dromara.system.mapper.SysOssMapper;
@@ -16,6 +17,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.system.service.ISysOssService;
+import org.dromara.system.uitil.FtpApche;
import org.dromara.system.uitil.HttpUtils;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
@@ -35,35 +37,44 @@
@Component
public class SystemApplicationRunner implements ApplicationRunner {
- private final Boundary boundary;
+// private final FtpConfig ftpConfig;
+// private final Boundary boundary;
private final ISysOssConfigService ossConfigService;
- private final SysOssMapper ossMapper;
- private final SysOssConfigMapper sysOssConfigMapper;
+// private final SysOssMapper ossMapper;
+// private final SysOssConfigMapper sysOssConfigMapper;
// private final AmazonS3 client;
@Override
public void run(ApplicationArguments args) throws Exception {
+// FtpApche.connect(ftpConfig);
+// log.info("杩炴帴ftp鏈嶅姟鎴愬姛");
ossConfigService.init();
//鍒濆鍖杘ssclient
- List<SysOssConfig> collect = sysOssConfigMapper.selectList().stream().filter(e -> e.getStatus().equals("0"))
- .collect(Collectors.toList());
- OssProperties properties = SysOssConfigClassConvert.INSTANCE.sysOssConfigToossProperties(collect.get(0));
- OssClient client = new OssClient("minio",properties);
- log.info("鍒濆鍖朞SS閰嶇疆鎴愬姛");
- log.info("閫氶亾: {} 鐩戝惉涓�......", "OSS");
+// List<SysOssConfig> collect = sysOssConfigMapper.selectList().stream().filter(e -> e.getStatus().equals("0"))
+// .collect(Collectors.toList());
+// OssProperties properties = SysOssConfigClassConvert.INSTANCE.sysOssConfigToossProperties(collect.get(0));
+// OssClient client = new OssClient("minio",properties);
+// log.info("鍒濆鍖朞SS閰嶇疆鎴愬姛");
+// log.info("閫氶亾: {} 鐩戝惉涓�......", "OSS");
// 椤圭洰鍒濆鍖栬缃竴娆″嵆鍙�
- QueueUtils.subscribeBlockingQueue("OSS", (String ossId) -> {
- // 瑙傚療鎺ユ敹鏃堕棿
- log.info("閫氶亾: {}, 鏀跺埌鏁版嵁: {}", "OSS", ossId);
- SysOssVo vo = ossMapper.selectVoById(ossId);
- client.delete( vo.getUrl());
- ossMapper.deleteById(Long.valueOf(ossId));
- try {
- HttpUtils.sendDeleteRequest(boundary.getVideo() + "/resource/synchronization/delete",ossId);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- });
+// QueueUtils.subscribeBlockingQueue("OSS", (String name) -> {
+// // 瑙傚療鎺ユ敹鏃堕棿
+// log.info("閫氶亾: {}, 鏀跺埌鏁版嵁: {}", "OSS", name);
+//// try {
+//// HttpUtils.sendDeleteRequest2(boundary.getLocalhost() + "/resource/synchronization/uploadByFileName",name);
+//// } catch (IOException e) {
+//// throw new RuntimeException(e);
+//// }
+//
+//// SysOssVo vo = ossMapper.selectVoById(ossId);
+//// client.delete( vo.getUrl());
+//// ossMapper.deleteById(Long.valueOf(ossId));
+//// try {
+//// HttpUtils.sendDeleteRequest(boundary.getVideo() + "/resource/synchronization/delete",ossId);
+//// } catch (IOException e) {
+//// throw new RuntimeException(e);
+//// }
+// });
}
}
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysOssService.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysOssService.java
index 6f338a2..ad0b1d8 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysOssService.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysOssService.java
@@ -35,6 +35,8 @@
SysOssVo upload2(SynchronousRequest request) throws ParseException;
+ SysOssVo upload3(SynchronousRequest request) throws ParseException;
+
// SysOssVo upload(File file);
void download(Long ossId, HttpServletResponse response) throws IOException;
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 22d6d70..345b542 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
@@ -10,6 +10,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.github.therapi.runtimejavadoc.repack.com.eclipsesource.json.Json;
+import org.apache.commons.io.IOUtils;
+import org.apache.xmlbeans.impl.common.IOUtil;
import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.domain.model.LoginUser;
@@ -45,9 +47,7 @@
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -177,13 +177,39 @@
}
/**
- * 鍚屾
+ * 鍚屾 瀹氭椂鎷夊彇
* @param
* @param
* @return
*/
@Override
public SysOssVo upload2(SynchronousRequest request) throws ParseException {
+ String originalfileName = request.getFileName();
+ String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
+ OssClient storage = OssFactory.instance();
+// String type = request.getFileName().substring(14,request.getFileName().length());
+ String type = request.getFile().getContentType();
+ UploadResult uploadResult;
+ try {
+ uploadResult = storage.uploadSuffix2(request.getFile().getBytes(), request.getPath(), type);
+ } catch (IOException e) {
+ throw new ServiceException(e.getMessage());
+ }
+ // 淇濆瓨鏂囦欢淇℃伅
+ System.out.println("canshu:" + "," + originalfileName +"," + suffix +"," + storage.getConfigKey() +"," + uploadResult + "," +request.getOssId()
+ +"," + request.getPassword() +"," + request.getCreateBy() +"," + request.getFileName() +"," + request.getCreateTime());
+ return buildResultEntity2(originalfileName, suffix, storage.getConfigKey(), uploadResult,request.getOssId(),
+ request.getPassword(), "1731588854831022081", request.getFileName(), request.getCreateTime());
+ }
+
+ /**
+ * 鍚屾 瀹氭椂鎷夊彇
+ * @param
+ * @param
+ * @return
+ */
+ @Override
+ public SysOssVo upload3(SynchronousRequest request) throws ParseException {
String originalfileName = request.getFileName();
String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
OssClient storage = OssFactory.instance();
@@ -195,7 +221,7 @@
}
// 淇濆瓨鏂囦欢淇℃伅
System.out.println("canshu:" + "," + originalfileName +"," + suffix +"," + storage.getConfigKey() +"," + uploadResult + "," +request.getOssId()
- +"," + request.getPassword() +"," + request.getCreateBy() +"," + request.getFileName() +"," + request.getCreateTime());
+ +"," + request.getPassword() +"," + request.getCreateBy() +"," + request.getFileName() +"," + request.getCreateTime());
return buildResultEntity2(originalfileName, suffix, storage.getConfigKey(), uploadResult,request.getOssId(),
request.getPassword(), "1731588854831022081", request.getFileName(), request.getCreateTime());
}
@@ -230,8 +256,8 @@
request.setPassword(oss.getPassword());
request.setCreateBy("1731588854831022081");
request.setOssId(String.valueOf(oss.getOssId()));
-// request.setOssId();
-// post(request);
+// request.setOssId("123890");
+ post(request);
SysOssVo sysOssVo = MapstructUtils.convert(oss, SysOssVo.class);
return this.matchingUrl(sysOssVo);
@@ -281,13 +307,15 @@
storage.delete(sysOss.getUrl());
if(sysOss.getPassword().equals(password) || password.equals("000000")){
baseMapper.deleteById(sysOss.getOssId());
- HttpUtils.sendDeleteRequest(boundary.getVideo() + "/resource/synchronization/delete",String.valueOf(sysOss.getOssId()));
+// HttpUtils.sendDeleteRequest(boundary.getVideo() + "/resource/synchronization/delete",String.valueOf(sysOss.getOssId()));
return true;
}
return false;
}
return true;
}
+
+
@Override
public R viewPasswordById(Long ossId) {
@@ -322,14 +350,6 @@
String requestUrl = boundary.getVideo() + "/resource/synchronization/upload";
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
- String jsonString = "";
- try {
- // 灏咼ava瀵硅薄杞崲涓篔SON瀛楃涓�
- jsonString = objectMapper.writeValueAsString(request);
-// System.out.println(jsonString);
- } catch (Exception e) {
-// e.printStackTrace();
- }
headers.put("content-type", "application/json");
// 鍙戦�乸ost璇锋眰
String resultData = HttpUtils.sendPostRequest(requestUrl, request);
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
new file mode 100644
index 0000000..192eda8
--- /dev/null
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/VideoPulSync.java
@@ -0,0 +1,117 @@
+package org.dromara.system.sync;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import org.dromara.common.core.utils.DateUtils;
+import org.dromara.common.oss.core.OssClient;
+import org.dromara.common.oss.entity.SynchronousRequest;
+import org.dromara.common.oss.entity.SynchronousRequest2;
+import org.dromara.common.oss.entity.UploadResult;
+import org.dromara.common.oss.entity.VideoRequest;
+import org.dromara.common.oss.factory.OssFactory;
+import org.dromara.system.domain.SysOss;
+import org.dromara.system.domain.properties.Boundary;
+import org.dromara.system.domain.properties.FtpConfig;
+import org.dromara.system.mapper.SysOssMapper;
+import org.dromara.system.uitil.FtpApche;
+import org.dromara.system.uitil.HttpUtils;
+import org.dromara.system.uitil.PasswordUtil;
+import org.jetbrains.annotations.NotNull;
+import org.springframework.http.MediaType;
+import org.springframework.mock.web.MockMultipartFile;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+@Component
+public class VideoPulSync {
+
+ private final Boundary boundary;
+ private final FtpConfig ftpConfig;
+ private final SysOssMapper baseMapper;
+
+ public VideoPulSync(Boundary boundary, FtpConfig ftpConfig, SysOssMapper baseMapper) {
+ this.boundary = boundary;
+ this.ftpConfig = ftpConfig;
+ this.baseMapper = baseMapper;
+ }
+
+// @Scheduled(cron = "0 0/1 * * * ?")
+ public void get() throws IOException {
+ System.out.println("鍚屾涓婁紶......");
+
+ List<String> list = FtpApche.downloadList(ftpConfig);
+ if(list.size() == 0){
+ return;
+ }
+ for (String str : list) {
+ //瀵嗙爜
+ String password = str.substring(0,6);
+ //鏂囦欢鍚嶇О
+ String fileName = str.substring(6,str.length());
+ InputStream input = FtpApche.downloadFileFromDailyDir(str);
+ byte[] fileBytesByName = FtpApche.getFileBytesByName(input);
+ OssClient storage = OssFactory.instance();
+ UploadResult uploadResult = storage.upload(input,getPath(fileName),fileName.substring(14,fileName.length()));
+ FtpApche.deleteFile(str);
+ MultipartFile file = new MockMultipartFile(fileName,fileName, fileName.substring(14,fileName.length()), input);
+ buildResultEntity(fileName, fileName.substring(14,fileName.length()), "minio", uploadResult, file,
+ password, fileBytesByName);
+
+ }
+
+ }
+
+ @NotNull
+ private void buildResultEntity(String originalfileName, String suffix, String configKey, UploadResult uploadResult
+ , MultipartFile file, String password, byte[] fileBytesByName) throws IOException {
+ SysOss oss = new SysOss();
+ oss.setUrl(uploadResult.getUrl());
+ oss.setFileSuffix(suffix);
+ oss.setFileName(uploadResult.getFilename());
+ oss.setOriginalName(originalfileName);
+ oss.setService(configKey);
+ oss.setPassword(password);
+ baseMapper.insert(oss);
+ //鎷兼帴鍚屾淇℃伅
+
+
+ SynchronousRequest request = new SynchronousRequest();
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ request.setFile(file);
+ request.setFileName(oss.getOriginalName());
+ request.setPath(uploadResult.getFilename());
+ request.setCreateTime(format.format(oss.getCreateTime()));
+ request.setPassword(oss.getPassword());
+ request.setCreateBy("1731588854831022081");
+ request.setOssId(String.valueOf(oss.getOssId()));
+// request.setOssId("999999900");
+ post(request, fileBytesByName);
+ }
+
+ private String post(SynchronousRequest request, byte[] bytes) throws IOException {
+ HashMap<String, String> headers = new HashMap<>(3);
+ String requestUrl = boundary.getVideo() + "/resource/synchronization/upload";
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
+ headers.put("content-type", "application/json");
+ // 鍙戦�乸ost璇锋眰
+ String resultData = HttpUtils.sendPostRequest2(requestUrl, request, bytes);
+ // 骞舵帴鏀惰繑鍥炵粨鏋�
+ System.out.println(resultData);
+ return resultData;
+ }
+
+ public String getPath(String suffix) {
+ return DateUtils.datePath() + "/" + suffix;
+ }
+
+
+}
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
new file mode 100644
index 0000000..a7a9066
--- /dev/null
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/sync/deleteSync.java
@@ -0,0 +1,43 @@
+package org.dromara.system.sync;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import org.dromara.system.domain.SysOss;
+import org.dromara.system.domain.properties.Boundary;
+import org.dromara.system.domain.vo.SysOssVo;
+import org.dromara.system.mapper.SysOssMapper;
+import org.dromara.system.uitil.HttpUtils;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.time.LocalDateTime;
+import java.util.List;
+
+@Component
+public class deleteSync {
+
+ private final SysOssMapper baseMapper;
+ private final Boundary boundary;
+
+ public deleteSync(SysOssMapper baseMapper, Boundary boundary) {
+ this.baseMapper = baseMapper;
+ this.boundary = boundary;
+ }
+
+
+// @Scheduled(cron = "0 */10 * * * ?")
+ public void remove() throws IOException {
+ System.out.println("鍚屾鍒犻櫎......");
+ List<SysOssVo> list = baseMapper.selectVoList(new LambdaQueryWrapper<SysOss>()
+ .le(SysOss::getCreateTime, LocalDateTime.now().minusDays(1)));
+
+ if (list.size() == 0) {
+ return;
+ }
+ for (SysOssVo vo : list) {
+ baseMapper.deleteById(vo.getOssId());
+ HttpUtils.sendDeleteRequest(boundary.getVideo() + "/resource/synchronization/delete",
+ String.valueOf(vo.getOssId()));
+ }
+ }
+}
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/FTPUtil.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/FTPUtil.java
new file mode 100644
index 0000000..fafadf3
--- /dev/null
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/FTPUtil.java
@@ -0,0 +1,547 @@
+package org.dromara.system.uitil;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPFile;
+import org.apache.commons.net.ftp.FTPReply;
+import org.dromara.system.domain.properties.FtpConfig;
+
+import java.io.*;
+import java.net.UnknownHostException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * FTP宸ュ叿绫�
+ *
+ * @author: simon
+ * @date: 2019/7/3 14:37
+ */
+public class FTPUtil {
+ /**
+ * 瀛楃闆�
+ */
+ private static final String DEFAULT_CHARSET = "UTF-8";
+
+ /**
+ * 瓒呮椂鏃堕棿
+ */
+ private static final int DEFAULT_TIMEOUT = 60 * 1000;
+
+ /**
+ * 涓绘満鍚嶆垨鑰卛p鍦板潃
+ */
+ private final String host;
+
+ /**
+ * ftp鏈嶅姟鍣ㄧ鍙�
+ */
+ private final int port;
+
+ /**
+ * ftp鐢ㄦ埛鍚�
+ */
+ private final String username;
+
+ /**
+ * ftp瀵嗙爜
+ */
+ private final String password;
+
+ /**
+ * ftpClient瀵硅薄
+ */
+ private FTPClient ftpClient;
+
+ /**
+ * 鍒濆鍖栨椂ftp鏈嶅姟鍣ㄨ矾寰�
+ */
+ private volatile String ftpBasePath = "";
+
+ /**
+ * 鏋勯�犲嚱鏁�
+ *
+ * @param host 涓绘満鍚嶆垨鑰卛p鍦板潃
+ * @param username ftp 鐢ㄦ埛鍚�
+ * @param password ftp 瀵嗙爜
+ * @param ftpBasePath 鍒濆鍖栨椂ftp鏈嶅姟鍣ㄨ矾寰�
+ */
+ private FTPUtil(String host, String username, String password,String ftpBasePath) {
+ this(host, 21, username, password, DEFAULT_CHARSET,ftpBasePath);
+ setTimeout(DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT);
+ }
+
+ /**
+ * 鏋勯�犲嚱鏁�
+ *
+// * @param host 涓绘満鍚嶆垨鑰卛p鍦板潃
+// * @param username ftp 鐢ㄦ埛鍚�
+// * @param password ftp 瀵嗙爜
+// * @param ftpBasePath 鍒濆鍖栨椂ftp鏈嶅姟鍣ㄨ矾寰�
+ */
+ public FTPUtil(FtpConfig ftpConfig) {
+ this(ftpConfig.getUrl(), 21, ftpConfig.getUsername(), ftpConfig.getPasswd(), DEFAULT_CHARSET,ftpConfig.getPath());
+ setTimeout(DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT);
+ }
+
+ /**
+ * 鏋勯�犲嚱鏁�
+ *
+ * @param host 涓绘満鍚嶆垨鑰卛p鍦板潃
+ * @param port ftp 绔彛
+ * @param username 鐢ㄦ埛鍚�
+ * @param password 瀵嗙爜
+ * @param ftpBasePath 鍒濆鍖栨椂ftp鏈嶅姟鍣ㄨ矾寰�
+ */
+ private FTPUtil(String host, int port, String username, String password, String charset, String ftpBasePath) {
+ ftpClient = new FTPClient();
+ ftpClient.setControlEncoding(charset);
+ this.host = StringUtils.isEmpty(host) ? "localhost" : host;
+ this.port = (port <= 0) ? 21 : port;
+ this.username = StringUtils.isEmpty(username) ? "anonymous" : username;
+ this.password = password;
+ this.ftpBasePath = ftpBasePath;
+ }
+
+ /**
+ * 鍒涘缓榛樿鐨刦tp瀹㈡埛绔�
+ *
+ * @param host 涓绘満鍚嶆垨鑰卛p鍦板潃
+ * @param username ftp鐢ㄦ埛鍚�
+ * @param password ftp瀵嗙爜
+ * @param ftpBasePath 鍒濆鍖栨椂ftp鏈嶅姟鍣ㄨ矾寰�
+ * @return com.siniswift.efb.acars.utils.FTPUtil
+ */
+ public static FTPUtil createFtpCli(String host, String username, String password,String ftpBasePath) {
+ return new FTPUtil(host, username, password,ftpBasePath);
+ }
+
+ /**
+ * 鍒涘缓鑷畾涔夊睘鎬х殑ftp瀹㈡埛绔�
+ *
+ * @param host 涓绘満鍚嶆垨鑰卛p鍦板潃
+ * @param port ftp绔彛
+ * @param username ftp鐢ㄦ埛鍚�
+ * @param password ftp瀵嗙爜
+ * @param charset 瀛楃闆�
+ * @param ftpBasePath 鍒濆鍖栨椂ftp鏈嶅姟鍣ㄨ矾寰�
+ * @return com.siniswift.efb.acars.utils.FTPUtil
+ */
+ public static FTPUtil createFtpCli(String host, int port, String username, String password, String charset,String ftpBasePath) {
+ return new FTPUtil(host, port, username, password, charset,ftpBasePath);
+ }
+
+ /**
+ * 璁剧疆瓒呮椂鏃堕棿
+ *
+ * @param defaultTimeout 瓒呮椂鏃堕棿
+ * @param connectTimeout 瓒呮椂鏃堕棿
+ * @param dataTimeout 瓒呮椂鏃堕棿
+ */
+ private void setTimeout(int defaultTimeout, int connectTimeout, int dataTimeout) {
+ ftpClient.setDefaultTimeout(defaultTimeout);
+ ftpClient.setConnectTimeout(connectTimeout);
+ ftpClient.setDataTimeout(dataTimeout);
+ }
+
+ /**
+ * 杩炴帴鍒癴tp
+ */
+ public void connect() throws IOException {
+ try {
+ ftpClient.connect(host, port);
+ } catch (UnknownHostException e) {
+ throw new IOException("Can't find FTP server :" + host);
+ }
+
+ int reply = ftpClient.getReplyCode();
+ if (!FTPReply.isPositiveCompletion(reply)) {
+ disconnect();
+ throw new IOException("Can't connect to server :" + host);
+ }
+
+ if (!ftpClient.login(username, password)) {
+ disconnect();
+ throw new IOException("Can't login to server :" + host);
+ }
+
+ // set data transfer mode.
+ ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
+
+ // Use passive mode to pass firewalls.
+ ftpClient.enterLocalPassiveMode();
+
+ initFtpBasePath();
+ }
+
+ /**
+ * 杩炴帴ftp鏃朵繚瀛樺垰鐧婚檰ftp鏃剁殑璺緞
+ */
+ private void initFtpBasePath() throws IOException {
+ if (StringUtils.isEmpty(ftpBasePath)) {
+ synchronized (this) {
+ if (StringUtils.isEmpty(ftpBasePath)) {
+ ftpBasePath = ftpClient.printWorkingDirectory();
+ }
+ }
+ }
+ }
+
+ /**
+ * ftp鏄惁澶勪簬杩炴帴鐘舵�侊紝鏄繛鎺ョ姸鎬佽繑鍥�<tt>true</tt>
+ *
+ * @return boolean 鏄繛鎺ョ姸鎬佽繑鍥�<tt>true</tt>
+ */
+ public boolean isConnected() {
+ return ftpClient.isConnected();
+ }
+
+ /**
+ * 涓婁紶鏂囦欢鍒板搴旂洰褰曚笅
+ *
+ * @param fileName 鏂囦欢鍚�
+ * @param inputStream 鏂囦欢杈撳叆娴�
+ * @param uploadDir 涓婁紶鏂囦欢鐨勭埗璺緞
+ * @return java.lang.String
+ */
+ public String uploadFile(String fileName, InputStream inputStream, String uploadDir) throws IOException {
+ changeWorkingDirectory(ftpBasePath);
+ SimpleDateFormat dateFormat = new SimpleDateFormat("/yyyy/MM/dd");
+ makeDirs(uploadDir);
+ storeFile(fileName, inputStream);
+ return uploadDir + "/" + fileName;
+ }
+
+ /**
+ * 鏍规嵁uploadFile杩斿洖鐨勮矾寰勶紝浠巉tp涓嬭浇鏂囦欢鍒版寚瀹氳緭鍑烘祦涓�
+ *
+ * @param ftpRealFilePath 鏂规硶uploadFile杩斿洖鐨勮矾寰�
+ * @param outputStream 杈撳嚭娴�
+ */
+ public void downloadFileFromDailyDir(String ftpRealFilePath, OutputStream outputStream) throws IOException {
+ changeWorkingDirectory(ftpBasePath);
+ ftpClient.retrieveFile(ftpRealFilePath, outputStream);
+ }
+
+ /**
+ * 鑾峰彇ftp涓婃寚瀹氭枃浠跺悕鍒拌緭鍑烘祦涓�
+ *
+ * @param ftpFileName 鏂囦欢鍦╢tp涓婄殑璺緞 濡傜粷瀵硅矾寰� /home/ftpuser/123.txt 鎴栬�呯浉瀵硅矾寰� 123.txt
+ * @param out 杈撳嚭娴�
+ */
+ public void retrieveFile(String ftpFileName, OutputStream out) throws IOException {
+ try {
+ FTPFile[] fileInfoArray = ftpClient.listFiles(ftpFileName);
+ if (fileInfoArray == null || fileInfoArray.length == 0) {
+ throw new FileNotFoundException("File '" + ftpFileName + "' was not found on FTP server.");
+ }
+
+ FTPFile fileInfo = fileInfoArray[0];
+ if (fileInfo.getSize() > Integer.MAX_VALUE) {
+ throw new IOException("File '" + ftpFileName + "' is too large.");
+ }
+
+ if (!ftpClient.retrieveFile(ftpFileName, out)) {
+ throw new IOException("Error loading file '" + ftpFileName + "' from FTP server. Check FTP permissions and path.");
+ }
+ out.flush();
+ } finally {
+ closeStream(out);
+ }
+ }
+
+
+ /**
+ * 灏嗚緭鍏ユ祦瀛樺偍鍒版寚瀹氱殑ftp璺緞涓�
+ *
+ * @param ftpFileName 鏂囦欢鍦╢tp涓婄殑璺緞 濡傜粷瀵硅矾寰� /home/ftpuser/123.txt 鎴栬�呯浉瀵硅矾寰� 123.txt
+ * @param in 杈撳叆娴�
+ */
+ private void storeFile(String ftpFileName, InputStream in) throws IOException {
+ try {
+ if (!ftpClient.storeFile(ftpFileName, in)) {
+ throw new IOException("Can't upload file '" + ftpFileName + "' to FTP server. Check FTP permissions and path.");
+ }
+ } finally {
+ closeStream(in);
+ }
+ }
+
+ /**
+ * 鏍规嵁鏂囦欢ftp璺緞鍚嶇О鍒犻櫎鏂囦欢
+ *
+ * @param ftpFileName 鏂囦欢ftp璺緞鍚嶇О
+ */
+ public void deleteFile(String ftpFileName) throws IOException {
+ if (!ftpClient.deleteFile(ftpFileName)) {
+ throw new IOException("Can't remove file '" + ftpFileName + "' from FTP server.");
+ }
+ }
+
+ /**
+ * 涓婁紶鏂囦欢鍒癴tp
+ *
+ * @param ftpFileName 涓婁紶鍒癴tp鏂囦欢璺緞鍚嶇О
+ * @param localFile 鏈湴鏂囦欢璺緞鍚嶇О
+ */
+ public void upload(String ftpFileName, File localFile) throws IOException {
+ if (!localFile.exists()) {
+ throw new IOException("Can't upload '" + localFile.getAbsolutePath() + "'. This file doesn't exist.");
+ }
+
+ InputStream in = null;
+ try {
+ in = new BufferedInputStream(new FileInputStream(localFile));
+ if (!ftpClient.storeFile(ftpFileName, in)) {
+ throw new IOException("Can't upload file '" + ftpFileName + "' to FTP server. Check FTP permissions and path.");
+ }
+ } finally {
+ closeStream(in);
+ }
+ }
+
+ /**
+ * 涓婁紶鏂囦欢澶瑰埌ftp涓�
+ *
+ * @param remotePath ftp涓婃枃浠跺す璺緞鍚嶇О
+ * @param localPath 鏈湴涓婁紶鐨勬枃浠跺す璺緞鍚嶇О
+ */
+ public void uploadDir(String remotePath, String localPath) throws IOException {
+ localPath = localPath.replace("\\\\", "/");
+ File file = new File(localPath);
+ if (file.exists()) {
+ if (!ftpClient.changeWorkingDirectory(remotePath)) {
+ ftpClient.makeDirectory(remotePath);
+ ftpClient.changeWorkingDirectory(remotePath);
+ }
+ File[] files = file.listFiles();
+ if (null != files) {
+ for (File f : files) {
+ if (f.isDirectory() && !f.getName().equals(".") && !f.getName().equals("..")) {
+ uploadDir(remotePath + "/" + f.getName(), f.getPath());
+ } else if (f.isFile()) {
+ upload(remotePath + "/" + f.getName(), f);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * 涓嬭浇ftp鏂囦欢鍒版湰鍦颁笂
+ *
+ * @param ftpFileName ftp鏂囦欢璺緞鍚嶇О
+ * @param localFile 鏈湴鏂囦欢璺緞鍚嶇О
+ */
+ public void download(String ftpFileName, File localFile) throws IOException {
+ OutputStream out = null;
+ try {
+ FTPFile[] fileInfoArray = ftpClient.listFiles(ftpFileName);
+ if (fileInfoArray == null || fileInfoArray.length == 0) {
+ throw new FileNotFoundException("File " + ftpFileName + " was not found on FTP server.");
+ }
+
+ FTPFile fileInfo = fileInfoArray[0];
+ if (fileInfo.getSize() > Integer.MAX_VALUE) {
+ throw new IOException("File " + ftpFileName + " is too large.");
+ }
+
+ out = new BufferedOutputStream(new FileOutputStream(localFile));
+ if (!ftpClient.retrieveFile(ftpFileName, out)) {
+ throw new IOException("Error loading file " + ftpFileName + " from FTP server. Check FTP permissions and path.");
+ }
+ out.flush();
+ } finally {
+ closeStream(out);
+ }
+ }
+
+
+ /**
+ * 鏀瑰彉宸ヤ綔鐩綍
+ *
+ * @param dir ftp鏈嶅姟鍣ㄤ笂鐩綍
+ * @return boolean 鏀瑰彉鎴愬姛杩斿洖true
+ */
+ public boolean changeWorkingDirectory(String dir) {
+ if (!ftpClient.isConnected()) {
+ return false;
+ }
+ try {
+ return ftpClient.changeWorkingDirectory(dir);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ /**
+ * 涓嬭浇ftp鏈嶅姟鍣ㄤ笅鏂囦欢澶瑰埌鏈湴
+ *
+ * @param remotePath ftp涓婃枃浠跺す璺緞鍚嶇О
+ * @param localPath 鏈湴涓婁紶鐨勬枃浠跺す璺緞鍚嶇О
+ */
+ public void downloadDir(String remotePath, String localPath) throws IOException {
+ localPath = localPath.replace("\\\\", "/");
+ File file = new File(localPath);
+ if (!file.exists()) {
+ file.mkdirs();
+ }
+ FTPFile[] ftpFiles = ftpClient.listFiles(remotePath);
+ for (int i = 0; ftpFiles != null && i < ftpFiles.length; i++) {
+ FTPFile ftpFile = ftpFiles[i];
+ if (ftpFile.isDirectory() && !ftpFile.getName().equals(".") && !ftpFile.getName().equals("..")) {
+ downloadDir(remotePath + "/" + ftpFile.getName(), localPath + "/" + ftpFile.getName());
+ } else {
+ download(remotePath + "/" + ftpFile.getName(), new File(localPath + "/" + ftpFile.getName()));
+ }
+ }
+ }
+
+
+ /**
+ * 鍒楀嚭ftp涓婃枃浠剁洰褰曚笅鐨勬枃浠�
+ *
+ * @param filePath ftp涓婃枃浠剁洰褰�
+ * @return java.util.List<java.lang.String>
+ */
+ public List<String> listFileNames(String filePath) throws IOException {
+ FTPFile[] ftpFiles = ftpClient.listFiles(filePath);
+ List<String> fileList = new ArrayList<>();
+ if (ftpFiles != null) {
+ for (int i = 0; i < ftpFiles.length; i++) {
+ FTPFile ftpFile = ftpFiles[i];
+ if (ftpFile.isFile()) {
+ fileList.add(ftpFile.getName());
+ }
+ }
+ }
+
+ return fileList;
+ }
+
+ /**
+ * 鍙戦�乫tp鍛戒护鍒癴tp鏈嶅姟鍣ㄤ腑
+ *
+ * @param args ftp鍛戒护
+ */
+ public void sendSiteCommand(String args) throws IOException {
+ if (!ftpClient.isConnected()) {
+ ftpClient.sendSiteCommand(args);
+ }
+ }
+
+ /**
+ * 鑾峰彇褰撳墠鎵�澶勭殑宸ヤ綔鐩綍
+ *
+ * @return java.lang.String 褰撳墠鎵�澶勭殑宸ヤ綔鐩綍
+ */
+ public String printWorkingDirectory() {
+ if (!ftpClient.isConnected()) {
+ return "";
+ }
+ try {
+ return ftpClient.printWorkingDirectory();
+ } catch (IOException e) {
+ // do nothing
+ }
+
+ return "";
+ }
+
+ /**
+ * 鍒囨崲鍒板綋鍓嶅伐浣滅洰褰曠殑鐖剁洰褰曚笅
+ *
+ * @return boolean 鍒囨崲鎴愬姛杩斿洖true
+ */
+ public boolean changeToParentDirectory() {
+
+ if (!ftpClient.isConnected()) {
+ return false;
+ }
+
+ try {
+ return ftpClient.changeToParentDirectory();
+ } catch (IOException e) {
+ // do nothing
+ }
+
+ return false;
+ }
+
+ /**
+ * 杩斿洖褰撳墠宸ヤ綔鐩綍鐨勪笂涓�绾х洰褰�
+ *
+ * @return java.lang.String 褰撳墠宸ヤ綔鐩綍鐨勭埗鐩綍
+ */
+ public String printParentDirectory() {
+ if (!ftpClient.isConnected()) {
+ return "";
+ }
+
+ String w = printWorkingDirectory();
+ changeToParentDirectory();
+ String p = printWorkingDirectory();
+ changeWorkingDirectory(w);
+
+ return p;
+ }
+
+ /**
+ * 鍒涘缓鐩綍
+ *
+ * @param pathname 璺緞鍚�
+ * @return boolean 鍒涘缓鎴愬姛杩斿洖true
+ */
+ public boolean makeDirectory(String pathname) throws IOException {
+ return ftpClient.makeDirectory(pathname);
+ }
+
+ /**
+ * 鍒涘缓澶氫釜鐩綍
+ *
+ * @param pathname 璺緞鍚�
+ */
+ public void makeDirs(String pathname) throws IOException {
+ pathname = pathname.replace("\\\\", "/");
+ String[] pathnameArray = pathname.split("/");
+ for (String each : pathnameArray) {
+ if (StringUtils.isNotEmpty(each)) {
+ ftpClient.makeDirectory(each);
+ ftpClient.changeWorkingDirectory(each);
+ }
+ }
+ }
+
+ /**
+ * 鍏抽棴娴�
+ *
+ * @param stream 娴�
+ */
+ private static void closeStream(Closeable stream) {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException ex) {
+ // do nothing
+ }
+ }
+ }
+
+ /**
+ * 鍏抽棴ftp杩炴帴
+ */
+ public void disconnect() {
+ if (null != ftpClient && ftpClient.isConnected()) {
+ try {
+ ftpClient.logout();
+ ftpClient.disconnect();
+ } catch (IOException ex) {
+ // do nothing
+ }
+ }
+ }
+}
+
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/FtpApche.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/FtpApche.java
new file mode 100644
index 0000000..a65468c
--- /dev/null
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/FtpApche.java
@@ -0,0 +1,193 @@
+package org.dromara.system.uitil;
+
+import cn.hutool.extra.ftp.Ftp;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPFile;
+import org.apache.commons.net.ftp.FTPReply;
+import org.dromara.system.domain.properties.FtpConfig;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.*;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 瀹炵幇FTP鏂囦欢涓婁紶鍜屾枃浠朵笅杞�
+ */
+public class FtpApche {
+ private static FTPClient ftpClient = new FTPClient();
+ private static String encoding = System.getProperty("file.encoding");
+ /**
+ * 瓒呮椂鏃堕棿
+ */
+ private static final int DEFAULT_TIMEOUT = 60 * 1000;
+
+ /**
+ * 杩炴帴鍒癴tp
+ */
+ public static void connect(FtpConfig config) throws IOException {
+ setTimeout();
+ try {
+ ftpClient.connect(config.getUrl(), 21);
+ } catch (UnknownHostException e) {
+ throw new IOException("Can't find FTP server :" + "21");
+ }
+
+ int reply = ftpClient.getReplyCode();
+ if (!FTPReply.isPositiveCompletion(reply)) {
+ disconnect();
+ throw new IOException("Can't connect to server :" + "21");
+ }
+
+ if (!ftpClient.login(config.getUsername(), config.getPasswd())) {
+ disconnect();
+ throw new IOException("Can't login to server :" + "21");
+ }
+
+ // set data transfer mode.
+ ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
+
+ // Use passive mode to pass firewalls.
+ ftpClient.enterLocalPassiveMode();
+ }
+
+ /**
+ * 璁剧疆瓒呮椂鏃堕棿
+ */
+ private static void setTimeout() {
+ ftpClient.setDefaultTimeout(DEFAULT_TIMEOUT);
+ ftpClient.setConnectTimeout(DEFAULT_TIMEOUT);
+ ftpClient.setDataTimeout(DEFAULT_TIMEOUT);
+ }
+
+ /**
+ * ftp鏄惁澶勪簬杩炴帴鐘舵�侊紝鏄繛鎺ョ姸鎬佽繑鍥�<tt>true</tt>
+ *
+ * @return boolean 鏄繛鎺ョ姸鎬佽繑鍥�<tt>true</tt>
+ */
+ public static boolean isConnected() {
+ return ftpClient.isConnected();
+ }
+
+ /**
+ * 鍏抽棴ftp杩炴帴
+ */
+ public static void disconnect() {
+ if (null != ftpClient && ftpClient.isConnected()) {
+ try {
+ ftpClient.logout();
+ ftpClient.disconnect();
+ } catch (IOException ex) {
+ // do nothing
+ }
+ }
+ }
+
+ /**
+ * 鏀瑰彉宸ヤ綔鐩綍
+ *
+ * @param dir ftp鏈嶅姟鍣ㄤ笂鐩綍
+ * @return boolean 鏀瑰彉鎴愬姛杩斿洖true
+ */
+ public static boolean changeWorkingDirectory(String dir) {
+ try {
+ return ftpClient.changeWorkingDirectory(dir);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ /**
+ * Description: 鍚慒TP鏈嶅姟鍣ㄤ笂浼犳枃浠�
+ *
+ * @return 鎴愬姛杩斿洖true锛屽惁鍒欒繑鍥瀎alse
+ */
+ public static boolean uploadFile(FtpConfig config, MultipartFile file, String name) throws IOException {
+ boolean result = false;
+ InputStream input = file.getInputStream();
+ try {
+ connect(config);
+ ftpClient.setBufferSize(1024 * 1024);
+ result = ftpClient.storeFile(new String(name.getBytes(encoding), "iso-8859-1"), input);
+ if (result) {
+ System.out.println("涓婁紶鎴愬姛!");
+ }
+ input.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ ftpClient.logout();
+ ftpClient.disconnect();
+ }
+ return result;
+ }
+
+ /**
+ * 鏍规嵁鏂囦欢ftp璺緞鍚嶇О鍒犻櫎鏂囦欢
+ *
+ * @param ftpFileName 鏂囦欢ftp璺緞鍚嶇О
+ */
+ public static void deleteFile(String ftpFileName) throws IOException {
+ int dele = ftpClient.dele(ftpFileName);
+ try {
+ ftpClient.logout();
+ ftpClient.disconnect();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * 鏍规嵁uploadFile杩斿洖鐨勮矾寰勶紝浠巉tp涓嬭浇鏂囦欢鍒版寚瀹氳緭鍑烘祦涓�
+ *
+ * @param filename 鏂囦欢鍚嶇О
+ */
+ public static InputStream downloadFileFromDailyDir(String filename) throws IOException {
+ return ftpClient.retrieveFileStream(filename);
+ }
+
+ public static List<String> downloadList(FtpConfig config) throws IOException {
+ connect(config);
+ List<String> list = new ArrayList<>();
+ FTPFile[] ftpFiles = ftpClient.listFiles();
+ if (ftpFiles.length == 0) {
+ return list;
+ }
+ for (FTPFile ftpFile : ftpFiles) {
+ list.add(ftpFile.getName());
+ }
+ return list;
+ }
+
+ /**
+ * 鏍规嵁鍚嶇О鑾峰彇鏂囦欢锛屼互瀛楄妭鏁扮粍杩斿洖
+ *
+ * @param ftpPath FTP鏈嶅姟鍣ㄦ枃浠剁浉瀵硅矾寰勶紝渚嬪锛歵est/123
+ * @param fileName 鏂囦欢鍚嶏紝渚嬪锛歵est.xls
+ * @return byte[] 瀛楄妭鏁扮粍瀵硅薄
+ */
+ public static byte[] getFileBytesByName(InputStream is) throws IOException {
+ //鍒涘缓byte鏁扮粍杈撳嚭娴�
+ ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+ try {
+ try {
+ byte[] buffer = new byte[1024 * 1024 * 4];
+ int len = -1;
+ while ((len = is.read(buffer, 0, 1024 * 1024 * 4)) != -1) {
+ byteStream.write(buffer, 0, len);
+ }
+ } catch (Exception e) {
+ System.out.println(e);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return byteStream.toByteArray();
+ }
+
+}
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 5d1b2ea..df3f77b 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
@@ -5,6 +5,7 @@
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
@@ -14,6 +15,7 @@
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.dromara.common.oss.entity.SynchronousRequest;
+import org.dromara.common.oss.entity.SynchronousRequest2;
import org.dromara.common.oss.entity.VideoRequest;
import org.springframework.web.multipart.MultipartFile;
@@ -25,36 +27,6 @@
import java.util.HashMap;
public class HttpUtils {
- public static String sendPostWithJson(String url, String jsonStr, HashMap<String,String> headers) {
- // 杩斿洖鐨勭粨鏋�
- String jsonResult = "";
- try {
- HttpClient client = new HttpClient();
- // 杩炴帴瓒呮椂
- client.getHttpConnectionManager().getParams().setConnectionTimeout(3*1000);
- // 璇诲彇鏁版嵁瓒呮椂
- client.getHttpConnectionManager().getParams().setSoTimeout(3*60*1000);
- client.getParams().setContentCharset("UTF-8");
- PostMethod postMethod = new PostMethod(url);
-
- postMethod.setRequestHeader("content-type", headers.get("content-type"));
-
- // 闈炵┖
- if (null != jsonStr && !"".equals(jsonStr)) {
- StringRequestEntity requestEntity = new StringRequestEntity(jsonStr, headers.get("content-type"), "UTF-8");
- postMethod.setRequestEntity(requestEntity);
- }
- int status = client.executeMethod(postMethod);
- if (status == HttpStatus.SC_OK) {
- jsonResult = postMethod.getResponseBodyAsString();
- } else {
- throw new RuntimeException("鎺ュ彛杩炴帴澶辫触锛�");
- }
- } catch (Exception e) {
- throw new RuntimeException("鎺ュ彛杩炴帴澶辫触锛�");
- }
- return jsonResult;
- }
private static final String BOUNDARY = "----WebKitFormBoundary7MA4YWxkTrZu0gW";
private static final String LINE_FEED = "\r\n";
@@ -66,59 +38,8 @@
return file;
}
- public static void sendPostRequest(String url, String stringParam, File fileParam) throws Exception {
-
- URL obj = new URL(url);
- HttpURLConnection con = (HttpURLConnection) obj.openConnection();
-
- // 璁剧疆POST璇锋眰
- con.setRequestMethod("POST");
- con.setDoOutput(true);
- con.setDoInput(true);
- con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
-
- // 鏋勫缓璇锋眰浣�
- DataOutputStream wr = new DataOutputStream(con.getOutputStream());
- wr.writeBytes("--" + BOUNDARY + LINE_FEED);
- wr.writeBytes("Content-Disposition: form-data; name=\"stringParam\"" + LINE_FEED);
- wr.writeBytes(LINE_FEED);
- wr.writeBytes(stringParam + LINE_FEED);
-
- wr.writeBytes("--" + BOUNDARY + LINE_FEED);
- wr.writeBytes("Content-Disposition: form-data; name=\"fileParam\"; filename=\"" + fileParam.getName() + "\"" + LINE_FEED);
- wr.writeBytes("Content-Type: " + HttpURLConnection.guessContentTypeFromName(fileParam.getName()) + LINE_FEED);
- wr.writeBytes("Content-Transfer-Encoding: binary" + LINE_FEED);
- wr.writeBytes(LINE_FEED);
-
- FileInputStream inputStream = new FileInputStream(fileParam);
- byte[] buffer = new byte[4096];
- int bytesRead = -1;
- while ((bytesRead = inputStream.read(buffer)) != -1) {
- wr.write(buffer, 0, bytesRead);
- }
- wr.writeBytes(LINE_FEED);
- wr.writeBytes("--" + BOUNDARY + "--" + LINE_FEED);
-
- wr.flush();
- wr.close();
-
- // 鍙戦�佽姹傚苟鑾峰彇鍝嶅簲
- 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());
- }
-
/**
- * 涓婁紶鍚屾 瑙嗛涓撶綉
+ * 涓婁紶鍚屾 瑙嗛涓撶綉 -- 鍏畨鍐呯綉
* @param url
* @param entity
* @return
@@ -182,32 +103,6 @@
return responseBody;
}
- /**
- * 涓婁紶鍚屾2
- * @param url
- * @param entity
- * @return
- * @throws IOException
- */
- public static String sendPostRequestTwo(String url, SynchronousRequest entity) throws IOException {
- org.apache.http.client.HttpClient httpClient = HttpClientBuilder.create().build();
- HttpPost httpPost = new HttpPost(url);
-
- ContentType contentType = ContentType.create("multipart/form-data", StandardCharsets.UTF_8);
- MultipartEntityBuilder builder = MultipartEntityBuilder.create();
- builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
-
- // 娣诲姞MultipartFile鍙傛暟
- builder.addBinaryBody("file", entity.getFile().getBytes(), ContentType.MULTIPART_FORM_DATA, entity.getFile().getOriginalFilename());
-
- 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;
- }
/**
* 鍒犻櫎鍚屾
@@ -236,5 +131,56 @@
System.out.println("Response: " + responseBody);
return responseBody;
}
+
+
+ /**
+ * 涓婁紶鍚屾 瑙嗛涓撶綉 -- 鍏畨鍐呯綉锛堝畾鏃讹級
+ * @param url
+ * @param entity
+ * @return
+ * @throws IOException
+ */
+ public static String sendPostRequest2(String url, SynchronousRequest entity, byte[] bytes) throws IOException {
+ org.apache.http.client.HttpClient httpClient = HttpClientBuilder.create().build();
+ HttpPost httpPost = new HttpPost(url);
+
+ ContentType contentType = ContentType.create("multipart/form-data", StandardCharsets.UTF_8);
+ MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+ builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
+
+ // 娣诲姞MultipartFile鍙傛暟
+ builder.addBinaryBody("file", bytes, ContentType.MULTIPART_FORM_DATA, entity.getFileName());
+
+ // 娣诲姞String鍙傛暟
+ builder.addTextBody("path", entity.getPath(), ContentType.TEXT_PLAIN);
+ builder.addTextBody("ossId", entity.getOssId(), ContentType.TEXT_PLAIN);
+ builder.addTextBody("createBy", entity.getCreateBy(), ContentType.TEXT_PLAIN);
+ builder.addTextBody("password", entity.getPassword(), ContentType.TEXT_PLAIN);
+ builder.addTextBody("fileName", entity.getFileName(), contentType);
+ builder.addTextBody("createTime", entity.getCreateTime(), ContentType.TEXT_PLAIN);
+
+ 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;
+ }
+
+ /**
+ * @param input 杈撳叆娴�
+ * @return byte[] 鏁扮粍
+ */
+ public static byte[] inputStream2byte(InputStream input) throws IOException {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ byte[] buffer = new byte[4096];
+ int n = 0;
+ while (-1 != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ }
+ return output.toByteArray();
+ }
+
}
--
Gitblit v1.8.0