diff --git a/drive-service-error.log b/drive-service-error.log new file mode 100644 index 0000000..e69de29 diff --git a/drive-service.log b/drive-service.log new file mode 100644 index 0000000..f48fd5a --- /dev/null +++ b/drive-service.log @@ -0,0 +1,73 @@ + + . ____ _ __ _ _ + /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ +( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ + \\/ ___)| |_)| | | | | || (_| | ) ) ) ) + ' |____| .__|_| |_|_| |_\__, | / / / / + =========|_|==============|___/=/_/_/_/ + :: Spring Boot :: (v3.2.5) + +2026-07-02T14:26:40.211+08:00 INFO 151212 --- [wangpan-drive-service] [ main] com.wangpan.DriveServiceApplication : Starting DriveServiceApplication v1.0-SNAPSHOT using Java 17.0.8 with PID 151212 (D:\java2\wangpan\java\wangpan-drive-service\target\wangpan-drive-service-1.0-SNAPSHOT.jar started by 李荣强 in D:\java2\wangpan\java) +2026-07-02T14:26:40.217+08:00 INFO 151212 --- [wangpan-drive-service] [ main] com.wangpan.DriveServiceApplication : No active profile set, falling back to 1 default profile: "default" +2026-07-02T14:26:41.606+08:00 INFO 151212 --- [wangpan-drive-service] [ main] ptablePropertiesBeanFactoryPostProcessor : Post-processing PropertySource instances +2026-07-02T14:26:41.608+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource configurationProperties [class org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource +2026-07-02T14:26:41.610+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource servletConfigInitParams [class org.springframework.core.env.PropertySource$StubPropertySource +2026-07-02T14:26:41.610+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource servletContextInitParams [class org.springframework.core.env.PropertySource$StubPropertySource +2026-07-02T14:26:41.610+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource systemProperties [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper +2026-07-02T14:26:41.611+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource systemEnvironment [org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource] to EncryptableSystemEnvironmentPropertySourceWrapper +2026-07-02T14:26:41.611+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource random [org.springframework.boot.env.RandomValuePropertySource] to EncryptablePropertySourceWrapper +2026-07-02T14:26:41.611+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource Config resource 'class path resource [application.yml]' via location 'optional:classpath:/' [org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper +2026-07-02T14:26:41.842+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.u.j.filter.DefaultLazyPropertyFilter : Property Filter custom Bean not found with name 'encryptablePropertyFilter'. Initializing Default Property Filter +2026-07-02T14:26:41.854+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.u.j.r.DefaultLazyPropertyResolver : Property Resolver custom Bean not found with name 'encryptablePropertyResolver'. Initializing Default Property Resolver +2026-07-02T14:26:41.856+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.u.j.d.DefaultLazyPropertyDetector : Property Detector custom Bean not found with name 'encryptablePropertyDetector'. Initializing Default Property Detector +2026-07-02T14:26:42.108+08:00 INFO 151212 --- [wangpan-drive-service] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8082 (http) +2026-07-02T14:26:42.121+08:00 INFO 151212 --- [wangpan-drive-service] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] +2026-07-02T14:26:42.122+08:00 INFO 151212 --- [wangpan-drive-service] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.20] +2026-07-02T14:26:42.179+08:00 INFO 151212 --- [wangpan-drive-service] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext +2026-07-02T14:26:42.180+08:00 INFO 151212 --- [wangpan-drive-service] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1857 ms +2026-07-02T14:26:42.353+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.u.j.encryptor.DefaultLazyEncryptor : String Encryptor custom Bean not found with name 'jasyptStringEncryptor'. Initializing Default String Encryptor +2026-07-02T14:26:42.367+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.u.j.c.StringEncryptorBuilder : Encryptor config not found for property jasypt.encryptor.provider-name, using default value: null +2026-07-02T14:26:42.368+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.u.j.c.StringEncryptorBuilder : Encryptor config not found for property jasypt.encryptor.provider-class-name, using default value: null +? 数据库配置加载成功: jdbc:mysql://118.178.238.159:33306/wangpan?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true +======================================== + [DatabaseInitializer] 网盘服务数据库初始化... +======================================== + ? 表已存在:wp_drive + ? 表已存在:wp_drive_folder + ? 表已存在:wp_drive_movie + ? 表已存在:wp_icon + ? 表已存在:wp_user_openlist + ? [wp_drive] logo_url 字段已存在 + ? [wp_drive] 表创建完成 + ? [wp_drive_folder] 表创建完成 + ? [wp_drive_movie] 表创建完成 +? 数据库初始化检查完成! +======================================== + ? 数据库初始化成功!耗时:743ms +======================================== + _ _ |_ _ _|_. ___ _ | _ +| | |\/|_)(_| | |_\ |_)||_|_\ + / | + 3.5.7 +2026-07-02T14:26:44.370+08:00 INFO 151212 --- [wangpan-drive-service] [ main] c.wangpan.listener.IconCleanupScheduler : [IconCleanupScheduler] 定时清理任务已启动 | 首次延迟=10分钟 | 间隔=24小时 +2026-07-02T14:26:44.963+08:00 INFO 151212 --- [wangpan-drive-service] [ main] com.wangpan.common.util.MinioUtil : [MinioUtil] 存储桶已存在: wangpan +2026-07-02T14:26:44.964+08:00 INFO 151212 --- [wangpan-drive-service] [ main] com.wangpan.common.util.MinioUtil : [MinioUtil] MinIO 客户端初始化成功: http://118.178.238.159:39000 +2026-07-02T14:26:45.450+08:00 INFO 151212 --- [wangpan-drive-service] [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 3 endpoint(s) beneath base path '/actuator' +2026-07-02T14:26:45.539+08:00 WARN 151212 --- [wangpan-drive-service] [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop' +2026-07-02T14:26:45.572+08:00 INFO 151212 --- [wangpan-drive-service] [ main] .s.b.a.l.ConditionEvaluationReportLogger : + +Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. +2026-07-02T14:26:45.604+08:00 ERROR 151212 --- [wangpan-drive-service] [ main] o.s.b.d.LoggingFailureAnalysisReporter : + +*************************** +APPLICATION FAILED TO START +*************************** + +Description: + +Web server failed to start. Port 8082 was already in use. + +Action: + +Identify and stop the process that's listening on port 8082 or configure this application to listen on another port. + diff --git a/restart-services.ps1 b/restart-services.ps1 index 4e789a0..d494d8b 100644 --- a/restart-services.ps1 +++ b/restart-services.ps1 @@ -56,7 +56,7 @@ foreach ($service in $services) { Write-Host " ERROR: Jar not found: $jarPath" -ForegroundColor Red continue } - $process = Start-Process -FilePath "java" -ArgumentList "-jar", $jarPath -WindowStyle Hidden -PassThru + $process = Start-Process -FilePath "java" -ArgumentList "-DJASYPT_ENCRYPTOR_PASSWORD=$JASYPT_PASSWORD", "-jar", $jarPath -WindowStyle Hidden -PassThru if ($process) { Write-Host " Started $name (PID: $($process.Id))" -ForegroundColor Green } else { diff --git a/wangpan-common/src/main/java/com/wangpan/common/config/MybatisPlusConfig.java b/wangpan-common/src/main/java/com/wangpan/common/config/MybatisPlusConfig.java new file mode 100644 index 0000000..20e1d7e --- /dev/null +++ b/wangpan-common/src/main/java/com/wangpan/common/config/MybatisPlusConfig.java @@ -0,0 +1,26 @@ +package com.wangpan.common.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * MyBatis-Plus 閰嶇疆 + * 娉ㄥ唽鍒嗛〉鎻掍欢锛屼娇 Page 鍒嗛〉鏌ヨ鐢熸晥 + */ +@Configuration +public class MybatisPlusConfig { + + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + // 娉ㄥ唽鍒嗛〉鎻掍欢锛屾寚瀹氭暟鎹簱绫诲瀷涓 MySQL + PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor(DbType.MYSQL); + // 鍗曢〉鏈澶ф潯鏁伴檺鍒讹紝闃叉璇紶瓒呭ぇ pageSize 瀵艰嚧 OOM + paginationInterceptor.setMaxLimit(500L); + interceptor.addInnerInterceptor(paginationInterceptor); + return interceptor; + } +} diff --git a/wangpan-common/src/main/java/com/wangpan/common/dal/dataobject/DriveDO.java b/wangpan-common/src/main/java/com/wangpan/common/dal/dataobject/DriveDO.java index f89fb16..ad14ba6 100644 --- a/wangpan-common/src/main/java/com/wangpan/common/dal/dataobject/DriveDO.java +++ b/wangpan-common/src/main/java/com/wangpan/common/dal/dataobject/DriveDO.java @@ -39,6 +39,12 @@ public class DriveDO implements Serializable { /** 缃戠洏 Logo URL锛圡inIO 瀛樺偍閾炬帴锛 */ private String logoUrl; + /** Logo 鏈鍚庤闂椂闂达紙鐢ㄤ簬鍥炴敹绛栫暐锛 */ + private LocalDateTime logoLastAccessTime; + + /** Logo 鐘舵侊細normal锛堟甯革級/recycling锛堝洖鏀朵腑锛/deleted锛堝凡鍒犻櫎锛 */ + private String logoStatus; + /** OpenList 瀛樺偍ID锛氬叧鑱 OpenList 涓殑瀛樺偍閰嶇疆 */ private String openlistStorageId; @@ -82,6 +88,12 @@ public class DriveDO implements Serializable { public String getLogoUrl() { return logoUrl; } public void setLogoUrl(String logoUrl) { this.logoUrl = logoUrl; } + public LocalDateTime getLogoLastAccessTime() { return logoLastAccessTime; } + public void setLogoLastAccessTime(LocalDateTime logoLastAccessTime) { this.logoLastAccessTime = logoLastAccessTime; } + + public String getLogoStatus() { return logoStatus; } + public void setLogoStatus(String logoStatus) { this.logoStatus = logoStatus; } + public String getOpenlistStorageId() { return openlistStorageId; } public void setOpenlistStorageId(String openlistStorageId) { this.openlistStorageId = openlistStorageId; } diff --git a/wangpan-common/src/main/java/com/wangpan/common/dal/mapper/DriveMapper.java b/wangpan-common/src/main/java/com/wangpan/common/dal/mapper/DriveMapper.java index 1529e30..ed670f3 100644 --- a/wangpan-common/src/main/java/com/wangpan/common/dal/mapper/DriveMapper.java +++ b/wangpan-common/src/main/java/com/wangpan/common/dal/mapper/DriveMapper.java @@ -16,19 +16,22 @@ public interface DriveMapper extends BaseMapper { /** 寤鸿〃SQL锛堜繚鐣欎緵 DatabaseInitializer 浣跨敤锛 */ String CREATE_TABLE_SQL = """ CREATE TABLE IF NOT EXISTS wp_drive ( - id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '缃戠洏ID', - user_id BIGINT NOT NULL COMMENT '鎵灞炵敤鎴稩D', - name VARCHAR(100) NOT NULL COMMENT '缃戠洏鍚嶇О', - description VARCHAR(500) DEFAULT NULL COMMENT '缃戠洏鎻忚堪', - logo_url TEXT DEFAULT NULL COMMENT '缃戠洏Logo URL锛圡inIO瀛樺偍閾炬帴锛', - folder_count INT NOT NULL DEFAULT 0 COMMENT '鏂囦欢澶规暟閲', - file_count INT NOT NULL DEFAULT 0 COMMENT '鏂囦欢鏁伴噺', - total_size BIGINT NOT NULL DEFAULT 0 COMMENT '鎬诲ぇ灏忥紙瀛楄妭锛', - status VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT '鐘舵侊細active/disabled', - update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '鏇存柊鏃堕棿', - create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '鍒涘缓鏃堕棿', + id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '缃戠洏ID', + user_id BIGINT NOT NULL COMMENT '鎵灞炵敤鎴稩D', + name VARCHAR(100) NOT NULL COMMENT '缃戠洏鍚嶇О', + description VARCHAR(500) DEFAULT NULL COMMENT '缃戠洏鎻忚堪', + logo_url TEXT DEFAULT NULL COMMENT '缃戠洏Logo URL锛圡inIO瀛樺偍閾炬帴锛', + logo_last_access_time DATETIME DEFAULT NULL COMMENT 'Logo鏈鍚庤闂椂闂达紙鐢ㄤ簬鍥炴敹绛栫暐锛', + logo_status VARCHAR(20) NOT NULL DEFAULT 'normal' COMMENT 'Logo鐘舵侊細normal锛堟甯革級/recycling锛堝洖鏀朵腑锛/deleted锛堝凡鍒犻櫎锛', + folder_count INT NOT NULL DEFAULT 0 COMMENT '鏂囦欢澶规暟閲', + file_count INT NOT NULL DEFAULT 0 COMMENT '鏂囦欢鏁伴噺', + total_size BIGINT NOT NULL DEFAULT 0 COMMENT '鎬诲ぇ灏忥紙瀛楄妭锛', + status VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT '鐘舵侊細active/disabled', + update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '鏇存柊鏃堕棿', + create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '鍒涘缓鏃堕棿', INDEX idx_user_id (user_id), - INDEX idx_status (status) + INDEX idx_status (status), + INDEX idx_logo_status (logo_status) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='缃戠洏琛' """; } diff --git a/wangpan-common/src/main/java/com/wangpan/common/dal/repository/DriveRepository.java b/wangpan-common/src/main/java/com/wangpan/common/dal/repository/DriveRepository.java index cc37f08..44340ce 100644 --- a/wangpan-common/src/main/java/com/wangpan/common/dal/repository/DriveRepository.java +++ b/wangpan-common/src/main/java/com/wangpan/common/dal/repository/DriveRepository.java @@ -90,6 +90,61 @@ public class DriveRepository extends ServiceImpl { return update(wrapper); } + /** + * 鏇存柊缃戠洏 Logo 鏈鍚庤闂椂闂达紙璁块棶鏃惰皟鐢紝鍒锋柊鍥炴敹绛栫暐璁℃椂锛 + * 濡傛灉 Logo 澶勪簬鍥炴敹妯″紡锛坮ecycling锛夛紝鍒欐仮澶嶆甯告ā寮忥紙normal锛夊苟閲嶆柊璁℃椂 + */ + public boolean updateLogoAccessTime(Long id) { + var wrapper = new LambdaUpdateWrapper() + .eq(DriveDO::getId, id) + .isNotNull(DriveDO::getLogoUrl) + .set(DriveDO::getLogoLastAccessTime, LocalDateTime.now()) + .set(DriveDO::getLogoStatus, "normal"); + return update(wrapper); + } + + /** + * 鏌ヨ鎵鏈夋湁 Logo 涓旂姸鎬佷负 normal 鐨勭綉鐩橈紙鐢ㄤ簬鍥炴敹绛栫暐妫鏌ワ級 + */ + public List findDrivesWithLogoNormal() { + var wrapper = new LambdaQueryWrapper() + .isNotNull(DriveDO::getLogoUrl) + .eq(DriveDO::getLogoStatus, "normal"); + return list(wrapper); + } + + /** + * 鏌ヨ鎵鏈夊浜庡洖鏀舵ā寮忥紙recycling锛夌殑缃戠洏锛堢敤浜庡垹闄ょ瓥鐣ユ鏌ワ級 + */ + public List findDrivesWithLogoRecycling() { + var wrapper = new LambdaQueryWrapper() + .isNotNull(DriveDO::getLogoUrl) + .eq(DriveDO::getLogoStatus, "recycling"); + return list(wrapper); + } + + /** + * 灏 Logo 鐘舵佹洿鏂颁负鍥炴敹妯″紡锛坮ecycling锛 + */ + public boolean updateLogoStatusToRecycling(Long id) { + var wrapper = new LambdaUpdateWrapper() + .eq(DriveDO::getId, id) + .set(DriveDO::getLogoStatus, "recycling"); + return update(wrapper); + } + + /** + * 鍒犻櫎 Logo锛氭竻绌 logo_url锛岃缃姸鎬佷负 deleted + */ + public boolean deleteLogo(Long id) { + var wrapper = new LambdaUpdateWrapper() + .eq(DriveDO::getId, id) + .set(DriveDO::getLogoUrl, null) + .set(DriveDO::getLogoStatus, "deleted") + .set(DriveDO::getLogoLastAccessTime, null); + return update(wrapper); + } + /** * 鏇存柊缃戠洏缁熻淇℃伅 * 浣跨敤 MyBatis-Plus LambdaUpdateWrapper 鏋勫缓鏇存柊鏉′欢 @@ -143,6 +198,8 @@ public class DriveRepository extends ServiceImpl { driveDO.setName(drive.getName()); driveDO.setDescription(drive.getDescription()); driveDO.setLogoUrl(drive.getLogoUrl()); + driveDO.setLogoLastAccessTime(drive.getLogoLastAccessTime()); + driveDO.setLogoStatus(drive.getLogoStatus()); driveDO.setOpenlistStorageId(drive.getOpenlistStorageId()); driveDO.setOpenlistMountPath(drive.getOpenlistMountPath()); driveDO.setFolderCount(drive.getFolderCount()); @@ -185,6 +242,8 @@ public class DriveRepository extends ServiceImpl { map.put("name", driveDO.getName()); map.put("description", driveDO.getDescription()); map.put("logoUrl", driveDO.getLogoUrl()); + map.put("logoLastAccessTime", driveDO.getLogoLastAccessTime() != null ? driveDO.getLogoLastAccessTime().toString() : null); + map.put("logoStatus", driveDO.getLogoStatus()); map.put("openlistStorageId", driveDO.getOpenlistStorageId()); map.put("openlistMountPath", driveDO.getOpenlistMountPath()); map.put("folderCount", driveDO.getFolderCount()); diff --git a/wangpan-common/src/main/java/com/wangpan/common/dal/repository/UserRepository.java b/wangpan-common/src/main/java/com/wangpan/common/dal/repository/UserRepository.java index 076e332..912537d 100644 --- a/wangpan-common/src/main/java/com/wangpan/common/dal/repository/UserRepository.java +++ b/wangpan-common/src/main/java/com/wangpan/common/dal/repository/UserRepository.java @@ -223,6 +223,15 @@ public class UserRepository extends ServiceImpl { /** * Entity 鈫 DO 杞崲 + * + * 鏃堕棿瀛楁鍏滃簳璇存槑锛 + * UserDO.createTime 鏍囨敞浜 @TableField(fill = FieldFill.INSERT)锛 + * 鏈熸湜鐢 MyBatis-Plus 鐨 MetaObjectHandler 鑷姩濉厖銆 + * 浣嗘湰椤圭洰鏈厤缃 MetaObjectHandler锛堝弬鑰 IconRepository.toIconDO 鐨勫鐞嗭級锛 + * 鑻ヨ皟鐢ㄦ柟鏈樉寮忚缃椂闂达紝浼氬鑷 INSERT 璇彞甯︿笂 create_time = null锛 + * 鑰 wp_user.create_time 涓 NOT NULL锛屼細鎶涘嚭 + * SQLIntegrityConstraintViolationException: Column 'create_time' cannot be null銆 + * 鍥犳鍦ㄦ澶勭粺涓鍏滃簳锛氭椂闂翠负 null 鏃跺彇褰撳墠鏃堕棿锛屼繚璇佸啓鍏ュ畨鍏ㄣ */ private UserDO toUserDO(User user) { var userDO = new UserDO(); @@ -240,8 +249,10 @@ public class UserRepository extends ServiceImpl { userDO.setLockUntil(user.getLockUntil()); userDO.setFailCount(user.getFailCount()); userDO.setTmdbApiKey(user.getTmdbApiKey()); - userDO.setCreateTime(user.getCreateTime()); - userDO.setUpdateTime(user.getUpdateTime()); + // 鏃堕棿瀛楁鍏滃簳锛氭湭璁剧疆鏃朵娇鐢ㄥ綋鍓嶆椂闂达紝閬垮厤 NOT NULL 绾︽潫鎶ラ敊 + var now = LocalDateTime.now(); + userDO.setCreateTime(user.getCreateTime() != null ? user.getCreateTime() : now); + userDO.setUpdateTime(user.getUpdateTime() != null ? user.getUpdateTime() : now); userDO.setIsDeleted(user.getIsDeleted()); userDO.setRemark(user.getRemark()); return userDO; diff --git a/wangpan-common/src/main/java/com/wangpan/common/entity/Drive.java b/wangpan-common/src/main/java/com/wangpan/common/entity/Drive.java index 6c7076d..f51b251 100644 --- a/wangpan-common/src/main/java/com/wangpan/common/entity/Drive.java +++ b/wangpan-common/src/main/java/com/wangpan/common/entity/Drive.java @@ -40,6 +40,12 @@ public class Drive implements Serializable { /** 缃戠洏 Logo URL锛氬瓨鍌ㄥ湪 MinIO 涓殑鍥剧墖閾炬帴 */ private String logoUrl; + /** Logo 鏈鍚庤闂椂闂达紙鐢ㄤ簬鍥炴敹绛栫暐锛 */ + private LocalDateTime logoLastAccessTime; + + /** Logo 鐘舵侊細normal锛堟甯革級/recycling锛堝洖鏀朵腑锛/deleted锛堝凡鍒犻櫎锛 */ + private String logoStatus; + // ==================== 缁熻灞炴 ==================== /** 鏂囦欢澶规暟閲 */ @@ -116,6 +122,12 @@ public class Drive implements Serializable { public String getLogoUrl() { return logoUrl; } public void setLogoUrl(String logoUrl) { this.logoUrl = logoUrl; } + public LocalDateTime getLogoLastAccessTime() { return logoLastAccessTime; } + public void setLogoLastAccessTime(LocalDateTime logoLastAccessTime) { this.logoLastAccessTime = logoLastAccessTime; } + + public String getLogoStatus() { return logoStatus; } + public void setLogoStatus(String logoStatus) { this.logoStatus = logoStatus; } + public Integer getFolderCount() { return folderCount; } public void setFolderCount(Integer folderCount) { this.folderCount = folderCount; } diff --git a/wangpan-common/src/main/java/com/wangpan/common/util/MinioUtil.java b/wangpan-common/src/main/java/com/wangpan/common/util/MinioUtil.java index ea4825a..f9e6fc7 100644 --- a/wangpan-common/src/main/java/com/wangpan/common/util/MinioUtil.java +++ b/wangpan-common/src/main/java/com/wangpan/common/util/MinioUtil.java @@ -51,8 +51,8 @@ public class MinioUtil { @Value("${minio.bucketName}") private String bucketName; - /** 棰勭鍚 URL 鏈夋晥鏈燂紙7澶╋級 */ - private static final int PRESIGNED_URL_EXPIRY_DAYS = 7; + /** 棰勭鍚 URL 鏈夋晥鏈燂紙365澶╋紝纭繚鍦ㄨ祫婧愮敓鍛藉懆鏈熷唴 URL 濮嬬粓鏈夋晥锛 */ + private static final int PRESIGNED_URL_EXPIRY_DAYS = 365; /** MinIO 瀹㈡埛绔疄渚嬶紙鍗曚緥妯″紡锛 */ private static volatile MinioClient client; diff --git a/wangpan-common/src/main/java/com/wangpan/common/util/OpenListClient.java b/wangpan-common/src/main/java/com/wangpan/common/util/OpenListClient.java index 69a39b0..3897c9c 100644 --- a/wangpan-common/src/main/java/com/wangpan/common/util/OpenListClient.java +++ b/wangpan-common/src/main/java/com/wangpan/common/util/OpenListClient.java @@ -169,6 +169,36 @@ public class OpenListClient { return result; } + /** + * 寮哄埗鍒锋柊骞堕獙璇 Token锛堝叕寮鏂规硶锛屼緵 Controller 璋冪敤锛 + * 鐢ㄤ簬鍦ㄥ悓姝ュ墠纭繚 Token 鏈夋晥 + * + * @param userId 鐢ㄦ埛ID + * @return 鏄惁鎴愬姛鍒锋柊骞堕獙璇 Token + */ + public boolean refreshAndVerifyToken(Long userId) { + UserOpenlist config = getUserOpenlist(userId); + if (config == null) { + log.warn("鐢ㄦ埛 {} 鏈粦瀹 OpenList锛屾棤娉曞埛鏂 Token", userId); + return false; + } + + log.info("鐢ㄦ埛 {} 寮濮嬪己鍒跺埛鏂板苟楠岃瘉 OpenList Token", userId); + var testResult = testConnection(config.getOpenlistUrl(), config.getOpenlistUsername(), config.getOpenlistPassword()); + boolean success = (boolean) testResult.get("success"); + + if (success && testResult.get("token") != null) { + String newToken = (String) testResult.get("token"); + long expireTime = System.currentTimeMillis() + 86400000; // 24 灏忔椂 + userOpenlistRepository.updateToken(userId, newToken, expireTime); + log.info("鐢ㄦ埛 {} 鐨 OpenList Token 宸插己鍒跺埛鏂板苟楠岃瘉鎴愬姛", userId); + return true; + } else { + log.warn("鐢ㄦ埛 {} 鐨 OpenList Token 鍒锋柊澶辫触: {}", userId, testResult.get("message")); + return false; + } + } + // ==================== 鏂囦欢鎿嶄綔 API锛堜娇鐢ㄧ敤鎴风骇杩炴帴锛 ==================== /** @@ -207,17 +237,51 @@ public class OpenListClient { /** * 妫鏌ュ搷搴旀槸鍚﹀洜 Token 澶辨晥鑰屽け璐 * OpenList 杩斿洖鏍煎紡锛歿"code": 401, "message": "token is invalidated", ...} + * + * @param response 鍝嶅簲浣 Map + * @return 鏄惁 Token 澶辨晥 */ private boolean isTokenInvalidated(Map response) { if (response == null) return false; + Object code = response.get("code"); Object message = response.get("message"); - return code != null && (int) code == 401 && message != null && message.toString().contains("token is invalidated"); + + log.info("妫鏌 Token 澶辨晥: code={}, message={}", code, message); + + // 鏇村仴澹殑绫诲瀷杞崲锛氭敮鎸 Number銆丼tring 绛夊绉嶇被鍨 + int codeValue = 0; + if (code instanceof Number) { + codeValue = ((Number) code).intValue(); + } else if (code instanceof String) { + try { + codeValue = Integer.parseInt((String) code); + } catch (NumberFormatException e) { + log.warn("鏃犳硶瑙f瀽 code 鍊: {}", code); + return false; + } + } else if (code != null) { + log.warn("鏈煡鐨 code 绫诲瀷: {}, 鍊: {}", code.getClass().getName(), code); + return false; + } + + // 澶у皬鍐欎笉鏁忔劅鍖归厤锛屽吋瀹 "token is invalidated"銆"Token is invalidated" 绛 + boolean isInvalidated = codeValue == 401 && message != null + && message.toString().toLowerCase().contains("token is invalidated"); + if (isInvalidated) { + log.info("妫娴嬪埌 Token 澶辨晥: code={}, message={}", code, message); + } + + return isInvalidated; } /** * 鎵ц POST 璇锋眰锛堝甫鑷姩閲嶈瘯锛 * 褰 Token 澶辨晥鏃惰嚜鍔ㄥ埛鏂板苟閲嶈瘯涓娆 + * + * 閲嶈锛歄penList 鍦 Token 澶辨晥鏃跺彲鑳借繑鍥 HTTP 401 鐘舵佺爜锛 + * RestTemplate 浼氭姏鍑 HttpClientErrorException 寮傚父锛 + * 鑰屼笉鏄繑鍥炲搷搴斾綋銆傚洜姝ら渶瑕佹崟鑾峰紓甯稿苟妫鏌ョ姸鎬佺爜銆 * * @param userId 鐢ㄦ埛ID * @param url 璇锋眰 URL @@ -229,25 +293,110 @@ public class OpenListClient { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - headers.setBearerAuth(token); + headers.set("Authorization", token); HttpEntity> entity = new HttpEntity<>(requestBody, headers); - ResponseEntity response = restTemplate.postForEntity(url, entity, Map.class); - Map result = response.getBody(); - - // 濡傛灉 Token 澶辨晥锛屽埛鏂板悗閲嶈瘯涓娆 - if (isTokenInvalidated(result)) { - log.info("鐢ㄦ埛 {} 鐨 OpenList Token 澶辨晥锛岃嚜鍔ㄥ埛鏂板苟閲嶈瘯", userId); - token = getValidToken(userId); // 寮哄埗鍒锋柊 - headers.setBearerAuth(token); - entity = new HttpEntity<>(requestBody, headers); - response = restTemplate.postForEntity(url, entity, Map.class); + Map result = null; + + try { + ResponseEntity response = restTemplate.postForEntity(url, entity, Map.class); result = response.getBody(); + } catch (org.springframework.web.client.HttpClientErrorException e) { + // 鎹曡幏 HTTP 4xx 閿欒锛堝寘鎷 401 Unauthorized锛 + log.warn("鐢ㄦ埛 {} 璇锋眰 OpenList API 澶辫触: HTTP {} - {}", userId, e.getStatusCode(), e.getMessage()); + + // 妫鏌ユ槸鍚︽槸 401 Token 澶辨晥 + if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) { + log.info("鐢ㄦ埛 {} 鐨 OpenList Token 澶辨晥锛圚TTP 401锛夛紝寮哄埗鍒锋柊骞堕噸璇", userId); + token = refreshToken(userId); + headers.set("Authorization", token); + entity = new HttpEntity<>(requestBody, headers); + + try { + ResponseEntity retryResponse = restTemplate.postForEntity(url, entity, Map.class); + result = retryResponse.getBody(); + log.info("鐢ㄦ埛 {} Token 鍒锋柊鍚庨噸璇曟垚鍔", userId); + } catch (Exception retryEx) { + log.error("鐢ㄦ埛 {} Token 鍒锋柊鍚庨噸璇曚粛鐒跺け璐", userId, retryEx); + throw new RuntimeException("OpenList API 璋冪敤澶辫触锛堥噸璇曞悗锛: " + retryEx.getMessage(), retryEx); + } + } else { + // 闈 401 閿欒锛岀洿鎺ユ姏鍑 + throw new RuntimeException("OpenList API 璋冪敤澶辫触: HTTP " + e.getStatusCode() + " - " + e.getMessage(), e); + } + } catch (Exception e) { + // 鍏朵粬寮傚父锛堢綉缁滈敊璇瓑锛 + log.error("鐢ㄦ埛 {} 璇锋眰 OpenList API 寮傚父", userId, e); + throw new RuntimeException("OpenList API 璋冪敤寮傚父: " + e.getMessage(), e); + } + + // 妫鏌ュ搷搴斾綋涓殑 Token 澶辨晥鏍囧織锛堟煇浜涙儏鍐典笅 OpenList 鍙兘杩斿洖 HTTP 200 浣 body 涓 code=401锛 + if (isTokenInvalidated(result)) { + log.info("鐢ㄦ埛 {} 鐨 OpenList Token 澶辨晥锛堝搷搴斾綋 code=401锛夛紝寮哄埗鍒锋柊骞堕噸璇", userId); + token = refreshToken(userId); + + // 楠岃瘉鏂拌幏鍙栫殑 Token 鏄惁鏈夋晥 + log.info("鐢ㄦ埛 {} 鏂 Token: {}", userId, token != null ? token.substring(0, Math.min(20, token.length())) + "..." : "null"); + + headers.set("Authorization", token); + entity = new HttpEntity<>(requestBody, headers); + + try { + ResponseEntity retryResponse = restTemplate.postForEntity(url, entity, Map.class); + result = retryResponse.getBody(); + + // 妫鏌ラ噸璇曞悗鐨勭粨鏋滄槸鍚︿粛鐒 Token 澶辨晥 + if (isTokenInvalidated(result)) { + log.error("鐢ㄦ埛 {} Token 鍒锋柊鍚庨噸璇曚粛鐒惰繑鍥 code=401锛屾柊 Token 鏃犳晥锛", userId); + throw new RuntimeException("OpenList Token 鍒锋柊鍚庝粛鐒跺け鏁堬紝璇锋鏌ョ敤鎴峰悕鍜屽瘑鐮佹槸鍚︽纭"); + } + + log.info("鐢ㄦ埛 {} Token 鍒锋柊鍚庨噸璇曟垚鍔", userId); + } catch (org.springframework.web.client.HttpClientErrorException e) { + log.error("鐢ㄦ埛 {} Token 鍒锋柊鍚庨噸璇 HTTP 閿欒: {}", userId, e.getStatusCode(), e); + throw new RuntimeException("OpenList API 璋冪敤澶辫触锛堥噸璇曞悗锛: HTTP " + e.getStatusCode() + " - " + e.getMessage(), e); + } catch (Exception retryEx) { + log.error("鐢ㄦ埛 {} Token 鍒锋柊鍚庨噸璇曚粛鐒跺け璐", userId, retryEx); + throw new RuntimeException("OpenList API 璋冪敤澶辫触锛堥噸璇曞悗锛: " + retryEx.getMessage(), retryEx); + } + } + + // 鏈缁堟鏌ワ細纭繚涓嶄細杩斿洖 Token 澶辨晥鐨勫搷搴 + // 濡傛灉缁忚繃澶氭閲嶈瘯鍚庝粛鐒惰繑鍥 code=401锛岃鏄 Token 鍒锋柊鏈哄埗瀛樺湪闂 + if (isTokenInvalidated(result)) { + log.error("鐢ㄦ埛 {} 缁忚繃澶氭閲嶈瘯鍚庝粛鐒惰繑鍥 Token 澶辨晥锛岃妫鏌 OpenList 鐢ㄦ埛鍚嶅拰瀵嗙爜", userId); + throw new RuntimeException("OpenList Token 鎸佺画澶辨晥锛岃妫鏌ョ敤鎴峰悕鍜屽瘑鐮佹槸鍚︽纭紝鎴 OpenList 鏈嶅姟鏄惁姝e父杩愯"); } return result; } + /** + * 寮哄埗鍒锋柊 Token锛堝拷鐣ョ紦瀛橈紝閲嶆柊鐧诲綍鑾峰彇锛 + * + * @param userId 鐢ㄦ埛ID + * @return 鏂扮殑 JWT Token + */ + private String refreshToken(Long userId) { + UserOpenlist config = getUserOpenlist(userId); + if (config == null) { + throw new RuntimeException("鐢ㄦ埛鏈粦瀹 OpenList"); + } + + log.info("鐢ㄦ埛 {} 寮哄埗鍒锋柊 OpenList Token", userId); + var testResult = testConnection(config.getOpenlistUrl(), config.getOpenlistUsername(), config.getOpenlistPassword()); + if (!(boolean) testResult.get("success")) { + throw new RuntimeException("OpenList Token 鍒锋柊澶辫触锛" + testResult.get("message")); + } + + // 缂撳瓨鏂 Token + String token = (String) testResult.get("token"); + long expireTime = System.currentTimeMillis() + 86400000; // 24 灏忔椂 + userOpenlistRepository.updateToken(userId, token, expireTime); + + return token; + } + /** * 鍒楀嚭鎸囧畾璺緞涓嬬殑鏂囦欢 * @@ -350,55 +499,67 @@ public class OpenListClient { return config != null ? config.getOpenlistUrl() : null; } - // ==================== 瀛樺偍绠$悊 API ==================== + // ==================== 鍚屾鐩稿叧 API ==================== /** - * 鑾峰彇鐢ㄦ埛鐨勬墍鏈夊瓨鍌ㄥ垪琛 - * OpenList 鏀寔澶氫釜瀛樺偍锛坰torage锛夛紝姣忎釜瀛樺偍鏈夌嫭绔嬬殑鎸傝浇璺緞 + * 鑾峰彇鐢ㄦ埛鐨勬墍鏈夊瓨鍌ㄩ┍鍔ㄥ櫒鍒楄〃 + * OpenList 涓殑姣忎釜瀛樺偍锛堝闃块噷浜戠洏銆佺櫨搴︾綉鐩樼瓑锛夐兘鏄竴涓嫭绔嬬殑椹卞姩鍣 + * 娉ㄦ剰锛氭 API 闇瑕佺鐞嗗憳鏉冮檺锛屾櫘閫氱敤鎴疯皟鐢ㄤ細澶辫触 * * @param userId 鐢ㄦ埛ID - * @return 瀛樺偍鍒楄〃锛屾瘡涓瓨鍌ㄥ寘鍚 id銆乵ount_path銆乨river 绛変俊鎭 + * @return 瀛樺偍椹卞姩鍣ㄥ垪琛紝姣忎釜椹卞姩鍣ㄥ寘鍚 id銆乵ount_path銆乨river 绛変俊鎭 + * @throws RuntimeException 褰 API 璋冪敤澶辫触鏃舵姏鍑哄紓甯 */ - public List> listStorages(Long userId) { + public List> getStorageList(Long userId) { UserOpenlist config = getUserOpenlist(userId); if (config == null) { throw new RuntimeException("鐢ㄦ埛鏈粦瀹 OpenList"); } - String url = config.getOpenlistUrl() + "/api/me/storages"; - - try { - String token = getValidToken(userId); - - HttpHeaders headers = new HttpHeaders(); - headers.setBearerAuth(token); - - HttpEntity entity = new HttpEntity<>(headers); - ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, entity, Map.class); - Map result = response.getBody(); - - if (result == null || (int) result.get("code") != 200) { - log.warn("鐢ㄦ埛 {} 鑾峰彇瀛樺偍鍒楄〃澶辫触: {}", userId, result); - return new ArrayList<>(); - } - - @SuppressWarnings("unchecked") - List> storages = (List>) result.get("data"); - if (storages == null) { - return new ArrayList<>(); - } - - log.info("鐢ㄦ埛 {} 鍏辨湁 {} 涓瓨鍌", userId, storages.size()); - return storages; - - } catch (Exception e) { - log.error("鐢ㄦ埛 {} 鑾峰彇瀛樺偍鍒楄〃寮傚父", userId, e); - return new ArrayList<>(); + String url = config.getOpenlistUrl() + "/api/admin/storage/list"; + log.info("鐢ㄦ埛 {} 灏濊瘯鑾峰彇瀛樺偍鍒楄〃锛堥渶瑕佺鐞嗗憳鏉冮檺锛夛紝URL: {}", userId, url); + + Map requestBody = new HashMap<>(); + Map result = postWithRetry(userId, url, requestBody); + + log.info("鐢ㄦ埛 {} 瀛樺偍鍒楄〃 API 鍝嶅簲: {}", userId, result); + + if (result == null) { + throw new RuntimeException("瀛樺偍鍒楄〃 API 鍝嶅簲涓 null"); } + + Object codeObj = result.get("code"); + int code = codeObj != null ? (int) codeObj : -1; + if (code != 200) { + String message = result.get("message") != null ? result.get("message").toString() : "鏈煡閿欒"; + throw new RuntimeException("瀛樺偍鍒楄〃 API 杩斿洖閿欒: code=" + code + ", message=" + message); + } + + Object dataObj = result.get("data"); + log.info("鐢ㄦ埛 {} 瀛樺偍鍒楄〃 data 绫诲瀷: {}, 鍐呭: {}", + userId, + dataObj != null ? dataObj.getClass().getSimpleName() : "null", + dataObj != null ? dataObj.toString() : "null"); + + if (dataObj == null) { + throw new RuntimeException("瀛樺偍鍒楄〃 data 涓虹┖"); + } + + @SuppressWarnings("unchecked") + List> storages = (List>) dataObj; + log.info("鐢ㄦ埛 {} 鍏辨湁 {} 涓瓨鍌ㄩ┍鍔ㄥ櫒", userId, storages.size()); + + // 鎵撳嵃姣忎釜瀛樺偍鐨勮缁嗕俊鎭 + for (int i = 0; i < storages.size(); i++) { + var storage = storages.get(i); + log.info("瀛樺偍 {}: id={}, mount_path={}, driver={}, status={}", + i, storage.get("id"), storage.get("mount_path"), + storage.get("driver"), storage.get("status")); + } + + return storages; } - // ==================== 鍚屾鐩稿叧 API ==================== - /** * 鑾峰彇鎸囧畾璺緞涓嬬殑鎵鏈夊唴瀹癸紙鑷姩澶勭悊鍒嗛〉锛岃繑鍥炲叏閮ㄧ粨鏋滐級 * 鐢ㄤ簬鍚屾鍦烘櫙锛岄渶瑕佽幏鍙栫洰褰曚笅鎵鏈夋枃浠跺拰鏂囦欢澶 @@ -406,6 +567,7 @@ public class OpenListClient { * @param userId 鐢ㄦ埛ID * @param path OpenList 璺緞锛屽 / 鎴 /movies * @return 鍐呭鍒楄〃锛堝寘鍚枃浠跺拰鏂囦欢澶逛俊鎭級 + * @throws RuntimeException 褰 API 璋冪敤澶辫触鏃舵姏鍑哄紓甯 */ public List> listAll(Long userId, String path) { UserOpenlist config = getUserOpenlist(userId); @@ -424,29 +586,46 @@ public class OpenListClient { requestBody.put("path", path); requestBody.put("page", page); requestBody.put("per_page", perPage); - requestBody.put("refresh", false); + log.info("鐢ㄦ埛 {} 璇锋眰鍒楀嚭璺緞 {} 绗 {} 椤碉紝鍙傛暟: {}", userId, path, page, requestBody); Map result = postWithRetry(userId, url, requestBody); - if (result == null || (int) result.get("code") != 200) { - log.warn("鐢ㄦ埛 {} 鍒楀嚭璺緞 {} 绗 {} 椤靛け璐: {}", userId, path, page, result); - break; + if (result == null) { + throw new RuntimeException("鍒楀嚭璺緞 " + path + " 澶辫触: API 鍝嶅簲涓 null"); } - Map data = (Map) result.get("data"); - if (data == null) break; + Object codeObj = result.get("code"); + int code = codeObj != null ? (int) codeObj : -1; + if (code != 200) { + String message = result.get("message") != null ? result.get("message").toString() : "鏈煡閿欒"; + throw new RuntimeException("鍒楀嚭璺緞 " + path + " 澶辫触: code=" + code + ", message=" + message); + } - Map content = (Map) data.get("content"); - if (content == null) break; + Object dataObj = result.get("data"); + log.info("鐢ㄦ埛 {} 璺緞 {} 绗 {} 椤靛搷搴 data 绫诲瀷: {}, 鍐呭: {}", + userId, path, page, + dataObj != null ? dataObj.getClass().getSimpleName() : "null", + dataObj != null ? dataObj.toString().substring(0, Math.min(500, dataObj.toString().length())) : "null"); + if (dataObj == null) { + throw new RuntimeException("鍒楀嚭璺緞 " + path + " 澶辫触: data 涓 null"); + } + + Map data = (Map) dataObj; + + // data.content 鏄枃浠/鏂囦欢澶规暟缁勶紝data.total 鏄绘暟 @SuppressWarnings("unchecked") - List> items = (List>) content.get("content"); - if (items == null || items.isEmpty()) break; + List> items = (List>) data.get("content"); + if (items == null || items.isEmpty()) { + log.info("鐢ㄦ埛 {} 璺緞 {} 绗 {} 椤 content 涓虹┖锛堢洰褰曞彲鑳戒负绌猴級", userId, path, page); + break; + } allContent.addAll(items); // 鍒ゆ柇鏄惁杩樻湁涓嬩竴椤 - int total = (int) content.getOrDefault("total", 0); + int total = (int) data.getOrDefault("total", 0); + log.info("鐢ㄦ埛 {} 璺緞 {} 绗 {} 椤佃幏鍙 {} 椤癸紝鎬昏 {} 椤", userId, path, page, items.size(), total); if (page * perPage >= total) { break; } diff --git a/wangpan-common/target/classes/com/wangpan/common/config/MybatisPlusConfig.class b/wangpan-common/target/classes/com/wangpan/common/config/MybatisPlusConfig.class new file mode 100644 index 0000000..e592b25 Binary files /dev/null and b/wangpan-common/target/classes/com/wangpan/common/config/MybatisPlusConfig.class differ diff --git a/wangpan-common/target/classes/com/wangpan/common/dal/dataobject/DriveDO.class b/wangpan-common/target/classes/com/wangpan/common/dal/dataobject/DriveDO.class index e69fd50..5a53cb2 100644 Binary files a/wangpan-common/target/classes/com/wangpan/common/dal/dataobject/DriveDO.class and b/wangpan-common/target/classes/com/wangpan/common/dal/dataobject/DriveDO.class differ diff --git a/wangpan-common/target/classes/com/wangpan/common/dal/mapper/DriveMapper.class b/wangpan-common/target/classes/com/wangpan/common/dal/mapper/DriveMapper.class index 9f34a30..4ad7d54 100644 Binary files a/wangpan-common/target/classes/com/wangpan/common/dal/mapper/DriveMapper.class and b/wangpan-common/target/classes/com/wangpan/common/dal/mapper/DriveMapper.class differ diff --git a/wangpan-common/target/classes/com/wangpan/common/dal/repository/DriveRepository.class b/wangpan-common/target/classes/com/wangpan/common/dal/repository/DriveRepository.class index e4eec7d..1909c6a 100644 Binary files a/wangpan-common/target/classes/com/wangpan/common/dal/repository/DriveRepository.class and b/wangpan-common/target/classes/com/wangpan/common/dal/repository/DriveRepository.class differ diff --git a/wangpan-common/target/classes/com/wangpan/common/dal/repository/UserRepository.class b/wangpan-common/target/classes/com/wangpan/common/dal/repository/UserRepository.class index 40c40d3..d6621ea 100644 Binary files a/wangpan-common/target/classes/com/wangpan/common/dal/repository/UserRepository.class and b/wangpan-common/target/classes/com/wangpan/common/dal/repository/UserRepository.class differ diff --git a/wangpan-common/target/classes/com/wangpan/common/entity/Drive.class b/wangpan-common/target/classes/com/wangpan/common/entity/Drive.class index c0e8edd..88f369d 100644 Binary files a/wangpan-common/target/classes/com/wangpan/common/entity/Drive.class and b/wangpan-common/target/classes/com/wangpan/common/entity/Drive.class differ diff --git a/wangpan-common/target/classes/com/wangpan/common/util/MinioUtil.class b/wangpan-common/target/classes/com/wangpan/common/util/MinioUtil.class index bb548ba..beedf75 100644 Binary files a/wangpan-common/target/classes/com/wangpan/common/util/MinioUtil.class and b/wangpan-common/target/classes/com/wangpan/common/util/MinioUtil.class differ diff --git a/wangpan-common/target/classes/com/wangpan/common/util/OpenListClient.class b/wangpan-common/target/classes/com/wangpan/common/util/OpenListClient.class index 52ce95e..0dc4096 100644 Binary files a/wangpan-common/target/classes/com/wangpan/common/util/OpenListClient.class and b/wangpan-common/target/classes/com/wangpan/common/util/OpenListClient.class differ diff --git a/wangpan-common/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/wangpan-common/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index bde4de2..465b310 100644 --- a/wangpan-common/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/wangpan-common/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -32,6 +32,7 @@ com\wangpan\common\util\AuthUtil.class com\wangpan\common\dal\dataobject\TmdbScraperLogDO.class com\wangpan\common\entity\UserOpenlist.class com\wangpan\common\dal\dataobject\TokenDO.class +com\wangpan\common\config\MybatisPlusConfig.class com\wangpan\common\dal\mapper\UserMapper.class com\wangpan\common\dal\dataobject\IconDO.class com\wangpan\common\dal\mapper\LoginLogMapper.class diff --git a/wangpan-common/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/wangpan-common/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index d3c433d..70433e8 100644 --- a/wangpan-common/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/wangpan-common/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -22,6 +22,7 @@ D:\java2\wangpan\java\wangpan-common\src\main\java\com\wangpan\common\dal\mapper D:\java2\wangpan\java\wangpan-common\src\main\java\com\wangpan\common\entity\UserOpenlist.java D:\java2\wangpan\java\wangpan-common\src\main\java\com\wangpan\common\Result.java D:\java2\wangpan\java\wangpan-common\src\main\java\com\wangpan\common\dal\repository\TmdbScraperLogRepository.java +D:\java2\wangpan\java\wangpan-common\src\main\java\com\wangpan\common\config\MybatisPlusConfig.java D:\java2\wangpan\java\wangpan-common\src\main\java\com\wangpan\common\dal\repository\DailyRecommendRepository.java D:\java2\wangpan\java\wangpan-common\src\main\java\com\wangpan\common\dal\dataobject\MovieDO.java D:\java2\wangpan\java\wangpan-common\src\main\java\com\wangpan\common\dal\dataobject\TmdbCacheDO.java diff --git a/wangpan-common/target/wangpan-common-1.0-SNAPSHOT.jar b/wangpan-common/target/wangpan-common-1.0-SNAPSHOT.jar index e042de5..158218c 100644 Binary files a/wangpan-common/target/wangpan-common-1.0-SNAPSHOT.jar and b/wangpan-common/target/wangpan-common-1.0-SNAPSHOT.jar differ diff --git a/wangpan-drive-service/src/main/java/com/wangpan/config/DatabaseInitializer.java b/wangpan-drive-service/src/main/java/com/wangpan/config/DatabaseInitializer.java index e3592b9..ff05515 100644 --- a/wangpan-drive-service/src/main/java/com/wangpan/config/DatabaseInitializer.java +++ b/wangpan-drive-service/src/main/java/com/wangpan/config/DatabaseInitializer.java @@ -136,6 +136,14 @@ public class DatabaseInitializer { SchemaUtil.ensureColumnExists(conn, "wp_user_openlist", "heartbeat_error", "VARCHAR(500) DEFAULT NULL COMMENT '蹇冭烦妫娴嬪け璐ュ師鍥'"); + // 妫鏌 wp_drive 琛ㄦ槸鍚︽湁 logo_last_access_time 瀛楁锛圠ogo 鏈鍚庤闂椂闂达級 + SchemaUtil.ensureColumnExists(conn, "wp_drive", "logo_last_access_time", + "DATETIME DEFAULT NULL COMMENT 'Logo鏈鍚庤闂椂闂达紙鐢ㄤ簬鍥炴敹绛栫暐锛'"); + + // 妫鏌 wp_drive 琛ㄦ槸鍚︽湁 logo_status 瀛楁锛圠ogo 鐘舵侊級 + SchemaUtil.ensureColumnExists(conn, "wp_drive", "logo_status", + "VARCHAR(20) NOT NULL DEFAULT 'normal' COMMENT 'Logo鐘舵侊細normal锛堟甯革級/recycling锛堝洖鏀朵腑锛/deleted锛堝凡鍒犻櫎锛'"); + // 绉婚櫎宸插簾寮冪殑 icon 鍒楋紙宸茶 logo_url 鏇夸唬锛 try (var checkStmt = conn.createStatement(); var checkRs = checkStmt.executeQuery("SHOW COLUMNS FROM wp_drive LIKE 'icon'")) { diff --git a/wangpan-drive-service/src/main/java/com/wangpan/controller/DriveController.java b/wangpan-drive-service/src/main/java/com/wangpan/controller/DriveController.java index e928450..ae1fbe5 100644 --- a/wangpan-drive-service/src/main/java/com/wangpan/controller/DriveController.java +++ b/wangpan-drive-service/src/main/java/com/wangpan/controller/DriveController.java @@ -87,6 +87,9 @@ public class DriveController { try { String logoUrl = uploadDriveLogo(logoData); drive.setLogoUrl(logoUrl); + // 璁剧疆 Logo 鍒濆鐘舵佷负 normal锛屽苟璁板綍棣栨璁块棶鏃堕棿 + drive.setLogoStatus("normal"); + drive.setLogoLastAccessTime(java.time.LocalDateTime.now()); } catch (Exception e) { log.error("Logo涓婁紶澶辫触", e); return Result.error("鍒涘缓缃戠洏澶辫触锛歀ogo鍥剧墖涓婁紶澶辫触"); @@ -117,6 +120,15 @@ public class DriveController { var list = driveRepository.queryByUserId(user.getId(), pageNo, pageSize); var total = driveRepository.countByUserId(user.getId()); + // 鏇存柊鎵鏈夋湁 Logo 鐨勭綉鐩樼殑鏈鍚庤闂椂闂达紙瑙﹀彂鍥炴敹绛栫暐閲嶇疆锛 + for (var driveMap : list) { + Long driveId = (Long) driveMap.get("id"); + String logoUrl = (String) driveMap.get("logoUrl"); + if (logoUrl != null && !logoUrl.isBlank()) { + driveRepository.updateLogoAccessTime(driveId); + } + } + var result = new LinkedHashMap(); result.put("list", list); result.put("total", total); @@ -139,6 +151,11 @@ public class DriveController { return Result.error("鏌ヨ澶辫触锛氱綉鐩樹笉瀛樺湪鎴栨棤鏉冭闂"); } + // 鏇存柊 Logo 鏈鍚庤闂椂闂达紙瑙﹀彂鍥炴敹绛栫暐閲嶇疆锛 + if (drive.getLogoUrl() != null && !drive.getLogoUrl().isBlank()) { + driveRepository.updateLogoAccessTime(id); + } + return Result.success("鏌ヨ鎴愬姛", driveToMap(drive)); } @@ -170,6 +187,8 @@ public class DriveController { if (logoData != null && !logoData.isBlank()) { try { logoUrl = uploadDriveLogo(logoData); + // 鏇存柊 Logo 鏃堕噸缃姸鎬佷负 normal锛屽苟鍒锋柊璁块棶鏃堕棿 + driveRepository.updateLogoAccessTime(id); } catch (Exception e) { log.error("Logo鏇存柊澶辫触", e); return Result.error("鏇存柊缃戠洏澶辫触锛歀ogo鍥剧墖涓婁紶澶辫触"); @@ -696,6 +715,8 @@ public class DriveController { map.put("name", drive.getName()); map.put("description", drive.getDescription()); map.put("logoUrl", drive.getLogoUrl()); + map.put("logoStatus", drive.getLogoStatus()); + map.put("logoLastAccessTime", drive.getLogoLastAccessTime() != null ? drive.getLogoLastAccessTime().toString() : null); map.put("folderCount", drive.getFolderCount()); map.put("fileCount", drive.getFileCount()); map.put("totalSize", drive.getTotalSize()); diff --git a/wangpan-drive-service/src/main/java/com/wangpan/controller/OpenListController.java b/wangpan-drive-service/src/main/java/com/wangpan/controller/OpenListController.java index d7482a3..e5e7661 100644 --- a/wangpan-drive-service/src/main/java/com/wangpan/controller/OpenListController.java +++ b/wangpan-drive-service/src/main/java/com/wangpan/controller/OpenListController.java @@ -2,6 +2,7 @@ package com.wangpan.controller; import com.wangpan.common.Result; import com.wangpan.common.annotation.RequireAuth; +import com.wangpan.common.dal.repository.UserOpenlistRepository; import com.wangpan.common.entity.User; import com.wangpan.common.entity.UserOpenlist; import com.wangpan.common.interceptor.AuthInterceptor; @@ -46,6 +47,9 @@ public class OpenListController { @Autowired private OpenListSyncService openListSyncService; + @Autowired + private UserOpenlistRepository userOpenlistRepository; + /** * 浠庤姹傚睘鎬т腑鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛锛堢敱 AuthInterceptor 娉ㄥ叆锛 */ @@ -256,16 +260,35 @@ public class OpenListController { return Result.success(null); } - // 瀹為檯娴嬭瘯 OpenList 杩炴帴锛岄獙璇佽处鍙峰瘑鐮佹槸鍚︿粛鐒跺彲鐢 + // 妫鏌ュ綋鍓 Token 鏄惁鏈夋晥锛屽鏋滄湁鏁堝氨涓嶉噸鏂扮櫥褰 + // 閬垮厤姣忔鏌ョ湅 info 閮界櫥褰 OpenList锛屽鑷翠箣鍓嶇殑 Token 琚綔搴 + // OpenList 鏄"鏈鍚庣櫥褰曟湁鏁"妯″紡锛屾瘡娆$櫥褰曚細浣挎棫 Token 澶辨晥 UserOpenlist config = openListClient.getUserOpenlist(user.getId()); if (config != null) { - var testResult = openListClient.testConnection( - config.getOpenlistUrl(), - config.getOpenlistUsername(), - config.getOpenlistPassword() - ); - info.put("connected", testResult.get("success")); - info.put("connectMessage", testResult.get("message")); + if (config.isTokenValid()) { + // Token 缂撳瓨浠嶇劧鏈夋晥锛屼笉闇瑕侀噸鏂扮櫥褰 + info.put("connected", true); + info.put("connectMessage", "杩炴帴姝e父"); + log.info("鐢ㄦ埛 {} 鐨 OpenList Token 缂撳瓨鏈夋晥锛屾棤闇閲嶆柊鐧诲綍", user.getId()); + } else { + // Token 宸茶繃鏈熸垨涓嶅瓨鍦紝闇瑕侀噸鏂扮櫥褰曢獙璇 + var testResult = openListClient.testConnection( + config.getOpenlistUrl(), + config.getOpenlistUsername(), + config.getOpenlistPassword() + ); + boolean connected = (boolean) testResult.get("success"); + info.put("connected", connected); + info.put("connectMessage", testResult.get("message")); + + // 濡傛灉杩炴帴鎴愬姛锛屽皢鏂拌幏鍙栫殑 token 淇濆瓨鍒版暟鎹簱 + if (connected && testResult.get("token") != null) { + String newToken = (String) testResult.get("token"); + long expireTime = System.currentTimeMillis() + 86400000; // 24 灏忔椂 + userOpenlistRepository.updateToken(user.getId(), newToken, expireTime); + log.info("鐢ㄦ埛 {} 鐨 OpenList Token 宸叉洿鏂板埌鏁版嵁搴", user.getId()); + } + } } else { info.put("connected", false); info.put("connectMessage", "鏈壘鍒拌繛鎺ラ厤缃"); @@ -306,12 +329,25 @@ public class OpenListController { } log.info("鐢ㄦ埛 {} 鎵嬪姩瑙﹀彂 OpenList 鍚屾", user.getId()); + + // 鍦ㄥ悓姝ュ墠寮哄埗鍒锋柊 Token锛岀‘淇濅娇鐢ㄧ殑鏄渶鏂版湁鏁堢殑 Token + // 閬垮厤鍥犱负 info 鎺ュ彛鐧诲綍鍚 Token 琚洿鏂帮紝浣 sync 鎺ュ彛浣跨敤鐨勬槸鏃 Token + boolean tokenRefreshed = openListClient.refreshAndVerifyToken(user.getId()); + if (!tokenRefreshed) { + return Result.error("鍚屾澶辫触锛氭棤娉曞埛鏂 OpenList Token锛岃妫鏌ョ敤鎴峰悕鍜屽瘑鐮"); + } + var syncResult = openListSyncService.syncFromOpenList(user.getId()); + // 鏍规嵁鏄惁鏈夐敊璇繑鍥炰笉鍚岀殑缁撴灉 if (syncResult.errors.isEmpty()) { + // 鍚屾瀹屽叏鎴愬姛 return Result.success("鍚屾瀹屾垚", syncResult.toMap()); } else { - return Result.success("鍚屾瀹屾垚锛堥儴鍒嗗け璐ワ級", syncResult.toMap()); + // 鍚屾澶辫触锛屽皢閿欒淇℃伅鎷兼帴鍦 message 涓繑鍥 + String errorDetails = String.join("; ", syncResult.errors); + String message = "鍚屾澶辫触: " + errorDetails; + return Result.error(message); } } } diff --git a/wangpan-drive-service/src/main/java/com/wangpan/listener/LogoRecycleScheduler.java b/wangpan-drive-service/src/main/java/com/wangpan/listener/LogoRecycleScheduler.java new file mode 100644 index 0000000..45e148b --- /dev/null +++ b/wangpan-drive-service/src/main/java/com/wangpan/listener/LogoRecycleScheduler.java @@ -0,0 +1,180 @@ +package com.wangpan.listener; + +import com.wangpan.common.dal.dataobject.DriveDO; +import com.wangpan.common.dal.repository.DriveRepository; +import com.wangpan.common.util.MinioUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; + +/** + * Logo 鍥炴敹瀹氭椂浠诲姟 + * + * 鍥炴敹绛栫暐锛 + * 1. 瓒呰繃 30 澶╂病鏈夎闂殑 Logo 杩涘叆鍥炴敹妯″紡锛坮ecycling锛 + * 2. 鍥炴敹妯″紡涓 7 澶╁唴璁块棶涓娆″垯鎭㈠姝e父妯″紡锛坣ormal锛夊苟閲嶆柊璁℃椂 30 澶 + * 3. 鍚﹀垯灏嗙洿鎺ヤ粠 MinIO 涓垹闄 + */ +@Component +public class LogoRecycleScheduler { + + private static final Logger log = LoggerFactory.getLogger(LogoRecycleScheduler.class); + + /** 姝e父妯″紡锛30 澶╂湭璁块棶杩涘叆鍥炴敹 */ + private static final int NORMAL_MODE_DAYS = 30; + + /** 鍥炴敹妯″紡锛7 澶╂湭璁块棶鍒欏垹闄 */ + private static final int RECYCLE_MODE_DAYS = 7; + + @Autowired + private DriveRepository driveRepository; + + /** + * 姣忓ぉ鍑屾櫒 2 鐐规墽琛屽洖鏀舵鏌 + */ + @Scheduled(cron = "0 0 2 * * ?") + public void checkAndRecycleLogos() { + log.info("========== Logo 鍥炴敹妫鏌ュ紑濮 =========="); + + try { + // 妫鏌ユ甯告ā寮忕殑 Logo锛岃秴杩 30 澶╂湭璁块棶鍒欒繘鍏ュ洖鏀舵ā寮 + checkNormalModeLogos(); + + // 妫鏌ュ洖鏀舵ā寮忕殑 Logo锛岃秴杩 7 澶╂湭璁块棶鍒欏垹闄 + checkRecycleModeLogos(); + + } catch (Exception e) { + log.error("Logo 鍥炴敹妫鏌ュけ璐", e); + } + + log.info("========== Logo 鍥炴敹妫鏌ュ畬鎴 =========="); + } + + /** + * 妫鏌ユ甯告ā寮忕殑 Logo + * 瓒呰繃 30 澶╂湭璁块棶鍒欒繘鍏ュ洖鏀舵ā寮 + */ + private void checkNormalModeLogos() { + var drives = driveRepository.findDrivesWithLogoNormal(); + log.info("妫鏌ユ甯告ā寮 Logo锛氬叡 {} 涓", drives.size()); + + int recycledCount = 0; + LocalDateTime now = LocalDateTime.now(); + + for (var drive : drives) { + if (drive.getLogoLastAccessTime() == null) { + // 浠庢湭璁板綍璁块棶鏃堕棿锛屼娇鐢ㄥ垱寤烘椂闂 + if (drive.getCreateTime() != null) { + long daysSinceCreation = ChronoUnit.DAYS.between(drive.getCreateTime(), now); + if (daysSinceCreation >= NORMAL_MODE_DAYS) { + // 杩涘叆鍥炴敹妯″紡 + driveRepository.updateLogoStatusToRecycling(drive.getId()); + log.info("缃戠洏 {} 鐨 Logo 杩涘叆鍥炴敹妯″紡锛堝垱寤鸿秴杩 {} 澶╂湭璁块棶锛", drive.getId(), daysSinceCreation); + recycledCount++; + } + } + } else { + long daysSinceLastAccess = ChronoUnit.DAYS.between(drive.getLogoLastAccessTime(), now); + if (daysSinceLastAccess >= NORMAL_MODE_DAYS) { + // 杩涘叆鍥炴敹妯″紡 + driveRepository.updateLogoStatusToRecycling(drive.getId()); + log.info("缃戠洏 {} 鐨 Logo 杩涘叆鍥炴敹妯″紡锛坽} 澶╂湭璁块棶锛", drive.getId(), daysSinceLastAccess); + recycledCount++; + } + } + } + + log.info("姝e父妯″紡妫鏌ュ畬鎴愶細{} 涓 Logo 杩涘叆鍥炴敹妯″紡", recycledCount); + } + + /** + * 妫鏌ュ洖鏀舵ā寮忕殑 Logo + * 瓒呰繃 7 澶╂湭璁块棶鍒欎粠 MinIO 鍒犻櫎 + */ + private void checkRecycleModeLogos() { + var drives = driveRepository.findDrivesWithLogoRecycling(); + log.info("妫鏌ュ洖鏀舵ā寮 Logo锛氬叡 {} 涓", drives.size()); + + int deletedCount = 0; + LocalDateTime now = LocalDateTime.now(); + + for (var drive : drives) { + if (drive.getLogoLastAccessTime() != null) { + long daysSinceLastAccess = ChronoUnit.DAYS.between(drive.getLogoLastAccessTime(), now); + if (daysSinceLastAccess >= RECYCLE_MODE_DAYS) { + // 浠 MinIO 鍒犻櫎 Logo + deleteLogoFromMinIO(drive); + deletedCount++; + } + } else { + // 鍥炴敹妯″紡涓嬫病鏈夎闂椂闂磋褰曪紝鐩存帴鍒犻櫎 + deleteLogoFromMinIO(drive); + deletedCount++; + } + } + + log.info("鍥炴敹妯″紡妫鏌ュ畬鎴愶細{} 涓 Logo 琚垹闄", deletedCount); + } + + /** + * 浠 MinIO 鍒犻櫎 Logo 骞舵洿鏂版暟鎹簱鐘舵 + */ + private void deleteLogoFromMinIO(DriveDO drive) { + String logoUrl = drive.getLogoUrl(); + if (logoUrl == null || logoUrl.isBlank()) { + driveRepository.deleteLogo(drive.getId()); + return; + } + + try { + // 浠 URL 涓彁鍙 objectName + // URL 鏍煎紡锛歨ttp://endpoint/bucket/objectName + String objectName = extractObjectNameFromUrl(logoUrl); + + if (objectName != null && !objectName.isBlank()) { + // 璋冪敤 MinIO 鍒犻櫎鏂囦欢 + boolean deleted = MinioUtil.deleteFile(objectName); + if (deleted) { + log.info("MinIO 鏂囦欢鍒犻櫎鎴愬姛锛歿}", objectName); + } else { + log.warn("MinIO 鏂囦欢鍒犻櫎澶辫触锛歿}", objectName); + } + } + + // 鏇存柊鏁版嵁搴撶姸鎬 + driveRepository.deleteLogo(drive.getId()); + log.info("缃戠洏 {} 鐨 Logo 宸插垹闄", drive.getId()); + + } catch (Exception e) { + log.error("鍒犻櫎缃戠洏 {} 鐨 Logo 澶辫触", drive.getId(), e); + } + } + + /** + * 浠 MinIO URL 涓彁鍙 objectName + * 渚嬪锛歨ttp://minio.example.com/bucket/path/to/file.jpg -> path/to/file.jpg + */ + private String extractObjectNameFromUrl(String url) { + try { + // 绠鍗曡В鏋愶細鎵惧埌绗笁涓 / 涔嬪悗鐨勯儴鍒 + int firstSlash = url.indexOf("://"); + if (firstSlash == -1) return null; + + int secondSlash = url.indexOf("/", firstSlash + 3); + if (secondSlash == -1) return null; + + int thirdSlash = url.indexOf("/", secondSlash + 1); + if (thirdSlash == -1) return null; + + return url.substring(thirdSlash + 1); + } catch (Exception e) { + log.error("瑙f瀽 MinIO URL 澶辫触锛歿}", url, e); + return null; + } + } +} diff --git a/wangpan-drive-service/src/main/java/com/wangpan/listener/OpenListHeartbeatScheduler.java b/wangpan-drive-service/src/main/java/com/wangpan/listener/OpenListHeartbeatScheduler.java index c944a09..59df561 100644 --- a/wangpan-drive-service/src/main/java/com/wangpan/listener/OpenListHeartbeatScheduler.java +++ b/wangpan-drive-service/src/main/java/com/wangpan/listener/OpenListHeartbeatScheduler.java @@ -58,7 +58,16 @@ public class OpenListHeartbeatScheduler { for (UserOpenlist config : configs) { Long userId = config.getUserId(); try { - // 璋冪敤 OpenList 鐧诲綍鎺ュ彛楠岃瘉杩炴帴 + // 蹇冭烦妫娴嬶細濡傛灉 Token 浠嶇劧鏈夋晥锛岃鏄庤繛鎺ユ甯革紝涓嶉渶瑕侀噸鏂扮櫥褰 + // 閬垮厤蹇冭烦鐧诲綍瀵艰嚧姝e湪浣跨敤鐨 Token 琚綔搴 + if (config.isTokenValid()) { + userOpenlistRepository.updateHeartbeat(userId, "success", null); + successCount++; + log.info("鐢ㄦ埛 {} OpenList 蹇冭烦妫娴嬫垚鍔燂紙Token 缂撳瓨鏈夋晥锛: {}", userId, config.getOpenlistUrl()); + continue; + } + + // Token 宸茶繃鏈燂紝闇瑕侀噸鏂扮櫥褰曢獙璇佽繛鎺 Map testResult = openListClient.testConnection( config.getOpenlistUrl(), config.getOpenlistUsername(), diff --git a/wangpan-drive-service/src/main/java/com/wangpan/service/OpenListSyncService.java b/wangpan-drive-service/src/main/java/com/wangpan/service/OpenListSyncService.java index a622e6c..d5bdfdc 100644 --- a/wangpan-drive-service/src/main/java/com/wangpan/service/OpenListSyncService.java +++ b/wangpan-drive-service/src/main/java/com/wangpan/service/OpenListSyncService.java @@ -77,7 +77,7 @@ public class OpenListSyncService { /** * 鎵ц鍏ㄩ噺鍚屾 - * 浠 OpenList 鏍圭洰褰曞紑濮嬶紝閫掑綊閬嶅巻骞跺悓姝ュ埌鏈湴鏁版嵁搴 + * 浠 OpenList 鏍圭洰褰曞垪鍑烘墍鏈夋枃浠跺す锛屾瘡涓枃浠跺す浣滀负涓涓嫭绔嬬殑缃戠洏 * * @param userId 鐢ㄦ埛ID * @return 鍚屾缁撴灉缁熻 @@ -94,55 +94,139 @@ public class OpenListSyncService { log.info("鐢ㄦ埛 {} 寮濮嬩粠 OpenList 鍚屾: {}", userId, config.getOpenlistUrl()); - // 2. 鑾峰彇 OpenList 鐨勬墍鏈夊瓨鍌 - List> storages = openListClient.listStorages(userId); - if (storages.isEmpty()) { - log.warn("鐢ㄦ埛 {} 鐨 OpenList 娌℃湁鍙敤瀛樺偍锛屽皾璇曚粠鏍圭洰褰曞悓姝", userId); - // 闄嶇骇澶勭悊锛氫粠鏍圭洰褰曞悓姝ワ紝鍒涘缓鍗曚釜 Drive - Drive drive = findOrCreateDrive(userId, config, null, null); - if (drive == null) { - result.errors.add("鍒涘缓缃戠洏澶辫触"); - return result; - } - result.driveCount = 1; - syncDirectory(userId, drive.getId(), "/", 0L, 0, result); - updateDriveStats(drive.getId(), userId); + // 2. 鐩存帴浠庢牴鐩綍鍒楀嚭鎵鏈夋枃浠跺す锛堜笉鍐嶄娇鐢ㄩ渶瑕佺鐞嗗憳鏉冮檺鐨勫瓨鍌ˋPI锛 + log.info("鐢ㄦ埛 {} 灏濊瘯浠庢牴鐩綍鍒楀嚭鎵鏈夊唴瀹", userId); + return syncFromRootDirectory(userId, config, result); + } + + /** + * 浠庢牴鐩綍鍒楄〃璇嗗埆瀛樺偍骞跺悓姝 + * 鍒楀嚭 OpenList 鏍圭洰褰曚笅鐨勬墍鏈夋枃浠跺す锛屾瘡涓枃浠跺す浣滀负涓涓嫭绔嬬殑缃戠洏 + */ + private SyncResult syncFromRootDirectory(Long userId, UserOpenlist config, SyncResult result) { + List> rootItems; + try { + log.info("鐢ㄦ埛 {} 寮濮嬪垪鍑 OpenList 鏍圭洰褰曞唴瀹", userId); + rootItems = openListClient.listAll(userId, "/"); + } catch (Exception e) { + log.error("鐢ㄦ埛 {} 鍒楀嚭 OpenList 鏍圭洰褰曞け璐", userId, e); + result.errors.add("鍒楀嚭 OpenList 鏍圭洰褰曞け璐: " + e.getMessage()); return result; } - log.info("鐢ㄦ埛 {} 鐨 OpenList 鍏辨湁 {} 涓瓨鍌", userId, storages.size()); + if (rootItems.isEmpty()) { + result.errors.add("OpenList 鏍圭洰褰曚负绌猴紝璇锋鏌 OpenList 鏄惁宸叉坊鍔犲瓨鍌"); + return result; + } - // 3. 涓烘瘡涓瓨鍌ㄥ垱寤烘垨鏌ユ壘瀵瑰簲鐨 Drive锛屽苟鍚屾鍐呭 - for (Map storage : storages) { - String storageId = String.valueOf(storage.get("id")); - String mountPath = (String) storage.get("mount_path"); - String driver = (String) storage.get("driver"); + log.info("鐢ㄦ埛 {} 鐨 OpenList 鏍圭洰褰曟湁 {} 涓」鐩", userId, rootItems.size()); - log.info("鐢ㄦ埛 {} 鍚屾瀛樺偍: id={}, mountPath={}, driver={}", userId, storageId, mountPath, driver); + // 鍒嗙瀛樺偍锛堟枃浠跺す锛夊拰鏂囦欢 + List> storages = new ArrayList<>(); + List> rootFiles = new ArrayList<>(); - // 鏌ユ壘鎴栧垱寤鸿瀛樺偍瀵瑰簲鐨 Drive - Drive drive = findOrCreateDrive(userId, config, storageId, mountPath); + for (var item : rootItems) { + Object isDirObj = item.get("is_dir"); + boolean isDir = false; + if (isDirObj instanceof Boolean) { + isDir = (Boolean) isDirObj; + } else if (isDirObj instanceof Integer) { + isDir = ((Integer) isDirObj) == 1; + } else if (isDirObj instanceof String) { + isDir = "true".equalsIgnoreCase((String) isDirObj) || "1".equals(isDirObj); + } + + if (isDir) { + storages.add(item); + } else { + rootFiles.add(item); + } + } + + log.info("鐢ㄦ埛 {} 鐨 OpenList 鏍圭洰褰曟湁 {} 涓枃浠跺す锛寋} 涓枃浠", + userId, storages.size(), rootFiles.size()); + + // 涓烘瘡涓枃浠跺す鍒涘缓缃戠洏 + for (var storage : storages) { + String storageName = (String) storage.get("name"); + String storagePath = "/" + storageName; + + Drive drive = findOrCreateDriveForStorage(userId, config, storageName, storagePath); if (drive == null) { - result.errors.add("鍒涘缓瀛樺偍 " + mountPath + " 鐨勭綉鐩樺け璐"); + result.errors.add("鍒涘缓瀛樺偍 " + storageName + " 鐨勭綉鐩樺け璐"); continue; } result.driveCount++; - // 浠庤瀛樺偍鐨勬寕杞借矾寰勫紑濮嬪悓姝 - String rootPath = mountPath != null ? mountPath : "/"; - syncDirectory(userId, drive.getId(), rootPath, 0L, 0, result); - - // 鏇存柊璇ョ綉鐩樼殑缁熻淇℃伅 + syncDirectory(userId, drive.getId(), storagePath, 0L, 0, result); updateDriveStats(drive.getId(), userId); } - log.info("鐢ㄦ埛 {} 鍚屾瀹屾垚: 缃戠洏={}, 鏂囦欢澶={}, 鐢靛奖={}, 璺宠繃鏂囦欢={}, 璺宠繃鏂囦欢澶={}, 閿欒={}", - userId, result.driveCount, result.folderCount, result.movieCount, - result.skippedFileCount, result.skippedFolderCount, result.errors.size()); + // 澶勭悊鏍圭洰褰曟枃浠 + if (!rootFiles.isEmpty()) { + Drive defaultDrive = findOrCreateDrive(userId, config); + if (defaultDrive != null) { + result.driveCount++; + syncRootFiles(userId, defaultDrive.getId(), rootFiles, result); + updateDriveStats(defaultDrive.getId(), userId); + } + } return result; } + /** + * 涓烘寚瀹氬瓨鍌ㄥ垱寤烘垨鏌ユ壘缃戠洏 + */ + private Drive findOrCreateDriveForStorage(Long userId, UserOpenlist config, String storageName, String storagePath) { + // 鏌ヨ鐢ㄦ埛鎵鏈夌綉鐩橈紝鏌ユ壘鍖归厤璇ュ瓨鍌ㄨ矾寰勭殑 + var drives = driveRepository.queryByUserId(userId, 1, 100); + for (var driveMap : drives) { + String mountPath = (String) driveMap.get("openlistMountPath"); + if (storagePath.equals(mountPath)) { + log.info("澶嶇敤宸叉湁缃戠洏: id={}, mountPath={}", driveMap.get("id"), mountPath); + return driveRepository.findById(((Number) driveMap.get("id")).longValue()); + } + } + + // 鍒涘缓鏂扮綉鐩 + Drive drive = new Drive(userId, storageName, "浠 OpenList 鍚屾鐨勭綉鐩: " + storagePath); + drive.setOpenlistMountPath(storagePath); + Long driveId = driveRepository.insert(drive); + drive.setId(driveId); + log.info("鍒涘缓鏂扮綉鐩: id={}, name={}, mountPath={}", driveId, storageName, storagePath); + return drive; + } + + /** + * 鍚屾鏍圭洰褰曠殑鏂囦欢锛堜笉灞炰簬浠讳綍瀛樺偍鐨勬枃浠讹級 + */ + private void syncRootFiles(Long userId, Long driveId, List> rootFiles, SyncResult result) { + for (var fileItem : rootFiles) { + String fileName = (String) fileItem.get("name"); + if (isVideoFile(fileName)) { + long fileSize = ((Number) fileItem.getOrDefault("size", 0L)).longValue(); + String extension = getFileExtension(fileName); + String openlistFilePath = "/" + fileName; + + DriveMovie movie = new DriveMovie(driveId, 0L, userId, + getMovieTitle(fileName), fileName); + movie.setFileSize(fileSize); + movie.setExtension(extension); + movie.setMimeType("video/" + extension); + movie.setOpenlistFilePath(openlistFilePath); + movie.setStorageType("openlist"); + movie.setScrapeType("none"); + movie.setScrapeStatus("pending"); + + movieRepository.insert(movie); + result.movieCount++; + } else { + result.skippedFileCount++; + } + } + } + /** * 鏇存柊缃戠洏缁熻淇℃伅 */ @@ -154,34 +238,30 @@ public class OpenListSyncService { /** * 鏌ユ壘鎴栧垱寤哄叧鑱旂綉鐩 - * 鏍规嵁 storageId 鏌ユ壘宸叉湁鐨 Drive锛屽鏋滄病鏈夊垯鍒涘缓鏂扮殑 + * 鏌ユ壘鐢ㄦ埛宸叉湁鐨 OpenList 缃戠洏锛屽鏋滄病鏈夊垯鍒涘缓鏂扮殑 * - * @param userId 鐢ㄦ埛ID - * @param config OpenList 閰嶇疆 - * @param storageId OpenList 瀛樺偍ID锛堝彲涓 null锛 - * @param mountPath 鎸傝浇璺緞锛堝彲涓 null锛 + * @param userId 鐢ㄦ埛ID + * @param config OpenList 閰嶇疆 * @return Drive 瀵硅薄 */ - private Drive findOrCreateDrive(Long userId, UserOpenlist config, String storageId, String mountPath) { - // 鏌ヨ鐢ㄦ埛鎵鏈夌綉鐩橈紝鏌ユ壘鍖归厤 storageId 鐨 + private Drive findOrCreateDrive(Long userId, UserOpenlist config) { + // 鏌ヨ鐢ㄦ埛鎵鏈夌綉鐩橈紝鏌ユ壘宸插叧鑱旂綉鐩樼殑 var drives = driveRepository.queryByUserId(userId, 1, 100); for (var driveMap : drives) { - String existingStorageId = (String) driveMap.get("openlistStorageId"); - if (storageId != null && storageId.equals(existingStorageId)) { + String mountPath = (String) driveMap.get("openlistMountPath"); + if (mountPath != null && !mountPath.isBlank()) { // 澶嶇敤宸叉湁缃戠洏 - log.info("澶嶇敤宸叉湁缃戠洏: id={}, storageId={}", driveMap.get("id"), storageId); + log.info("澶嶇敤宸叉湁缃戠洏: id={}", driveMap.get("id")); return driveRepository.findById(((Number) driveMap.get("id")).longValue()); } } // 鍒涘缓鏂扮綉鐩 - String driveName = mountPath != null ? "OpenList: " + mountPath : "OpenList 缃戠洏"; - Drive drive = new Drive(userId, driveName, "浠 OpenList 鍚屾鐨勭綉鐩"); - drive.setOpenlistStorageId(storageId); - drive.setOpenlistMountPath(mountPath != null ? mountPath : "/"); + Drive drive = new Drive(userId, "OpenList 缃戠洏", "浠 OpenList 鍚屾鐨勭綉鐩"); + drive.setOpenlistMountPath(config.getMountPath() != null ? config.getMountPath() : "/"); Long driveId = driveRepository.insert(drive); drive.setId(driveId); - log.info("鍒涘缓鏂扮綉鐩: id={}, storageId={}, mountPath={}", driveId, storageId, mountPath); + log.info("鍒涘缓鏂扮綉鐩: id={}", driveId); return drive; } @@ -200,9 +280,17 @@ public class OpenListSyncService { try { // 鑾峰彇鐩綍涓嬫墍鏈夊唴瀹 List> items = openListClient.listAll(userId, openlistPath); + log.info("鐢ㄦ埛 {} 璺緞 {} 鑾峰彇鍒 {} 涓唴瀹归」", userId, openlistPath, items.size()); if (items.isEmpty()) { + log.warn("鐢ㄦ埛 {} 璺緞 {} 涓虹┖锛岃烦杩囧悓姝", userId, openlistPath); return; } + + // 鎵撳嵃鍓嶅嚑涓」鐩敤浜庤皟璇 + for (int i = 0; i < Math.min(3, items.size()); i++) { + var item = items.get(i); + log.info("椤圭洰 {}: name={}, is_dir={}, type={}", i, item.get("name"), item.get("is_dir"), item.get("type")); + } // 鍒嗙鏂囦欢澶瑰拰瑙嗛鏂囦欢 List> folders = new ArrayList<>(); @@ -210,7 +298,17 @@ public class OpenListSyncService { for (var item : items) { String name = (String) item.get("name"); - boolean isDir = (boolean) item.getOrDefault("is_dir", false); + + // 澶勭悊 is_dir 瀛楁鍙兘鏄 Boolean銆両nteger 鎴 String 绫诲瀷 + Object isDirObj = item.get("is_dir"); + boolean isDir = false; + if (isDirObj instanceof Boolean) { + isDir = (Boolean) isDirObj; + } else if (isDirObj instanceof Integer) { + isDir = ((Integer) isDirObj) == 1; + } else if (isDirObj instanceof String) { + isDir = "true".equalsIgnoreCase((String) isDirObj) || "1".equals(isDirObj); + } if (isDir) { folders.add(item); diff --git a/wangpan-drive-service/target/classes/com/wangpan/DriveServiceApplication.class b/wangpan-drive-service/target/classes/com/wangpan/DriveServiceApplication.class index f9220bf..150b657 100644 Binary files a/wangpan-drive-service/target/classes/com/wangpan/DriveServiceApplication.class and b/wangpan-drive-service/target/classes/com/wangpan/DriveServiceApplication.class differ diff --git a/wangpan-drive-service/target/classes/com/wangpan/config/DatabaseInitializer.class b/wangpan-drive-service/target/classes/com/wangpan/config/DatabaseInitializer.class index a2b23d1..8d7d43e 100644 Binary files a/wangpan-drive-service/target/classes/com/wangpan/config/DatabaseInitializer.class and b/wangpan-drive-service/target/classes/com/wangpan/config/DatabaseInitializer.class differ diff --git a/wangpan-drive-service/target/classes/com/wangpan/controller/DriveController.class b/wangpan-drive-service/target/classes/com/wangpan/controller/DriveController.class index 8b003ca..8605985 100644 Binary files a/wangpan-drive-service/target/classes/com/wangpan/controller/DriveController.class and b/wangpan-drive-service/target/classes/com/wangpan/controller/DriveController.class differ diff --git a/wangpan-drive-service/target/classes/com/wangpan/controller/IconController.class b/wangpan-drive-service/target/classes/com/wangpan/controller/IconController.class index 4ddbb15..8f228ab 100644 Binary files a/wangpan-drive-service/target/classes/com/wangpan/controller/IconController.class and b/wangpan-drive-service/target/classes/com/wangpan/controller/IconController.class differ diff --git a/wangpan-drive-service/target/classes/com/wangpan/controller/OpenListController.class b/wangpan-drive-service/target/classes/com/wangpan/controller/OpenListController.class index c11cfa2..2c733be 100644 Binary files a/wangpan-drive-service/target/classes/com/wangpan/controller/OpenListController.class and b/wangpan-drive-service/target/classes/com/wangpan/controller/OpenListController.class differ diff --git a/wangpan-drive-service/target/classes/com/wangpan/listener/IconCleanupScheduler$CleanupTask.class b/wangpan-drive-service/target/classes/com/wangpan/listener/IconCleanupScheduler$CleanupTask.class index 560f717..f4b2a68 100644 Binary files a/wangpan-drive-service/target/classes/com/wangpan/listener/IconCleanupScheduler$CleanupTask.class and b/wangpan-drive-service/target/classes/com/wangpan/listener/IconCleanupScheduler$CleanupTask.class differ diff --git a/wangpan-drive-service/target/classes/com/wangpan/listener/IconCleanupScheduler.class b/wangpan-drive-service/target/classes/com/wangpan/listener/IconCleanupScheduler.class index cba3a4b..b32368d 100644 Binary files a/wangpan-drive-service/target/classes/com/wangpan/listener/IconCleanupScheduler.class and b/wangpan-drive-service/target/classes/com/wangpan/listener/IconCleanupScheduler.class differ diff --git a/wangpan-drive-service/target/classes/com/wangpan/listener/LogoRecycleScheduler.class b/wangpan-drive-service/target/classes/com/wangpan/listener/LogoRecycleScheduler.class new file mode 100644 index 0000000..936358b Binary files /dev/null and b/wangpan-drive-service/target/classes/com/wangpan/listener/LogoRecycleScheduler.class differ diff --git a/wangpan-drive-service/target/classes/com/wangpan/listener/OpenListHeartbeatScheduler.class b/wangpan-drive-service/target/classes/com/wangpan/listener/OpenListHeartbeatScheduler.class index d6d74f6..659ace1 100644 Binary files a/wangpan-drive-service/target/classes/com/wangpan/listener/OpenListHeartbeatScheduler.class and b/wangpan-drive-service/target/classes/com/wangpan/listener/OpenListHeartbeatScheduler.class differ diff --git a/wangpan-drive-service/target/classes/com/wangpan/service/OpenListSyncService$SyncResult.class b/wangpan-drive-service/target/classes/com/wangpan/service/OpenListSyncService$SyncResult.class index 417f02f..46d5a73 100644 Binary files a/wangpan-drive-service/target/classes/com/wangpan/service/OpenListSyncService$SyncResult.class and b/wangpan-drive-service/target/classes/com/wangpan/service/OpenListSyncService$SyncResult.class differ diff --git a/wangpan-drive-service/target/classes/com/wangpan/service/OpenListSyncService.class b/wangpan-drive-service/target/classes/com/wangpan/service/OpenListSyncService.class index f84331a..745ae9a 100644 Binary files a/wangpan-drive-service/target/classes/com/wangpan/service/OpenListSyncService.class and b/wangpan-drive-service/target/classes/com/wangpan/service/OpenListSyncService.class differ diff --git a/wangpan-drive-service/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/wangpan-drive-service/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index 41db8e9..dde7c42 100644 --- a/wangpan-drive-service/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/wangpan-drive-service/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -7,4 +7,5 @@ com\wangpan\controller\OpenListController.class com\wangpan\controller\DriveController.class com\wangpan\DriveServiceApplication.class com\wangpan\listener\IconCleanupScheduler$CleanupTask.class +com\wangpan\listener\LogoRecycleScheduler.class com\wangpan\listener\OpenListHeartbeatScheduler.class diff --git a/wangpan-drive-service/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/wangpan-drive-service/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index 5b9fd04..4245703 100644 --- a/wangpan-drive-service/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/wangpan-drive-service/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -6,3 +6,4 @@ D:\java2\wangpan\java\wangpan-drive-service\src\main\java\com\wangpan\service\Op D:\java2\wangpan\java\wangpan-drive-service\src\main\java\com\wangpan\controller\IconController.java D:\java2\wangpan\java\wangpan-drive-service\src\main\java\com\wangpan\controller\OpenListController.java D:\java2\wangpan\java\wangpan-drive-service\src\main\java\com\wangpan\listener\OpenListHeartbeatScheduler.java +D:\java2\wangpan\java\wangpan-drive-service\src\main\java\com\wangpan\listener\LogoRecycleScheduler.java diff --git a/wangpan-drive-service/target/wangpan-drive-service-1.0-SNAPSHOT.jar b/wangpan-drive-service/target/wangpan-drive-service-1.0-SNAPSHOT.jar index 320b071..8077078 100644 Binary files a/wangpan-drive-service/target/wangpan-drive-service-1.0-SNAPSHOT.jar and b/wangpan-drive-service/target/wangpan-drive-service-1.0-SNAPSHOT.jar differ diff --git a/wangpan-drive-service/target/wangpan-drive-service-1.0-SNAPSHOT.jar.original b/wangpan-drive-service/target/wangpan-drive-service-1.0-SNAPSHOT.jar.original index b6e31e1..5582ae3 100644 Binary files a/wangpan-drive-service/target/wangpan-drive-service-1.0-SNAPSHOT.jar.original and b/wangpan-drive-service/target/wangpan-drive-service-1.0-SNAPSHOT.jar.original differ diff --git a/wangpan-gateway/target/wangpan-gateway-1.0-SNAPSHOT.jar b/wangpan-gateway/target/wangpan-gateway-1.0-SNAPSHOT.jar index 6e705a4..a9af629 100644 Binary files a/wangpan-gateway/target/wangpan-gateway-1.0-SNAPSHOT.jar and b/wangpan-gateway/target/wangpan-gateway-1.0-SNAPSHOT.jar differ diff --git a/wangpan-gateway/target/wangpan-gateway-1.0-SNAPSHOT.jar.original b/wangpan-gateway/target/wangpan-gateway-1.0-SNAPSHOT.jar.original index b0cedf8..b7e9bfe 100644 Binary files a/wangpan-gateway/target/wangpan-gateway-1.0-SNAPSHOT.jar.original and b/wangpan-gateway/target/wangpan-gateway-1.0-SNAPSHOT.jar.original differ diff --git a/wangpan-tmdb-service/target/wangpan-tmdb-service-1.0-SNAPSHOT.jar b/wangpan-tmdb-service/target/wangpan-tmdb-service-1.0-SNAPSHOT.jar index 44dcefb..e535fc2 100644 Binary files a/wangpan-tmdb-service/target/wangpan-tmdb-service-1.0-SNAPSHOT.jar and b/wangpan-tmdb-service/target/wangpan-tmdb-service-1.0-SNAPSHOT.jar differ diff --git a/wangpan-tmdb-service/target/wangpan-tmdb-service-1.0-SNAPSHOT.jar.original b/wangpan-tmdb-service/target/wangpan-tmdb-service-1.0-SNAPSHOT.jar.original index f2049fa..d004e02 100644 Binary files a/wangpan-tmdb-service/target/wangpan-tmdb-service-1.0-SNAPSHOT.jar.original and b/wangpan-tmdb-service/target/wangpan-tmdb-service-1.0-SNAPSHOT.jar.original differ diff --git a/wangpan-user-service/src/main/java/com/wangpan/controller/UserController.java b/wangpan-user-service/src/main/java/com/wangpan/controller/UserController.java index 009a343..906be29 100644 --- a/wangpan-user-service/src/main/java/com/wangpan/controller/UserController.java +++ b/wangpan-user-service/src/main/java/com/wangpan/controller/UserController.java @@ -75,8 +75,10 @@ public class UserController { Map data = userRepository.queryUsers(username, status, userType, pageNo, pageSize); return Result.success("鏌ヨ鎴愬姛", data); } catch (Exception e) { - log.error("鏌ヨ鐢ㄦ埛鍒楄〃澶辫触", e); - return Result.error("绯荤粺绻佸繖锛岃绋嶅悗閲嶈瘯"); + // 鏃ュ織甯︿笂鏌ヨ鏉′欢锛屼究浜庡畾浣嶆槸鍝鏌ヨ瑙﹀彂鐨勫紓甯 + log.error("鏌ヨ鐢ㄦ埛鍒楄〃澶辫触 | username={} status={} userType={} page={}", + username, status, userType, pageNo, e); + return Result.error(500, "绯荤粺绻佸繖锛岃绋嶅悗閲嶈瘯"); } } @@ -94,13 +96,14 @@ public class UserController { User currentUser = getCurrentUser(request); log.info("绠$悊鍛 [{}] 鏂板鐢ㄦ埛", currentUser.getUsername()); + // 鎻愬彇鐢ㄦ埛鍚/瀵嗙爜渚 catch 鍧楁棩蹇椾娇鐢 + String username = (String) body.get("username"); + String password = (String) body.get("password"); + try { // 1. 鍙傛暟鎻愬彇涓庢牎楠 - String username = (String) body.get("username"); - String password = (String) body.get("password"); - if (username == null || username.isBlank() || password == null || password.isBlank()) { - return Result.error(400, "鐢ㄦ埛鍚嶅拰瀵嗙爜涓嶈兘涓虹┖"); + return Result.badRequest("鐢ㄦ埛鍚嶅拰瀵嗙爜涓嶈兘涓虹┖"); } // 2. 妫鏌ョ敤鎴峰悕鏄惁宸插瓨鍦 @@ -116,7 +119,7 @@ public class UserController { newUser.setEmail((String) body.get("email")); newUser.setPhone((String) body.get("phone")); newUser.setRealName((String) body.get("realName")); - + // 鍙夊瓧娈碉細鐘舵佸拰瑙掕壊锛堥粯璁ゆ櫘閫氱敤鎴凤級 if (body.containsKey("status") && body.get("status") != null) { newUser.setStatus(Integer.parseInt(body.get("status").toString())); @@ -129,13 +132,22 @@ public class UserController { newUser.setUserType(0); } + // 璁剧疆鏁版嵁搴 NOT NULL 瀛楁鐨勯粯璁ゅ + newUser.setFailCount(0); + newUser.setIsDeleted(0); + // 4. 鎻掑叆鏁版嵁搴 userRepository.insert(newUser); return Result.success("鐢ㄦ埛鍒涘缓鎴愬姛", null); + } catch (NumberFormatException e) { + // status/userType 浼犱簡闈炴暟瀛楀硷紝灞炰簬瀹㈡埛绔弬鏁版牸寮忛敊璇紝杩斿洖 400 鑰岄潪 500 + log.warn("鏂板鐢ㄦ埛鍙傛暟鏍煎紡閿欒 | username={} err={}", username, e.getMessage()); + return Result.badRequest("鍙傛暟鏍煎紡閿欒锛歴tatus/userType 蹇呴』涓烘暣鏁"); } catch (Exception e) { - log.error("鏂板鐢ㄦ埛澶辫触", e); - return Result.error("绯荤粺绻佸繖锛岃绋嶅悗閲嶈瘯"); + // 鏈煡绯荤粺寮傚父锛氭棩蹇楄褰曞畬鏁村爢鏍堬紙鍚敤鎴峰悕渚夸簬杩芥函锛夛紝瀵瑰杩斿洖绗肩粺鎻愮ず + log.error("鏂板鐢ㄦ埛澶辫触 | username={}", username, e); + return Result.error(500, "绯荤粺绻佸繖锛岃绋嶅悗閲嶈瘯"); } } @@ -159,7 +171,7 @@ public class UserController { // 1. 妫鏌ョ洰鏍囩敤鎴锋槸鍚﹀瓨鍦 User targetUser = userRepository.findById(userId); if (targetUser == null) { - return Result.error(404, "鐩爣鐢ㄦ埛涓嶅瓨鍦"); + return Result.notFound("鐩爣鐢ㄦ埛涓嶅瓨鍦"); } // 2. 鎻愬彇鍙夊弬鏁帮紙鍙鐞嗘槑纭紶鍏ョ殑瀛楁锛 @@ -177,12 +189,16 @@ public class UserController { if (rows > 0) { return Result.success("鐢ㄦ埛淇℃伅鏇存柊鎴愬姛", null); } else { - return Result.error(400, "娌℃湁闇瑕佹洿鏂扮殑瀛楁"); + return Result.badRequest("娌℃湁闇瑕佹洿鏂扮殑瀛楁"); } + } catch (NumberFormatException e) { + // status/userType 浼犱簡闈炴暟瀛楀硷紝灞炰簬瀹㈡埛绔弬鏁版牸寮忛敊璇 + log.warn("淇敼鐢ㄦ埛鍙傛暟鏍煎紡閿欒 | userId={} err={}", userId, e.getMessage()); + return Result.badRequest("鍙傛暟鏍煎紡閿欒锛歴tatus/userType 蹇呴』涓烘暣鏁"); } catch (Exception e) { - log.error("淇敼鐢ㄦ埛澶辫触", e); - return Result.error("绯荤粺绻佸繖锛岃绋嶅悗閲嶈瘯"); + log.error("淇敼鐢ㄦ埛澶辫触 | userId={}", userId, e); + return Result.error(500, "绯荤粺绻佸繖锛岃绋嶅悗閲嶈瘯"); } } @@ -204,7 +220,7 @@ public class UserController { // 1. 妫鏌ョ洰鏍囩敤鎴锋槸鍚﹀瓨鍦 User targetUser = userRepository.findById(userId); if (targetUser == null) { - return Result.error(404, "鐩爣鐢ㄦ埛涓嶅瓨鍦"); + return Result.notFound("鐩爣鐢ㄦ埛涓嶅瓨鍦"); } // 2. 鎵ц杞垹闄 @@ -213,12 +229,12 @@ public class UserController { if (rows > 0) { return Result.success("鐢ㄦ埛宸插垹闄", null); } else { - return Result.error(400, "鍒犻櫎澶辫触锛岀敤鎴峰彲鑳藉凡琚垹闄"); + return Result.badRequest("鍒犻櫎澶辫触锛岀敤鎴峰彲鑳藉凡琚垹闄"); } } catch (Exception e) { - log.error("鍒犻櫎鐢ㄦ埛澶辫触", e); - return Result.error("绯荤粺绻佸繖锛岃绋嶅悗閲嶈瘯"); + log.error("鍒犻櫎鐢ㄦ埛澶辫触 | userId={}", userId, e); + return Result.error(500, "绯荤粺绻佸繖锛岃绋嶅悗閲嶈瘯"); } } } \ No newline at end of file diff --git a/wangpan-user-service/target/classes/com/wangpan/controller/UserController.class b/wangpan-user-service/target/classes/com/wangpan/controller/UserController.class index 9379979..1c6a014 100644 Binary files a/wangpan-user-service/target/classes/com/wangpan/controller/UserController.class and b/wangpan-user-service/target/classes/com/wangpan/controller/UserController.class differ diff --git a/wangpan-user-service/target/wangpan-user-service-1.0-SNAPSHOT.jar b/wangpan-user-service/target/wangpan-user-service-1.0-SNAPSHOT.jar index 8dfc8cb..0898de7 100644 Binary files a/wangpan-user-service/target/wangpan-user-service-1.0-SNAPSHOT.jar and b/wangpan-user-service/target/wangpan-user-service-1.0-SNAPSHOT.jar differ diff --git a/wangpan-user-service/target/wangpan-user-service-1.0-SNAPSHOT.jar.original b/wangpan-user-service/target/wangpan-user-service-1.0-SNAPSHOT.jar.original index 32d4a1e..36c9e2a 100644 Binary files a/wangpan-user-service/target/wangpan-user-service-1.0-SNAPSHOT.jar.original and b/wangpan-user-service/target/wangpan-user-service-1.0-SNAPSHOT.jar.original differ