From a73f68e08760b3883d5e68915732849437590043 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Wed, 12 Mar 2025 12:02:07 +0800 Subject: [PATCH 01/62] ocean-docs-file-service dependency upgrade upgrade `org.jodconverter` from 3.x to 4.4.8 --- .idea/compiler.xml | 10 +++---- .idea/jarRepositories.xml | 4 +-- .idea/kotlinc.xml | 9 ++++++ .idea/libraries/jodconverter_core.xml | 12 ++++++++ .idea/libraries/jodconverter_local.xml | 17 +++++++++++ .idea/libraries/jodconverter_local_oo.xml | 18 ++++++++++++ .idea/libraries/jodconverter_spring.xml | 27 ++++++++++++++++++ .../jodconverter_spring_boot_starter.xml | 28 +++++++++++++++++++ .idea/misc.xml | 2 +- .idea/validation.xml | 15 ++++++++++ .../common/vo/OceanExceptionHandler.java | 2 +- ocean-docs-file-service/pom.xml | 11 ++++++++ .../oriole/ocean/utils/OpenOfficeUtils.java | 19 +++++++------ pom.xml | 11 ++++++++ 14 files changed, 166 insertions(+), 19 deletions(-) create mode 100644 .idea/kotlinc.xml create mode 100644 .idea/libraries/jodconverter_core.xml create mode 100644 .idea/libraries/jodconverter_local.xml create mode 100644 .idea/libraries/jodconverter_local_oo.xml create mode 100644 .idea/libraries/jodconverter_spring.xml create mode 100644 .idea/libraries/jodconverter_spring_boot_starter.xml create mode 100644 .idea/validation.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fa317b3..10e6a08 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,8 @@ + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml index d46a6c7..22e83c6 100644 --- a/.idea/jarRepositories.xml +++ b/.idea/jarRepositories.xml @@ -4,12 +4,12 @@ - + \ No newline at end of file diff --git a/.idea/validation.xml b/.idea/validation.xml new file mode 100644 index 0000000..a7b9942 --- /dev/null +++ b/.idea/validation.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/vo/OceanExceptionHandler.java b/ocean-common/src/main/java/com/oriole/ocean/common/vo/OceanExceptionHandler.java index 86fc9d4..f0c2bc9 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/vo/OceanExceptionHandler.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/vo/OceanExceptionHandler.java @@ -7,7 +7,7 @@ import java.util.Arrays; import java.util.Date; -@Slf4j + @Slf4j public class OceanExceptionHandler { @Data diff --git a/ocean-docs-file-service/pom.xml b/ocean-docs-file-service/pom.xml index 2ee87f3..e7aa5fe 100644 --- a/ocean-docs-file-service/pom.xml +++ b/ocean-docs-file-service/pom.xml @@ -148,5 +148,16 @@ org.apache.commons commons-lang3 + + + org.jodconverter + jodconverter-local + 4.4.8 + + + org.jodconverter + jodconverter-core + 4.4.8 + diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/OpenOfficeUtils.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/OpenOfficeUtils.java index 3d35aa4..9fe1022 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/OpenOfficeUtils.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/OpenOfficeUtils.java @@ -1,9 +1,9 @@ package com.oriole.ocean.utils; -import org.jodconverter.OfficeDocumentConverter; -import org.jodconverter.office.DefaultOfficeManagerBuilder; -import org.jodconverter.office.OfficeException; -import org.jodconverter.office.OfficeManager; +import org.jodconverter.local.LocalConverter; +import org.jodconverter.local.office.LocalOfficeManager; +import org.jodconverter.core.office.OfficeException; +import org.jodconverter.core.office.OfficeManager; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -33,13 +33,14 @@ public OpenOfficeUtils(Boolean useOpenOffice) { * @throws OfficeException */ private OfficeManager getOfficeManager() throws OfficeException { - DefaultOfficeManagerBuilder builder = new DefaultOfficeManagerBuilder(); + LocalOfficeManager.Builder builder = LocalOfficeManager.builder(); //此处填写OpenOffice安装路径 if (useOpenOffice) { - builder.setOfficeHome(OPENOFFICE_PATH); + builder.officeHome(OPENOFFICE_PATH); } else { - builder.setOfficeHome(LIBREOFFICE_PATH); + builder.officeHome(LIBREOFFICE_PATH); } + builder.install(); OfficeManager officeManager = builder.build(); //officeManager提供了开启OpenOffice的API服务 officeManager.start(); @@ -57,8 +58,8 @@ public Boolean openOfficeExperience(String path, String fileName, String suffix, //设置转换后的文件存储路径,文件名 //使用OfficeDocumentConverter类转换文件,其实核心就这一句 - OfficeDocumentConverter converter = new OfficeDocumentConverter(manage); - converter.convert(inputTempFile, outputTempFile); + LocalConverter converter = LocalConverter.make(manage); + converter.convert(inputTempFile).to(outputTempFile).execute(); return true; } catch (Exception e) { e.printStackTrace(); diff --git a/pom.xml b/pom.xml index 9d00873..76f770d 100644 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,17 @@ springfox-swagger-ui 2.9.2 + + + org.jodconverter + jodconverter-core + 4.4.8 + + + org.jodconverter + jodconverter-local + 4.4.8 + From 8407da3bd106ba01af7a174e784e83b327450c60 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Mon, 17 Mar 2025 13:15:36 +0800 Subject: [PATCH 02/62] chore: updated to java23 --- .idea/misc.xml | 2 +- ocean-docs-file-service/pom.xml | 4 ++-- ocean-docs-service/pom.xml | 4 ++-- ocean-note-service/pom.xml | 4 ++-- ocean-notify-service/pom.xml | 4 ++-- ocean-user-service/pom.xml | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 24ef09d..c059b1a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -16,7 +16,7 @@ - + \ No newline at end of file diff --git a/ocean-docs-file-service/pom.xml b/ocean-docs-file-service/pom.xml index e7aa5fe..d04c785 100644 --- a/ocean-docs-file-service/pom.xml +++ b/ocean-docs-file-service/pom.xml @@ -63,8 +63,8 @@ - mysql - mysql-connector-java + com.mysql + mysql-connector-j diff --git a/ocean-docs-service/pom.xml b/ocean-docs-service/pom.xml index d39a16e..beb1030 100644 --- a/ocean-docs-service/pom.xml +++ b/ocean-docs-service/pom.xml @@ -67,8 +67,8 @@ - mysql - mysql-connector-java + com.mysql + mysql-connector-j diff --git a/ocean-note-service/pom.xml b/ocean-note-service/pom.xml index bb3fea3..d7540e6 100644 --- a/ocean-note-service/pom.xml +++ b/ocean-note-service/pom.xml @@ -63,8 +63,8 @@ - mysql - mysql-connector-java + com.mysql + mysql-connector-j diff --git a/ocean-notify-service/pom.xml b/ocean-notify-service/pom.xml index 06e461a..da8ffd9 100644 --- a/ocean-notify-service/pom.xml +++ b/ocean-notify-service/pom.xml @@ -63,8 +63,8 @@ - mysql - mysql-connector-java + com.mysql + mysql-connector-j diff --git a/ocean-user-service/pom.xml b/ocean-user-service/pom.xml index b859331..7943437 100644 --- a/ocean-user-service/pom.xml +++ b/ocean-user-service/pom.xml @@ -63,8 +63,8 @@ - mysql - mysql-connector-java + com.mysql + mysql-connector-j From 7eb1c573f6eafbf56bed0b54bc511d74532b4cb0 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Fri, 21 Mar 2025 12:42:22 +0800 Subject: [PATCH 03/62] chore: update all dependencies Bug: can't read configs from nacos (but can register service). --- .idea/compiler.xml | 4 +- .idea/jarRepositories.xml | 5 + .idea/libraries/projectlombok_lombok.xml | 10 + ocean-collection-service/pom.xml | 75 +++++++- .../oriole/ocean/config/Swagger2Config.java | 37 ---- .../oriole/ocean/config/SwaggerConfig.java | 40 ++++ .../controller/UserCollectionController.java | 6 +- .../service/UserCollectionServiceImpl.java | 2 +- .../src/main/resources/bootstrap.yaml | 1 + .../src/test/java/com/oriole/AppTest.java | 30 +-- ocean-comment-service/pom.xml | 58 +++++- .../oriole/ocean/config/Swagger2Config.java | 37 ---- .../oriole/ocean/config/SwaggerConfig.java | 40 ++++ .../controller/UserCommentController.java | 32 ++-- .../ocean/service/CommentServiceImpl.java | 2 +- .../src/main/resources/bootstrap.yaml | 1 + .../src/test/java/com/oriole/AppTest.java | 30 +-- ocean-common/pom.xml | 21 ++- .../auth/AuthUserMethodArgumentResolver.java | 2 +- .../ocean/common/enumerate/ResultCode.java | 1 - .../common/po/mongo/UserBehaviorEntity.java | 2 +- .../po/mongo/comment/CommentEntity.java | 2 + .../po/mongo/comment/CommentReplyEntity.java | 2 + .../ocean/common/po/mysql/UserEntity.java | 6 +- .../common/service/UserBehaviorService.java | 1 - .../oriole/ocean/common/tools/JwtUtils.java | 31 ++-- .../ocean/common/vo/BusinessException.java | 15 +- ocean-docs-file-service/pom.xml | 81 +++++++- .../ocean/controller/DocIOController.java | 2 +- .../utils/objectStorage/AliOSSUtils.java | 2 +- .../objectStorage/ObjectStorageUtils.java | 2 +- .../src/main/resources/bootstrap.yaml | 1 + .../src/test/java/com/oriole/AppTest.java | 30 +-- ocean-docs-service/pom.xml | 70 ++++++- .../controller/DocFunctionController.java | 2 +- .../ocean/service/ESearchServiceImpl.java | 2 +- .../oriole/ocean/service/FileServiceImpl.java | 2 +- .../src/test/java/com/oriole/AppTest.java | 30 +-- ocean-gateway/pom.xml | 34 +++- .../gateway/config/WebSecurityConfig.java | 31 ++-- .../filter/UserAuthGatewayFilterFactory.java | 2 +- .../gateway/security/SecurityRepository.java | 2 +- .../oriole/ocean/gateway/tools/JwtUtils.java | 31 ++-- .../src/test/java/com/oriole/AppTest.java | 30 +-- ocean-note-service/pom.xml | 59 +++++- .../src/main/resources/bootstrap.yaml | 1 + .../src/test/java/com/oriole/AppTest.java | 30 +-- ocean-notify-service/pom.xml | 55 +++++- .../ocean/service/UserNotifyServiceImpl.java | 2 +- .../src/main/resources/bootstrap.yaml | 1 + .../src/test/java/com/oriole/AppTest.java | 30 +-- ocean-user-behavior-service/pom.xml | 35 +++- .../service/UserBehaviorServiceImpl.java | 2 +- .../src/main/resources/bootstrap.yaml | 1 + .../src/test/java/com/oriole/AppTest.java | 30 +-- ocean-user-service/pom.xml | 120 ++++++++++-- .../ocean/config/MybatisPlusConfig.java | 9 +- .../UserWalletChangeRecordServiceImpl.java | 2 + .../src/main/resources/bootstrap.yaml | 1 + .../src/test/java/com/oriole/AppTest.java | 30 +-- pom.xml | 173 ++++++++++++++++-- 61 files changed, 938 insertions(+), 490 deletions(-) create mode 100644 .idea/libraries/projectlombok_lombok.xml delete mode 100644 ocean-collection-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java create mode 100644 ocean-collection-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java delete mode 100644 ocean-comment-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java create mode 100644 ocean-comment-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 10e6a08..16a7e3a 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,7 +2,6 @@ + + \ No newline at end of file diff --git a/.idea/libraries/projectlombok_lombok.xml b/.idea/libraries/projectlombok_lombok.xml new file mode 100644 index 0000000..8fe179f --- /dev/null +++ b/.idea/libraries/projectlombok_lombok.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ocean-collection-service/pom.xml b/ocean-collection-service/pom.xml index fefb62e..c235d3d 100644 --- a/ocean-collection-service/pom.xml +++ b/ocean-collection-service/pom.xml @@ -18,6 +18,28 @@ + + + org.projectlombok + lombok + provided + + + + org.slf4j + slf4j-api + + + + org.apache.logging.log4j + log4j-core + + + + org.slf4j + slf4j-reload4j + test + org.springframework.boot @@ -27,6 +49,12 @@ org.springframework.cloud spring-cloud-starter-bootstrap + + + jakarta.servlet + jakarta.servlet-api + provided + com.alibaba.cloud @@ -45,19 +73,34 @@ org.apache.dubbo dubbo-registry-nacos + + org.apache.dubbo.extensions + dubbo-serialization-kryo + + + com.esotericsoftware + kryo + + + de.javakaffee + kryo-serializers + com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - + + + - io.springfox - springfox-swagger2 + io.swagger.core.v3 + swagger-annotations-jakarta + - io.springfox - springfox-swagger-ui + org.springdoc + springdoc-openapi-starter-webmvc-ui @@ -67,10 +110,26 @@ spring-boot-starter-data-mongodb + + + org.junit.jupiter + junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 + test + + - junit - junit - 3.8.1 + org.junit + junit-bom + 5.12.1 + pom test diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java b/ocean-collection-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java deleted file mode 100644 index fa396a9..0000000 --- a/ocean-collection-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.oriole.ocean.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - -@Configuration -@EnableSwagger2 -public class Swagger2Config { - - @Bean - public Docket createRestApi() { - return new Docket(DocumentationType.SWAGGER_12) - .apiInfo(apiInfo()) - .select() - .apis(RequestHandlerSelectors.basePackage("com.oriole.ocean")) - .paths(PathSelectors.any()) - .build(); - } - - private ApiInfo apiInfo() { - return new ApiInfoBuilder() - .title("Lib4Univ 开源高校文库项目 RESTful API列表") - .description("注意不得在生产环境启用Swagger") - .termsOfServiceUrl("http://www.oceanlibrary.cn/") - .contact("基于深度遗忘的程序猿") - .version("2.1") - .build(); - } -} - diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java b/ocean-collection-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java new file mode 100644 index 0000000..b948345 --- /dev/null +++ b/ocean-collection-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java @@ -0,0 +1,40 @@ +package com.oriole.ocean.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import org.springdoc.core.models.GroupedOpenApi; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + + @Bean + public GroupedOpenApi createRestApi() { + return GroupedOpenApi.builder() + .group("wtf") + .packagesToScan("com.oriole.ocean") + .pathsToMatch("/**") + .build(); + } + + @Bean + public OpenAPI openAPI() { + return new OpenAPI() + .info(new Info() + .title("Lib4Univ开源高校文库项目 RESTful API列表") + .description("注意不得在生产环境启用 Swagger") + .version("2.1") + .contact(new Contact() + .name("基于深度遗忘的程序猿") + .url("http://www.oceanlibrary.cn") + .email("null")) + .termsOfService("http://www.oceanlibrary.cn/") + .license(new License() + .name("Apache2.0") + .url("https://www.apache.org/licenses/LICENSE-2.0"))); + } +} + diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java b/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java index 700d2a9..5e0fdbc 100644 --- a/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java +++ b/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java @@ -1,8 +1,8 @@ package com.oriole.ocean.controller; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.oriole.ocean.common.auth.AuthUser; import com.oriole.ocean.common.enumerate.*; import com.oriole.ocean.common.enumerate.MainType; diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java b/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java index 24f35b2..3d216ed 100644 --- a/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java +++ b/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java @@ -1,6 +1,6 @@ package com.oriole.ocean.service; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.oriole.ocean.common.enumerate.DocStatisticItemType; import com.oriole.ocean.common.enumerate.MainType; import com.oriole.ocean.common.po.mysql.UserCollectionEntity; diff --git a/ocean-collection-service/src/main/resources/bootstrap.yaml b/ocean-collection-service/src/main/resources/bootstrap.yaml index 09a2c69..39c89bf 100644 --- a/ocean-collection-service/src/main/resources/bootstrap.yaml +++ b/ocean-collection-service/src/main/resources/bootstrap.yaml @@ -20,5 +20,6 @@ dubbo: group: dubbo protocol: port: -1 + serialization: kryo consumer: check: false diff --git a/ocean-collection-service/src/test/java/com/oriole/AppTest.java b/ocean-collection-service/src/test/java/com/oriole/AppTest.java index 38e2a80..06fc0f9 100644 --- a/ocean-collection-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-collection-service/src/test/java/com/oriole/AppTest.java @@ -1,38 +1,20 @@ package com.oriole; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; /** * Unit test for simple App. */ -public class AppTest - extends TestCase +public class AppTest { - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - /** * Rigourous Test :-) */ + @Test public void testApp() { - assertTrue( true ); + System.out.println("Hello World"); + Assertions.assertTrue( true ); } } diff --git a/ocean-comment-service/pom.xml b/ocean-comment-service/pom.xml index f8cba00..7849610 100644 --- a/ocean-comment-service/pom.xml +++ b/ocean-comment-service/pom.xml @@ -45,19 +45,39 @@ org.apache.dubbo dubbo-registry-nacos + + org.apache.dubbo.extensions + dubbo-serialization-kryo + + + com.esotericsoftware + kryo + + + de.javakaffee + kryo-serializers + com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - + + + + + io.swagger.core.v3 + swagger-annotations-jakarta + + - io.springfox - springfox-swagger2 + org.springdoc + springdoc-openapi-starter-webmvc-ui + - io.springfox - springfox-swagger-ui + org.springframework + spring-webmvc @@ -67,10 +87,27 @@ spring-boot-starter-data-mongodb + + - junit - junit - 3.8.1 + org.junit.jupiter + junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 + test + + + + org.junit + junit-bom + 5.12.1 + pom test @@ -85,5 +122,10 @@ org.apache.commons commons-lang3 + + org.projectlombok + lombok + compile + diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java b/ocean-comment-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java deleted file mode 100644 index fa396a9..0000000 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.oriole.ocean.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - -@Configuration -@EnableSwagger2 -public class Swagger2Config { - - @Bean - public Docket createRestApi() { - return new Docket(DocumentationType.SWAGGER_12) - .apiInfo(apiInfo()) - .select() - .apis(RequestHandlerSelectors.basePackage("com.oriole.ocean")) - .paths(PathSelectors.any()) - .build(); - } - - private ApiInfo apiInfo() { - return new ApiInfoBuilder() - .title("Lib4Univ 开源高校文库项目 RESTful API列表") - .description("注意不得在生产环境启用Swagger") - .termsOfServiceUrl("http://www.oceanlibrary.cn/") - .contact("基于深度遗忘的程序猿") - .version("2.1") - .build(); - } -} - diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java b/ocean-comment-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java new file mode 100644 index 0000000..b948345 --- /dev/null +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java @@ -0,0 +1,40 @@ +package com.oriole.ocean.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import org.springdoc.core.models.GroupedOpenApi; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + + @Bean + public GroupedOpenApi createRestApi() { + return GroupedOpenApi.builder() + .group("wtf") + .packagesToScan("com.oriole.ocean") + .pathsToMatch("/**") + .build(); + } + + @Bean + public OpenAPI openAPI() { + return new OpenAPI() + .info(new Info() + .title("Lib4Univ开源高校文库项目 RESTful API列表") + .description("注意不得在生产环境启用 Swagger") + .version("2.1") + .contact(new Contact() + .name("基于深度遗忘的程序猿") + .url("http://www.oceanlibrary.cn") + .email("null")) + .termsOfService("http://www.oceanlibrary.cn/") + .license(new License() + .name("Apache2.0") + .url("https://www.apache.org/licenses/LICENSE-2.0"))); + } +} + diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index d8ad741..d28bae4 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -12,9 +12,9 @@ import com.oriole.ocean.common.vo.BusinessException; import com.oriole.ocean.common.vo.MsgEntity; import com.oriole.ocean.service.CommentServiceImpl; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; import org.apache.commons.lang3.RandomStringUtils; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; @@ -44,11 +44,11 @@ public class UserCommentController { @DubboReference NotifySubscriptionService notifySubscriptionService; - @ApiOperation(value = "删除评论区评论或回复") - @ApiImplicitParams({ - @ApiImplicitParam(name = "bindID", value = "资源唯一编号", required = true), - @ApiImplicitParam(name = "mainType", value = "主资源类型(文档/纸条)", required = true), - @ApiImplicitParam(name = "commentID", value = "评论唯一编号", required = true) + @Operation(summary = "删除评论区评论或回复") + @Parameters({ + @Parameter(name = "bindID", description = "资源唯一编号", required = true), + @Parameter(name = "mainType", description = "主资源类型(文档/纸条)", required = true), + @Parameter(name = "commentID", description = "评论唯一编号", required = true) }) @RequestMapping(value = "/deleteComment", method = RequestMethod.GET) public MsgEntity deleteComment(@AuthUser AuthUserEntity authUser, @@ -85,7 +85,7 @@ public MsgEntity deleteComment(@AuthUser AuthUserEntity authUser, commentStatusType = CommentStatusType.USER_CLOSURE; } } - if (commentStatusType == null) { // 仍然没有找到合乎清理的删除理由,说明没有权限 + if (commentStatusType == null) { // 仍然没有找到合乎情理的删除理由,说明没有权限 throw new BusinessException("-2", "权限不足,必须为评论发布者或文档发布者"); } //执行删除 @@ -200,13 +200,13 @@ public MsgEntity getCommentReply( return new MsgEntity<>("SUCCESS", "1", commentEntity); } - @ApiOperation(value = "评价一条评论或回复", notes = "isLike参数为评价操作的分类(true表示为点赞操作,false表示为点踩操作),isCancel为是否为取消评价操作。如isLike为false,isCancel为true,则表示取消点踩操作") - @ApiImplicitParams({ - @ApiImplicitParam(name = "bindID", value = "唯一资源编号", required = true), - @ApiImplicitParam(name = "mainType", value = "资源类型", required = true), - @ApiImplicitParam(name = "commentID", value = "评论唯一编号", required = true), - @ApiImplicitParam(name = "isCancel", value = "是否为取消操作", required = true), - @ApiImplicitParam(name = "isLike", value = "是否为点赞操作", required = true) + @Operation(summary = "评价一条评论或回复", description = "isLike参数为评价操作的分类(true表示为点赞操作,false表示为点踩操作),isCancel为是否为取消评价操作。如isLike为false,isCancel为true,则表示取消点踩操作") + @Parameters({ + @Parameter(name = "bindID", description = "唯一资源编号", required = true), + @Parameter(name = "mainType", description = "资源类型", required = true), + @Parameter(name = "commentID", description = "评论唯一编号", required = true), + @Parameter(name = "isCancel", description = "是否为取消操作", required = true), + @Parameter(name = "isLike", description = "是否为点赞操作", required = true) }) @RequestMapping(value = "/evaluateComment", method = RequestMethod.GET) public MsgEntity evaluateComment(@AuthUser AuthUserEntity authUser, diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java b/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java index af84916..9469b69 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java @@ -1,6 +1,6 @@ package com.oriole.ocean.service; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.oriole.ocean.common.enumerate.DocStatisticItemType; import com.oriole.ocean.common.enumerate.EvaluateType; import com.oriole.ocean.common.enumerate.MainType; diff --git a/ocean-comment-service/src/main/resources/bootstrap.yaml b/ocean-comment-service/src/main/resources/bootstrap.yaml index 70aa295..38d2b9c 100644 --- a/ocean-comment-service/src/main/resources/bootstrap.yaml +++ b/ocean-comment-service/src/main/resources/bootstrap.yaml @@ -20,5 +20,6 @@ dubbo: group: dubbo protocol: port: -1 + serialization: kryo consumer: check: false \ No newline at end of file diff --git a/ocean-comment-service/src/test/java/com/oriole/AppTest.java b/ocean-comment-service/src/test/java/com/oriole/AppTest.java index 38e2a80..06fc0f9 100644 --- a/ocean-comment-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-comment-service/src/test/java/com/oriole/AppTest.java @@ -1,38 +1,20 @@ package com.oriole; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; /** * Unit test for simple App. */ -public class AppTest - extends TestCase +public class AppTest { - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - /** * Rigourous Test :-) */ + @Test public void testApp() { - assertTrue( true ); + System.out.println("Hello World"); + Assertions.assertTrue( true ); } } diff --git a/ocean-common/pom.xml b/ocean-common/pom.xml index e23ede0..9657a81 100644 --- a/ocean-common/pom.xml +++ b/ocean-common/pom.xml @@ -23,15 +23,19 @@ spring-boot-starter-web + org.projectlombok lombok + 1.18.36 + provided + com.baomidou mybatis-plus - 3.5.4.1 + 3.5.10.1 @@ -44,21 +48,24 @@ spring-boot-starter-data-mongodb + - com.alibaba - fastjson - 2.0.43 + com.alibaba.fastjson2 + fastjson2 + 2.0.56 + io.jsonwebtoken - jjwt - 0.9.1 + jjwt-api + 0.12.6 + com.auth0 java-jwt - 3.4.0 + 4.5.0 \ No newline at end of file diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/auth/AuthUserMethodArgumentResolver.java b/ocean-common/src/main/java/com/oriole/ocean/common/auth/AuthUserMethodArgumentResolver.java index 553f855..ceafe39 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/auth/AuthUserMethodArgumentResolver.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/auth/AuthUserMethodArgumentResolver.java @@ -1,6 +1,6 @@ package com.oriole.ocean.common.auth; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.oriole.ocean.common.vo.AuthUserEntity; import org.springframework.core.MethodParameter; import org.springframework.http.HttpHeaders; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/enumerate/ResultCode.java b/ocean-common/src/main/java/com/oriole/ocean/common/enumerate/ResultCode.java index 91fbc7a..373b978 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/enumerate/ResultCode.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/enumerate/ResultCode.java @@ -1,6 +1,5 @@ package com.oriole.ocean.common.enumerate; - import lombok.Getter; @Getter diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/UserBehaviorEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/UserBehaviorEntity.java index 6f4d826..08b3d2f 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/UserBehaviorEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/UserBehaviorEntity.java @@ -1,6 +1,6 @@ package com.oriole.ocean.common.po.mongo; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.oriole.ocean.common.enumerate.BehaviorExtraInfo; import com.oriole.ocean.common.enumerate.BehaviorType; import com.oriole.ocean.common.enumerate.MainType; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentEntity.java index 5d26dd1..52cdb11 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentEntity.java @@ -1,10 +1,12 @@ package com.oriole.ocean.common.po.mongo.comment; import lombok.Data; +import lombok.EqualsAndHashCode; import java.util.ArrayList; @Data +@EqualsAndHashCode(callSuper=false) public class CommentEntity extends AbstractComment implements java.io.Serializable { private String commentBuildUsername; private Integer hotValue; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentReplyEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentReplyEntity.java index 66fe4e5..cb36758 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentReplyEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentReplyEntity.java @@ -1,8 +1,10 @@ package com.oriole.ocean.common.po.mongo.comment; import lombok.Data; +import lombok.EqualsAndHashCode; @Data +@EqualsAndHashCode(callSuper=false) public class CommentReplyEntity extends AbstractComment implements java.io.Serializable { private String replyBuildUsername; private String replyToCommentReplier;// 回复另一个回复时必填(被回复的回复者) diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java index 63eece5..69271d5 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java @@ -3,11 +3,13 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; +import lombok.Getter; +import lombok.Setter; import java.util.Date; -@Data +@Getter +@Setter @TableName("user") public class UserEntity implements java.io.Serializable { diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/UserBehaviorService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/UserBehaviorService.java index 533554f..159a483 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/UserBehaviorService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/UserBehaviorService.java @@ -1,6 +1,5 @@ package com.oriole.ocean.common.service; -import com.alibaba.fastjson.JSONObject; import com.oriole.ocean.common.enumerate.BehaviorExtraInfo; import com.oriole.ocean.common.enumerate.EvaluateType; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java b/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java index 04bcb66..3a1258d 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java @@ -6,7 +6,7 @@ import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.security.Keys; import org.apache.commons.codec.binary.Base64; import java.util.Date; @@ -23,7 +23,6 @@ * */ public class JwtUtils { private final String base64EncodedSecretKey; - private final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; public JwtUtils(String secretKey) { this.base64EncodedSecretKey = Base64.encodeBase64String(secretKey.getBytes()); @@ -50,15 +49,15 @@ public String encode(String iss, long ttlMillis, Map claims) { } long nowMillis = System.currentTimeMillis(); JwtBuilder builder = Jwts.builder() - .setClaims(claims) - .setId(UUID.randomUUID().toString())//2. 这个是JWT的唯一标识,一般设置成唯一的,这个方法可以生成唯一标识 - .setIssuedAt(new Date(nowMillis))//1. 这个地方就是以毫秒为单位,换算当前系统时间生成的iat - .setSubject(iss)//3. 签发人,也就是JWT是给谁的(逻辑上一般都是username或者userId) - .signWith(signatureAlgorithm, base64EncodedSecretKey);//这个地方是生成jwt使用的算法和秘钥 + .claims(claims) + .id(UUID.randomUUID().toString())//2. 这个是JWT的唯一标识,一般设置成唯一的,这个方法可以生成唯一标识 + .issuedAt(new Date(nowMillis))//1. 这个地方就是以毫秒为单位,换算当前系统时间生成的iat + .subject(iss)//3. 签发人,也就是JWT是给谁的(逻辑上一般都是username或者userId) + .signWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes()));//这个地方是生成jwt使用的算法和秘钥 if (ttlMillis >= 0) { long expMillis = nowMillis + ttlMillis; Date exp = new Date(expMillis);//4. 过期时间,这个也是使用毫秒生成的,使用当前时间+前面传入的持续时间生成 - builder.setExpiration(exp); + builder.expiration(exp); } return builder.compact(); } @@ -69,22 +68,16 @@ public Claims decode(String jwtToken) { // 得到 DefaultJwtParser return Jwts.parser() // 设置签名的秘钥 - .setSigningKey(base64EncodedSecretKey) + .verifyWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes())) + .build() // 设置需要解析的 jwt - .parseClaimsJws(jwtToken) - .getBody(); + .parseSignedClaims(jwtToken) + .getPayload(); } //判断jwtToken是否合法 public boolean isVerify(String jwtToken) { - Algorithm algorithm; - switch (signatureAlgorithm) { - case HS256: - algorithm = Algorithm.HMAC256(Base64.decodeBase64(base64EncodedSecretKey)); - break; - default: - throw new RuntimeException("not support this algorithm"); - } + Algorithm algorithm = Algorithm.HMAC256(Base64.decodeBase64(base64EncodedSecretKey)); JWTVerifier verifier = JWT.require(algorithm).build(); try { verifier.verify(jwtToken); // 校验不通过会抛出异常 diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java b/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java index 572f0d5..4fd1658 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java @@ -1,7 +1,10 @@ package com.oriole.ocean.common.vo; import com.oriole.ocean.common.enumerate.ResultCode; +import lombok.Getter; +import lombok.Setter; +@Setter public class BusinessException extends RuntimeException { private static final long serialVersionUID = -7480022450501760611L; @@ -9,6 +12,7 @@ public class BusinessException extends RuntimeException { /** * 异常码 */ + @Getter private String code; /** @@ -29,20 +33,9 @@ public BusinessException(String code, String msg) { this.message = msg; } - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - @Override public String getMessage() { return message; } - public void setMessage(String message) { - this.message = message; - } } diff --git a/ocean-docs-file-service/pom.xml b/ocean-docs-file-service/pom.xml index d04c785..8f330c1 100644 --- a/ocean-docs-file-service/pom.xml +++ b/ocean-docs-file-service/pom.xml @@ -18,6 +18,37 @@ + + + jakarta.servlet + jakarta.servlet-api + provided + + + + org.projectlombok + lombok + provided + + + + org.slf4j + slf4j-api + 2.0.17 + + + + org.apache.logging.log4j + log4j-core + 2.24.3 + + + + org.slf4j + slf4j-reload4j + 2.0.17 + test + org.springframework.boot @@ -45,19 +76,34 @@ org.apache.dubbo dubbo-registry-nacos + + org.apache.dubbo.extensions + dubbo-serialization-kryo + + + com.esotericsoftware + kryo + + + de.javakaffee + kryo-serializers + com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - + + + - io.springfox - springfox-swagger2 + io.swagger.core.v3 + swagger-annotations-jakarta + - io.springfox - springfox-swagger-ui + org.springdoc + springdoc-openapi-starter-webmvc-ui @@ -70,7 +116,7 @@ org.mybatis.spring.boot mybatis-spring-boot-starter - 2.1.0 + 3.0.4 @@ -131,10 +177,27 @@ 5.5.13.1 + + + + org.junit.jupiter + junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 + test + + - junit - junit - 3.8.1 + org.junit + junit-bom + 5.12.1 + pom test diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java index 2f4f006..9d0ebcc 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java @@ -30,7 +30,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; import java.io.IOException; diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java index 686e8c1..9e9f350 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java @@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import java.io.BufferedInputStream; import java.io.File; import java.io.InputStream; diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java index 276599a..aa495de 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java @@ -1,6 +1,6 @@ package com.oriole.ocean.utils.objectStorage; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import java.io.InputStream; public interface ObjectStorageUtils { diff --git a/ocean-docs-file-service/src/main/resources/bootstrap.yaml b/ocean-docs-file-service/src/main/resources/bootstrap.yaml index 3d19248..40b7cb4 100644 --- a/ocean-docs-file-service/src/main/resources/bootstrap.yaml +++ b/ocean-docs-file-service/src/main/resources/bootstrap.yaml @@ -20,5 +20,6 @@ dubbo: group: dubbo protocol: port: -1 + serialization: kryo consumer: check: false diff --git a/ocean-docs-file-service/src/test/java/com/oriole/AppTest.java b/ocean-docs-file-service/src/test/java/com/oriole/AppTest.java index 38e2a80..e6782ee 100644 --- a/ocean-docs-file-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-docs-file-service/src/test/java/com/oriole/AppTest.java @@ -1,38 +1,20 @@ package com.oriole; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Unit test for simple App. */ -public class AppTest - extends TestCase +public class AppTest { - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - /** * Rigourous Test :-) */ + @Test public void testApp() { - assertTrue( true ); + System.out.println("Hello World"); + Assertions.assertTrue( true ); } } diff --git a/ocean-docs-service/pom.xml b/ocean-docs-service/pom.xml index beb1030..effcbe5 100644 --- a/ocean-docs-service/pom.xml +++ b/ocean-docs-service/pom.xml @@ -42,6 +42,18 @@ org.apache.dubbo dubbo-registry-nacos + + org.apache.dubbo.extensions + dubbo-serialization-kryo + + + com.esotericsoftware + kryo + + + de.javakaffee + kryo-serializers + com.alibaba.cloud @@ -54,14 +66,22 @@ 1.8.6 - + + + - io.springfox - springfox-swagger2 + io.swagger.core.v3 + swagger-annotations-jakarta + - io.springfox - springfox-swagger-ui + org.springdoc + springdoc-openapi-starter-webmvc-ui + + + + org.springframework + spring-webmvc @@ -74,7 +94,7 @@ org.mybatis.spring.boot mybatis-spring-boot-starter - 2.1.0 + 3.0.4 @@ -105,10 +125,27 @@ + + - junit - junit - 3.8.1 + org.junit.jupiter + junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 + test + + + + org.junit + junit-bom + 5.12.1 + pom test @@ -118,5 +155,20 @@ 1.0-SNAPSHOT compile + + org.projectlombok + lombok + + + + org.elasticsearch + elasticsearch + 8.17.3 + + + org.springframework.data + spring-data-elasticsearch + 4.3.10 + diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java index 9fdcdec..e6fac26 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java @@ -1,6 +1,6 @@ package com.oriole.ocean.controller; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.oriole.ocean.common.enumerate.*; import com.oriole.ocean.common.auth.AuthUser; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java index 793532c..9d9788e 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java @@ -17,7 +17,7 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.stereotype.Service; -import javax.annotation.Resource; +import jakarta.annotation.Resource; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java index e539fc4..4235745 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; +import jakarta.annotation.Resource; import java.util.List; @Service diff --git a/ocean-docs-service/src/test/java/com/oriole/AppTest.java b/ocean-docs-service/src/test/java/com/oriole/AppTest.java index 38e2a80..e6782ee 100644 --- a/ocean-docs-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-docs-service/src/test/java/com/oriole/AppTest.java @@ -1,38 +1,20 @@ package com.oriole; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Unit test for simple App. */ -public class AppTest - extends TestCase +public class AppTest { - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - /** * Rigourous Test :-) */ + @Test public void testApp() { - assertTrue( true ); + System.out.println("Hello World"); + Assertions.assertTrue( true ); } } diff --git a/ocean-gateway/pom.xml b/ocean-gateway/pom.xml index 9cd874d..9bd9156 100644 --- a/ocean-gateway/pom.xml +++ b/ocean-gateway/pom.xml @@ -44,26 +44,48 @@ spring-boot-starter-security + io.jsonwebtoken - jjwt - 0.9.1 + jjwt-api + 0.12.6 + com.auth0 java-jwt - 3.4.0 + 4.5.0 + org.projectlombok lombok + 1.18.36 + provided + + + + org.junit.jupiter + junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 + test + + - junit - junit - 3.8.1 + org.junit + junit-bom + 5.12.1 + pom test diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java index 0363479..cb7513a 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java @@ -6,6 +6,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; +import org.springframework.security.config.Customizer; import org.springframework.security.config.web.server.ServerHttpSecurity; import org.springframework.security.web.server.SecurityWebFilterChain; import org.springframework.web.cors.reactive.CorsConfigurationSource; @@ -56,19 +57,23 @@ public class WebSecurityConfig { public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http .securityContextRepository(securityRepository) - .authorizeExchange() - .pathMatchers(path).permitAll() - .pathMatchers(HttpMethod.OPTIONS).permitAll() - .pathMatchers("/userWalletService/**").hasAnyRole("USER","ADMIN") - .pathMatchers("/userInfoService/**").hasAnyRole("USER","ADMIN") - .pathMatchers("/userFunctionService/**").hasAnyRole("USER","ADMIN") - .anyExchange().authenticated() - .and() - .httpBasic() - .and().exceptionHandling().authenticationEntryPoint(authenticationEntryPoint) - .accessDeniedHandler(accessDeniedHandler) //基于http的接口请求鉴权失败 - .and().cors().configurationSource(corsConfigSource()) - .and().csrf().disable(); //必须支持跨域 + .authorizeExchange(authorize -> authorize + .pathMatchers(path).permitAll() + .pathMatchers(HttpMethod.OPTIONS).permitAll() + .pathMatchers("/userWalletService/**").hasAnyRole("USER","ADMIN") + .pathMatchers("/userInfoService/**").hasAnyRole("USER","ADMIN") + .pathMatchers("/userFunctionService/**").hasAnyRole("USER","ADMIN") + .anyExchange().authenticated() + ) + .httpBasic(Customizer.withDefaults()) + .exceptionHandling(handling -> handling + .authenticationEntryPoint(authenticationEntryPoint) + .accessDeniedHandler(accessDeniedHandler) //基于http的接口请求鉴权失败 + ).cors( cors -> cors + .configurationSource(corsConfigSource()) + ).csrf( csrf -> csrf + .disable() + ); //必须支持跨域 return http.build(); } diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java index 9ca3737..02e9e98 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java @@ -1,6 +1,6 @@ package com.oriole.ocean.gateway.filter; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.oriole.ocean.gateway.tools.JwtUtils; import lombok.extern.slf4j.Slf4j; import org.reactivestreams.Publisher; diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java index 8ad8c33..4450abf 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java @@ -1,6 +1,6 @@ package com.oriole.ocean.gateway.security; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.oriole.ocean.gateway.tools.JwtUtils; import io.jsonwebtoken.Claims; import lombok.extern.slf4j.Slf4j; diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java index 4f5a17b..4b484f3 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java @@ -6,7 +6,7 @@ import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.security.Keys; import org.apache.commons.codec.binary.Base64; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -26,7 +26,6 @@ @Component public class JwtUtils { private final String base64EncodedSecretKey; - private final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS512; public JwtUtils(@Value("${auth.login.token.secretkey}") String secretKey) { this.base64EncodedSecretKey = Base64.encodeBase64String(secretKey.getBytes()); @@ -54,15 +53,15 @@ public String encode(String iss, long ttlMillis, Map claims) { long nowMillis = System.currentTimeMillis(); JwtBuilder builder = Jwts.builder() - .setClaims(claims) - .setId(UUID.randomUUID().toString())//2. 这个是JWT的唯一标识,一般设置成唯一的,这个方法可以生成唯一标识 - .setIssuedAt(new Date(nowMillis))//1. 这个地方就是以毫秒为单位,换算当前系统时间生成的iat - .setSubject(iss)//3. 签发人,也就是JWT是给谁的(逻辑上一般都是username或者userId) - .signWith(signatureAlgorithm, base64EncodedSecretKey);//这个地方是生成jwt使用的算法和秘钥 + .claims(claims) + .id(UUID.randomUUID().toString())//2. 这个是JWT的唯一标识,一般设置成唯一的,这个方法可以生成唯一标识 + .issuedAt(new Date(nowMillis))//1. 这个地方就是以毫秒为单位,换算当前系统时间生成的iat + .subject(iss)//3. 签发人,也就是JWT是给谁的(逻辑上一般都是username或者userId) + .signWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes()));//这个地方是生成jwt使用的算法和秘钥 if (ttlMillis >= 0) { long expMillis = nowMillis + ttlMillis; Date exp = new Date(expMillis);//4. 过期时间,这个也是使用毫秒生成的,使用当前时间+前面传入的持续时间生成 - builder.setExpiration(exp); + builder.expiration(exp); } return builder.compact(); } @@ -74,22 +73,16 @@ public Claims decode(String jwtToken) { // 得到 DefaultJwtParser return Jwts.parser() // 设置签名的秘钥 - .setSigningKey(base64EncodedSecretKey) + .verifyWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes())) + .build() // 设置需要解析的 jwt - .parseClaimsJws(jwtToken) - .getBody(); + .parseSignedClaims(jwtToken) + .getPayload(); } //判断jwtToken是否合法 public boolean isVerify(String jwtToken) { - Algorithm algorithm; - switch (signatureAlgorithm) { - case HS512: - algorithm = Algorithm.HMAC512(Base64.decodeBase64(base64EncodedSecretKey)); - break; - default: - throw new RuntimeException("not support this algorithm"); - } + Algorithm algorithm = Algorithm.HMAC256(Base64.decodeBase64(base64EncodedSecretKey)); JWTVerifier verifier = JWT.require(algorithm).build(); try { verifier.verify(jwtToken); // 校验不通过会抛出异常 diff --git a/ocean-gateway/src/test/java/com/oriole/AppTest.java b/ocean-gateway/src/test/java/com/oriole/AppTest.java index 38e2a80..e6782ee 100644 --- a/ocean-gateway/src/test/java/com/oriole/AppTest.java +++ b/ocean-gateway/src/test/java/com/oriole/AppTest.java @@ -1,38 +1,20 @@ package com.oriole; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Unit test for simple App. */ -public class AppTest - extends TestCase +public class AppTest { - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - /** * Rigourous Test :-) */ + @Test public void testApp() { - assertTrue( true ); + System.out.println("Hello World"); + Assertions.assertTrue( true ); } } diff --git a/ocean-note-service/pom.xml b/ocean-note-service/pom.xml index d7540e6..d942c90 100644 --- a/ocean-note-service/pom.xml +++ b/ocean-note-service/pom.xml @@ -45,19 +45,39 @@ org.apache.dubbo dubbo-registry-nacos + + org.apache.dubbo.extensions + dubbo-serialization-kryo + + + com.esotericsoftware + kryo + + + de.javakaffee + kryo-serializers + com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - + + + + + io.swagger.core.v3 + swagger-annotations-jakarta + + - io.springfox - springfox-swagger2 + org.springdoc + springdoc-openapi-starter-webmvc-ui + - io.springfox - springfox-swagger-ui + org.springframework + spring-webmvc @@ -70,7 +90,7 @@ org.mybatis.spring.boot mybatis-spring-boot-starter - 2.1.0 + 3.0.4 @@ -101,10 +121,27 @@ + + - junit - junit - 3.8.1 + org.junit.jupiter + junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 + test + + + + org.junit + junit-bom + 5.12.1 + pom test @@ -114,5 +151,9 @@ 1.0-SNAPSHOT compile + + org.projectlombok + lombok + diff --git a/ocean-note-service/src/main/resources/bootstrap.yaml b/ocean-note-service/src/main/resources/bootstrap.yaml index 5ba9b08..5301e09 100644 --- a/ocean-note-service/src/main/resources/bootstrap.yaml +++ b/ocean-note-service/src/main/resources/bootstrap.yaml @@ -20,5 +20,6 @@ dubbo: group: dubbo protocol: port: -1 + serialization: kryo consumer: check: false \ No newline at end of file diff --git a/ocean-note-service/src/test/java/com/oriole/AppTest.java b/ocean-note-service/src/test/java/com/oriole/AppTest.java index 38e2a80..e6782ee 100644 --- a/ocean-note-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-note-service/src/test/java/com/oriole/AppTest.java @@ -1,38 +1,20 @@ package com.oriole; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Unit test for simple App. */ -public class AppTest - extends TestCase +public class AppTest { - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - /** * Rigourous Test :-) */ + @Test public void testApp() { - assertTrue( true ); + System.out.println("Hello World"); + Assertions.assertTrue( true ); } } diff --git a/ocean-notify-service/pom.xml b/ocean-notify-service/pom.xml index da8ffd9..c10786d 100644 --- a/ocean-notify-service/pom.xml +++ b/ocean-notify-service/pom.xml @@ -45,19 +45,34 @@ org.apache.dubbo dubbo-registry-nacos + + org.apache.dubbo.extensions + dubbo-serialization-kryo + + + com.esotericsoftware + kryo + + + de.javakaffee + kryo-serializers + com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - + + + - io.springfox - springfox-swagger2 + io.swagger.core.v3 + swagger-annotations-jakarta + - io.springfox - springfox-swagger-ui + org.springdoc + springdoc-openapi-starter-webmvc-ui @@ -70,7 +85,7 @@ org.mybatis.spring.boot mybatis-spring-boot-starter - 2.1.0 + 3.0.4 @@ -101,10 +116,27 @@ + + + + org.junit.jupiter + junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 + test + + - junit - junit - 3.8.1 + org.junit + junit-bom + 5.12.1 + pom test @@ -119,5 +151,10 @@ org.apache.commons commons-lang3 + + org.projectlombok + lombok + compile + diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java index fdc4733..478a07b 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java @@ -6,7 +6,7 @@ import com.oriole.ocean.common.po.mysql.UserNotifyEntity; import org.springframework.stereotype.Service; -import javax.annotation.Resource; +import jakarta.annotation.Resource; import java.util.Date; import java.util.List; diff --git a/ocean-notify-service/src/main/resources/bootstrap.yaml b/ocean-notify-service/src/main/resources/bootstrap.yaml index 6002fbc..2d3cb8f 100644 --- a/ocean-notify-service/src/main/resources/bootstrap.yaml +++ b/ocean-notify-service/src/main/resources/bootstrap.yaml @@ -20,5 +20,6 @@ dubbo: group: dubbo protocol: port: -1 + serialization: kryo consumer: check: false \ No newline at end of file diff --git a/ocean-notify-service/src/test/java/com/oriole/AppTest.java b/ocean-notify-service/src/test/java/com/oriole/AppTest.java index 38e2a80..e6782ee 100644 --- a/ocean-notify-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-notify-service/src/test/java/com/oriole/AppTest.java @@ -1,38 +1,20 @@ package com.oriole; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Unit test for simple App. */ -public class AppTest - extends TestCase +public class AppTest { - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - /** * Rigourous Test :-) */ + @Test public void testApp() { - assertTrue( true ); + System.out.println("Hello World"); + Assertions.assertTrue( true ); } } diff --git a/ocean-user-behavior-service/pom.xml b/ocean-user-behavior-service/pom.xml index c74ff75..b6fb809 100644 --- a/ocean-user-behavior-service/pom.xml +++ b/ocean-user-behavior-service/pom.xml @@ -45,6 +45,18 @@ org.apache.dubbo dubbo-registry-nacos + + org.apache.dubbo.extensions + dubbo-serialization-kryo + + + com.esotericsoftware + kryo + + + de.javakaffee + kryo-serializers + com.alibaba.cloud @@ -58,10 +70,27 @@ spring-boot-starter-data-mongodb + + + + org.junit.jupiter + junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 + test + + - junit - junit - 3.8.1 + org.junit + junit-bom + 5.12.1 + pom test diff --git a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java index b724d70..8c8ba4f 100644 --- a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java +++ b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java @@ -1,6 +1,6 @@ package com.oriole.ocean.service; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.oriole.ocean.common.enumerate.BehaviorExtraInfo; import com.oriole.ocean.common.enumerate.BehaviorType; import com.oriole.ocean.common.enumerate.EvaluateType; diff --git a/ocean-user-behavior-service/src/main/resources/bootstrap.yaml b/ocean-user-behavior-service/src/main/resources/bootstrap.yaml index b33d220..e3e011d 100644 --- a/ocean-user-behavior-service/src/main/resources/bootstrap.yaml +++ b/ocean-user-behavior-service/src/main/resources/bootstrap.yaml @@ -17,5 +17,6 @@ dubbo: group: dubbo protocol: port: -1 + serialization: kryo consumer: check: false \ No newline at end of file diff --git a/ocean-user-behavior-service/src/test/java/com/oriole/AppTest.java b/ocean-user-behavior-service/src/test/java/com/oriole/AppTest.java index 38e2a80..e6782ee 100644 --- a/ocean-user-behavior-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-user-behavior-service/src/test/java/com/oriole/AppTest.java @@ -1,38 +1,20 @@ package com.oriole; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Unit test for simple App. */ -public class AppTest - extends TestCase +public class AppTest { - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - /** * Rigourous Test :-) */ + @Test public void testApp() { - assertTrue( true ); + System.out.println("Hello World"); + Assertions.assertTrue( true ); } } diff --git a/ocean-user-service/pom.xml b/ocean-user-service/pom.xml index 7943437..9e10518 100644 --- a/ocean-user-service/pom.xml +++ b/ocean-user-service/pom.xml @@ -17,7 +17,43 @@ UTF-8 + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.2 + + + + + + + org.projectlombok + lombok + provided + + + + org.slf4j + slf4j-api + 2.0.17 + + + + org.apache.logging.log4j + log4j-core + 2.24.3 + + + + org.slf4j + slf4j-reload4j + 2.0.17 + test + org.springframework.boot @@ -45,19 +81,34 @@ org.apache.dubbo dubbo-registry-nacos + + org.apache.dubbo.extensions + dubbo-serialization-kryo + + + com.esotericsoftware + kryo + + + de.javakaffee + kryo-serializers + com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - + + + - io.springfox - springfox-swagger2 + io.swagger.core.v3 + swagger-annotations-jakarta + - io.springfox - springfox-swagger-ui + org.springdoc + springdoc-openapi-starter-webmvc-ui @@ -67,32 +118,37 @@ mysql-connector-j + org.mybatis.spring.boot mybatis-spring-boot-starter - 2.1.0 + 3.0.4 + com.baomidou mybatis-plus-boot-starter - 3.3.2 + 3.5.10.1 + com.github.pagehelper pagehelper - 6.0.0 + 6.1.0 + - com.github.pagehelper - pagehelper-spring-boot-autoconfigure - 2.0.0 + org.springframework.boot + spring-boot-autoconfigure + 3.3.9 + com.github.pagehelper pagehelper-spring-boot-starter - 2.0.0 + 2.1.0 org.mybatis @@ -101,10 +157,27 @@ + + + + org.junit.jupiter + junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 + test + + - junit - junit - 3.8.1 + org.junit + junit-bom + 5.12.1 + pom test @@ -114,5 +187,22 @@ 1.0-SNAPSHOT compile + + org.springframework + spring-context + 5.3.31 + + + com.baomidou + mybatis-plus-extension + 3.5.10.1 + compile + + + + com.baomidou + mybatis-plus-jsqlparser + 3.5.10.1 + diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java b/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java index 07bfe5b..c71cfaa 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java @@ -1,6 +1,7 @@ package com.oriole.ocean.config; -import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import org.mybatis.spring.mapper.MapperScannerConfigurer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -11,8 +12,10 @@ public class MybatisPlusConfig { * 分页插件 */ @Bean - public PaginationInterceptor paginationInterceptor() { - return new PaginationInterceptor(); + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); + return interceptor; } @Bean diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java index 5407772..1b9d5a2 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java @@ -11,6 +11,8 @@ import java.util.List; +import static com.baomidou.mybatisplus.extension.toolkit.Db.list; + @Service @Transactional public class UserWalletChangeRecordServiceImpl extends ServiceImpl { diff --git a/ocean-user-service/src/main/resources/bootstrap.yaml b/ocean-user-service/src/main/resources/bootstrap.yaml index d4db3be..e6dbc94 100644 --- a/ocean-user-service/src/main/resources/bootstrap.yaml +++ b/ocean-user-service/src/main/resources/bootstrap.yaml @@ -20,5 +20,6 @@ dubbo: group: dubbo protocol: port: -1 + serialization: kryo consumer: check: false \ No newline at end of file diff --git a/ocean-user-service/src/test/java/com/oriole/AppTest.java b/ocean-user-service/src/test/java/com/oriole/AppTest.java index 38e2a80..06fc0f9 100644 --- a/ocean-user-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-user-service/src/test/java/com/oriole/AppTest.java @@ -1,38 +1,20 @@ package com.oriole; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; /** * Unit test for simple App. */ -public class AppTest - extends TestCase +public class AppTest { - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - /** * Rigourous Test :-) */ + @Test public void testApp() { - assertTrue( true ); + System.out.println("Hello World"); + Assertions.assertTrue( true ); } } diff --git a/pom.xml b/pom.xml index 76f770d..9836a55 100644 --- a/pom.xml +++ b/pom.xml @@ -1,9 +1,10 @@ + org.springframework.boot spring-boot-starter-parent - 2.6.15 + 3.3.9 ocean-common @@ -28,46 +29,192 @@ ocean http://maven.apache.org + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + full + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.2 + + + + + + + jakarta.servlet + jakarta.servlet-api + 6.1.0 + provided + + + + org.springframework.boot + spring-boot-starter-web + 3.3.9 + + + + org.junit.platform + junit-platform-surefire-provider + 1.3.2 + + + + org.junit.jupiter + junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 + test + + + + org.junit + junit-bom + 5.12.1 + pom + test + + + + org.projectlombok + lombok + 1.18.36 + provided + + + + org.slf4j + slf4j-api + 2.0.17 + + + + org.apache.logging.log4j + log4j-core + 2.24.3 + + + + org.slf4j + slf4j-reload4j + 2.0.17 + test + + com.alibaba.cloud spring-cloud-alibaba-dependencies - 2021.0.5.0 + 2023.0.3.2 pom - import + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + 2023.0.3.2 + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2023.0.3.2 + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + 2023.0.3.2 + org.springframework.cloud spring-cloud-dependencies - 2021.0.8 + 2023.0.3 pom import + + + org.apache.dubbo dubbo-spring-boot-starter - 3.0.9 + 3.3.1 + + + + + org.apache.dubbo.extensions + dubbo-serialization-kryo + 3.3.1 + + + + + com.esotericsoftware + kryo + 5.6.2 + + org.apache.dubbo dubbo-registry-nacos - 3.0.9 + 3.3.4 + + + + + de.javakaffee + kryo-serializers + 0.45 - + + + + + io.swagger.core.v3 + swagger-annotations-jakarta + 2.2.28 + + + + org.springframework + spring-webmvc + 6.1.17 + + - io.springfox - springfox-swagger2 - 2.9.2 + org.springframework + spring-web + 6.1.17 + - io.springfox - springfox-swagger-ui - 2.9.2 + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.6.0 From e9ef6bf05d36c5e0fcc2361ae0676c49eda84d2a Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Mon, 31 Mar 2025 18:20:41 +0800 Subject: [PATCH 04/62] chore: update the project to the new stable dependencies removed all useless imports and refactored some deprecated functions --- ocean-collection-service/pom.xml | 24 +--- .../controller/UserCollectionController.java | 3 +- .../service/UserCollectionServiceImpl.java | 2 + .../src/main/resources/bootstrap.yaml | 7 +- .../src/test/java/com/oriole/AppTest.java | 2 +- ocean-comment-service/pom.xml | 18 +-- .../controller/UserCommentController.java | 2 +- .../src/test/java/com/oriole/AppTest.java | 2 +- ocean-common/pom.xml | 7 +- .../po/mongo/comment/CommentsListEntity.java | 3 +- .../ocean/common/po/mysql/NoteEntity.java | 1 - .../ocean/common/po/mysql/NoteTypeEntity.java | 2 - .../ocean/common/po/mysql/NotifyEntity.java | 2 - .../po/mysql/NotifySubscriptionEntity.java | 3 +- .../ocean/common/po/mysql/UserEntity.java | 6 +- .../service/NotifySubscriptionService.java | 2 - .../oriole/ocean/common/tools/JwtUtils.java | 11 +- .../ocean/common/vo/AuthUserEntity.java | 1 - .../ocean/common/vo/BusinessException.java | 3 + ocean-docs-file-service/pom.xml | 66 ++-------- .../ocean/controller/DocIOController.java | 27 +++-- .../ocean/service/FileUploadTempService.java | 9 +- .../oriole/ocean/utils/OpenOfficeUtils.java | 4 +- .../utils/objectStorage/AliOSSUtils.java | 2 +- .../objectStorage/ObjectStorageUtils.java | 1 + ocean-docs-service/pom.xml | 63 +--------- .../ocean/OceanDocsServiceApplication.java | 2 + .../ocean/config/MybatisPlusConfig.java | 19 ++- .../DocClassificationController.java | 23 ++-- .../controller/DocFunctionController.java | 6 +- .../ocean/controller/DocInfoController.java | 30 ++--- .../java/com/oriole/ocean/dao/FileDao.java | 5 +- .../ocean/service/DocTagServiceImpl.java | 2 +- .../ocean/service/DocTypeServiceImpl.java | 2 +- .../ocean/service/ESearchServiceImpl.java | 114 +++++++++++------- .../ocean/service/FileCheckServiceImpl.java | 2 +- .../ocean/service/FileExtraServiceImpl.java | 2 +- .../ocean/service/FileSearchServiceImpl.java | 2 +- .../oriole/ocean/service/FileServiceImpl.java | 13 +- .../src/main/resources/bootstrap.yaml | 6 +- ocean-gateway/pom.xml | 22 ++-- .../gateway/config/WebSecurityConfig.java | 4 +- .../filter/UserAuthGatewayFilterFactory.java | 4 +- .../gateway/security/AccessDeniedHandler.java | 2 +- .../security/AuthenticationEntryPoint.java | 2 +- .../gateway/security/SecurityRepository.java | 2 +- .../oriole/ocean/gateway/tools/JwtUtils.java | 11 +- ocean-note-service/pom.xml | 52 +------- .../ocean/OceanNoteServiceApplication.java | 2 + .../ocean/config/MybatisPlusConfig.java | 19 ++- .../ocean/controller/NoteController.java | 15 +-- .../com/oriole/ocean/service/NoteService.java | 9 +- .../oriole/ocean/service/NoteTypeService.java | 2 +- ocean-notify-service/pom.xml | 53 +------- .../oriole/ocean/OceanNotifyApplication.java | 4 +- .../ocean/config/MybatisPlusConfig.java | 19 ++- .../ocean/service/NotifyServiceImpl.java | 2 +- .../NotifySubscriptionServiceImpl.java | 3 +- .../ocean/service/UserNotifyServiceImpl.java | 4 +- ocean-user-behavior-service/pom.xml | 13 -- ocean-user-service/pom.xml | 78 +----------- .../ocean/OceanUserServiceApplication.java | 2 + .../ocean/config/MybatisPlusConfig.java | 9 -- .../ocean/controller/AuthController.java | 5 +- .../ocean/controller/UserInfoController.java | 5 +- .../controller/UserWalletController.java | 17 ++- .../controller/api/WalletController.java | 5 +- .../service/UserFunctionServiceImpl.java | 1 - .../ocean/service/UserInfoServiceImpl.java | 3 - .../service/base/UserBaseInfoServiceImpl.java | 4 +- .../base/UserCertificationServiceImpl.java | 2 +- .../base/UserExtraInfoServiceImpl.java | 2 +- .../UserWalletChangeRecordServiceImpl.java | 17 +-- .../service/base/UserWalletServiceImpl.java | 5 +- .../src/test/java/com/oriole/AppTest.java | 2 +- pom.xml | 36 +----- 76 files changed, 322 insertions(+), 616 deletions(-) diff --git a/ocean-collection-service/pom.xml b/ocean-collection-service/pom.xml index c235d3d..7bd736b 100644 --- a/ocean-collection-service/pom.xml +++ b/ocean-collection-service/pom.xml @@ -34,12 +34,6 @@ org.apache.logging.log4j log4j-core - - - org.slf4j - slf4j-reload4j - test - org.springframework.boot @@ -60,6 +54,7 @@ com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery + com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config @@ -77,10 +72,6 @@ org.apache.dubbo.extensions dubbo-serialization-kryo - - com.esotericsoftware - kryo - de.javakaffee kryo-serializers @@ -90,13 +81,7 @@ com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - - - - io.swagger.core.v3 - swagger-annotations-jakarta - org.springdoc @@ -117,13 +102,6 @@ 5.12.1 test - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 - test - org.junit diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java b/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java index 5e0fdbc..0770dfd 100644 --- a/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java +++ b/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java @@ -4,7 +4,7 @@ import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.oriole.ocean.common.auth.AuthUser; -import com.oriole.ocean.common.enumerate.*; +import com.oriole.ocean.common.enumerate.BehaviorType; import com.oriole.ocean.common.enumerate.MainType; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; import com.oriole.ocean.common.po.mysql.UserCollectionEntity; @@ -17,7 +17,6 @@ import org.apache.commons.lang3.RandomStringUtils; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java b/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java index 3d216ed..e4a01fb 100644 --- a/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java +++ b/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java @@ -7,6 +7,7 @@ import com.oriole.ocean.common.service.FileExtraService; import com.oriole.ocean.common.vo.BusinessException; import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.config.annotation.DubboService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.aggregation.Aggregation; @@ -21,6 +22,7 @@ import java.util.List; @Service +@DubboService public class UserCollectionServiceImpl { @Autowired diff --git a/ocean-collection-service/src/main/resources/bootstrap.yaml b/ocean-collection-service/src/main/resources/bootstrap.yaml index 39c89bf..ff4f24a 100644 --- a/ocean-collection-service/src/main/resources/bootstrap.yaml +++ b/ocean-collection-service/src/main/resources/bootstrap.yaml @@ -1,4 +1,6 @@ spring: + profiles: + active: devx mvc: pathmatch: matching-strategy: ANT_PATH_MATCHER @@ -7,18 +9,21 @@ spring: cloud: nacos: config: - server-addr: ${spring.cloud.nacos.discovery.server-addr} + server-addr: 127.0.0.1:8848 file-extension: yaml group: DEFAULT_GROUP discovery: server-addr: 127.0.0.1:8848 dubbo: + application: + name: ${spring.application.name} registry: address: nacos://127.0.0.1:8848 parameters: namespace: 2a9c5897-b4a7-4825-9c0c-fabcf61a5863 group: dubbo protocol: + name: dubbo port: -1 serialization: kryo consumer: diff --git a/ocean-collection-service/src/test/java/com/oriole/AppTest.java b/ocean-collection-service/src/test/java/com/oriole/AppTest.java index 06fc0f9..e6782ee 100644 --- a/ocean-collection-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-collection-service/src/test/java/com/oriole/AppTest.java @@ -1,7 +1,7 @@ package com.oriole; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Unit test for simple App. diff --git a/ocean-comment-service/pom.xml b/ocean-comment-service/pom.xml index 7849610..42fb324 100644 --- a/ocean-comment-service/pom.xml +++ b/ocean-comment-service/pom.xml @@ -49,26 +49,17 @@ org.apache.dubbo.extensions dubbo-serialization-kryo - - com.esotericsoftware - kryo - de.javakaffee kryo-serializers + 0.45 com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - - - - io.swagger.core.v3 - swagger-annotations-jakarta - org.springdoc @@ -95,13 +86,6 @@ 5.12.1 test - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 - test - org.junit diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index d28bae4..4b34d29 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -1,7 +1,7 @@ package com.oriole.ocean.controller; -import com.oriole.ocean.common.enumerate.*; import com.oriole.ocean.common.auth.AuthUser; +import com.oriole.ocean.common.enumerate.*; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; import com.oriole.ocean.common.po.mongo.comment.*; import com.oriole.ocean.common.po.mysql.NotifyEntity; diff --git a/ocean-comment-service/src/test/java/com/oriole/AppTest.java b/ocean-comment-service/src/test/java/com/oriole/AppTest.java index 06fc0f9..e6782ee 100644 --- a/ocean-comment-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-comment-service/src/test/java/com/oriole/AppTest.java @@ -1,7 +1,7 @@ package com.oriole; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Unit test for simple App. diff --git a/ocean-common/pom.xml b/ocean-common/pom.xml index 9657a81..7f746cc 100644 --- a/ocean-common/pom.xml +++ b/ocean-common/pom.xml @@ -35,7 +35,12 @@ com.baomidou mybatis-plus - 3.5.10.1 + 3.5.7 + + + com.github.jsqlparser + jsqlparser + 4.9 diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentsListEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentsListEntity.java index f91c043..a0349c4 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentsListEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentsListEntity.java @@ -1,7 +1,8 @@ package com.oriole.ocean.common.po.mongo.comment; -import com.oriole.ocean.common.enumerate.MainType; +import com.oriole.ocean.common.enumerate.MainType; import lombok.Data; + import java.util.ArrayList; import java.util.List; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java index d98556d..d5f302f 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java @@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; -import java.time.DateTimeException; import java.util.Date; @Data diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteTypeEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteTypeEntity.java index 3ea5ada..ebc2bec 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteTypeEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteTypeEntity.java @@ -4,8 +4,6 @@ import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; -import java.util.Date; - @Data @TableName("`note_type`") public class NoteTypeEntity implements java.io.Serializable { diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifyEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifyEntity.java index 3560168..ad8c415 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifyEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifyEntity.java @@ -5,12 +5,10 @@ import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; -import com.oriole.ocean.common.enumerate.BehaviorType; import com.oriole.ocean.common.enumerate.MainType; import com.oriole.ocean.common.enumerate.NotifyAction; import com.oriole.ocean.common.enumerate.NotifyType; import lombok.Data; -import org.springframework.data.annotation.Id; import java.util.Date; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifySubscriptionEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifySubscriptionEntity.java index 74b095f..29a4024 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifySubscriptionEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifySubscriptionEntity.java @@ -5,7 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; -import com.oriole.ocean.common.enumerate.*; +import com.oriole.ocean.common.enumerate.NotifyAction; +import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; import lombok.Data; import java.util.Date; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java index 69271d5..63eece5 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java @@ -3,13 +3,11 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; import java.util.Date; -@Getter -@Setter +@Data @TableName("user") public class UserEntity implements java.io.Serializable { diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifySubscriptionService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifySubscriptionService.java index af1cc2d..06c22d6 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifySubscriptionService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifySubscriptionService.java @@ -2,9 +2,7 @@ import com.oriole.ocean.common.enumerate.NotifyAction; import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; -import com.oriole.ocean.common.po.mysql.NotifySubscriptionEntity; -import java.util.ArrayList; import java.util.List; public interface NotifySubscriptionService { diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java b/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java index 3a1258d..a3a946b 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java @@ -6,7 +6,7 @@ import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.security.Keys; +import io.jsonwebtoken.SignatureAlgorithm; import org.apache.commons.codec.binary.Base64; import java.util.Date; @@ -23,6 +23,7 @@ * */ public class JwtUtils { private final String base64EncodedSecretKey; + private final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; public JwtUtils(String secretKey) { this.base64EncodedSecretKey = Base64.encodeBase64String(secretKey.getBytes()); @@ -53,7 +54,7 @@ public String encode(String iss, long ttlMillis, Map claims) { .id(UUID.randomUUID().toString())//2. 这个是JWT的唯一标识,一般设置成唯一的,这个方法可以生成唯一标识 .issuedAt(new Date(nowMillis))//1. 这个地方就是以毫秒为单位,换算当前系统时间生成的iat .subject(iss)//3. 签发人,也就是JWT是给谁的(逻辑上一般都是username或者userId) - .signWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes()));//这个地方是生成jwt使用的算法和秘钥 + .signWith(signatureAlgorithm, base64EncodedSecretKey);;//这个地方是生成jwt使用的算法和秘钥 if (ttlMillis >= 0) { long expMillis = nowMillis + ttlMillis; Date exp = new Date(expMillis);//4. 过期时间,这个也是使用毫秒生成的,使用当前时间+前面传入的持续时间生成 @@ -68,11 +69,11 @@ public Claims decode(String jwtToken) { // 得到 DefaultJwtParser return Jwts.parser() // 设置签名的秘钥 - .verifyWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes())) + .setSigningKey(base64EncodedSecretKey) .build() // 设置需要解析的 jwt - .parseSignedClaims(jwtToken) - .getPayload(); + .parseClaimsJws(jwtToken) + .getBody(); } //判断jwtToken是否合法 diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/vo/AuthUserEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/vo/AuthUserEntity.java index a186b05..b777960 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/vo/AuthUserEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/vo/AuthUserEntity.java @@ -4,7 +4,6 @@ import java.util.List; -import static com.oriole.ocean.common.enumerate.ResultCode.DOCS_NOT_APPROVED; import static com.oriole.ocean.common.enumerate.ResultCode.UNAUTHORIZED_OPERATION; @Data diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java b/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java index 4fd1658..2b02f05 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java @@ -4,9 +4,12 @@ import lombok.Getter; import lombok.Setter; +import java.io.Serial; + @Setter public class BusinessException extends RuntimeException { + @Serial private static final long serialVersionUID = -7480022450501760611L; /** diff --git a/ocean-docs-file-service/pom.xml b/ocean-docs-file-service/pom.xml index 8f330c1..83576f1 100644 --- a/ocean-docs-file-service/pom.xml +++ b/ocean-docs-file-service/pom.xml @@ -34,20 +34,11 @@ org.slf4j slf4j-api - 2.0.17 org.apache.logging.log4j log4j-core - 2.24.3 - - - - org.slf4j - slf4j-reload4j - 2.0.17 - test @@ -80,10 +71,6 @@ org.apache.dubbo.extensions dubbo-serialization-kryo - - com.esotericsoftware - kryo - de.javakaffee kryo-serializers @@ -93,13 +80,7 @@ com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - - - - io.swagger.core.v3 - swagger-annotations-jakarta - org.springdoc @@ -112,39 +93,16 @@ com.mysql mysql-connector-j - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 3.0.4 - com.baomidou - mybatis-plus-boot-starter - 3.3.2 - - - - com.github.pagehelper - pagehelper - 6.0.0 + mybatis-plus-spring-boot3-starter + 3.5.7 - com.github.pagehelper - pagehelper-spring-boot-autoconfigure - 2.0.0 - - - com.github.pagehelper - pagehelper-spring-boot-starter - 2.0.0 - - - org.mybatis - mybatis - - + com.github.jsqlparser + jsqlparser + 4.9 @@ -178,25 +136,17 @@ + org.junit.jupiter junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 test org.junit junit-bom - 5.12.1 pom test @@ -214,12 +164,12 @@ org.jodconverter - jodconverter-local + jodconverter-core 4.4.8 org.jodconverter - jodconverter-core + jodconverter-local 4.4.8 diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java index 9d0ebcc..f6e31b9 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java @@ -1,24 +1,27 @@ package com.oriole.ocean.controller; import com.aliyun.oss.model.CannedAccessControlList; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.oriole.ocean.common.auth.AuthUser; +import com.oriole.ocean.common.enumerate.NotifyAction; +import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; +import com.oriole.ocean.common.po.mysql.FileEntity; +import com.oriole.ocean.common.po.mysql.FileExtraEntity; +import com.oriole.ocean.common.po.mysql.FileSearchEntity; +import com.oriole.ocean.common.po.mysql.FileUploadTempEntity; import com.oriole.ocean.common.service.FileSearchService; import com.oriole.ocean.common.service.FileService; -import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.common.service.NotifySubscriptionService; import com.oriole.ocean.common.tools.JwtUtils; import com.oriole.ocean.common.vo.AuthUserEntity; -import com.oriole.ocean.config.OSSConfig; -import com.oriole.ocean.common.enumerate.*; -import com.oriole.ocean.common.po.mysql.*; import com.oriole.ocean.common.vo.BusinessException; import com.oriole.ocean.common.vo.MsgEntity; -import com.oriole.ocean.service.*; +import com.oriole.ocean.config.OSSConfig; +import com.oriole.ocean.service.FileUploadTempService; import com.oriole.ocean.utils.OpenOfficeUtils; import com.oriole.ocean.utils.PdfUtils; import com.oriole.ocean.utils.objectStorage.AliOSSUtils; +import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomStringUtils; import org.apache.dubbo.config.annotation.DubboReference; @@ -30,7 +33,6 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import jakarta.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -75,14 +77,15 @@ public class DocIOController { public String DOWNLOAD_TOKEN_ENCODED_SECRET_KEY; @RequestMapping(value = "/getIncompleteInfoFileList", method = RequestMethod.GET) - public MsgEntity> getIncompleteInfoFileList(@AuthUser AuthUserEntity authUser, + public MsgEntity> getIncompleteInfoFileList(@AuthUser AuthUserEntity authUser, @RequestParam(required = false) String username, @RequestParam Integer pageNum, @RequestParam Integer pageSize) { username = authUser.getAllowOperationUsername(username); - PageHelper.startPage(pageNum, pageSize, true); - PageInfo fileUploadTempEntityListPageInfo = new PageInfo<>(fileUploadTempService.getAllUploadTempFileInfoByUsername(username)); - return new MsgEntity<>("SUCCESS", "1", fileUploadTempEntityListPageInfo); + Page page = new Page<>(pageNum, pageSize); + + Page fileUploadTempEntityListPage = fileUploadTempService.getAllUploadTempFileInfoByUsername(username, page); + return new MsgEntity<>("SUCCESS", "1", fileUploadTempEntityListPage); } @RequestMapping(value = "/getUploadFileTempInfo", method = RequestMethod.GET) public MsgEntity getUploadFileTempInfo(@AuthUser String username, @RequestParam Integer uploadID) throws Exception { diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/service/FileUploadTempService.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/service/FileUploadTempService.java index c7be3fe..6c91508 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/service/FileUploadTempService.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/service/FileUploadTempService.java @@ -1,14 +1,13 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.dao.FileUploadTempDao; import com.oriole.ocean.common.po.mysql.FileUploadTempEntity; +import com.oriole.ocean.dao.FileUploadTempDao; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - @Service @Transactional public class FileUploadTempService extends ServiceImpl { @@ -28,9 +27,9 @@ public FileUploadTempEntity getUploadTempFileInfo(Integer uploadID, String usern } //文档上传临时文件信息批量查询 - public List getAllUploadTempFileInfoByUsername(String username) { + public Page getAllUploadTempFileInfoByUsername(String username, Page page) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("upload_username", username); - return list(queryWrapper); + return page(page, queryWrapper); } } diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/OpenOfficeUtils.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/OpenOfficeUtils.java index 9fe1022..9c6a27f 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/OpenOfficeUtils.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/OpenOfficeUtils.java @@ -1,9 +1,9 @@ package com.oriole.ocean.utils; -import org.jodconverter.local.LocalConverter; -import org.jodconverter.local.office.LocalOfficeManager; import org.jodconverter.core.office.OfficeException; import org.jodconverter.core.office.OfficeManager; +import org.jodconverter.local.LocalConverter; +import org.jodconverter.local.office.LocalOfficeManager; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java index 9e9f350..5012db5 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java @@ -6,10 +6,10 @@ import com.aliyun.oss.model.GetObjectRequest; import com.aliyun.oss.model.OSSObject; import com.oriole.ocean.config.OSSConfig; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import jakarta.servlet.http.HttpServletResponse; import java.io.BufferedInputStream; import java.io.File; import java.io.InputStream; diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java index aa495de..c36d6fc 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java @@ -1,6 +1,7 @@ package com.oriole.ocean.utils.objectStorage; import jakarta.servlet.http.HttpServletResponse; + import java.io.InputStream; public interface ObjectStorageUtils { diff --git a/ocean-docs-service/pom.xml b/ocean-docs-service/pom.xml index effcbe5..6896336 100644 --- a/ocean-docs-service/pom.xml +++ b/ocean-docs-service/pom.xml @@ -46,10 +46,6 @@ org.apache.dubbo.extensions dubbo-serialization-kryo - - com.esotericsoftware - kryo - de.javakaffee kryo-serializers @@ -68,11 +64,6 @@ - - - io.swagger.core.v3 - swagger-annotations-jakarta - org.springdoc @@ -90,61 +81,28 @@ com.mysql mysql-connector-j - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 3.0.4 - com.baomidou - mybatis-plus-boot-starter - 3.3.2 - - - - com.github.pagehelper - pagehelper - 6.0.0 - - - com.github.pagehelper - pagehelper-spring-boot-autoconfigure - 2.0.0 + mybatis-plus-spring-boot3-starter + 3.5.7 - com.github.pagehelper - pagehelper-spring-boot-starter - 2.0.0 - - - org.mybatis - mybatis - - + com.github.jsqlparser + jsqlparser + 4.9 - org.junit.jupiter junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 test org.junit junit-bom - 5.12.1 pom test @@ -159,16 +117,5 @@ org.projectlombok lombok - - - org.elasticsearch - elasticsearch - 8.17.3 - - - org.springframework.data - spring-data-elasticsearch - 4.3.10 - diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/OceanDocsServiceApplication.java b/ocean-docs-service/src/main/java/com/oriole/ocean/OceanDocsServiceApplication.java index ca036d9..04ff359 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/OceanDocsServiceApplication.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/OceanDocsServiceApplication.java @@ -1,10 +1,12 @@ package com.oriole.ocean; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication +@MapperScan(basePackages = "com.oriole.ocean.dao") @EnableDubbo public class OceanDocsServiceApplication { public static void main(String[] args) { diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java b/ocean-docs-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java index 07bfe5b..b58e588 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java @@ -1,7 +1,7 @@ package com.oriole.ocean.config; -import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; -import org.mybatis.spring.mapper.MapperScannerConfigurer; +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; @@ -11,15 +11,10 @@ public class MybatisPlusConfig { * 分页插件 */ @Bean - public PaginationInterceptor paginationInterceptor() { - return new PaginationInterceptor(); - } - - @Bean - public MapperScannerConfigurer mapperScannerConfigurer(){ - MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer(); - //可以通过环境变量获取你的mapper路径,这样mapper扫描可以通过配置文件配置了 - scannerConfigurer.setBasePackage("com.oriole.ocean.dao"); - return scannerConfigurer; + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + // 添加分页插件 + interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); + return interceptor; } } \ No newline at end of file diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocClassificationController.java b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocClassificationController.java index 3cbc953..91c9568 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocClassificationController.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocClassificationController.java @@ -1,7 +1,6 @@ package com.oriole.ocean.controller; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.oriole.ocean.common.po.mongo.IndexNodeEntity; import com.oriole.ocean.common.po.mysql.FileEntity; import com.oriole.ocean.common.po.mysql.FileTypeEntity; @@ -46,18 +45,22 @@ public MsgEntity> getTypesByTypeString(@RequestParam String } @RequestMapping(value = "/getGroupsFileList",method = RequestMethod.GET) - public MsgEntity> getFileListByTypeIDAndTagIDAndIndexString( + public MsgEntity> getFileListByTypeIDAndTagIDAndIndexString( @RequestParam(required = false) Integer typeID, @RequestParam(required = false) String tagString, @RequestParam(required = false) String indexString, @RequestParam Integer pageNum, @RequestParam Integer pageSize) { - PageHelper.startPage(pageNum, pageSize, true); - List fileEntityList = fileService.getFileDetailsInfoListByTypeIDAndTagStringAndIndexString(typeID, tagString, indexString); - for (FileEntity fileEntity : fileEntityList) { - fileEntity.setRealObjectName(null); - } - PageInfo pageInfo = new PageInfo<>(fileEntityList); - return new MsgEntity<>("SUCCESS", "1", pageInfo); + Page page = new Page<>(pageNum, pageSize); + + Page resultPage = fileService.getFileDetailsInfoListByTypeIDAndTagStringAndIndexString( + typeID, + tagString, + indexString, + page); + + resultPage.getRecords().forEach(file -> file.setRealObjectName(null)); + + return new MsgEntity<>("SUCCESS", "1", resultPage); } @RequestMapping(value = "/getIndexList",method = RequestMethod.GET) diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java index e6fac26..bcd87fd 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java @@ -1,8 +1,8 @@ package com.oriole.ocean.controller; import com.alibaba.fastjson2.JSONObject; -import com.oriole.ocean.common.enumerate.*; import com.oriole.ocean.common.auth.AuthUser; +import com.oriole.ocean.common.enumerate.*; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; import com.oriole.ocean.common.po.mysql.FileEntity; import com.oriole.ocean.common.service.UserBehaviorService; @@ -11,6 +11,8 @@ import com.oriole.ocean.common.vo.AuthUserEntity; import com.oriole.ocean.common.vo.BusinessException; import com.oriole.ocean.common.vo.MsgEntity; +import com.oriole.ocean.service.FileExtraServiceImpl; +import com.oriole.ocean.service.FileServiceImpl; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; @@ -19,8 +21,6 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.oriole.ocean.service.*; - import java.util.HashMap; import java.util.List; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocInfoController.java b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocInfoController.java index cc17eec..c3147b5 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocInfoController.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocInfoController.java @@ -1,7 +1,6 @@ package com.oriole.ocean.controller; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.oriole.ocean.common.auth.AuthUser; import com.oriole.ocean.common.enumerate.BehaviorType; import com.oriole.ocean.common.enumerate.MainType; @@ -17,8 +16,10 @@ import com.oriole.ocean.service.FileServiceImpl; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.Comparator; @@ -42,15 +43,16 @@ public class DocInfoController { FileCheckServiceImpl fileCheckService; @RequestMapping(value = "/getFileList", method = RequestMethod.GET) - public MsgEntity> getFileList(@AuthUser AuthUserEntity authUser, + public MsgEntity> getFileList(@AuthUser AuthUserEntity authUser, @RequestParam(required = false) String username, @RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam Boolean isFolder) { username = authUser.getAllowOperationUsername(username); - PageHelper.startPage(pageNum, pageSize, true); - PageInfo fileEntityListPageInfo = new PageInfo<>(fileService.getFileDetailsInfoListByUsername(username, true, isFolder)); - return new MsgEntity<>("SUCCESS", "1", fileEntityListPageInfo); + Page page = new Page<>(pageNum, pageSize); + + Page fileEntityListPage = fileService.getFileDetailsInfoListByUsername(username, true, isFolder, page); + return new MsgEntity<>("SUCCESS", "1", fileEntityListPage); } @RequestMapping(value = "/getFileListByFolderID", method = RequestMethod.GET) @@ -124,21 +126,21 @@ public MsgEntity changeDocumentInfo(@AuthUser AuthUserEntity authUser, @ } @RequestMapping(value = "/getNotAcceptedFileList", method = RequestMethod.GET) - public MsgEntity> getNotAcceptedFileList(@AuthUser AuthUserEntity authUser, + public MsgEntity> getNotAcceptedFileList(@AuthUser AuthUserEntity authUser, @RequestParam(required = false) String username, @RequestParam Integer pageNum, @RequestParam Integer pageSize) { username = authUser.getAllowOperationUsername(username); - PageHelper.startPage(pageNum, pageSize, true); - List fileEntityList = fileService.getFileDetailsInfoListByUsername(username, false, false); - fileEntityList.forEach(fileEntity -> { + Page page = new Page<>(pageNum, pageSize); + + Page resultPage = fileService.getFileDetailsInfoListByUsername(username, false, false, page); + resultPage.getRecords().forEach(fileEntity -> { if (!fileEntity.getIsApproved().equals((byte) 0)) { FileCheckEntity fileCheckEntity = fileCheckService.getFileCheckInfo(fileEntity.getFileID()); fileEntity.setFileCheckEntity(fileCheckEntity); } }); - PageInfo fileEntityListPageInfo = new PageInfo<>(fileEntityList); - return new MsgEntity<>("SUCCESS", "1", fileEntityListPageInfo); + return new MsgEntity<>("SUCCESS", "1", resultPage); } @RequestMapping(value = "/getRecentlyReadList", method = RequestMethod.GET) diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/dao/FileDao.java b/ocean-docs-service/src/main/java/com/oriole/ocean/dao/FileDao.java index ee53e1d..7000cf5 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/dao/FileDao.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/dao/FileDao.java @@ -1,6 +1,7 @@ package com.oriole.ocean.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.oriole.ocean.common.po.mysql.FileEntity; import org.apache.ibatis.annotations.Param; @@ -8,8 +9,8 @@ public interface FileDao extends BaseMapper { - List getFileListByTypeIDAndTagIDAndIndexString(Integer typeID,String[] tagIDs,String indexString); - List getFileListByUsername(String username,Boolean isApproved, Boolean isFolder); + Page getFileListByTypeIDAndTagIDAndIndexString(Page page, Integer typeID, String[] tagIDs, String indexString); + Page getFileListByUsername(Page page, String username,Boolean isApproved, Boolean isFolder); List getFileListByFolderID(String folderID); FileEntity getFileDetailInfoById(@Param("fileID") Integer fileID); diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTagServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTagServiceImpl.java index 84be1b2..9c78326 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTagServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTagServiceImpl.java @@ -1,8 +1,8 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.dao.TagDao; import com.oriole.ocean.common.po.mysql.FileTagEntity; +import com.oriole.ocean.dao.TagDao; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTypeServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTypeServiceImpl.java index e20f014..25a0237 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTypeServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTypeServiceImpl.java @@ -2,8 +2,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.dao.TypeDao; import com.oriole.ocean.common.po.mysql.FileTypeEntity; +import com.oriole.ocean.dao.TypeDao; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java index 9d9788e..6ab15a3 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java @@ -1,23 +1,21 @@ package com.oriole.ocean.service; +import co.elastic.clients.elasticsearch.core.search.CompletionSuggester; +import co.elastic.clients.elasticsearch.core.search.Suggester; import com.oriole.ocean.common.po.es.FileSearchEntity; -import org.elasticsearch.common.unit.Fuzziness; -import org.elasticsearch.index.query.BoolQueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; -import org.elasticsearch.search.suggest.Suggest; -import org.elasticsearch.search.suggest.SuggestBuilder; -import org.elasticsearch.search.suggest.SuggestBuilders; -import org.elasticsearch.search.suggest.completion.CompletionSuggestion; -import org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder; +import jakarta.annotation.Resource; import org.springframework.data.domain.PageRequest; -import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; +import org.springframework.data.elasticsearch.client.elc.NativeQuery; +import org.springframework.data.elasticsearch.client.elc.NativeQueryBuilder; +import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.SearchHits; -import org.springframework.data.elasticsearch.core.query.NativeSearchQuery; -import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; +import org.springframework.data.elasticsearch.core.query.HighlightQuery; +import org.springframework.data.elasticsearch.core.query.highlight.Highlight; +import org.springframework.data.elasticsearch.core.query.highlight.HighlightField; +import org.springframework.data.elasticsearch.core.query.highlight.HighlightFieldParameters; +import org.springframework.data.elasticsearch.core.suggest.response.Suggest; import org.springframework.stereotype.Service; -import jakarta.annotation.Resource; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; @@ -27,29 +25,50 @@ public class ESearchServiceImpl { @Resource - private ElasticsearchRestTemplate elasticsearchRestTemplate; + private ElasticsearchOperations elasticsearchOperations; public SearchHits searchFile(String keywords, Integer page, Integer rows) { - BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery() - .should(QueryBuilders.fuzzyQuery("analyzer_title", keywords).fuzziness(Fuzziness.AUTO)) - .should(QueryBuilders.fuzzyQuery("analyzer_content", keywords).fuzziness(Fuzziness.AUTO)) - .should(QueryBuilders.fuzzyQuery("analyzer_abstract_content", keywords).fuzziness(Fuzziness.AUTO)) - .must(QueryBuilders.multiMatchQuery(keywords,"analyzer_title","analyzer_content","analyzer_abstract_content")) - .must(QueryBuilders.matchQuery("is_approved", "true"));//必须是已经被核准的才能被检索出来 + HighlightFieldParameters highlightFieldParameters = HighlightFieldParameters.builder() + .withMatchedFields( + "analyzer_title", + "analyzer_abstract_content", + "analyzer_content" + ) + .withPreTags("") + .withPostTags("") + .build(); //构建高亮查询 - NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(boolQueryBuilder) - .withHighlightFields( - new HighlightBuilder.Field("analyzer_title"), - new HighlightBuilder.Field("analyzer_abstract_content"), - new HighlightBuilder.Field("analyzer_content")) - .withHighlightBuilder(new HighlightBuilder().preTags("").postTags("")) - .withPageable(PageRequest.of(page - 1, rows)).build(); + Highlight highlight = new Highlight( + List.of( + new HighlightField("analyzer_title", + highlightFieldParameters), + new HighlightField("analyzer_abstract_content", + highlightFieldParameters), + new HighlightField("analyzer_content", + highlightFieldParameters) + ) + ); + HighlightQuery highlightQuery = new HighlightQuery(highlight, FileSearchEntity.class); + + NativeQuery searchQuery = new NativeQueryBuilder() + .withQuery(q -> q + .multiMatch(m -> m + .query(keywords) + .fields( + "analyzer_title", + "analyzer_content", + "analyzer_abstract_content"))) + .withQuery(q -> q + .match(m -> m + .query("true") + .field("is_approved"))) + .withHighlightQuery(highlightQuery) + .withPageable(PageRequest.of(page - 1, rows)) + .build(); - SearchHits searchHits = elasticsearchRestTemplate.search(searchQuery, FileSearchEntity.class); - return searchHits; + return elasticsearchOperations.search(searchQuery, FileSearchEntity.class); } public ArrayList suggestTitle(String keyword,Integer rows) { return suggest("suggest_title",keyword,rows); @@ -58,25 +77,32 @@ public ArrayList suggestTitle(String keyword,Integer rows) { public ArrayList suggest(String fieldName, String keyword,Integer rows) { HashSet returnSet = new LinkedHashSet<>(); // 用于存储查询到的结果 // 创建CompletionSuggestionBuilder - CompletionSuggestionBuilder textBuilder = SuggestBuilders.completionSuggestion(fieldName) // 指定字段名 - .size(rows) // 设定返回数量 - .skipDuplicates(true); // 去重 + CompletionSuggester.Builder textBuilder = new CompletionSuggester.Builder() + .field(fieldName) + .size(rows) + .skipDuplicates(true); + + // 创建nativeQuery并将completionBuilder添加进去 + NativeQuery nativeQuery = new NativeQueryBuilder() + .withSuggester(Suggester.of(s -> s + .suggesters("suggest_text", a -> a + .completion(textBuilder.build()) + .prefix(keyword)))) + .build(); - // 创建suggestBuilder并将completionBuilder添加进去 - SuggestBuilder suggestBuilder = new SuggestBuilder(); - suggestBuilder.addSuggestion("suggest_text", textBuilder) - .setGlobalText(keyword); // 执行请求 - Suggest suggest = elasticsearchRestTemplate.suggest(suggestBuilder, elasticsearchRestTemplate.getIndexCoordinatesFor(FileSearchEntity.class)).getSuggest(); + SearchHits searchHits = elasticsearchOperations.search(nativeQuery, FileSearchEntity.class); + // 取出结果 - Suggest.Suggestion> textSuggestion = suggest.getSuggestion("suggest_text"); - for (Suggest.Suggestion.Entry entry : textSuggestion.getEntries()) { - List options = entry.getOptions(); - for (Suggest.Suggestion.Entry.Option option : options) { - returnSet.add(option.getText().toString()); + if(searchHits.hasSuggest()) { + Suggest suggest = searchHits.getSuggest(); + var textSuggestion = suggest.getSuggestion("suggest_text"); + for (var entry : textSuggestion.getEntries()) { + for (Suggest.Suggestion.Entry.Option option : entry.getOptions()) { + returnSet.add(option.getText()); + } } } return new ArrayList<>(returnSet); } - } diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileCheckServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileCheckServiceImpl.java index 1656b86..fe5be04 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileCheckServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileCheckServiceImpl.java @@ -1,8 +1,8 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.dao.FileCheckDao; import com.oriole.ocean.common.po.mysql.FileCheckEntity; +import com.oriole.ocean.dao.FileCheckDao; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileExtraServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileExtraServiceImpl.java index d1189f7..6077153 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileExtraServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileExtraServiceImpl.java @@ -4,9 +4,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.oriole.ocean.common.enumerate.DocStatisticItemType; import com.oriole.ocean.common.enumerate.EvaluateType; +import com.oriole.ocean.common.po.mysql.FileExtraEntity; import com.oriole.ocean.common.service.FileExtraService; import com.oriole.ocean.dao.FileExtraDao; -import com.oriole.ocean.common.po.mysql.FileExtraEntity; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileSearchServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileSearchServiceImpl.java index 25fa590..a2b6cbe 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileSearchServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileSearchServiceImpl.java @@ -1,9 +1,9 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oriole.ocean.common.po.mysql.FileSearchEntity; import com.oriole.ocean.common.service.FileSearchService; import com.oriole.ocean.dao.FileSearchDao; -import com.oriole.ocean.common.po.mysql.FileSearchEntity; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java index 4235745..f638d3e 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java @@ -1,16 +1,17 @@ package com.oriole.ocean.service; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oriole.ocean.common.po.mysql.FileEntity; import com.oriole.ocean.common.po.mysql.FileExtraEntity; import com.oriole.ocean.common.service.FileService; import com.oriole.ocean.dao.FileDao; -import com.oriole.ocean.common.po.mysql.FileEntity; +import jakarta.annotation.Resource; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import jakarta.annotation.Resource; import java.util.List; @Service @@ -34,17 +35,17 @@ public FileEntity getFileDetailsInfoByFileID(Integer fileIDs) { } //文章详细信息查询(通过用户名查询)(可区分是否已被审核) - public List getFileDetailsInfoListByUsername(String username, Boolean isApproved, Boolean isFolder) { - return fileDao.getFileListByUsername(username, isApproved, isFolder); + public Page getFileDetailsInfoListByUsername(String username, Boolean isApproved, Boolean isFolder, Page page) { + return fileDao.getFileListByUsername(page, username, isApproved, isFolder); } //文章详细信息查询(通过分类ID、标签ID和索引字符串查询) - public List getFileDetailsInfoListByTypeIDAndTagStringAndIndexString(Integer typeID, String tagString, String indexString) { + public Page getFileDetailsInfoListByTypeIDAndTagStringAndIndexString(Integer typeID, String tagString, String indexString, Page page) { String[] tagIDs = new String[0]; if (!tagString.isEmpty() && !tagString.equals("null")) { tagIDs = tagString.split("\\,"); } - return fileDao.getFileListByTypeIDAndTagIDAndIndexString(typeID, tagIDs, indexString + "%"); + return fileDao.getFileListByTypeIDAndTagIDAndIndexString(page, typeID, tagIDs, indexString + "%"); } //文章详细信息查询(通过FolderID查询) diff --git a/ocean-docs-service/src/main/resources/bootstrap.yaml b/ocean-docs-service/src/main/resources/bootstrap.yaml index c2b277b..d9114c6 100644 --- a/ocean-docs-service/src/main/resources/bootstrap.yaml +++ b/ocean-docs-service/src/main/resources/bootstrap.yaml @@ -21,4 +21,8 @@ dubbo: protocol: port: -1 consumer: - check: false \ No newline at end of file + check: false +logging: + level: + org: + DEBUG \ No newline at end of file diff --git a/ocean-gateway/pom.xml b/ocean-gateway/pom.xml index 9bd9156..e32ec73 100644 --- a/ocean-gateway/pom.xml +++ b/ocean-gateway/pom.xml @@ -50,6 +50,20 @@ jjwt-api 0.12.6 + + + io.jsonwebtoken + jjwt-impl + 0.12.6 + runtime + + + + io.jsonwebtoken + jjwt-jackson + 0.12.6 + runtime + com.auth0 @@ -70,14 +84,6 @@ org.junit.jupiter junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 test diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java index cb7513a..6447bf1 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java @@ -1,6 +1,8 @@ package com.oriole.ocean.gateway.config; -import com.oriole.ocean.gateway.security.*; +import com.oriole.ocean.gateway.security.AccessDeniedHandler; +import com.oriole.ocean.gateway.security.AuthenticationEntryPoint; +import com.oriole.ocean.gateway.security.SecurityRepository; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java index 02e9e98..b04888f 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java @@ -21,8 +21,10 @@ import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; + import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.HashMap; +import java.util.Map; @Slf4j @Component diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AccessDeniedHandler.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AccessDeniedHandler.java index 9ba5704..0c492bd 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AccessDeniedHandler.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AccessDeniedHandler.java @@ -8,9 +8,9 @@ import org.springframework.http.HttpStatus; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.security.access.AccessDeniedException; -import org.springframework.web.server.ServerWebExchange; import org.springframework.security.web.server.authorization.ServerAccessDeniedHandler; import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; @Slf4j diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AuthenticationEntryPoint.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AuthenticationEntryPoint.java index 50a32d7..8c13548 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AuthenticationEntryPoint.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AuthenticationEntryPoint.java @@ -9,8 +9,8 @@ import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.server.authentication.HttpBasicServerAuthenticationEntryPoint; -import org.springframework.web.server.ServerWebExchange; import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; @Slf4j diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java index 4450abf..63484e3 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java @@ -18,7 +18,7 @@ import java.util.ArrayList; import java.util.Collection; -import static org.springframework.security.core.context.SecurityContextHolder.*; +import static org.springframework.security.core.context.SecurityContextHolder.createEmptyContext; @Slf4j @Component diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java index 4b484f3..84d62a1 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java @@ -6,7 +6,7 @@ import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.security.Keys; +import io.jsonwebtoken.SignatureAlgorithm; import org.apache.commons.codec.binary.Base64; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -26,6 +26,7 @@ @Component public class JwtUtils { private final String base64EncodedSecretKey; + private final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; public JwtUtils(@Value("${auth.login.token.secretkey}") String secretKey) { this.base64EncodedSecretKey = Base64.encodeBase64String(secretKey.getBytes()); @@ -57,7 +58,7 @@ public String encode(String iss, long ttlMillis, Map claims) { .id(UUID.randomUUID().toString())//2. 这个是JWT的唯一标识,一般设置成唯一的,这个方法可以生成唯一标识 .issuedAt(new Date(nowMillis))//1. 这个地方就是以毫秒为单位,换算当前系统时间生成的iat .subject(iss)//3. 签发人,也就是JWT是给谁的(逻辑上一般都是username或者userId) - .signWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes()));//这个地方是生成jwt使用的算法和秘钥 + .signWith(signatureAlgorithm, base64EncodedSecretKey);;//这个地方是生成jwt使用的算法和秘钥 if (ttlMillis >= 0) { long expMillis = nowMillis + ttlMillis; Date exp = new Date(expMillis);//4. 过期时间,这个也是使用毫秒生成的,使用当前时间+前面传入的持续时间生成 @@ -73,11 +74,11 @@ public Claims decode(String jwtToken) { // 得到 DefaultJwtParser return Jwts.parser() // 设置签名的秘钥 - .verifyWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes())) + .setSigningKey(base64EncodedSecretKey) .build() // 设置需要解析的 jwt - .parseSignedClaims(jwtToken) - .getPayload(); + .parseClaimsJws(jwtToken) + .getBody(); } //判断jwtToken是否合法 diff --git a/ocean-note-service/pom.xml b/ocean-note-service/pom.xml index d942c90..cf4950f 100644 --- a/ocean-note-service/pom.xml +++ b/ocean-note-service/pom.xml @@ -49,10 +49,6 @@ org.apache.dubbo.extensions dubbo-serialization-kryo - - com.esotericsoftware - kryo - de.javakaffee kryo-serializers @@ -62,13 +58,7 @@ com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - - - - io.swagger.core.v3 - swagger-annotations-jakarta - org.springdoc @@ -86,54 +76,22 @@ com.mysql mysql-connector-j - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 3.0.4 - com.baomidou - mybatis-plus-boot-starter - 3.3.2 - - - - com.github.pagehelper - pagehelper - 6.0.0 + mybatis-plus-spring-boot3-starter + 3.5.7 - com.github.pagehelper - pagehelper-spring-boot-autoconfigure - 2.0.0 + com.github.jsqlparser + jsqlparser + 4.9 - - com.github.pagehelper - pagehelper-spring-boot-starter - 2.0.0 - - - org.mybatis - mybatis - - - - org.junit.jupiter junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 test diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/OceanNoteServiceApplication.java b/ocean-note-service/src/main/java/com/oriole/ocean/OceanNoteServiceApplication.java index d4cdfd9..83067cf 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/OceanNoteServiceApplication.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/OceanNoteServiceApplication.java @@ -1,10 +1,12 @@ package com.oriole.ocean; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication +@MapperScan(basePackages = "com.oriole.ocean.dao") @EnableDubbo public class OceanNoteServiceApplication { public static void main(String[] args) { diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java b/ocean-note-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java index 07bfe5b..b58e588 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java @@ -1,7 +1,7 @@ package com.oriole.ocean.config; -import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; -import org.mybatis.spring.mapper.MapperScannerConfigurer; +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; @@ -11,15 +11,10 @@ public class MybatisPlusConfig { * 分页插件 */ @Bean - public PaginationInterceptor paginationInterceptor() { - return new PaginationInterceptor(); - } - - @Bean - public MapperScannerConfigurer mapperScannerConfigurer(){ - MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer(); - //可以通过环境变量获取你的mapper路径,这样mapper扫描可以通过配置文件配置了 - scannerConfigurer.setBasePackage("com.oriole.ocean.dao"); - return scannerConfigurer; + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + // 添加分页插件 + interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); + return interceptor; } } \ No newline at end of file diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index a129929..eda90f9 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -1,7 +1,6 @@ package com.oriole.ocean.controller; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.oriole.ocean.common.po.mysql.NoteEntity; import com.oriole.ocean.common.po.mysql.NoteTypeEntity; import com.oriole.ocean.common.vo.MsgEntity; @@ -31,10 +30,12 @@ public MsgEntity> getAllNoteType() { } @RequestMapping(value = "/getNoteByNoteType",method = RequestMethod.GET) - public MsgEntity> getNoteByNoteType(@RequestParam(required = false) Integer noteType,@RequestParam Integer pageNum, @RequestParam Integer pageSize) { - PageHelper.startPage(pageNum, pageSize, true); - List noteEntityList = noteService.getNoteByNoteType(noteType); - PageInfo pageInfo = new PageInfo<>(noteEntityList); - return new MsgEntity<>("SUCCESS", "1", pageInfo); + public MsgEntity> getNoteByNoteType(@RequestParam(required = false) Integer noteType,@RequestParam Integer pageNum, @RequestParam Integer pageSize) { + + Page page = new Page<>(pageNum, pageSize); + + Page resultPage = noteService.getNoteByNoteType(noteType, page); + + return new MsgEntity<>("SUCCESS", "1", resultPage); } } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java index 2ad3710..dc7cb8e 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java @@ -1,22 +1,21 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.dao.NoteDao; import com.oriole.ocean.common.po.mysql.NoteEntity; +import com.oriole.ocean.dao.NoteDao; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - @Service @Transactional public class NoteService extends ServiceImpl { - public List getNoteByNoteType(Integer noteType){ + public Page getNoteByNoteType(Integer noteType, Page page){ QueryWrapper queryWrapper = new QueryWrapper<>(); if(noteType!=null) { queryWrapper.eq("note_type", noteType); } - return list(queryWrapper); + return page(page, queryWrapper); } } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java index b021e9a..c6a8cd5 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java @@ -1,8 +1,8 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.dao.NoteTypeDao; import com.oriole.ocean.common.po.mysql.NoteTypeEntity; +import com.oriole.ocean.dao.NoteTypeDao; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-notify-service/pom.xml b/ocean-notify-service/pom.xml index c10786d..f0b4ae3 100644 --- a/ocean-notify-service/pom.xml +++ b/ocean-notify-service/pom.xml @@ -49,10 +49,6 @@ org.apache.dubbo.extensions dubbo-serialization-kryo - - com.esotericsoftware - kryo - de.javakaffee kryo-serializers @@ -62,13 +58,7 @@ com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - - - - io.swagger.core.v3 - swagger-annotations-jakarta - org.springdoc @@ -81,54 +71,23 @@ com.mysql mysql-connector-j - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 3.0.4 - + com.baomidou - mybatis-plus-boot-starter - 3.3.2 - - - - com.github.pagehelper - pagehelper - 6.0.0 + mybatis-plus-spring-boot3-starter + 3.5.7 - com.github.pagehelper - pagehelper-spring-boot-autoconfigure - 2.0.0 + com.github.jsqlparser + jsqlparser + 4.9 - - com.github.pagehelper - pagehelper-spring-boot-starter - 2.0.0 - - - org.mybatis - mybatis - - - - org.junit.jupiter junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 test diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/OceanNotifyApplication.java b/ocean-notify-service/src/main/java/com/oriole/ocean/OceanNotifyApplication.java index 9bee39a..48eb039 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/OceanNotifyApplication.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/OceanNotifyApplication.java @@ -1,11 +1,13 @@ package com.oriole.ocean; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -@EnableDubbo +@MapperScan(basePackages = "com.oriole.ocean.dao") +@EnableDubbo(scanBasePackages = "com.oriole.ocean.service") public class OceanNotifyApplication { public static void main(String[] args) { SpringApplication.run(OceanNotifyApplication.class, args); diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java b/ocean-notify-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java index 07bfe5b..b58e588 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java @@ -1,7 +1,7 @@ package com.oriole.ocean.config; -import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; -import org.mybatis.spring.mapper.MapperScannerConfigurer; +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; @@ -11,15 +11,10 @@ public class MybatisPlusConfig { * 分页插件 */ @Bean - public PaginationInterceptor paginationInterceptor() { - return new PaginationInterceptor(); - } - - @Bean - public MapperScannerConfigurer mapperScannerConfigurer(){ - MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer(); - //可以通过环境变量获取你的mapper路径,这样mapper扫描可以通过配置文件配置了 - scannerConfigurer.setBasePackage("com.oriole.ocean.dao"); - return scannerConfigurer; + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + // 添加分页插件 + interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); + return interceptor; } } \ No newline at end of file diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java index 06c50d6..e9da9e1 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java @@ -5,9 +5,9 @@ import com.oriole.ocean.common.enumerate.NotifyAction; import com.oriole.ocean.common.enumerate.NotifyType; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; +import com.oriole.ocean.common.po.mysql.NotifyEntity; import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.dao.NotifyDao; -import com.oriole.ocean.common.po.mysql.NotifyEntity; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.stereotype.Service; diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifySubscriptionServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifySubscriptionServiceImpl.java index feeff95..4ef3e9e 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifySubscriptionServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifySubscriptionServiceImpl.java @@ -4,14 +4,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.oriole.ocean.common.enumerate.NotifyAction; import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; +import com.oriole.ocean.common.po.mysql.NotifySubscriptionEntity; import com.oriole.ocean.common.service.NotifySubscriptionService; import com.oriole.ocean.dao.NotifySubscriptionDao; -import com.oriole.ocean.common.po.mysql.NotifySubscriptionEntity; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; import java.util.List; @Service diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java index 478a07b..cff96fa 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java @@ -2,11 +2,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.dao.UserNotifyDao; import com.oriole.ocean.common.po.mysql.UserNotifyEntity; +import com.oriole.ocean.dao.UserNotifyDao; +import jakarta.annotation.Resource; import org.springframework.stereotype.Service; -import jakarta.annotation.Resource; import java.util.Date; import java.util.List; diff --git a/ocean-user-behavior-service/pom.xml b/ocean-user-behavior-service/pom.xml index b6fb809..3c70b0c 100644 --- a/ocean-user-behavior-service/pom.xml +++ b/ocean-user-behavior-service/pom.xml @@ -49,10 +49,6 @@ org.apache.dubbo.extensions dubbo-serialization-kryo - - com.esotericsoftware - kryo - de.javakaffee kryo-serializers @@ -75,21 +71,12 @@ org.junit.jupiter junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 test org.junit junit-bom - 5.12.1 pom test diff --git a/ocean-user-service/pom.xml b/ocean-user-service/pom.xml index 9e10518..ed4e0ba 100644 --- a/ocean-user-service/pom.xml +++ b/ocean-user-service/pom.xml @@ -47,13 +47,6 @@ log4j-core 2.24.3 - - - org.slf4j - slf4j-reload4j - 2.0.17 - test - org.springframework.boot @@ -85,10 +78,6 @@ org.apache.dubbo.extensions dubbo-serialization-kryo - - com.esotericsoftware - kryo - de.javakaffee kryo-serializers @@ -98,13 +87,7 @@ com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - - - - io.swagger.core.v3 - swagger-annotations-jakarta - org.springdoc @@ -117,66 +100,29 @@ com.mysql mysql-connector-j - - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 3.0.4 - com.baomidou - mybatis-plus-boot-starter - 3.5.10.1 - - - - - com.github.pagehelper - pagehelper - 6.1.0 - - - - org.springframework.boot - spring-boot-autoconfigure - 3.3.9 + mybatis-plus-spring-boot3-starter + 3.5.7 - - com.github.pagehelper - pagehelper-spring-boot-starter - 2.1.0 - - - org.mybatis - mybatis - - + com.github.jsqlparser + jsqlparser + 4.9 - org.junit.jupiter junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 test org.junit junit-bom - 5.12.1 pom test @@ -190,19 +136,7 @@ org.springframework spring-context - 5.3.31 - - - com.baomidou - mybatis-plus-extension - 3.5.10.1 - compile - - - - com.baomidou - mybatis-plus-jsqlparser - 3.5.10.1 + 6.1.14 diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/OceanUserServiceApplication.java b/ocean-user-service/src/main/java/com/oriole/ocean/OceanUserServiceApplication.java index f06ccf1..3a4833a 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/OceanUserServiceApplication.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/OceanUserServiceApplication.java @@ -1,10 +1,12 @@ package com.oriole.ocean; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication +@MapperScan(basePackages = "com.oriole.ocean.dao") @EnableDubbo public class OceanUserServiceApplication { public static void main(String[] args) { diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java b/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java index c71cfaa..02e940a 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java @@ -2,7 +2,6 @@ import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; -import org.mybatis.spring.mapper.MapperScannerConfigurer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -17,12 +16,4 @@ public MybatisPlusInterceptor mybatisPlusInterceptor() { interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); return interceptor; } - - @Bean - public MapperScannerConfigurer mapperScannerConfigurer(){ - MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer(); - //可以通过环境变量获取你的mapper路径,这样mapper扫描可以通过配置文件配置了 - scannerConfigurer.setBasePackage("com.oriole.ocean.dao"); - return scannerConfigurer; - } } \ No newline at end of file diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/controller/AuthController.java b/ocean-user-service/src/main/java/com/oriole/ocean/controller/AuthController.java index 1df8023..37f7269 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/controller/AuthController.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/controller/AuthController.java @@ -1,15 +1,12 @@ package com.oriole.ocean.controller; -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson2.JSON; import com.oriole.ocean.common.po.mysql.UserEntity; +import com.oriole.ocean.common.vo.MsgEntity; import com.oriole.ocean.service.base.UserBaseInfoServiceImpl; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; -import com.oriole.ocean.common.vo.MsgEntity; import org.springframework.web.bind.annotation.RestController; @RestController diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java index 4f36fe8..a05dd77 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java @@ -10,7 +10,10 @@ import com.oriole.ocean.service.base.UserBaseInfoServiceImpl; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @RestController @Slf4j diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserWalletController.java b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserWalletController.java index c23e632..2da2eb3 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserWalletController.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserWalletController.java @@ -1,6 +1,6 @@ package com.oriole.ocean.controller; -import com.github.pagehelper.PageInfo; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.oriole.ocean.common.auth.AuthUser; import com.oriole.ocean.common.po.mysql.WalletChangeRecordEntity; import com.oriole.ocean.common.vo.AuthUserEntity; @@ -20,8 +20,17 @@ public class UserWalletController { UserWalletChangeRecordServiceImpl walletChangeRecordService; @RequestMapping(value = "/getWalletChangeRecord",method = RequestMethod.GET) - public MsgEntity> getWalletChangeRecord(@AuthUser AuthUserEntity authUser, @RequestParam Integer pageNum, @RequestParam Integer pageSize) { - return new MsgEntity<>("SUCCESS", "1", - walletChangeRecordService.getWalletChangeRecord(authUser.getUsername(),pageNum,pageSize)); + public MsgEntity> getWalletChangeRecord( + @AuthUser AuthUserEntity authUser, + @RequestParam Integer pageNum, + @RequestParam Integer pageSize) { + + Page pageResult = walletChangeRecordService.getWalletChangeRecord( + authUser.getUsername(), + pageNum, + pageSize + ); + + return new MsgEntity<>("SUCCESS", "1", pageResult); } } diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/controller/api/WalletController.java b/ocean-user-service/src/main/java/com/oriole/ocean/controller/api/WalletController.java index e7beba6..24d5806 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/controller/api/WalletController.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/controller/api/WalletController.java @@ -6,7 +6,10 @@ import com.oriole.ocean.common.enumerate.WalletMoneyType; import com.oriole.ocean.service.base.UserWalletServiceImpl; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/walletAPI") diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/UserFunctionServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/UserFunctionServiceImpl.java index 11fbe6d..4662b94 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/UserFunctionServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/UserFunctionServiceImpl.java @@ -5,7 +5,6 @@ import com.oriole.ocean.common.service.UserBehaviorService; import com.oriole.ocean.common.vo.BusinessException; import org.apache.dubbo.config.annotation.DubboReference; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/UserInfoServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/UserInfoServiceImpl.java index 97ec15a..f40d48d 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/UserInfoServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/UserInfoServiceImpl.java @@ -2,15 +2,12 @@ import com.oriole.ocean.common.enumerate.UserInfoLevel; import com.oriole.ocean.common.po.mysql.UserEntity; -import com.oriole.ocean.common.vo.BusinessException; -import com.oriole.ocean.common.vo.MsgEntity; import com.oriole.ocean.service.base.UserBaseInfoServiceImpl; import com.oriole.ocean.service.base.UserCertificationServiceImpl; import com.oriole.ocean.service.base.UserExtraInfoServiceImpl; import com.oriole.ocean.service.base.UserWalletServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.RequestParam; @Service public class UserInfoServiceImpl { diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserBaseInfoServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserBaseInfoServiceImpl.java index a5309ce..afefcdd 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserBaseInfoServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserBaseInfoServiceImpl.java @@ -1,13 +1,11 @@ package com.oriole.ocean.service.base; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oriole.ocean.common.po.mysql.UserEntity; import com.oriole.ocean.common.vo.BusinessException; -import com.oriole.ocean.common.vo.MsgEntity; import com.oriole.ocean.dao.UserDao; -import com.oriole.ocean.common.po.mysql.UserEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.RequestParam; @Service @Transactional diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserCertificationServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserCertificationServiceImpl.java index 055b3fd..e03d8d1 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserCertificationServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserCertificationServiceImpl.java @@ -1,8 +1,8 @@ package com.oriole.ocean.service.base; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.dao.UserCertificationDao; import com.oriole.ocean.common.po.mysql.UserCertificationEntity; +import com.oriole.ocean.dao.UserCertificationDao; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserExtraInfoServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserExtraInfoServiceImpl.java index d386780..b3a1d51 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserExtraInfoServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserExtraInfoServiceImpl.java @@ -1,8 +1,8 @@ package com.oriole.ocean.service.base; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.dao.UserExtraDao; import com.oriole.ocean.common.po.mysql.UserExtraEntity; +import com.oriole.ocean.dao.UserExtraDao; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java index 1b9d5a2..cab5d23 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java @@ -1,31 +1,24 @@ package com.oriole.ocean.service.base; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; -import com.oriole.ocean.dao.WalletChangeRecordDao; import com.oriole.ocean.common.po.mysql.WalletChangeRecordEntity; +import com.oriole.ocean.dao.WalletChangeRecordDao; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - -import static com.baomidou.mybatisplus.extension.toolkit.Db.list; - @Service @Transactional public class UserWalletChangeRecordServiceImpl extends ServiceImpl { - public PageInfo getWalletChangeRecord(String username, Integer pageNum, Integer pageSize) { + public Page getWalletChangeRecord(String username, Integer pageNum, Integer pageSize) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("username", username); - PageHelper.startPage(pageNum, pageSize, true); - - List walletChangeRecordEntityList = list(queryWrapper); + Page page = new Page<>(pageNum, pageSize); - return new PageInfo<>(walletChangeRecordEntityList); + return baseMapper.selectPage(page, queryWrapper); } } diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletServiceImpl.java index fea2eeb..f76552d 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletServiceImpl.java @@ -3,15 +3,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.oriole.ocean.common.enumerate.VipOperationState; import com.oriole.ocean.common.enumerate.VipOperationType; -import com.oriole.ocean.common.service.UserWalletService; -import com.oriole.ocean.dao.WalletDao; import com.oriole.ocean.common.po.mysql.WalletChangeRecordEntity; import com.oriole.ocean.common.po.mysql.WalletEntity; +import com.oriole.ocean.common.service.UserWalletService; +import com.oriole.ocean.dao.WalletDao; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.RequestParam; @Service @DubboService diff --git a/ocean-user-service/src/test/java/com/oriole/AppTest.java b/ocean-user-service/src/test/java/com/oriole/AppTest.java index 06fc0f9..e6782ee 100644 --- a/ocean-user-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-user-service/src/test/java/com/oriole/AppTest.java @@ -1,7 +1,7 @@ package com.oriole; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Unit test for simple App. diff --git a/pom.xml b/pom.xml index 9836a55..77a7cb8 100644 --- a/pom.xml +++ b/pom.xml @@ -63,12 +63,6 @@ spring-boot-starter-web 3.3.9 - - - org.junit.platform - junit-platform-surefire-provider - 1.3.2 - org.junit.jupiter @@ -76,13 +70,6 @@ 5.12.1 test - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 - test - org.junit @@ -122,33 +109,16 @@ com.alibaba.cloud spring-cloud-alibaba-dependencies - 2023.0.3.2 + 2023.0.1.2 pom - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-sentinel - 2023.0.3.2 - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - 2023.0.3.2 - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-config - 2023.0.3.2 + import org.springframework.cloud spring-cloud-dependencies - 2023.0.3 + 2023.0.1 pom import From 969606759b2574ad8d5f43e8e32fb78beeef78c9 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Wed, 16 Apr 2025 12:42:20 +0800 Subject: [PATCH 05/62] Revert "chore: update the project to the new stable dependencies" This reverts commit e9ef6bf05d36c5e0fcc2361ae0676c49eda84d2a. --- ocean-collection-service/pom.xml | 24 +++- .../controller/UserCollectionController.java | 3 +- .../service/UserCollectionServiceImpl.java | 2 - .../src/main/resources/bootstrap.yaml | 7 +- .../src/test/java/com/oriole/AppTest.java | 2 +- ocean-comment-service/pom.xml | 18 ++- .../controller/UserCommentController.java | 2 +- .../src/test/java/com/oriole/AppTest.java | 2 +- ocean-common/pom.xml | 7 +- .../po/mongo/comment/CommentsListEntity.java | 3 +- .../ocean/common/po/mysql/NoteEntity.java | 1 + .../ocean/common/po/mysql/NoteTypeEntity.java | 2 + .../ocean/common/po/mysql/NotifyEntity.java | 2 + .../po/mysql/NotifySubscriptionEntity.java | 3 +- .../ocean/common/po/mysql/UserEntity.java | 6 +- .../service/NotifySubscriptionService.java | 2 + .../oriole/ocean/common/tools/JwtUtils.java | 11 +- .../ocean/common/vo/AuthUserEntity.java | 1 + .../ocean/common/vo/BusinessException.java | 3 - ocean-docs-file-service/pom.xml | 66 ++++++++-- .../ocean/controller/DocIOController.java | 27 ++--- .../ocean/service/FileUploadTempService.java | 9 +- .../oriole/ocean/utils/OpenOfficeUtils.java | 4 +- .../utils/objectStorage/AliOSSUtils.java | 2 +- .../objectStorage/ObjectStorageUtils.java | 1 - ocean-docs-service/pom.xml | 63 +++++++++- .../ocean/OceanDocsServiceApplication.java | 2 - .../ocean/config/MybatisPlusConfig.java | 19 +-- .../DocClassificationController.java | 23 ++-- .../controller/DocFunctionController.java | 6 +- .../ocean/controller/DocInfoController.java | 30 +++-- .../java/com/oriole/ocean/dao/FileDao.java | 5 +- .../ocean/service/DocTagServiceImpl.java | 2 +- .../ocean/service/DocTypeServiceImpl.java | 2 +- .../ocean/service/ESearchServiceImpl.java | 114 +++++++----------- .../ocean/service/FileCheckServiceImpl.java | 2 +- .../ocean/service/FileExtraServiceImpl.java | 2 +- .../ocean/service/FileSearchServiceImpl.java | 2 +- .../oriole/ocean/service/FileServiceImpl.java | 13 +- .../src/main/resources/bootstrap.yaml | 6 +- ocean-gateway/pom.xml | 22 ++-- .../gateway/config/WebSecurityConfig.java | 4 +- .../filter/UserAuthGatewayFilterFactory.java | 4 +- .../gateway/security/AccessDeniedHandler.java | 2 +- .../security/AuthenticationEntryPoint.java | 2 +- .../gateway/security/SecurityRepository.java | 2 +- .../oriole/ocean/gateway/tools/JwtUtils.java | 11 +- ocean-note-service/pom.xml | 52 +++++++- .../ocean/OceanNoteServiceApplication.java | 2 - .../ocean/config/MybatisPlusConfig.java | 19 +-- .../ocean/controller/NoteController.java | 15 ++- .../com/oriole/ocean/service/NoteService.java | 9 +- .../oriole/ocean/service/NoteTypeService.java | 2 +- ocean-notify-service/pom.xml | 53 +++++++- .../oriole/ocean/OceanNotifyApplication.java | 4 +- .../ocean/config/MybatisPlusConfig.java | 19 +-- .../ocean/service/NotifyServiceImpl.java | 2 +- .../NotifySubscriptionServiceImpl.java | 3 +- .../ocean/service/UserNotifyServiceImpl.java | 4 +- ocean-user-behavior-service/pom.xml | 13 ++ ocean-user-service/pom.xml | 78 +++++++++++- .../ocean/OceanUserServiceApplication.java | 2 - .../ocean/config/MybatisPlusConfig.java | 9 ++ .../ocean/controller/AuthController.java | 5 +- .../ocean/controller/UserInfoController.java | 5 +- .../controller/UserWalletController.java | 17 +-- .../controller/api/WalletController.java | 5 +- .../service/UserFunctionServiceImpl.java | 1 + .../ocean/service/UserInfoServiceImpl.java | 3 + .../service/base/UserBaseInfoServiceImpl.java | 4 +- .../base/UserCertificationServiceImpl.java | 2 +- .../base/UserExtraInfoServiceImpl.java | 2 +- .../UserWalletChangeRecordServiceImpl.java | 17 ++- .../service/base/UserWalletServiceImpl.java | 5 +- .../src/test/java/com/oriole/AppTest.java | 2 +- pom.xml | 36 +++++- 76 files changed, 616 insertions(+), 322 deletions(-) diff --git a/ocean-collection-service/pom.xml b/ocean-collection-service/pom.xml index 7bd736b..c235d3d 100644 --- a/ocean-collection-service/pom.xml +++ b/ocean-collection-service/pom.xml @@ -34,6 +34,12 @@ org.apache.logging.log4j log4j-core + + + org.slf4j + slf4j-reload4j + test + org.springframework.boot @@ -54,7 +60,6 @@ com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery - com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config @@ -72,6 +77,10 @@ org.apache.dubbo.extensions dubbo-serialization-kryo + + com.esotericsoftware + kryo + de.javakaffee kryo-serializers @@ -81,7 +90,13 @@ com.alibaba.cloud spring-cloud-starter-alibaba-sentinel + + + + io.swagger.core.v3 + swagger-annotations-jakarta + org.springdoc @@ -102,6 +117,13 @@ 5.12.1 test + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 + test + org.junit diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java b/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java index 0770dfd..5e0fdbc 100644 --- a/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java +++ b/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java @@ -4,7 +4,7 @@ import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.oriole.ocean.common.auth.AuthUser; -import com.oriole.ocean.common.enumerate.BehaviorType; +import com.oriole.ocean.common.enumerate.*; import com.oriole.ocean.common.enumerate.MainType; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; import com.oriole.ocean.common.po.mysql.UserCollectionEntity; @@ -17,6 +17,7 @@ import org.apache.commons.lang3.RandomStringUtils; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.query.Query; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java b/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java index e4a01fb..3d216ed 100644 --- a/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java +++ b/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java @@ -7,7 +7,6 @@ import com.oriole.ocean.common.service.FileExtraService; import com.oriole.ocean.common.vo.BusinessException; import org.apache.dubbo.config.annotation.DubboReference; -import org.apache.dubbo.config.annotation.DubboService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.aggregation.Aggregation; @@ -22,7 +21,6 @@ import java.util.List; @Service -@DubboService public class UserCollectionServiceImpl { @Autowired diff --git a/ocean-collection-service/src/main/resources/bootstrap.yaml b/ocean-collection-service/src/main/resources/bootstrap.yaml index ff4f24a..39c89bf 100644 --- a/ocean-collection-service/src/main/resources/bootstrap.yaml +++ b/ocean-collection-service/src/main/resources/bootstrap.yaml @@ -1,6 +1,4 @@ spring: - profiles: - active: devx mvc: pathmatch: matching-strategy: ANT_PATH_MATCHER @@ -9,21 +7,18 @@ spring: cloud: nacos: config: - server-addr: 127.0.0.1:8848 + server-addr: ${spring.cloud.nacos.discovery.server-addr} file-extension: yaml group: DEFAULT_GROUP discovery: server-addr: 127.0.0.1:8848 dubbo: - application: - name: ${spring.application.name} registry: address: nacos://127.0.0.1:8848 parameters: namespace: 2a9c5897-b4a7-4825-9c0c-fabcf61a5863 group: dubbo protocol: - name: dubbo port: -1 serialization: kryo consumer: diff --git a/ocean-collection-service/src/test/java/com/oriole/AppTest.java b/ocean-collection-service/src/test/java/com/oriole/AppTest.java index e6782ee..06fc0f9 100644 --- a/ocean-collection-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-collection-service/src/test/java/com/oriole/AppTest.java @@ -1,7 +1,7 @@ package com.oriole; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; /** * Unit test for simple App. diff --git a/ocean-comment-service/pom.xml b/ocean-comment-service/pom.xml index 42fb324..7849610 100644 --- a/ocean-comment-service/pom.xml +++ b/ocean-comment-service/pom.xml @@ -49,17 +49,26 @@ org.apache.dubbo.extensions dubbo-serialization-kryo + + com.esotericsoftware + kryo + de.javakaffee kryo-serializers - 0.45 com.alibaba.cloud spring-cloud-starter-alibaba-sentinel + + + + io.swagger.core.v3 + swagger-annotations-jakarta + org.springdoc @@ -86,6 +95,13 @@ 5.12.1 test + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 + test + org.junit diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index 4b34d29..d28bae4 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -1,7 +1,7 @@ package com.oriole.ocean.controller; -import com.oriole.ocean.common.auth.AuthUser; import com.oriole.ocean.common.enumerate.*; +import com.oriole.ocean.common.auth.AuthUser; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; import com.oriole.ocean.common.po.mongo.comment.*; import com.oriole.ocean.common.po.mysql.NotifyEntity; diff --git a/ocean-comment-service/src/test/java/com/oriole/AppTest.java b/ocean-comment-service/src/test/java/com/oriole/AppTest.java index e6782ee..06fc0f9 100644 --- a/ocean-comment-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-comment-service/src/test/java/com/oriole/AppTest.java @@ -1,7 +1,7 @@ package com.oriole; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; /** * Unit test for simple App. diff --git a/ocean-common/pom.xml b/ocean-common/pom.xml index 7f746cc..9657a81 100644 --- a/ocean-common/pom.xml +++ b/ocean-common/pom.xml @@ -35,12 +35,7 @@ com.baomidou mybatis-plus - 3.5.7 - - - com.github.jsqlparser - jsqlparser - 4.9 + 3.5.10.1 diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentsListEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentsListEntity.java index a0349c4..f91c043 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentsListEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentsListEntity.java @@ -1,8 +1,7 @@ package com.oriole.ocean.common.po.mongo.comment; - import com.oriole.ocean.common.enumerate.MainType; -import lombok.Data; +import lombok.Data; import java.util.ArrayList; import java.util.List; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java index d5f302f..d98556d 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; +import java.time.DateTimeException; import java.util.Date; @Data diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteTypeEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteTypeEntity.java index ebc2bec..3ea5ada 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteTypeEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteTypeEntity.java @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; +import java.util.Date; + @Data @TableName("`note_type`") public class NoteTypeEntity implements java.io.Serializable { diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifyEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifyEntity.java index ad8c415..3560168 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifyEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifyEntity.java @@ -5,10 +5,12 @@ import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; +import com.oriole.ocean.common.enumerate.BehaviorType; import com.oriole.ocean.common.enumerate.MainType; import com.oriole.ocean.common.enumerate.NotifyAction; import com.oriole.ocean.common.enumerate.NotifyType; import lombok.Data; +import org.springframework.data.annotation.Id; import java.util.Date; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifySubscriptionEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifySubscriptionEntity.java index 29a4024..74b095f 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifySubscriptionEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifySubscriptionEntity.java @@ -5,8 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; -import com.oriole.ocean.common.enumerate.NotifyAction; -import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; +import com.oriole.ocean.common.enumerate.*; import lombok.Data; import java.util.Date; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java index 63eece5..69271d5 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java @@ -3,11 +3,13 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; +import lombok.Getter; +import lombok.Setter; import java.util.Date; -@Data +@Getter +@Setter @TableName("user") public class UserEntity implements java.io.Serializable { diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifySubscriptionService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifySubscriptionService.java index 06c22d6..af1cc2d 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifySubscriptionService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifySubscriptionService.java @@ -2,7 +2,9 @@ import com.oriole.ocean.common.enumerate.NotifyAction; import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; +import com.oriole.ocean.common.po.mysql.NotifySubscriptionEntity; +import java.util.ArrayList; import java.util.List; public interface NotifySubscriptionService { diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java b/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java index a3a946b..3a1258d 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java @@ -6,7 +6,7 @@ import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.security.Keys; import org.apache.commons.codec.binary.Base64; import java.util.Date; @@ -23,7 +23,6 @@ * */ public class JwtUtils { private final String base64EncodedSecretKey; - private final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; public JwtUtils(String secretKey) { this.base64EncodedSecretKey = Base64.encodeBase64String(secretKey.getBytes()); @@ -54,7 +53,7 @@ public String encode(String iss, long ttlMillis, Map claims) { .id(UUID.randomUUID().toString())//2. 这个是JWT的唯一标识,一般设置成唯一的,这个方法可以生成唯一标识 .issuedAt(new Date(nowMillis))//1. 这个地方就是以毫秒为单位,换算当前系统时间生成的iat .subject(iss)//3. 签发人,也就是JWT是给谁的(逻辑上一般都是username或者userId) - .signWith(signatureAlgorithm, base64EncodedSecretKey);;//这个地方是生成jwt使用的算法和秘钥 + .signWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes()));//这个地方是生成jwt使用的算法和秘钥 if (ttlMillis >= 0) { long expMillis = nowMillis + ttlMillis; Date exp = new Date(expMillis);//4. 过期时间,这个也是使用毫秒生成的,使用当前时间+前面传入的持续时间生成 @@ -69,11 +68,11 @@ public Claims decode(String jwtToken) { // 得到 DefaultJwtParser return Jwts.parser() // 设置签名的秘钥 - .setSigningKey(base64EncodedSecretKey) + .verifyWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes())) .build() // 设置需要解析的 jwt - .parseClaimsJws(jwtToken) - .getBody(); + .parseSignedClaims(jwtToken) + .getPayload(); } //判断jwtToken是否合法 diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/vo/AuthUserEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/vo/AuthUserEntity.java index b777960..a186b05 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/vo/AuthUserEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/vo/AuthUserEntity.java @@ -4,6 +4,7 @@ import java.util.List; +import static com.oriole.ocean.common.enumerate.ResultCode.DOCS_NOT_APPROVED; import static com.oriole.ocean.common.enumerate.ResultCode.UNAUTHORIZED_OPERATION; @Data diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java b/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java index 2b02f05..4fd1658 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java @@ -4,12 +4,9 @@ import lombok.Getter; import lombok.Setter; -import java.io.Serial; - @Setter public class BusinessException extends RuntimeException { - @Serial private static final long serialVersionUID = -7480022450501760611L; /** diff --git a/ocean-docs-file-service/pom.xml b/ocean-docs-file-service/pom.xml index 83576f1..8f330c1 100644 --- a/ocean-docs-file-service/pom.xml +++ b/ocean-docs-file-service/pom.xml @@ -34,11 +34,20 @@ org.slf4j slf4j-api + 2.0.17 org.apache.logging.log4j log4j-core + 2.24.3 + + + + org.slf4j + slf4j-reload4j + 2.0.17 + test @@ -71,6 +80,10 @@ org.apache.dubbo.extensions dubbo-serialization-kryo + + com.esotericsoftware + kryo + de.javakaffee kryo-serializers @@ -80,7 +93,13 @@ com.alibaba.cloud spring-cloud-starter-alibaba-sentinel + + + + io.swagger.core.v3 + swagger-annotations-jakarta + org.springdoc @@ -93,16 +112,39 @@ com.mysql mysql-connector-j + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 3.0.4 + com.baomidou - mybatis-plus-spring-boot3-starter - 3.5.7 + mybatis-plus-boot-starter + 3.3.2 + + + + com.github.pagehelper + pagehelper + 6.0.0 - com.github.jsqlparser - jsqlparser - 4.9 + com.github.pagehelper + pagehelper-spring-boot-autoconfigure + 2.0.0 + + + com.github.pagehelper + pagehelper-spring-boot-starter + 2.0.0 + + + org.mybatis + mybatis + + @@ -136,17 +178,25 @@ - org.junit.jupiter junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 test org.junit junit-bom + 5.12.1 pom test @@ -164,12 +214,12 @@ org.jodconverter - jodconverter-core + jodconverter-local 4.4.8 org.jodconverter - jodconverter-local + jodconverter-core 4.4.8 diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java index f6e31b9..9d0ebcc 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java @@ -1,27 +1,24 @@ package com.oriole.ocean.controller; import com.aliyun.oss.model.CannedAccessControlList; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.oriole.ocean.common.auth.AuthUser; -import com.oriole.ocean.common.enumerate.NotifyAction; -import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; -import com.oriole.ocean.common.po.mysql.FileEntity; -import com.oriole.ocean.common.po.mysql.FileExtraEntity; -import com.oriole.ocean.common.po.mysql.FileSearchEntity; -import com.oriole.ocean.common.po.mysql.FileUploadTempEntity; import com.oriole.ocean.common.service.FileSearchService; import com.oriole.ocean.common.service.FileService; +import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.common.service.NotifySubscriptionService; import com.oriole.ocean.common.tools.JwtUtils; import com.oriole.ocean.common.vo.AuthUserEntity; +import com.oriole.ocean.config.OSSConfig; +import com.oriole.ocean.common.enumerate.*; +import com.oriole.ocean.common.po.mysql.*; import com.oriole.ocean.common.vo.BusinessException; import com.oriole.ocean.common.vo.MsgEntity; -import com.oriole.ocean.config.OSSConfig; -import com.oriole.ocean.service.FileUploadTempService; +import com.oriole.ocean.service.*; import com.oriole.ocean.utils.OpenOfficeUtils; import com.oriole.ocean.utils.PdfUtils; import com.oriole.ocean.utils.objectStorage.AliOSSUtils; -import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomStringUtils; import org.apache.dubbo.config.annotation.DubboReference; @@ -33,6 +30,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import jakarta.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -77,15 +75,14 @@ public class DocIOController { public String DOWNLOAD_TOKEN_ENCODED_SECRET_KEY; @RequestMapping(value = "/getIncompleteInfoFileList", method = RequestMethod.GET) - public MsgEntity> getIncompleteInfoFileList(@AuthUser AuthUserEntity authUser, + public MsgEntity> getIncompleteInfoFileList(@AuthUser AuthUserEntity authUser, @RequestParam(required = false) String username, @RequestParam Integer pageNum, @RequestParam Integer pageSize) { username = authUser.getAllowOperationUsername(username); - Page page = new Page<>(pageNum, pageSize); - - Page fileUploadTempEntityListPage = fileUploadTempService.getAllUploadTempFileInfoByUsername(username, page); - return new MsgEntity<>("SUCCESS", "1", fileUploadTempEntityListPage); + PageHelper.startPage(pageNum, pageSize, true); + PageInfo fileUploadTempEntityListPageInfo = new PageInfo<>(fileUploadTempService.getAllUploadTempFileInfoByUsername(username)); + return new MsgEntity<>("SUCCESS", "1", fileUploadTempEntityListPageInfo); } @RequestMapping(value = "/getUploadFileTempInfo", method = RequestMethod.GET) public MsgEntity getUploadFileTempInfo(@AuthUser String username, @RequestParam Integer uploadID) throws Exception { diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/service/FileUploadTempService.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/service/FileUploadTempService.java index 6c91508..c7be3fe 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/service/FileUploadTempService.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/service/FileUploadTempService.java @@ -1,13 +1,14 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.po.mysql.FileUploadTempEntity; import com.oriole.ocean.dao.FileUploadTempDao; +import com.oriole.ocean.common.po.mysql.FileUploadTempEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Service @Transactional public class FileUploadTempService extends ServiceImpl { @@ -27,9 +28,9 @@ public FileUploadTempEntity getUploadTempFileInfo(Integer uploadID, String usern } //文档上传临时文件信息批量查询 - public Page getAllUploadTempFileInfoByUsername(String username, Page page) { + public List getAllUploadTempFileInfoByUsername(String username) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("upload_username", username); - return page(page, queryWrapper); + return list(queryWrapper); } } diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/OpenOfficeUtils.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/OpenOfficeUtils.java index 9c6a27f..9fe1022 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/OpenOfficeUtils.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/OpenOfficeUtils.java @@ -1,9 +1,9 @@ package com.oriole.ocean.utils; -import org.jodconverter.core.office.OfficeException; -import org.jodconverter.core.office.OfficeManager; import org.jodconverter.local.LocalConverter; import org.jodconverter.local.office.LocalOfficeManager; +import org.jodconverter.core.office.OfficeException; +import org.jodconverter.core.office.OfficeManager; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java index 5012db5..9e9f350 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java @@ -6,10 +6,10 @@ import com.aliyun.oss.model.GetObjectRequest; import com.aliyun.oss.model.OSSObject; import com.oriole.ocean.config.OSSConfig; -import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import jakarta.servlet.http.HttpServletResponse; import java.io.BufferedInputStream; import java.io.File; import java.io.InputStream; diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java index c36d6fc..aa495de 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java @@ -1,7 +1,6 @@ package com.oriole.ocean.utils.objectStorage; import jakarta.servlet.http.HttpServletResponse; - import java.io.InputStream; public interface ObjectStorageUtils { diff --git a/ocean-docs-service/pom.xml b/ocean-docs-service/pom.xml index 6896336..effcbe5 100644 --- a/ocean-docs-service/pom.xml +++ b/ocean-docs-service/pom.xml @@ -46,6 +46,10 @@ org.apache.dubbo.extensions dubbo-serialization-kryo + + com.esotericsoftware + kryo + de.javakaffee kryo-serializers @@ -64,6 +68,11 @@ + + + io.swagger.core.v3 + swagger-annotations-jakarta + org.springdoc @@ -81,28 +90,61 @@ com.mysql mysql-connector-j + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 3.0.4 + com.baomidou - mybatis-plus-spring-boot3-starter - 3.5.7 + mybatis-plus-boot-starter + 3.3.2 + + + + com.github.pagehelper + pagehelper + 6.0.0 + + + com.github.pagehelper + pagehelper-spring-boot-autoconfigure + 2.0.0 - com.github.jsqlparser - jsqlparser - 4.9 + com.github.pagehelper + pagehelper-spring-boot-starter + 2.0.0 + + + org.mybatis + mybatis + + + org.junit.jupiter junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 test org.junit junit-bom + 5.12.1 pom test @@ -117,5 +159,16 @@ org.projectlombok lombok + + + org.elasticsearch + elasticsearch + 8.17.3 + + + org.springframework.data + spring-data-elasticsearch + 4.3.10 + diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/OceanDocsServiceApplication.java b/ocean-docs-service/src/main/java/com/oriole/ocean/OceanDocsServiceApplication.java index 04ff359..ca036d9 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/OceanDocsServiceApplication.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/OceanDocsServiceApplication.java @@ -1,12 +1,10 @@ package com.oriole.ocean; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; -import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -@MapperScan(basePackages = "com.oriole.ocean.dao") @EnableDubbo public class OceanDocsServiceApplication { public static void main(String[] args) { diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java b/ocean-docs-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java index b58e588..07bfe5b 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java @@ -1,7 +1,7 @@ package com.oriole.ocean.config; -import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +import org.mybatis.spring.mapper.MapperScannerConfigurer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -11,10 +11,15 @@ public class MybatisPlusConfig { * 分页插件 */ @Bean - public MybatisPlusInterceptor mybatisPlusInterceptor() { - MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); - // 添加分页插件 - interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); - return interceptor; + public PaginationInterceptor paginationInterceptor() { + return new PaginationInterceptor(); + } + + @Bean + public MapperScannerConfigurer mapperScannerConfigurer(){ + MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer(); + //可以通过环境变量获取你的mapper路径,这样mapper扫描可以通过配置文件配置了 + scannerConfigurer.setBasePackage("com.oriole.ocean.dao"); + return scannerConfigurer; } } \ No newline at end of file diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocClassificationController.java b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocClassificationController.java index 91c9568..3cbc953 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocClassificationController.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocClassificationController.java @@ -1,6 +1,7 @@ package com.oriole.ocean.controller; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.oriole.ocean.common.po.mongo.IndexNodeEntity; import com.oriole.ocean.common.po.mysql.FileEntity; import com.oriole.ocean.common.po.mysql.FileTypeEntity; @@ -45,22 +46,18 @@ public MsgEntity> getTypesByTypeString(@RequestParam String } @RequestMapping(value = "/getGroupsFileList",method = RequestMethod.GET) - public MsgEntity> getFileListByTypeIDAndTagIDAndIndexString( + public MsgEntity> getFileListByTypeIDAndTagIDAndIndexString( @RequestParam(required = false) Integer typeID, @RequestParam(required = false) String tagString, @RequestParam(required = false) String indexString, @RequestParam Integer pageNum, @RequestParam Integer pageSize) { - Page page = new Page<>(pageNum, pageSize); - - Page resultPage = fileService.getFileDetailsInfoListByTypeIDAndTagStringAndIndexString( - typeID, - tagString, - indexString, - page); - - resultPage.getRecords().forEach(file -> file.setRealObjectName(null)); - - return new MsgEntity<>("SUCCESS", "1", resultPage); + PageHelper.startPage(pageNum, pageSize, true); + List fileEntityList = fileService.getFileDetailsInfoListByTypeIDAndTagStringAndIndexString(typeID, tagString, indexString); + for (FileEntity fileEntity : fileEntityList) { + fileEntity.setRealObjectName(null); + } + PageInfo pageInfo = new PageInfo<>(fileEntityList); + return new MsgEntity<>("SUCCESS", "1", pageInfo); } @RequestMapping(value = "/getIndexList",method = RequestMethod.GET) diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java index bcd87fd..e6fac26 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java @@ -1,8 +1,8 @@ package com.oriole.ocean.controller; import com.alibaba.fastjson2.JSONObject; -import com.oriole.ocean.common.auth.AuthUser; import com.oriole.ocean.common.enumerate.*; +import com.oriole.ocean.common.auth.AuthUser; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; import com.oriole.ocean.common.po.mysql.FileEntity; import com.oriole.ocean.common.service.UserBehaviorService; @@ -11,8 +11,6 @@ import com.oriole.ocean.common.vo.AuthUserEntity; import com.oriole.ocean.common.vo.BusinessException; import com.oriole.ocean.common.vo.MsgEntity; -import com.oriole.ocean.service.FileExtraServiceImpl; -import com.oriole.ocean.service.FileServiceImpl; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; @@ -21,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.oriole.ocean.service.*; + import java.util.HashMap; import java.util.List; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocInfoController.java b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocInfoController.java index c3147b5..cc17eec 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocInfoController.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocInfoController.java @@ -1,6 +1,7 @@ package com.oriole.ocean.controller; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.oriole.ocean.common.auth.AuthUser; import com.oriole.ocean.common.enumerate.BehaviorType; import com.oriole.ocean.common.enumerate.MainType; @@ -16,10 +17,8 @@ import com.oriole.ocean.service.FileServiceImpl; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.http.HttpHeaders; +import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.Comparator; @@ -43,16 +42,15 @@ public class DocInfoController { FileCheckServiceImpl fileCheckService; @RequestMapping(value = "/getFileList", method = RequestMethod.GET) - public MsgEntity> getFileList(@AuthUser AuthUserEntity authUser, + public MsgEntity> getFileList(@AuthUser AuthUserEntity authUser, @RequestParam(required = false) String username, @RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam Boolean isFolder) { username = authUser.getAllowOperationUsername(username); - Page page = new Page<>(pageNum, pageSize); - - Page fileEntityListPage = fileService.getFileDetailsInfoListByUsername(username, true, isFolder, page); - return new MsgEntity<>("SUCCESS", "1", fileEntityListPage); + PageHelper.startPage(pageNum, pageSize, true); + PageInfo fileEntityListPageInfo = new PageInfo<>(fileService.getFileDetailsInfoListByUsername(username, true, isFolder)); + return new MsgEntity<>("SUCCESS", "1", fileEntityListPageInfo); } @RequestMapping(value = "/getFileListByFolderID", method = RequestMethod.GET) @@ -126,21 +124,21 @@ public MsgEntity changeDocumentInfo(@AuthUser AuthUserEntity authUser, @ } @RequestMapping(value = "/getNotAcceptedFileList", method = RequestMethod.GET) - public MsgEntity> getNotAcceptedFileList(@AuthUser AuthUserEntity authUser, + public MsgEntity> getNotAcceptedFileList(@AuthUser AuthUserEntity authUser, @RequestParam(required = false) String username, @RequestParam Integer pageNum, @RequestParam Integer pageSize) { username = authUser.getAllowOperationUsername(username); - Page page = new Page<>(pageNum, pageSize); - - Page resultPage = fileService.getFileDetailsInfoListByUsername(username, false, false, page); - resultPage.getRecords().forEach(fileEntity -> { + PageHelper.startPage(pageNum, pageSize, true); + List fileEntityList = fileService.getFileDetailsInfoListByUsername(username, false, false); + fileEntityList.forEach(fileEntity -> { if (!fileEntity.getIsApproved().equals((byte) 0)) { FileCheckEntity fileCheckEntity = fileCheckService.getFileCheckInfo(fileEntity.getFileID()); fileEntity.setFileCheckEntity(fileCheckEntity); } }); - return new MsgEntity<>("SUCCESS", "1", resultPage); + PageInfo fileEntityListPageInfo = new PageInfo<>(fileEntityList); + return new MsgEntity<>("SUCCESS", "1", fileEntityListPageInfo); } @RequestMapping(value = "/getRecentlyReadList", method = RequestMethod.GET) diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/dao/FileDao.java b/ocean-docs-service/src/main/java/com/oriole/ocean/dao/FileDao.java index 7000cf5..ee53e1d 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/dao/FileDao.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/dao/FileDao.java @@ -1,7 +1,6 @@ package com.oriole.ocean.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.oriole.ocean.common.po.mysql.FileEntity; import org.apache.ibatis.annotations.Param; @@ -9,8 +8,8 @@ public interface FileDao extends BaseMapper { - Page getFileListByTypeIDAndTagIDAndIndexString(Page page, Integer typeID, String[] tagIDs, String indexString); - Page getFileListByUsername(Page page, String username,Boolean isApproved, Boolean isFolder); + List getFileListByTypeIDAndTagIDAndIndexString(Integer typeID,String[] tagIDs,String indexString); + List getFileListByUsername(String username,Boolean isApproved, Boolean isFolder); List getFileListByFolderID(String folderID); FileEntity getFileDetailInfoById(@Param("fileID") Integer fileID); diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTagServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTagServiceImpl.java index 9c78326..84be1b2 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTagServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTagServiceImpl.java @@ -1,8 +1,8 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.po.mysql.FileTagEntity; import com.oriole.ocean.dao.TagDao; +import com.oriole.ocean.common.po.mysql.FileTagEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTypeServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTypeServiceImpl.java index 25a0237..e20f014 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTypeServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocTypeServiceImpl.java @@ -2,8 +2,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.po.mysql.FileTypeEntity; import com.oriole.ocean.dao.TypeDao; +import com.oriole.ocean.common.po.mysql.FileTypeEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java index 6ab15a3..9d9788e 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java @@ -1,21 +1,23 @@ package com.oriole.ocean.service; -import co.elastic.clients.elasticsearch.core.search.CompletionSuggester; -import co.elastic.clients.elasticsearch.core.search.Suggester; import com.oriole.ocean.common.po.es.FileSearchEntity; -import jakarta.annotation.Resource; +import org.elasticsearch.common.unit.Fuzziness; +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; +import org.elasticsearch.search.suggest.Suggest; +import org.elasticsearch.search.suggest.SuggestBuilder; +import org.elasticsearch.search.suggest.SuggestBuilders; +import org.elasticsearch.search.suggest.completion.CompletionSuggestion; +import org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder; import org.springframework.data.domain.PageRequest; -import org.springframework.data.elasticsearch.client.elc.NativeQuery; -import org.springframework.data.elasticsearch.client.elc.NativeQueryBuilder; -import org.springframework.data.elasticsearch.core.ElasticsearchOperations; +import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; import org.springframework.data.elasticsearch.core.SearchHits; -import org.springframework.data.elasticsearch.core.query.HighlightQuery; -import org.springframework.data.elasticsearch.core.query.highlight.Highlight; -import org.springframework.data.elasticsearch.core.query.highlight.HighlightField; -import org.springframework.data.elasticsearch.core.query.highlight.HighlightFieldParameters; -import org.springframework.data.elasticsearch.core.suggest.response.Suggest; +import org.springframework.data.elasticsearch.core.query.NativeSearchQuery; +import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.stereotype.Service; +import jakarta.annotation.Resource; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; @@ -25,50 +27,29 @@ public class ESearchServiceImpl { @Resource - private ElasticsearchOperations elasticsearchOperations; + private ElasticsearchRestTemplate elasticsearchRestTemplate; public SearchHits searchFile(String keywords, Integer page, Integer rows) { + BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery() + .should(QueryBuilders.fuzzyQuery("analyzer_title", keywords).fuzziness(Fuzziness.AUTO)) + .should(QueryBuilders.fuzzyQuery("analyzer_content", keywords).fuzziness(Fuzziness.AUTO)) + .should(QueryBuilders.fuzzyQuery("analyzer_abstract_content", keywords).fuzziness(Fuzziness.AUTO)) + .must(QueryBuilders.multiMatchQuery(keywords,"analyzer_title","analyzer_content","analyzer_abstract_content")) + .must(QueryBuilders.matchQuery("is_approved", "true"));//必须是已经被核准的才能被检索出来 - HighlightFieldParameters highlightFieldParameters = HighlightFieldParameters.builder() - .withMatchedFields( - "analyzer_title", - "analyzer_abstract_content", - "analyzer_content" - ) - .withPreTags("") - .withPostTags("") - .build(); //构建高亮查询 - Highlight highlight = new Highlight( - List.of( - new HighlightField("analyzer_title", - highlightFieldParameters), - new HighlightField("analyzer_abstract_content", - highlightFieldParameters), - new HighlightField("analyzer_content", - highlightFieldParameters) - ) - ); - HighlightQuery highlightQuery = new HighlightQuery(highlight, FileSearchEntity.class); - - NativeQuery searchQuery = new NativeQueryBuilder() - .withQuery(q -> q - .multiMatch(m -> m - .query(keywords) - .fields( - "analyzer_title", - "analyzer_content", - "analyzer_abstract_content"))) - .withQuery(q -> q - .match(m -> m - .query("true") - .field("is_approved"))) - .withHighlightQuery(highlightQuery) - .withPageable(PageRequest.of(page - 1, rows)) - .build(); + NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(boolQueryBuilder) + .withHighlightFields( + new HighlightBuilder.Field("analyzer_title"), + new HighlightBuilder.Field("analyzer_abstract_content"), + new HighlightBuilder.Field("analyzer_content")) + .withHighlightBuilder(new HighlightBuilder().preTags("").postTags("")) + .withPageable(PageRequest.of(page - 1, rows)).build(); - return elasticsearchOperations.search(searchQuery, FileSearchEntity.class); + SearchHits searchHits = elasticsearchRestTemplate.search(searchQuery, FileSearchEntity.class); + return searchHits; } public ArrayList suggestTitle(String keyword,Integer rows) { return suggest("suggest_title",keyword,rows); @@ -77,32 +58,25 @@ public ArrayList suggestTitle(String keyword,Integer rows) { public ArrayList suggest(String fieldName, String keyword,Integer rows) { HashSet returnSet = new LinkedHashSet<>(); // 用于存储查询到的结果 // 创建CompletionSuggestionBuilder - CompletionSuggester.Builder textBuilder = new CompletionSuggester.Builder() - .field(fieldName) - .size(rows) - .skipDuplicates(true); - - // 创建nativeQuery并将completionBuilder添加进去 - NativeQuery nativeQuery = new NativeQueryBuilder() - .withSuggester(Suggester.of(s -> s - .suggesters("suggest_text", a -> a - .completion(textBuilder.build()) - .prefix(keyword)))) - .build(); + CompletionSuggestionBuilder textBuilder = SuggestBuilders.completionSuggestion(fieldName) // 指定字段名 + .size(rows) // 设定返回数量 + .skipDuplicates(true); // 去重 + // 创建suggestBuilder并将completionBuilder添加进去 + SuggestBuilder suggestBuilder = new SuggestBuilder(); + suggestBuilder.addSuggestion("suggest_text", textBuilder) + .setGlobalText(keyword); // 执行请求 - SearchHits searchHits = elasticsearchOperations.search(nativeQuery, FileSearchEntity.class); - + Suggest suggest = elasticsearchRestTemplate.suggest(suggestBuilder, elasticsearchRestTemplate.getIndexCoordinatesFor(FileSearchEntity.class)).getSuggest(); // 取出结果 - if(searchHits.hasSuggest()) { - Suggest suggest = searchHits.getSuggest(); - var textSuggestion = suggest.getSuggestion("suggest_text"); - for (var entry : textSuggestion.getEntries()) { - for (Suggest.Suggestion.Entry.Option option : entry.getOptions()) { - returnSet.add(option.getText()); - } + Suggest.Suggestion> textSuggestion = suggest.getSuggestion("suggest_text"); + for (Suggest.Suggestion.Entry entry : textSuggestion.getEntries()) { + List options = entry.getOptions(); + for (Suggest.Suggestion.Entry.Option option : options) { + returnSet.add(option.getText().toString()); } } return new ArrayList<>(returnSet); } + } diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileCheckServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileCheckServiceImpl.java index fe5be04..1656b86 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileCheckServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileCheckServiceImpl.java @@ -1,8 +1,8 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.po.mysql.FileCheckEntity; import com.oriole.ocean.dao.FileCheckDao; +import com.oriole.ocean.common.po.mysql.FileCheckEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileExtraServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileExtraServiceImpl.java index 6077153..d1189f7 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileExtraServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileExtraServiceImpl.java @@ -4,9 +4,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.oriole.ocean.common.enumerate.DocStatisticItemType; import com.oriole.ocean.common.enumerate.EvaluateType; -import com.oriole.ocean.common.po.mysql.FileExtraEntity; import com.oriole.ocean.common.service.FileExtraService; import com.oriole.ocean.dao.FileExtraDao; +import com.oriole.ocean.common.po.mysql.FileExtraEntity; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileSearchServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileSearchServiceImpl.java index a2b6cbe..25fa590 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileSearchServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileSearchServiceImpl.java @@ -1,9 +1,9 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.po.mysql.FileSearchEntity; import com.oriole.ocean.common.service.FileSearchService; import com.oriole.ocean.dao.FileSearchDao; +import com.oriole.ocean.common.po.mysql.FileSearchEntity; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java index f638d3e..4235745 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java @@ -1,17 +1,16 @@ package com.oriole.ocean.service; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.po.mysql.FileEntity; import com.oriole.ocean.common.po.mysql.FileExtraEntity; import com.oriole.ocean.common.service.FileService; import com.oriole.ocean.dao.FileDao; -import jakarta.annotation.Resource; +import com.oriole.ocean.common.po.mysql.FileEntity; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import jakarta.annotation.Resource; import java.util.List; @Service @@ -35,17 +34,17 @@ public FileEntity getFileDetailsInfoByFileID(Integer fileIDs) { } //文章详细信息查询(通过用户名查询)(可区分是否已被审核) - public Page getFileDetailsInfoListByUsername(String username, Boolean isApproved, Boolean isFolder, Page page) { - return fileDao.getFileListByUsername(page, username, isApproved, isFolder); + public List getFileDetailsInfoListByUsername(String username, Boolean isApproved, Boolean isFolder) { + return fileDao.getFileListByUsername(username, isApproved, isFolder); } //文章详细信息查询(通过分类ID、标签ID和索引字符串查询) - public Page getFileDetailsInfoListByTypeIDAndTagStringAndIndexString(Integer typeID, String tagString, String indexString, Page page) { + public List getFileDetailsInfoListByTypeIDAndTagStringAndIndexString(Integer typeID, String tagString, String indexString) { String[] tagIDs = new String[0]; if (!tagString.isEmpty() && !tagString.equals("null")) { tagIDs = tagString.split("\\,"); } - return fileDao.getFileListByTypeIDAndTagIDAndIndexString(page, typeID, tagIDs, indexString + "%"); + return fileDao.getFileListByTypeIDAndTagIDAndIndexString(typeID, tagIDs, indexString + "%"); } //文章详细信息查询(通过FolderID查询) diff --git a/ocean-docs-service/src/main/resources/bootstrap.yaml b/ocean-docs-service/src/main/resources/bootstrap.yaml index d9114c6..c2b277b 100644 --- a/ocean-docs-service/src/main/resources/bootstrap.yaml +++ b/ocean-docs-service/src/main/resources/bootstrap.yaml @@ -21,8 +21,4 @@ dubbo: protocol: port: -1 consumer: - check: false -logging: - level: - org: - DEBUG \ No newline at end of file + check: false \ No newline at end of file diff --git a/ocean-gateway/pom.xml b/ocean-gateway/pom.xml index e32ec73..9bd9156 100644 --- a/ocean-gateway/pom.xml +++ b/ocean-gateway/pom.xml @@ -50,20 +50,6 @@ jjwt-api 0.12.6 - - - io.jsonwebtoken - jjwt-impl - 0.12.6 - runtime - - - - io.jsonwebtoken - jjwt-jackson - 0.12.6 - runtime - com.auth0 @@ -84,6 +70,14 @@ org.junit.jupiter junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 test diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java index 6447bf1..cb7513a 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java @@ -1,8 +1,6 @@ package com.oriole.ocean.gateway.config; -import com.oriole.ocean.gateway.security.AccessDeniedHandler; -import com.oriole.ocean.gateway.security.AuthenticationEntryPoint; -import com.oriole.ocean.gateway.security.SecurityRepository; +import com.oriole.ocean.gateway.security.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java index b04888f..02e9e98 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java @@ -21,10 +21,8 @@ import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; - import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; +import java.util.*; @Slf4j @Component diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AccessDeniedHandler.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AccessDeniedHandler.java index 0c492bd..9ba5704 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AccessDeniedHandler.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AccessDeniedHandler.java @@ -8,9 +8,9 @@ import org.springframework.http.HttpStatus; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.security.access.AccessDeniedException; +import org.springframework.web.server.ServerWebExchange; import org.springframework.security.web.server.authorization.ServerAccessDeniedHandler; import org.springframework.stereotype.Component; -import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; @Slf4j diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AuthenticationEntryPoint.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AuthenticationEntryPoint.java index 8c13548..50a32d7 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AuthenticationEntryPoint.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/AuthenticationEntryPoint.java @@ -9,8 +9,8 @@ import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.server.authentication.HttpBasicServerAuthenticationEntryPoint; -import org.springframework.stereotype.Component; import org.springframework.web.server.ServerWebExchange; +import org.springframework.stereotype.Component; import reactor.core.publisher.Mono; @Slf4j diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java index 63484e3..4450abf 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java @@ -18,7 +18,7 @@ import java.util.ArrayList; import java.util.Collection; -import static org.springframework.security.core.context.SecurityContextHolder.createEmptyContext; +import static org.springframework.security.core.context.SecurityContextHolder.*; @Slf4j @Component diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java index 84d62a1..4b484f3 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java @@ -6,7 +6,7 @@ import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.security.Keys; import org.apache.commons.codec.binary.Base64; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -26,7 +26,6 @@ @Component public class JwtUtils { private final String base64EncodedSecretKey; - private final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; public JwtUtils(@Value("${auth.login.token.secretkey}") String secretKey) { this.base64EncodedSecretKey = Base64.encodeBase64String(secretKey.getBytes()); @@ -58,7 +57,7 @@ public String encode(String iss, long ttlMillis, Map claims) { .id(UUID.randomUUID().toString())//2. 这个是JWT的唯一标识,一般设置成唯一的,这个方法可以生成唯一标识 .issuedAt(new Date(nowMillis))//1. 这个地方就是以毫秒为单位,换算当前系统时间生成的iat .subject(iss)//3. 签发人,也就是JWT是给谁的(逻辑上一般都是username或者userId) - .signWith(signatureAlgorithm, base64EncodedSecretKey);;//这个地方是生成jwt使用的算法和秘钥 + .signWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes()));//这个地方是生成jwt使用的算法和秘钥 if (ttlMillis >= 0) { long expMillis = nowMillis + ttlMillis; Date exp = new Date(expMillis);//4. 过期时间,这个也是使用毫秒生成的,使用当前时间+前面传入的持续时间生成 @@ -74,11 +73,11 @@ public Claims decode(String jwtToken) { // 得到 DefaultJwtParser return Jwts.parser() // 设置签名的秘钥 - .setSigningKey(base64EncodedSecretKey) + .verifyWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes())) .build() // 设置需要解析的 jwt - .parseClaimsJws(jwtToken) - .getBody(); + .parseSignedClaims(jwtToken) + .getPayload(); } //判断jwtToken是否合法 diff --git a/ocean-note-service/pom.xml b/ocean-note-service/pom.xml index cf4950f..d942c90 100644 --- a/ocean-note-service/pom.xml +++ b/ocean-note-service/pom.xml @@ -49,6 +49,10 @@ org.apache.dubbo.extensions dubbo-serialization-kryo + + com.esotericsoftware + kryo + de.javakaffee kryo-serializers @@ -58,7 +62,13 @@ com.alibaba.cloud spring-cloud-starter-alibaba-sentinel + + + + io.swagger.core.v3 + swagger-annotations-jakarta + org.springdoc @@ -76,22 +86,54 @@ com.mysql mysql-connector-j + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 3.0.4 + com.baomidou - mybatis-plus-spring-boot3-starter - 3.5.7 + mybatis-plus-boot-starter + 3.3.2 + + + + com.github.pagehelper + pagehelper + 6.0.0 - com.github.jsqlparser - jsqlparser - 4.9 + com.github.pagehelper + pagehelper-spring-boot-autoconfigure + 2.0.0 + + com.github.pagehelper + pagehelper-spring-boot-starter + 2.0.0 + + + org.mybatis + mybatis + + + + org.junit.jupiter junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 test diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/OceanNoteServiceApplication.java b/ocean-note-service/src/main/java/com/oriole/ocean/OceanNoteServiceApplication.java index 83067cf..d4cdfd9 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/OceanNoteServiceApplication.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/OceanNoteServiceApplication.java @@ -1,12 +1,10 @@ package com.oriole.ocean; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; -import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -@MapperScan(basePackages = "com.oriole.ocean.dao") @EnableDubbo public class OceanNoteServiceApplication { public static void main(String[] args) { diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java b/ocean-note-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java index b58e588..07bfe5b 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java @@ -1,7 +1,7 @@ package com.oriole.ocean.config; -import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +import org.mybatis.spring.mapper.MapperScannerConfigurer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -11,10 +11,15 @@ public class MybatisPlusConfig { * 分页插件 */ @Bean - public MybatisPlusInterceptor mybatisPlusInterceptor() { - MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); - // 添加分页插件 - interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); - return interceptor; + public PaginationInterceptor paginationInterceptor() { + return new PaginationInterceptor(); + } + + @Bean + public MapperScannerConfigurer mapperScannerConfigurer(){ + MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer(); + //可以通过环境变量获取你的mapper路径,这样mapper扫描可以通过配置文件配置了 + scannerConfigurer.setBasePackage("com.oriole.ocean.dao"); + return scannerConfigurer; } } \ No newline at end of file diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index eda90f9..a129929 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -1,6 +1,7 @@ package com.oriole.ocean.controller; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.oriole.ocean.common.po.mysql.NoteEntity; import com.oriole.ocean.common.po.mysql.NoteTypeEntity; import com.oriole.ocean.common.vo.MsgEntity; @@ -30,12 +31,10 @@ public MsgEntity> getAllNoteType() { } @RequestMapping(value = "/getNoteByNoteType",method = RequestMethod.GET) - public MsgEntity> getNoteByNoteType(@RequestParam(required = false) Integer noteType,@RequestParam Integer pageNum, @RequestParam Integer pageSize) { - - Page page = new Page<>(pageNum, pageSize); - - Page resultPage = noteService.getNoteByNoteType(noteType, page); - - return new MsgEntity<>("SUCCESS", "1", resultPage); + public MsgEntity> getNoteByNoteType(@RequestParam(required = false) Integer noteType,@RequestParam Integer pageNum, @RequestParam Integer pageSize) { + PageHelper.startPage(pageNum, pageSize, true); + List noteEntityList = noteService.getNoteByNoteType(noteType); + PageInfo pageInfo = new PageInfo<>(noteEntityList); + return new MsgEntity<>("SUCCESS", "1", pageInfo); } } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java index dc7cb8e..2ad3710 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java @@ -1,21 +1,22 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.po.mysql.NoteEntity; import com.oriole.ocean.dao.NoteDao; +import com.oriole.ocean.common.po.mysql.NoteEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Service @Transactional public class NoteService extends ServiceImpl { - public Page getNoteByNoteType(Integer noteType, Page page){ + public List getNoteByNoteType(Integer noteType){ QueryWrapper queryWrapper = new QueryWrapper<>(); if(noteType!=null) { queryWrapper.eq("note_type", noteType); } - return page(page, queryWrapper); + return list(queryWrapper); } } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java index c6a8cd5..b021e9a 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java @@ -1,8 +1,8 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.po.mysql.NoteTypeEntity; import com.oriole.ocean.dao.NoteTypeDao; +import com.oriole.ocean.common.po.mysql.NoteTypeEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-notify-service/pom.xml b/ocean-notify-service/pom.xml index f0b4ae3..c10786d 100644 --- a/ocean-notify-service/pom.xml +++ b/ocean-notify-service/pom.xml @@ -49,6 +49,10 @@ org.apache.dubbo.extensions dubbo-serialization-kryo + + com.esotericsoftware + kryo + de.javakaffee kryo-serializers @@ -58,7 +62,13 @@ com.alibaba.cloud spring-cloud-starter-alibaba-sentinel + + + + io.swagger.core.v3 + swagger-annotations-jakarta + org.springdoc @@ -71,23 +81,54 @@ com.mysql mysql-connector-j + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 3.0.4 + - com.baomidou - mybatis-plus-spring-boot3-starter - 3.5.7 + mybatis-plus-boot-starter + 3.3.2 + + + + com.github.pagehelper + pagehelper + 6.0.0 - com.github.jsqlparser - jsqlparser - 4.9 + com.github.pagehelper + pagehelper-spring-boot-autoconfigure + 2.0.0 + + com.github.pagehelper + pagehelper-spring-boot-starter + 2.0.0 + + + org.mybatis + mybatis + + + + org.junit.jupiter junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 test diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/OceanNotifyApplication.java b/ocean-notify-service/src/main/java/com/oriole/ocean/OceanNotifyApplication.java index 48eb039..9bee39a 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/OceanNotifyApplication.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/OceanNotifyApplication.java @@ -1,13 +1,11 @@ package com.oriole.ocean; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; -import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -@MapperScan(basePackages = "com.oriole.ocean.dao") -@EnableDubbo(scanBasePackages = "com.oriole.ocean.service") +@EnableDubbo public class OceanNotifyApplication { public static void main(String[] args) { SpringApplication.run(OceanNotifyApplication.class, args); diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java b/ocean-notify-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java index b58e588..07bfe5b 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java @@ -1,7 +1,7 @@ package com.oriole.ocean.config; -import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +import org.mybatis.spring.mapper.MapperScannerConfigurer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -11,10 +11,15 @@ public class MybatisPlusConfig { * 分页插件 */ @Bean - public MybatisPlusInterceptor mybatisPlusInterceptor() { - MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); - // 添加分页插件 - interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); - return interceptor; + public PaginationInterceptor paginationInterceptor() { + return new PaginationInterceptor(); + } + + @Bean + public MapperScannerConfigurer mapperScannerConfigurer(){ + MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer(); + //可以通过环境变量获取你的mapper路径,这样mapper扫描可以通过配置文件配置了 + scannerConfigurer.setBasePackage("com.oriole.ocean.dao"); + return scannerConfigurer; } } \ No newline at end of file diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java index e9da9e1..06c50d6 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java @@ -5,9 +5,9 @@ import com.oriole.ocean.common.enumerate.NotifyAction; import com.oriole.ocean.common.enumerate.NotifyType; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; -import com.oriole.ocean.common.po.mysql.NotifyEntity; import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.dao.NotifyDao; +import com.oriole.ocean.common.po.mysql.NotifyEntity; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.stereotype.Service; diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifySubscriptionServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifySubscriptionServiceImpl.java index 4ef3e9e..feeff95 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifySubscriptionServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifySubscriptionServiceImpl.java @@ -4,13 +4,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.oriole.ocean.common.enumerate.NotifyAction; import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; -import com.oriole.ocean.common.po.mysql.NotifySubscriptionEntity; import com.oriole.ocean.common.service.NotifySubscriptionService; import com.oriole.ocean.dao.NotifySubscriptionDao; +import com.oriole.ocean.common.po.mysql.NotifySubscriptionEntity; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; @Service diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java index cff96fa..478a07b 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java @@ -2,11 +2,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.po.mysql.UserNotifyEntity; import com.oriole.ocean.dao.UserNotifyDao; -import jakarta.annotation.Resource; +import com.oriole.ocean.common.po.mysql.UserNotifyEntity; import org.springframework.stereotype.Service; +import jakarta.annotation.Resource; import java.util.Date; import java.util.List; diff --git a/ocean-user-behavior-service/pom.xml b/ocean-user-behavior-service/pom.xml index 3c70b0c..b6fb809 100644 --- a/ocean-user-behavior-service/pom.xml +++ b/ocean-user-behavior-service/pom.xml @@ -49,6 +49,10 @@ org.apache.dubbo.extensions dubbo-serialization-kryo + + com.esotericsoftware + kryo + de.javakaffee kryo-serializers @@ -71,12 +75,21 @@ org.junit.jupiter junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 test org.junit junit-bom + 5.12.1 pom test diff --git a/ocean-user-service/pom.xml b/ocean-user-service/pom.xml index ed4e0ba..9e10518 100644 --- a/ocean-user-service/pom.xml +++ b/ocean-user-service/pom.xml @@ -47,6 +47,13 @@ log4j-core 2.24.3 + + + org.slf4j + slf4j-reload4j + 2.0.17 + test + org.springframework.boot @@ -78,6 +85,10 @@ org.apache.dubbo.extensions dubbo-serialization-kryo + + com.esotericsoftware + kryo + de.javakaffee kryo-serializers @@ -87,7 +98,13 @@ com.alibaba.cloud spring-cloud-starter-alibaba-sentinel + + + + io.swagger.core.v3 + swagger-annotations-jakarta + org.springdoc @@ -100,29 +117,66 @@ com.mysql mysql-connector-j + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 3.0.4 + com.baomidou - mybatis-plus-spring-boot3-starter - 3.5.7 + mybatis-plus-boot-starter + 3.5.10.1 + + + + + com.github.pagehelper + pagehelper + 6.1.0 + + + + org.springframework.boot + spring-boot-autoconfigure + 3.3.9 + - com.github.jsqlparser - jsqlparser - 4.9 + com.github.pagehelper + pagehelper-spring-boot-starter + 2.1.0 + + + org.mybatis + mybatis + + + org.junit.jupiter junit-jupiter-api + 5.12.1 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 test org.junit junit-bom + 5.12.1 pom test @@ -136,7 +190,19 @@ org.springframework spring-context - 6.1.14 + 5.3.31 + + + com.baomidou + mybatis-plus-extension + 3.5.10.1 + compile + + + + com.baomidou + mybatis-plus-jsqlparser + 3.5.10.1 diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/OceanUserServiceApplication.java b/ocean-user-service/src/main/java/com/oriole/ocean/OceanUserServiceApplication.java index 3a4833a..f06ccf1 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/OceanUserServiceApplication.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/OceanUserServiceApplication.java @@ -1,12 +1,10 @@ package com.oriole.ocean; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; -import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -@MapperScan(basePackages = "com.oriole.ocean.dao") @EnableDubbo public class OceanUserServiceApplication { public static void main(String[] args) { diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java b/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java index 02e940a..c71cfaa 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java @@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.mybatis.spring.mapper.MapperScannerConfigurer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -16,4 +17,12 @@ public MybatisPlusInterceptor mybatisPlusInterceptor() { interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); return interceptor; } + + @Bean + public MapperScannerConfigurer mapperScannerConfigurer(){ + MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer(); + //可以通过环境变量获取你的mapper路径,这样mapper扫描可以通过配置文件配置了 + scannerConfigurer.setBasePackage("com.oriole.ocean.dao"); + return scannerConfigurer; + } } \ No newline at end of file diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/controller/AuthController.java b/ocean-user-service/src/main/java/com/oriole/ocean/controller/AuthController.java index 37f7269..1df8023 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/controller/AuthController.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/controller/AuthController.java @@ -1,12 +1,15 @@ package com.oriole.ocean.controller; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSON; import com.oriole.ocean.common.po.mysql.UserEntity; -import com.oriole.ocean.common.vo.MsgEntity; import com.oriole.ocean.service.base.UserBaseInfoServiceImpl; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import com.oriole.ocean.common.vo.MsgEntity; import org.springframework.web.bind.annotation.RestController; @RestController diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java index a05dd77..4f36fe8 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java @@ -10,10 +10,7 @@ import com.oriole.ocean.service.base.UserBaseInfoServiceImpl; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @Slf4j diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserWalletController.java b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserWalletController.java index 2da2eb3..c23e632 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserWalletController.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserWalletController.java @@ -1,6 +1,6 @@ package com.oriole.ocean.controller; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.pagehelper.PageInfo; import com.oriole.ocean.common.auth.AuthUser; import com.oriole.ocean.common.po.mysql.WalletChangeRecordEntity; import com.oriole.ocean.common.vo.AuthUserEntity; @@ -20,17 +20,8 @@ public class UserWalletController { UserWalletChangeRecordServiceImpl walletChangeRecordService; @RequestMapping(value = "/getWalletChangeRecord",method = RequestMethod.GET) - public MsgEntity> getWalletChangeRecord( - @AuthUser AuthUserEntity authUser, - @RequestParam Integer pageNum, - @RequestParam Integer pageSize) { - - Page pageResult = walletChangeRecordService.getWalletChangeRecord( - authUser.getUsername(), - pageNum, - pageSize - ); - - return new MsgEntity<>("SUCCESS", "1", pageResult); + public MsgEntity> getWalletChangeRecord(@AuthUser AuthUserEntity authUser, @RequestParam Integer pageNum, @RequestParam Integer pageSize) { + return new MsgEntity<>("SUCCESS", "1", + walletChangeRecordService.getWalletChangeRecord(authUser.getUsername(),pageNum,pageSize)); } } diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/controller/api/WalletController.java b/ocean-user-service/src/main/java/com/oriole/ocean/controller/api/WalletController.java index 24d5806..e7beba6 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/controller/api/WalletController.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/controller/api/WalletController.java @@ -6,10 +6,7 @@ import com.oriole.ocean.common.enumerate.WalletMoneyType; import com.oriole.ocean.service.base.UserWalletServiceImpl; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/walletAPI") diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/UserFunctionServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/UserFunctionServiceImpl.java index 4662b94..11fbe6d 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/UserFunctionServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/UserFunctionServiceImpl.java @@ -5,6 +5,7 @@ import com.oriole.ocean.common.service.UserBehaviorService; import com.oriole.ocean.common.vo.BusinessException; import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/UserInfoServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/UserInfoServiceImpl.java index f40d48d..97ec15a 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/UserInfoServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/UserInfoServiceImpl.java @@ -2,12 +2,15 @@ import com.oriole.ocean.common.enumerate.UserInfoLevel; import com.oriole.ocean.common.po.mysql.UserEntity; +import com.oriole.ocean.common.vo.BusinessException; +import com.oriole.ocean.common.vo.MsgEntity; import com.oriole.ocean.service.base.UserBaseInfoServiceImpl; import com.oriole.ocean.service.base.UserCertificationServiceImpl; import com.oriole.ocean.service.base.UserExtraInfoServiceImpl; import com.oriole.ocean.service.base.UserWalletServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.RequestParam; @Service public class UserInfoServiceImpl { diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserBaseInfoServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserBaseInfoServiceImpl.java index afefcdd..a5309ce 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserBaseInfoServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserBaseInfoServiceImpl.java @@ -1,11 +1,13 @@ package com.oriole.ocean.service.base; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.po.mysql.UserEntity; import com.oriole.ocean.common.vo.BusinessException; +import com.oriole.ocean.common.vo.MsgEntity; import com.oriole.ocean.dao.UserDao; +import com.oriole.ocean.common.po.mysql.UserEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.RequestParam; @Service @Transactional diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserCertificationServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserCertificationServiceImpl.java index e03d8d1..055b3fd 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserCertificationServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserCertificationServiceImpl.java @@ -1,8 +1,8 @@ package com.oriole.ocean.service.base; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.po.mysql.UserCertificationEntity; import com.oriole.ocean.dao.UserCertificationDao; +import com.oriole.ocean.common.po.mysql.UserCertificationEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserExtraInfoServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserExtraInfoServiceImpl.java index b3a1d51..d386780 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserExtraInfoServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserExtraInfoServiceImpl.java @@ -1,8 +1,8 @@ package com.oriole.ocean.service.base; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.po.mysql.UserExtraEntity; import com.oriole.ocean.dao.UserExtraDao; +import com.oriole.ocean.common.po.mysql.UserExtraEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java index cab5d23..1b9d5a2 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java @@ -1,24 +1,31 @@ package com.oriole.ocean.service.base; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.po.mysql.WalletChangeRecordEntity; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.oriole.ocean.dao.WalletChangeRecordDao; +import com.oriole.ocean.common.po.mysql.WalletChangeRecordEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + +import static com.baomidou.mybatisplus.extension.toolkit.Db.list; + @Service @Transactional public class UserWalletChangeRecordServiceImpl extends ServiceImpl { - public Page getWalletChangeRecord(String username, Integer pageNum, Integer pageSize) { + public PageInfo getWalletChangeRecord(String username, Integer pageNum, Integer pageSize) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("username", username); - Page page = new Page<>(pageNum, pageSize); + PageHelper.startPage(pageNum, pageSize, true); + + List walletChangeRecordEntityList = list(queryWrapper); - return baseMapper.selectPage(page, queryWrapper); + return new PageInfo<>(walletChangeRecordEntityList); } } diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletServiceImpl.java index f76552d..fea2eeb 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletServiceImpl.java @@ -3,14 +3,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.oriole.ocean.common.enumerate.VipOperationState; import com.oriole.ocean.common.enumerate.VipOperationType; -import com.oriole.ocean.common.po.mysql.WalletChangeRecordEntity; -import com.oriole.ocean.common.po.mysql.WalletEntity; import com.oriole.ocean.common.service.UserWalletService; import com.oriole.ocean.dao.WalletDao; +import com.oriole.ocean.common.po.mysql.WalletChangeRecordEntity; +import com.oriole.ocean.common.po.mysql.WalletEntity; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.RequestParam; @Service @DubboService diff --git a/ocean-user-service/src/test/java/com/oriole/AppTest.java b/ocean-user-service/src/test/java/com/oriole/AppTest.java index e6782ee..06fc0f9 100644 --- a/ocean-user-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-user-service/src/test/java/com/oriole/AppTest.java @@ -1,7 +1,7 @@ package com.oriole; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; /** * Unit test for simple App. diff --git a/pom.xml b/pom.xml index 77a7cb8..9836a55 100644 --- a/pom.xml +++ b/pom.xml @@ -63,6 +63,12 @@ spring-boot-starter-web 3.3.9 + + + org.junit.platform + junit-platform-surefire-provider + 1.3.2 + org.junit.jupiter @@ -70,6 +76,13 @@ 5.12.1 test + + + org.junit.jupiter + junit-jupiter-engine + 5.12.1 + test + org.junit @@ -109,16 +122,33 @@ com.alibaba.cloud spring-cloud-alibaba-dependencies - 2023.0.1.2 + 2023.0.3.2 pom - import + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + 2023.0.3.2 + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2023.0.3.2 + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + 2023.0.3.2 org.springframework.cloud spring-cloud-dependencies - 2023.0.1 + 2023.0.3 pom import From 3b641a2c176e41c41e52a9aa64e7a93c07fc7419 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Wed, 16 Apr 2025 12:42:26 +0800 Subject: [PATCH 06/62] Revert "chore: update all dependencies" This reverts commit 7eb1c573f6eafbf56bed0b54bc511d74532b4cb0. --- .idea/compiler.xml | 4 +- .idea/jarRepositories.xml | 5 - .idea/libraries/projectlombok_lombok.xml | 10 - ocean-collection-service/pom.xml | 75 +------- .../oriole/ocean/config/Swagger2Config.java | 37 ++++ .../oriole/ocean/config/SwaggerConfig.java | 40 ---- .../controller/UserCollectionController.java | 6 +- .../service/UserCollectionServiceImpl.java | 2 +- .../src/main/resources/bootstrap.yaml | 1 - .../src/test/java/com/oriole/AppTest.java | 30 ++- ocean-comment-service/pom.xml | 58 +----- .../oriole/ocean/config/Swagger2Config.java | 37 ++++ .../oriole/ocean/config/SwaggerConfig.java | 40 ---- .../controller/UserCommentController.java | 32 ++-- .../ocean/service/CommentServiceImpl.java | 2 +- .../src/main/resources/bootstrap.yaml | 1 - .../src/test/java/com/oriole/AppTest.java | 30 ++- ocean-common/pom.xml | 21 +-- .../auth/AuthUserMethodArgumentResolver.java | 2 +- .../ocean/common/enumerate/ResultCode.java | 1 + .../common/po/mongo/UserBehaviorEntity.java | 2 +- .../po/mongo/comment/CommentEntity.java | 2 - .../po/mongo/comment/CommentReplyEntity.java | 2 - .../ocean/common/po/mysql/UserEntity.java | 6 +- .../common/service/UserBehaviorService.java | 1 + .../oriole/ocean/common/tools/JwtUtils.java | 31 ++-- .../ocean/common/vo/BusinessException.java | 15 +- ocean-docs-file-service/pom.xml | 81 +------- .../ocean/controller/DocIOController.java | 2 +- .../utils/objectStorage/AliOSSUtils.java | 2 +- .../objectStorage/ObjectStorageUtils.java | 2 +- .../src/main/resources/bootstrap.yaml | 1 - .../src/test/java/com/oriole/AppTest.java | 30 ++- ocean-docs-service/pom.xml | 70 +------ .../controller/DocFunctionController.java | 2 +- .../ocean/service/ESearchServiceImpl.java | 2 +- .../oriole/ocean/service/FileServiceImpl.java | 2 +- .../src/test/java/com/oriole/AppTest.java | 30 ++- ocean-gateway/pom.xml | 34 +--- .../gateway/config/WebSecurityConfig.java | 31 ++-- .../filter/UserAuthGatewayFilterFactory.java | 2 +- .../gateway/security/SecurityRepository.java | 2 +- .../oriole/ocean/gateway/tools/JwtUtils.java | 31 ++-- .../src/test/java/com/oriole/AppTest.java | 30 ++- ocean-note-service/pom.xml | 59 +----- .../src/main/resources/bootstrap.yaml | 1 - .../src/test/java/com/oriole/AppTest.java | 30 ++- ocean-notify-service/pom.xml | 55 +----- .../ocean/service/UserNotifyServiceImpl.java | 2 +- .../src/main/resources/bootstrap.yaml | 1 - .../src/test/java/com/oriole/AppTest.java | 30 ++- ocean-user-behavior-service/pom.xml | 35 +--- .../service/UserBehaviorServiceImpl.java | 2 +- .../src/main/resources/bootstrap.yaml | 1 - .../src/test/java/com/oriole/AppTest.java | 30 ++- ocean-user-service/pom.xml | 120 ++---------- .../ocean/config/MybatisPlusConfig.java | 9 +- .../UserWalletChangeRecordServiceImpl.java | 2 - .../src/main/resources/bootstrap.yaml | 1 - .../src/test/java/com/oriole/AppTest.java | 30 ++- pom.xml | 173 ++---------------- 61 files changed, 490 insertions(+), 938 deletions(-) delete mode 100644 .idea/libraries/projectlombok_lombok.xml create mode 100644 ocean-collection-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java delete mode 100644 ocean-collection-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java create mode 100644 ocean-comment-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java delete mode 100644 ocean-comment-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 16a7e3a..10e6a08 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,6 +2,7 @@ \ No newline at end of file diff --git a/.idea/libraries/projectlombok_lombok.xml b/.idea/libraries/projectlombok_lombok.xml deleted file mode 100644 index 8fe179f..0000000 --- a/.idea/libraries/projectlombok_lombok.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/ocean-collection-service/pom.xml b/ocean-collection-service/pom.xml index c235d3d..fefb62e 100644 --- a/ocean-collection-service/pom.xml +++ b/ocean-collection-service/pom.xml @@ -18,28 +18,6 @@ - - - org.projectlombok - lombok - provided - - - - org.slf4j - slf4j-api - - - - org.apache.logging.log4j - log4j-core - - - - org.slf4j - slf4j-reload4j - test - org.springframework.boot @@ -49,12 +27,6 @@ org.springframework.cloud spring-cloud-starter-bootstrap - - - jakarta.servlet - jakarta.servlet-api - provided - com.alibaba.cloud @@ -73,34 +45,19 @@ org.apache.dubbo dubbo-registry-nacos - - org.apache.dubbo.extensions - dubbo-serialization-kryo - - - com.esotericsoftware - kryo - - - de.javakaffee - kryo-serializers - com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - - - + - io.swagger.core.v3 - swagger-annotations-jakarta + io.springfox + springfox-swagger2 - - org.springdoc - springdoc-openapi-starter-webmvc-ui + io.springfox + springfox-swagger-ui @@ -110,26 +67,10 @@ spring-boot-starter-data-mongodb - - - org.junit.jupiter - junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 - test - - - org.junit - junit-bom - 5.12.1 - pom + junit + junit + 3.8.1 test diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java b/ocean-collection-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java new file mode 100644 index 0000000..fa396a9 --- /dev/null +++ b/ocean-collection-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java @@ -0,0 +1,37 @@ +package com.oriole.ocean.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class Swagger2Config { + + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_12) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.oriole.ocean")) + .paths(PathSelectors.any()) + .build(); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("Lib4Univ 开源高校文库项目 RESTful API列表") + .description("注意不得在生产环境启用Swagger") + .termsOfServiceUrl("http://www.oceanlibrary.cn/") + .contact("基于深度遗忘的程序猿") + .version("2.1") + .build(); + } +} + diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java b/ocean-collection-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java deleted file mode 100644 index b948345..0000000 --- a/ocean-collection-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.oriole.ocean.config; - -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Contact; -import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.info.License; -import org.springdoc.core.models.GroupedOpenApi; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class SwaggerConfig { - - @Bean - public GroupedOpenApi createRestApi() { - return GroupedOpenApi.builder() - .group("wtf") - .packagesToScan("com.oriole.ocean") - .pathsToMatch("/**") - .build(); - } - - @Bean - public OpenAPI openAPI() { - return new OpenAPI() - .info(new Info() - .title("Lib4Univ开源高校文库项目 RESTful API列表") - .description("注意不得在生产环境启用 Swagger") - .version("2.1") - .contact(new Contact() - .name("基于深度遗忘的程序猿") - .url("http://www.oceanlibrary.cn") - .email("null")) - .termsOfService("http://www.oceanlibrary.cn/") - .license(new License() - .name("Apache2.0") - .url("https://www.apache.org/licenses/LICENSE-2.0"))); - } -} - diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java b/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java index 5e0fdbc..700d2a9 100644 --- a/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java +++ b/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java @@ -1,8 +1,8 @@ package com.oriole.ocean.controller; -import com.alibaba.fastjson2.JSON; -import com.alibaba.fastjson2.JSONArray; -import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.oriole.ocean.common.auth.AuthUser; import com.oriole.ocean.common.enumerate.*; import com.oriole.ocean.common.enumerate.MainType; diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java b/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java index 3d216ed..24f35b2 100644 --- a/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java +++ b/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java @@ -1,6 +1,6 @@ package com.oriole.ocean.service; -import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson.JSONObject; import com.oriole.ocean.common.enumerate.DocStatisticItemType; import com.oriole.ocean.common.enumerate.MainType; import com.oriole.ocean.common.po.mysql.UserCollectionEntity; diff --git a/ocean-collection-service/src/main/resources/bootstrap.yaml b/ocean-collection-service/src/main/resources/bootstrap.yaml index 39c89bf..09a2c69 100644 --- a/ocean-collection-service/src/main/resources/bootstrap.yaml +++ b/ocean-collection-service/src/main/resources/bootstrap.yaml @@ -20,6 +20,5 @@ dubbo: group: dubbo protocol: port: -1 - serialization: kryo consumer: check: false diff --git a/ocean-collection-service/src/test/java/com/oriole/AppTest.java b/ocean-collection-service/src/test/java/com/oriole/AppTest.java index 06fc0f9..38e2a80 100644 --- a/ocean-collection-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-collection-service/src/test/java/com/oriole/AppTest.java @@ -1,20 +1,38 @@ package com.oriole; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Assertions; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; /** * Unit test for simple App. */ -public class AppTest +public class AppTest + extends TestCase { + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + /** * Rigourous Test :-) */ - @Test public void testApp() { - System.out.println("Hello World"); - Assertions.assertTrue( true ); + assertTrue( true ); } } diff --git a/ocean-comment-service/pom.xml b/ocean-comment-service/pom.xml index 7849610..f8cba00 100644 --- a/ocean-comment-service/pom.xml +++ b/ocean-comment-service/pom.xml @@ -45,39 +45,19 @@ org.apache.dubbo dubbo-registry-nacos - - org.apache.dubbo.extensions - dubbo-serialization-kryo - - - com.esotericsoftware - kryo - - - de.javakaffee - kryo-serializers - com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - - - - - io.swagger.core.v3 - swagger-annotations-jakarta - - + - org.springdoc - springdoc-openapi-starter-webmvc-ui + io.springfox + springfox-swagger2 - - org.springframework - spring-webmvc + io.springfox + springfox-swagger-ui @@ -87,27 +67,10 @@ spring-boot-starter-data-mongodb - - - org.junit.jupiter - junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 - test - - - - org.junit - junit-bom - 5.12.1 - pom + junit + junit + 3.8.1 test @@ -122,10 +85,5 @@ org.apache.commons commons-lang3 - - org.projectlombok - lombok - compile - diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java b/ocean-comment-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java new file mode 100644 index 0000000..fa396a9 --- /dev/null +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/config/Swagger2Config.java @@ -0,0 +1,37 @@ +package com.oriole.ocean.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class Swagger2Config { + + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_12) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.oriole.ocean")) + .paths(PathSelectors.any()) + .build(); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("Lib4Univ 开源高校文库项目 RESTful API列表") + .description("注意不得在生产环境启用Swagger") + .termsOfServiceUrl("http://www.oceanlibrary.cn/") + .contact("基于深度遗忘的程序猿") + .version("2.1") + .build(); + } +} + diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java b/ocean-comment-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java deleted file mode 100644 index b948345..0000000 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/config/SwaggerConfig.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.oriole.ocean.config; - -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Contact; -import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.info.License; -import org.springdoc.core.models.GroupedOpenApi; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class SwaggerConfig { - - @Bean - public GroupedOpenApi createRestApi() { - return GroupedOpenApi.builder() - .group("wtf") - .packagesToScan("com.oriole.ocean") - .pathsToMatch("/**") - .build(); - } - - @Bean - public OpenAPI openAPI() { - return new OpenAPI() - .info(new Info() - .title("Lib4Univ开源高校文库项目 RESTful API列表") - .description("注意不得在生产环境启用 Swagger") - .version("2.1") - .contact(new Contact() - .name("基于深度遗忘的程序猿") - .url("http://www.oceanlibrary.cn") - .email("null")) - .termsOfService("http://www.oceanlibrary.cn/") - .license(new License() - .name("Apache2.0") - .url("https://www.apache.org/licenses/LICENSE-2.0"))); - } -} - diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index d28bae4..d8ad741 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -12,9 +12,9 @@ import com.oriole.ocean.common.vo.BusinessException; import com.oriole.ocean.common.vo.MsgEntity; import com.oriole.ocean.service.CommentServiceImpl; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.RandomStringUtils; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; @@ -44,11 +44,11 @@ public class UserCommentController { @DubboReference NotifySubscriptionService notifySubscriptionService; - @Operation(summary = "删除评论区评论或回复") - @Parameters({ - @Parameter(name = "bindID", description = "资源唯一编号", required = true), - @Parameter(name = "mainType", description = "主资源类型(文档/纸条)", required = true), - @Parameter(name = "commentID", description = "评论唯一编号", required = true) + @ApiOperation(value = "删除评论区评论或回复") + @ApiImplicitParams({ + @ApiImplicitParam(name = "bindID", value = "资源唯一编号", required = true), + @ApiImplicitParam(name = "mainType", value = "主资源类型(文档/纸条)", required = true), + @ApiImplicitParam(name = "commentID", value = "评论唯一编号", required = true) }) @RequestMapping(value = "/deleteComment", method = RequestMethod.GET) public MsgEntity deleteComment(@AuthUser AuthUserEntity authUser, @@ -85,7 +85,7 @@ public MsgEntity deleteComment(@AuthUser AuthUserEntity authUser, commentStatusType = CommentStatusType.USER_CLOSURE; } } - if (commentStatusType == null) { // 仍然没有找到合乎情理的删除理由,说明没有权限 + if (commentStatusType == null) { // 仍然没有找到合乎清理的删除理由,说明没有权限 throw new BusinessException("-2", "权限不足,必须为评论发布者或文档发布者"); } //执行删除 @@ -200,13 +200,13 @@ public MsgEntity getCommentReply( return new MsgEntity<>("SUCCESS", "1", commentEntity); } - @Operation(summary = "评价一条评论或回复", description = "isLike参数为评价操作的分类(true表示为点赞操作,false表示为点踩操作),isCancel为是否为取消评价操作。如isLike为false,isCancel为true,则表示取消点踩操作") - @Parameters({ - @Parameter(name = "bindID", description = "唯一资源编号", required = true), - @Parameter(name = "mainType", description = "资源类型", required = true), - @Parameter(name = "commentID", description = "评论唯一编号", required = true), - @Parameter(name = "isCancel", description = "是否为取消操作", required = true), - @Parameter(name = "isLike", description = "是否为点赞操作", required = true) + @ApiOperation(value = "评价一条评论或回复", notes = "isLike参数为评价操作的分类(true表示为点赞操作,false表示为点踩操作),isCancel为是否为取消评价操作。如isLike为false,isCancel为true,则表示取消点踩操作") + @ApiImplicitParams({ + @ApiImplicitParam(name = "bindID", value = "唯一资源编号", required = true), + @ApiImplicitParam(name = "mainType", value = "资源类型", required = true), + @ApiImplicitParam(name = "commentID", value = "评论唯一编号", required = true), + @ApiImplicitParam(name = "isCancel", value = "是否为取消操作", required = true), + @ApiImplicitParam(name = "isLike", value = "是否为点赞操作", required = true) }) @RequestMapping(value = "/evaluateComment", method = RequestMethod.GET) public MsgEntity evaluateComment(@AuthUser AuthUserEntity authUser, diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java b/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java index 9469b69..af84916 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java @@ -1,6 +1,6 @@ package com.oriole.ocean.service; -import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson.JSONObject; import com.oriole.ocean.common.enumerate.DocStatisticItemType; import com.oriole.ocean.common.enumerate.EvaluateType; import com.oriole.ocean.common.enumerate.MainType; diff --git a/ocean-comment-service/src/main/resources/bootstrap.yaml b/ocean-comment-service/src/main/resources/bootstrap.yaml index 38d2b9c..70aa295 100644 --- a/ocean-comment-service/src/main/resources/bootstrap.yaml +++ b/ocean-comment-service/src/main/resources/bootstrap.yaml @@ -20,6 +20,5 @@ dubbo: group: dubbo protocol: port: -1 - serialization: kryo consumer: check: false \ No newline at end of file diff --git a/ocean-comment-service/src/test/java/com/oriole/AppTest.java b/ocean-comment-service/src/test/java/com/oriole/AppTest.java index 06fc0f9..38e2a80 100644 --- a/ocean-comment-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-comment-service/src/test/java/com/oriole/AppTest.java @@ -1,20 +1,38 @@ package com.oriole; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Assertions; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; /** * Unit test for simple App. */ -public class AppTest +public class AppTest + extends TestCase { + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + /** * Rigourous Test :-) */ - @Test public void testApp() { - System.out.println("Hello World"); - Assertions.assertTrue( true ); + assertTrue( true ); } } diff --git a/ocean-common/pom.xml b/ocean-common/pom.xml index 9657a81..e23ede0 100644 --- a/ocean-common/pom.xml +++ b/ocean-common/pom.xml @@ -23,19 +23,15 @@ spring-boot-starter-web - org.projectlombok lombok - 1.18.36 - provided - com.baomidou mybatis-plus - 3.5.10.1 + 3.5.4.1 @@ -48,24 +44,21 @@ spring-boot-starter-data-mongodb - - com.alibaba.fastjson2 - fastjson2 - 2.0.56 + com.alibaba + fastjson + 2.0.43 - io.jsonwebtoken - jjwt-api - 0.12.6 + jjwt + 0.9.1 - com.auth0 java-jwt - 4.5.0 + 3.4.0 \ No newline at end of file diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/auth/AuthUserMethodArgumentResolver.java b/ocean-common/src/main/java/com/oriole/ocean/common/auth/AuthUserMethodArgumentResolver.java index ceafe39..553f855 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/auth/AuthUserMethodArgumentResolver.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/auth/AuthUserMethodArgumentResolver.java @@ -1,6 +1,6 @@ package com.oriole.ocean.common.auth; -import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson.JSONObject; import com.oriole.ocean.common.vo.AuthUserEntity; import org.springframework.core.MethodParameter; import org.springframework.http.HttpHeaders; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/enumerate/ResultCode.java b/ocean-common/src/main/java/com/oriole/ocean/common/enumerate/ResultCode.java index 373b978..91fbc7a 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/enumerate/ResultCode.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/enumerate/ResultCode.java @@ -1,5 +1,6 @@ package com.oriole.ocean.common.enumerate; + import lombok.Getter; @Getter diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/UserBehaviorEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/UserBehaviorEntity.java index 08b3d2f..6f4d826 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/UserBehaviorEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/UserBehaviorEntity.java @@ -1,6 +1,6 @@ package com.oriole.ocean.common.po.mongo; -import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson.JSONObject; import com.oriole.ocean.common.enumerate.BehaviorExtraInfo; import com.oriole.ocean.common.enumerate.BehaviorType; import com.oriole.ocean.common.enumerate.MainType; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentEntity.java index 52cdb11..5d26dd1 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentEntity.java @@ -1,12 +1,10 @@ package com.oriole.ocean.common.po.mongo.comment; import lombok.Data; -import lombok.EqualsAndHashCode; import java.util.ArrayList; @Data -@EqualsAndHashCode(callSuper=false) public class CommentEntity extends AbstractComment implements java.io.Serializable { private String commentBuildUsername; private Integer hotValue; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentReplyEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentReplyEntity.java index cb36758..66fe4e5 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentReplyEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/CommentReplyEntity.java @@ -1,10 +1,8 @@ package com.oriole.ocean.common.po.mongo.comment; import lombok.Data; -import lombok.EqualsAndHashCode; @Data -@EqualsAndHashCode(callSuper=false) public class CommentReplyEntity extends AbstractComment implements java.io.Serializable { private String replyBuildUsername; private String replyToCommentReplier;// 回复另一个回复时必填(被回复的回复者) diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java index 69271d5..63eece5 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/UserEntity.java @@ -3,13 +3,11 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; import java.util.Date; -@Getter -@Setter +@Data @TableName("user") public class UserEntity implements java.io.Serializable { diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/UserBehaviorService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/UserBehaviorService.java index 159a483..533554f 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/UserBehaviorService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/UserBehaviorService.java @@ -1,5 +1,6 @@ package com.oriole.ocean.common.service; +import com.alibaba.fastjson.JSONObject; import com.oriole.ocean.common.enumerate.BehaviorExtraInfo; import com.oriole.ocean.common.enumerate.EvaluateType; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java b/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java index 3a1258d..04bcb66 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/tools/JwtUtils.java @@ -6,7 +6,7 @@ import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.security.Keys; +import io.jsonwebtoken.SignatureAlgorithm; import org.apache.commons.codec.binary.Base64; import java.util.Date; @@ -23,6 +23,7 @@ * */ public class JwtUtils { private final String base64EncodedSecretKey; + private final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; public JwtUtils(String secretKey) { this.base64EncodedSecretKey = Base64.encodeBase64String(secretKey.getBytes()); @@ -49,15 +50,15 @@ public String encode(String iss, long ttlMillis, Map claims) { } long nowMillis = System.currentTimeMillis(); JwtBuilder builder = Jwts.builder() - .claims(claims) - .id(UUID.randomUUID().toString())//2. 这个是JWT的唯一标识,一般设置成唯一的,这个方法可以生成唯一标识 - .issuedAt(new Date(nowMillis))//1. 这个地方就是以毫秒为单位,换算当前系统时间生成的iat - .subject(iss)//3. 签发人,也就是JWT是给谁的(逻辑上一般都是username或者userId) - .signWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes()));//这个地方是生成jwt使用的算法和秘钥 + .setClaims(claims) + .setId(UUID.randomUUID().toString())//2. 这个是JWT的唯一标识,一般设置成唯一的,这个方法可以生成唯一标识 + .setIssuedAt(new Date(nowMillis))//1. 这个地方就是以毫秒为单位,换算当前系统时间生成的iat + .setSubject(iss)//3. 签发人,也就是JWT是给谁的(逻辑上一般都是username或者userId) + .signWith(signatureAlgorithm, base64EncodedSecretKey);//这个地方是生成jwt使用的算法和秘钥 if (ttlMillis >= 0) { long expMillis = nowMillis + ttlMillis; Date exp = new Date(expMillis);//4. 过期时间,这个也是使用毫秒生成的,使用当前时间+前面传入的持续时间生成 - builder.expiration(exp); + builder.setExpiration(exp); } return builder.compact(); } @@ -68,16 +69,22 @@ public Claims decode(String jwtToken) { // 得到 DefaultJwtParser return Jwts.parser() // 设置签名的秘钥 - .verifyWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes())) - .build() + .setSigningKey(base64EncodedSecretKey) // 设置需要解析的 jwt - .parseSignedClaims(jwtToken) - .getPayload(); + .parseClaimsJws(jwtToken) + .getBody(); } //判断jwtToken是否合法 public boolean isVerify(String jwtToken) { - Algorithm algorithm = Algorithm.HMAC256(Base64.decodeBase64(base64EncodedSecretKey)); + Algorithm algorithm; + switch (signatureAlgorithm) { + case HS256: + algorithm = Algorithm.HMAC256(Base64.decodeBase64(base64EncodedSecretKey)); + break; + default: + throw new RuntimeException("not support this algorithm"); + } JWTVerifier verifier = JWT.require(algorithm).build(); try { verifier.verify(jwtToken); // 校验不通过会抛出异常 diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java b/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java index 4fd1658..572f0d5 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/vo/BusinessException.java @@ -1,10 +1,7 @@ package com.oriole.ocean.common.vo; import com.oriole.ocean.common.enumerate.ResultCode; -import lombok.Getter; -import lombok.Setter; -@Setter public class BusinessException extends RuntimeException { private static final long serialVersionUID = -7480022450501760611L; @@ -12,7 +9,6 @@ public class BusinessException extends RuntimeException { /** * 异常码 */ - @Getter private String code; /** @@ -33,9 +29,20 @@ public BusinessException(String code, String msg) { this.message = msg; } + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + @Override public String getMessage() { return message; } + public void setMessage(String message) { + this.message = message; + } } diff --git a/ocean-docs-file-service/pom.xml b/ocean-docs-file-service/pom.xml index 8f330c1..d04c785 100644 --- a/ocean-docs-file-service/pom.xml +++ b/ocean-docs-file-service/pom.xml @@ -18,37 +18,6 @@ - - - jakarta.servlet - jakarta.servlet-api - provided - - - - org.projectlombok - lombok - provided - - - - org.slf4j - slf4j-api - 2.0.17 - - - - org.apache.logging.log4j - log4j-core - 2.24.3 - - - - org.slf4j - slf4j-reload4j - 2.0.17 - test - org.springframework.boot @@ -76,34 +45,19 @@ org.apache.dubbo dubbo-registry-nacos - - org.apache.dubbo.extensions - dubbo-serialization-kryo - - - com.esotericsoftware - kryo - - - de.javakaffee - kryo-serializers - com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - - - + - io.swagger.core.v3 - swagger-annotations-jakarta + io.springfox + springfox-swagger2 - - org.springdoc - springdoc-openapi-starter-webmvc-ui + io.springfox + springfox-swagger-ui @@ -116,7 +70,7 @@ org.mybatis.spring.boot mybatis-spring-boot-starter - 3.0.4 + 2.1.0 @@ -177,27 +131,10 @@ 5.5.13.1 - - - - org.junit.jupiter - junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 - test - - - org.junit - junit-bom - 5.12.1 - pom + junit + junit + 3.8.1 test diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java index 9d0ebcc..2f4f006 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/controller/DocIOController.java @@ -30,7 +30,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import jakarta.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; import java.io.IOException; diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java index 9e9f350..686e8c1 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/AliOSSUtils.java @@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import jakarta.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponse; import java.io.BufferedInputStream; import java.io.File; import java.io.InputStream; diff --git a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java index aa495de..276599a 100644 --- a/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java +++ b/ocean-docs-file-service/src/main/java/com/oriole/ocean/utils/objectStorage/ObjectStorageUtils.java @@ -1,6 +1,6 @@ package com.oriole.ocean.utils.objectStorage; -import jakarta.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponse; import java.io.InputStream; public interface ObjectStorageUtils { diff --git a/ocean-docs-file-service/src/main/resources/bootstrap.yaml b/ocean-docs-file-service/src/main/resources/bootstrap.yaml index 40b7cb4..3d19248 100644 --- a/ocean-docs-file-service/src/main/resources/bootstrap.yaml +++ b/ocean-docs-file-service/src/main/resources/bootstrap.yaml @@ -20,6 +20,5 @@ dubbo: group: dubbo protocol: port: -1 - serialization: kryo consumer: check: false diff --git a/ocean-docs-file-service/src/test/java/com/oriole/AppTest.java b/ocean-docs-file-service/src/test/java/com/oriole/AppTest.java index e6782ee..38e2a80 100644 --- a/ocean-docs-file-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-docs-file-service/src/test/java/com/oriole/AppTest.java @@ -1,20 +1,38 @@ package com.oriole; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; /** * Unit test for simple App. */ -public class AppTest +public class AppTest + extends TestCase { + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + /** * Rigourous Test :-) */ - @Test public void testApp() { - System.out.println("Hello World"); - Assertions.assertTrue( true ); + assertTrue( true ); } } diff --git a/ocean-docs-service/pom.xml b/ocean-docs-service/pom.xml index effcbe5..beb1030 100644 --- a/ocean-docs-service/pom.xml +++ b/ocean-docs-service/pom.xml @@ -42,18 +42,6 @@ org.apache.dubbo dubbo-registry-nacos - - org.apache.dubbo.extensions - dubbo-serialization-kryo - - - com.esotericsoftware - kryo - - - de.javakaffee - kryo-serializers - com.alibaba.cloud @@ -66,22 +54,14 @@ 1.8.6 - - - + - io.swagger.core.v3 - swagger-annotations-jakarta + io.springfox + springfox-swagger2 - - org.springdoc - springdoc-openapi-starter-webmvc-ui - - - - org.springframework - spring-webmvc + io.springfox + springfox-swagger-ui @@ -94,7 +74,7 @@ org.mybatis.spring.boot mybatis-spring-boot-starter - 3.0.4 + 2.1.0 @@ -125,27 +105,10 @@ - - - org.junit.jupiter - junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 - test - - - - org.junit - junit-bom - 5.12.1 - pom + junit + junit + 3.8.1 test @@ -155,20 +118,5 @@ 1.0-SNAPSHOT compile - - org.projectlombok - lombok - - - - org.elasticsearch - elasticsearch - 8.17.3 - - - org.springframework.data - spring-data-elasticsearch - 4.3.10 - diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java index e6fac26..9fdcdec 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocFunctionController.java @@ -1,6 +1,6 @@ package com.oriole.ocean.controller; -import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson.JSONObject; import com.oriole.ocean.common.enumerate.*; import com.oriole.ocean.common.auth.AuthUser; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java index 9d9788e..793532c 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/ESearchServiceImpl.java @@ -17,7 +17,7 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.stereotype.Service; -import jakarta.annotation.Resource; +import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java index 4235745..e539fc4 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/FileServiceImpl.java @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import jakarta.annotation.Resource; +import javax.annotation.Resource; import java.util.List; @Service diff --git a/ocean-docs-service/src/test/java/com/oriole/AppTest.java b/ocean-docs-service/src/test/java/com/oriole/AppTest.java index e6782ee..38e2a80 100644 --- a/ocean-docs-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-docs-service/src/test/java/com/oriole/AppTest.java @@ -1,20 +1,38 @@ package com.oriole; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; /** * Unit test for simple App. */ -public class AppTest +public class AppTest + extends TestCase { + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + /** * Rigourous Test :-) */ - @Test public void testApp() { - System.out.println("Hello World"); - Assertions.assertTrue( true ); + assertTrue( true ); } } diff --git a/ocean-gateway/pom.xml b/ocean-gateway/pom.xml index 9bd9156..9cd874d 100644 --- a/ocean-gateway/pom.xml +++ b/ocean-gateway/pom.xml @@ -44,48 +44,26 @@ spring-boot-starter-security - io.jsonwebtoken - jjwt-api - 0.12.6 + jjwt + 0.9.1 - com.auth0 java-jwt - 4.5.0 + 3.4.0 - org.projectlombok lombok - 1.18.36 - provided - - - - org.junit.jupiter - junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 - test - - - org.junit - junit-bom - 5.12.1 - pom + junit + junit + 3.8.1 test diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java index cb7513a..0363479 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java @@ -6,7 +6,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; -import org.springframework.security.config.Customizer; import org.springframework.security.config.web.server.ServerHttpSecurity; import org.springframework.security.web.server.SecurityWebFilterChain; import org.springframework.web.cors.reactive.CorsConfigurationSource; @@ -57,23 +56,19 @@ public class WebSecurityConfig { public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http .securityContextRepository(securityRepository) - .authorizeExchange(authorize -> authorize - .pathMatchers(path).permitAll() - .pathMatchers(HttpMethod.OPTIONS).permitAll() - .pathMatchers("/userWalletService/**").hasAnyRole("USER","ADMIN") - .pathMatchers("/userInfoService/**").hasAnyRole("USER","ADMIN") - .pathMatchers("/userFunctionService/**").hasAnyRole("USER","ADMIN") - .anyExchange().authenticated() - ) - .httpBasic(Customizer.withDefaults()) - .exceptionHandling(handling -> handling - .authenticationEntryPoint(authenticationEntryPoint) - .accessDeniedHandler(accessDeniedHandler) //基于http的接口请求鉴权失败 - ).cors( cors -> cors - .configurationSource(corsConfigSource()) - ).csrf( csrf -> csrf - .disable() - ); //必须支持跨域 + .authorizeExchange() + .pathMatchers(path).permitAll() + .pathMatchers(HttpMethod.OPTIONS).permitAll() + .pathMatchers("/userWalletService/**").hasAnyRole("USER","ADMIN") + .pathMatchers("/userInfoService/**").hasAnyRole("USER","ADMIN") + .pathMatchers("/userFunctionService/**").hasAnyRole("USER","ADMIN") + .anyExchange().authenticated() + .and() + .httpBasic() + .and().exceptionHandling().authenticationEntryPoint(authenticationEntryPoint) + .accessDeniedHandler(accessDeniedHandler) //基于http的接口请求鉴权失败 + .and().cors().configurationSource(corsConfigSource()) + .and().csrf().disable(); //必须支持跨域 return http.build(); } diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java index 02e9e98..9ca3737 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java @@ -1,6 +1,6 @@ package com.oriole.ocean.gateway.filter; -import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson.JSONObject; import com.oriole.ocean.gateway.tools.JwtUtils; import lombok.extern.slf4j.Slf4j; import org.reactivestreams.Publisher; diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java index 4450abf..8ad8c33 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java @@ -1,6 +1,6 @@ package com.oriole.ocean.gateway.security; -import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson.JSONObject; import com.oriole.ocean.gateway.tools.JwtUtils; import io.jsonwebtoken.Claims; import lombok.extern.slf4j.Slf4j; diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java index 4b484f3..4f5a17b 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/tools/JwtUtils.java @@ -6,7 +6,7 @@ import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.security.Keys; +import io.jsonwebtoken.SignatureAlgorithm; import org.apache.commons.codec.binary.Base64; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -26,6 +26,7 @@ @Component public class JwtUtils { private final String base64EncodedSecretKey; + private final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS512; public JwtUtils(@Value("${auth.login.token.secretkey}") String secretKey) { this.base64EncodedSecretKey = Base64.encodeBase64String(secretKey.getBytes()); @@ -53,15 +54,15 @@ public String encode(String iss, long ttlMillis, Map claims) { long nowMillis = System.currentTimeMillis(); JwtBuilder builder = Jwts.builder() - .claims(claims) - .id(UUID.randomUUID().toString())//2. 这个是JWT的唯一标识,一般设置成唯一的,这个方法可以生成唯一标识 - .issuedAt(new Date(nowMillis))//1. 这个地方就是以毫秒为单位,换算当前系统时间生成的iat - .subject(iss)//3. 签发人,也就是JWT是给谁的(逻辑上一般都是username或者userId) - .signWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes()));//这个地方是生成jwt使用的算法和秘钥 + .setClaims(claims) + .setId(UUID.randomUUID().toString())//2. 这个是JWT的唯一标识,一般设置成唯一的,这个方法可以生成唯一标识 + .setIssuedAt(new Date(nowMillis))//1. 这个地方就是以毫秒为单位,换算当前系统时间生成的iat + .setSubject(iss)//3. 签发人,也就是JWT是给谁的(逻辑上一般都是username或者userId) + .signWith(signatureAlgorithm, base64EncodedSecretKey);//这个地方是生成jwt使用的算法和秘钥 if (ttlMillis >= 0) { long expMillis = nowMillis + ttlMillis; Date exp = new Date(expMillis);//4. 过期时间,这个也是使用毫秒生成的,使用当前时间+前面传入的持续时间生成 - builder.expiration(exp); + builder.setExpiration(exp); } return builder.compact(); } @@ -73,16 +74,22 @@ public Claims decode(String jwtToken) { // 得到 DefaultJwtParser return Jwts.parser() // 设置签名的秘钥 - .verifyWith(Keys.hmacShaKeyFor(base64EncodedSecretKey.getBytes())) - .build() + .setSigningKey(base64EncodedSecretKey) // 设置需要解析的 jwt - .parseSignedClaims(jwtToken) - .getPayload(); + .parseClaimsJws(jwtToken) + .getBody(); } //判断jwtToken是否合法 public boolean isVerify(String jwtToken) { - Algorithm algorithm = Algorithm.HMAC256(Base64.decodeBase64(base64EncodedSecretKey)); + Algorithm algorithm; + switch (signatureAlgorithm) { + case HS512: + algorithm = Algorithm.HMAC512(Base64.decodeBase64(base64EncodedSecretKey)); + break; + default: + throw new RuntimeException("not support this algorithm"); + } JWTVerifier verifier = JWT.require(algorithm).build(); try { verifier.verify(jwtToken); // 校验不通过会抛出异常 diff --git a/ocean-gateway/src/test/java/com/oriole/AppTest.java b/ocean-gateway/src/test/java/com/oriole/AppTest.java index e6782ee..38e2a80 100644 --- a/ocean-gateway/src/test/java/com/oriole/AppTest.java +++ b/ocean-gateway/src/test/java/com/oriole/AppTest.java @@ -1,20 +1,38 @@ package com.oriole; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; /** * Unit test for simple App. */ -public class AppTest +public class AppTest + extends TestCase { + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + /** * Rigourous Test :-) */ - @Test public void testApp() { - System.out.println("Hello World"); - Assertions.assertTrue( true ); + assertTrue( true ); } } diff --git a/ocean-note-service/pom.xml b/ocean-note-service/pom.xml index d942c90..d7540e6 100644 --- a/ocean-note-service/pom.xml +++ b/ocean-note-service/pom.xml @@ -45,39 +45,19 @@ org.apache.dubbo dubbo-registry-nacos - - org.apache.dubbo.extensions - dubbo-serialization-kryo - - - com.esotericsoftware - kryo - - - de.javakaffee - kryo-serializers - com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - - - - - io.swagger.core.v3 - swagger-annotations-jakarta - - + - org.springdoc - springdoc-openapi-starter-webmvc-ui + io.springfox + springfox-swagger2 - - org.springframework - spring-webmvc + io.springfox + springfox-swagger-ui @@ -90,7 +70,7 @@ org.mybatis.spring.boot mybatis-spring-boot-starter - 3.0.4 + 2.1.0 @@ -121,27 +101,10 @@ - - - org.junit.jupiter - junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 - test - - - - org.junit - junit-bom - 5.12.1 - pom + junit + junit + 3.8.1 test @@ -151,9 +114,5 @@ 1.0-SNAPSHOT compile - - org.projectlombok - lombok - diff --git a/ocean-note-service/src/main/resources/bootstrap.yaml b/ocean-note-service/src/main/resources/bootstrap.yaml index 5301e09..5ba9b08 100644 --- a/ocean-note-service/src/main/resources/bootstrap.yaml +++ b/ocean-note-service/src/main/resources/bootstrap.yaml @@ -20,6 +20,5 @@ dubbo: group: dubbo protocol: port: -1 - serialization: kryo consumer: check: false \ No newline at end of file diff --git a/ocean-note-service/src/test/java/com/oriole/AppTest.java b/ocean-note-service/src/test/java/com/oriole/AppTest.java index e6782ee..38e2a80 100644 --- a/ocean-note-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-note-service/src/test/java/com/oriole/AppTest.java @@ -1,20 +1,38 @@ package com.oriole; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; /** * Unit test for simple App. */ -public class AppTest +public class AppTest + extends TestCase { + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + /** * Rigourous Test :-) */ - @Test public void testApp() { - System.out.println("Hello World"); - Assertions.assertTrue( true ); + assertTrue( true ); } } diff --git a/ocean-notify-service/pom.xml b/ocean-notify-service/pom.xml index c10786d..da8ffd9 100644 --- a/ocean-notify-service/pom.xml +++ b/ocean-notify-service/pom.xml @@ -45,34 +45,19 @@ org.apache.dubbo dubbo-registry-nacos - - org.apache.dubbo.extensions - dubbo-serialization-kryo - - - com.esotericsoftware - kryo - - - de.javakaffee - kryo-serializers - com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - - - + - io.swagger.core.v3 - swagger-annotations-jakarta + io.springfox + springfox-swagger2 - - org.springdoc - springdoc-openapi-starter-webmvc-ui + io.springfox + springfox-swagger-ui @@ -85,7 +70,7 @@ org.mybatis.spring.boot mybatis-spring-boot-starter - 3.0.4 + 2.1.0 @@ -116,27 +101,10 @@ - - - - org.junit.jupiter - junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 - test - - - org.junit - junit-bom - 5.12.1 - pom + junit + junit + 3.8.1 test @@ -151,10 +119,5 @@ org.apache.commons commons-lang3 - - org.projectlombok - lombok - compile - diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java index 478a07b..fdc4733 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java @@ -6,7 +6,7 @@ import com.oriole.ocean.common.po.mysql.UserNotifyEntity; import org.springframework.stereotype.Service; -import jakarta.annotation.Resource; +import javax.annotation.Resource; import java.util.Date; import java.util.List; diff --git a/ocean-notify-service/src/main/resources/bootstrap.yaml b/ocean-notify-service/src/main/resources/bootstrap.yaml index 2d3cb8f..6002fbc 100644 --- a/ocean-notify-service/src/main/resources/bootstrap.yaml +++ b/ocean-notify-service/src/main/resources/bootstrap.yaml @@ -20,6 +20,5 @@ dubbo: group: dubbo protocol: port: -1 - serialization: kryo consumer: check: false \ No newline at end of file diff --git a/ocean-notify-service/src/test/java/com/oriole/AppTest.java b/ocean-notify-service/src/test/java/com/oriole/AppTest.java index e6782ee..38e2a80 100644 --- a/ocean-notify-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-notify-service/src/test/java/com/oriole/AppTest.java @@ -1,20 +1,38 @@ package com.oriole; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; /** * Unit test for simple App. */ -public class AppTest +public class AppTest + extends TestCase { + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + /** * Rigourous Test :-) */ - @Test public void testApp() { - System.out.println("Hello World"); - Assertions.assertTrue( true ); + assertTrue( true ); } } diff --git a/ocean-user-behavior-service/pom.xml b/ocean-user-behavior-service/pom.xml index b6fb809..c74ff75 100644 --- a/ocean-user-behavior-service/pom.xml +++ b/ocean-user-behavior-service/pom.xml @@ -45,18 +45,6 @@ org.apache.dubbo dubbo-registry-nacos - - org.apache.dubbo.extensions - dubbo-serialization-kryo - - - com.esotericsoftware - kryo - - - de.javakaffee - kryo-serializers - com.alibaba.cloud @@ -70,27 +58,10 @@ spring-boot-starter-data-mongodb - - - - org.junit.jupiter - junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 - test - - - org.junit - junit-bom - 5.12.1 - pom + junit + junit + 3.8.1 test diff --git a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java index 8c8ba4f..b724d70 100644 --- a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java +++ b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java @@ -1,6 +1,6 @@ package com.oriole.ocean.service; -import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson.JSONObject; import com.oriole.ocean.common.enumerate.BehaviorExtraInfo; import com.oriole.ocean.common.enumerate.BehaviorType; import com.oriole.ocean.common.enumerate.EvaluateType; diff --git a/ocean-user-behavior-service/src/main/resources/bootstrap.yaml b/ocean-user-behavior-service/src/main/resources/bootstrap.yaml index e3e011d..b33d220 100644 --- a/ocean-user-behavior-service/src/main/resources/bootstrap.yaml +++ b/ocean-user-behavior-service/src/main/resources/bootstrap.yaml @@ -17,6 +17,5 @@ dubbo: group: dubbo protocol: port: -1 - serialization: kryo consumer: check: false \ No newline at end of file diff --git a/ocean-user-behavior-service/src/test/java/com/oriole/AppTest.java b/ocean-user-behavior-service/src/test/java/com/oriole/AppTest.java index e6782ee..38e2a80 100644 --- a/ocean-user-behavior-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-user-behavior-service/src/test/java/com/oriole/AppTest.java @@ -1,20 +1,38 @@ package com.oriole; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; /** * Unit test for simple App. */ -public class AppTest +public class AppTest + extends TestCase { + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + /** * Rigourous Test :-) */ - @Test public void testApp() { - System.out.println("Hello World"); - Assertions.assertTrue( true ); + assertTrue( true ); } } diff --git a/ocean-user-service/pom.xml b/ocean-user-service/pom.xml index 9e10518..7943437 100644 --- a/ocean-user-service/pom.xml +++ b/ocean-user-service/pom.xml @@ -17,43 +17,7 @@ UTF-8 - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.5.2 - - - - - - - org.projectlombok - lombok - provided - - - - org.slf4j - slf4j-api - 2.0.17 - - - - org.apache.logging.log4j - log4j-core - 2.24.3 - - - - org.slf4j - slf4j-reload4j - 2.0.17 - test - org.springframework.boot @@ -81,34 +45,19 @@ org.apache.dubbo dubbo-registry-nacos - - org.apache.dubbo.extensions - dubbo-serialization-kryo - - - com.esotericsoftware - kryo - - - de.javakaffee - kryo-serializers - com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - - - + - io.swagger.core.v3 - swagger-annotations-jakarta + io.springfox + springfox-swagger2 - - org.springdoc - springdoc-openapi-starter-webmvc-ui + io.springfox + springfox-swagger-ui @@ -118,37 +67,32 @@ mysql-connector-j - org.mybatis.spring.boot mybatis-spring-boot-starter - 3.0.4 + 2.1.0 - com.baomidou mybatis-plus-boot-starter - 3.5.10.1 + 3.3.2 - com.github.pagehelper pagehelper - 6.1.0 + 6.0.0 - - org.springframework.boot - spring-boot-autoconfigure - 3.3.9 + com.github.pagehelper + pagehelper-spring-boot-autoconfigure + 2.0.0 - com.github.pagehelper pagehelper-spring-boot-starter - 2.1.0 + 2.0.0 org.mybatis @@ -157,27 +101,10 @@ - - - - org.junit.jupiter - junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 - test - - - org.junit - junit-bom - 5.12.1 - pom + junit + junit + 3.8.1 test @@ -187,22 +114,5 @@ 1.0-SNAPSHOT compile - - org.springframework - spring-context - 5.3.31 - - - com.baomidou - mybatis-plus-extension - 3.5.10.1 - compile - - - - com.baomidou - mybatis-plus-jsqlparser - 3.5.10.1 - diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java b/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java index c71cfaa..07bfe5b 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/config/MybatisPlusConfig.java @@ -1,7 +1,6 @@ package com.oriole.ocean.config; -import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; import org.mybatis.spring.mapper.MapperScannerConfigurer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -12,10 +11,8 @@ public class MybatisPlusConfig { * 分页插件 */ @Bean - public MybatisPlusInterceptor mybatisPlusInterceptor() { - MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); - interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); - return interceptor; + public PaginationInterceptor paginationInterceptor() { + return new PaginationInterceptor(); } @Bean diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java index 1b9d5a2..5407772 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserWalletChangeRecordServiceImpl.java @@ -11,8 +11,6 @@ import java.util.List; -import static com.baomidou.mybatisplus.extension.toolkit.Db.list; - @Service @Transactional public class UserWalletChangeRecordServiceImpl extends ServiceImpl { diff --git a/ocean-user-service/src/main/resources/bootstrap.yaml b/ocean-user-service/src/main/resources/bootstrap.yaml index e6dbc94..d4db3be 100644 --- a/ocean-user-service/src/main/resources/bootstrap.yaml +++ b/ocean-user-service/src/main/resources/bootstrap.yaml @@ -20,6 +20,5 @@ dubbo: group: dubbo protocol: port: -1 - serialization: kryo consumer: check: false \ No newline at end of file diff --git a/ocean-user-service/src/test/java/com/oriole/AppTest.java b/ocean-user-service/src/test/java/com/oriole/AppTest.java index 06fc0f9..38e2a80 100644 --- a/ocean-user-service/src/test/java/com/oriole/AppTest.java +++ b/ocean-user-service/src/test/java/com/oriole/AppTest.java @@ -1,20 +1,38 @@ package com.oriole; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Assertions; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; /** * Unit test for simple App. */ -public class AppTest +public class AppTest + extends TestCase { + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + /** * Rigourous Test :-) */ - @Test public void testApp() { - System.out.println("Hello World"); - Assertions.assertTrue( true ); + assertTrue( true ); } } diff --git a/pom.xml b/pom.xml index 9836a55..76f770d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,9 @@ - org.springframework.boot spring-boot-starter-parent - 3.3.9 + 2.6.15 ocean-common @@ -29,192 +28,46 @@ ocean http://maven.apache.org - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.13.0 - - full - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.5.2 - - - - - - - jakarta.servlet - jakarta.servlet-api - 6.1.0 - provided - - - - org.springframework.boot - spring-boot-starter-web - 3.3.9 - - - - org.junit.platform - junit-platform-surefire-provider - 1.3.2 - - - - org.junit.jupiter - junit-jupiter-api - 5.12.1 - test - - - - org.junit.jupiter - junit-jupiter-engine - 5.12.1 - test - - - - org.junit - junit-bom - 5.12.1 - pom - test - - - - org.projectlombok - lombok - 1.18.36 - provided - - - - org.slf4j - slf4j-api - 2.0.17 - - - - org.apache.logging.log4j - log4j-core - 2.24.3 - - - - org.slf4j - slf4j-reload4j - 2.0.17 - test - - com.alibaba.cloud spring-cloud-alibaba-dependencies - 2023.0.3.2 + 2021.0.5.0 pom - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-sentinel - 2023.0.3.2 - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - 2023.0.3.2 - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-config - 2023.0.3.2 + import - org.springframework.cloud spring-cloud-dependencies - 2023.0.3 + 2021.0.8 pom import - - - org.apache.dubbo dubbo-spring-boot-starter - 3.3.1 - - - - - org.apache.dubbo.extensions - dubbo-serialization-kryo - 3.3.1 - - - - - com.esotericsoftware - kryo - 5.6.2 + 3.0.9 - - org.apache.dubbo dubbo-registry-nacos - 3.3.4 - - - - - de.javakaffee - kryo-serializers - 0.45 + 3.0.9 - - - - - io.swagger.core.v3 - swagger-annotations-jakarta - 2.2.28 - - - - org.springframework - spring-webmvc - 6.1.17 - - + - org.springframework - spring-web - 6.1.17 + io.springfox + springfox-swagger2 + 2.9.2 - - org.springdoc - springdoc-openapi-starter-webmvc-ui - 2.6.0 + io.springfox + springfox-swagger-ui + 2.9.2 From 0a86e84afd8e8e9fd6cd5f42803a76700595415a Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Wed, 16 Apr 2025 12:42:30 +0800 Subject: [PATCH 07/62] Revert "chore: updated to java23" This reverts commit 8407da3bd106ba01af7a174e784e83b327450c60. --- .idea/misc.xml | 2 +- ocean-docs-file-service/pom.xml | 4 ++-- ocean-docs-service/pom.xml | 4 ++-- ocean-note-service/pom.xml | 4 ++-- ocean-notify-service/pom.xml | 4 ++-- ocean-user-service/pom.xml | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index c059b1a..24ef09d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -16,7 +16,7 @@ - + \ No newline at end of file diff --git a/ocean-docs-file-service/pom.xml b/ocean-docs-file-service/pom.xml index d04c785..e7aa5fe 100644 --- a/ocean-docs-file-service/pom.xml +++ b/ocean-docs-file-service/pom.xml @@ -63,8 +63,8 @@ - com.mysql - mysql-connector-j + mysql + mysql-connector-java diff --git a/ocean-docs-service/pom.xml b/ocean-docs-service/pom.xml index beb1030..d39a16e 100644 --- a/ocean-docs-service/pom.xml +++ b/ocean-docs-service/pom.xml @@ -67,8 +67,8 @@ - com.mysql - mysql-connector-j + mysql + mysql-connector-java diff --git a/ocean-note-service/pom.xml b/ocean-note-service/pom.xml index d7540e6..bb3fea3 100644 --- a/ocean-note-service/pom.xml +++ b/ocean-note-service/pom.xml @@ -63,8 +63,8 @@ - com.mysql - mysql-connector-j + mysql + mysql-connector-java diff --git a/ocean-notify-service/pom.xml b/ocean-notify-service/pom.xml index da8ffd9..06e461a 100644 --- a/ocean-notify-service/pom.xml +++ b/ocean-notify-service/pom.xml @@ -63,8 +63,8 @@ - com.mysql - mysql-connector-j + mysql + mysql-connector-java diff --git a/ocean-user-service/pom.xml b/ocean-user-service/pom.xml index 7943437..b859331 100644 --- a/ocean-user-service/pom.xml +++ b/ocean-user-service/pom.xml @@ -63,8 +63,8 @@ - com.mysql - mysql-connector-j + mysql + mysql-connector-java From 79ceefa56aa109b07713088cf66ee1c6530d16c6 Mon Sep 17 00:00:00 2001 From: cms42 Date: Sun, 20 Apr 2025 10:31:33 +0800 Subject: [PATCH 08/62] fix(gateway): register note service --- ocean-gateway/src/main/resources/application.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ocean-gateway/src/main/resources/application.yaml b/ocean-gateway/src/main/resources/application.yaml index f2ddba2..c941411 100644 --- a/ocean-gateway/src/main/resources/application.yaml +++ b/ocean-gateway/src/main/resources/application.yaml @@ -40,6 +40,10 @@ spring: uri: lb://ocean-notify-service predicates: - Path=/notify/** + - id: note + uri: lb://ocean-note-service + predicates: + - Path=/noteService/** auth: login: token: From 9202c53287de4ea2436e66ef4d0decbdc770b9a4 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sun, 20 Apr 2025 14:01:05 +0800 Subject: [PATCH 09/62] feat: recover notify service --- .../ocean/service/CommentServiceImpl.java | 4 +- ocean-common/pom.xml | 2 +- .../ocean/service/NotifyServiceImpl.java | 44 +++++++++++++++++++ ocean-user-behavior-service/pom.xml | 6 +++ .../service/UserBehaviorServiceImpl.java | 6 +-- 5 files changed, 56 insertions(+), 6 deletions(-) diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java b/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java index af84916..fdeb3b0 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java @@ -76,7 +76,7 @@ public boolean isCanAddComment(Integer bindID, String username, MainType mainTyp } private String getCollectionName(MainType mainType){ - return "comments_" + mainType.toString(); + return mainType.toString().toLowerCase() + "_comments"; } public CommentsListEntity getCommentsListEntity(Integer bindID, MainType mainType) { @@ -91,7 +91,7 @@ public CommentsListEntity getCommentsListEntity(Integer bindID, MainType mainTyp public List getComments(Integer bindID, MainType mainType, Integer commentCount, Integer queryReplyCount, Integer pageNum) { List operations = new ArrayList<>(); operations.add(Aggregation.match(Criteria.where("bindID").is(bindID))); - operations.add(Aggregation.unwind("comments")); + operations.add(Aggregation.unwind("comments", true)); operations.add(Aggregation.sort(Sort.by(new Sort.Order(Sort.Direction.DESC, "comments.hotValue"))) .and(Sort.by(new Sort.Order(Sort.Direction.DESC, "comments.likeNumber"))) .and(Sort.by(new Sort.Order(Sort.Direction.ASC, "comments.dislikeNumber")))); diff --git a/ocean-common/pom.xml b/ocean-common/pom.xml index e23ede0..a7800c0 100644 --- a/ocean-common/pom.xml +++ b/ocean-common/pom.xml @@ -31,7 +31,7 @@ com.baomidou mybatis-plus - 3.5.4.1 + 3.3.2 diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java index 06c50d6..17862d3 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java @@ -3,20 +3,32 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.oriole.ocean.common.enumerate.NotifyAction; +import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; import com.oriole.ocean.common.enumerate.NotifyType; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; +import com.oriole.ocean.common.po.mysql.NotifySubscriptionEntity; +import com.oriole.ocean.common.po.mysql.UserNotifyEntity; import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.dao.NotifyDao; import com.oriole.ocean.common.po.mysql.NotifyEntity; import org.apache.dubbo.config.annotation.DubboService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Arrays; import java.util.Date; import java.util.List; @Service @DubboService public class NotifyServiceImpl extends ServiceImpl implements NotifyService { + + @Autowired + private NotifySubscriptionServiceImpl notifySubscriptionServiceImpl; + + @Autowired + private UserNotifyServiceImpl userNotifyServiceImpl; + public void addNotify(NotifyEntity notifyEntity){ save(notifyEntity); } @@ -42,6 +54,38 @@ public void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity) { notifyEntity.setUserBehaviorID(userBehaviorEntity.getId()); notifyEntity.setTargetIDAndType(String.valueOf(userBehaviorEntity.getBindID()),userBehaviorEntity.getType()); addNotify(notifyEntity); + + NotifySubscriptionTargetType temp; + switch (notifyEntity.getTargetType()) { + case NOTE: + temp = NotifySubscriptionTargetType.NOTE; + break; + case DOCUMENT: + temp = NotifySubscriptionTargetType.DOCUMENT; + break; + default: + temp = NotifySubscriptionTargetType.NOTE; + break; + } + + List notifySubscriptionEntities = + notifySubscriptionServiceImpl.getAllSubscriptionByTargetAndAction( + notifyEntity.getTargetID(), + temp, + notifyEntity.getAction() + ); + + List userNotifyEntities = + Arrays.asList(new UserNotifyEntity[notifySubscriptionEntities.size()]); + + for(int i = 0;i < notifySubscriptionEntities.size();i++) { + userNotifyEntities.get(i).setUsername(notifySubscriptionEntities.get(i).getUsername()); + userNotifyEntities.get(i).setIsRead((byte)0); + userNotifyEntities.get(i).setNotifyID(notifyEntity.getId()); + userNotifyEntities.get(i).setBuildDate(notifyEntity.getBuildDate()); + } + + userNotifyServiceImpl.setUserNotifyList(userNotifyEntities); } // 查询指定时间之后产生的所有消息 diff --git a/ocean-user-behavior-service/pom.xml b/ocean-user-behavior-service/pom.xml index c74ff75..b9dc89b 100644 --- a/ocean-user-behavior-service/pom.xml +++ b/ocean-user-behavior-service/pom.xml @@ -71,5 +71,11 @@ 1.0-SNAPSHOT compile + + com.oriole + ocean-notify-service + 1.0-SNAPSHOT + compile + diff --git a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java index b724d70..4a05d43 100644 --- a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java +++ b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java @@ -30,8 +30,8 @@ public class UserBehaviorServiceImpl implements UserBehaviorService { @Autowired private MongoTemplate mongoTemplate; -// @Autowired -// private NotifyServiceImpl notifyService; + @Autowired + private NotifyServiceImpl notifyService; // 检查某用户针对特定对象(某文档/某便签等)的评价行为,并得出此次评价所需发生的全部评价行为 // 对特定对象具有评论区时,也可处理对其评论区的评价行为 @@ -133,7 +133,7 @@ public List findAllBehaviorRecords(UserBehaviorEntity userBe public void setBehaviorRecord(UserBehaviorEntity userBehavior) { mongoTemplate.save(userBehavior, "user_behavior"); // 部分用户行为需要产生用户消息 -// notifyService.addNotifyByBehaviorRecord(userBehaviorEntity); + notifyService.addNotifyByBehaviorRecord(userBehavior); } public void updateBehaviorRecordExtraInfo(UserBehaviorEntity userBehavior, BehaviorExtraInfo behaviorExtraInfo, Object value) { From 7b3dd52faf3f4221f5c65fff53c3b4666a33f219 Mon Sep 17 00:00:00 2001 From: AInfinity-LilacDream <1977741520@qq.com> Date: Tue, 6 May 2025 11:49:36 +0800 Subject: [PATCH 10/62] fix: null safety check --- .../com/oriole/ocean/service/UserCollectionServiceImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java b/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java index 24f35b2..b12d1a8 100644 --- a/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java +++ b/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java @@ -68,6 +68,10 @@ public UserCollectionEntity.CollectionEntity getCollectionByUsernameAndCollectio AggregationResults results = mongoTemplate.aggregate(aggregation, getCollectionName(mainType), UserCollectionEntity.CollectionEntity.class); + + if (results.getMappedResults() == null) { + return null; + } return results.getMappedResults().get(0); } From 0266b2796c31728a35de09b447a7c5b0d15147f2 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Tue, 6 May 2025 17:20:47 +0800 Subject: [PATCH 11/62] fix: comment id problem --- .../controller/UserCommentController.java | 1 + .../ocean/service/CommentServiceImpl.java | 4 +- .../ocean/service/NotifyServiceImpl.java | 41 +------------------ 3 files changed, 5 insertions(+), 41 deletions(-) diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index d8ad741..c1cf61b 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -217,6 +217,7 @@ public MsgEntity evaluateComment(@AuthUser AuthUserEntity authUser, @RequestParam Boolean isLike) { // 添加用户行为 UserBehaviorEntity userBehaviorEntity = new UserBehaviorEntity(bindID, mainType, authUser.getUsername(), null); + userBehaviorEntity.setExtraInfo(BehaviorExtraInfo.COMMENT_ID, commentID); List evaluates = userBehaviorService.checkAndGetUserEvaluateBehavior(userBehaviorEntity, isCancel, isLike); userBehaviorService.setUserEvaluateBehavior(userBehaviorEntity, evaluates); diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java b/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java index fdeb3b0..e60e7f1 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java @@ -37,7 +37,7 @@ public class CommentServiceImpl { private FileExtraService fileExtraService; @DubboReference - private FileService fileService ; + private FileService fileService; public void commentStatisticsChange(Integer itemID, String addNumber, MainType mainType) { switch (mainType){ @@ -97,7 +97,7 @@ public List getComments(Integer bindID, MainType mainType, Intege .and(Sort.by(new Sort.Order(Sort.Direction.ASC, "comments.dislikeNumber")))); ProjectionOperation projectionOperation = Aggregation.project("commentBuildUsername", "commentContent", "hotValue", "likeNumber", "dislikeNumber", "buildDate", "replyCount") - .andExpression("comments._id").as("_id") + .andExpression("comments._id").as("ID") .andExpression("comments.commentBuildUsername").as("commentBuildUsername") .andExpression("comments.commentContent").as("commentContent") .andExpression("comments.hotValue").as("hotValue") diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java index 17862d3..10df130 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java @@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oriole.ocean.common.enumerate.BehaviorExtraInfo; import com.oriole.ocean.common.enumerate.NotifyAction; import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; import com.oriole.ocean.common.enumerate.NotifyType; @@ -23,12 +24,6 @@ @DubboService public class NotifyServiceImpl extends ServiceImpl implements NotifyService { - @Autowired - private NotifySubscriptionServiceImpl notifySubscriptionServiceImpl; - - @Autowired - private UserNotifyServiceImpl userNotifyServiceImpl; - public void addNotify(NotifyEntity notifyEntity){ save(notifyEntity); } @@ -46,7 +41,7 @@ public void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity) { break; case DO_COMMENT_LIKE: notifyEntity.setAction(NotifyAction.LIKE_COMMENT); - notifyEntity.setCommentID(userBehaviorEntity.getExtraInfo().getString("commentID")); + notifyEntity.setCommentID((String) userBehaviorEntity.getExtraInfo(BehaviorExtraInfo.COMMENT_ID)); break; default: return; @@ -54,38 +49,6 @@ public void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity) { notifyEntity.setUserBehaviorID(userBehaviorEntity.getId()); notifyEntity.setTargetIDAndType(String.valueOf(userBehaviorEntity.getBindID()),userBehaviorEntity.getType()); addNotify(notifyEntity); - - NotifySubscriptionTargetType temp; - switch (notifyEntity.getTargetType()) { - case NOTE: - temp = NotifySubscriptionTargetType.NOTE; - break; - case DOCUMENT: - temp = NotifySubscriptionTargetType.DOCUMENT; - break; - default: - temp = NotifySubscriptionTargetType.NOTE; - break; - } - - List notifySubscriptionEntities = - notifySubscriptionServiceImpl.getAllSubscriptionByTargetAndAction( - notifyEntity.getTargetID(), - temp, - notifyEntity.getAction() - ); - - List userNotifyEntities = - Arrays.asList(new UserNotifyEntity[notifySubscriptionEntities.size()]); - - for(int i = 0;i < notifySubscriptionEntities.size();i++) { - userNotifyEntities.get(i).setUsername(notifySubscriptionEntities.get(i).getUsername()); - userNotifyEntities.get(i).setIsRead((byte)0); - userNotifyEntities.get(i).setNotifyID(notifyEntity.getId()); - userNotifyEntities.get(i).setBuildDate(notifyEntity.getBuildDate()); - } - - userNotifyServiceImpl.setUserNotifyList(userNotifyEntities); } // 查询指定时间之后产生的所有消息 From c9553c0a0b7a70ccaa0042c5946267b272f4b33e Mon Sep 17 00:00:00 2001 From: AInfinity-LilacDream <1977741520@qq.com> Date: Thu, 8 May 2025 15:28:53 +0800 Subject: [PATCH 12/62] feat: add create note logic --- .../ocean/common/dto/NoteEntityDTO.java | 19 +++++++++++++++++ .../ocean/common/po/mysql/NoteEntity.java | 13 +++++++++--- .../ocean/controller/NoteController.java | 8 +++++++ .../com/oriole/ocean/service/NoteService.java | 21 +++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 ocean-common/src/main/java/com/oriole/ocean/common/dto/NoteEntityDTO.java diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/dto/NoteEntityDTO.java b/ocean-common/src/main/java/com/oriole/ocean/common/dto/NoteEntityDTO.java new file mode 100644 index 0000000..79b90c0 --- /dev/null +++ b/ocean-common/src/main/java/com/oriole/ocean/common/dto/NoteEntityDTO.java @@ -0,0 +1,19 @@ +package com.oriole.ocean.common.dto; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.time.DateTimeException; +import java.util.Date; + +@Data +@TableName("`note`") +public class NoteEntityDTO implements java.io.Serializable { + private String tag; + private String content; + private String buildUsername; + private Byte isAnon; + private Byte isApproved; + private Byte isAllowComment; +} diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java index d98556d..d3ee5f6 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java @@ -12,17 +12,24 @@ public class NoteEntity implements java.io.Serializable { @TableId("note_id") private Integer noteID; - - private Integer noteType; + private String tag; private String content; + @TableId("like_num") private Integer likeNum; + @TableId("comment_num") private Integer commentNum; + @TableId("read_num") private Integer readNum; + @TableId("refresh_date") private Date refreshDate; + @TableId("build_date") private Date buildDate; + @TableId("build_username") private String buildUsername; + @TableId("is_anon") private Byte isAnon; + @TableId("is_approved") private Byte isApproved; + @TableId("is_allow_comment") private Byte isAllowComment; - } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index a129929..650d7cf 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -7,12 +7,14 @@ import com.oriole.ocean.common.vo.MsgEntity; import com.oriole.ocean.service.NoteService; import com.oriole.ocean.service.NoteTypeService; +import com.oriole.ocean.common.dto.NoteEntityDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.Date; import java.util.List; @RestController @@ -25,6 +27,12 @@ public class NoteController { @Autowired NoteTypeService noteTypeService; + @RequestMapping(value = "/createNote", method = RequestMethod.POST) + public MsgEntity createNote(@RequestParam() NoteEntityDTO noteEntity) { + NoteEntity note = noteService.createNote(noteEntity); + return new MsgEntity<>("SUCCESS", "1", note); + } + @RequestMapping(value = "/getAllNoteType",method = RequestMethod.GET) public MsgEntity> getAllNoteType() { return new MsgEntity<>("SUCCESS", "1", noteTypeService.getAllNoteType()); diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java index 2ad3710..9bd7492 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java @@ -2,11 +2,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oriole.ocean.common.dto.NoteEntityDTO; import com.oriole.ocean.dao.NoteDao; import com.oriole.ocean.common.po.mysql.NoteEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Date; import java.util.List; @Service @@ -19,4 +21,23 @@ public List getNoteByNoteType(Integer noteType){ } return list(queryWrapper); } + + public NoteEntity createNote(NoteEntityDTO noteEntity){ + NoteEntity note = new NoteEntity(); + note.setTag(noteEntity.getTag()); + note.setContent(noteEntity.getContent()); + note.setBuildUsername(noteEntity.getBuildUsername()); + note.setIsAnon(noteEntity.getIsAnon()); + note.setIsApproved(noteEntity.getIsApproved()); + note.setIsAllowComment(noteEntity.getIsAllowComment()); + + note.setLikeNum(0); + note.setCommentNum(0); + note.setReadNum(0); + note.setBuildDate(new Date()); + + // TODO: write note into mysql; allocate noteID + + return note; + } } From 18951f41c1177c15f35cd1186cd5faa92fb10aa9 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Tue, 13 May 2025 10:19:40 +0800 Subject: [PATCH 13/62] fix: deprecate the subscription methods and use database instead DROP TRIGGER IF EXISTS distribute_notify; DELIMITER // CREATE TRIGGER distribute_notify AFTER INSERT ON notify FOR EACH ROW BEGIN INSERT INTO user_notify (username, is_read, notify_id, build_date) SELECT ns.username, '0', NEW.id, NOW() FROM notify_subscription ns WHERE NEW.action = ns.action AND NEW.target_id = ns.target_id; IF NEW.comment_id IS NOT NULL THEN INSERT INTO notify_subscription (target_id, target_type, action, username, build_date) VALUES( NEW.comment_id, 'COMMENT', 'LIKE_COMMENT', NEW.build_username, NOW()), ( NEW.comment_id, 'COMMENT', 'NEW_REPLY', NEW.build_username, NOW()); END IF; END// DELIMITER ; --- .../ocean/controller/UserCommentController.java | 12 +++++++----- .../com/oriole/ocean/service/NotifyServiceImpl.java | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index c1cf61b..c7a013b 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -141,12 +141,14 @@ public MsgEntity addComment(@AuthUser AuthUserEntity authUser, notifyEntity.setCommentID(replyInCommentID); } } + + /*--- DEPRECATED ---*/ // 增加用户消息订阅事件:用户需要订阅自己发布的评论或回复的动态 - List notifyActionList = new ArrayList<>(); - notifyActionList.add(NotifyAction.LIKE_COMMENT); - notifyActionList.add(NotifyAction.NEW_REPLY); - notifySubscriptionService.setNotifySubscription(authUser.getUsername(), notifyActionList, - returnEntity.getId(), NotifySubscriptionTargetType.COMMENT); +// List notifyActionList = new ArrayList<>(); +// notifyActionList.add(NotifyAction.LIKE_COMMENT); +// notifyActionList.add(NotifyAction.NEW_REPLY); +// notifySubscriptionService.setNotifySubscription(authUser.getUsername(), notifyActionList, +// returnEntity.getId(), NotifySubscriptionTargetType.COMMENT); // 产生用户消息事件 notifyService.addNotify(notifyEntity); diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java index 10df130..60bbbf9 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java @@ -32,6 +32,7 @@ public void addNotify(NotifyEntity notifyEntity){ public void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity) { // 收藏、每日签到、阅读等行为都不需要记录为通知行为 NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND,userBehaviorEntity.getDoUsername()); + String targetID = String.valueOf(userBehaviorEntity.getBindID()); switch (userBehaviorEntity.getBehaviorType()) { case DO_DOWNLOAD: notifyEntity.setAction(NotifyAction.DOWNLOAD); @@ -41,13 +42,13 @@ public void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity) { break; case DO_COMMENT_LIKE: notifyEntity.setAction(NotifyAction.LIKE_COMMENT); - notifyEntity.setCommentID((String) userBehaviorEntity.getExtraInfo(BehaviorExtraInfo.COMMENT_ID)); + targetID = (String) userBehaviorEntity.getExtraInfo(BehaviorExtraInfo.COMMENT_ID); break; default: return; } notifyEntity.setUserBehaviorID(userBehaviorEntity.getId()); - notifyEntity.setTargetIDAndType(String.valueOf(userBehaviorEntity.getBindID()),userBehaviorEntity.getType()); + notifyEntity.setTargetIDAndType(targetID,userBehaviorEntity.getType()); addNotify(notifyEntity); } From ed9c2d4a0a59475e0ecce28e37c8e4af625901be Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Wed, 14 May 2025 09:55:59 +0800 Subject: [PATCH 14/62] Revert "fix: deprecate the subscription methods and use database instead" This reverts commit 18951f41c1177c15f35cd1186cd5faa92fb10aa9. --- .../ocean/controller/UserCommentController.java | 12 +++++------- .../com/oriole/ocean/service/NotifyServiceImpl.java | 5 ++--- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index c7a013b..c1cf61b 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -141,14 +141,12 @@ public MsgEntity addComment(@AuthUser AuthUserEntity authUser, notifyEntity.setCommentID(replyInCommentID); } } - - /*--- DEPRECATED ---*/ // 增加用户消息订阅事件:用户需要订阅自己发布的评论或回复的动态 -// List notifyActionList = new ArrayList<>(); -// notifyActionList.add(NotifyAction.LIKE_COMMENT); -// notifyActionList.add(NotifyAction.NEW_REPLY); -// notifySubscriptionService.setNotifySubscription(authUser.getUsername(), notifyActionList, -// returnEntity.getId(), NotifySubscriptionTargetType.COMMENT); + List notifyActionList = new ArrayList<>(); + notifyActionList.add(NotifyAction.LIKE_COMMENT); + notifyActionList.add(NotifyAction.NEW_REPLY); + notifySubscriptionService.setNotifySubscription(authUser.getUsername(), notifyActionList, + returnEntity.getId(), NotifySubscriptionTargetType.COMMENT); // 产生用户消息事件 notifyService.addNotify(notifyEntity); diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java index 60bbbf9..10df130 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java @@ -32,7 +32,6 @@ public void addNotify(NotifyEntity notifyEntity){ public void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity) { // 收藏、每日签到、阅读等行为都不需要记录为通知行为 NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND,userBehaviorEntity.getDoUsername()); - String targetID = String.valueOf(userBehaviorEntity.getBindID()); switch (userBehaviorEntity.getBehaviorType()) { case DO_DOWNLOAD: notifyEntity.setAction(NotifyAction.DOWNLOAD); @@ -42,13 +41,13 @@ public void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity) { break; case DO_COMMENT_LIKE: notifyEntity.setAction(NotifyAction.LIKE_COMMENT); - targetID = (String) userBehaviorEntity.getExtraInfo(BehaviorExtraInfo.COMMENT_ID); + notifyEntity.setCommentID((String) userBehaviorEntity.getExtraInfo(BehaviorExtraInfo.COMMENT_ID)); break; default: return; } notifyEntity.setUserBehaviorID(userBehaviorEntity.getId()); - notifyEntity.setTargetIDAndType(targetID,userBehaviorEntity.getType()); + notifyEntity.setTargetIDAndType(String.valueOf(userBehaviorEntity.getBindID()),userBehaviorEntity.getType()); addNotify(notifyEntity); } From 3403841d62a0f26a7e38d6455168fbaa54407e9e Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Wed, 14 May 2025 11:06:44 +0800 Subject: [PATCH 15/62] fix: remove default null comment in list. --- .../com/oriole/ocean/controller/UserCommentController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index c1cf61b..eb428b8 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -166,7 +166,8 @@ public MsgEntity getComment(@RequestParam Integer bindID, @RequestParam Integer commentCount, @RequestParam Integer replyCount, @RequestParam Integer pageNum) { CommentsListEntity commentsListEntity = commentService.getCommentsListEntity(bindID, mainType); - if (commentsListEntity == null) { + if (commentsListEntity == null || + commentsListEntity.getComments().isEmpty()) { // 新建评论文档 return new MsgEntity<>("SUCCESS", "1", commentService.initCommentArea(bindID, mainType)); } From d1d46534e8f1fae1e3fbdd90d95700ae1179d394 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Wed, 14 May 2025 11:07:33 +0800 Subject: [PATCH 16/62] fix: rename 'ID' to '_id'. --- .../main/java/com/oriole/ocean/service/CommentServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java b/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java index e60e7f1..c0547a3 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java @@ -97,7 +97,7 @@ public List getComments(Integer bindID, MainType mainType, Intege .and(Sort.by(new Sort.Order(Sort.Direction.ASC, "comments.dislikeNumber")))); ProjectionOperation projectionOperation = Aggregation.project("commentBuildUsername", "commentContent", "hotValue", "likeNumber", "dislikeNumber", "buildDate", "replyCount") - .andExpression("comments._id").as("ID") + .andExpression("comments._id").as("_id") .andExpression("comments.commentBuildUsername").as("commentBuildUsername") .andExpression("comments.commentContent").as("commentContent") .andExpression("comments.hotValue").as("hotValue") From 35345bc328030863fa28ec683568aa0fdf116a4f Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Wed, 14 May 2025 11:08:17 +0800 Subject: [PATCH 17/62] feat: try apply auto read method when getting notify --- .../src/main/java/com/oriole/ocean/dao/UserNotifyDao.java | 1 + .../com/oriole/ocean/service/UserNotifyServiceImpl.java | 4 +++- .../src/main/resources/mapper/UserNotifyMapper.xml | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/dao/UserNotifyDao.java b/ocean-notify-service/src/main/java/com/oriole/ocean/dao/UserNotifyDao.java index a629e14..1472df8 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/dao/UserNotifyDao.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/dao/UserNotifyDao.java @@ -8,4 +8,5 @@ public interface UserNotifyDao extends BaseMapper { List getAllNotifyByUsernameAndLastPullDate(String username, Date latestPullDate); + void readAllNotifyByUsernameAndLastPullDate(String username, Date latestPullDate); } diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java index fdc4733..f6dffaf 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java @@ -17,7 +17,9 @@ public class UserNotifyServiceImpl extends ServiceImpl getAllNotifyByUsernameAndLastPullDate(String username, Date latestPullDate){ - return userNotifyDao.getAllNotifyByUsernameAndLastPullDate(username,latestPullDate); + List result = userNotifyDao.getAllNotifyByUsernameAndLastPullDate(username,latestPullDate); + userNotifyDao.readAllNotifyByUsernameAndLastPullDate(username,latestPullDate); + return result; } // 查询用户消息表中最后的更新时间 diff --git a/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml b/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml index 08d6326..07a9f0d 100644 --- a/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml +++ b/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml @@ -25,4 +25,12 @@ AND build_date >= #{latestPullDate} + + + UPDATE user_notify WHERE username = #{username} + SET is_read = 1; + + AND build_date >= #{latestPullDate} + + \ No newline at end of file From 714897cd24460685696c3763c51e18499c81ecf9 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Wed, 14 May 2025 11:30:14 +0800 Subject: [PATCH 18/62] fix: remove query illusions in comment service in MongoDB query in join process removed the auto generated null row. --- .../com/oriole/ocean/controller/UserCommentController.java | 4 ++-- .../java/com/oriole/ocean/service/CommentServiceImpl.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index eb428b8..2be5c5e 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -166,13 +166,13 @@ public MsgEntity getComment(@RequestParam Integer bindID, @RequestParam Integer commentCount, @RequestParam Integer replyCount, @RequestParam Integer pageNum) { CommentsListEntity commentsListEntity = commentService.getCommentsListEntity(bindID, mainType); - if (commentsListEntity == null || - commentsListEntity.getComments().isEmpty()) { + if (commentsListEntity == null) { // 新建评论文档 return new MsgEntity<>("SUCCESS", "1", commentService.initCommentArea(bindID, mainType)); } List commentEntities = commentService.getComments(bindID, mainType, commentCount, replyCount, pageNum); //处理评论 + //commentEntities.removeIf( commentEntity -> commentEntity.getId() == null); for (CommentEntity comment : commentEntities) { //处理评论日期信息 comment.setBuildDate(handleTime(comment.getBuildDate())); diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java b/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java index c0547a3..32f1808 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/service/CommentServiceImpl.java @@ -91,6 +91,8 @@ public CommentsListEntity getCommentsListEntity(Integer bindID, MainType mainTyp public List getComments(Integer bindID, MainType mainType, Integer commentCount, Integer queryReplyCount, Integer pageNum) { List operations = new ArrayList<>(); operations.add(Aggregation.match(Criteria.where("bindID").is(bindID))); + operations.add(Aggregation.match(Criteria.where("comments").exists(true))); + operations.add(Aggregation.match(Criteria.where("comments").not().size(0))); operations.add(Aggregation.unwind("comments", true)); operations.add(Aggregation.sort(Sort.by(new Sort.Order(Sort.Direction.DESC, "comments.hotValue"))) .and(Sort.by(new Sort.Order(Sort.Direction.DESC, "comments.likeNumber"))) From cb1dc1fe96d604528aaf1f253f4f1fd7dbb69011 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Wed, 14 May 2025 11:38:16 +0800 Subject: [PATCH 19/62] feat: enable notify reading process and update SQL trigger DROP TRIGGER IF EXISTS distribute_notify; DELIMITER // CREATE TRIGGER distribute_notify AFTER INSERT ON notify FOR EACH ROW BEGIN INSERT INTO user_notify (username, is_read, notify_id, build_date) SELECT ns.username, '0', NEW.id, NOW() FROM notify_subscription ns WHERE NEW.action = ns.action AND ( (ns.target_type = NEW.target_type AND NEW.comment_id = ns.target_id) OR (ns.target_type = 'COMMENT' AND NEW.comment_id = ns.target_id) ); END// DELIMITER ; --- .../ocean/controller/UserNotifyController.java | 10 ++++++++++ .../java/com/oriole/ocean/dao/UserNotifyDao.java | 2 +- .../oriole/ocean/service/UserNotifyServiceImpl.java | 12 ++++++++---- .../src/main/resources/mapper/UserNotifyMapper.xml | 4 ++-- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/controller/UserNotifyController.java b/ocean-notify-service/src/main/java/com/oriole/ocean/controller/UserNotifyController.java index cc6bb83..cb98709 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/controller/UserNotifyController.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/controller/UserNotifyController.java @@ -37,4 +37,14 @@ public MsgEntity> getLatestNotifications( return new MsgEntity<>("SUCCESS", "1", userNotifyService.getAllNotifyByUsernameAndLastPullDate(username, lastPullDate)); } + + @RequestMapping("/readNotifications") + public MsgEntity readNotifications( + @AuthUser AuthUserEntity authUser, + @RequestParam(required = false) String username, + @RequestParam(required = false) Date latestReadNotifyDate) { + username = authUser.getAllowOperationUsername(username); + + return new MsgEntity<>("SUCCESS", "1", userNotifyService.readAllNotifyByUsernameAndLatestReadNotifyDate(username, latestReadNotifyDate)); + } } diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/dao/UserNotifyDao.java b/ocean-notify-service/src/main/java/com/oriole/ocean/dao/UserNotifyDao.java index 1472df8..9cf0c8f 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/dao/UserNotifyDao.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/dao/UserNotifyDao.java @@ -8,5 +8,5 @@ public interface UserNotifyDao extends BaseMapper { List getAllNotifyByUsernameAndLastPullDate(String username, Date latestPullDate); - void readAllNotifyByUsernameAndLastPullDate(String username, Date latestPullDate); + void readAllNotifyByUsernameAndLatestReadNotifyDate(String username, Date latestReadNotifyDate); } diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java index f6dffaf..3f02dc3 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java @@ -15,11 +15,15 @@ public class UserNotifyServiceImpl extends ServiceImpl getAllNotifyByUsernameAndLastPullDate(String username, Date latestPullDate){ - List result = userNotifyDao.getAllNotifyByUsernameAndLastPullDate(username,latestPullDate); - userNotifyDao.readAllNotifyByUsernameAndLastPullDate(username,latestPullDate); - return result; + return userNotifyDao.getAllNotifyByUsernameAndLastPullDate(username,latestPullDate); + } + + // 用户阅读消息 + public boolean readAllNotifyByUsernameAndLatestReadNotifyDate(String username, Date latestReadNotifyDate){ + userNotifyDao.readAllNotifyByUsernameAndLatestReadNotifyDate(username, latestReadNotifyDate); + return true; } // 查询用户消息表中最后的更新时间 diff --git a/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml b/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml index 07a9f0d..d0b9ba9 100644 --- a/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml +++ b/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml @@ -29,8 +29,8 @@ UPDATE user_notify WHERE username = #{username} SET is_read = 1; - - AND build_date >= #{latestPullDate} + + AND build_date >= #{latestReadNotifyDate} \ No newline at end of file From f98dd3bb570e2836ea6793c9cff70e4bbaac1cb7 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Wed, 14 May 2025 18:20:37 +0800 Subject: [PATCH 20/62] fix: you shall have a name --- .../com/oriole/ocean/controller/UserNotifyController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/controller/UserNotifyController.java b/ocean-notify-service/src/main/java/com/oriole/ocean/controller/UserNotifyController.java index cb98709..6fdcf60 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/controller/UserNotifyController.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/controller/UserNotifyController.java @@ -31,7 +31,7 @@ public class UserNotifyController { @RequestMapping("/getLatestNotifications") public MsgEntity> getLatestNotifications( @AuthUser AuthUserEntity authUser, - @RequestParam(required = false) String username, + @RequestParam String username, @RequestParam(required = false) Date lastPullDate) { username = authUser.getAllowOperationUsername(username); @@ -41,7 +41,7 @@ public MsgEntity> getLatestNotifications( @RequestMapping("/readNotifications") public MsgEntity readNotifications( @AuthUser AuthUserEntity authUser, - @RequestParam(required = false) String username, + @RequestParam String username, @RequestParam(required = false) Date latestReadNotifyDate) { username = authUser.getAllowOperationUsername(username); From 76414eb822d07ef60b10bc14cf596e6f7825e1e6 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Wed, 14 May 2025 18:36:19 +0800 Subject: [PATCH 21/62] feat: add new interface for unread notify check --- .../oriole/ocean/controller/UserNotifyController.java | 9 +++++++++ .../main/java/com/oriole/ocean/dao/UserNotifyDao.java | 1 + .../oriole/ocean/service/UserNotifyServiceImpl.java | 5 +++++ .../src/main/resources/mapper/UserNotifyMapper.xml | 11 +++++++++++ 4 files changed, 26 insertions(+) diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/controller/UserNotifyController.java b/ocean-notify-service/src/main/java/com/oriole/ocean/controller/UserNotifyController.java index 6fdcf60..ee49d13 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/controller/UserNotifyController.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/controller/UserNotifyController.java @@ -47,4 +47,13 @@ public MsgEntity readNotifications( return new MsgEntity<>("SUCCESS", "1", userNotifyService.readAllNotifyByUsernameAndLatestReadNotifyDate(username, latestReadNotifyDate)); } + + @RequestMapping("/ifExistsUnreadNotifications") + public MsgEntity readNotifications( + @AuthUser AuthUserEntity authUser, + @RequestParam String username) { + username = authUser.getAllowOperationUsername(username); + + return new MsgEntity<>("SUCCESS", "1", userNotifyService.checkUnreadNotify(username)); + } } diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/dao/UserNotifyDao.java b/ocean-notify-service/src/main/java/com/oriole/ocean/dao/UserNotifyDao.java index 9cf0c8f..78d26f3 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/dao/UserNotifyDao.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/dao/UserNotifyDao.java @@ -9,4 +9,5 @@ public interface UserNotifyDao extends BaseMapper { List getAllNotifyByUsernameAndLastPullDate(String username, Date latestPullDate); void readAllNotifyByUsernameAndLatestReadNotifyDate(String username, Date latestReadNotifyDate); + boolean checkUnreadNotify(String username); } diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java index 3f02dc3..d84cb62 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/UserNotifyServiceImpl.java @@ -26,6 +26,11 @@ public boolean readAllNotifyByUsernameAndLatestReadNotifyDate(String username, D return true; } + // 用户阅读消息 + public boolean checkUnreadNotify(String username){ + return userNotifyDao.checkUnreadNotify(username); + } + // 查询用户消息表中最后的更新时间 public Date getUserNotifyLastUpdateTime() { QueryWrapper queryWrapper = new QueryWrapper<>(); diff --git a/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml b/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml index d0b9ba9..54a4825 100644 --- a/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml +++ b/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml @@ -33,4 +33,15 @@ AND build_date >= #{latestReadNotifyDate} + + \ No newline at end of file From a89376bfe7b74783d5cadada71fc3bc8fc416e41 Mon Sep 17 00:00:00 2001 From: AInfinity-LilacDream <1977741520@qq.com> Date: Sat, 17 May 2025 21:32:47 +0800 Subject: [PATCH 22/62] minor: update NoteEntity --- .../com/oriole/ocean/common/po/mysql/NoteEntity.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java index d3ee5f6..7b96fb2 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java @@ -14,22 +14,13 @@ public class NoteEntity implements java.io.Serializable { private Integer noteID; private String tag; private String content; - @TableId("like_num") private Integer likeNum; - @TableId("comment_num") private Integer commentNum; - @TableId("read_num") private Integer readNum; - @TableId("refresh_date") private Date refreshDate; - @TableId("build_date") private Date buildDate; - @TableId("build_username") private String buildUsername; - @TableId("is_anon") + private boolean isDeleted; private Byte isAnon; - @TableId("is_approved") - private Byte isApproved; - @TableId("is_allow_comment") private Byte isAllowComment; } From aad5d6ef1cee6a4d03f690b7c7a382919693d0e3 Mon Sep 17 00:00:00 2001 From: SeleiXi Date: Sat, 17 May 2025 21:46:53 +0800 Subject: [PATCH 23/62] refactor: standardize project structure, convert NoteService and NoteTypeService to interfaces --- .../com/oriole/ocean/service/NoteService.java | 48 +++++-------------- .../oriole/ocean/service/NoteTypeService.java | 17 +++---- .../ocean/service/impl/NoteServiceImpl.java | 47 ++++++++++++++++++ .../service/impl/NoteTypeServiceImpl.java | 20 ++++++++ 4 files changed, 86 insertions(+), 46 deletions(-) create mode 100644 ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteServiceImpl.java create mode 100644 ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteTypeServiceImpl.java diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java index 9bd7492..2b2eac7 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java @@ -1,43 +1,21 @@ package com.oriole.ocean.service; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.oriole.ocean.common.dto.NoteEntityDTO; -import com.oriole.ocean.dao.NoteDao; import com.oriole.ocean.common.po.mysql.NoteEntity; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Date; import java.util.List; -@Service -@Transactional -public class NoteService extends ServiceImpl { - public List getNoteByNoteType(Integer noteType){ - QueryWrapper queryWrapper = new QueryWrapper<>(); - if(noteType!=null) { - queryWrapper.eq("note_type", noteType); - } - return list(queryWrapper); - } - - public NoteEntity createNote(NoteEntityDTO noteEntity){ - NoteEntity note = new NoteEntity(); - note.setTag(noteEntity.getTag()); - note.setContent(noteEntity.getContent()); - note.setBuildUsername(noteEntity.getBuildUsername()); - note.setIsAnon(noteEntity.getIsAnon()); - note.setIsApproved(noteEntity.getIsApproved()); - note.setIsAllowComment(noteEntity.getIsAllowComment()); - - note.setLikeNum(0); - note.setCommentNum(0); - note.setReadNum(0); - note.setBuildDate(new Date()); - - // TODO: write note into mysql; allocate noteID +public interface NoteService { + /** + * 根据笔记类型获取笔记列表 + * @param noteType 笔记类型 + * @return 笔记列表 + */ + List getNoteByNoteType(Integer noteType); - return note; - } + /** + * 创建新笔记 + * @param noteEntity 笔记信息 + * @return 创建的笔记实体 + */ + NoteEntity createNote(NoteEntityDTO noteEntity); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java index b021e9a..723325d 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java @@ -1,17 +1,12 @@ package com.oriole.ocean.service; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.dao.NoteTypeDao; import com.oriole.ocean.common.po.mysql.NoteTypeEntity; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - import java.util.List; -@Service -@Transactional -public class NoteTypeService extends ServiceImpl { - public List getAllNoteType(){ - return list(); - } +public interface NoteTypeService { + /** + * 获取所有笔记类型 + * @return 笔记类型列表 + */ + List getAllNoteType(); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteServiceImpl.java new file mode 100644 index 0000000..cb4756e --- /dev/null +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteServiceImpl.java @@ -0,0 +1,47 @@ +package com.oriole.ocean.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oriole.ocean.common.dto.NoteEntityDTO; +import com.oriole.ocean.dao.NoteDao; +import com.oriole.ocean.common.po.mysql.NoteEntity; +import com.oriole.ocean.service.NoteService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.List; + +@Service +@Transactional +public class NoteServiceImpl extends ServiceImpl implements NoteService { + + @Override + public List getNoteByNoteType(Integer noteType) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if(noteType != null) { + queryWrapper.eq("note_type", noteType); + } + return list(queryWrapper); + } + + @Override + public NoteEntity createNote(NoteEntityDTO noteEntity) { + NoteEntity note = new NoteEntity(); + note.setTag(noteEntity.getTag()); + note.setContent(noteEntity.getContent()); + note.setBuildUsername(noteEntity.getBuildUsername()); + note.setIsAnon(noteEntity.getIsAnon()); + note.setIsApproved(noteEntity.getIsApproved()); + note.setIsAllowComment(noteEntity.getIsAllowComment()); + + note.setLikeNum(0); + note.setCommentNum(0); + note.setReadNum(0); + note.setBuildDate(new Date()); + + // TODO: write note into mysql; allocate noteID + + return note; + } +} \ No newline at end of file diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteTypeServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteTypeServiceImpl.java new file mode 100644 index 0000000..1ecc3e7 --- /dev/null +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteTypeServiceImpl.java @@ -0,0 +1,20 @@ +package com.oriole.ocean.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oriole.ocean.dao.NoteTypeDao; +import com.oriole.ocean.common.po.mysql.NoteTypeEntity; +import com.oriole.ocean.service.NoteTypeService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +@Transactional +public class NoteTypeServiceImpl extends ServiceImpl implements NoteTypeService { + + @Override + public List getAllNoteType() { + return list(); + } +} \ No newline at end of file From 091f198036f74cb5944103aceaed3065aab67891 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sat, 17 May 2025 23:07:00 +0800 Subject: [PATCH 24/62] feat: add note database logic Sorry SeleiXi, I've already done something. --- .../ocean/common/dto/NoteEntityDTO.java | 19 ----- .../ocean/common/po/mysql/NoteEntity.java | 22 +++--- .../ocean/common/po/mysql/NoteLikeEntity.java | 18 +++++ .../ocean/controller/NoteController.java | 41 +++++++---- .../java/com/oriole/ocean/dao/NoteDao.java | 8 +++ .../com/oriole/ocean/service/NoteService.java | 70 +++++++++++++++---- .../src/main/resources/mapper/NoteMapper.xml | 53 ++++++++++++++ .../resources/mapper/UserNotifyMapper.xml | 5 +- 8 files changed, 178 insertions(+), 58 deletions(-) delete mode 100644 ocean-common/src/main/java/com/oriole/ocean/common/dto/NoteEntityDTO.java create mode 100644 ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteLikeEntity.java create mode 100644 ocean-note-service/src/main/resources/mapper/NoteMapper.xml diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/dto/NoteEntityDTO.java b/ocean-common/src/main/java/com/oriole/ocean/common/dto/NoteEntityDTO.java deleted file mode 100644 index 79b90c0..0000000 --- a/ocean-common/src/main/java/com/oriole/ocean/common/dto/NoteEntityDTO.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.oriole.ocean.common.dto; - -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; - -import java.time.DateTimeException; -import java.util.Date; - -@Data -@TableName("`note`") -public class NoteEntityDTO implements java.io.Serializable { - private String tag; - private String content; - private String buildUsername; - private Byte isAnon; - private Byte isApproved; - private Byte isAllowComment; -} diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java index 7b96fb2..2e45981 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java @@ -10,17 +10,21 @@ @Data @TableName("`note`") public class NoteEntity implements java.io.Serializable { - @TableId("note_id") - private Integer noteID; - private String tag; + @TableId("id") + private Integer id; + private String buildUsername; + // contents private String content; - private Integer likeNum; - private Integer commentNum; - private Integer readNum; - private Date refreshDate; + private String tag; + // extra info private Date buildDate; - private String buildUsername; - private boolean isDeleted; + private Date refreshDate; + // states + private Byte isDeleted; private Byte isAnon; private Byte isAllowComment; + // statistics (changing with relation 'likes') + private Integer likeNum; + private Integer commentNum; + private Integer readNum; } diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteLikeEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteLikeEntity.java new file mode 100644 index 0000000..e6eb2eb --- /dev/null +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteLikeEntity.java @@ -0,0 +1,18 @@ +package com.oriole.ocean.common.po.mysql; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("`note_like`") +public class NoteLikeEntity implements java.io.Serializable { + @TableId(type = IdType.AUTO) + private Integer id; // 自增主键(ORM需要,业务无关) + + private Integer postId; // 帖子ID + private Integer userId; // 用户ID +} diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index 650d7cf..226855b 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -2,19 +2,17 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.oriole.ocean.common.auth.AuthUser; import com.oriole.ocean.common.po.mysql.NoteEntity; -import com.oriole.ocean.common.po.mysql.NoteTypeEntity; +import com.oriole.ocean.common.vo.AuthUserEntity; import com.oriole.ocean.common.vo.MsgEntity; import com.oriole.ocean.service.NoteService; -import com.oriole.ocean.service.NoteTypeService; -import com.oriole.ocean.common.dto.NoteEntityDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.util.Date; import java.util.List; @RestController @@ -24,24 +22,41 @@ public class NoteController { @Autowired NoteService noteService; - @Autowired - NoteTypeService noteTypeService; + @RequestMapping(value = "/getLatestNote", method = RequestMethod.POST) + public MsgEntity> getNoteByPage( + @RequestParam int pageNO, + @RequestParam int pageSize) { + PageHelper.startPage(pageNO, pageSize, true); + List noteEntityList = noteService.getLatestNotes(); + PageInfo pageInfo = new PageInfo<>(noteEntityList); + return new MsgEntity<>("SUCCESS","1",pageInfo); + } @RequestMapping(value = "/createNote", method = RequestMethod.POST) - public MsgEntity createNote(@RequestParam() NoteEntityDTO noteEntity) { + public MsgEntity createNote( + @AuthUser AuthUserEntity authUser, + @RequestParam() NoteEntity noteEntity) { + noteEntity.setBuildUsername(authUser.getUsername()); NoteEntity note = noteService.createNote(noteEntity); return new MsgEntity<>("SUCCESS", "1", note); } - @RequestMapping(value = "/getAllNoteType",method = RequestMethod.GET) - public MsgEntity> getAllNoteType() { - return new MsgEntity<>("SUCCESS", "1", noteTypeService.getAllNoteType()); + @RequestMapping(value = "/deleteNote", method = RequestMethod.POST) + public MsgEntity deleteNote( + @AuthUser AuthUserEntity authUser, + @RequestParam() int noteID) { + if(!noteService.deleteNote(noteID, authUser.getUsername())) + return new MsgEntity<>("FAILED", "400", "Invalid Note ID or Wrong User"); + return new MsgEntity<>("SUCCESS", "1", "山本!お前の先人を犯してやる!"); } - @RequestMapping(value = "/getNoteByNoteType",method = RequestMethod.GET) - public MsgEntity> getNoteByNoteType(@RequestParam(required = false) Integer noteType,@RequestParam Integer pageNum, @RequestParam Integer pageSize) { + @RequestMapping(value = "/getNoteByTag",method = RequestMethod.GET) + public MsgEntity> getNoteByTag( + @RequestParam(required = false) String tag, + @RequestParam Integer pageNum, + @RequestParam Integer pageSize) { PageHelper.startPage(pageNum, pageSize, true); - List noteEntityList = noteService.getNoteByNoteType(noteType); + List noteEntityList = noteService.getNotesByTag(tag); PageInfo pageInfo = new PageInfo<>(noteEntityList); return new MsgEntity<>("SUCCESS", "1", pageInfo); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java index 4bb9739..62e97bb 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java @@ -2,6 +2,14 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.oriole.ocean.common.po.mysql.NoteEntity; +import com.oriole.ocean.common.po.mysql.UserNotifyEntity; + +import java.util.Date; +import java.util.List; public interface NoteDao extends BaseMapper { + List getLatestNotes(); + void deleteNote(int noteId, String username); + boolean checkNoteBuilder(int noteId, String username); + List getNotesByTag(String tag); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java index 2b2eac7..0872c95 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java @@ -1,21 +1,61 @@ package com.oriole.ocean.service; -import com.oriole.ocean.common.dto.NoteEntityDTO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oriole.ocean.dao.NoteDao; import com.oriole.ocean.common.po.mysql.NoteEntity; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; import java.util.List; -public interface NoteService { - /** - * 根据笔记类型获取笔记列表 - * @param noteType 笔记类型 - * @return 笔记列表 - */ - List getNoteByNoteType(Integer noteType); - - /** - * 创建新笔记 - * @param noteEntity 笔记信息 - * @return 创建的笔记实体 - */ - NoteEntity createNote(NoteEntityDTO noteEntity); +@Service +@Transactional +public class NoteService extends ServiceImpl { + + @Resource + private NoteDao noteDao; + + public List getNoteByNoteType(Integer noteType){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + if(noteType!=null) { + queryWrapper.eq("note_type", noteType); + } + return list(queryWrapper); + } + + public void addNote(NoteEntity note){ + save(note); + } + + public boolean deleteNote(int noteID, String username){ + if(!noteDao.checkNoteBuilder(noteID, username)) { + return false; + } + noteDao.deleteNote(noteID, username); + return true; + } + + public List getLatestNotes() { + return noteDao.getLatestNotes(); + } + + public List getNotesByTag(String tag) { + return noteDao.getNotesByTag(tag); + } + + public NoteEntity createNote(NoteEntity noteEntity){ + noteEntity.setBuildDate(new Date()); + noteEntity.setRefreshDate(new Date()); + noteEntity.setCommentNum(0); + noteEntity.setLikeNum(0); + noteEntity.setReadNum(0); + noteEntity.setIsDeleted((byte) 0); + + addNote(noteEntity); + + return noteEntity; + } } diff --git a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml new file mode 100644 index 0000000..1722c53 --- /dev/null +++ b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + UPDATE note + SET is_deleted = 1 + WHERE note.id = #{noteID} AND note.buildUsername = #{username}; + + + \ No newline at end of file diff --git a/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml b/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml index 54a4825..d7faf0c 100644 --- a/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml +++ b/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml @@ -27,8 +27,9 @@ - UPDATE user_notify WHERE username = #{username} - SET is_read = 1; + UPDATE user_notify + SET is_read = 1 + WHERE username = #{username}; AND build_date >= #{latestReadNotifyDate} From 74c57cd069709fe443c7e9c28207a1213dbb2334 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sun, 18 May 2025 00:06:25 +0800 Subject: [PATCH 25/62] fix: specify what frontend should give. --- .../ocean/common/service/NoteService.java | 15 ++++++ .../ocean/controller/NoteController.java | 12 ++++- ...{NoteService.java => NoteServiceImpl.java} | 17 ++----- .../{impl => }/NoteTypeServiceImpl.java | 3 +- .../ocean/service/impl/NoteServiceImpl.java | 47 ------------------- 5 files changed, 30 insertions(+), 64 deletions(-) create mode 100644 ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java rename ocean-note-service/src/main/java/com/oriole/ocean/service/{NoteService.java => NoteServiceImpl.java} (73%) rename ocean-note-service/src/main/java/com/oriole/ocean/service/{impl => }/NoteTypeServiceImpl.java (85%) delete mode 100644 ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteServiceImpl.java diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java new file mode 100644 index 0000000..33cef49 --- /dev/null +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java @@ -0,0 +1,15 @@ +package com.oriole.ocean.common.service; + +import com.oriole.ocean.common.po.mysql.NoteEntity; +import java.util.List; + +public interface NoteService { + + boolean deleteNote(int noteID, String username); + + List getLatestNotes(); + + List getNotesByTag(String tag); + + NoteEntity createNote(NoteEntity noteEntity); +} diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index 226855b..148b6c7 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -6,7 +6,7 @@ import com.oriole.ocean.common.po.mysql.NoteEntity; import com.oriole.ocean.common.vo.AuthUserEntity; import com.oriole.ocean.common.vo.MsgEntity; -import com.oriole.ocean.service.NoteService; +import com.oriole.ocean.common.service.NoteService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -35,8 +35,16 @@ public MsgEntity> getNoteByPage( @RequestMapping(value = "/createNote", method = RequestMethod.POST) public MsgEntity createNote( @AuthUser AuthUserEntity authUser, - @RequestParam() NoteEntity noteEntity) { + @RequestParam String content, + @RequestParam String tag, + @RequestParam Byte isAnon, + @RequestParam Byte isAllowComment) { + NoteEntity noteEntity = new NoteEntity(); noteEntity.setBuildUsername(authUser.getUsername()); + noteEntity.setContent(content); + noteEntity.setTag(tag); + noteEntity.setIsAnon(isAnon); + noteEntity.setIsAllowComment(isAllowComment); NoteEntity note = noteService.createNote(noteEntity); return new MsgEntity<>("SUCCESS", "1", note); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java similarity index 73% rename from ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java rename to ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java index 0872c95..f7abe61 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteService.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java @@ -1,7 +1,7 @@ package com.oriole.ocean.service; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oriole.ocean.common.service.NoteService; import com.oriole.ocean.dao.NoteDao; import com.oriole.ocean.common.po.mysql.NoteEntity; import org.springframework.stereotype.Service; @@ -13,20 +13,11 @@ @Service @Transactional -public class NoteService extends ServiceImpl { - +public class NoteServiceImpl extends ServiceImpl implements NoteService { @Resource private NoteDao noteDao; - public List getNoteByNoteType(Integer noteType){ - QueryWrapper queryWrapper = new QueryWrapper<>(); - if(noteType!=null) { - queryWrapper.eq("note_type", noteType); - } - return list(queryWrapper); - } - - public void addNote(NoteEntity note){ + private void addNote(NoteEntity note){ save(note); } @@ -58,4 +49,4 @@ public NoteEntity createNote(NoteEntity noteEntity){ return noteEntity; } -} +} \ No newline at end of file diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteTypeServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeServiceImpl.java similarity index 85% rename from ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteTypeServiceImpl.java rename to ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeServiceImpl.java index 1ecc3e7..eb56c64 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteTypeServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeServiceImpl.java @@ -1,9 +1,8 @@ -package com.oriole.ocean.service.impl; +package com.oriole.ocean.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.oriole.ocean.dao.NoteTypeDao; import com.oriole.ocean.common.po.mysql.NoteTypeEntity; -import com.oriole.ocean.service.NoteTypeService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteServiceImpl.java deleted file mode 100644 index cb4756e..0000000 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/impl/NoteServiceImpl.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.oriole.ocean.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.dto.NoteEntityDTO; -import com.oriole.ocean.dao.NoteDao; -import com.oriole.ocean.common.po.mysql.NoteEntity; -import com.oriole.ocean.service.NoteService; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Date; -import java.util.List; - -@Service -@Transactional -public class NoteServiceImpl extends ServiceImpl implements NoteService { - - @Override - public List getNoteByNoteType(Integer noteType) { - QueryWrapper queryWrapper = new QueryWrapper<>(); - if(noteType != null) { - queryWrapper.eq("note_type", noteType); - } - return list(queryWrapper); - } - - @Override - public NoteEntity createNote(NoteEntityDTO noteEntity) { - NoteEntity note = new NoteEntity(); - note.setTag(noteEntity.getTag()); - note.setContent(noteEntity.getContent()); - note.setBuildUsername(noteEntity.getBuildUsername()); - note.setIsAnon(noteEntity.getIsAnon()); - note.setIsApproved(noteEntity.getIsApproved()); - note.setIsAllowComment(noteEntity.getIsAllowComment()); - - note.setLikeNum(0); - note.setCommentNum(0); - note.setReadNum(0); - note.setBuildDate(new Date()); - - // TODO: write note into mysql; allocate noteID - - return note; - } -} \ No newline at end of file From 7a07de8f9b0357c2048d9374bdbfa6d86004a6e9 Mon Sep 17 00:00:00 2001 From: cms42 Date: Sun, 18 May 2025 00:17:09 +0800 Subject: [PATCH 26/62] feat: implement getMyFileList API to support "myUpload" page --- .../ocean/controller/DocInfoController.java | 30 ++++++++++++ .../com/oriole/ocean/dao/FileInfoDao.java | 49 +++++++++++++++++++ .../oriole/ocean/model/FileExtraEntity.java | 19 +++++++ .../java/com/oriole/ocean/model/FileInfo.java | 35 +++++++++++++ .../oriole/ocean/service/DocInfoService.java | 19 +++++++ .../service/impl/DocInfoServiceImpl.java | 38 ++++++++++++++ 6 files changed, 190 insertions(+) create mode 100644 ocean-docs-service/src/main/java/com/oriole/ocean/dao/FileInfoDao.java create mode 100644 ocean-docs-service/src/main/java/com/oriole/ocean/model/FileExtraEntity.java create mode 100644 ocean-docs-service/src/main/java/com/oriole/ocean/model/FileInfo.java create mode 100644 ocean-docs-service/src/main/java/com/oriole/ocean/service/DocInfoService.java create mode 100644 ocean-docs-service/src/main/java/com/oriole/ocean/service/impl/DocInfoServiceImpl.java diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocInfoController.java b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocInfoController.java index cc17eec..fe63f52 100644 --- a/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocInfoController.java +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/controller/DocInfoController.java @@ -15,18 +15,25 @@ import com.oriole.ocean.common.vo.MsgEntity; import com.oriole.ocean.service.FileCheckServiceImpl; import com.oriole.ocean.service.FileServiceImpl; +import com.oriole.ocean.model.FileInfo; +import com.oriole.ocean.service.DocInfoService; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; +import java.util.Map; import static com.oriole.ocean.common.enumerate.ResultCode.*; +/** + * Controller for handling document information related requests. + */ @RestController //@Slf4j @RequestMapping("/docInfoService") @@ -41,6 +48,9 @@ public class DocInfoController { @Autowired FileCheckServiceImpl fileCheckService; + @Autowired + private DocInfoService docInfoService; + @RequestMapping(value = "/getFileList", method = RequestMethod.GET) public MsgEntity> getFileList(@AuthUser AuthUserEntity authUser, @RequestParam(required = false) String username, @@ -185,4 +195,24 @@ public MsgEntity submitFolderInfo(@AuthUser String username, @RequestPar fileService.saveOrUpdateFileInfo(new FileEntity(title, abstractContent, username, folderID)); return new MsgEntity<>(SUCCESS); } + + /** + * Retrieves a paginated list of files owned by the current user. + * + * @param authUser Current authenticated user + * @param isFolder Whether to fetch folders (false for files) + * @param pageNum Page number for pagination + * @param pageSize Number of items per page + * @return MsgEntity containing the list of files and pagination info + */ + @GetMapping("/getMyFileList") + public MsgEntity> getMyFileList( + @AuthUser AuthUserEntity authUser, + @RequestParam boolean isFolder, + @RequestParam int pageNum, + @RequestParam int pageSize) { + + Map result = docInfoService.getMyFileList(authUser.getUsername(), isFolder, pageNum, pageSize); + return new MsgEntity<>("SUCCESS", "1", result); + } } diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/dao/FileInfoDao.java b/ocean-docs-service/src/main/java/com/oriole/ocean/dao/FileInfoDao.java new file mode 100644 index 0000000..3af9179 --- /dev/null +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/dao/FileInfoDao.java @@ -0,0 +1,49 @@ +package com.oriole.ocean.dao; + +import com.oriole.ocean.model.FileInfo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * Data Access Object for file information operations. + */ +@Mapper +public interface FileInfoDao { + + /** + * Counts the total number of files owned by the current user. + * + * @param username Username of the current user + * @param isFolder Whether to count folders (false for files) + * @return Total count of files + */ + @Select("SELECT COUNT(*) FROM file f " + + "WHERE f.upload_username = #{username} " + + "AND ((#{isFolder} = true AND f.file_id IN (SELECT folder_id FROM file WHERE folder_id IS NOT NULL)) " + + "OR (#{isFolder} = false AND f.file_id NOT IN (SELECT folder_id FROM file WHERE folder_id IS NOT NULL)))") + int countMyFiles(@Param("username") String username, @Param("isFolder") boolean isFolder); + + /** + * Retrieves a paginated list of files owned by the current user. + * + * @param username Username of the current user + * @param isFolder Whether to fetch folders (false for files) + * @param offset Offset for pagination + * @param limit Number of items to fetch + * @return List of file information + */ + @Select("SELECT f.*, fe.* FROM file f " + + "LEFT JOIN file_extra fe ON f.file_id = fe.file_id " + + "WHERE f.upload_username = #{username} " + + "AND ((#{isFolder} = true AND f.file_id IN (SELECT folder_id FROM file WHERE folder_id IS NOT NULL)) " + + "OR (#{isFolder} = false AND f.file_id NOT IN (SELECT folder_id FROM file WHERE folder_id IS NOT NULL))) " + + "ORDER BY f.upload_date DESC " + + "LIMIT #{offset}, #{limit}") + List getMyFiles(@Param("username") String username, + @Param("isFolder") boolean isFolder, + @Param("offset") int offset, + @Param("limit") int limit); +} \ No newline at end of file diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/model/FileExtraEntity.java b/ocean-docs-service/src/main/java/com/oriole/ocean/model/FileExtraEntity.java new file mode 100644 index 0000000..430988c --- /dev/null +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/model/FileExtraEntity.java @@ -0,0 +1,19 @@ +package com.oriole.ocean.model; + +import lombok.Data; + +/** + * Represents additional statistics and metadata for a file. + */ +@Data +public class FileExtraEntity { + private Integer readNum; + private Double score; + private Integer ratersNum; + private Boolean isVipIncome; + private Integer downloadNum; + private Integer likeNum; + private Integer collectionNum; + private Integer commentNum; + private Integer isProCert; +} \ No newline at end of file diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/model/FileInfo.java b/ocean-docs-service/src/main/java/com/oriole/ocean/model/FileInfo.java new file mode 100644 index 0000000..f146e56 --- /dev/null +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/model/FileInfo.java @@ -0,0 +1,35 @@ +package com.oriole.ocean.model; + +import lombok.Data; +import java.util.List; + +/** + * Represents a file's information in the system. + */ +@Data +public class FileInfo { + private Integer fileId; + private String title; + private String abstractContent; + private String fileType; + private String previewPictureObjectName; + private String uploadDate; + private Integer paymentMethod; + private Integer paymentAmount; + private List tagNames; + private FileExtraEntity fileExtraEntity; + + // Additional fields from file table + private Integer size; + private Integer folderId; + private String previewPdfObjectName; + private String uploadUsername; + private String realObjectName; + private Double hideScore; + private Boolean isApproved; + private Boolean isAllowAnon; + private Boolean isAllowVipfree; + private Boolean isAllowComment; + private String indexString; + private Integer typeId; +} \ No newline at end of file diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocInfoService.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocInfoService.java new file mode 100644 index 0000000..e0e0cb0 --- /dev/null +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/DocInfoService.java @@ -0,0 +1,19 @@ +package com.oriole.ocean.service; + +import java.util.Map; + +/** + * Service interface for document information operations. + */ +public interface DocInfoService { + /** + * Retrieves a paginated list of files owned by the current user. + * + * @param username Username of the current user + * @param isFolder Whether to fetch folders (false for files) + * @param pageNum Page number for pagination + * @param pageSize Number of items per page + * @return Map containing the list of files and pagination info + */ + Map getMyFileList(String username, boolean isFolder, int pageNum, int pageSize); +} \ No newline at end of file diff --git a/ocean-docs-service/src/main/java/com/oriole/ocean/service/impl/DocInfoServiceImpl.java b/ocean-docs-service/src/main/java/com/oriole/ocean/service/impl/DocInfoServiceImpl.java new file mode 100644 index 0000000..9b8a1ab --- /dev/null +++ b/ocean-docs-service/src/main/java/com/oriole/ocean/service/impl/DocInfoServiceImpl.java @@ -0,0 +1,38 @@ +package com.oriole.ocean.service.impl; + +import com.oriole.ocean.dao.FileInfoDao; +import com.oriole.ocean.model.FileInfo; +import com.oriole.ocean.service.DocInfoService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Implementation of the document information service. + */ +@Service +public class DocInfoServiceImpl implements DocInfoService { + + @Autowired + private FileInfoDao fileInfoDao; + + @Override + public Map getMyFileList(String username, boolean isFolder, int pageNum, int pageSize) { + // Calculate offset for pagination + int offset = (pageNum - 1) * pageSize; + + // Get total count and list of files + int totalCount = fileInfoDao.countMyFiles(username, isFolder); + List files = fileInfoDao.getMyFiles(username, isFolder, offset, pageSize); + + // Prepare response + Map result = new HashMap<>(); + result.put("list", files); + result.put("isLastPage", (offset + pageSize) >= totalCount); + + return result; + } +} \ No newline at end of file From 1c3eb5f5007dfe7ddd026a3ae70f241cab75c99e Mon Sep 17 00:00:00 2001 From: cms42 Date: Sun, 18 May 2025 00:54:24 +0800 Subject: [PATCH 27/62] feat: implement updateUserInfo interface to support `edit my profile` feature --- .../ocean/controller/UserInfoController.java | 18 ++++++++ .../oriole/ocean/dto/UserInfoUpdateDTO.java | 31 +++++++++++++ .../ocean/service/UserInfoServiceImpl.java | 46 +++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 ocean-user-service/src/main/java/com/oriole/ocean/dto/UserInfoUpdateDTO.java diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java index 4f36fe8..05be2bd 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java @@ -6,6 +6,7 @@ import com.oriole.ocean.common.vo.AuthUserEntity; import com.oriole.ocean.common.vo.BusinessException; import com.oriole.ocean.common.vo.MsgEntity; +import com.oriole.ocean.dto.UserInfoUpdateDTO; import com.oriole.ocean.service.UserInfoServiceImpl; import com.oriole.ocean.service.base.UserBaseInfoServiceImpl; import lombok.extern.slf4j.Slf4j; @@ -48,4 +49,21 @@ public MsgEntity getUserAllInfo(@AuthUser AuthUserEntity authUser) { return new MsgEntity<>("SUCCESS", "1", userInfoService.getUserInfo(authUser.getUsername(), UserInfoLevel.ALL)); } + + @PostMapping("/updateUserInfo") + /** + * Update user personal information. Only non-null fields will be updated. + * @param authUser Authenticated user (from token) + * @param updateDTO Fields to update + * @return Success message or error + */ + public MsgEntity updateUserInfo(@AuthUser AuthUserEntity authUser, @RequestBody UserInfoUpdateDTO updateDTO) { + try { + userInfoService.updateUserInfo(authUser.getUsername(), updateDTO); + return new MsgEntity<>("SUCCESS", "1", "User info updated successfully"); + } catch (Exception e) { + log.error("Failed to update user info for {}: {}", authUser.getUsername(), e.getMessage(), e); + throw new BusinessException("-1", "Failed to update user info: " + e.getMessage()); + } + } } diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/dto/UserInfoUpdateDTO.java b/ocean-user-service/src/main/java/com/oriole/ocean/dto/UserInfoUpdateDTO.java new file mode 100644 index 0000000..24badc9 --- /dev/null +++ b/ocean-user-service/src/main/java/com/oriole/ocean/dto/UserInfoUpdateDTO.java @@ -0,0 +1,31 @@ +package com.oriole.ocean.dto; + +import lombok.Data; +import java.io.Serializable; +import java.util.Date; + +/** + * Data Transfer Object for updating user information. + * Supports partial updates for both user and user_extra fields. + * Fields left null will not be updated. + * + * MAY NEED REVIEW: Adjust fields as needed for your business logic. + */ +@Data +public class UserInfoUpdateDTO implements Serializable { + // User table fields + private String nickname; + private String email; + private String phoneNum; + private String realname; + private String avatar; + private Integer levelGrade; + private Integer certID; + + // UserExtra table fields + private String college; + private String major; + private Date birthday; + private Integer sex; + private String personalSignature; +} \ No newline at end of file diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/UserInfoServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/UserInfoServiceImpl.java index 97ec15a..344c9be 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/UserInfoServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/UserInfoServiceImpl.java @@ -8,6 +8,8 @@ import com.oriole.ocean.service.base.UserCertificationServiceImpl; import com.oriole.ocean.service.base.UserExtraInfoServiceImpl; import com.oriole.ocean.service.base.UserWalletServiceImpl; +import com.oriole.ocean.dto.UserInfoUpdateDTO; +import com.oriole.ocean.common.po.mysql.UserExtraEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestParam; @@ -51,4 +53,48 @@ public UserEntity getUserInfo(String username, UserInfoLevel userInfoLevel) { throw new RuntimeException("not support this userInfo level"); } } + + /** + * Update user and user_extra info for the given username. Only non-null fields in updateDTO will be updated. + * @param username Username to update + * @param updateDTO DTO containing fields to update + * @throws BusinessException if user does not exist or update fails + */ + public void updateUserInfo(String username, UserInfoUpdateDTO updateDTO) { + UserEntity user = userService.getById(username); + if (user == null) { + throw new BusinessException("-2", "User not found"); + } + boolean userChanged = false; + // Update user fields + if (updateDTO.getNickname() != null) { user.setNickname(updateDTO.getNickname()); userChanged = true; } + if (updateDTO.getEmail() != null) { user.setEmail(updateDTO.getEmail()); userChanged = true; } + if (updateDTO.getPhoneNum() != null) { user.setPhoneNum(updateDTO.getPhoneNum()); userChanged = true; } + if (updateDTO.getRealname() != null) { user.setRealname(updateDTO.getRealname()); userChanged = true; } + if (updateDTO.getAvatar() != null) { user.setAvatar(updateDTO.getAvatar()); userChanged = true; } + if (updateDTO.getLevelGrade() != null) { user.setLevelGrade(updateDTO.getLevelGrade()); userChanged = true; } + if (updateDTO.getCertID() != null) { user.setCertID(updateDTO.getCertID()); userChanged = true; } + if (userChanged) { + if (!userService.updateById(user)) { + throw new BusinessException("-3", "Failed to update user base info"); + } + } + // Update user_extra fields + UserExtraEntity extra = userExtraService.getById(username); + boolean extraChanged = false; + if (extra == null) { + extra = new UserExtraEntity(); + extra.setUsername(username); + } + if (updateDTO.getCollege() != null) { extra.setCollege(updateDTO.getCollege()); extraChanged = true; } + if (updateDTO.getMajor() != null) { extra.setMajor(updateDTO.getMajor()); extraChanged = true; } + if (updateDTO.getBirthday() != null) { extra.setBirthday(updateDTO.getBirthday()); extraChanged = true; } + if (updateDTO.getSex() != null) { extra.setSex(updateDTO.getSex()); extraChanged = true; } + if (updateDTO.getPersonalSignature() != null) { extra.setPersonalSignature(updateDTO.getPersonalSignature()); extraChanged = true; } + if (extraChanged) { + if (!userExtraService.saveOrUpdate(extra)) { + throw new BusinessException("-4", "Failed to update user extra info"); + } + } + } } From 4a7410480d905d82a462b9b97b1900ad0aee89c3 Mon Sep 17 00:00:00 2001 From: AInfinity-LilacDream <1977741520@qq.com> Date: Sun, 18 May 2025 10:43:44 +0800 Subject: [PATCH 28/62] fix: add translation between NoteEntity and note db --- .../ocean/common/po/mysql/NoteEntity.java | 31 +++++++++++++++---- .../src/main/resources/mapper/NoteMapper.xml | 2 +- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java index 2e45981..fb3e135 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java @@ -1,5 +1,6 @@ package com.oriole.ocean.common.po.mysql; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -10,21 +11,39 @@ @Data @TableName("`note`") public class NoteEntity implements java.io.Serializable { - @TableId("id") - private Integer id; + @TableId("note_id") + private String id; + + @TableField("build_username") private String buildUsername; - // contents + + @TableField("content") private String content; + + @TableField("tag") private String tag; - // extra info + + @TableField("build_date") private Date buildDate; + + @TableField("refresh_date") private Date refreshDate; - // states + + @TableField("is_deleted") private Byte isDeleted; + + @TableField("is_anon") private Byte isAnon; + + @TableField("is_allow_comment") private Byte isAllowComment; - // statistics (changing with relation 'likes') + + @TableField("like_num") private Integer likeNum; + + @TableField("comment_num") private Integer commentNum; + + @TableField("read_num") private Integer readNum; } diff --git a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml index 1722c53..6ee91ce 100644 --- a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml +++ b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml @@ -6,7 +6,7 @@ - + From 593e83892d0a32b04b9721516f538e1f0864b216 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Tue, 20 May 2025 12:45:27 +0800 Subject: [PATCH 29/62] feat: add search function ALTER TABLE note ADD FULLTEXT(content); --- .../oriole/ocean/common/service/NoteService.java | 2 ++ .../oriole/ocean/controller/NoteController.java | 15 +++++++++++++-- .../main/java/com/oriole/ocean/dao/NoteDao.java | 1 + .../oriole/ocean/service/NoteServiceImpl.java | 4 ++++ .../src/main/resources/mapper/NoteMapper.xml | 16 ++++++++++++++-- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java index 33cef49..de092fb 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java @@ -9,6 +9,8 @@ public interface NoteService { List getLatestNotes(); + List getNotesByKeywords(String serchString); + List getNotesByTag(String tag); NoteEntity createNote(NoteEntity noteEntity); diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index 148b6c7..23e1695 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -32,6 +32,17 @@ public MsgEntity> getNoteByPage( return new MsgEntity<>("SUCCESS","1",pageInfo); } + @RequestMapping(value = "/getNotesByKeywords", method = RequestMethod.POST) + public MsgEntity> getNotesByKeywords( + @RequestParam String searchString, + @RequestParam int pageNO, + @RequestParam int pageSize) { + PageHelper.startPage(pageNO, pageSize, true); + List noteEntityList = noteService.getNotesByKeywords(searchString); + PageInfo pageInfo = new PageInfo<>(noteEntityList); + return new MsgEntity<>("SUCCESS","1",pageInfo); + } + @RequestMapping(value = "/createNote", method = RequestMethod.POST) public MsgEntity createNote( @AuthUser AuthUserEntity authUser, @@ -61,9 +72,9 @@ public MsgEntity deleteNote( @RequestMapping(value = "/getNoteByTag",method = RequestMethod.GET) public MsgEntity> getNoteByTag( @RequestParam(required = false) String tag, - @RequestParam Integer pageNum, + @RequestParam Integer pageNo, @RequestParam Integer pageSize) { - PageHelper.startPage(pageNum, pageSize, true); + PageHelper.startPage(pageNo, pageSize, true); List noteEntityList = noteService.getNotesByTag(tag); PageInfo pageInfo = new PageInfo<>(noteEntityList); return new MsgEntity<>("SUCCESS", "1", pageInfo); diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java index 62e97bb..39f3b5a 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java @@ -9,6 +9,7 @@ public interface NoteDao extends BaseMapper { List getLatestNotes(); + List getNotesByKeywords(String serchString); void deleteNote(int noteId, String username); boolean checkNoteBuilder(int noteId, String username); List getNotesByTag(String tag); diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java index f7abe61..85dc6b0 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java @@ -33,6 +33,10 @@ public List getLatestNotes() { return noteDao.getLatestNotes(); } + public List getNotesByKeywords(String serchString) { + return noteDao.getNotesByKeywords(serchString); + } + public List getNotesByTag(String tag) { return noteDao.getNotesByTag(tag); } diff --git a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml index 6ee91ce..0bdd9dc 100644 --- a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml +++ b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml @@ -26,11 +26,23 @@ + + - SELECT * FROM note WHERE note.id = #{noteID}; + SELECT * FROM note WHERE note.note_id = #{noteID}; UPDATE note SET is_deleted = 1 - WHERE note.id = #{noteID} AND note.buildUsername = #{username}; + WHERE note.note_id = #{noteID}; \ No newline at end of file From ed393ab8f819d89e1002f1b8e23b4f0d140231ad Mon Sep 17 00:00:00 2001 From: AInfinity-LilacDream <1977741520@qq.com> Date: Tue, 27 May 2025 23:38:24 +0800 Subject: [PATCH 34/62] feat: impl note collection logic --- .../ocean/common/po/mongo/FavorEntity.java | 17 ++++ .../ocean/common/service/NoteService.java | 9 ++ .../ocean/controller/NoteController.java | 38 ++++++++ .../oriole/ocean/dao/NoteCollectionDao.java | 53 +++++++++++ .../com/oriole/ocean/dao/NoteCommentDao.java | 47 ++++++++++ .../java/com/oriole/ocean/dao/NoteDao.java | 1 + .../oriole/ocean/service/NoteServiceImpl.java | 87 ++++++++++--------- .../src/main/resources/mapper/NoteMapper.xml | 19 ++++ 8 files changed, 232 insertions(+), 39 deletions(-) create mode 100644 ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/FavorEntity.java create mode 100644 ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCollectionDao.java create mode 100644 ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/FavorEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/FavorEntity.java new file mode 100644 index 0000000..d288abb --- /dev/null +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/FavorEntity.java @@ -0,0 +1,17 @@ +package com.oriole.ocean.common.po.mongo; + +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.util.Map; + +@Data +@Document(collection = "note_favor") +public class FavorEntity implements java.io.Serializable { + @Id + private String id; + + private String username; + private String noteId; +} diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java index 8620a3b..4264f1a 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java @@ -1,5 +1,6 @@ package com.oriole.ocean.common.service; +import com.oriole.ocean.common.po.mongo.FavorEntity; import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteEntity; import java.util.List; @@ -8,8 +9,16 @@ public interface NoteService { boolean deleteNote(String noteID); + FavorEntity favoriteNote(String username, boolean isFavor, String noteID, String id); + + NoteEntity getNoteById(String noteID); + boolean deleteNoteComment(String commentId); + FavorEntity getBehaviourByUsernameAndNoteId(String username, String noteId); + + List getBehaviourByUsername(String username, int pageNo, int pageSize); + List getLatestNotes(); List getNotesByKeywords(String serchString); diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index fde3737..0e3c52d 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -3,12 +3,14 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.oriole.ocean.common.auth.AuthUser; +import com.oriole.ocean.common.po.mongo.FavorEntity; import com.oriole.ocean.common.po.mongo.comment.CommentReplyEntity; import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteEntity; import com.oriole.ocean.common.vo.AuthUserEntity; import com.oriole.ocean.common.vo.MsgEntity; import com.oriole.ocean.common.service.NoteService; +import com.oriole.ocean.dao.NoteCollectionDao; import jdk.nashorn.internal.ir.RuntimeNode; import org.apache.commons.lang3.RandomStringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -20,6 +22,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; @RestController @RequestMapping("/noteService") @@ -49,6 +52,13 @@ public MsgEntity> getNotesByKeywords( return new MsgEntity<>("SUCCESS","1",pageInfo); } + @RequestMapping(value = "/getNoteById", method = RequestMethod.POST) + public MsgEntity getNoteById( + @RequestParam String noteId + ) { + return new MsgEntity<>("SUCCESS", "1", noteService.getNoteById(noteId)); + } + @RequestMapping(value = "/createNote", method = RequestMethod.POST) public MsgEntity createNote( @AuthUser AuthUserEntity authUser, @@ -122,4 +132,32 @@ public MsgEntity deleteNoteComment( return new MsgEntity<>("FAILED", "400", "删除评论失败"); return new MsgEntity<>("SUCCESS", "1", "评论删除成功"); } + + @RequestMapping(value = "/favoriteNote", method = RequestMethod.POST) + public MsgEntity favoriteNote( + @RequestParam String username, + @RequestParam Boolean isFavor, + @RequestParam String noteId, + @RequestParam(required = false) String id) { + return new MsgEntity<>("SUCCESS", "1", noteService.favoriteNote(username, isFavor, noteId, id)); + } + + @RequestMapping(value = "/getBehaviourByUsernameAndNoteId", method = RequestMethod.POST) + public MsgEntity getBehaviourByUsernameAndNoteId( + @RequestParam String username, + @RequestParam String noteId) { + FavorEntity favorEntity = noteService.getBehaviourByUsernameAndNoteId(username, noteId); + if (favorEntity == null) return new MsgEntity<>("SUCCESS", "2", null); + return new MsgEntity<>("SUCCESS", "1", favorEntity); + } + + @RequestMapping(value = "/getBehaviourByUsername", method = RequestMethod.POST) + public MsgEntity> getBehaviourByUsername( + @RequestParam String username, + @RequestParam Integer pageNo, + @RequestParam Integer pageSize) { + List collectionList = noteService.getBehaviourByUsername(username, pageNo, pageSize); + PageInfo pageInfo = new PageInfo<>(collectionList); + return new MsgEntity<>("SUCCESS", "1", pageInfo); + } } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCollectionDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCollectionDao.java new file mode 100644 index 0000000..35de7a6 --- /dev/null +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCollectionDao.java @@ -0,0 +1,53 @@ +package com.oriole.ocean.dao; + +import com.oriole.ocean.common.po.mongo.FavorEntity; +import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public class NoteCollectionDao { + @Autowired + private MongoTemplate mongoTemplate; + + // 根据用户名和笔记ID查找收藏(用于删除时获取完整对象) + public FavorEntity findByUsernameAndNoteId(String username, String noteId) { + Criteria criteria = new Criteria().orOperator( + Criteria.where("username").is(username), + Criteria.where("noteId").is(noteId) + ); + + Query query = new Query(criteria); + + List res = mongoTemplate.find(query, FavorEntity.class, "note_favor"); + if (res.isEmpty()) return null; + return res.iterator().next(); + } + + public List getBehaviourByUsername(String username, int pageNo, int pageSize) { + Pageable pageable = PageRequest.of(pageNo - 1, pageSize); + Criteria criteria = new Criteria().orOperator( + Criteria.where("username").is(username) + ); + + Query query = new Query(criteria); + query.with(pageable); + + return mongoTemplate.find(query, FavorEntity.class, "note_favor"); + } + + public void save(FavorEntity favorEntity) { + mongoTemplate.save(favorEntity, "note_favor"); + } + + public void delete(FavorEntity favorEntity) { + mongoTemplate.remove(favorEntity, "note_favor"); + } +} diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java new file mode 100644 index 0000000..42f80cd --- /dev/null +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java @@ -0,0 +1,47 @@ +package com.oriole.ocean.dao; + +import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public class NoteCommentDao { + @Autowired + private MongoTemplate mongoTemplate; + + public void addNoteComment(NoteCommentEntity noteComment) { + mongoTemplate.save(noteComment, "note_comments"); + } + + public List getNoteCommentsByNoteId(String noteId, int pageNo, int pageSize) { + Pageable pageable = PageRequest.of(pageNo - 1, pageSize); + + // 创建查询条件,同时支持String和Long类型的noteId(为了兼容旧数据) + Criteria criteria = new Criteria().orOperator( + Criteria.where("noteId").is(noteId), + Criteria.where("noteId").is(Long.parseLong(noteId)) + ); + + Query query = new Query(criteria); + query.with(pageable); + + return mongoTemplate.find(query, NoteCommentEntity.class, "note_comments"); + } + + public boolean deleteNoteComment(String commentId) { + try { + Query query = new Query(Criteria.where("_id").is(commentId)); + mongoTemplate.remove(query, NoteCommentEntity.class, "note_comments"); + return true; + } catch (Exception e) { + return false; + } + } +} diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java index 8ab7d1b..83615e0 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java @@ -12,6 +12,7 @@ public interface NoteDao extends BaseMapper { List getLatestNotes(); List getNotesByKeywords(String serchString); void deleteNote(String noteId); + NoteEntity getNoteById(String noteId); boolean checkNoteBuilder(String noteId); List getNotesByTag(String tag); List getNoteCommentsByNoteId(String noteId); diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java index 80107dc..58822b5 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java @@ -1,9 +1,12 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oriole.ocean.common.po.mongo.FavorEntity; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; import com.oriole.ocean.common.service.NoteService; +import com.oriole.ocean.dao.NoteCollectionDao; +import com.oriole.ocean.dao.NoteCommentDao; import com.oriole.ocean.dao.NoteDao; import com.oriole.ocean.common.po.mysql.NoteEntity; import org.springframework.beans.factory.annotation.Autowired; @@ -25,16 +28,11 @@ public class NoteServiceImpl extends ServiceImpl implements @Resource private NoteDao noteDao; - @Autowired - private MongoTemplate mongoTemplate; - - private void addNote(NoteEntity note){ - save(note); - } + @Resource + private NoteCollectionDao noteCollectionDao; - private void addNoteComment(NoteCommentEntity noteComment){ - mongoTemplate.save(noteComment, "note_comments"); - } + @Resource + private NoteCommentDao noteCommentDao; public boolean deleteNote(String noteID){ if(!noteDao.checkNoteBuilder(noteID)) { @@ -45,6 +43,32 @@ public boolean deleteNote(String noteID){ return true; } + public NoteEntity getNoteById(String noteID) { + return noteDao.getNoteById(noteID); + } + + public FavorEntity favoriteNote(String username, boolean isFavor, String noteID, String id){ + if(!noteDao.checkNoteBuilder(noteID)) { + return null; + } + + if (isFavor) { + FavorEntity favorEntity = new FavorEntity(); + favorEntity.setUsername(username); + favorEntity.setNoteId(noteID); + noteCollectionDao.save(favorEntity); + return noteCollectionDao.findByUsernameAndNoteId(username, noteID); + } + else { + FavorEntity favorEntity = new FavorEntity(); + favorEntity.setUsername(username); + favorEntity.setNoteId(noteID); + favorEntity.setId(id); + noteCollectionDao.delete(favorEntity); + return null; + } + } + public List getLatestNotes() { return noteDao.getLatestNotes(); } @@ -65,7 +89,7 @@ public NoteEntity createNote(NoteEntity noteEntity){ noteEntity.setReadNum(0); noteEntity.setIsDeleted((byte) 0); - addNote(noteEntity); + save(noteEntity); return noteEntity; } @@ -74,44 +98,29 @@ public NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity) noteCommentEntity.setLikeNum(0); noteCommentEntity.setCreateTime(new Date()); - addNoteComment(noteCommentEntity); + noteCommentDao.addNoteComment(noteCommentEntity); return noteCommentEntity; } public List getNoteCommentsByNoteId(String noteId, int pageNo, int pageSize) { - Pageable pageable = PageRequest.of(pageNo - 1, pageSize); - - // 创建查询条件,同时支持String和Long类型的noteId(为了兼容旧数据) - Criteria criteria = new Criteria().orOperator( - Criteria.where("noteId").is(noteId), - Criteria.where("noteId").is(tryParseLong(noteId)) - ); - - Query query = new Query(criteria); - query.with(pageable); - - return mongoTemplate.find(query, NoteCommentEntity.class, "note_comments"); + return noteCommentDao.getNoteCommentsByNoteId(noteId, pageNo, pageSize); + } + + public boolean deleteNoteComment(String commentId) { + return noteCommentDao.deleteNoteComment(commentId); } - - /** - * 尝试将字符串转换为Long,如果失败则返回null - */ - private Long tryParseLong(String str) { - try { - return Long.parseLong(str); - } catch (NumberFormatException e) { + + public FavorEntity getBehaviourByUsernameAndNoteId(String username, String noteId) { + if (!noteDao.checkNoteBuilder(noteId)) { return null; } + + return noteCollectionDao.findByUsernameAndNoteId(username, noteId); } - public boolean deleteNoteComment(String commentId) { - try { - Query query = new Query(Criteria.where("_id").is(commentId)); - mongoTemplate.remove(query, NoteCommentEntity.class, "note_comments"); - return true; - } catch (Exception e) { - return false; - } + public List getBehaviourByUsername(String username, int pageNo, int pageSize) { + return noteCollectionDao.getBehaviourByUsername(username, pageNo, pageSize); } + } \ No newline at end of file diff --git a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml index 7897123..b5d0820 100644 --- a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml +++ b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml @@ -47,6 +47,25 @@ FROM note WHERE note.is_deleted = 0 AND note.tag = #{tag} ORDER BY note.refresh_date ASC; + + - - UPDATE note SET is_deleted = 1 From 1681a3910f3a23a310eb20a900ef94ba54befd11 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sat, 31 May 2025 14:56:46 +0800 Subject: [PATCH 38/62] fix: remove unused code --- .../oriole/ocean/service/NoteTypeService.java | 12 ------------ .../ocean/service/NoteTypeServiceImpl.java | 19 ------------------- 2 files changed, 31 deletions(-) delete mode 100644 ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java delete mode 100644 ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeServiceImpl.java diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java deleted file mode 100644 index 723325d..0000000 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeService.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.oriole.ocean.service; - -import com.oriole.ocean.common.po.mysql.NoteTypeEntity; -import java.util.List; - -public interface NoteTypeService { - /** - * 获取所有笔记类型 - * @return 笔记类型列表 - */ - List getAllNoteType(); -} diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeServiceImpl.java deleted file mode 100644 index eb56c64..0000000 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteTypeServiceImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.oriole.ocean.service; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.dao.NoteTypeDao; -import com.oriole.ocean.common.po.mysql.NoteTypeEntity; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Service -@Transactional -public class NoteTypeServiceImpl extends ServiceImpl implements NoteTypeService { - - @Override - public List getAllNoteType() { - return list(); - } -} \ No newline at end of file From b497c4a05f2bf05194a064f5180715f1808f09fb Mon Sep 17 00:00:00 2001 From: cms42 Date: Sun, 1 Jun 2025 00:23:50 +0800 Subject: [PATCH 39/62] fix: register AuthUserMethodArgumentResolver in note microservice --- .../com/oriole/ocean/config/WebConfig.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 ocean-note-service/src/main/java/com/oriole/ocean/config/WebConfig.java diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/config/WebConfig.java b/ocean-note-service/src/main/java/com/oriole/ocean/config/WebConfig.java new file mode 100644 index 0000000..be05ee6 --- /dev/null +++ b/ocean-note-service/src/main/java/com/oriole/ocean/config/WebConfig.java @@ -0,0 +1,21 @@ +package com.oriole.ocean.config; + +import com.oriole.ocean.common.auth.AuthUserMethodArgumentResolver; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import java.util.List; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Autowired + AuthUserMethodArgumentResolver authUserMethodArgumentResolver; + + @Override + public void addArgumentResolvers(List argumentResolvers) { + argumentResolvers.add(authUserMethodArgumentResolver); + } +} \ No newline at end of file From 32b797548a39a2dd6085d597475ac8aee334631d Mon Sep 17 00:00:00 2001 From: cms42 Date: Sun, 1 Jun 2025 00:25:26 +0800 Subject: [PATCH 40/62] feat: implement `like` for note --- .../ocean/common/po/mysql/NoteEntity.java | 7 + .../ocean/common/po/mysql/NoteLikeEntity.java | 42 +++- .../ocean/common/service/NoteService.java | 136 ++++++++++++- .../gateway/security/SecurityRepository.java | 5 + .../ocean/controller/NoteController.java | 132 ++++++++++++- .../java/com/oriole/ocean/dao/NoteDao.java | 85 +++++++- .../com/oriole/ocean/dao/NoteLikeDao.java | 45 +++++ .../oriole/ocean/service/NoteServiceImpl.java | 187 +++++++++++++++++- .../main/resources/mapper/NoteLikeMapper.xml | 39 ++++ .../src/main/resources/mapper/NoteMapper.xml | 86 ++++++++ 10 files changed, 741 insertions(+), 23 deletions(-) create mode 100644 ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteLikeDao.java create mode 100644 ocean-note-service/src/main/resources/mapper/NoteLikeMapper.xml diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java index 5319fc5..8305385 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteEntity.java @@ -47,4 +47,11 @@ public class NoteEntity implements java.io.Serializable { @TableField("read_num") private Integer readNum; + + /** + * Whether the current user has liked this note + * This field is not mapped to database, only used for data transfer + */ + @TableField(exist = false) + private Boolean isLikedByCurrentUser; } diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteLikeEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteLikeEntity.java index e6eb2eb..3621733 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteLikeEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteLikeEntity.java @@ -1,18 +1,48 @@ package com.oriole.ocean.common.po.mysql; -import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; import lombok.Data; import java.util.Date; +/** + * Note like record entity + * Records the like relationship between users and notes + */ @Data @TableName("`note_like`") public class NoteLikeEntity implements java.io.Serializable { - @TableId(type = IdType.AUTO) - private Integer id; // 自增主键(ORM需要,业务无关) - - private Integer postId; // 帖子ID - private Integer userId; // 用户ID + + @TableId(value = "id", type = IdType.ASSIGN_ID) + private String id; + + @TableField("username") + private String username; + + @TableField("note_id") + private String noteId; + + @TableField("like_time") + private Date likeTime; + + /** + * Default constructor + */ + public NoteLikeEntity() { + this.likeTime = new Date(); + } + + /** + * Constructor with username and noteId + * @param username The username who likes the note + * @param noteId The ID of the liked note + */ + public NoteLikeEntity(String username, String noteId) { + this.username = username; + this.noteId = noteId; + this.likeTime = new Date(); + } } diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java index 8c2e6c9..364f212 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java @@ -3,33 +3,167 @@ import com.oriole.ocean.common.po.mongo.FavorEntity; import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteEntity; +import com.oriole.ocean.common.po.mysql.NoteLikeEntity; import java.util.List; +/** + * Note service interface + * Provides business logic for note operations + */ public interface NoteService { + /** + * Check if user is the creator of a note + * @param noteId Note ID + * @param username Username to check + * @return true if user is creator, false otherwise + */ boolean isNoteCreator(String noteId, String username); + /** + * Delete a note (soft delete) + * @param noteID Note ID to delete + */ void deleteNote(String noteID); + /** + * Favorite/unfavorite a note + * @param username Username + * @param isFavor Whether to favor or unfavor + * @param noteID Note ID + * @param id Existing favor record ID (for unfavor operation) + * @return Favor entity or null + */ FavorEntity favoriteNote(String username, boolean isFavor, String noteID, String id); + /** + * Get note by ID + * @param noteID Note ID + * @return Note entity + */ NoteEntity getNoteById(String noteID); + /** + * Get note by ID with like status for current user + * @param noteID Note ID + * @param username Current user's username + * @return Note entity with like status + */ + NoteEntity getNoteByIdWithLikeStatus(String noteID, String username); + + /** + * Delete a note comment + * @param commentId Comment ID + */ void deleteNoteComment(String commentId); + /** + * Get user behavior (favorites) for a specific note + * @param username Username + * @param noteId Note ID + * @return Favor entity or null + */ FavorEntity getBehaviourByUsernameAndNoteId(String username, String noteId); + /** + * Get user behaviors (favorites) list + * @param username Username + * @param pageNo Page number + * @param pageSize Page size + * @return List of favor entities + */ List getBehaviourByUsername(String username, int pageNo, int pageSize); + /** + * Get latest notes + * @return List of latest notes + */ List getLatestNotes(); - List getNotesByKeywords(String serchString); + /** + * Get latest notes with like status for current user + * @param username Current user's username + * @return List of latest notes with like status + */ + List getLatestNotesWithLikeStatus(String username); + + /** + * Get notes by keywords + * @param searchString Search keywords + * @return List of matching notes + */ + List getNotesByKeywords(String searchString); + + /** + * Get notes by keywords with like status for current user + * @param searchString Search keywords + * @param username Current user's username + * @return List of matching notes with like status + */ + List getNotesByKeywordsWithLikeStatus(String searchString, String username); + /** + * Get notes by tag + * @param tag Note tag + * @return List of notes with specified tag + */ List getNotesByTag(String tag); + /** + * Get notes by tag with like status for current user + * @param tag Note tag + * @param username Current user's username + * @return List of notes with specified tag and like status + */ + List getNotesByTagWithLikeStatus(String tag, String username); + + /** + * Get note comments by note ID + * @param noteId Note ID + * @param pageNo Page number + * @param pageSize Page size + * @return List of note comments + */ List getNoteCommentsByNoteId(String noteId, int pageNo, int pageSize); + /** + * Create a new note + * @param noteEntity Note entity to create + * @return Created note entity + */ NoteEntity createNote(NoteEntity noteEntity); + /** + * Create a new note comment + * @param noteCommentEntity Note comment entity to create + * @return Created note comment entity + */ NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity); + + // === Like functionality === + + /** + * Like or unlike a note + * @param username Username who likes/unlikes + * @param noteId Note ID to like/unlike + * @param isLike true to like, false to unlike + * @return NoteLikeEntity if liked, null if unliked + */ + NoteLikeEntity likeNote(String username, String noteId, boolean isLike); + + /** + * Check if a user has liked a specific note + * @param username Username to check + * @param noteId Note ID to check + * @return true if liked, false otherwise + */ + boolean hasUserLikedNote(String username, String noteId); + + /** + * Get like record for a user and note + * @param username Username + * @param noteId Note ID + * @return NoteLikeEntity if exists, null otherwise + */ + NoteLikeEntity getNoteLike(String username, String noteId); } diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java index 8ad8c33..67585e1 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/security/SecurityRepository.java @@ -45,6 +45,11 @@ public Mono load(ServerWebExchange exchange) { authInfo.put("username", claims.get("username")); authInfo.put("role", claims.get("role")); + // 打印authInfo + System.out.println("load"); + System.out.println(exchange.getRequest().getPath()); + System.out.println(authInfo); + /* 重设头信息 */ exchange.getRequest().mutate().headers(httpHeaders -> httpHeaders.set(HttpHeaders.AUTHORIZATION, authInfo.toString()) diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index 7af538f..0307baa 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -12,6 +12,7 @@ import com.oriole.ocean.common.po.mongo.comment.CommentReplyEntity; import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteEntity; +import com.oriole.ocean.common.po.mysql.NoteLikeEntity; import com.oriole.ocean.common.po.mysql.NotifyEntity; import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.common.service.NotifySubscriptionService; @@ -34,6 +35,10 @@ import java.util.List; import java.util.Objects; +/** + * Note controller + * Handles HTTP requests for note operations including like functionality + */ @RestController @RequestMapping("/noteService") public class NoteController { @@ -47,34 +52,79 @@ public class NoteController { @DubboReference NotifySubscriptionService notifySubscriptionService; + /** + * Get latest notes with pagination + * Returns notes with like status for authenticated user + */ @RequestMapping(value = "/getLatestNote", method = RequestMethod.POST) public MsgEntity> getNoteByPage( + @AuthUser AuthUserEntity authUser, @RequestParam int pageNO, @RequestParam int pageSize) { PageHelper.startPage(pageNO, pageSize, true); - List noteEntityList = noteService.getLatestNotes(); + + List noteEntityList; + if (authUser != null) { + // Authenticated user - include like status + noteEntityList = noteService.getLatestNotesWithLikeStatus(authUser.getUsername()); + } else { + // Anonymous user - without like status + noteEntityList = noteService.getLatestNotes(); + } + PageInfo pageInfo = new PageInfo<>(noteEntityList); return new MsgEntity<>("SUCCESS","1",pageInfo); } + /** + * Search notes by keywords with pagination + * Returns notes with like status for authenticated user + */ @RequestMapping(value = "/getNotesByKeywords", method = RequestMethod.POST) public MsgEntity> getNotesByKeywords( + @AuthUser AuthUserEntity authUser, @RequestParam String searchString, @RequestParam int pageNO, @RequestParam int pageSize) { PageHelper.startPage(pageNO, pageSize, true); - List noteEntityList = noteService.getNotesByKeywords(searchString); + + List noteEntityList; + if (authUser != null) { + // Authenticated user - include like status + noteEntityList = noteService.getNotesByKeywordsWithLikeStatus(searchString, authUser.getUsername()); + } else { + // Anonymous user - without like status + noteEntityList = noteService.getNotesByKeywords(searchString); + } + PageInfo pageInfo = new PageInfo<>(noteEntityList); return new MsgEntity<>("SUCCESS","1",pageInfo); } + /** + * Get note by ID + * Returns note with like status for authenticated user + */ @RequestMapping(value = "/getNoteById", method = RequestMethod.POST) public MsgEntity getNoteById( + @AuthUser AuthUserEntity authUser, @RequestParam String noteId ) { - return new MsgEntity<>("SUCCESS", "1", noteService.getNoteById(noteId)); + NoteEntity note; + if (authUser != null) { + // Authenticated user - include like status + note = noteService.getNoteByIdWithLikeStatus(noteId, authUser.getUsername()); + } else { + // Anonymous user - without like status + note = noteService.getNoteById(noteId); + } + + return new MsgEntity<>("SUCCESS", "1", note); } + /** + * Create a new note + */ @RequestMapping(value = "/createNote", method = RequestMethod.POST) public MsgEntity createNote( @AuthUser AuthUserEntity authUser, @@ -102,6 +152,9 @@ public MsgEntity createNote( return new MsgEntity<>("SUCCESS", "1", note); } + /** + * Delete a note + */ @RequestMapping(value = "/deleteNote", method = RequestMethod.POST) public MsgEntity deleteNote( @AuthUser AuthUserEntity authUser, @@ -114,20 +167,82 @@ public MsgEntity deleteNote( } } noteService.deleteNote(noteID); - return new MsgEntity<>("SUCCESS", "1", "山本!お前の先人を犯してやる!"); + return new MsgEntity<>("SUCCESS", "1", "Note deleted successfully"); } + /** + * Get notes by tag with pagination + * Returns notes with like status for authenticated user + */ @RequestMapping(value = "/getNoteByTag",method = RequestMethod.GET) public MsgEntity> getNoteByTag( + @AuthUser AuthUserEntity authUser, @RequestParam(required = false) String tag, @RequestParam Integer pageNo, @RequestParam Integer pageSize) { PageHelper.startPage(pageNo, pageSize, true); - List noteEntityList = noteService.getNotesByTag(tag); + + List noteEntityList; + if (authUser != null) { + // Authenticated user - include like status + noteEntityList = noteService.getNotesByTagWithLikeStatus(tag, authUser.getUsername()); + } else { + // Anonymous user - without like status + noteEntityList = noteService.getNotesByTag(tag); + } + PageInfo pageInfo = new PageInfo<>(noteEntityList); return new MsgEntity<>("SUCCESS", "1", pageInfo); } + // === Like functionality APIs === + + /** + * Like or unlike a note + * @param authUser Authenticated user + * @param noteId Note ID to like/unlike + * @param isLike true to like, false to unlike + * @return Success message with like status + */ + @RequestMapping(value = "/likeNote", method = RequestMethod.POST) + public MsgEntity likeNote( + @AuthUser AuthUserEntity authUser, + @RequestParam String noteId, + @RequestParam Boolean isLike) { + + String username = authUser.getUsername(); + + NoteLikeEntity result = noteService.likeNote(username, noteId, isLike); + + if (isLike) { + return new MsgEntity<>("SUCCESS", "1", result); + } else { + return new MsgEntity<>("SUCCESS", "1", null); + } + } + + /** + * Check if current user has liked a specific note + * @param authUser Authenticated user + * @param noteId Note ID to check + * @return Like status + */ + @RequestMapping(value = "/checkNoteLikeStatus", method = RequestMethod.POST) + public MsgEntity checkNoteLikeStatus( + @AuthUser AuthUserEntity authUser, + @RequestParam String noteId) { + + String username = authUser.getUsername(); + boolean hasLiked = noteService.hasUserLikedNote(username, noteId); + + return new MsgEntity<>("SUCCESS", "1", hasLiked); + } + + // === Original comment and favorite APIs === + + /** + * Get note comments by note ID + */ @RequestMapping(value = "/getNoteCommentByNoteId", method = RequestMethod.POST) public MsgEntity> getNoteCommentByNoteId( @RequestParam String noteId, @@ -139,6 +254,9 @@ public MsgEntity> getNoteCommentByNoteId( return new MsgEntity<>("SUCCESS", "1", pageInfo); } + /** + * Create a note comment + */ @RequestMapping(value = "/createNoteComment", method = RequestMethod.POST) public MsgEntity createNoteComment( @AuthUser AuthUserEntity authUser, @@ -179,6 +297,9 @@ public MsgEntity createNoteComment( return new MsgEntity<>("SUCCESS", "1", noteComment); } + /** + * Delete a note comment + */ @RequestMapping(value = "/deleteNoteComment", method = RequestMethod.POST) public MsgEntity deleteNoteComment( @AuthUser AuthUserEntity authUser, @@ -194,6 +315,7 @@ public MsgEntity deleteNoteComment( return new MsgEntity<>("SUCCESS", "1", "评论删除成功"); } + // 收藏功能 @RequestMapping(value = "/favoriteNote", method = RequestMethod.POST) public MsgEntity favoriteNote( @AuthUser AuthUserEntity authUser, diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java index d5c698a..441c792 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java @@ -4,15 +4,90 @@ import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteEntity; import com.oriole.ocean.common.po.mysql.UserNotifyEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.Date; import java.util.List; +/** + * Note data access object + * Handles database operations for note records + */ +@Mapper public interface NoteDao extends BaseMapper { + + /** + * Get latest notes + * @return List of latest notes + */ List getLatestNotes(); - List getNotesByKeywords(String serchString); - void deleteNote(String noteId); - NoteEntity getNoteById(String noteId); - List getNotesByTag(String tag); - List getNoteCommentsByNoteId(String noteId); + + /** + * Get latest notes with like status for current user + * @param username Current user's username + * @return List of latest notes with like status + */ + List getLatestNotesWithLikeStatus(@Param("username") String username); + + /** + * Get notes by keywords + * @param searchString Search keywords + * @return List of notes matching keywords + */ + List getNotesByKeywords(@Param("searchString") String searchString); + + /** + * Get notes by keywords with like status for current user + * @param searchString Search keywords + * @param username Current user's username + * @return List of notes matching keywords with like status + */ + List getNotesByKeywordsWithLikeStatus(@Param("searchString") String searchString, + @Param("username") String username); + + /** + * Get notes by tag + * @param tag Note tag + * @return List of notes with specified tag + */ + List getNotesByTag(@Param("tag") String tag); + + /** + * Get notes by tag with like status for current user + * @param tag Note tag + * @param username Current user's username + * @return List of notes with specified tag and like status + */ + List getNotesByTagWithLikeStatus(@Param("tag") String tag, + @Param("username") String username); + + /** + * Get note by ID + * @param noteId Note ID + * @return Note entity + */ + NoteEntity getNoteById(@Param("noteId") String noteId); + + /** + * Get note by ID with like status for current user + * @param noteId Note ID + * @param username Current user's username + * @return Note entity with like status + */ + NoteEntity getNoteByIdWithLikeStatus(@Param("noteId") String noteId, + @Param("username") String username); + + /** + * Delete note (soft delete) + * @param noteID Note ID to delete + */ + void deleteNote(@Param("noteID") String noteID); + + /** + * Get note comments by note ID + * @param noteId Note ID + * @return List of note comments + */ + List getNoteCommentsByNoteId(@Param("noteId") String noteId); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteLikeDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteLikeDao.java new file mode 100644 index 0000000..a44e143 --- /dev/null +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteLikeDao.java @@ -0,0 +1,45 @@ +package com.oriole.ocean.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.oriole.ocean.common.po.mysql.NoteLikeEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * Note like data access object + * Handles database operations for note like records + */ +@Mapper +public interface NoteLikeDao extends BaseMapper { + + /** + * Add a like record + * @param noteLikeEntity The like record to add + * @return Number of affected rows + */ + int addNoteLike(NoteLikeEntity noteLikeEntity); + + /** + * Remove a like record + * @param username The username who likes the note + * @param noteId The ID of the note + * @return Number of affected rows + */ + int removeNoteLike(@Param("username") String username, @Param("noteId") String noteId); + + /** + * Check if a user has liked a specific note + * @param username The username to check + * @param noteId The ID of the note + * @return The like record if exists, null otherwise + */ + NoteLikeEntity findNoteLike(@Param("username") String username, @Param("noteId") String noteId); + + /** + * Check if a user has liked a specific note (returns boolean) + * @param username The username to check + * @param noteId The ID of the note + * @return true if liked, false otherwise + */ + boolean hasUserLikedNote(@Param("username") String username, @Param("noteId") String noteId); +} \ No newline at end of file diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java index dabbed8..955e9f7 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java @@ -4,10 +4,12 @@ import com.oriole.ocean.common.po.mongo.FavorEntity; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteLikeEntity; import com.oriole.ocean.common.service.NoteService; import com.oriole.ocean.dao.NoteCollectionDao; import com.oriole.ocean.dao.NoteCommentDao; import com.oriole.ocean.dao.NoteDao; +import com.oriole.ocean.dao.NoteLikeDao; import com.oriole.ocean.common.po.mysql.NoteEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; @@ -22,6 +24,10 @@ import java.util.Date; import java.util.List; +/** + * Note service implementation + * Implements business logic for note operations including like functionality + */ @Service @Transactional public class NoteServiceImpl extends ServiceImpl implements NoteService { @@ -33,21 +39,57 @@ public class NoteServiceImpl extends ServiceImpl implements @Resource private NoteCommentDao noteCommentDao; + + @Resource + private NoteLikeDao noteLikeDao; + /** + * Check if user is the creator of a note + * @param noteId Note ID + * @param username Username to check + * @return true if user is creator, false otherwise + */ public boolean isNoteCreator(String noteId, String username) { - return noteDao.getNoteById(noteId).getBuildUsername().equals(username); + NoteEntity note = noteDao.getNoteById(noteId); + return note != null && note.getBuildUsername().equals(username); } + /** + * Delete a note (soft delete) + * @param noteID Note ID to delete + */ public void deleteNote(String noteID){ noteDao.deleteNote(noteID); } + /** + * Get note by ID + * @param noteID Note ID + * @return Note entity + */ public NoteEntity getNoteById(String noteID) { return noteDao.getNoteById(noteID); } + + /** + * Get note by ID with like status for current user + * @param noteID Note ID + * @param username Current user's username + * @return Note entity with like status + */ + public NoteEntity getNoteByIdWithLikeStatus(String noteID, String username) { + return noteDao.getNoteByIdWithLikeStatus(noteID, username); + } + /** + * Favorite/unfavorite a note + * @param username Username + * @param isFavor Whether to favor or unfavor + * @param noteID Note ID + * @param id Existing favor record ID (for unfavor operation) + * @return Favor entity or null + */ public FavorEntity favoriteNote(String username, boolean isFavor, String noteID, String id){ - if (isFavor) { FavorEntity favorEntity = new FavorEntity(); favorEntity.setUsername(username); @@ -65,18 +107,66 @@ public FavorEntity favoriteNote(String username, boolean isFavor, String noteID, } } + /** + * Get latest notes + * @return List of latest notes + */ public List getLatestNotes() { return noteDao.getLatestNotes(); } + + /** + * Get latest notes with like status for current user + * @param username Current user's username + * @return List of latest notes with like status + */ + public List getLatestNotesWithLikeStatus(String username) { + return noteDao.getLatestNotesWithLikeStatus(username); + } - public List getNotesByKeywords(String serchString) { - return noteDao.getNotesByKeywords(serchString); + /** + * Get notes by keywords + * @param searchString Search keywords + * @return List of matching notes + */ + public List getNotesByKeywords(String searchString) { + return noteDao.getNotesByKeywords(searchString); + } + + /** + * Get notes by keywords with like status for current user + * @param searchString Search keywords + * @param username Current user's username + * @return List of matching notes with like status + */ + public List getNotesByKeywordsWithLikeStatus(String searchString, String username) { + return noteDao.getNotesByKeywordsWithLikeStatus(searchString, username); } + /** + * Get notes by tag + * @param tag Note tag + * @return List of notes with specified tag + */ public List getNotesByTag(String tag) { return noteDao.getNotesByTag(tag); } + + /** + * Get notes by tag with like status for current user + * @param tag Note tag + * @param username Current user's username + * @return List of notes with specified tag and like status + */ + public List getNotesByTagWithLikeStatus(String tag, String username) { + return noteDao.getNotesByTagWithLikeStatus(tag, username); + } + /** + * Create a new note + * @param noteEntity Note entity to create + * @return Created note entity + */ public NoteEntity createNote(NoteEntity noteEntity){ noteEntity.setBuildDate(new Date()); noteEntity.setRefreshDate(new Date()); @@ -90,6 +180,11 @@ public NoteEntity createNote(NoteEntity noteEntity){ return noteEntity; } + /** + * Create a new note comment + * @param noteCommentEntity Note comment entity to create + * @return Created note comment entity + */ public NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity) { noteCommentEntity.setLikeNum(0); noteCommentEntity.setCreateTime(new Date()); @@ -99,25 +194,105 @@ public NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity) return noteCommentEntity; } + /** + * Get note comments by note ID + * @param noteId Note ID + * @param pageNo Page number + * @param pageSize Page size + * @return List of note comments + */ public List getNoteCommentsByNoteId(String noteId, int pageNo, int pageSize) { return noteCommentDao.getNoteCommentsByNoteId(noteId, pageNo, pageSize); } + /** + * Check if user is the creator of a comment + * @param commentId Comment ID + * @param username Username to check + * @return true if user is creator, false otherwise + */ public boolean isCommentCreator(String commentId, String username) { - return noteCommentDao.getNoteComment(commentId).getNoteCommentBuildUsername().equals(username); + NoteCommentEntity comment = noteCommentDao.getNoteComment(commentId); + return comment != null && comment.getNoteCommentBuildUsername().equals(username); } + /** + * Delete a note comment + * @param commentId Comment ID + */ public void deleteNoteComment(String commentId) { noteCommentDao.deleteNoteComment(commentId); - return; } + /** + * Get user behavior (favorites) for a specific note + * @param username Username + * @param noteId Note ID + * @return Favor entity or null + */ public FavorEntity getBehaviourByUsernameAndNoteId(String username, String noteId) { return noteCollectionDao.findByUsernameAndNoteId(username, noteId); } + /** + * Get user behaviors (favorites) list + * @param username Username + * @param pageNo Page number + * @param pageSize Page size + * @return List of favor entities + */ public List getBehaviourByUsername(String username, int pageNo, int pageSize) { return noteCollectionDao.getBehaviourByUsername(username, pageNo, pageSize); } + // === Like functionality implementation === + + /** + * Like or unlike a note + * @param username Username who likes/unlikes + * @param noteId Note ID to like/unlike + * @param isLike true to like, false to unlike + * @return NoteLikeEntity if liked, null if unliked + */ + @Override + public NoteLikeEntity likeNote(String username, String noteId, boolean isLike) { + if (isLike) { + // Check if already liked + NoteLikeEntity existingLike = noteLikeDao.findNoteLike(username, noteId); + if (existingLike != null) { + return existingLike; // Already liked, return existing record + } + + // Create new like record + NoteLikeEntity noteLikeEntity = new NoteLikeEntity(username, noteId); + noteLikeDao.addNoteLike(noteLikeEntity); + return noteLikeEntity; + } else { + // Remove like record + noteLikeDao.removeNoteLike(username, noteId); + return null; + } + } + + /** + * Check if a user has liked a specific note + * @param username Username to check + * @param noteId Note ID to check + * @return true if liked, false otherwise + */ + @Override + public boolean hasUserLikedNote(String username, String noteId) { + return noteLikeDao.hasUserLikedNote(username, noteId); + } + + /** + * Get like record for a user and note + * @param username Username + * @param noteId Note ID + * @return NoteLikeEntity if exists, null otherwise + */ + @Override + public NoteLikeEntity getNoteLike(String username, String noteId) { + return noteLikeDao.findNoteLike(username, noteId); + } } \ No newline at end of file diff --git a/ocean-note-service/src/main/resources/mapper/NoteLikeMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteLikeMapper.xml new file mode 100644 index 0000000..03fe54e --- /dev/null +++ b/ocean-note-service/src/main/resources/mapper/NoteLikeMapper.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + INSERT INTO note_like (id, username, note_id, like_time) + VALUES (#{id}, #{username}, #{noteId}, #{likeTime}) + + + + + DELETE FROM note_like + WHERE username = #{username} AND note_id = #{noteId} + + + + + + + + + \ No newline at end of file diff --git a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml index 91be16e..68a521d 100644 --- a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml +++ b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml @@ -30,6 +30,27 @@ FROM note WHERE note.is_deleted = 0 ORDER BY note.refresh_date DESC + + + + + + + + UPDATE note SET is_deleted = 1 From c70292f2c3946e3346ec6417a9051724b7395da2 Mon Sep 17 00:00:00 2001 From: AInfinity-LilacDream <1977741520@qq.com> Date: Sun, 1 Jun 2025 07:34:31 +0800 Subject: [PATCH 41/62] fix: notify logic --- .../java/com/oriole/ocean/controller/UserCommentController.java | 2 +- .../src/main/resources/mapper/UserNotifyMapper.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index 2be5c5e..f3b7267 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -124,7 +124,7 @@ public MsgEntity addComment(@AuthUser AuthUserEntity authUser, commentEntity.setBuildDate(handleTime(commentEntity.getBuildDate())); returnEntity = commentEntity; notifyEntity.setAction(NotifyAction.NEW_COMMENT);// 新评论事件不面向任何其他评论 - + notifyEntity.setCommentID(String.valueOf(bindID)); } else { CommentReplyEntity fileCommentReplyEntity = new CommentReplyEntity( replyInCommentID + "_" + cid, authUser.getUsername(), diff --git a/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml b/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml index d7faf0c..5284994 100644 --- a/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml +++ b/ocean-notify-service/src/main/resources/mapper/UserNotifyMapper.xml @@ -26,7 +26,7 @@ - + UPDATE user_notify SET is_read = 1 WHERE username = #{username}; From 039b5544eb03e5b303d0084de2d53d89ae3abe1c Mon Sep 17 00:00:00 2001 From: AInfinity-LilacDream <1977741520@qq.com> Date: Wed, 11 Jun 2025 11:21:17 +0800 Subject: [PATCH 42/62] fix: comment evaluation --- .../ocean/controller/UserCommentController.java | 13 +++++++++++++ .../ocean/service/UserBehaviorServiceImpl.java | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index f3b7267..7b37184 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -28,6 +28,7 @@ import java.util.Date; import java.util.List; +import static com.oriole.ocean.common.enumerate.BehaviorType.DO_COMMENT_LIKE; import static com.oriole.ocean.common.enumerate.ResultCode.SUCCESS; import static com.oriole.ocean.common.enumerate.ResultCode.UNAUTHORIZED_OPERATION; @@ -227,6 +228,18 @@ public MsgEntity evaluateComment(@AuthUser AuthUserEntity authUser, return new MsgEntity<>(SUCCESS); } + @RequestMapping(value = "/findEvaluateRecord", method = RequestMethod.GET) + public MsgEntity findEvaluateRecord(@AuthUser AuthUserEntity authUser, + @RequestParam Integer bindID, + @RequestParam MainType mainType, + @RequestParam String commentID) { + UserBehaviorEntity userBehaviorEntity = new UserBehaviorEntity(bindID, mainType, authUser.getUsername(), DO_COMMENT_LIKE); + userBehaviorEntity.setExtraInfo(BehaviorExtraInfo.COMMENT_ID, commentID); + + boolean ifExists = (userBehaviorService.findBehaviorRecord(userBehaviorEntity) != null); + return new MsgEntity<>("SUCCESS", "1", ifExists); + } + public String handleTime(String buildDate) { long timeDifference = new Date().getTime() - Long.parseLong(buildDate); diff --git a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java index 4a05d43..c1dacf1 100644 --- a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java +++ b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java @@ -157,5 +157,4 @@ public void deleteBehaviorRecordReal(UserBehaviorEntity userBehavior) { Query query = userBehavior.getQuery(); mongoTemplate.remove(query, "user_behavior"); } - } From b97ea37d0e639b7f94873d23e966693b2b11cf1a Mon Sep 17 00:00:00 2001 From: cms42 Date: Sat, 21 Jun 2025 13:51:18 +0800 Subject: [PATCH 43/62] feat: implement user info update validation --- ocean-user-service/pom.xml | 6 + .../ocean/ControllerExceptionHandler.java | 46 ++++++ .../ocean/controller/UserInfoController.java | 50 +++++- .../oriole/ocean/dto/UserInfoUpdateDTO.java | 26 +++ .../com/oriole/ocean/util/ValidationUtil.java | 119 ++++++++++++++ .../ocean/validation/ValidationTest.java | 154 ++++++++++++++++++ 6 files changed, 399 insertions(+), 2 deletions(-) create mode 100644 ocean-user-service/src/main/java/com/oriole/ocean/util/ValidationUtil.java create mode 100644 ocean-user-service/src/test/java/com/oriole/ocean/validation/ValidationTest.java diff --git a/ocean-user-service/pom.xml b/ocean-user-service/pom.xml index b859331..14260bb 100644 --- a/ocean-user-service/pom.xml +++ b/ocean-user-service/pom.xml @@ -60,6 +60,12 @@ springfox-swagger-ui + + + org.springframework.boot + spring-boot-starter-validation + + diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/ControllerExceptionHandler.java b/ocean-user-service/src/main/java/com/oriole/ocean/ControllerExceptionHandler.java index 0a1cd06..7e178ad 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/ControllerExceptionHandler.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/ControllerExceptionHandler.java @@ -5,11 +5,16 @@ import com.oriole.ocean.common.vo.OceanExceptionHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import java.util.stream.Collectors; + @Slf4j @ControllerAdvice @ResponseBody @@ -20,6 +25,47 @@ public MsgEntity businessExceptionHandler(Busine return super.businessExceptionHandler(ex); } + /** + * Handle validation errors from @Valid annotation on request body + */ + @ExceptionHandler(MethodArgumentNotValidException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public MsgEntity handleValidationException(MethodArgumentNotValidException ex) { + String errorMessage = ex.getBindingResult() + .getFieldErrors() + .stream() + .map(error -> error.getDefaultMessage()) + .collect(Collectors.joining("; ")); + + log.warn("Validation error: {}", errorMessage); + ErrorMsg errorMsg = new ErrorMsg( + "VALIDATION_ERROR", + "handleValidationException", + "ControllerExceptionHandler", + "数据验证失败: " + errorMessage); + return new MsgEntity<>("VALIDATION_ERROR", "-8", errorMsg); + } + + /** + * Handle validation errors from @Validated annotation on method parameters + */ + @ExceptionHandler(ConstraintViolationException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public MsgEntity handleConstraintViolationException(ConstraintViolationException ex) { + String errorMessage = ex.getConstraintViolations() + .stream() + .map(ConstraintViolation::getMessage) + .collect(Collectors.joining("; ")); + + log.warn("Constraint violation: {}", errorMessage); + ErrorMsg errorMsg = new ErrorMsg( + "CONSTRAINT_VIOLATION", + "handleConstraintViolationException", + "ControllerExceptionHandler", + "参数验证失败: " + errorMessage); + return new MsgEntity<>("VALIDATION_ERROR", "-9", errorMsg); + } + @ExceptionHandler(Exception.class) @ResponseStatus(value= HttpStatus.INTERNAL_SERVER_ERROR) @Override diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java index 05be2bd..8866424 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java @@ -9,10 +9,13 @@ import com.oriole.ocean.dto.UserInfoUpdateDTO; import com.oriole.ocean.service.UserInfoServiceImpl; import com.oriole.ocean.service.base.UserBaseInfoServiceImpl; +import com.oriole.ocean.util.ValidationUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.validation.Valid; + @RestController @Slf4j @RequestMapping("/userInfoService") @@ -53,12 +56,16 @@ public MsgEntity getUserAllInfo(@AuthUser AuthUserEntity authUser) { @PostMapping("/updateUserInfo") /** * Update user personal information. Only non-null fields will be updated. + * Includes comprehensive validation for security and data integrity. * @param authUser Authenticated user (from token) - * @param updateDTO Fields to update + * @param updateDTO Fields to update (validated) * @return Success message or error */ - public MsgEntity updateUserInfo(@AuthUser AuthUserEntity authUser, @RequestBody UserInfoUpdateDTO updateDTO) { + public MsgEntity updateUserInfo(@AuthUser AuthUserEntity authUser, @Valid @RequestBody UserInfoUpdateDTO updateDTO) { try { + // Additional security validation beyond annotation validation + validateSecurityConstraints(updateDTO); + userInfoService.updateUserInfo(authUser.getUsername(), updateDTO); return new MsgEntity<>("SUCCESS", "1", "User info updated successfully"); } catch (Exception e) { @@ -66,4 +73,43 @@ public MsgEntity updateUserInfo(@AuthUser AuthUserEntity authUser, @Requ throw new BusinessException("-1", "Failed to update user info: " + e.getMessage()); } } + + /** + * Validates security constraints for all string fields in the DTO + * Checks for HTML tags, SQL injection, and XSS attempts + * + * @param updateDTO DTO to validate + * @throws BusinessException if validation fails + */ + private void validateSecurityConstraints(UserInfoUpdateDTO updateDTO) { + // Validate all string fields for security threats + if (!ValidationUtil.isSafeInput(updateDTO.getNickname())) { + throw new BusinessException("-5", "昵称包含不允许的字符或标签"); + } + if (!ValidationUtil.isSafeInput(updateDTO.getRealname())) { + throw new BusinessException("-5", "真实姓名包含不允许的字符或标签"); + } + if (!ValidationUtil.isSafeInput(updateDTO.getAvatar())) { + throw new BusinessException("-5", "头像URL包含不允许的字符或标签"); + } + if (!ValidationUtil.isSafeInput(updateDTO.getCollege())) { + throw new BusinessException("-5", "学院名称包含不允许的字符或标签"); + } + if (!ValidationUtil.isSafeInput(updateDTO.getMajor())) { + throw new BusinessException("-5", "专业名称包含不允许的字符或标签"); + } + if (!ValidationUtil.isSafeInput(updateDTO.getPersonalSignature())) { + throw new BusinessException("-5", "个人签名包含不允许的字符或标签"); + } + + // Additional email validation (beyond annotation) + if (!ValidationUtil.isValidEmail(updateDTO.getEmail())) { + throw new BusinessException("-6", "邮箱格式不正确"); + } + + // Additional phone validation (beyond annotation) + if (!ValidationUtil.isValidPhoneNumber(updateDTO.getPhoneNum())) { + throw new BusinessException("-7", "手机号格式不正确"); + } + } } diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/dto/UserInfoUpdateDTO.java b/ocean-user-service/src/main/java/com/oriole/ocean/dto/UserInfoUpdateDTO.java index 24badc9..a07b7f0 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/dto/UserInfoUpdateDTO.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/dto/UserInfoUpdateDTO.java @@ -1,6 +1,7 @@ package com.oriole.ocean.dto; import lombok.Data; +import javax.validation.constraints.*; import java.io.Serializable; import java.util.Date; @@ -14,18 +15,43 @@ @Data public class UserInfoUpdateDTO implements Serializable { // User table fields + @Size(max = 50, message = "昵称长度不能超过50个字符") private String nickname; + + @Email(message = "邮箱格式不正确") + @Size(max = 100, message = "邮箱长度不能超过100个字符") private String email; + + @Pattern(regexp = "^[0-9+\\-\\s()]{10,20}$", message = "手机号格式不正确") private String phoneNum; + + @Size(max = 50, message = "真实姓名长度不能超过50个字符") private String realname; + + @Size(max = 255, message = "头像URL长度不能超过255个字符") private String avatar; + + @Min(value = 0, message = "等级不能小于0") + @Max(value = 999999, message = "等级不能大于999999") private Integer levelGrade; + + @Min(value = 1, message = "认证ID必须大于0") private Integer certID; // UserExtra table fields + @Size(max = 100, message = "学院名称长度不能超过100个字符") private String college; + + @Size(max = 100, message = "专业名称长度不能超过100个字符") private String major; + + @Past(message = "生日必须是过去的日期") private Date birthday; + + @Min(value = 0, message = "性别值不正确") + @Max(value = 2, message = "性别值不正确") private Integer sex; + + @Size(max = 500, message = "个人签名长度不能超过500个字符") private String personalSignature; } \ No newline at end of file diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/util/ValidationUtil.java b/ocean-user-service/src/main/java/com/oriole/ocean/util/ValidationUtil.java new file mode 100644 index 0000000..f64de88 --- /dev/null +++ b/ocean-user-service/src/main/java/com/oriole/ocean/util/ValidationUtil.java @@ -0,0 +1,119 @@ +package com.oriole.ocean.util; + +import java.util.regex.Pattern; + +/** + * Utility class for data validation including security checks + * + * @author Ocean Team + */ +public class ValidationUtil { + + // Regex patterns for security validation + private static final Pattern HTML_TAG_PATTERN = Pattern.compile("<[^>]*>"); + private static final Pattern EMAIL_PATTERN = Pattern.compile("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"); + private static final Pattern PHONE_PATTERN = Pattern.compile("^[0-9+\\-\\s()]{10,20}$"); + + // SQL injection patterns + private static final Pattern[] SQL_INJECTION_PATTERNS = { + Pattern.compile("(\\b(SELECT|INSERT|UPDATE|DELETE|DROP|CREATE|ALTER|EXEC|UNION|SCRIPT)\\b)", Pattern.CASE_INSENSITIVE), + Pattern.compile("(--|/\\*|\\*/|;|'|\"|`)"), + Pattern.compile("(\\bOR\\b|\\bAND\\b).*[=<>]", Pattern.CASE_INSENSITIVE) + }; + + // XSS patterns + private static final Pattern[] XSS_PATTERNS = { + Pattern.compile("javascript:", Pattern.CASE_INSENSITIVE), + Pattern.compile("on\\w+\\s*=", Pattern.CASE_INSENSITIVE), + Pattern.compile("data:text/html", Pattern.CASE_INSENSITIVE), + Pattern.compile("vbscript:", Pattern.CASE_INSENSITIVE) + }; + + /** + * Validates input for security threats (HTML tags, SQL injection, XSS) + * + * @param input Input string to validate + * @return true if input is safe, false otherwise + */ + public static boolean isSafeInput(String input) { + if (input == null || input.trim().isEmpty()) { + return true; // Allow empty values + } + + // Check for HTML tags + if (HTML_TAG_PATTERN.matcher(input).find()) { + return false; + } + + // Check for SQL injection patterns + for (Pattern pattern : SQL_INJECTION_PATTERNS) { + if (pattern.matcher(input).find()) { + return false; + } + } + + // Check for XSS patterns + for (Pattern pattern : XSS_PATTERNS) { + if (pattern.matcher(input).find()) { + return false; + } + } + + return true; + } + + /** + * Validates email format + * + * @param email Email string to validate + * @return true if valid email format, false otherwise + */ + public static boolean isValidEmail(String email) { + if (email == null || email.trim().isEmpty()) { + return true; // Allow empty email (optional field) + } + return EMAIL_PATTERN.matcher(email.trim()).matches(); + } + + /** + * Validates phone number format + * + * @param phoneNum Phone number to validate + * @return true if valid phone format, false otherwise + */ + public static boolean isValidPhoneNumber(String phoneNum) { + if (phoneNum == null || phoneNum.trim().isEmpty()) { + return true; // Allow empty phone (optional field) + } + return PHONE_PATTERN.matcher(phoneNum.trim()).matches(); + } + + /** + * Validates string length + * + * @param input String to validate + * @param maxLength Maximum allowed length + * @return true if within length limit, false otherwise + */ + public static boolean isValidLength(String input, int maxLength) { + if (input == null) { + return true; + } + return input.length() <= maxLength; + } + + /** + * Validates that integer is within specified range + * + * @param value Integer value to validate + * @param min Minimum allowed value (inclusive) + * @param max Maximum allowed value (inclusive) + * @return true if within range, false otherwise + */ + public static boolean isValidRange(Integer value, int min, int max) { + if (value == null) { + return true; + } + return value >= min && value <= max; + } +} \ No newline at end of file diff --git a/ocean-user-service/src/test/java/com/oriole/ocean/validation/ValidationTest.java b/ocean-user-service/src/test/java/com/oriole/ocean/validation/ValidationTest.java new file mode 100644 index 0000000..fc5dbce --- /dev/null +++ b/ocean-user-service/src/test/java/com/oriole/ocean/validation/ValidationTest.java @@ -0,0 +1,154 @@ +package com.oriole.ocean.validation; + +import com.oriole.ocean.dto.UserInfoUpdateDTO; +import com.oriole.ocean.util.ValidationUtil; +import junit.framework.TestCase; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import java.util.Date; +import java.util.Set; + +/** + * Test class for validation functionality + * Demonstrates various validation scenarios for UserInfoUpdateDTO + */ +public class ValidationTest extends TestCase { + + private Validator validator; + + public void setUp() { + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + validator = factory.getValidator(); + } + + public void testValidUserInfoUpdateDTO() { + UserInfoUpdateDTO dto = new UserInfoUpdateDTO(); + dto.setNickname("TestUser"); + dto.setEmail("test@example.com"); + dto.setPhoneNum("1234567890"); + dto.setRealname("Test User"); + dto.setLevelGrade(100); + dto.setCollege("Computer Science"); + dto.setMajor("Software Engineering"); + dto.setBirthday(new Date(System.currentTimeMillis() - 86400000L)); // Yesterday + dto.setSex(1); + dto.setPersonalSignature("Hello World"); + + Set> violations = validator.validate(dto); + assertTrue("Valid DTO should have no violations", violations.isEmpty()); + } + + public void testInvalidEmail() { + UserInfoUpdateDTO dto = new UserInfoUpdateDTO(); + dto.setEmail("invalid-email"); + + Set> violations = validator.validate(dto); + assertFalse("Invalid email should cause violations", violations.isEmpty()); + assertTrue("Should contain email validation error", + violations.stream().anyMatch(v -> v.getMessage().contains("邮箱格式不正确"))); + } + + public void testInvalidPhoneNumber() { + UserInfoUpdateDTO dto = new UserInfoUpdateDTO(); + dto.setPhoneNum("abc"); + + Set> violations = validator.validate(dto); + assertFalse("Invalid phone should cause violations", violations.isEmpty()); + assertTrue("Should contain phone validation error", + violations.stream().anyMatch(v -> v.getMessage().contains("手机号格式不正确"))); + } + + public void testMaxLengthViolation() { + UserInfoUpdateDTO dto = new UserInfoUpdateDTO(); + // Create a string longer than 50 characters + StringBuilder longNickname = new StringBuilder(); + for (int i = 0; i < 51; i++) { + longNickname.append("a"); + } + dto.setNickname(longNickname.toString()); + + Set> violations = validator.validate(dto); + assertFalse("Long nickname should cause violations", violations.isEmpty()); + assertTrue("Should contain length validation error", + violations.stream().anyMatch(v -> v.getMessage().contains("昵称长度不能超过50个字符"))); + } + + public void testFutureDateValidation() { + UserInfoUpdateDTO dto = new UserInfoUpdateDTO(); + dto.setBirthday(new Date(System.currentTimeMillis() + 86400000L)); // Tomorrow + + Set> violations = validator.validate(dto); + assertFalse("Future birthday should cause violations", violations.isEmpty()); + assertTrue("Should contain past date validation error", + violations.stream().anyMatch(v -> v.getMessage().contains("生日必须是过去的日期"))); + } + + public void testInvalidSexValue() { + UserInfoUpdateDTO dto = new UserInfoUpdateDTO(); + dto.setSex(5); // Invalid value (should be 0-2) + + Set> violations = validator.validate(dto); + assertFalse("Invalid sex value should cause violations", violations.isEmpty()); + assertTrue("Should contain sex validation error", + violations.stream().anyMatch(v -> v.getMessage().contains("性别值不正确"))); + } + + // Security validation tests using ValidationUtil + + public void testSafeInputValidation() { + assertTrue("Normal text should be safe", ValidationUtil.isSafeInput("Normal text")); + assertTrue("Empty string should be safe", ValidationUtil.isSafeInput("")); + assertTrue("Null should be safe", ValidationUtil.isSafeInput(null)); + } + + public void testHtmlTagDetection() { + assertFalse("HTML tags should be detected", ValidationUtil.isSafeInput("")); + assertFalse("HTML tags should be detected", ValidationUtil.isSafeInput("Hello world")); + assertFalse("HTML tags should be detected", ValidationUtil.isSafeInput("
content
")); + } + + public void testSqlInjectionDetection() { + assertFalse("SQL injection should be detected", ValidationUtil.isSafeInput("'; DROP TABLE users; --")); + assertFalse("SQL injection should be detected", ValidationUtil.isSafeInput("1' OR '1'='1")); + assertFalse("SQL injection should be detected", ValidationUtil.isSafeInput("SELECT * FROM users")); + assertFalse("SQL injection should be detected", ValidationUtil.isSafeInput("admin'--")); + } + + public void testXssDetection() { + assertFalse("XSS should be detected", ValidationUtil.isSafeInput("javascript:alert('xss')")); + assertFalse("XSS should be detected", ValidationUtil.isSafeInput("onclick=alert('xss')")); + assertFalse("XSS should be detected", ValidationUtil.isSafeInput("data:text/html,")); + assertFalse("XSS should be detected", ValidationUtil.isSafeInput("vbscript:msgbox('xss')")); + } + + public void testEmailValidation() { + assertTrue("Valid email should pass", ValidationUtil.isValidEmail("test@example.com")); + assertTrue("Valid email should pass", ValidationUtil.isValidEmail("user.name@domain.co.uk")); + assertTrue("Empty email should pass", ValidationUtil.isValidEmail("")); + assertTrue("Null email should pass", ValidationUtil.isValidEmail(null)); + + assertFalse("Invalid email should fail", ValidationUtil.isValidEmail("invalid-email")); + assertFalse("Invalid email should fail", ValidationUtil.isValidEmail("@domain.com")); + assertFalse("Invalid email should fail", ValidationUtil.isValidEmail("user@")); + } + + public void testPhoneValidation() { + assertTrue("Valid phone should pass", ValidationUtil.isValidPhoneNumber("1234567890")); + assertTrue("Valid phone should pass", ValidationUtil.isValidPhoneNumber("+1-234-567-8900")); + assertTrue("Valid phone should pass", ValidationUtil.isValidPhoneNumber("(123) 456-7890")); + assertTrue("Empty phone should pass", ValidationUtil.isValidPhoneNumber("")); + assertTrue("Null phone should pass", ValidationUtil.isValidPhoneNumber(null)); + + assertFalse("Invalid phone should fail", ValidationUtil.isValidPhoneNumber("abc")); + assertFalse("Invalid phone should fail", ValidationUtil.isValidPhoneNumber("123")); + // Create a very long phone number + StringBuilder longPhone = new StringBuilder(); + for (int i = 0; i < 25; i++) { + longPhone.append("1"); + } + assertFalse("Invalid phone should fail", ValidationUtil.isValidPhoneNumber(longPhone.toString())); + } +} \ No newline at end of file From 82895bd72dd3d3792c6fde3b9f1b19c6c5faed97 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sat, 21 Jun 2025 15:00:42 +0800 Subject: [PATCH 44/62] feat: unlike will remove the like notification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- cascade delete trigger DELIMITER // CREATE TRIGGER trg_cleanup_user_notify BEFORE DELETE ON notify FOR EACH ROW BEGIN DELETE FROM user_notify WHERE user_notify.notify_id = OLD.id; END// DELIMITER ; -- delete function DELIMITER // CREATE PROCEDURE sp_safe_delete_notify( IN p_target_id VARCHAR(255), IN p_target_type VARCHAR(255), IN p_comment_id VARCHAR(255), IN p_action VARCHAR(255), IN p_build_username VARCHAR(255) ) BEGIN DECLARE v_id INT; -- 声明变量存储查询到的 id START TRANSACTION; -- 开启事务 SELECT id -- 查询符合条件的 id(最多 1 个) INTO v_id FROM notify WHERE target_id = p_target_id AND target_type = p_target_type AND comment_id = p_comment_id AND action = p_action AND build_username = p_build_username LIMIT 1; -- 如果找到记录,则删除 IF v_id IS NOT NULL THEN DELETE FROM notify WHERE id = v_id; END IF; COMMIT; -- 提交事务 END // DELIMITER ; --- .../controller/UserCommentController.java | 18 ++---- .../ocean/common/service/NotifyService.java | 9 +++ .../oriole/ocean/service/NoteServiceImpl.java | 4 ++ .../java/com/oriole/ocean/dao/NotifyDao.java | 1 + .../ocean/service/NotifyServiceImpl.java | 55 +++++++++++++++++-- .../src/main/resources/mapper/Notify.xml | 11 ++++ .../service/UserBehaviorServiceImpl.java | 3 +- 7 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 ocean-notify-service/src/main/resources/mapper/Notify.xml diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index 7b37184..1579202 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -116,16 +116,12 @@ public MsgEntity addComment(@AuthUser AuthUserEntity authUser, String cid = RandomStringUtils.randomAlphanumeric(8).toUpperCase(); AbstractComment returnEntity; //构建用户消息事件 - NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND,authUser.getUsername()); - notifyEntity.setTargetIDAndType(String.valueOf(bindID),mainType); - notifyEntity.setContent(commentContent); if (!isReply) { CommentEntity commentEntity = new CommentEntity(cid, authUser.getUsername(), commentContent); - commentService.addComment(bindID, mainType, commentEntity); commentEntity.setBuildDate(handleTime(commentEntity.getBuildDate())); + commentService.addComment(bindID, mainType, commentEntity); + notifyService.addNotifyByComment(bindID, mainType, commentEntity); returnEntity = commentEntity; - notifyEntity.setAction(NotifyAction.NEW_COMMENT);// 新评论事件不面向任何其他评论 - notifyEntity.setCommentID(String.valueOf(bindID)); } else { CommentReplyEntity fileCommentReplyEntity = new CommentReplyEntity( replyInCommentID + "_" + cid, authUser.getUsername(), @@ -134,13 +130,12 @@ public MsgEntity addComment(@AuthUser AuthUserEntity authUser, commentContent); commentService.addCommentReply(bindID, mainType, replyInCommentID, fileCommentReplyEntity); fileCommentReplyEntity.setBuildDate(handleTime(fileCommentReplyEntity.getBuildDate())); - returnEntity = fileCommentReplyEntity; - notifyEntity.setAction(NotifyAction.NEW_REPLY); if(!replyToCommentReplyID.isEmpty()){ - notifyEntity.setCommentID(replyToCommentReplyID); + notifyService.addNotifyByReply(bindID, mainType, replyToCommentReplyID, fileCommentReplyEntity); }else { - notifyEntity.setCommentID(replyInCommentID); + notifyService.addNotifyByReply(bindID, mainType, replyInCommentID, fileCommentReplyEntity); } + returnEntity = fileCommentReplyEntity; } // 增加用户消息订阅事件:用户需要订阅自己发布的评论或回复的动态 List notifyActionList = new ArrayList<>(); @@ -149,9 +144,6 @@ public MsgEntity addComment(@AuthUser AuthUserEntity authUser, notifySubscriptionService.setNotifySubscription(authUser.getUsername(), notifyActionList, returnEntity.getId(), NotifySubscriptionTargetType.COMMENT); - // 产生用户消息事件 - notifyService.addNotify(notifyEntity); - if (!isReply) { // 只有评论才计入文章的评论量统计 commentService.commentStatisticsChange(bindID, "+1", mainType); diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifyService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifyService.java index 8a35f08..b144975 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifyService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifyService.java @@ -1,7 +1,16 @@ package com.oriole.ocean.common.service; +import com.oriole.ocean.common.enumerate.MainType; +import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; +import com.oriole.ocean.common.po.mongo.comment.CommentEntity; +import com.oriole.ocean.common.po.mongo.comment.CommentReplyEntity; import com.oriole.ocean.common.po.mysql.NotifyEntity; public interface NotifyService { void addNotify(NotifyEntity notifyEntity); + void addNotifyByComment(Integer bindID, MainType mainType, + CommentEntity fileCommentEntity); + void addNotifyByReply(Integer bindID, MainType mainType, + String replyInCommentID, CommentReplyEntity fileCommentReplyEntity); + void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java index 955e9f7..425cf2a 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java @@ -6,6 +6,7 @@ import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteLikeEntity; import com.oriole.ocean.common.service.NoteService; +import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.dao.NoteCollectionDao; import com.oriole.ocean.dao.NoteCommentDao; import com.oriole.ocean.dao.NoteDao; @@ -43,6 +44,9 @@ public class NoteServiceImpl extends ServiceImpl implements @Resource private NoteLikeDao noteLikeDao; + @Resource + private NotifyService notifyService; + /** * Check if user is the creator of a note * @param noteId Note ID diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/dao/NotifyDao.java b/ocean-notify-service/src/main/java/com/oriole/ocean/dao/NotifyDao.java index df9b6b3..1c6e18e 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/dao/NotifyDao.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/dao/NotifyDao.java @@ -4,4 +4,5 @@ import com.oriole.ocean.common.po.mysql.NotifyEntity; public interface NotifyDao extends BaseMapper { + void removeNotify(NotifyEntity notifyEntity); } diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java index 10df130..2f16033 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java @@ -2,11 +2,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.enumerate.BehaviorExtraInfo; -import com.oriole.ocean.common.enumerate.NotifyAction; -import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; -import com.oriole.ocean.common.enumerate.NotifyType; +import com.oriole.ocean.common.enumerate.*; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; +import com.oriole.ocean.common.po.mongo.comment.CommentEntity; +import com.oriole.ocean.common.po.mongo.comment.CommentReplyEntity; +import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteEntity; import com.oriole.ocean.common.po.mysql.NotifySubscriptionEntity; import com.oriole.ocean.common.po.mysql.UserNotifyEntity; import com.oriole.ocean.common.service.NotifyService; @@ -19,6 +20,7 @@ import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.Objects; @Service @DubboService @@ -28,18 +30,53 @@ public void addNotify(NotifyEntity notifyEntity){ save(notifyEntity); } + public void addNotifyByComment(Integer bindID, MainType mainType, + CommentEntity fileCommentEntity){ + NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND, fileCommentEntity.getCommentBuildUsername()); + notifyEntity.setTargetID(bindID.toString()); + notifyEntity.setTargetType(mainType); + notifyEntity.setContent(fileCommentEntity.getCommentContent()); + notifyEntity.setAction(NotifyAction.NEW_COMMENT); + addNotify(notifyEntity); + } + + public void addNotifyByReply(Integer bindID, MainType mainType, + String replyInCommentID, CommentReplyEntity fileCommentReplyEntity){ + NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND, fileCommentReplyEntity.getReplyBuildUsername()); + notifyEntity.setTargetID(bindID.toString()); + notifyEntity.setTargetType(mainType); + notifyEntity.setCommentID(replyInCommentID); + notifyEntity.setContent(fileCommentReplyEntity.getCommentContent()); + notifyEntity.setAction(NotifyAction.NEW_REPLY); + addNotify(notifyEntity); + } + // 根据用户行为生产消息 public void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity) { // 收藏、每日签到、阅读等行为都不需要记录为通知行为 + boolean add_or_remove = true; NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND,userBehaviorEntity.getDoUsername()); switch (userBehaviorEntity.getBehaviorType()) { case DO_DOWNLOAD: notifyEntity.setAction(NotifyAction.DOWNLOAD); break; case DO_LIKE: + add_or_remove = true; + notifyEntity.setAction(NotifyAction.LIKE); + notifyEntity.setContent(userBehaviorEntity.getDoUsername() + "点赞了你的帖子"); + break; + case DO_DISLIKE: + add_or_remove = false; notifyEntity.setAction(NotifyAction.LIKE); break; case DO_COMMENT_LIKE: + add_or_remove = true; + notifyEntity.setAction(NotifyAction.LIKE_COMMENT); + notifyEntity.setCommentID((String) userBehaviorEntity.getExtraInfo(BehaviorExtraInfo.COMMENT_ID)); + notifyEntity.setContent(userBehaviorEntity.getDoUsername() + "点赞了你的评论"); + break; + case DO_COMMENT_DISLIKE: + add_or_remove = false; notifyEntity.setAction(NotifyAction.LIKE_COMMENT); notifyEntity.setCommentID((String) userBehaviorEntity.getExtraInfo(BehaviorExtraInfo.COMMENT_ID)); break; @@ -48,7 +85,15 @@ public void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity) { } notifyEntity.setUserBehaviorID(userBehaviorEntity.getId()); notifyEntity.setTargetIDAndType(String.valueOf(userBehaviorEntity.getBindID()),userBehaviorEntity.getType()); - addNotify(notifyEntity); + if(add_or_remove) + addNotify(notifyEntity); + else + removeNotify(notifyEntity); + } + + private void removeNotify(NotifyEntity notifyEntity) { + NotifyDao notifyDao = getBaseMapper(); + notifyDao.removeNotify(notifyEntity); } // 查询指定时间之后产生的所有消息 diff --git a/ocean-notify-service/src/main/resources/mapper/Notify.xml b/ocean-notify-service/src/main/resources/mapper/Notify.xml new file mode 100644 index 0000000..f91e442 --- /dev/null +++ b/ocean-notify-service/src/main/resources/mapper/Notify.xml @@ -0,0 +1,11 @@ + + + + + CALL sp_safe_delete_notify( + #{targetId}, #{targetType}, + #{commentId}, #{action}, + #{buildUsername}); + + \ No newline at end of file diff --git a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java index c1dacf1..0cfd273 100644 --- a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java +++ b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java @@ -5,6 +5,7 @@ import com.oriole.ocean.common.enumerate.BehaviorType; import com.oriole.ocean.common.enumerate.EvaluateType; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; +import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.common.service.UserBehaviorService; import com.oriole.ocean.common.vo.BusinessException; import org.apache.dubbo.config.annotation.DubboService; @@ -31,7 +32,7 @@ public class UserBehaviorServiceImpl implements UserBehaviorService { private MongoTemplate mongoTemplate; @Autowired - private NotifyServiceImpl notifyService; + private NotifyService notifyService; // 检查某用户针对特定对象(某文档/某便签等)的评价行为,并得出此次评价所需发生的全部评价行为 // 对特定对象具有评论区时,也可处理对其评论区的评价行为 From befda7728d8d4b2f7fa74dcdbdd8f6b2cc95524e Mon Sep 17 00:00:00 2001 From: AInfinity-LilacDream <1977741520@qq.com> Date: Sat, 21 Jun 2025 15:11:53 +0800 Subject: [PATCH 45/62] feat: add readnum support --- .../ocean/common/service/NoteService.java | 2 ++ .../ocean/controller/NoteController.java | 22 ++++++++++++++----- .../com/oriole/ocean/dao/NoteCommentDao.java | 3 +++ .../java/com/oriole/ocean/dao/NoteDao.java | 7 ++++++ .../oriole/ocean/service/NoteServiceImpl.java | 9 ++++++-- .../src/main/resources/mapper/NoteMapper.xml | 19 ++++++++++++++++ 6 files changed, 54 insertions(+), 8 deletions(-) diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java index 364f212..2c98191 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java @@ -20,6 +20,8 @@ public interface NoteService { */ boolean isNoteCreator(String noteId, String username); + void readNote(String noteId); + /** * Delete a note (soft delete) * @param noteID Note ID to delete diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index 0307baa..d7b3b6a 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -212,13 +212,22 @@ public MsgEntity likeNote( String username = authUser.getUsername(); - NoteLikeEntity result = noteService.likeNote(username, noteId, isLike); + NoteLikeEntity result = noteService.likeNote(username, noteId, isLike); - if (isLike) { - return new MsgEntity<>("SUCCESS", "1", result); - } else { - return new MsgEntity<>("SUCCESS", "1", null); - } + if (isLike) return new MsgEntity<>("SUCCESS", "1", result); + else return new MsgEntity<>("SUCCESS", "1", null); + } + + @RequestMapping (value = "/readNote", method = RequestMethod.POST) + public MsgEntity readNote( + @AuthUser AuthUserEntity authUser, + @RequestParam String noteId) { + + String username = authUser.getUsername(); + + noteService.readNote(noteId); + + return new MsgEntity<>("SUCCESS", "1", "Note read successfully"); } /** @@ -305,6 +314,7 @@ public MsgEntity deleteNoteComment( @AuthUser AuthUserEntity authUser, @RequestParam String _id) { if(!noteService.isNoteCreator(_id, authUser.getUsername())) { + System.out.println(authUser.getUsername()); if(authUser.isAdmin()) { //TODO: Record administrator operation } else { diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java index 65f6189..20a00a6 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java @@ -15,9 +15,12 @@ public class NoteCommentDao { @Autowired private MongoTemplate mongoTemplate; + @Autowired + private NoteDao noteDao; public void addNoteComment(NoteCommentEntity noteComment) { mongoTemplate.save(noteComment, "note_comments"); + noteDao.increaseCommentCnt(noteComment.getNoteId()); } public List getNoteCommentsByNoteId(String noteId, int pageNo, int pageSize) { diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java index 441c792..b5476aa 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java @@ -16,6 +16,11 @@ */ @Mapper public interface NoteDao extends BaseMapper { + + + String getNoteCreator(String noteID); + + void readNote(String noteId); /** * Get latest notes @@ -90,4 +95,6 @@ NoteEntity getNoteByIdWithLikeStatus(@Param("noteId") String noteId, * @return List of note comments */ List getNoteCommentsByNoteId(@Param("noteId") String noteId); + + void increaseCommentCnt(@Param("noteID") String noteID); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java index 955e9f7..d70da47 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java @@ -50,8 +50,9 @@ public class NoteServiceImpl extends ServiceImpl implements * @return true if user is creator, false otherwise */ public boolean isNoteCreator(String noteId, String username) { - NoteEntity note = noteDao.getNoteById(noteId); - return note != null && note.getBuildUsername().equals(username); + System.out.println(noteId); + NoteCommentEntity note = noteCommentDao.getNoteComment(noteId); + return note != null && note.getNoteCommentBuildUsername().equals(username); } /** @@ -205,6 +206,10 @@ public List getNoteCommentsByNoteId(String noteId, int pageNo return noteCommentDao.getNoteCommentsByNoteId(noteId, pageNo, pageSize); } + public void readNote(String noteId) { + noteDao.readNote(noteId); + } + /** * Check if user is the creator of a comment * @param commentId Comment ID diff --git a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml index 68a521d..8b3bb6d 100644 --- a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml +++ b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml @@ -158,4 +158,23 @@ WHERE note.note_id = #{noteID}; + + UPDATE note + SET read_num = read_num + 1 + WHERE note.note_id = #{noteId}; + + + + UPDATE note + SET comment_num = comment_num + 1 + WHERE note.note_id = #{noteID}; + + + + \ No newline at end of file From 9661f147c2ae7139cef8c3fb71cb9c3c43b262ea Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sat, 21 Jun 2025 16:51:15 +0800 Subject: [PATCH 46/62] feat: new handler '/getMyNotes' online untested --- .../ocean/common/service/NoteService.java | 7 +++++ .../ocean/controller/NoteController.java | 15 ++++++++++ .../java/com/oriole/ocean/dao/NoteDao.java | 9 +++++- .../oriole/ocean/service/NoteServiceImpl.java | 9 ++++++ .../src/main/resources/mapper/NoteMapper.xml | 28 +++++++++++++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java index 364f212..ecad982 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java @@ -87,6 +87,13 @@ public interface NoteService { */ List getLatestNotesWithLikeStatus(String username); + /** + * Get notes by creator name + * @param username Current user's name + * @return list of notes created by that user + */ + List getNotesByUsernameWithLikeStatus(String username); + /** * Get notes by keywords * @param searchString Search keywords diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index 0307baa..6712900 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -101,6 +101,21 @@ public MsgEntity> getNotesByKeywords( return new MsgEntity<>("SUCCESS","1",pageInfo); } + /** + * Select notes by creator name with pagination + * Returns notes with like status for authenticated user + */ + @RequestMapping(value = "/getMyNotes", method = RequestMethod.POST) + public MsgEntity> getMyNotes( + @AuthUser AuthUserEntity authUser, + @RequestParam int pageNO, + @RequestParam int pageSize) { + PageHelper.startPage(pageNO, pageSize, true); + List noteEntityList = noteService.getNotesByUsernameWithLikeStatus(authUser.getUsername()); + PageInfo pageInfo = new PageInfo<>(noteEntityList); + return new MsgEntity<>("SUCCESS","1",pageInfo); + } + /** * Get note by ID * Returns note with like status for authenticated user diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java index 441c792..75fac39 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java @@ -61,7 +61,14 @@ List getNotesByKeywordsWithLikeStatus(@Param("searchString") String */ List getNotesByTagWithLikeStatus(@Param("tag") String tag, @Param("username") String username); - + + /** + * Get notes by creator name + * @param username Current user's name + * @return list of notes created by that user + */ + List getNotesByMyNameWithLikeStatus(@Param("username") String username); + /** * Get note by ID * @param noteId Note ID diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java index 425cf2a..4d15376 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java @@ -128,6 +128,15 @@ public List getLatestNotesWithLikeStatus(String username) { return noteDao.getLatestNotesWithLikeStatus(username); } + /** + * Get notes by creator name + * @param username Current user's name + * @return list of notes created by that user + */ + public List getNotesByUsernameWithLikeStatus(String username) { + return noteDao.getNotesByMyNameWithLikeStatus(username); + } + /** * Get notes by keywords * @param searchString Search keywords diff --git a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml index 68a521d..c440858 100644 --- a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml +++ b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml @@ -152,6 +152,34 @@ WHERE n.note_id = #{noteId} AND n.is_deleted = 0 + + UPDATE note SET is_deleted = 1 From eae868dbb17599034a7a8a515ad91808d5a83af9 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sat, 21 Jun 2025 17:16:40 +0800 Subject: [PATCH 47/62] fix: small mapper mistake --- ocean-note-service/src/main/resources/mapper/NoteMapper.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml index c440858..9de02d0 100644 --- a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml +++ b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml @@ -152,7 +152,7 @@ WHERE n.note_id = #{noteId} AND n.is_deleted = 0 - SELECT n.note_id as id, n.build_username, @@ -177,7 +177,7 @@ ON n.note_id = nl.note_id AND nl.username = #{username} WHERE n.is_deleted = 0 AND n.build_username = #{username} - ORDER BY n.refresh_date DESC; + ORDER BY n.refresh_date DESC From 9b8d0383012be04b38b4c6d1a3b369579b618483 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sat, 21 Jun 2025 22:40:09 +0800 Subject: [PATCH 48/62] feat: add comment like and move comment to MySQL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- comment table -- CREATE TABLE `note_comment` ( `id` varchar(32) NOT NULL COMMENT '主键ID', `note_id` varchar(32) NOT NULL COMMENT '笔记ID', `content` text NOT NULL COMMENT '评论内容', `build_username` varchar(255) NOT NULL COMMENT '评论用户', `like_num` int(11) DEFAULT '0' COMMENT '点赞数', `build_date` datetime NOT NULL COMMENT '创建时间', `is_deleted` tinyint(1) DEFAULT '0' COMMENT '是否删除(0:未删除,1:已删除)', `reply_id` varchar(32) DEFAULT NULL COMMENT '回复的评论ID', `reply_username` varchar(255) DEFAULT NULL COMMENT '回复的用户名', PRIMARY KEY (`id`), KEY `idx_note_id` (`note_id`), KEY `idx_build_username` (`build_username`), KEY `idx_reply_id` (`reply_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='笔记评论表'; -- like table -- CREATE TABLE `note_like` ( `id` varchar(32) NOT NULL COMMENT '主键ID', `username` varchar(255) NOT NULL COMMENT '点赞用户名', `comment_id` varchar(32) NOT NULL COMMENT '评论ID', `like_time` datetime NOT NULL COMMENT '点赞时间', PRIMARY KEY (`id`), KEY `idx_comment_id` (`comment_id`), KEY `idx_username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='笔记评论点赞表'; -- add like -- DELIMITER // CREATE TRIGGER `trg_note_like_after_insert` AFTER INSERT ON `note_like` FOR EACH ROW BEGIN UPDATE `note_comment` SET `like_num` = `like_num` + 1 WHERE `id` = NEW.`comment_id`; END// DELIMITER ; -- delete like -- DELIMITER // CREATE TRIGGER `trg_note_like_after_delete` AFTER DELETE ON `note_like` FOR EACH ROW BEGIN UPDATE `note_comment` SET `like_num` = `like_num` - 1 WHERE `id` = OLD.`comment_id`; END// DELIMITER ; --- .../po/mongo/comment/NoteCommentEntity.java | 29 ---- .../common/po/mysql/NoteCommentEntity.java | 53 +++++++ .../po/mysql/NoteCommentLikeEntity.java | 48 +++++++ .../common/service/NoteCommentService.java | 77 ++++++++++ .../ocean/common/service/NoteService.java | 24 +--- .../ocean/controller/NoteController.java | 60 ++++---- .../oriole/ocean/dao/NoteCollectionDao.java | 1 - .../com/oriole/ocean/dao/NoteCommentDao.java | 59 ++------ .../oriole/ocean/dao/NoteCommentLikeDao.java | 45 ++++++ .../java/com/oriole/ocean/dao/NoteDao.java | 4 +- .../ocean/service/NoteCommentServiceImpl.java | 131 ++++++++++++++++++ .../oriole/ocean/service/NoteServiceImpl.java | 60 +------- .../mapper/NoteCommentLikeMapper.xml | 39 ++++++ .../resources/mapper/NoteCommentMapper.xml | 34 +++++ .../ocean/service/NotifyServiceImpl.java | 7 - 15 files changed, 473 insertions(+), 198 deletions(-) delete mode 100644 ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/NoteCommentEntity.java create mode 100644 ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentEntity.java create mode 100644 ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentLikeEntity.java create mode 100644 ocean-common/src/main/java/com/oriole/ocean/common/service/NoteCommentService.java create mode 100644 ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentLikeDao.java create mode 100644 ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java create mode 100644 ocean-note-service/src/main/resources/mapper/NoteCommentLikeMapper.xml create mode 100644 ocean-note-service/src/main/resources/mapper/NoteCommentMapper.xml diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/NoteCommentEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/NoteCommentEntity.java deleted file mode 100644 index c6bd25f..0000000 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/NoteCommentEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.oriole.ocean.common.po.mongo.comment; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; - -import java.util.ArrayList; -import java.util.Date; - -@Data -public class NoteCommentEntity implements java.io.Serializable { - private String _id; - private String noteId; - private String noteCommentBuildUsername; - private Integer likeNum; - private Date createTime; - private String replyTo; - private String replyToUsername; - private String commentContent; - - public NoteCommentEntity(String noteId, String noteCommentBuildUsername, String commentContent, String replyTo, String replyToUsername) { - this.noteId = noteId; - this.commentContent = commentContent; - this.noteCommentBuildUsername = noteCommentBuildUsername; - this.replyTo = replyTo; - this.replyToUsername = replyToUsername; - } -} diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentEntity.java new file mode 100644 index 0000000..64f7be9 --- /dev/null +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentEntity.java @@ -0,0 +1,53 @@ +package com.oriole.ocean.common.po.mysql; + +import com.baomidou.mybatisplus.annotation.TableField; +import lombok.Data; + +import java.util.Date; + +@Data +public class NoteCommentEntity implements java.io.Serializable { + @TableField("id") + private String id; + + @TableField("note_id") + private String noteId; + + @TableField("content") + private String content; + + @TableField("build_username") + private String buildUsername; + + @TableField("like_num") + private Integer likeNum; + + @TableField("build_date") + private Date buildDate; + + @TableField("is_deleted") + private Byte isDeleted; + + @TableField("reply_id") + private String replyId; + + @TableField("reply_username") + private String replyUsername; + + /** + * Whether the current user has liked this comment. + * This field is not mapped to the database, only used for data transfer + */ + @TableField(exist = false) + private Boolean isLikedByCurrentUser; + + public NoteCommentEntity( + String noteId, String buildUsername, + String content, String replyId, String replyUsername) { + this.noteId = noteId; + this.content = content; + this.buildUsername = buildUsername; + this.replyId = replyId; + this.replyUsername = replyUsername; + } +} diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentLikeEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentLikeEntity.java new file mode 100644 index 0000000..52e51f2 --- /dev/null +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentLikeEntity.java @@ -0,0 +1,48 @@ +package com.oriole.ocean.common.po.mysql; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +/** + * Note like record entity + * Records the like relationship between users and notes + */ +@Data +@TableName("`note_like`") +public class NoteCommentLikeEntity implements java.io.Serializable { + + @TableId(value = "id", type = IdType.ASSIGN_ID) + private String id; + + @TableField("username") + private String username; + + @TableField("comment_id") + private String commentId; + + @TableField("like_time") + private Date likeTime; + + /** + * Default constructor + */ + public NoteCommentLikeEntity() { + this.likeTime = new Date(); + } + + /** + * Constructor with username and commentId + * @param username The username who likes the comment + * @param commentId The ID of the liked comment + */ + public NoteCommentLikeEntity(String username, String commentId) { + this.username = username; + this.commentId = commentId; + this.likeTime = new Date(); + } +} diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteCommentService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteCommentService.java new file mode 100644 index 0000000..f69b680 --- /dev/null +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteCommentService.java @@ -0,0 +1,77 @@ +package com.oriole.ocean.common.service; + +import com.oriole.ocean.common.po.mongo.FavorEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentLikeEntity; +import com.oriole.ocean.common.po.mysql.NoteEntity; +import com.oriole.ocean.common.po.mysql.NoteLikeEntity; + +import java.util.List; + +/** + * Note service interface + * Provides business logic for note operations + */ +public interface NoteCommentService { + + /** + * Check if user is the creator of a comment + * @param commentId Comment ID + * @param username Username to check + * @return true if user is creator, false otherwise + */ + boolean isCommentCreator(String commentId, String username); + + /** + * Delete a note comment + * @param commentId Comment ID + */ + void deleteNoteComment(String commentId); + + /** + * Get note comments by note ID + * @param noteId Note ID + * @return List of note comments + */ + List getNoteCommentsByNoteIdWithLikeStatus(String noteId); + + /** + * Get note comments by comment ID + * @param commentId comment ID + * @return note comment + */ + NoteCommentEntity getNoteComment(String commentId); + + /** + * Create a new note comment + * @param noteCommentEntity Note comment entity to create + * @return Created note comment entity + */ + NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity); + + + /** + * Like or unlike a note + * @param username Username who likes/unlikes + * @param commentId Note ID to like/unlike + * @param isLike true to like, false to unlike + * @return NoteLikeEntity if liked, null if unliked + */ + NoteCommentLikeEntity likeNoteComment(String username, String commentId, boolean isLike); + + /** + * Check if a user has liked a specific note + * @param username Username to check + * @param commentId Note ID to check + * @return true if liked, false otherwise + */ + boolean hasUserLikedNoteComment(String username, String commentId); + + /** + * Get like record for a user and note + * @param username Username + * @param commentId Note ID + * @return NoteLikeEntity if exists, null otherwise + */ + NoteCommentLikeEntity getNoteCommentLike(String username, String commentId); +} diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java index ecad982..9234f75 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java @@ -1,7 +1,7 @@ package com.oriole.ocean.common.service; import com.oriole.ocean.common.po.mongo.FavorEntity; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteEntity; import com.oriole.ocean.common.po.mysql.NoteLikeEntity; import java.util.List; @@ -51,12 +51,6 @@ public interface NoteService { */ NoteEntity getNoteByIdWithLikeStatus(String noteID, String username); - /** - * Delete a note comment - * @param commentId Comment ID - */ - void deleteNoteComment(String commentId); - /** * Get user behavior (favorites) for a specific note * @param username Username @@ -124,15 +118,6 @@ public interface NoteService { */ List getNotesByTagWithLikeStatus(String tag, String username); - /** - * Get note comments by note ID - * @param noteId Note ID - * @param pageNo Page number - * @param pageSize Page size - * @return List of note comments - */ - List getNoteCommentsByNoteId(String noteId, int pageNo, int pageSize); - /** * Create a new note * @param noteEntity Note entity to create @@ -140,13 +125,6 @@ public interface NoteService { */ NoteEntity createNote(NoteEntity noteEntity); - /** - * Create a new note comment - * @param noteCommentEntity Note comment entity to create - * @return Created note comment entity - */ - NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity); - // === Like functionality === /** diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index 6712900..401b94a 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -8,21 +8,13 @@ import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; import com.oriole.ocean.common.enumerate.NotifyType; import com.oriole.ocean.common.po.mongo.FavorEntity; -import com.oriole.ocean.common.po.mongo.comment.CommentEntity; -import com.oriole.ocean.common.po.mongo.comment.CommentReplyEntity; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteEntity; import com.oriole.ocean.common.po.mysql.NoteLikeEntity; import com.oriole.ocean.common.po.mysql.NotifyEntity; -import com.oriole.ocean.common.service.NotifyService; -import com.oriole.ocean.common.service.NotifySubscriptionService; -import com.oriole.ocean.common.service.UserBehaviorService; +import com.oriole.ocean.common.service.*; import com.oriole.ocean.common.vo.AuthUserEntity; import com.oriole.ocean.common.vo.MsgEntity; -import com.oriole.ocean.common.service.NoteService; -import com.oriole.ocean.dao.NoteCollectionDao; -import jdk.nashorn.internal.ir.RuntimeNode; -import org.apache.commons.lang3.RandomStringUtils; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; @@ -31,7 +23,6 @@ import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.Objects; @@ -45,6 +36,8 @@ public class NoteController { @Autowired NoteService noteService; + @Autowired + NoteCommentService noteCommentService; @DubboReference UserBehaviorService userBehaviorService; @DubboReference @@ -264,7 +257,7 @@ public MsgEntity> getNoteCommentByNoteId( @RequestParam Integer pageNo, @RequestParam Integer pageSize) { PageHelper.startPage(pageNo, pageSize, true); - List noteCommentEntityList = noteService.getNoteCommentsByNoteId(noteId, pageNo, pageSize); + List noteCommentEntityList = noteCommentService.getNoteCommentsByNoteIdWithLikeStatus(noteId); PageInfo pageInfo = new PageInfo<>(noteCommentEntityList); return new MsgEntity<>("SUCCESS", "1", pageInfo); } @@ -276,35 +269,35 @@ public MsgEntity> getNoteCommentByNoteId( public MsgEntity createNoteComment( @AuthUser AuthUserEntity authUser, @RequestParam String noteId, - @RequestParam String commentContent, - @RequestParam String replyTo, - @RequestParam String replyToUsername + @RequestParam String content, + @RequestParam String replyId, + @RequestParam String replyUsername ) { String userName = authUser.getUsername(); - NoteCommentEntity noteCommentEntity = new NoteCommentEntity(noteId, userName, commentContent, replyTo, replyToUsername); + NoteCommentEntity noteCommentEntity = new NoteCommentEntity(noteId, userName, content, replyId, replyUsername); - noteCommentEntity.setReplyTo(replyTo); - NoteCommentEntity noteComment = noteService.createNoteComment(noteCommentEntity); + noteCommentEntity.setReplyId(replyId); + NoteCommentEntity noteComment = noteCommentService.createNoteComment(noteCommentEntity); //构建用户消息事件 NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND, userName); notifyEntity.setTargetIDAndType(noteId, MainType.NOTE); - notifyEntity.setContent(commentContent); - System.out.println(replyTo); + notifyEntity.setContent(content); + System.out.println(replyId); System.out.println(noteId); - if (Objects.equals(replyTo, noteId)) { // 直接回复帖子 + if (Objects.equals(replyId, noteId)) { // 直接回复帖子 notifyEntity.setAction(NotifyAction.NEW_COMMENT);// 新评论事件不面向任何其他评论 } else { notifyEntity.setAction(NotifyAction.NEW_REPLY); } - notifyEntity.setCommentID(replyTo); + notifyEntity.setCommentID(replyId); // 增加用户消息订阅事件:用户需要订阅自己发布的评论或回复的动态 List notifyActionList = new ArrayList<>(); notifyActionList.add(NotifyAction.LIKE_COMMENT); notifyActionList.add(NotifyAction.NEW_REPLY); notifySubscriptionService.setNotifySubscription(userName, notifyActionList, - replyTo, NotifySubscriptionTargetType.COMMENT); + replyId, NotifySubscriptionTargetType.COMMENT); // 产生用户消息事件 notifyService.addNotify(notifyEntity); @@ -319,15 +312,20 @@ public MsgEntity createNoteComment( public MsgEntity deleteNoteComment( @AuthUser AuthUserEntity authUser, @RequestParam String _id) { - if(!noteService.isNoteCreator(_id, authUser.getUsername())) { - if(authUser.isAdmin()) { - //TODO: Record administrator operation - } else { - return new MsgEntity<>("FAILED", "400", "删除评论失败"); - } + if(noteCommentService.isCommentCreator(_id, authUser.getUsername())) { + noteCommentService.deleteNoteComment(_id); + return new MsgEntity<>("SUCCESS", "1", "评论删除成功"); + } + NoteCommentEntity noteComment = noteCommentService.getNoteComment(_id); + if(noteService.isNoteCreator(noteComment.getNoteId(), authUser.getUsername())) { + noteCommentService.deleteNoteComment(_id); + return new MsgEntity<>("SUCCESS", "1", "帖主删除评论成功"); + } + if(authUser.isAdmin()) { + noteCommentService.deleteNoteComment(_id); + return new MsgEntity<>("SUCCESS", "1", "管理员删除评论成功"); } - noteService.deleteNoteComment(_id); - return new MsgEntity<>("SUCCESS", "1", "评论删除成功"); + return new MsgEntity<>("FAILED", "400", "删除评论失败"); } // 收藏功能 diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCollectionDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCollectionDao.java index 35de7a6..e250447 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCollectionDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCollectionDao.java @@ -1,7 +1,6 @@ package com.oriole.ocean.dao; import com.oriole.ocean.common.po.mongo.FavorEntity; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java index 65f6189..5055fb1 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java @@ -1,51 +1,20 @@ package com.oriole.ocean.dao; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; -import org.springframework.stereotype.Repository; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; +import org.apache.ibatis.annotations.Mapper; import java.util.List; -@Repository -public class NoteCommentDao { - @Autowired - private MongoTemplate mongoTemplate; - - public void addNoteComment(NoteCommentEntity noteComment) { - mongoTemplate.save(noteComment, "note_comments"); - } - - public List getNoteCommentsByNoteId(String noteId, int pageNo, int pageSize) { - Pageable pageable = PageRequest.of(pageNo - 1, pageSize); - - // 创建查询条件,同时支持String和Long类型的noteId(为了兼容旧数据) - Criteria criteria = new Criteria().orOperator( - Criteria.where("noteId").is(noteId), - Criteria.where("noteId").is(Long.parseLong(noteId)) - ); - - Query query = new Query(criteria); - query.with(pageable); - - return mongoTemplate.find(query, NoteCommentEntity.class, "note_comments"); - } - - public boolean deleteNoteComment(String commentId) { - try { - Query query = new Query(Criteria.where("_id").is(commentId)); - mongoTemplate.remove(query, NoteCommentEntity.class, "note_comments"); - return true; - } catch (Exception e) { - return false; - } - } - - public NoteCommentEntity getNoteComment(String noteId) { - return mongoTemplate.findById(noteId, NoteCommentEntity.class, "note_comments"); - } +/** + * Note data access object + * Handles database operations for note records + */ +@Mapper +public interface NoteCommentDao extends BaseMapper { + + void addNoteComment(NoteCommentEntity noteComment); + boolean deleteNoteComment(String commentId); + List getNoteCommentsByNoteIdWithLikeStatus(String noteId); + NoteCommentEntity getNoteComment(String commentId); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentLikeDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentLikeDao.java new file mode 100644 index 0000000..50ee734 --- /dev/null +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentLikeDao.java @@ -0,0 +1,45 @@ +package com.oriole.ocean.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.oriole.ocean.common.po.mysql.NoteCommentLikeEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * Note like data access object + * Handles database operations for comment like records + */ +@Mapper +public interface NoteCommentLikeDao extends BaseMapper { + + /** + * Add a like record + * @param noteCommentLikeEntity The like record to add + * @return Number of affected rows + */ + int addNoteCommentLike(NoteCommentLikeEntity noteCommentLikeEntity); + + /** + * Remove a like record + * @param username The username who likes the comment + * @param commentId The ID of the comment + * @return Number of affected rows + */ + int removeNoteCommentLike(@Param("username") String username, @Param("commentId") String commentId); + + /** + * Check if a user has liked a specific comment + * @param username The username to check + * @param commentId The ID of the comment + * @return The like record if exists, null otherwise + */ + NoteCommentLikeEntity findNoteCommentLike(@Param("username") String username, @Param("commentId") String commentId); + + /** + * Check if a user has liked a specific comment (returns boolean) + * @param username The username to check + * @param commentId The ID of the comment + * @return true if liked, false otherwise + */ + boolean hasUserLikedNoteComment(@Param("username") String username, @Param("commentId") String commentId); +} \ No newline at end of file diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java index 75fac39..2b32891 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java @@ -1,13 +1,11 @@ package com.oriole.ocean.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteEntity; -import com.oriole.ocean.common.po.mysql.UserNotifyEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import java.util.Date; import java.util.List; /** diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java new file mode 100644 index 0000000..06aafaa --- /dev/null +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java @@ -0,0 +1,131 @@ +package com.oriole.ocean.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentLikeEntity; +import com.oriole.ocean.common.service.NoteCommentService; +import com.oriole.ocean.dao.*; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +/** + * Note service implementation + * Implements business logic for note operations including like functionality + */ +@Service +@Transactional +public class NoteCommentServiceImpl extends ServiceImpl implements NoteCommentService { + + @Resource + private NoteCommentDao noteCommentDao; + + @Resource + private NoteCommentLikeDao noteCommentLikeDao; + + /** + * Check if user is the creator of a comment + * @param commentId Comment ID + * @param username Username to check + * @return true if user is creator, false otherwise + */ + public boolean isCommentCreator(String commentId, String username) { + NoteCommentEntity comment = noteCommentDao.getNoteComment(commentId); + return comment != null && comment.getBuildUsername().equals(username); + } + + /** + * Create a new note comment + * @param noteCommentEntity Note comment entity to create + * @return Created note comment entity + */ + public NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity) { + noteCommentEntity.setLikeNum(0); + noteCommentEntity.setBuildDate(new Date()); + + noteCommentDao.addNoteComment(noteCommentEntity); + + return noteCommentEntity; + } + + /** + * Get note comments by note ID + * @param noteId Note ID + * @return List of note comments + */ + public List getNoteCommentsByNoteIdWithLikeStatus(String noteId) { + return noteCommentDao.getNoteCommentsByNoteIdWithLikeStatus(noteId); + } + + /** + * Get note comments by comment ID + * @param commentId comment ID + * @return note comment + */ + public NoteCommentEntity getNoteComment(String commentId) { + return noteCommentDao.getNoteComment(commentId); + } + + /** + * Delete a note comment + * @param commentId Comment ID + */ + public void deleteNoteComment(String commentId) { + noteCommentDao.deleteNoteComment(commentId); + } + + + // === Like functionality implementation === + + /** + * Like or unlike a note + * @param username Username who likes/unlikes + * @param commentId Note ID to like/unlike + * @param isLike true to like, false to unlike + * @return NoteLikeEntity if liked, null if unliked + */ + @Override + public NoteCommentLikeEntity likeNoteComment(String username, String commentId, boolean isLike) { + if (isLike) { + // Check if already liked + NoteCommentLikeEntity existingLike = noteCommentLikeDao.findNoteCommentLike(username, commentId); + if (existingLike != null) { + return existingLike; // Already liked, return existing record + } + + // Create new like record + NoteCommentLikeEntity noteCommentLikeEntity = new NoteCommentLikeEntity(username, commentId); + noteCommentLikeDao.addNoteCommentLike(noteCommentLikeEntity); + return null; + } else { + // Remove like record + noteCommentLikeDao.removeNoteCommentLike(username, commentId); + return null; + } + } + + /** + * Check if a user has liked a specific note + * @param username Username to check + * @param commentId Note ID to check + * @return true if liked, false otherwise + */ + @Override + public boolean hasUserLikedNoteComment(String username, String commentId) { + return noteCommentLikeDao.hasUserLikedNoteComment(username, commentId); + } + + /** + * Get like record for a user and note + * @param username Username + * @param commentId Note ID + * @return NoteLikeEntity if exists, null otherwise + */ + @Override + public NoteCommentLikeEntity getNoteCommentLike(String username, String commentId) { + return noteCommentLikeDao.findNoteCommentLike(username, commentId); + } +} \ No newline at end of file diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java index 4d15376..e1560f7 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java @@ -2,22 +2,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.oriole.ocean.common.po.mongo.FavorEntity; -import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteLikeEntity; import com.oriole.ocean.common.service.NoteService; import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.dao.NoteCollectionDao; -import com.oriole.ocean.dao.NoteCommentDao; import com.oriole.ocean.dao.NoteDao; import com.oriole.ocean.dao.NoteLikeDao; import com.oriole.ocean.common.po.mysql.NoteEntity; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -37,16 +29,10 @@ public class NoteServiceImpl extends ServiceImpl implements @Resource private NoteCollectionDao noteCollectionDao; - - @Resource - private NoteCommentDao noteCommentDao; @Resource private NoteLikeDao noteLikeDao; - @Resource - private NotifyService notifyService; - /** * Check if user is the creator of a note * @param noteId Note ID @@ -193,50 +179,6 @@ public NoteEntity createNote(NoteEntity noteEntity){ return noteEntity; } - /** - * Create a new note comment - * @param noteCommentEntity Note comment entity to create - * @return Created note comment entity - */ - public NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity) { - noteCommentEntity.setLikeNum(0); - noteCommentEntity.setCreateTime(new Date()); - - noteCommentDao.addNoteComment(noteCommentEntity); - - return noteCommentEntity; - } - - /** - * Get note comments by note ID - * @param noteId Note ID - * @param pageNo Page number - * @param pageSize Page size - * @return List of note comments - */ - public List getNoteCommentsByNoteId(String noteId, int pageNo, int pageSize) { - return noteCommentDao.getNoteCommentsByNoteId(noteId, pageNo, pageSize); - } - - /** - * Check if user is the creator of a comment - * @param commentId Comment ID - * @param username Username to check - * @return true if user is creator, false otherwise - */ - public boolean isCommentCreator(String commentId, String username) { - NoteCommentEntity comment = noteCommentDao.getNoteComment(commentId); - return comment != null && comment.getNoteCommentBuildUsername().equals(username); - } - - /** - * Delete a note comment - * @param commentId Comment ID - */ - public void deleteNoteComment(String commentId) { - noteCommentDao.deleteNoteComment(commentId); - } - /** * Get user behavior (favorites) for a specific note * @param username Username diff --git a/ocean-note-service/src/main/resources/mapper/NoteCommentLikeMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteCommentLikeMapper.xml new file mode 100644 index 0000000..d46dcf0 --- /dev/null +++ b/ocean-note-service/src/main/resources/mapper/NoteCommentLikeMapper.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + INSERT INTO note_comment_like (id, username, comment_id, like_time) + VALUES (#{id}, #{username}, #{commentId}, #{likeTime}) + + + + + DELETE FROM note_comment_like + WHERE username = #{username} AND comment_id = #{commentId} + + + + + + + + + \ No newline at end of file diff --git a/ocean-note-service/src/main/resources/mapper/NoteCommentMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteCommentMapper.xml new file mode 100644 index 0000000..df07bc4 --- /dev/null +++ b/ocean-note-service/src/main/resources/mapper/NoteCommentMapper.xml @@ -0,0 +1,34 @@ + + + + + + INSERT INTO note_comment + (id, note_id, build_username, like_num, build_date, + reply_id. reply_username, content, is_deleted) + VALUES (#{id}, #{noteId}, #{buildUsername}, 0, + #{build_date}, #{replyId}, #{replyUsername}, #{content}, 0) + + + + UPDATE note_comment + SET is_deleted = 1 + WHERE id = #{commentId} + + + + + + \ No newline at end of file diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java index 2f16033..3073d86 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java @@ -6,21 +6,14 @@ import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; import com.oriole.ocean.common.po.mongo.comment.CommentEntity; import com.oriole.ocean.common.po.mongo.comment.CommentReplyEntity; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; -import com.oriole.ocean.common.po.mysql.NoteEntity; -import com.oriole.ocean.common.po.mysql.NotifySubscriptionEntity; -import com.oriole.ocean.common.po.mysql.UserNotifyEntity; import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.dao.NotifyDao; import com.oriole.ocean.common.po.mysql.NotifyEntity; import org.apache.dubbo.config.annotation.DubboService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.Arrays; import java.util.Date; import java.util.List; -import java.util.Objects; @Service @DubboService From 578dfb3fdc64bcabc66e492bd6840d9337c0a29f Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sat, 21 Jun 2025 22:46:07 +0800 Subject: [PATCH 49/62] feat: add comment like controller --- .../ocean/controller/NoteController.java | 72 ++++++++++++++----- 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index 401b94a..e875b71 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -8,10 +8,7 @@ import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; import com.oriole.ocean.common.enumerate.NotifyType; import com.oriole.ocean.common.po.mongo.FavorEntity; -import com.oriole.ocean.common.po.mysql.NoteCommentEntity; -import com.oriole.ocean.common.po.mysql.NoteEntity; -import com.oriole.ocean.common.po.mysql.NoteLikeEntity; -import com.oriole.ocean.common.po.mysql.NotifyEntity; +import com.oriole.ocean.common.po.mysql.*; import com.oriole.ocean.common.service.*; import com.oriole.ocean.common.vo.AuthUserEntity; import com.oriole.ocean.common.vo.MsgEntity; @@ -204,7 +201,7 @@ public MsgEntity> getNoteByTag( } // === Like functionality APIs === - + /** * Like or unlike a note * @param authUser Authenticated user @@ -217,18 +214,18 @@ public MsgEntity likeNote( @AuthUser AuthUserEntity authUser, @RequestParam String noteId, @RequestParam Boolean isLike) { - + String username = authUser.getUsername(); - - NoteLikeEntity result = noteService.likeNote(username, noteId, isLike); - - if (isLike) { - return new MsgEntity<>("SUCCESS", "1", result); - } else { - return new MsgEntity<>("SUCCESS", "1", null); - } + + NoteLikeEntity result = noteService.likeNote(username, noteId, isLike); + + if (isLike) { + return new MsgEntity<>("SUCCESS", "1", result); + } else { + return new MsgEntity<>("SUCCESS", "1", null); + } } - + /** * Check if current user has liked a specific note * @param authUser Authenticated user @@ -239,10 +236,51 @@ public MsgEntity likeNote( public MsgEntity checkNoteLikeStatus( @AuthUser AuthUserEntity authUser, @RequestParam String noteId) { - + String username = authUser.getUsername(); boolean hasLiked = noteService.hasUserLikedNote(username, noteId); - + + return new MsgEntity<>("SUCCESS", "1", hasLiked); + } + + /** + * Like or unlike a comment + * @param authUser Authenticated user + * @param commentId Comment ID to like/unlike + * @param isLike true to like, false to unlike + * @return Success message with like status + */ + @RequestMapping(value = "/likeNoteComment", method = RequestMethod.POST) + public MsgEntity likeNoteComment( + @AuthUser AuthUserEntity authUser, + @RequestParam String commentId, + @RequestParam Boolean isLike) { + + String username = authUser.getUsername(); + + NoteCommentLikeEntity result = noteCommentService.likeNoteComment(username, commentId, isLike); + + if (isLike) { + return new MsgEntity<>("SUCCESS", "1", result); + } else { + return new MsgEntity<>("SUCCESS", "1", null); + } + } + + /** + * Check if the current user has liked a specific comment + * @param authUser Authenticated user + * @param commentId Comment ID to check + * @return Like status + */ + @RequestMapping(value = "/checkNoteCommentLikeStatus", method = RequestMethod.POST) + public MsgEntity checkNoteCommentLikeStatus( + @AuthUser AuthUserEntity authUser, + @RequestParam String commentId) { + + String username = authUser.getUsername(); + boolean hasLiked = noteCommentService.hasUserLikedNoteComment(username, commentId); + return new MsgEntity<>("SUCCESS", "1", hasLiked); } From 6b1c9ab8b387a6ea2979d707c88e187ea4c356e5 Mon Sep 17 00:00:00 2001 From: cms42 Date: Sat, 21 Jun 2025 13:51:18 +0800 Subject: [PATCH 50/62] feat: implement user info update validation --- ocean-user-service/pom.xml | 6 + .../ocean/ControllerExceptionHandler.java | 46 ++++++ .../ocean/controller/UserInfoController.java | 50 +++++- .../oriole/ocean/dto/UserInfoUpdateDTO.java | 26 +++ .../com/oriole/ocean/util/ValidationUtil.java | 119 ++++++++++++++ .../ocean/validation/ValidationTest.java | 154 ++++++++++++++++++ 6 files changed, 399 insertions(+), 2 deletions(-) create mode 100644 ocean-user-service/src/main/java/com/oriole/ocean/util/ValidationUtil.java create mode 100644 ocean-user-service/src/test/java/com/oriole/ocean/validation/ValidationTest.java diff --git a/ocean-user-service/pom.xml b/ocean-user-service/pom.xml index b859331..14260bb 100644 --- a/ocean-user-service/pom.xml +++ b/ocean-user-service/pom.xml @@ -60,6 +60,12 @@ springfox-swagger-ui
+ + + org.springframework.boot + spring-boot-starter-validation + + diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/ControllerExceptionHandler.java b/ocean-user-service/src/main/java/com/oriole/ocean/ControllerExceptionHandler.java index 0a1cd06..7e178ad 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/ControllerExceptionHandler.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/ControllerExceptionHandler.java @@ -5,11 +5,16 @@ import com.oriole.ocean.common.vo.OceanExceptionHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import java.util.stream.Collectors; + @Slf4j @ControllerAdvice @ResponseBody @@ -20,6 +25,47 @@ public MsgEntity businessExceptionHandler(Busine return super.businessExceptionHandler(ex); } + /** + * Handle validation errors from @Valid annotation on request body + */ + @ExceptionHandler(MethodArgumentNotValidException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public MsgEntity handleValidationException(MethodArgumentNotValidException ex) { + String errorMessage = ex.getBindingResult() + .getFieldErrors() + .stream() + .map(error -> error.getDefaultMessage()) + .collect(Collectors.joining("; ")); + + log.warn("Validation error: {}", errorMessage); + ErrorMsg errorMsg = new ErrorMsg( + "VALIDATION_ERROR", + "handleValidationException", + "ControllerExceptionHandler", + "数据验证失败: " + errorMessage); + return new MsgEntity<>("VALIDATION_ERROR", "-8", errorMsg); + } + + /** + * Handle validation errors from @Validated annotation on method parameters + */ + @ExceptionHandler(ConstraintViolationException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public MsgEntity handleConstraintViolationException(ConstraintViolationException ex) { + String errorMessage = ex.getConstraintViolations() + .stream() + .map(ConstraintViolation::getMessage) + .collect(Collectors.joining("; ")); + + log.warn("Constraint violation: {}", errorMessage); + ErrorMsg errorMsg = new ErrorMsg( + "CONSTRAINT_VIOLATION", + "handleConstraintViolationException", + "ControllerExceptionHandler", + "参数验证失败: " + errorMessage); + return new MsgEntity<>("VALIDATION_ERROR", "-9", errorMsg); + } + @ExceptionHandler(Exception.class) @ResponseStatus(value= HttpStatus.INTERNAL_SERVER_ERROR) @Override diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java index 05be2bd..8866424 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/controller/UserInfoController.java @@ -9,10 +9,13 @@ import com.oriole.ocean.dto.UserInfoUpdateDTO; import com.oriole.ocean.service.UserInfoServiceImpl; import com.oriole.ocean.service.base.UserBaseInfoServiceImpl; +import com.oriole.ocean.util.ValidationUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.validation.Valid; + @RestController @Slf4j @RequestMapping("/userInfoService") @@ -53,12 +56,16 @@ public MsgEntity getUserAllInfo(@AuthUser AuthUserEntity authUser) { @PostMapping("/updateUserInfo") /** * Update user personal information. Only non-null fields will be updated. + * Includes comprehensive validation for security and data integrity. * @param authUser Authenticated user (from token) - * @param updateDTO Fields to update + * @param updateDTO Fields to update (validated) * @return Success message or error */ - public MsgEntity updateUserInfo(@AuthUser AuthUserEntity authUser, @RequestBody UserInfoUpdateDTO updateDTO) { + public MsgEntity updateUserInfo(@AuthUser AuthUserEntity authUser, @Valid @RequestBody UserInfoUpdateDTO updateDTO) { try { + // Additional security validation beyond annotation validation + validateSecurityConstraints(updateDTO); + userInfoService.updateUserInfo(authUser.getUsername(), updateDTO); return new MsgEntity<>("SUCCESS", "1", "User info updated successfully"); } catch (Exception e) { @@ -66,4 +73,43 @@ public MsgEntity updateUserInfo(@AuthUser AuthUserEntity authUser, @Requ throw new BusinessException("-1", "Failed to update user info: " + e.getMessage()); } } + + /** + * Validates security constraints for all string fields in the DTO + * Checks for HTML tags, SQL injection, and XSS attempts + * + * @param updateDTO DTO to validate + * @throws BusinessException if validation fails + */ + private void validateSecurityConstraints(UserInfoUpdateDTO updateDTO) { + // Validate all string fields for security threats + if (!ValidationUtil.isSafeInput(updateDTO.getNickname())) { + throw new BusinessException("-5", "昵称包含不允许的字符或标签"); + } + if (!ValidationUtil.isSafeInput(updateDTO.getRealname())) { + throw new BusinessException("-5", "真实姓名包含不允许的字符或标签"); + } + if (!ValidationUtil.isSafeInput(updateDTO.getAvatar())) { + throw new BusinessException("-5", "头像URL包含不允许的字符或标签"); + } + if (!ValidationUtil.isSafeInput(updateDTO.getCollege())) { + throw new BusinessException("-5", "学院名称包含不允许的字符或标签"); + } + if (!ValidationUtil.isSafeInput(updateDTO.getMajor())) { + throw new BusinessException("-5", "专业名称包含不允许的字符或标签"); + } + if (!ValidationUtil.isSafeInput(updateDTO.getPersonalSignature())) { + throw new BusinessException("-5", "个人签名包含不允许的字符或标签"); + } + + // Additional email validation (beyond annotation) + if (!ValidationUtil.isValidEmail(updateDTO.getEmail())) { + throw new BusinessException("-6", "邮箱格式不正确"); + } + + // Additional phone validation (beyond annotation) + if (!ValidationUtil.isValidPhoneNumber(updateDTO.getPhoneNum())) { + throw new BusinessException("-7", "手机号格式不正确"); + } + } } diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/dto/UserInfoUpdateDTO.java b/ocean-user-service/src/main/java/com/oriole/ocean/dto/UserInfoUpdateDTO.java index 24badc9..a07b7f0 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/dto/UserInfoUpdateDTO.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/dto/UserInfoUpdateDTO.java @@ -1,6 +1,7 @@ package com.oriole.ocean.dto; import lombok.Data; +import javax.validation.constraints.*; import java.io.Serializable; import java.util.Date; @@ -14,18 +15,43 @@ @Data public class UserInfoUpdateDTO implements Serializable { // User table fields + @Size(max = 50, message = "昵称长度不能超过50个字符") private String nickname; + + @Email(message = "邮箱格式不正确") + @Size(max = 100, message = "邮箱长度不能超过100个字符") private String email; + + @Pattern(regexp = "^[0-9+\\-\\s()]{10,20}$", message = "手机号格式不正确") private String phoneNum; + + @Size(max = 50, message = "真实姓名长度不能超过50个字符") private String realname; + + @Size(max = 255, message = "头像URL长度不能超过255个字符") private String avatar; + + @Min(value = 0, message = "等级不能小于0") + @Max(value = 999999, message = "等级不能大于999999") private Integer levelGrade; + + @Min(value = 1, message = "认证ID必须大于0") private Integer certID; // UserExtra table fields + @Size(max = 100, message = "学院名称长度不能超过100个字符") private String college; + + @Size(max = 100, message = "专业名称长度不能超过100个字符") private String major; + + @Past(message = "生日必须是过去的日期") private Date birthday; + + @Min(value = 0, message = "性别值不正确") + @Max(value = 2, message = "性别值不正确") private Integer sex; + + @Size(max = 500, message = "个人签名长度不能超过500个字符") private String personalSignature; } \ No newline at end of file diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/util/ValidationUtil.java b/ocean-user-service/src/main/java/com/oriole/ocean/util/ValidationUtil.java new file mode 100644 index 0000000..f64de88 --- /dev/null +++ b/ocean-user-service/src/main/java/com/oriole/ocean/util/ValidationUtil.java @@ -0,0 +1,119 @@ +package com.oriole.ocean.util; + +import java.util.regex.Pattern; + +/** + * Utility class for data validation including security checks + * + * @author Ocean Team + */ +public class ValidationUtil { + + // Regex patterns for security validation + private static final Pattern HTML_TAG_PATTERN = Pattern.compile("<[^>]*>"); + private static final Pattern EMAIL_PATTERN = Pattern.compile("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"); + private static final Pattern PHONE_PATTERN = Pattern.compile("^[0-9+\\-\\s()]{10,20}$"); + + // SQL injection patterns + private static final Pattern[] SQL_INJECTION_PATTERNS = { + Pattern.compile("(\\b(SELECT|INSERT|UPDATE|DELETE|DROP|CREATE|ALTER|EXEC|UNION|SCRIPT)\\b)", Pattern.CASE_INSENSITIVE), + Pattern.compile("(--|/\\*|\\*/|;|'|\"|`)"), + Pattern.compile("(\\bOR\\b|\\bAND\\b).*[=<>]", Pattern.CASE_INSENSITIVE) + }; + + // XSS patterns + private static final Pattern[] XSS_PATTERNS = { + Pattern.compile("javascript:", Pattern.CASE_INSENSITIVE), + Pattern.compile("on\\w+\\s*=", Pattern.CASE_INSENSITIVE), + Pattern.compile("data:text/html", Pattern.CASE_INSENSITIVE), + Pattern.compile("vbscript:", Pattern.CASE_INSENSITIVE) + }; + + /** + * Validates input for security threats (HTML tags, SQL injection, XSS) + * + * @param input Input string to validate + * @return true if input is safe, false otherwise + */ + public static boolean isSafeInput(String input) { + if (input == null || input.trim().isEmpty()) { + return true; // Allow empty values + } + + // Check for HTML tags + if (HTML_TAG_PATTERN.matcher(input).find()) { + return false; + } + + // Check for SQL injection patterns + for (Pattern pattern : SQL_INJECTION_PATTERNS) { + if (pattern.matcher(input).find()) { + return false; + } + } + + // Check for XSS patterns + for (Pattern pattern : XSS_PATTERNS) { + if (pattern.matcher(input).find()) { + return false; + } + } + + return true; + } + + /** + * Validates email format + * + * @param email Email string to validate + * @return true if valid email format, false otherwise + */ + public static boolean isValidEmail(String email) { + if (email == null || email.trim().isEmpty()) { + return true; // Allow empty email (optional field) + } + return EMAIL_PATTERN.matcher(email.trim()).matches(); + } + + /** + * Validates phone number format + * + * @param phoneNum Phone number to validate + * @return true if valid phone format, false otherwise + */ + public static boolean isValidPhoneNumber(String phoneNum) { + if (phoneNum == null || phoneNum.trim().isEmpty()) { + return true; // Allow empty phone (optional field) + } + return PHONE_PATTERN.matcher(phoneNum.trim()).matches(); + } + + /** + * Validates string length + * + * @param input String to validate + * @param maxLength Maximum allowed length + * @return true if within length limit, false otherwise + */ + public static boolean isValidLength(String input, int maxLength) { + if (input == null) { + return true; + } + return input.length() <= maxLength; + } + + /** + * Validates that integer is within specified range + * + * @param value Integer value to validate + * @param min Minimum allowed value (inclusive) + * @param max Maximum allowed value (inclusive) + * @return true if within range, false otherwise + */ + public static boolean isValidRange(Integer value, int min, int max) { + if (value == null) { + return true; + } + return value >= min && value <= max; + } +} \ No newline at end of file diff --git a/ocean-user-service/src/test/java/com/oriole/ocean/validation/ValidationTest.java b/ocean-user-service/src/test/java/com/oriole/ocean/validation/ValidationTest.java new file mode 100644 index 0000000..fc5dbce --- /dev/null +++ b/ocean-user-service/src/test/java/com/oriole/ocean/validation/ValidationTest.java @@ -0,0 +1,154 @@ +package com.oriole.ocean.validation; + +import com.oriole.ocean.dto.UserInfoUpdateDTO; +import com.oriole.ocean.util.ValidationUtil; +import junit.framework.TestCase; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import java.util.Date; +import java.util.Set; + +/** + * Test class for validation functionality + * Demonstrates various validation scenarios for UserInfoUpdateDTO + */ +public class ValidationTest extends TestCase { + + private Validator validator; + + public void setUp() { + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + validator = factory.getValidator(); + } + + public void testValidUserInfoUpdateDTO() { + UserInfoUpdateDTO dto = new UserInfoUpdateDTO(); + dto.setNickname("TestUser"); + dto.setEmail("test@example.com"); + dto.setPhoneNum("1234567890"); + dto.setRealname("Test User"); + dto.setLevelGrade(100); + dto.setCollege("Computer Science"); + dto.setMajor("Software Engineering"); + dto.setBirthday(new Date(System.currentTimeMillis() - 86400000L)); // Yesterday + dto.setSex(1); + dto.setPersonalSignature("Hello World"); + + Set> violations = validator.validate(dto); + assertTrue("Valid DTO should have no violations", violations.isEmpty()); + } + + public void testInvalidEmail() { + UserInfoUpdateDTO dto = new UserInfoUpdateDTO(); + dto.setEmail("invalid-email"); + + Set> violations = validator.validate(dto); + assertFalse("Invalid email should cause violations", violations.isEmpty()); + assertTrue("Should contain email validation error", + violations.stream().anyMatch(v -> v.getMessage().contains("邮箱格式不正确"))); + } + + public void testInvalidPhoneNumber() { + UserInfoUpdateDTO dto = new UserInfoUpdateDTO(); + dto.setPhoneNum("abc"); + + Set> violations = validator.validate(dto); + assertFalse("Invalid phone should cause violations", violations.isEmpty()); + assertTrue("Should contain phone validation error", + violations.stream().anyMatch(v -> v.getMessage().contains("手机号格式不正确"))); + } + + public void testMaxLengthViolation() { + UserInfoUpdateDTO dto = new UserInfoUpdateDTO(); + // Create a string longer than 50 characters + StringBuilder longNickname = new StringBuilder(); + for (int i = 0; i < 51; i++) { + longNickname.append("a"); + } + dto.setNickname(longNickname.toString()); + + Set> violations = validator.validate(dto); + assertFalse("Long nickname should cause violations", violations.isEmpty()); + assertTrue("Should contain length validation error", + violations.stream().anyMatch(v -> v.getMessage().contains("昵称长度不能超过50个字符"))); + } + + public void testFutureDateValidation() { + UserInfoUpdateDTO dto = new UserInfoUpdateDTO(); + dto.setBirthday(new Date(System.currentTimeMillis() + 86400000L)); // Tomorrow + + Set> violations = validator.validate(dto); + assertFalse("Future birthday should cause violations", violations.isEmpty()); + assertTrue("Should contain past date validation error", + violations.stream().anyMatch(v -> v.getMessage().contains("生日必须是过去的日期"))); + } + + public void testInvalidSexValue() { + UserInfoUpdateDTO dto = new UserInfoUpdateDTO(); + dto.setSex(5); // Invalid value (should be 0-2) + + Set> violations = validator.validate(dto); + assertFalse("Invalid sex value should cause violations", violations.isEmpty()); + assertTrue("Should contain sex validation error", + violations.stream().anyMatch(v -> v.getMessage().contains("性别值不正确"))); + } + + // Security validation tests using ValidationUtil + + public void testSafeInputValidation() { + assertTrue("Normal text should be safe", ValidationUtil.isSafeInput("Normal text")); + assertTrue("Empty string should be safe", ValidationUtil.isSafeInput("")); + assertTrue("Null should be safe", ValidationUtil.isSafeInput(null)); + } + + public void testHtmlTagDetection() { + assertFalse("HTML tags should be detected", ValidationUtil.isSafeInput("")); + assertFalse("HTML tags should be detected", ValidationUtil.isSafeInput("Hello world")); + assertFalse("HTML tags should be detected", ValidationUtil.isSafeInput("
content
")); + } + + public void testSqlInjectionDetection() { + assertFalse("SQL injection should be detected", ValidationUtil.isSafeInput("'; DROP TABLE users; --")); + assertFalse("SQL injection should be detected", ValidationUtil.isSafeInput("1' OR '1'='1")); + assertFalse("SQL injection should be detected", ValidationUtil.isSafeInput("SELECT * FROM users")); + assertFalse("SQL injection should be detected", ValidationUtil.isSafeInput("admin'--")); + } + + public void testXssDetection() { + assertFalse("XSS should be detected", ValidationUtil.isSafeInput("javascript:alert('xss')")); + assertFalse("XSS should be detected", ValidationUtil.isSafeInput("onclick=alert('xss')")); + assertFalse("XSS should be detected", ValidationUtil.isSafeInput("data:text/html,")); + assertFalse("XSS should be detected", ValidationUtil.isSafeInput("vbscript:msgbox('xss')")); + } + + public void testEmailValidation() { + assertTrue("Valid email should pass", ValidationUtil.isValidEmail("test@example.com")); + assertTrue("Valid email should pass", ValidationUtil.isValidEmail("user.name@domain.co.uk")); + assertTrue("Empty email should pass", ValidationUtil.isValidEmail("")); + assertTrue("Null email should pass", ValidationUtil.isValidEmail(null)); + + assertFalse("Invalid email should fail", ValidationUtil.isValidEmail("invalid-email")); + assertFalse("Invalid email should fail", ValidationUtil.isValidEmail("@domain.com")); + assertFalse("Invalid email should fail", ValidationUtil.isValidEmail("user@")); + } + + public void testPhoneValidation() { + assertTrue("Valid phone should pass", ValidationUtil.isValidPhoneNumber("1234567890")); + assertTrue("Valid phone should pass", ValidationUtil.isValidPhoneNumber("+1-234-567-8900")); + assertTrue("Valid phone should pass", ValidationUtil.isValidPhoneNumber("(123) 456-7890")); + assertTrue("Empty phone should pass", ValidationUtil.isValidPhoneNumber("")); + assertTrue("Null phone should pass", ValidationUtil.isValidPhoneNumber(null)); + + assertFalse("Invalid phone should fail", ValidationUtil.isValidPhoneNumber("abc")); + assertFalse("Invalid phone should fail", ValidationUtil.isValidPhoneNumber("123")); + // Create a very long phone number + StringBuilder longPhone = new StringBuilder(); + for (int i = 0; i < 25; i++) { + longPhone.append("1"); + } + assertFalse("Invalid phone should fail", ValidationUtil.isValidPhoneNumber(longPhone.toString())); + } +} \ No newline at end of file From 3d53393703de4edac599ae6afd6d14835073ed86 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sat, 21 Jun 2025 15:00:42 +0800 Subject: [PATCH 51/62] feat: unlike will remove the like notification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- cascade delete trigger DELIMITER // CREATE TRIGGER trg_cleanup_user_notify BEFORE DELETE ON notify FOR EACH ROW BEGIN DELETE FROM user_notify WHERE user_notify.notify_id = OLD.id; END// DELIMITER ; -- delete function DELIMITER // CREATE PROCEDURE sp_safe_delete_notify( IN p_target_id VARCHAR(255), IN p_target_type VARCHAR(255), IN p_comment_id VARCHAR(255), IN p_action VARCHAR(255), IN p_build_username VARCHAR(255) ) BEGIN DECLARE v_id INT; -- 声明变量存储查询到的 id START TRANSACTION; -- 开启事务 SELECT id -- 查询符合条件的 id(最多 1 个) INTO v_id FROM notify WHERE target_id = p_target_id AND target_type = p_target_type AND comment_id = p_comment_id AND action = p_action AND build_username = p_build_username LIMIT 1; -- 如果找到记录,则删除 IF v_id IS NOT NULL THEN DELETE FROM notify WHERE id = v_id; END IF; COMMIT; -- 提交事务 END // DELIMITER ; --- .../controller/UserCommentController.java | 18 ++---- .../ocean/common/service/NotifyService.java | 9 +++ .../oriole/ocean/service/NoteServiceImpl.java | 4 ++ .../java/com/oriole/ocean/dao/NotifyDao.java | 1 + .../ocean/service/NotifyServiceImpl.java | 55 +++++++++++++++++-- .../src/main/resources/mapper/Notify.xml | 11 ++++ .../service/UserBehaviorServiceImpl.java | 3 +- 7 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 ocean-notify-service/src/main/resources/mapper/Notify.xml diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index 7b37184..1579202 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -116,16 +116,12 @@ public MsgEntity addComment(@AuthUser AuthUserEntity authUser, String cid = RandomStringUtils.randomAlphanumeric(8).toUpperCase(); AbstractComment returnEntity; //构建用户消息事件 - NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND,authUser.getUsername()); - notifyEntity.setTargetIDAndType(String.valueOf(bindID),mainType); - notifyEntity.setContent(commentContent); if (!isReply) { CommentEntity commentEntity = new CommentEntity(cid, authUser.getUsername(), commentContent); - commentService.addComment(bindID, mainType, commentEntity); commentEntity.setBuildDate(handleTime(commentEntity.getBuildDate())); + commentService.addComment(bindID, mainType, commentEntity); + notifyService.addNotifyByComment(bindID, mainType, commentEntity); returnEntity = commentEntity; - notifyEntity.setAction(NotifyAction.NEW_COMMENT);// 新评论事件不面向任何其他评论 - notifyEntity.setCommentID(String.valueOf(bindID)); } else { CommentReplyEntity fileCommentReplyEntity = new CommentReplyEntity( replyInCommentID + "_" + cid, authUser.getUsername(), @@ -134,13 +130,12 @@ public MsgEntity addComment(@AuthUser AuthUserEntity authUser, commentContent); commentService.addCommentReply(bindID, mainType, replyInCommentID, fileCommentReplyEntity); fileCommentReplyEntity.setBuildDate(handleTime(fileCommentReplyEntity.getBuildDate())); - returnEntity = fileCommentReplyEntity; - notifyEntity.setAction(NotifyAction.NEW_REPLY); if(!replyToCommentReplyID.isEmpty()){ - notifyEntity.setCommentID(replyToCommentReplyID); + notifyService.addNotifyByReply(bindID, mainType, replyToCommentReplyID, fileCommentReplyEntity); }else { - notifyEntity.setCommentID(replyInCommentID); + notifyService.addNotifyByReply(bindID, mainType, replyInCommentID, fileCommentReplyEntity); } + returnEntity = fileCommentReplyEntity; } // 增加用户消息订阅事件:用户需要订阅自己发布的评论或回复的动态 List notifyActionList = new ArrayList<>(); @@ -149,9 +144,6 @@ public MsgEntity addComment(@AuthUser AuthUserEntity authUser, notifySubscriptionService.setNotifySubscription(authUser.getUsername(), notifyActionList, returnEntity.getId(), NotifySubscriptionTargetType.COMMENT); - // 产生用户消息事件 - notifyService.addNotify(notifyEntity); - if (!isReply) { // 只有评论才计入文章的评论量统计 commentService.commentStatisticsChange(bindID, "+1", mainType); diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifyService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifyService.java index 8a35f08..b144975 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifyService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NotifyService.java @@ -1,7 +1,16 @@ package com.oriole.ocean.common.service; +import com.oriole.ocean.common.enumerate.MainType; +import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; +import com.oriole.ocean.common.po.mongo.comment.CommentEntity; +import com.oriole.ocean.common.po.mongo.comment.CommentReplyEntity; import com.oriole.ocean.common.po.mysql.NotifyEntity; public interface NotifyService { void addNotify(NotifyEntity notifyEntity); + void addNotifyByComment(Integer bindID, MainType mainType, + CommentEntity fileCommentEntity); + void addNotifyByReply(Integer bindID, MainType mainType, + String replyInCommentID, CommentReplyEntity fileCommentReplyEntity); + void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java index d70da47..84352c1 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java @@ -6,6 +6,7 @@ import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteLikeEntity; import com.oriole.ocean.common.service.NoteService; +import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.dao.NoteCollectionDao; import com.oriole.ocean.dao.NoteCommentDao; import com.oriole.ocean.dao.NoteDao; @@ -43,6 +44,9 @@ public class NoteServiceImpl extends ServiceImpl implements @Resource private NoteLikeDao noteLikeDao; + @Resource + private NotifyService notifyService; + /** * Check if user is the creator of a note * @param noteId Note ID diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/dao/NotifyDao.java b/ocean-notify-service/src/main/java/com/oriole/ocean/dao/NotifyDao.java index df9b6b3..1c6e18e 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/dao/NotifyDao.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/dao/NotifyDao.java @@ -4,4 +4,5 @@ import com.oriole.ocean.common.po.mysql.NotifyEntity; public interface NotifyDao extends BaseMapper { + void removeNotify(NotifyEntity notifyEntity); } diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java index 10df130..2f16033 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java @@ -2,11 +2,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oriole.ocean.common.enumerate.BehaviorExtraInfo; -import com.oriole.ocean.common.enumerate.NotifyAction; -import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; -import com.oriole.ocean.common.enumerate.NotifyType; +import com.oriole.ocean.common.enumerate.*; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; +import com.oriole.ocean.common.po.mongo.comment.CommentEntity; +import com.oriole.ocean.common.po.mongo.comment.CommentReplyEntity; +import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteEntity; import com.oriole.ocean.common.po.mysql.NotifySubscriptionEntity; import com.oriole.ocean.common.po.mysql.UserNotifyEntity; import com.oriole.ocean.common.service.NotifyService; @@ -19,6 +20,7 @@ import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.Objects; @Service @DubboService @@ -28,18 +30,53 @@ public void addNotify(NotifyEntity notifyEntity){ save(notifyEntity); } + public void addNotifyByComment(Integer bindID, MainType mainType, + CommentEntity fileCommentEntity){ + NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND, fileCommentEntity.getCommentBuildUsername()); + notifyEntity.setTargetID(bindID.toString()); + notifyEntity.setTargetType(mainType); + notifyEntity.setContent(fileCommentEntity.getCommentContent()); + notifyEntity.setAction(NotifyAction.NEW_COMMENT); + addNotify(notifyEntity); + } + + public void addNotifyByReply(Integer bindID, MainType mainType, + String replyInCommentID, CommentReplyEntity fileCommentReplyEntity){ + NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND, fileCommentReplyEntity.getReplyBuildUsername()); + notifyEntity.setTargetID(bindID.toString()); + notifyEntity.setTargetType(mainType); + notifyEntity.setCommentID(replyInCommentID); + notifyEntity.setContent(fileCommentReplyEntity.getCommentContent()); + notifyEntity.setAction(NotifyAction.NEW_REPLY); + addNotify(notifyEntity); + } + // 根据用户行为生产消息 public void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity) { // 收藏、每日签到、阅读等行为都不需要记录为通知行为 + boolean add_or_remove = true; NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND,userBehaviorEntity.getDoUsername()); switch (userBehaviorEntity.getBehaviorType()) { case DO_DOWNLOAD: notifyEntity.setAction(NotifyAction.DOWNLOAD); break; case DO_LIKE: + add_or_remove = true; + notifyEntity.setAction(NotifyAction.LIKE); + notifyEntity.setContent(userBehaviorEntity.getDoUsername() + "点赞了你的帖子"); + break; + case DO_DISLIKE: + add_or_remove = false; notifyEntity.setAction(NotifyAction.LIKE); break; case DO_COMMENT_LIKE: + add_or_remove = true; + notifyEntity.setAction(NotifyAction.LIKE_COMMENT); + notifyEntity.setCommentID((String) userBehaviorEntity.getExtraInfo(BehaviorExtraInfo.COMMENT_ID)); + notifyEntity.setContent(userBehaviorEntity.getDoUsername() + "点赞了你的评论"); + break; + case DO_COMMENT_DISLIKE: + add_or_remove = false; notifyEntity.setAction(NotifyAction.LIKE_COMMENT); notifyEntity.setCommentID((String) userBehaviorEntity.getExtraInfo(BehaviorExtraInfo.COMMENT_ID)); break; @@ -48,7 +85,15 @@ public void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity) { } notifyEntity.setUserBehaviorID(userBehaviorEntity.getId()); notifyEntity.setTargetIDAndType(String.valueOf(userBehaviorEntity.getBindID()),userBehaviorEntity.getType()); - addNotify(notifyEntity); + if(add_or_remove) + addNotify(notifyEntity); + else + removeNotify(notifyEntity); + } + + private void removeNotify(NotifyEntity notifyEntity) { + NotifyDao notifyDao = getBaseMapper(); + notifyDao.removeNotify(notifyEntity); } // 查询指定时间之后产生的所有消息 diff --git a/ocean-notify-service/src/main/resources/mapper/Notify.xml b/ocean-notify-service/src/main/resources/mapper/Notify.xml new file mode 100644 index 0000000..f91e442 --- /dev/null +++ b/ocean-notify-service/src/main/resources/mapper/Notify.xml @@ -0,0 +1,11 @@ + + + + + CALL sp_safe_delete_notify( + #{targetId}, #{targetType}, + #{commentId}, #{action}, + #{buildUsername}); + + \ No newline at end of file diff --git a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java index c1dacf1..0cfd273 100644 --- a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java +++ b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java @@ -5,6 +5,7 @@ import com.oriole.ocean.common.enumerate.BehaviorType; import com.oriole.ocean.common.enumerate.EvaluateType; import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; +import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.common.service.UserBehaviorService; import com.oriole.ocean.common.vo.BusinessException; import org.apache.dubbo.config.annotation.DubboService; @@ -31,7 +32,7 @@ public class UserBehaviorServiceImpl implements UserBehaviorService { private MongoTemplate mongoTemplate; @Autowired - private NotifyServiceImpl notifyService; + private NotifyService notifyService; // 检查某用户针对特定对象(某文档/某便签等)的评价行为,并得出此次评价所需发生的全部评价行为 // 对特定对象具有评论区时,也可处理对其评论区的评价行为 From b4da2d548edf50cbe85717b4c51d8bfa11ca5026 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sat, 21 Jun 2025 16:51:15 +0800 Subject: [PATCH 52/62] feat: new handler '/getMyNotes' online untested --- .../ocean/common/service/NoteService.java | 7 +++++ .../ocean/controller/NoteController.java | 15 ++++++++++ .../java/com/oriole/ocean/dao/NoteDao.java | 9 +++++- .../oriole/ocean/service/NoteServiceImpl.java | 9 ++++++ .../src/main/resources/mapper/NoteMapper.xml | 28 +++++++++++++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java index 2c98191..d3871cb 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java @@ -89,6 +89,13 @@ public interface NoteService { */ List getLatestNotesWithLikeStatus(String username); + /** + * Get notes by creator name + * @param username Current user's name + * @return list of notes created by that user + */ + List getNotesByUsernameWithLikeStatus(String username); + /** * Get notes by keywords * @param searchString Search keywords diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index d7b3b6a..8a451d9 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -101,6 +101,21 @@ public MsgEntity> getNotesByKeywords( return new MsgEntity<>("SUCCESS","1",pageInfo); } + /** + * Select notes by creator name with pagination + * Returns notes with like status for authenticated user + */ + @RequestMapping(value = "/getMyNotes", method = RequestMethod.POST) + public MsgEntity> getMyNotes( + @AuthUser AuthUserEntity authUser, + @RequestParam int pageNO, + @RequestParam int pageSize) { + PageHelper.startPage(pageNO, pageSize, true); + List noteEntityList = noteService.getNotesByUsernameWithLikeStatus(authUser.getUsername()); + PageInfo pageInfo = new PageInfo<>(noteEntityList); + return new MsgEntity<>("SUCCESS","1",pageInfo); + } + /** * Get note by ID * Returns note with like status for authenticated user diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java index b5476aa..4536b4e 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java @@ -66,7 +66,14 @@ List getNotesByKeywordsWithLikeStatus(@Param("searchString") String */ List getNotesByTagWithLikeStatus(@Param("tag") String tag, @Param("username") String username); - + + /** + * Get notes by creator name + * @param username Current user's name + * @return list of notes created by that user + */ + List getNotesByMyNameWithLikeStatus(@Param("username") String username); + /** * Get note by ID * @param noteId Note ID diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java index 84352c1..100171c 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java @@ -129,6 +129,15 @@ public List getLatestNotesWithLikeStatus(String username) { return noteDao.getLatestNotesWithLikeStatus(username); } + /** + * Get notes by creator name + * @param username Current user's name + * @return list of notes created by that user + */ + public List getNotesByUsernameWithLikeStatus(String username) { + return noteDao.getNotesByMyNameWithLikeStatus(username); + } + /** * Get notes by keywords * @param searchString Search keywords diff --git a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml index 8b3bb6d..8c2fe0a 100644 --- a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml +++ b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml @@ -152,6 +152,34 @@ WHERE n.note_id = #{noteId} AND n.is_deleted = 0 + + UPDATE note SET is_deleted = 1 From ed1077a4852d597f1a98e77c3c2fe42b4ace2651 Mon Sep 17 00:00:00 2001 From: AInfinity-LilacDream <1977741520@qq.com> Date: Sun, 22 Jun 2025 00:31:18 +0800 Subject: [PATCH 53/62] fix: sql syntax --- ocean-note-service/src/main/resources/mapper/NoteMapper.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml index 8c2fe0a..79df120 100644 --- a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml +++ b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml @@ -152,7 +152,7 @@ WHERE n.note_id = #{noteId} AND n.is_deleted = 0 - SELECT n.note_id as id, n.build_username, @@ -177,7 +177,7 @@ ON n.note_id = nl.note_id AND nl.username = #{username} WHERE n.is_deleted = 0 AND n.build_username = #{username} - ORDER BY n.refresh_date DESC; + ORDER BY n.refresh_date DESC From d4d737a5419d31d30b2d1fc966fcb4bfd6565b11 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sat, 21 Jun 2025 22:40:09 +0800 Subject: [PATCH 54/62] feat: add comment like and move comment to MySQL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- comment table -- CREATE TABLE `note_comment` ( `id` varchar(32) NOT NULL COMMENT '主键ID', `note_id` varchar(32) NOT NULL COMMENT '笔记ID', `content` text NOT NULL COMMENT '评论内容', `build_username` varchar(255) NOT NULL COMMENT '评论用户', `like_num` int(11) DEFAULT '0' COMMENT '点赞数', `build_date` datetime NOT NULL COMMENT '创建时间', `is_deleted` tinyint(1) DEFAULT '0' COMMENT '是否删除(0:未删除,1:已删除)', `reply_id` varchar(32) DEFAULT NULL COMMENT '回复的评论ID', `reply_username` varchar(255) DEFAULT NULL COMMENT '回复的用户名', PRIMARY KEY (`id`), KEY `idx_note_id` (`note_id`), KEY `idx_build_username` (`build_username`), KEY `idx_reply_id` (`reply_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='笔记评论表'; -- like table -- CREATE TABLE `note_like` ( `id` varchar(32) NOT NULL COMMENT '主键ID', `username` varchar(255) NOT NULL COMMENT '点赞用户名', `comment_id` varchar(32) NOT NULL COMMENT '评论ID', `like_time` datetime NOT NULL COMMENT '点赞时间', PRIMARY KEY (`id`), KEY `idx_comment_id` (`comment_id`), KEY `idx_username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='笔记评论点赞表'; -- add like -- DELIMITER // CREATE TRIGGER `trg_note_like_after_insert` AFTER INSERT ON `note_like` FOR EACH ROW BEGIN UPDATE `note_comment` SET `like_num` = `like_num` + 1 WHERE `id` = NEW.`comment_id`; END// DELIMITER ; -- delete like -- DELIMITER // CREATE TRIGGER `trg_note_like_after_delete` AFTER DELETE ON `note_like` FOR EACH ROW BEGIN UPDATE `note_comment` SET `like_num` = `like_num` - 1 WHERE `id` = OLD.`comment_id`; END// DELIMITER ; --- .../po/mongo/comment/NoteCommentEntity.java | 29 ---- .../common/po/mysql/NoteCommentEntity.java | 53 +++++++ .../po/mysql/NoteCommentLikeEntity.java | 48 +++++++ .../common/service/NoteCommentService.java | 77 ++++++++++ .../ocean/common/service/NoteService.java | 24 +--- .../ocean/controller/NoteController.java | 61 ++++---- .../oriole/ocean/dao/NoteCollectionDao.java | 1 - .../com/oriole/ocean/dao/NoteCommentDao.java | 62 ++------- .../oriole/ocean/dao/NoteCommentLikeDao.java | 45 ++++++ .../java/com/oriole/ocean/dao/NoteDao.java | 4 +- .../ocean/service/NoteCommentServiceImpl.java | 131 ++++++++++++++++++ .../oriole/ocean/service/NoteServiceImpl.java | 59 +------- .../mapper/NoteCommentLikeMapper.xml | 39 ++++++ .../resources/mapper/NoteCommentMapper.xml | 34 +++++ .../ocean/service/NotifyServiceImpl.java | 7 - 15 files changed, 473 insertions(+), 201 deletions(-) delete mode 100644 ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/NoteCommentEntity.java create mode 100644 ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentEntity.java create mode 100644 ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentLikeEntity.java create mode 100644 ocean-common/src/main/java/com/oriole/ocean/common/service/NoteCommentService.java create mode 100644 ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentLikeDao.java create mode 100644 ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java create mode 100644 ocean-note-service/src/main/resources/mapper/NoteCommentLikeMapper.xml create mode 100644 ocean-note-service/src/main/resources/mapper/NoteCommentMapper.xml diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/NoteCommentEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/NoteCommentEntity.java deleted file mode 100644 index c6bd25f..0000000 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mongo/comment/NoteCommentEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.oriole.ocean.common.po.mongo.comment; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; - -import java.util.ArrayList; -import java.util.Date; - -@Data -public class NoteCommentEntity implements java.io.Serializable { - private String _id; - private String noteId; - private String noteCommentBuildUsername; - private Integer likeNum; - private Date createTime; - private String replyTo; - private String replyToUsername; - private String commentContent; - - public NoteCommentEntity(String noteId, String noteCommentBuildUsername, String commentContent, String replyTo, String replyToUsername) { - this.noteId = noteId; - this.commentContent = commentContent; - this.noteCommentBuildUsername = noteCommentBuildUsername; - this.replyTo = replyTo; - this.replyToUsername = replyToUsername; - } -} diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentEntity.java new file mode 100644 index 0000000..64f7be9 --- /dev/null +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentEntity.java @@ -0,0 +1,53 @@ +package com.oriole.ocean.common.po.mysql; + +import com.baomidou.mybatisplus.annotation.TableField; +import lombok.Data; + +import java.util.Date; + +@Data +public class NoteCommentEntity implements java.io.Serializable { + @TableField("id") + private String id; + + @TableField("note_id") + private String noteId; + + @TableField("content") + private String content; + + @TableField("build_username") + private String buildUsername; + + @TableField("like_num") + private Integer likeNum; + + @TableField("build_date") + private Date buildDate; + + @TableField("is_deleted") + private Byte isDeleted; + + @TableField("reply_id") + private String replyId; + + @TableField("reply_username") + private String replyUsername; + + /** + * Whether the current user has liked this comment. + * This field is not mapped to the database, only used for data transfer + */ + @TableField(exist = false) + private Boolean isLikedByCurrentUser; + + public NoteCommentEntity( + String noteId, String buildUsername, + String content, String replyId, String replyUsername) { + this.noteId = noteId; + this.content = content; + this.buildUsername = buildUsername; + this.replyId = replyId; + this.replyUsername = replyUsername; + } +} diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentLikeEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentLikeEntity.java new file mode 100644 index 0000000..52e51f2 --- /dev/null +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NoteCommentLikeEntity.java @@ -0,0 +1,48 @@ +package com.oriole.ocean.common.po.mysql; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +/** + * Note like record entity + * Records the like relationship between users and notes + */ +@Data +@TableName("`note_like`") +public class NoteCommentLikeEntity implements java.io.Serializable { + + @TableId(value = "id", type = IdType.ASSIGN_ID) + private String id; + + @TableField("username") + private String username; + + @TableField("comment_id") + private String commentId; + + @TableField("like_time") + private Date likeTime; + + /** + * Default constructor + */ + public NoteCommentLikeEntity() { + this.likeTime = new Date(); + } + + /** + * Constructor with username and commentId + * @param username The username who likes the comment + * @param commentId The ID of the liked comment + */ + public NoteCommentLikeEntity(String username, String commentId) { + this.username = username; + this.commentId = commentId; + this.likeTime = new Date(); + } +} diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteCommentService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteCommentService.java new file mode 100644 index 0000000..f69b680 --- /dev/null +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteCommentService.java @@ -0,0 +1,77 @@ +package com.oriole.ocean.common.service; + +import com.oriole.ocean.common.po.mongo.FavorEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentLikeEntity; +import com.oriole.ocean.common.po.mysql.NoteEntity; +import com.oriole.ocean.common.po.mysql.NoteLikeEntity; + +import java.util.List; + +/** + * Note service interface + * Provides business logic for note operations + */ +public interface NoteCommentService { + + /** + * Check if user is the creator of a comment + * @param commentId Comment ID + * @param username Username to check + * @return true if user is creator, false otherwise + */ + boolean isCommentCreator(String commentId, String username); + + /** + * Delete a note comment + * @param commentId Comment ID + */ + void deleteNoteComment(String commentId); + + /** + * Get note comments by note ID + * @param noteId Note ID + * @return List of note comments + */ + List getNoteCommentsByNoteIdWithLikeStatus(String noteId); + + /** + * Get note comments by comment ID + * @param commentId comment ID + * @return note comment + */ + NoteCommentEntity getNoteComment(String commentId); + + /** + * Create a new note comment + * @param noteCommentEntity Note comment entity to create + * @return Created note comment entity + */ + NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity); + + + /** + * Like or unlike a note + * @param username Username who likes/unlikes + * @param commentId Note ID to like/unlike + * @param isLike true to like, false to unlike + * @return NoteLikeEntity if liked, null if unliked + */ + NoteCommentLikeEntity likeNoteComment(String username, String commentId, boolean isLike); + + /** + * Check if a user has liked a specific note + * @param username Username to check + * @param commentId Note ID to check + * @return true if liked, false otherwise + */ + boolean hasUserLikedNoteComment(String username, String commentId); + + /** + * Get like record for a user and note + * @param username Username + * @param commentId Note ID + * @return NoteLikeEntity if exists, null otherwise + */ + NoteCommentLikeEntity getNoteCommentLike(String username, String commentId); +} diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java index d3871cb..3222c63 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java @@ -1,7 +1,7 @@ package com.oriole.ocean.common.service; import com.oriole.ocean.common.po.mongo.FavorEntity; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteEntity; import com.oriole.ocean.common.po.mysql.NoteLikeEntity; import java.util.List; @@ -53,12 +53,6 @@ public interface NoteService { */ NoteEntity getNoteByIdWithLikeStatus(String noteID, String username); - /** - * Delete a note comment - * @param commentId Comment ID - */ - void deleteNoteComment(String commentId); - /** * Get user behavior (favorites) for a specific note * @param username Username @@ -126,15 +120,6 @@ public interface NoteService { */ List getNotesByTagWithLikeStatus(String tag, String username); - /** - * Get note comments by note ID - * @param noteId Note ID - * @param pageNo Page number - * @param pageSize Page size - * @return List of note comments - */ - List getNoteCommentsByNoteId(String noteId, int pageNo, int pageSize); - /** * Create a new note * @param noteEntity Note entity to create @@ -142,13 +127,6 @@ public interface NoteService { */ NoteEntity createNote(NoteEntity noteEntity); - /** - * Create a new note comment - * @param noteCommentEntity Note comment entity to create - * @return Created note comment entity - */ - NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity); - // === Like functionality === /** diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index 8a451d9..22d0fe8 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -8,21 +8,13 @@ import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; import com.oriole.ocean.common.enumerate.NotifyType; import com.oriole.ocean.common.po.mongo.FavorEntity; -import com.oriole.ocean.common.po.mongo.comment.CommentEntity; -import com.oriole.ocean.common.po.mongo.comment.CommentReplyEntity; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteEntity; import com.oriole.ocean.common.po.mysql.NoteLikeEntity; import com.oriole.ocean.common.po.mysql.NotifyEntity; -import com.oriole.ocean.common.service.NotifyService; -import com.oriole.ocean.common.service.NotifySubscriptionService; -import com.oriole.ocean.common.service.UserBehaviorService; +import com.oriole.ocean.common.service.*; import com.oriole.ocean.common.vo.AuthUserEntity; import com.oriole.ocean.common.vo.MsgEntity; -import com.oriole.ocean.common.service.NoteService; -import com.oriole.ocean.dao.NoteCollectionDao; -import jdk.nashorn.internal.ir.RuntimeNode; -import org.apache.commons.lang3.RandomStringUtils; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; @@ -31,7 +23,6 @@ import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.Objects; @@ -45,6 +36,8 @@ public class NoteController { @Autowired NoteService noteService; + @Autowired + NoteCommentService noteCommentService; @DubboReference UserBehaviorService userBehaviorService; @DubboReference @@ -273,7 +266,7 @@ public MsgEntity> getNoteCommentByNoteId( @RequestParam Integer pageNo, @RequestParam Integer pageSize) { PageHelper.startPage(pageNo, pageSize, true); - List noteCommentEntityList = noteService.getNoteCommentsByNoteId(noteId, pageNo, pageSize); + List noteCommentEntityList = noteCommentService.getNoteCommentsByNoteIdWithLikeStatus(noteId); PageInfo pageInfo = new PageInfo<>(noteCommentEntityList); return new MsgEntity<>("SUCCESS", "1", pageInfo); } @@ -285,35 +278,35 @@ public MsgEntity> getNoteCommentByNoteId( public MsgEntity createNoteComment( @AuthUser AuthUserEntity authUser, @RequestParam String noteId, - @RequestParam String commentContent, - @RequestParam String replyTo, - @RequestParam String replyToUsername + @RequestParam String content, + @RequestParam String replyId, + @RequestParam String replyUsername ) { String userName = authUser.getUsername(); - NoteCommentEntity noteCommentEntity = new NoteCommentEntity(noteId, userName, commentContent, replyTo, replyToUsername); + NoteCommentEntity noteCommentEntity = new NoteCommentEntity(noteId, userName, content, replyId, replyUsername); - noteCommentEntity.setReplyTo(replyTo); - NoteCommentEntity noteComment = noteService.createNoteComment(noteCommentEntity); + noteCommentEntity.setReplyId(replyId); + NoteCommentEntity noteComment = noteCommentService.createNoteComment(noteCommentEntity); //构建用户消息事件 NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND, userName); notifyEntity.setTargetIDAndType(noteId, MainType.NOTE); - notifyEntity.setContent(commentContent); - System.out.println(replyTo); + notifyEntity.setContent(content); + System.out.println(replyId); System.out.println(noteId); - if (Objects.equals(replyTo, noteId)) { // 直接回复帖子 + if (Objects.equals(replyId, noteId)) { // 直接回复帖子 notifyEntity.setAction(NotifyAction.NEW_COMMENT);// 新评论事件不面向任何其他评论 } else { notifyEntity.setAction(NotifyAction.NEW_REPLY); } - notifyEntity.setCommentID(replyTo); + notifyEntity.setCommentID(replyId); // 增加用户消息订阅事件:用户需要订阅自己发布的评论或回复的动态 List notifyActionList = new ArrayList<>(); notifyActionList.add(NotifyAction.LIKE_COMMENT); notifyActionList.add(NotifyAction.NEW_REPLY); notifySubscriptionService.setNotifySubscription(userName, notifyActionList, - replyTo, NotifySubscriptionTargetType.COMMENT); + replyId, NotifySubscriptionTargetType.COMMENT); // 产生用户消息事件 notifyService.addNotify(notifyEntity); @@ -328,16 +321,20 @@ public MsgEntity createNoteComment( public MsgEntity deleteNoteComment( @AuthUser AuthUserEntity authUser, @RequestParam String _id) { - if(!noteService.isNoteCreator(_id, authUser.getUsername())) { - System.out.println(authUser.getUsername()); - if(authUser.isAdmin()) { - //TODO: Record administrator operation - } else { - return new MsgEntity<>("FAILED", "400", "删除评论失败"); - } + if(noteCommentService.isCommentCreator(_id, authUser.getUsername())) { + noteCommentService.deleteNoteComment(_id); + return new MsgEntity<>("SUCCESS", "1", "评论删除成功"); + } + NoteCommentEntity noteComment = noteCommentService.getNoteComment(_id); + if(noteService.isNoteCreator(noteComment.getNoteId(), authUser.getUsername())) { + noteCommentService.deleteNoteComment(_id); + return new MsgEntity<>("SUCCESS", "1", "帖主删除评论成功"); + } + if(authUser.isAdmin()) { + noteCommentService.deleteNoteComment(_id); + return new MsgEntity<>("SUCCESS", "1", "管理员删除评论成功"); } - noteService.deleteNoteComment(_id); - return new MsgEntity<>("SUCCESS", "1", "评论删除成功"); + return new MsgEntity<>("FAILED", "400", "删除评论失败"); } // 收藏功能 diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCollectionDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCollectionDao.java index 35de7a6..e250447 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCollectionDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCollectionDao.java @@ -1,7 +1,6 @@ package com.oriole.ocean.dao; import com.oriole.ocean.common.po.mongo.FavorEntity; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java index 20a00a6..5055fb1 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java @@ -1,54 +1,20 @@ package com.oriole.ocean.dao; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; -import org.springframework.stereotype.Repository; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; +import org.apache.ibatis.annotations.Mapper; import java.util.List; -@Repository -public class NoteCommentDao { - @Autowired - private MongoTemplate mongoTemplate; - @Autowired - private NoteDao noteDao; - - public void addNoteComment(NoteCommentEntity noteComment) { - mongoTemplate.save(noteComment, "note_comments"); - noteDao.increaseCommentCnt(noteComment.getNoteId()); - } - - public List getNoteCommentsByNoteId(String noteId, int pageNo, int pageSize) { - Pageable pageable = PageRequest.of(pageNo - 1, pageSize); - - // 创建查询条件,同时支持String和Long类型的noteId(为了兼容旧数据) - Criteria criteria = new Criteria().orOperator( - Criteria.where("noteId").is(noteId), - Criteria.where("noteId").is(Long.parseLong(noteId)) - ); - - Query query = new Query(criteria); - query.with(pageable); - - return mongoTemplate.find(query, NoteCommentEntity.class, "note_comments"); - } - - public boolean deleteNoteComment(String commentId) { - try { - Query query = new Query(Criteria.where("_id").is(commentId)); - mongoTemplate.remove(query, NoteCommentEntity.class, "note_comments"); - return true; - } catch (Exception e) { - return false; - } - } - - public NoteCommentEntity getNoteComment(String noteId) { - return mongoTemplate.findById(noteId, NoteCommentEntity.class, "note_comments"); - } +/** + * Note data access object + * Handles database operations for note records + */ +@Mapper +public interface NoteCommentDao extends BaseMapper { + + void addNoteComment(NoteCommentEntity noteComment); + boolean deleteNoteComment(String commentId); + List getNoteCommentsByNoteIdWithLikeStatus(String noteId); + NoteCommentEntity getNoteComment(String commentId); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentLikeDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentLikeDao.java new file mode 100644 index 0000000..50ee734 --- /dev/null +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentLikeDao.java @@ -0,0 +1,45 @@ +package com.oriole.ocean.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.oriole.ocean.common.po.mysql.NoteCommentLikeEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * Note like data access object + * Handles database operations for comment like records + */ +@Mapper +public interface NoteCommentLikeDao extends BaseMapper { + + /** + * Add a like record + * @param noteCommentLikeEntity The like record to add + * @return Number of affected rows + */ + int addNoteCommentLike(NoteCommentLikeEntity noteCommentLikeEntity); + + /** + * Remove a like record + * @param username The username who likes the comment + * @param commentId The ID of the comment + * @return Number of affected rows + */ + int removeNoteCommentLike(@Param("username") String username, @Param("commentId") String commentId); + + /** + * Check if a user has liked a specific comment + * @param username The username to check + * @param commentId The ID of the comment + * @return The like record if exists, null otherwise + */ + NoteCommentLikeEntity findNoteCommentLike(@Param("username") String username, @Param("commentId") String commentId); + + /** + * Check if a user has liked a specific comment (returns boolean) + * @param username The username to check + * @param commentId The ID of the comment + * @return true if liked, false otherwise + */ + boolean hasUserLikedNoteComment(@Param("username") String username, @Param("commentId") String commentId); +} \ No newline at end of file diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java index 4536b4e..76ef8c4 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java @@ -1,13 +1,11 @@ package com.oriole.ocean.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteEntity; -import com.oriole.ocean.common.po.mysql.UserNotifyEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import java.util.Date; import java.util.List; /** diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java new file mode 100644 index 0000000..06aafaa --- /dev/null +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java @@ -0,0 +1,131 @@ +package com.oriole.ocean.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentLikeEntity; +import com.oriole.ocean.common.service.NoteCommentService; +import com.oriole.ocean.dao.*; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +/** + * Note service implementation + * Implements business logic for note operations including like functionality + */ +@Service +@Transactional +public class NoteCommentServiceImpl extends ServiceImpl implements NoteCommentService { + + @Resource + private NoteCommentDao noteCommentDao; + + @Resource + private NoteCommentLikeDao noteCommentLikeDao; + + /** + * Check if user is the creator of a comment + * @param commentId Comment ID + * @param username Username to check + * @return true if user is creator, false otherwise + */ + public boolean isCommentCreator(String commentId, String username) { + NoteCommentEntity comment = noteCommentDao.getNoteComment(commentId); + return comment != null && comment.getBuildUsername().equals(username); + } + + /** + * Create a new note comment + * @param noteCommentEntity Note comment entity to create + * @return Created note comment entity + */ + public NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity) { + noteCommentEntity.setLikeNum(0); + noteCommentEntity.setBuildDate(new Date()); + + noteCommentDao.addNoteComment(noteCommentEntity); + + return noteCommentEntity; + } + + /** + * Get note comments by note ID + * @param noteId Note ID + * @return List of note comments + */ + public List getNoteCommentsByNoteIdWithLikeStatus(String noteId) { + return noteCommentDao.getNoteCommentsByNoteIdWithLikeStatus(noteId); + } + + /** + * Get note comments by comment ID + * @param commentId comment ID + * @return note comment + */ + public NoteCommentEntity getNoteComment(String commentId) { + return noteCommentDao.getNoteComment(commentId); + } + + /** + * Delete a note comment + * @param commentId Comment ID + */ + public void deleteNoteComment(String commentId) { + noteCommentDao.deleteNoteComment(commentId); + } + + + // === Like functionality implementation === + + /** + * Like or unlike a note + * @param username Username who likes/unlikes + * @param commentId Note ID to like/unlike + * @param isLike true to like, false to unlike + * @return NoteLikeEntity if liked, null if unliked + */ + @Override + public NoteCommentLikeEntity likeNoteComment(String username, String commentId, boolean isLike) { + if (isLike) { + // Check if already liked + NoteCommentLikeEntity existingLike = noteCommentLikeDao.findNoteCommentLike(username, commentId); + if (existingLike != null) { + return existingLike; // Already liked, return existing record + } + + // Create new like record + NoteCommentLikeEntity noteCommentLikeEntity = new NoteCommentLikeEntity(username, commentId); + noteCommentLikeDao.addNoteCommentLike(noteCommentLikeEntity); + return null; + } else { + // Remove like record + noteCommentLikeDao.removeNoteCommentLike(username, commentId); + return null; + } + } + + /** + * Check if a user has liked a specific note + * @param username Username to check + * @param commentId Note ID to check + * @return true if liked, false otherwise + */ + @Override + public boolean hasUserLikedNoteComment(String username, String commentId) { + return noteCommentLikeDao.hasUserLikedNoteComment(username, commentId); + } + + /** + * Get like record for a user and note + * @param username Username + * @param commentId Note ID + * @return NoteLikeEntity if exists, null otherwise + */ + @Override + public NoteCommentLikeEntity getNoteCommentLike(String username, String commentId) { + return noteCommentLikeDao.findNoteCommentLike(username, commentId); + } +} \ No newline at end of file diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java index 100171c..f7780b3 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java @@ -2,22 +2,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.oriole.ocean.common.po.mongo.FavorEntity; -import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; +import com.oriole.ocean.common.po.mysql.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteLikeEntity; import com.oriole.ocean.common.service.NoteService; import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.dao.NoteCollectionDao; -import com.oriole.ocean.dao.NoteCommentDao; import com.oriole.ocean.dao.NoteDao; import com.oriole.ocean.dao.NoteLikeDao; import com.oriole.ocean.common.po.mysql.NoteEntity; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -37,16 +29,10 @@ public class NoteServiceImpl extends ServiceImpl implements @Resource private NoteCollectionDao noteCollectionDao; - - @Resource - private NoteCommentDao noteCommentDao; @Resource private NoteLikeDao noteLikeDao; - @Resource - private NotifyService notifyService; - /** * Check if user is the creator of a note * @param noteId Note ID @@ -194,53 +180,10 @@ public NoteEntity createNote(NoteEntity noteEntity){ return noteEntity; } - /** - * Create a new note comment - * @param noteCommentEntity Note comment entity to create - * @return Created note comment entity - */ - public NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity) { - noteCommentEntity.setLikeNum(0); - noteCommentEntity.setCreateTime(new Date()); - - noteCommentDao.addNoteComment(noteCommentEntity); - - return noteCommentEntity; - } - - /** - * Get note comments by note ID - * @param noteId Note ID - * @param pageNo Page number - * @param pageSize Page size - * @return List of note comments - */ - public List getNoteCommentsByNoteId(String noteId, int pageNo, int pageSize) { - return noteCommentDao.getNoteCommentsByNoteId(noteId, pageNo, pageSize); - } - public void readNote(String noteId) { noteDao.readNote(noteId); } - /** - * Check if user is the creator of a comment - * @param commentId Comment ID - * @param username Username to check - * @return true if user is creator, false otherwise - */ - public boolean isCommentCreator(String commentId, String username) { - NoteCommentEntity comment = noteCommentDao.getNoteComment(commentId); - return comment != null && comment.getNoteCommentBuildUsername().equals(username); - } - - /** - * Delete a note comment - * @param commentId Comment ID - */ - public void deleteNoteComment(String commentId) { - noteCommentDao.deleteNoteComment(commentId); - } /** * Get user behavior (favorites) for a specific note diff --git a/ocean-note-service/src/main/resources/mapper/NoteCommentLikeMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteCommentLikeMapper.xml new file mode 100644 index 0000000..d46dcf0 --- /dev/null +++ b/ocean-note-service/src/main/resources/mapper/NoteCommentLikeMapper.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + INSERT INTO note_comment_like (id, username, comment_id, like_time) + VALUES (#{id}, #{username}, #{commentId}, #{likeTime}) + + + + + DELETE FROM note_comment_like + WHERE username = #{username} AND comment_id = #{commentId} + + + + + + + + + \ No newline at end of file diff --git a/ocean-note-service/src/main/resources/mapper/NoteCommentMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteCommentMapper.xml new file mode 100644 index 0000000..df07bc4 --- /dev/null +++ b/ocean-note-service/src/main/resources/mapper/NoteCommentMapper.xml @@ -0,0 +1,34 @@ + + + + + + INSERT INTO note_comment + (id, note_id, build_username, like_num, build_date, + reply_id. reply_username, content, is_deleted) + VALUES (#{id}, #{noteId}, #{buildUsername}, 0, + #{build_date}, #{replyId}, #{replyUsername}, #{content}, 0) + + + + UPDATE note_comment + SET is_deleted = 1 + WHERE id = #{commentId} + + + + + + \ No newline at end of file diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java index 2f16033..3073d86 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java @@ -6,21 +6,14 @@ import com.oriole.ocean.common.po.mongo.UserBehaviorEntity; import com.oriole.ocean.common.po.mongo.comment.CommentEntity; import com.oriole.ocean.common.po.mongo.comment.CommentReplyEntity; -import com.oriole.ocean.common.po.mongo.comment.NoteCommentEntity; -import com.oriole.ocean.common.po.mysql.NoteEntity; -import com.oriole.ocean.common.po.mysql.NotifySubscriptionEntity; -import com.oriole.ocean.common.po.mysql.UserNotifyEntity; import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.dao.NotifyDao; import com.oriole.ocean.common.po.mysql.NotifyEntity; import org.apache.dubbo.config.annotation.DubboService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.Arrays; import java.util.Date; import java.util.List; -import java.util.Objects; @Service @DubboService From 14d7c2a993c48e52a55a819af7e39541dc26294a Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sat, 21 Jun 2025 22:46:07 +0800 Subject: [PATCH 55/62] feat: add comment like controller --- .../ocean/controller/NoteController.java | 56 ++++++++++++++++--- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index 22d0fe8..64d7b37 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -8,10 +8,7 @@ import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; import com.oriole.ocean.common.enumerate.NotifyType; import com.oriole.ocean.common.po.mongo.FavorEntity; -import com.oriole.ocean.common.po.mysql.NoteCommentEntity; -import com.oriole.ocean.common.po.mysql.NoteEntity; -import com.oriole.ocean.common.po.mysql.NoteLikeEntity; -import com.oriole.ocean.common.po.mysql.NotifyEntity; +import com.oriole.ocean.common.po.mysql.*; import com.oriole.ocean.common.service.*; import com.oriole.ocean.common.vo.AuthUserEntity; import com.oriole.ocean.common.vo.MsgEntity; @@ -204,7 +201,7 @@ public MsgEntity> getNoteByTag( } // === Like functionality APIs === - + /** * Like or unlike a note * @param authUser Authenticated user @@ -217,7 +214,7 @@ public MsgEntity likeNote( @AuthUser AuthUserEntity authUser, @RequestParam String noteId, @RequestParam Boolean isLike) { - + String username = authUser.getUsername(); NoteLikeEntity result = noteService.likeNote(username, noteId, isLike); @@ -237,7 +234,7 @@ public MsgEntity readNote( return new MsgEntity<>("SUCCESS", "1", "Note read successfully"); } - + /** * Check if current user has liked a specific note * @param authUser Authenticated user @@ -248,10 +245,51 @@ public MsgEntity readNote( public MsgEntity checkNoteLikeStatus( @AuthUser AuthUserEntity authUser, @RequestParam String noteId) { - + String username = authUser.getUsername(); boolean hasLiked = noteService.hasUserLikedNote(username, noteId); - + + return new MsgEntity<>("SUCCESS", "1", hasLiked); + } + + /** + * Like or unlike a comment + * @param authUser Authenticated user + * @param commentId Comment ID to like/unlike + * @param isLike true to like, false to unlike + * @return Success message with like status + */ + @RequestMapping(value = "/likeNoteComment", method = RequestMethod.POST) + public MsgEntity likeNoteComment( + @AuthUser AuthUserEntity authUser, + @RequestParam String commentId, + @RequestParam Boolean isLike) { + + String username = authUser.getUsername(); + + NoteCommentLikeEntity result = noteCommentService.likeNoteComment(username, commentId, isLike); + + if (isLike) { + return new MsgEntity<>("SUCCESS", "1", result); + } else { + return new MsgEntity<>("SUCCESS", "1", null); + } + } + + /** + * Check if the current user has liked a specific comment + * @param authUser Authenticated user + * @param commentId Comment ID to check + * @return Like status + */ + @RequestMapping(value = "/checkNoteCommentLikeStatus", method = RequestMethod.POST) + public MsgEntity checkNoteCommentLikeStatus( + @AuthUser AuthUserEntity authUser, + @RequestParam String commentId) { + + String username = authUser.getUsername(); + boolean hasLiked = noteCommentService.hasUserLikedNoteComment(username, commentId); + return new MsgEntity<>("SUCCESS", "1", hasLiked); } From 8b9cd1b7fcf29f554246703f28e8fa93dbbba90e Mon Sep 17 00:00:00 2001 From: cms42 Date: Sun, 22 Jun 2025 10:01:32 +0800 Subject: [PATCH 56/62] fix: update old code to use new note comment implementation --- .../main/java/com/oriole/ocean/service/NoteServiceImpl.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java index f7780b3..e50e765 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java @@ -2,10 +2,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.oriole.ocean.common.po.mongo.FavorEntity; -import com.oriole.ocean.common.po.mysql.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteLikeEntity; import com.oriole.ocean.common.service.NoteService; -import com.oriole.ocean.common.service.NotifyService; import com.oriole.ocean.dao.NoteCollectionDao; import com.oriole.ocean.dao.NoteDao; import com.oriole.ocean.dao.NoteLikeDao; @@ -41,8 +39,8 @@ public class NoteServiceImpl extends ServiceImpl implements */ public boolean isNoteCreator(String noteId, String username) { System.out.println(noteId); - NoteCommentEntity note = noteCommentDao.getNoteComment(noteId); - return note != null && note.getNoteCommentBuildUsername().equals(username); + NoteEntity note = noteDao.getNoteById(noteId); + return note != null && note.getBuildUsername().equals(username); } /** From d0fa971706aa6f1e90baa280681c86bd4499bb5a Mon Sep 17 00:00:00 2001 From: cms42 Date: Sun, 22 Jun 2025 11:17:59 +0800 Subject: [PATCH 57/62] fix: note comment db mapping --- .../common/service/NoteCommentService.java | 32 +++++++++++------- .../ocean/controller/NoteController.java | 33 ++++++++++++------- .../com/oriole/ocean/dao/NoteCommentDao.java | 22 +++++++++++-- .../ocean/service/NoteCommentServiceImpl.java | 16 +++++++-- .../mapper/NoteCommentLikeMapper.xml | 2 +- .../resources/mapper/NoteCommentMapper.xml | 22 +++++++++---- 6 files changed, 90 insertions(+), 37 deletions(-) diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteCommentService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteCommentService.java index f69b680..02014f5 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteCommentService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteCommentService.java @@ -9,8 +9,8 @@ import java.util.List; /** - * Note service interface - * Provides business logic for note operations + * Note comment service interface + * Provides business logic for note comment operations */ public interface NoteCommentService { @@ -29,11 +29,19 @@ public interface NoteCommentService { void deleteNoteComment(String commentId); /** - * Get note comments by note ID + * Get note comments by note ID (for anonymous users) * @param noteId Note ID * @return List of note comments */ - List getNoteCommentsByNoteIdWithLikeStatus(String noteId); + List getNoteCommentsByNoteId(String noteId); + + /** + * Get note comments by note ID with like status (for authenticated users) + * @param noteId Note ID + * @param username Current user's username + * @return List of note comments with like status + */ + List getNoteCommentsByNoteIdWithLikeStatus(String noteId, String username); /** * Get note comments by comment ID @@ -51,27 +59,27 @@ public interface NoteCommentService { /** - * Like or unlike a note + * Like or unlike a comment * @param username Username who likes/unlikes - * @param commentId Note ID to like/unlike + * @param commentId Comment ID to like/unlike * @param isLike true to like, false to unlike - * @return NoteLikeEntity if liked, null if unliked + * @return NoteCommentLikeEntity if liked, null if unliked */ NoteCommentLikeEntity likeNoteComment(String username, String commentId, boolean isLike); /** - * Check if a user has liked a specific note + * Check if a user has liked a specific comment * @param username Username to check - * @param commentId Note ID to check + * @param commentId Comment ID to check * @return true if liked, false otherwise */ boolean hasUserLikedNoteComment(String username, String commentId); /** - * Get like record for a user and note + * Get like record for a user and comment * @param username Username - * @param commentId Note ID - * @return NoteLikeEntity if exists, null otherwise + * @param commentId Comment ID + * @return NoteCommentLikeEntity if exists, null otherwise */ NoteCommentLikeEntity getNoteCommentLike(String username, String commentId); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index 64d7b37..621fd54 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -297,14 +297,25 @@ public MsgEntity checkNoteCommentLikeStatus( /** * Get note comments by note ID + * Returns comments with like status for authenticated user */ @RequestMapping(value = "/getNoteCommentByNoteId", method = RequestMethod.POST) public MsgEntity> getNoteCommentByNoteId( + @AuthUser AuthUserEntity authUser, @RequestParam String noteId, @RequestParam Integer pageNo, @RequestParam Integer pageSize) { PageHelper.startPage(pageNo, pageSize, true); - List noteCommentEntityList = noteCommentService.getNoteCommentsByNoteIdWithLikeStatus(noteId); + + List noteCommentEntityList; + if (authUser != null) { + // Authenticated user - include like status + noteCommentEntityList = noteCommentService.getNoteCommentsByNoteIdWithLikeStatus(noteId, authUser.getUsername()); + } else { + // Anonymous user - without like status + noteCommentEntityList = noteCommentService.getNoteCommentsByNoteId(noteId); + } + PageInfo pageInfo = new PageInfo<>(noteCommentEntityList); return new MsgEntity<>("SUCCESS", "1", pageInfo); } @@ -316,35 +327,35 @@ public MsgEntity> getNoteCommentByNoteId( public MsgEntity createNoteComment( @AuthUser AuthUserEntity authUser, @RequestParam String noteId, - @RequestParam String content, - @RequestParam String replyId, - @RequestParam String replyUsername + @RequestParam String commentContent, + @RequestParam String replyTo, + @RequestParam String replyToUsername ) { String userName = authUser.getUsername(); - NoteCommentEntity noteCommentEntity = new NoteCommentEntity(noteId, userName, content, replyId, replyUsername); + NoteCommentEntity noteCommentEntity = new NoteCommentEntity(noteId, userName, commentContent, replyTo, replyToUsername); - noteCommentEntity.setReplyId(replyId); + noteCommentEntity.setReplyId(replyTo); NoteCommentEntity noteComment = noteCommentService.createNoteComment(noteCommentEntity); //构建用户消息事件 NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND, userName); notifyEntity.setTargetIDAndType(noteId, MainType.NOTE); - notifyEntity.setContent(content); - System.out.println(replyId); + notifyEntity.setContent(commentContent); + System.out.println(replyTo); System.out.println(noteId); - if (Objects.equals(replyId, noteId)) { // 直接回复帖子 + if (Objects.equals(replyTo, noteId)) { // 直接回复帖子 notifyEntity.setAction(NotifyAction.NEW_COMMENT);// 新评论事件不面向任何其他评论 } else { notifyEntity.setAction(NotifyAction.NEW_REPLY); } - notifyEntity.setCommentID(replyId); + notifyEntity.setCommentID(replyTo); // 增加用户消息订阅事件:用户需要订阅自己发布的评论或回复的动态 List notifyActionList = new ArrayList<>(); notifyActionList.add(NotifyAction.LIKE_COMMENT); notifyActionList.add(NotifyAction.NEW_REPLY); notifySubscriptionService.setNotifySubscription(userName, notifyActionList, - replyId, NotifySubscriptionTargetType.COMMENT); + replyTo, NotifySubscriptionTargetType.COMMENT); // 产生用户消息事件 notifyService.addNotify(notifyEntity); diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java index 5055fb1..6ba207a 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteCommentDao.java @@ -3,18 +3,34 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.oriole.ocean.common.po.mysql.NoteCommentEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; /** - * Note data access object - * Handles database operations for note records + * Note comment data access object + * Handles database operations for note comment records */ @Mapper public interface NoteCommentDao extends BaseMapper { void addNoteComment(NoteCommentEntity noteComment); boolean deleteNoteComment(String commentId); - List getNoteCommentsByNoteIdWithLikeStatus(String noteId); + + /** + * Get note comments by note ID without like status (for anonymous users) + * @param noteId Note ID + * @return List of note comments + */ + List getNoteCommentsByNoteId(@Param("noteId") String noteId); + + /** + * Get note comments by note ID with like status for authenticated user + * @param noteId Note ID + * @param username Current user's username + * @return List of note comments with like status + */ + List getNoteCommentsByNoteIdWithLikeStatus(@Param("noteId") String noteId, @Param("username") String username); + NoteCommentEntity getNoteComment(String commentId); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java index 06aafaa..88a257b 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java @@ -52,12 +52,22 @@ public NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity) } /** - * Get note comments by note ID + * Get note comments by note ID (for anonymous users) * @param noteId Note ID * @return List of note comments */ - public List getNoteCommentsByNoteIdWithLikeStatus(String noteId) { - return noteCommentDao.getNoteCommentsByNoteIdWithLikeStatus(noteId); + public List getNoteCommentsByNoteId(String noteId) { + return noteCommentDao.getNoteCommentsByNoteId(noteId); + } + + /** + * Get note comments by note ID with like status (for authenticated users) + * @param noteId Note ID + * @param username Current user's username + * @return List of note comments with like status + */ + public List getNoteCommentsByNoteIdWithLikeStatus(String noteId, String username) { + return noteCommentDao.getNoteCommentsByNoteIdWithLikeStatus(noteId, username); } /** diff --git a/ocean-note-service/src/main/resources/mapper/NoteCommentLikeMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteCommentLikeMapper.xml index d46dcf0..bb7f2e7 100644 --- a/ocean-note-service/src/main/resources/mapper/NoteCommentLikeMapper.xml +++ b/ocean-note-service/src/main/resources/mapper/NoteCommentLikeMapper.xml @@ -1,7 +1,7 @@ - + diff --git a/ocean-note-service/src/main/resources/mapper/NoteCommentMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteCommentMapper.xml index df07bc4..54d84df 100644 --- a/ocean-note-service/src/main/resources/mapper/NoteCommentMapper.xml +++ b/ocean-note-service/src/main/resources/mapper/NoteCommentMapper.xml @@ -1,14 +1,14 @@  - + INSERT INTO note_comment (id, note_id, build_username, like_num, build_date, - reply_id. reply_username, content, is_deleted) + reply_id, reply_username, content, is_deleted) VALUES (#{id}, #{noteId}, #{buildUsername}, 0, - #{build_date}, #{replyId}, #{replyUsername}, #{content}, 0) + #{buildDate}, #{replyId}, #{replyUsername}, #{content}, 0) @@ -17,18 +17,26 @@ WHERE id = #{commentId} - + SELECT nc.* + FROM note_comment nc + WHERE nc.note_id = #{noteId} AND nc.is_deleted = 0 + ORDER BY nc.build_date ASC + + + - SELECT * FROM note_comment - WHERE id = #{commentId} + WHERE id = #{commentId} AND is_deleted = 0 LIMIT 1 \ No newline at end of file From c76d130e2031dfa2b7c45068cd4ca1e6d02e24f3 Mon Sep 17 00:00:00 2001 From: AInfinity-LilacDream <1977741520@qq.com> Date: Sun, 22 Jun 2025 12:47:27 +0800 Subject: [PATCH 58/62] refactor: refactor note & notecomment --- .../controller/UserCollectionController.java | 49 +++++++++++-------- .../service/UserCollectionServiceImpl.java | 5 +- .../controller/UserCommentController.java | 14 +++++- .../ocean/common/service/NoteService.java | 2 + .../ocean/controller/NoteController.java | 41 ++++++++-------- .../java/com/oriole/ocean/dao/NoteDao.java | 9 ++-- .../oriole/ocean/service/NoteServiceImpl.java | 4 ++ .../src/main/resources/mapper/NoteMapper.xml | 33 +++++-------- 8 files changed, 86 insertions(+), 71 deletions(-) diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java b/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java index 700d2a9..253341a 100644 --- a/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java +++ b/ocean-collection-service/src/main/java/com/oriole/ocean/controller/UserCollectionController.java @@ -16,6 +16,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomStringUtils; import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.query.Query; import org.springframework.web.bind.annotation.RequestMapping; @@ -77,16 +78,20 @@ public MsgEntity deleteCollection(@AuthUser AuthUserEntity authUser, // 需要一并清空用户的收藏情况记录 for (Integer itemID : collectionEntity.getItems()) { // 遍历被删除的收藏夹中的文件对应用户行为记录 UserBehaviorEntity userBehaviorEntityQuery = new UserBehaviorEntity(itemID, mainType, username, BehaviorType.DO_COLLECTION); - JSONArray collectionList = (JSONArray) userBehaviorService.findBehaviorRecord(userBehaviorEntityQuery).getExtraInfo(IN_COLLECTION); - collectionList.remove(collectionID); - if (collectionList.isEmpty()) {//所有的收藏已经被全部删除了 - // 移除收藏量统计 - userCollectionService.collectionStatisticsChange(itemID, "-1", mainType); - // 移除用户行为记录 - userBehaviorService.deleteBehaviorRecord(userBehaviorEntityQuery); - } else { // 还有收藏记录存在,更新记录 - userBehaviorService.updateBehaviorRecordExtraInfo(userBehaviorEntityQuery, IN_COLLECTION, collectionList); + Object extraInfo = userBehaviorService.findBehaviorRecord(userBehaviorEntityQuery).getExtraInfo(IN_COLLECTION); + if (extraInfo instanceof List) { + List collectionList = (List) extraInfo; + collectionList.removeIf(id -> id.equals(collectionID)); + + if (collectionList.isEmpty()) {//所有的收藏已经被全部删除了 + // 移除文件收藏量统计 + userCollectionService.collectionStatisticsChange(itemID, "-1", mainType); + // 移除用户行为记录 + userBehaviorService.deleteBehaviorRecord(userBehaviorEntityQuery); + } else { // 还有收藏记录存在,更新记录 + userBehaviorService.updateBehaviorRecordExtraInfo(userBehaviorEntityQuery, IN_COLLECTION, collectionList); + } } } return new MsgEntity<>(SUCCESS); @@ -148,11 +153,10 @@ public MsgEntity changeCollectionItem(@AuthUser AuthUserEn @RequestMapping(value = "/deleteCollectionItem", method = RequestMethod.GET) public MsgEntity deleteCollectedItem(@AuthUser AuthUserEntity authUser, - @RequestParam(required = false) String username, @RequestParam String collectionID, @RequestParam Integer itemID, @RequestParam MainType mainType) { - username = authUser.getAllowOperationUsername(username); + String username = authUser.getUsername(); Integer removedItemID = userCollectionService.deleteOneCollectionItem(username, collectionID, itemID, mainType); if (removedItemID == null) { @@ -160,16 +164,20 @@ public MsgEntity deleteCollectedItem(@AuthUser AuthUserEntity authUser, } // 进行到了此处说明肯定有删除发生 UserBehaviorEntity userBehaviorEntityQuery = new UserBehaviorEntity(itemID, mainType, username, BehaviorType.DO_COLLECTION); - JSONArray collectionList = (JSONArray) userBehaviorService.findBehaviorRecord(userBehaviorEntityQuery).getExtraInfo(IN_COLLECTION); - collectionList.remove(collectionID); - if (collectionList.isEmpty()) {//所有的收藏已经被全部删除了 - // 移除文件收藏量统计 - userCollectionService.collectionStatisticsChange(itemID, "-1", mainType); - // 移除用户行为记录 - userBehaviorService.deleteBehaviorRecord(userBehaviorEntityQuery); - } else { // 还有收藏记录存在,更新记录 - userBehaviorService.updateBehaviorRecordExtraInfo(userBehaviorEntityQuery, IN_COLLECTION, collectionList); + Object extraInfo = userBehaviorService.findBehaviorRecord(userBehaviorEntityQuery).getExtraInfo(IN_COLLECTION); + if (extraInfo instanceof List) { + List collectionList = (List) extraInfo; + collectionList.removeIf(id -> id.equals(collectionID)); + + if (collectionList.isEmpty()) {//所有的收藏已经被全部删除了 + // 移除文件收藏量统计 + userCollectionService.collectionStatisticsChange(itemID, "-1", mainType); + // 移除用户行为记录 + userBehaviorService.deleteBehaviorRecord(userBehaviorEntityQuery); + } else { // 还有收藏记录存在,更新记录 + userBehaviorService.updateBehaviorRecordExtraInfo(userBehaviorEntityQuery, IN_COLLECTION, collectionList); + } } return new MsgEntity<>(SUCCESS); } @@ -182,6 +190,7 @@ public MsgEntity> getCollectionItemList(@AuthUser AuthUserEntity a username = authUser.getAllowOperationUsername(username); UserCollectionEntity.CollectionEntity collectionEntity = userCollectionService.getCollectionByUsernameAndCollectionID(username, collectionID, mainType); + if (collectionEntity == null) return new MsgEntity<>("SUCCESS", "2", null); return new MsgEntity<>("SUCCESS", "1", collectionEntity.getItems()); } } diff --git a/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java b/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java index b12d1a8..a54e3dc 100644 --- a/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java +++ b/ocean-collection-service/src/main/java/com/oriole/ocean/service/UserCollectionServiceImpl.java @@ -69,9 +69,8 @@ public UserCollectionEntity.CollectionEntity getCollectionByUsernameAndCollectio AggregationResults results = mongoTemplate.aggregate(aggregation, getCollectionName(mainType), UserCollectionEntity.CollectionEntity.class); - if (results.getMappedResults() == null) { - return null; - } + System.out.println(results.getMappedResults()); + if (results.getMappedResults().isEmpty()) return null; return results.getMappedResults().get(0); } diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index 1579202..04aa227 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import javax.xml.stream.events.Comment; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -118,9 +119,9 @@ public MsgEntity addComment(@AuthUser AuthUserEntity authUser, //构建用户消息事件 if (!isReply) { CommentEntity commentEntity = new CommentEntity(cid, authUser.getUsername(), commentContent); - commentEntity.setBuildDate(handleTime(commentEntity.getBuildDate())); commentService.addComment(bindID, mainType, commentEntity); notifyService.addNotifyByComment(bindID, mainType, commentEntity); + commentEntity.setBuildDate(handleTime(commentEntity.getBuildDate())); returnEntity = commentEntity; } else { CommentReplyEntity fileCommentReplyEntity = new CommentReplyEntity( @@ -129,12 +130,12 @@ public MsgEntity addComment(@AuthUser AuthUserEntity authUser, replyToCommentReplyID, commentContent); commentService.addCommentReply(bindID, mainType, replyInCommentID, fileCommentReplyEntity); - fileCommentReplyEntity.setBuildDate(handleTime(fileCommentReplyEntity.getBuildDate())); if(!replyToCommentReplyID.isEmpty()){ notifyService.addNotifyByReply(bindID, mainType, replyToCommentReplyID, fileCommentReplyEntity); }else { notifyService.addNotifyByReply(bindID, mainType, replyInCommentID, fileCommentReplyEntity); } + fileCommentReplyEntity.setBuildDate(handleTime(fileCommentReplyEntity.getBuildDate())); returnEntity = fileCommentReplyEntity; } // 增加用户消息订阅事件:用户需要订阅自己发布的评论或回复的动态 @@ -178,6 +179,15 @@ public MsgEntity getComment(@RequestParam Integer bindID, return new MsgEntity<>("SUCCESS", "1", commentsListEntity); } + @RequestMapping(value = "/getCommentById", method = RequestMethod.GET) + public MsgEntity getCommentById( + @RequestParam Integer bindID, + @RequestParam MainType mainType, + @RequestParam String commentID) { + CommentEntity commentEntity = commentService.getCommentByCommentID(bindID, mainType, commentID); + return new MsgEntity<>("SUCCESS", "1", commentEntity); + } + @RequestMapping(value = "/getCommentReply", method = RequestMethod.GET) public MsgEntity getCommentReply( @RequestParam Integer bindID, diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java index 3222c63..ab53ff3 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/service/NoteService.java @@ -12,6 +12,8 @@ */ public interface NoteService { + void changeNoteCommentNum(String noteId, int value); + /** * Check if user is the creator of a note * @param noteId Note ID diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index 621fd54..dca5c27 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -175,6 +175,15 @@ public MsgEntity deleteNote( return new MsgEntity<>("SUCCESS", "1", "Note deleted successfully"); } + @RequestMapping(value = "/canDeleteNote", method = RequestMethod.POST) + public MsgEntity canDeleteNote( + @AuthUser AuthUserEntity authUser, + @RequestParam String noteID) { + if(!noteService.isNoteCreator(noteID, authUser.getUsername()) && !authUser.isAdmin()) + return new MsgEntity<>("SUCCESS", "1", "false"); + return new MsgEntity<>("SUCCESS", "1", "true"); + } + /** * Get notes by tag with pagination * Returns notes with like status for authenticated user @@ -297,7 +306,6 @@ public MsgEntity checkNoteCommentLikeStatus( /** * Get note comments by note ID - * Returns comments with like status for authenticated user */ @RequestMapping(value = "/getNoteCommentByNoteId", method = RequestMethod.POST) public MsgEntity> getNoteCommentByNoteId( @@ -306,16 +314,7 @@ public MsgEntity> getNoteCommentByNoteId( @RequestParam Integer pageNo, @RequestParam Integer pageSize) { PageHelper.startPage(pageNo, pageSize, true); - - List noteCommentEntityList; - if (authUser != null) { - // Authenticated user - include like status - noteCommentEntityList = noteCommentService.getNoteCommentsByNoteIdWithLikeStatus(noteId, authUser.getUsername()); - } else { - // Anonymous user - without like status - noteCommentEntityList = noteCommentService.getNoteCommentsByNoteId(noteId); - } - + List noteCommentEntityList = noteCommentService.getNoteCommentsByNoteIdWithLikeStatus(noteId, authUser.getUsername()); PageInfo pageInfo = new PageInfo<>(noteCommentEntityList); return new MsgEntity<>("SUCCESS", "1", pageInfo); } @@ -327,35 +326,35 @@ public MsgEntity> getNoteCommentByNoteId( public MsgEntity createNoteComment( @AuthUser AuthUserEntity authUser, @RequestParam String noteId, - @RequestParam String commentContent, - @RequestParam String replyTo, - @RequestParam String replyToUsername + @RequestParam String content, + @RequestParam String replyId, + @RequestParam String replyUsername ) { String userName = authUser.getUsername(); - NoteCommentEntity noteCommentEntity = new NoteCommentEntity(noteId, userName, commentContent, replyTo, replyToUsername); + NoteCommentEntity noteCommentEntity = new NoteCommentEntity(noteId, userName, content, replyId, replyUsername); - noteCommentEntity.setReplyId(replyTo); + noteCommentEntity.setReplyId(replyId); NoteCommentEntity noteComment = noteCommentService.createNoteComment(noteCommentEntity); //构建用户消息事件 NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND, userName); notifyEntity.setTargetIDAndType(noteId, MainType.NOTE); - notifyEntity.setContent(commentContent); - System.out.println(replyTo); + notifyEntity.setContent(content); + System.out.println(replyId); System.out.println(noteId); - if (Objects.equals(replyTo, noteId)) { // 直接回复帖子 + if (Objects.equals(replyId, noteId)) { // 直接回复帖子 notifyEntity.setAction(NotifyAction.NEW_COMMENT);// 新评论事件不面向任何其他评论 } else { notifyEntity.setAction(NotifyAction.NEW_REPLY); } - notifyEntity.setCommentID(replyTo); + notifyEntity.setCommentID(replyId); // 增加用户消息订阅事件:用户需要订阅自己发布的评论或回复的动态 List notifyActionList = new ArrayList<>(); notifyActionList.add(NotifyAction.LIKE_COMMENT); notifyActionList.add(NotifyAction.NEW_REPLY); notifySubscriptionService.setNotifySubscription(userName, notifyActionList, - replyTo, NotifySubscriptionTargetType.COMMENT); + replyId, NotifySubscriptionTargetType.COMMENT); // 产生用户消息事件 notifyService.addNotify(notifyEntity); diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java index 76ef8c4..0bbc47f 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/dao/NoteDao.java @@ -3,9 +3,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.oriole.ocean.common.po.mysql.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteEntity; +import com.oriole.ocean.common.po.mysql.UserNotifyEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.Date; import java.util.List; /** @@ -15,11 +17,10 @@ @Mapper public interface NoteDao extends BaseMapper { + void readNote(String noteId); - String getNoteCreator(String noteID); + void changeNoteCommentNum(String noteId, int value); - void readNote(String noteId); - /** * Get latest notes * @return List of latest notes @@ -100,6 +101,4 @@ NoteEntity getNoteByIdWithLikeStatus(@Param("noteId") String noteId, * @return List of note comments */ List getNoteCommentsByNoteId(@Param("noteId") String noteId); - - void increaseCommentCnt(@Param("noteID") String noteID); } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java index 675ec9d..9c8703c 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteServiceImpl.java @@ -45,6 +45,10 @@ public boolean isNoteCreator(String noteId, String username) { return note != null && note.getBuildUsername().equals(username); } + public void changeNoteCommentNum(String noteId, int value) { + noteDao.changeNoteCommentNum(noteId, value); + } + /** * Delete a note (soft delete) * @param noteID Note ID to delete diff --git a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml index 79df120..3260f88 100644 --- a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml +++ b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml @@ -152,6 +152,18 @@ WHERE n.note_id = #{noteId} AND n.is_deleted = 0 + + UPDATE note + SET read_num = read_num + 1 + WHERE note.note_id = #{noteId}; + + + + UPDATE note + SET comment_num = comment_num + #{value} + WHERE note.note_id = #{noteId}; + + @@ -186,23 +198,4 @@ WHERE note.note_id = #{noteID}; - - UPDATE note - SET read_num = read_num + 1 - WHERE note.note_id = #{noteId}; - - - - UPDATE note - SET comment_num = comment_num + 1 - WHERE note.note_id = #{noteID}; - - - - \ No newline at end of file From c0a1a510882303a48cbf01d6cb3dd39b98044eff Mon Sep 17 00:00:00 2001 From: AInfinity-LilacDream <1977741520@qq.com> Date: Sun, 22 Jun 2025 14:13:15 +0800 Subject: [PATCH 59/62] fix: notify logic --- .../com/oriole/ocean/controller/NoteController.java | 11 ++++++++++- .../oriole/ocean/service/NoteCommentServiceImpl.java | 4 ++++ .../src/main/resources/mapper/NoteMapper.xml | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index dca5c27..c8b23a5 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -319,6 +319,14 @@ public MsgEntity> getNoteCommentByNoteId( return new MsgEntity<>("SUCCESS", "1", pageInfo); } + @RequestMapping(value = "/getNoteCommentById", method = RequestMethod.POST) + public MsgEntity getNoteCommentById( + @AuthUser AuthUserEntity authUser, + @RequestParam String commentID) { + + return new MsgEntity<>("SUCCESS", "1", noteCommentService.getNoteComment(commentID)); + } + /** * Create a note comment */ @@ -348,13 +356,14 @@ public MsgEntity createNoteComment( } else { notifyEntity.setAction(NotifyAction.NEW_REPLY); } + System.out.println(replyId); notifyEntity.setCommentID(replyId); // 增加用户消息订阅事件:用户需要订阅自己发布的评论或回复的动态 List notifyActionList = new ArrayList<>(); notifyActionList.add(NotifyAction.LIKE_COMMENT); notifyActionList.add(NotifyAction.NEW_REPLY); notifySubscriptionService.setNotifySubscription(userName, notifyActionList, - replyId, NotifySubscriptionTargetType.COMMENT); + noteComment.getId(), NotifySubscriptionTargetType.COMMENT); // 产生用户消息事件 notifyService.addNotify(notifyEntity); diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java index 88a257b..82cc361 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/service/NoteCommentServiceImpl.java @@ -1,6 +1,8 @@ package com.oriole.ocean.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oriole.ocean.common.enumerate.NotifyAction; +import com.oriole.ocean.common.enumerate.NotifySubscriptionTargetType; import com.oriole.ocean.common.po.mysql.NoteCommentEntity; import com.oriole.ocean.common.po.mysql.NoteCommentLikeEntity; import com.oriole.ocean.common.service.NoteCommentService; @@ -9,6 +11,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -48,6 +51,7 @@ public NoteCommentEntity createNoteComment(NoteCommentEntity noteCommentEntity) noteCommentDao.addNoteComment(noteCommentEntity); + return noteCommentEntity; } diff --git a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml index 3260f88..8b2b477 100644 --- a/ocean-note-service/src/main/resources/mapper/NoteMapper.xml +++ b/ocean-note-service/src/main/resources/mapper/NoteMapper.xml @@ -189,7 +189,7 @@ ON n.note_id = nl.note_id AND nl.username = #{username} WHERE n.is_deleted = 0 AND n.build_username = #{username} - ORDER BY n.refresh_date DESC; + ORDER BY n.refresh_date DESC From 9dbea404da1bf2a393e3202aa10bddf92e631e87 Mon Sep 17 00:00:00 2001 From: NegaVoayz Date: Sun, 22 Jun 2025 14:21:59 +0800 Subject: [PATCH 60/62] feat: add document comment reply getter API --- .../oriole/ocean/controller/UserCommentController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java index 04aa227..b0e53c5 100644 --- a/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java +++ b/ocean-comment-service/src/main/java/com/oriole/ocean/controller/UserCommentController.java @@ -188,6 +188,15 @@ public MsgEntity getCommentById( return new MsgEntity<>("SUCCESS", "1", commentEntity); } + @RequestMapping(value = "/getCommentReplyByCommentReplyID", method = RequestMethod.GET) + public MsgEntity getCommentReplyByCommentReplyID( + @RequestParam Integer bindID, + @RequestParam MainType mainType, + @RequestParam String commentReplyID) { + CommentReplyEntity commentReplyEntity = commentService.getCommentReplyByCommentReplyID(bindID, mainType, commentReplyID); + return new MsgEntity<>("SUCCESS", "1", commentReplyEntity); + } + @RequestMapping(value = "/getCommentReply", method = RequestMethod.GET) public MsgEntity getCommentReply( @RequestParam Integer bindID, From af2354bb913d4da2fcefe98e799cd40e9ffd757f Mon Sep 17 00:00:00 2001 From: cms42 Date: Sun, 22 Jun 2025 15:53:10 +0800 Subject: [PATCH 61/62] fix: implement user register logic --- .../gateway/config/WebSecurityConfig.java | 2 +- .../filter/UserAuthGatewayFilterFactory.java | 25 ++++++++++------- .../src/main/resources/application.yaml | 2 +- .../ocean/controller/AuthController.java | 5 ++++ .../service/base/UserBaseInfoServiceImpl.java | 28 +++++++++++++++++++ 5 files changed, 50 insertions(+), 12 deletions(-) diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java index 0363479..271a84e 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/config/WebSecurityConfig.java @@ -37,7 +37,7 @@ public class WebSecurityConfig { "/userAuth/login", //login接口是可以匿名访问的 "/userAuth/**Login", //login接口是可以匿名访问的 "/thirdPartLogin/**", //thirdPartLogin三方登录接口是可以匿名访问的 - "/userInfoService/reg", //reg接口是可以匿名访问的 + "/userAuth/reg", //reg接口是可以匿名访问的 "/docInfoService/getFileInfoByFileIDWithAnon", //这个接口在文件不允许匿名访问时返回错误信息 diff --git a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java index 9ca3737..3b9e584 100644 --- a/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java +++ b/ocean-gateway/src/main/java/com/oriole/ocean/gateway/filter/UserAuthGatewayFilterFactory.java @@ -75,20 +75,25 @@ public Mono writeWith(Publisher body) { JSONObject loginResponseObject = JSONObject.parseObject(responseData); if(loginResponseObject.get("state").equals("SUCCESS") && loginResponseObject.get("code").equals("1")){ - JSONObject loginInfo = loginResponseObject.getJSONObject("msg"); + Object msgObject = loginResponseObject.get("msg"); + if (msgObject instanceof JSONObject) { + JSONObject loginInfo = (JSONObject) msgObject; - Map chaim = new HashMap<>(); - chaim.put("username", loginInfo.getString("username")); - chaim.put("role", loginInfo.getString("role")); + Map chaim = new HashMap<>(); + chaim.put("username", loginInfo.getString("username")); + chaim.put("role", loginInfo.getString("role")); - String token = jwtUtils.encode(loginInfo.getString("username"), 24 * 60 * 60 * 1000, chaim); + String token = jwtUtils.encode(loginInfo.getString("username"), 24 * 60 * 60 * 1000, chaim); - loginResponseObject.put("msg", token); + loginResponseObject.put("msg", token); - byte[] uppedContent = loginResponseObject.toString().getBytes(); - originalResponse.getHeaders().set(HttpHeaders.AUTHORIZATION, token); - originalResponse.getHeaders().setContentLength(uppedContent.length); - return Mono.just(bufferFactory.wrap(uppedContent)); + byte[] uppedContent = loginResponseObject.toString().getBytes(); + originalResponse.getHeaders().set(HttpHeaders.AUTHORIZATION, token); + originalResponse.getHeaders().setContentLength(uppedContent.length); + return Mono.just(bufferFactory.wrap(uppedContent)); + } else { + return Mono.just(bufferFactory.wrap(bytes)); + } }else { originalResponse.setStatusCode(HttpStatus.UNAUTHORIZED); return Mono.just(bufferFactory.wrap(bytes)); diff --git a/ocean-gateway/src/main/resources/application.yaml b/ocean-gateway/src/main/resources/application.yaml index c941411..1a1d7e9 100644 --- a/ocean-gateway/src/main/resources/application.yaml +++ b/ocean-gateway/src/main/resources/application.yaml @@ -17,7 +17,7 @@ spring: - id: login uri: lb://ocean-user-service predicates: - - Path=/userAuth/login + - Path=/userAuth/login,/userAuth/reg filters: - UserAuth - id: user # 路由规则id,自定义,唯一 diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/controller/AuthController.java b/ocean-user-service/src/main/java/com/oriole/ocean/controller/AuthController.java index 1df8023..dd9785d 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/controller/AuthController.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/controller/AuthController.java @@ -25,4 +25,9 @@ public MsgEntity login(@RequestParam String username, @RequestParam return new MsgEntity<>("SUCCESS","1", userEntity); } + @RequestMapping(value = "/reg", method = RequestMethod.POST) + public MsgEntity register(@RequestParam String username, @RequestParam String password, @RequestParam(required = false) String nickname, @RequestParam(required = false) String phoneNum, @RequestParam(required = false) String email) { + return userBaseInfoService.registerUser(username, password, nickname, phoneNum, email); + } + } diff --git a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserBaseInfoServiceImpl.java b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserBaseInfoServiceImpl.java index a5309ce..af71c07 100644 --- a/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserBaseInfoServiceImpl.java +++ b/ocean-user-service/src/main/java/com/oriole/ocean/service/base/UserBaseInfoServiceImpl.java @@ -30,4 +30,32 @@ private UserEntity userLoginHandler(UserEntity userEntity) { } return userEntity; } + + public MsgEntity registerUser(String username, String password, String nickname, String phoneNum, String email) { + // Check if username already exists + UserEntity existingUser = getById(username); + if (existingUser != null) { + throw new BusinessException("-5", "Username already exists"); + } + + // Create new user + UserEntity newUser = new UserEntity(); + newUser.setUsername(username); + newUser.setPassword(password); + newUser.setNickname(nickname); + newUser.setPhoneNum(phoneNum); + newUser.setEmail(email); + newUser.setIsValid((byte) 0); // Set to pending review + newUser.setRegDate(new java.util.Date()); + newUser.setRole("USER"); + newUser.setLevelGrade(0); + + // Save user to database + boolean saved = save(newUser); + if (saved) { + return new MsgEntity<>("SUCCESS", "1", "Registration successful, waiting for admin review"); + } else { + throw new BusinessException("-6", "Registration failed, please try again later"); + } + } } From 5b76a69907d3c8bb56c1b13a1e6d3961c9bad32c Mon Sep 17 00:00:00 2001 From: AInfinity-LilacDream <1977741520@qq.com> Date: Sun, 22 Jun 2025 16:00:59 +0800 Subject: [PATCH 62/62] fix: impl comment like button --- .../ocean/common/po/mysql/NotifyEntity.java | 6 +++--- .../ocean/controller/NoteController.java | 2 +- .../java/com/oriole/ocean/dao/NotifyDao.java | 4 +++- .../ocean/service/NotifyServiceImpl.java | 21 ++++++------------- .../service/UserBehaviorServiceImpl.java | 4 ++++ 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifyEntity.java b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifyEntity.java index 3560168..3eb7dac 100644 --- a/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifyEntity.java +++ b/ocean-common/src/main/java/com/oriole/ocean/common/po/mysql/NotifyEntity.java @@ -24,7 +24,7 @@ public class NotifyEntity implements java.io.Serializable { private NotifyType type; @TableField(value = "target_id") - private String targetID; + private String targetId; private MainType targetType; @TableField(value = "comment_id") @@ -50,8 +50,8 @@ public NotifyEntity(NotifyType type, String buildUsername) { this.buildDate = new Date(); } - public void setTargetIDAndType(String targetID,MainType targetType) { - this.targetID = targetID; + public void setTargetIdAndType(String targetId, MainType targetType) { + this.targetId = targetId; this.targetType = targetType; } } diff --git a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java index c8b23a5..35701bb 100644 --- a/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java +++ b/ocean-note-service/src/main/java/com/oriole/ocean/controller/NoteController.java @@ -347,7 +347,7 @@ public MsgEntity createNoteComment( //构建用户消息事件 NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND, userName); - notifyEntity.setTargetIDAndType(noteId, MainType.NOTE); + notifyEntity.setTargetIdAndType(noteId, MainType.NOTE); notifyEntity.setContent(content); System.out.println(replyId); System.out.println(noteId); diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/dao/NotifyDao.java b/ocean-notify-service/src/main/java/com/oriole/ocean/dao/NotifyDao.java index 1c6e18e..d56a26b 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/dao/NotifyDao.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/dao/NotifyDao.java @@ -1,8 +1,10 @@ package com.oriole.ocean.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.oriole.ocean.common.enumerate.MainType; +import com.oriole.ocean.common.enumerate.NotifyAction; import com.oriole.ocean.common.po.mysql.NotifyEntity; public interface NotifyDao extends BaseMapper { - void removeNotify(NotifyEntity notifyEntity); + void removeNotify(String targetId, MainType targetType, String commentId, NotifyAction action, String buildUsername); } diff --git a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java index 3073d86..e6eb306 100644 --- a/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java +++ b/ocean-notify-service/src/main/java/com/oriole/ocean/service/NotifyServiceImpl.java @@ -26,7 +26,7 @@ public void addNotify(NotifyEntity notifyEntity){ public void addNotifyByComment(Integer bindID, MainType mainType, CommentEntity fileCommentEntity){ NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND, fileCommentEntity.getCommentBuildUsername()); - notifyEntity.setTargetID(bindID.toString()); + notifyEntity.setTargetId(bindID.toString()); notifyEntity.setTargetType(mainType); notifyEntity.setContent(fileCommentEntity.getCommentContent()); notifyEntity.setAction(NotifyAction.NEW_COMMENT); @@ -36,7 +36,7 @@ public void addNotifyByComment(Integer bindID, MainType mainType, public void addNotifyByReply(Integer bindID, MainType mainType, String replyInCommentID, CommentReplyEntity fileCommentReplyEntity){ NotifyEntity notifyEntity = new NotifyEntity(NotifyType.REMIND, fileCommentReplyEntity.getReplyBuildUsername()); - notifyEntity.setTargetID(bindID.toString()); + notifyEntity.setTargetId(bindID.toString()); notifyEntity.setTargetType(mainType); notifyEntity.setCommentID(replyInCommentID); notifyEntity.setContent(fileCommentReplyEntity.getCommentContent()); @@ -54,30 +54,21 @@ public void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity) { notifyEntity.setAction(NotifyAction.DOWNLOAD); break; case DO_LIKE: - add_or_remove = true; + add_or_remove = !userBehaviorEntity.getIsCancel(); notifyEntity.setAction(NotifyAction.LIKE); notifyEntity.setContent(userBehaviorEntity.getDoUsername() + "点赞了你的帖子"); break; - case DO_DISLIKE: - add_or_remove = false; - notifyEntity.setAction(NotifyAction.LIKE); - break; case DO_COMMENT_LIKE: - add_or_remove = true; + add_or_remove = !userBehaviorEntity.getIsCancel(); notifyEntity.setAction(NotifyAction.LIKE_COMMENT); notifyEntity.setCommentID((String) userBehaviorEntity.getExtraInfo(BehaviorExtraInfo.COMMENT_ID)); notifyEntity.setContent(userBehaviorEntity.getDoUsername() + "点赞了你的评论"); break; - case DO_COMMENT_DISLIKE: - add_or_remove = false; - notifyEntity.setAction(NotifyAction.LIKE_COMMENT); - notifyEntity.setCommentID((String) userBehaviorEntity.getExtraInfo(BehaviorExtraInfo.COMMENT_ID)); - break; default: return; } notifyEntity.setUserBehaviorID(userBehaviorEntity.getId()); - notifyEntity.setTargetIDAndType(String.valueOf(userBehaviorEntity.getBindID()),userBehaviorEntity.getType()); + notifyEntity.setTargetIdAndType(String.valueOf(userBehaviorEntity.getBindID()),userBehaviorEntity.getType()); if(add_or_remove) addNotify(notifyEntity); else @@ -86,7 +77,7 @@ public void addNotifyByBehaviorRecord(UserBehaviorEntity userBehaviorEntity) { private void removeNotify(NotifyEntity notifyEntity) { NotifyDao notifyDao = getBaseMapper(); - notifyDao.removeNotify(notifyEntity); + notifyDao.removeNotify(notifyEntity.getTargetId(),notifyEntity.getTargetType(),notifyEntity.getCommentID(), notifyEntity.getAction(),notifyEntity.getBuildUsername()); } // 查询指定时间之后产生的所有消息 diff --git a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java index 0cfd273..5c15fb8 100644 --- a/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java +++ b/ocean-user-behavior-service/src/main/java/com/oriole/ocean/service/UserBehaviorServiceImpl.java @@ -84,10 +84,12 @@ public void setUserEvaluateBehavior(UserBehaviorEntity userBehavior, List