From bc4cbc022f9c041539eb1c0eda2f411ec4681e73 Mon Sep 17 00:00:00 2001 From: yeguiyang Date: Wed, 10 Sep 2025 21:35:01 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/compiler.xml | 18 ++++ .idea/encodings.xml | 46 +++++++++- .idea/gradle.xml | 1 + .idea/misc.xml | 37 +++++++- qa-service/pom.xml | 46 +++++++--- qa-service/qa-service-adapter/pom.xml | 38 ++++++++ .../qa-adapter-in/.gitignore | 33 +++++++ .../qa-service-adapter/qa-adapter-in/pom.xml | 37 ++++++++ .../qa-adapter-in-web/.gitignore | 33 +++++++ .../qa-adapter-in/qa-adapter-in-web/pom.xml | 62 +++++++++++++ .../demos/web/controller/QaController.java | 25 ++++++ .../qa-service-adapter/qa-adapter-out/pom.xml | 38 ++++++++ .../qa-adapter-out-persistence/.gitignore | 33 +++++++ .../qa-adapter-out-persistence/pom.xml | 86 +++++++++++++++++++ .../persistence/bridge/GetQaListBridge.java | 27 ++++++ .../persistence/convertor/QaConvertor.java | 24 ++++++ .../out/persistence/entity/QaEntity.java | 19 ++++ .../out/persistence/mapper/QaMapper.java | 7 ++ qa-service/qa-service-application/.gitignore | 33 +++++++ qa-service/qa-service-application/pom.xml | 55 ++++++++++++ .../application/port/in/GetQaListUseCase.java | 9 ++ .../application/service/GetQaListService.java | 19 ++++ qa-service/qa-service-bootstrap/.gitignore | 33 +++++++ qa-service/qa-service-bootstrap/pom.xml | 84 ++++++++++++++++++ .../QaServiceBootstrapApplication.java | 15 ++++ .../src/main/resources/application.properties | 33 +++++++ .../src/main/resources/static/index.html | 6 ++ .../QaServiceBootstrapApplicationTests.java | 13 +++ qa-service/qa-service-common/.gitignore | 33 +++++++ qa-service/qa-service-common/pom.xml | 55 ++++++++++++ qa-service/qa-service-domain/.gitignore | 33 +++++++ qa-service/qa-service-domain/pom.xml | 57 ++++++++++++ .../com/example/qa/service/domain/Qa.java | 32 +++++++ .../qa/service/domain/port/GetQaListPort.java | 9 ++ .../qa/service/domain/valueobject/Answer.java | 7 ++ .../qa/service/domain/valueobject/QaId.java | 7 ++ .../service/domain/valueobject/Question.java | 7 ++ 37 files changed, 1134 insertions(+), 16 deletions(-) create mode 100644 qa-service/qa-service-adapter/pom.xml create mode 100644 qa-service/qa-service-adapter/qa-adapter-in/.gitignore create mode 100644 qa-service/qa-service-adapter/qa-adapter-in/pom.xml create mode 100644 qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/.gitignore create mode 100644 qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/pom.xml create mode 100644 qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/pom.xml create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/.gitignore create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/pom.xml create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaListBridge.java create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/convertor/QaConvertor.java create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/entity/QaEntity.java create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/mapper/QaMapper.java create mode 100644 qa-service/qa-service-application/.gitignore create mode 100644 qa-service/qa-service-application/pom.xml create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaListUseCase.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaListService.java create mode 100644 qa-service/qa-service-bootstrap/.gitignore create mode 100644 qa-service/qa-service-bootstrap/pom.xml create mode 100644 qa-service/qa-service-bootstrap/src/main/java/com/example/qa/service/bootstrap/QaServiceBootstrapApplication.java create mode 100644 qa-service/qa-service-bootstrap/src/main/resources/application.properties create mode 100644 qa-service/qa-service-bootstrap/src/main/resources/static/index.html create mode 100644 qa-service/qa-service-bootstrap/src/test/java/com/example/qa/service/bootstrap/QaServiceBootstrapApplicationTests.java create mode 100644 qa-service/qa-service-common/.gitignore create mode 100644 qa-service/qa-service-common/pom.xml create mode 100644 qa-service/qa-service-domain/.gitignore create mode 100644 qa-service/qa-service-domain/pom.xml create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaListPort.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/Answer.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaId.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/Question.java diff --git a/.idea/compiler.xml b/.idea/compiler.xml index a1757ae..b8cc292 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -3,6 +3,24 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml index da0415a..f36de08 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,4 +1,48 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index c4be5fb..514d7a6 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,5 +1,6 @@ + diff --git a/.idea/misc.xml b/.idea/misc.xml index 7280f00..94dc7f3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,39 @@ - - \ No newline at end of file diff --git a/qa-service/pom.xml b/qa-service/pom.xml index 0b70349..a335e77 100644 --- a/qa-service/pom.xml +++ b/qa-service/pom.xml @@ -8,25 +8,32 @@ qa-service qa-service - 17 + 21 UTF-8 UTF-8 - 3.0.2 + 3.2.4 + 2023.0.1.0 + 2023.0.1 - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-test - test - - + pom + + + qa-service-application + qa-service-bootstrap + qa-service-adapter + qa-service-domain + qa-service-common + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + org.springframework.boot spring-boot-dependencies @@ -34,6 +41,19 @@ pom import + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + ${spring-cloud-alibaba.version} + pom + import + + + + com.baomidou + mybatis-plus-spring-boot3-starter + 3.5.14 + diff --git a/qa-service/qa-service-adapter/pom.xml b/qa-service/qa-service-adapter/pom.xml new file mode 100644 index 0000000..26ebd4b --- /dev/null +++ b/qa-service/qa-service-adapter/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + com.example + qa-service-adapter + 0.0.1-SNAPSHOT + qa-service-adapter + qa-service-adapter + + com.example + qa-service + 0.0.1-SNAPSHOT + + + pom + + + qa-adapter-in + qa-adapter-out + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + + + diff --git a/qa-service/qa-service-adapter/qa-adapter-in/.gitignore b/qa-service/qa-service-adapter/qa-adapter-in/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/qa-service/qa-service-adapter/qa-adapter-in/pom.xml b/qa-service/qa-service-adapter/qa-adapter-in/pom.xml new file mode 100644 index 0000000..cc4dfac --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + com.example + qa-adapter-in + 0.0.1-SNAPSHOT + qa-adapter-in + qa-adapter-in + + pom + + + com.example + qa-service-adapter + 0.0.1-SNAPSHOT + + + qa-adapter-in-web + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + + + + diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/.gitignore b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/pom.xml b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/pom.xml new file mode 100644 index 0000000..600d905 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + com.example + qa-adapter-in-web + 0.0.1-SNAPSHOT + qa-adapter-in-web + qa-adapter-in-web + + + + com.example + qa-adapter-in + 0.0.1-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + provided + + + org.projectlombok + lombok + + + + com.example + qa-service-application + 0.0.1-SNAPSHOT + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + + + diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java new file mode 100644 index 0000000..99bac8b --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java @@ -0,0 +1,25 @@ +package com.example.qa.adapter.in.web.demos.web.controller; + +import com.example.qa.service.application.port.in.GetQaListUseCase; +import com.example.qa.service.domain.Qa; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Slf4j +@RequestMapping("/qa") +@RestController +@RequiredArgsConstructor +public class QaController { + private final GetQaListUseCase getQaListUseCase; + @GetMapping("/get") + public List getQas() + { + log.info("getQas"); + return getQaListUseCase.getQas(); + } +} diff --git a/qa-service/qa-service-adapter/qa-adapter-out/pom.xml b/qa-service/qa-service-adapter/qa-adapter-out/pom.xml new file mode 100644 index 0000000..afd42e2 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + com.example + qa-adapter-out + 0.0.1-SNAPSHOT + qa-adapter-out + qa-adapter-out + + + pom + + + com.example + qa-service-adapter + 0.0.1-SNAPSHOT + + + qa-adapter-out-persistence + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + + + + diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/.gitignore b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/pom.xml b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/pom.xml new file mode 100644 index 0000000..1ae4d28 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + com.example + qa-adapter-out-persistence + 0.0.1-SNAPSHOT + qa-adapter-out-persistence + qa-adapter-out-persistence + + com.example + qa-adapter-out + 0.0.1-SNAPSHOT + + + + + + org.projectlombok + lombok + provided + + + + com.example + qa-service-domain + 0.0.1-SNAPSHOT + + + + com.baomidou + mybatis-plus-spring-boot3-starter + + + + com.mysql + mysql-connector-j + runtime + + + + 、 + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 17 + 17 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + com.example.qa.adapter.out.persistence.QaAdapterOutPersistenceApplication + true + + + + repackage + + repackage + + + + + + + + diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaListBridge.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaListBridge.java new file mode 100644 index 0000000..2431695 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaListBridge.java @@ -0,0 +1,27 @@ +package com.example.qa.adapter.out.persistence.bridge; + +import com.example.qa.adapter.out.persistence.convertor.QaConvertor; +import com.example.qa.adapter.out.persistence.entity.QaEntity; +import com.example.qa.adapter.out.persistence.mapper.QaMapper; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.port.GetQaListPort; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +@Component +public class GetQaListBridge implements GetQaListPort { + @Resource + private QaMapper qaMapper; + @Override + public List getQas() { + List qaEntities = qaMapper.selectList(null); + ArrayList qas = new ArrayList<>(); + qaEntities.forEach(qaEntity -> { + Qa qa = QaConvertor.toDomain(qaEntity); + qas.add(qa); + }); + return qas; + } +} diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/convertor/QaConvertor.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/convertor/QaConvertor.java new file mode 100644 index 0000000..9b52dd6 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/convertor/QaConvertor.java @@ -0,0 +1,24 @@ +package com.example.qa.adapter.out.persistence.convertor; + +import com.example.qa.adapter.out.persistence.entity.QaEntity; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.valueobject.Answer; +import com.example.qa.service.domain.valueobject.QaId; +import com.example.qa.service.domain.valueobject.Question; + +public class QaConvertor { + public static Qa toDomain(QaEntity qaEntity){ + return new Qa( + new Answer(qaEntity.getAnswer()), + new QaId(qaEntity.getId()), + new Question(qaEntity.getQuestion()) + ); + } + public static QaEntity toEntity(Qa qa){ + return new QaEntity( + qa.getId().id(), + qa.getQuestion().question(), + qa.getAnswer().answer() + ); + } +} diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/entity/QaEntity.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/entity/QaEntity.java new file mode 100644 index 0000000..f82648c --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/entity/QaEntity.java @@ -0,0 +1,19 @@ +package com.example.qa.adapter.out.persistence.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("qa") +public class QaEntity { + @TableId(type= IdType.ASSIGN_ID) + private Long id; + private String question; + private String answer; +} diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/mapper/QaMapper.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/mapper/QaMapper.java new file mode 100644 index 0000000..4c2f4ab --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/mapper/QaMapper.java @@ -0,0 +1,7 @@ +package com.example.qa.adapter.out.persistence.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.example.qa.adapter.out.persistence.entity.QaEntity; + +public interface QaMapper extends BaseMapper { +} diff --git a/qa-service/qa-service-application/.gitignore b/qa-service/qa-service-application/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/qa-service/qa-service-application/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/qa-service/qa-service-application/pom.xml b/qa-service/qa-service-application/pom.xml new file mode 100644 index 0000000..bccb7b1 --- /dev/null +++ b/qa-service/qa-service-application/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + com.example + qa-service-application + 0.0.1-SNAPSHOT + qa-service-application + qa-service-application + + com.example + qa-service + 0.0.1-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + provided + + + + com.example + qa-service-domain + 0.0.1-SNAPSHOT + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + + + diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaListUseCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaListUseCase.java new file mode 100644 index 0000000..839e056 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaListUseCase.java @@ -0,0 +1,9 @@ +package com.example.qa.service.application.port.in; + +import com.example.qa.service.domain.Qa; + +import java.util.List; + +public interface GetQaListUseCase { + List getQas(); +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaListService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaListService.java new file mode 100644 index 0000000..71e428e --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaListService.java @@ -0,0 +1,19 @@ +package com.example.qa.service.application.service; + +import com.example.qa.service.application.port.in.GetQaListUseCase; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.port.GetQaListPort; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Component; + +import java.util.List; +@Component +public class GetQaListService implements GetQaListUseCase { + @Resource + private GetQaListPort getQaListPort; + @Override + public List getQas() { + List qas = Qa.getQas(getQaListPort); + return qas; + } +} diff --git a/qa-service/qa-service-bootstrap/.gitignore b/qa-service/qa-service-bootstrap/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/qa-service/qa-service-bootstrap/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/qa-service/qa-service-bootstrap/pom.xml b/qa-service/qa-service-bootstrap/pom.xml new file mode 100644 index 0000000..4069b26 --- /dev/null +++ b/qa-service/qa-service-bootstrap/pom.xml @@ -0,0 +1,84 @@ + + + 4.0.0 + com.example + qa-service-bootstrap + 0.0.1-SNAPSHOT + qa-service-bootstrap + qa-service-bootstrap + + com.example + qa-service + 0.0.1-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.example + qa-adapter-in-web + 0.0.1-SNAPSHOT + + + + com.example + qa-adapter-out-persistence + 0.0.1-SNAPSHOT + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + com.example.user.service.bootstrap.UserServiceBootstrapApplication + false + + + + repackage + + repackage + + + + + + + + diff --git a/qa-service/qa-service-bootstrap/src/main/java/com/example/qa/service/bootstrap/QaServiceBootstrapApplication.java b/qa-service/qa-service-bootstrap/src/main/java/com/example/qa/service/bootstrap/QaServiceBootstrapApplication.java new file mode 100644 index 0000000..714d3f9 --- /dev/null +++ b/qa-service/qa-service-bootstrap/src/main/java/com/example/qa/service/bootstrap/QaServiceBootstrapApplication.java @@ -0,0 +1,15 @@ +package com.example.qa.service.bootstrap; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication(scanBasePackages = "com.example") +@MapperScan("com.example.qa.adapter.out.persistence.mapper") +public class QaServiceBootstrapApplication { + + public static void main(String[] args) { + SpringApplication.run(QaServiceBootstrapApplication.class, args); + } + +} diff --git a/qa-service/qa-service-bootstrap/src/main/resources/application.properties b/qa-service/qa-service-bootstrap/src/main/resources/application.properties new file mode 100644 index 0000000..9e6a2fb --- /dev/null +++ b/qa-service/qa-service-bootstrap/src/main/resources/application.properties @@ -0,0 +1,33 @@ +server.port=28081 + +spring.application.name=qa-service +spring.datasource.url=jdbc:mysql://localhost:3306/shixun +spring.datasource.username=root +spring.datasource.password=root +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + +## Nacos\u8BA4\u8BC1\u4FE1\u606F +#spring.cloud.nacos.discovery.username=nacos +#spring.cloud.nacos.discovery.password=nacos +## Nacos \u670D\u52A1\u53D1\u73B0\u4E0E\u6CE8\u518C\u914D\u7F6E\uFF0C\u5176\u4E2D\u5B50\u5C5E\u6027 server-addr \u6307\u5B9A Nacos \u670D\u52A1\u5668\u4E3B\u673A\u548C\u7AEF\u53E3 +#spring.cloud.nacos.discovery.server-addr=localhost:8848 +## \u6CE8\u518C\u5230 nacos \u7684\u6307\u5B9A namespace\uFF0C\u9ED8\u8BA4\u4E3A public +#spring.cloud.nacos.discovery.namespace=public +# +## Nacos\u5E2E\u52A9\u6587\u6863: https://nacos.io/zh-cn/docs/concepts.html +## Nacos\u8BA4\u8BC1\u4FE1\u606F +#spring.cloud.nacos.config.username=nacos +#spring.cloud.nacos.config.password=nacos +#spring.cloud.nacos.config.contextPath=/nacos +## \u8BBE\u7F6E\u914D\u7F6E\u4E2D\u5FC3\u670D\u52A1\u7AEF\u5730\u5740 +#spring.cloud.nacos.config.server-addr=localhost::8848 +## Nacos \u914D\u7F6E\u4E2D\u5FC3\u7684namespace\u3002\u9700\u8981\u6CE8\u610F\uFF0C\u5982\u679C\u4F7F\u7528 public \u7684 namcespace \uFF0C\u8BF7\u4E0D\u8981\u586B\u5199\u8FD9\u4E2A\u503C\uFF0C\u76F4\u63A5\u7559\u7A7A\u5373\u53EF +## spring.cloud.nacos.config.namespace= +#spring.config.import=nacos:${spring.application.name}.properties?refresh=true + + + + + + + diff --git a/qa-service/qa-service-bootstrap/src/main/resources/static/index.html b/qa-service/qa-service-bootstrap/src/main/resources/static/index.html new file mode 100644 index 0000000..89bb8ba --- /dev/null +++ b/qa-service/qa-service-bootstrap/src/main/resources/static/index.html @@ -0,0 +1,6 @@ + + +

hello word!!!

+

this is a html page

+ + \ No newline at end of file diff --git a/qa-service/qa-service-bootstrap/src/test/java/com/example/qa/service/bootstrap/QaServiceBootstrapApplicationTests.java b/qa-service/qa-service-bootstrap/src/test/java/com/example/qa/service/bootstrap/QaServiceBootstrapApplicationTests.java new file mode 100644 index 0000000..153ddf1 --- /dev/null +++ b/qa-service/qa-service-bootstrap/src/test/java/com/example/qa/service/bootstrap/QaServiceBootstrapApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.qa.service.bootstrap; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class QaServiceBootstrapApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/qa-service/qa-service-common/.gitignore b/qa-service/qa-service-common/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/qa-service/qa-service-common/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/qa-service/qa-service-common/pom.xml b/qa-service/qa-service-common/pom.xml new file mode 100644 index 0000000..aeb6c42 --- /dev/null +++ b/qa-service/qa-service-common/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + com.example + qa-service-common + 0.0.1-SNAPSHOT + qa-service-common + qa-service-common + + + com.example + qa-service + 0.0.1-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + + + diff --git a/qa-service/qa-service-domain/.gitignore b/qa-service/qa-service-domain/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/qa-service/qa-service-domain/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/qa-service/qa-service-domain/pom.xml b/qa-service/qa-service-domain/pom.xml new file mode 100644 index 0000000..a561c5e --- /dev/null +++ b/qa-service/qa-service-domain/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + com.example + qa-service-domain + 0.0.1-SNAPSHOT + qa-service-domain + qa-service-domain + + + com.example + qa-service + 0.0.1-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + provided + + + + com.example + qa-service-common + 0.0.1-SNAPSHOT + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + + + + diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java new file mode 100644 index 0000000..44f30ac --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java @@ -0,0 +1,32 @@ +package com.example.qa.service.domain; + +import com.example.qa.service.domain.port.GetQaListPort; +import com.example.qa.service.domain.valueobject.Answer; +import com.example.qa.service.domain.valueobject.QaId; +import com.example.qa.service.domain.valueobject.Question; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.util.List; + +@Setter +@Getter +@ToString +public class Qa { + private QaId id; + private Question question; + private Answer answer; + + public Qa() { + } + + public Qa(Answer answer, QaId id, Question question) { + this.answer = answer; + this.id = id; + this.question = question; + } + public static List getQas(GetQaListPort getQaListPort) { + return getQaListPort.getQas(); + } +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaListPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaListPort.java new file mode 100644 index 0000000..ad52920 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaListPort.java @@ -0,0 +1,9 @@ +package com.example.qa.service.domain.port; + +import com.example.qa.service.domain.Qa; + +import java.util.List; + +public interface GetQaListPort { + List getQas(); +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/Answer.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/Answer.java new file mode 100644 index 0000000..4d0e1d4 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/Answer.java @@ -0,0 +1,7 @@ +package com.example.qa.service.domain.valueobject; + +public record Answer(String answer) { + public String getValue() { + return answer; + } +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaId.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaId.java new file mode 100644 index 0000000..69700f0 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaId.java @@ -0,0 +1,7 @@ +package com.example.qa.service.domain.valueobject; + +public record QaId (Long id){ + public Long getValue() { + return id; + } +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/Question.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/Question.java new file mode 100644 index 0000000..27bbf25 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/Question.java @@ -0,0 +1,7 @@ +package com.example.qa.service.domain.valueobject; + +public record Question(String question ) { + public String getValue() { + return question; + } +} -- Gitee From 12366af16d5962293a67d607551f4d1da1768236 Mon Sep 17 00:00:00 2001 From: yeguiyang Date: Wed, 10 Sep 2025 21:36:31 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E6=96=B0=E5=A2=9E-=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=89=80=E6=9C=89=E9=97=AE=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/in/web/demos/web/controller/QaController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java index 99bac8b..5f8f768 100644 --- a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java @@ -16,6 +16,12 @@ import java.util.List; @RequiredArgsConstructor public class QaController { private final GetQaListUseCase getQaListUseCase; + + /** + * author: yeguiyang + * 获取所有问答 + * @return + */ @GetMapping("/get") public List getQas() { -- Gitee From da074afdaeb1d37e0a3478f94119560c7d979605 Mon Sep 17 00:00:00 2001 From: yeguiyang Date: Wed, 10 Sep 2025 22:45:37 +0800 Subject: [PATCH 03/12] =?UTF-8?q?feat(qa-service):=20=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=8D=95=E4=B8=AA=E9=97=AE=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通过传入id进行查询对应问答 [skip ci] --- .../demos/web/controller/QaController.java | 16 ++++++++++++++ .../persistence/bridge/GetQaListBridge.java | 2 ++ .../persistence/bridge/GetQaoneBridge.java | 21 +++++++++++++++++++ .../application/port/in/GetQaoneUseCase.java | 9 ++++++++ .../application/service/GeQaoneService.java | 19 +++++++++++++++++ .../qa/service/domain/port/GetQaonePort.java | 10 +++++++++ 6 files changed, 77 insertions(+) create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaoneBridge.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaoneUseCase.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GeQaoneService.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaonePort.java diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java index 5f8f768..6f3e291 100644 --- a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java @@ -1,10 +1,13 @@ package com.example.qa.adapter.in.web.demos.web.controller; import com.example.qa.service.application.port.in.GetQaListUseCase; +import com.example.qa.service.application.port.in.GetQaoneUseCase; import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.valueobject.QaId; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -16,6 +19,7 @@ import java.util.List; @RequiredArgsConstructor public class QaController { private final GetQaListUseCase getQaListUseCase; + private final GetQaoneUseCase getQaoneUseCase; /** * author: yeguiyang @@ -28,4 +32,16 @@ public class QaController { log.info("getQas"); return getQaListUseCase.getQas(); } + + /** + * author: liwenchao + * 获取单个问答 + * @return + */ + @GetMapping("/getone/{id}") + public Qa getQa(@PathVariable("id") long id) + { + log.info("getQa"); + return getQaoneUseCase.getQa( id); + } } diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaListBridge.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaListBridge.java index 2431695..7d81415 100644 --- a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaListBridge.java +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaListBridge.java @@ -24,4 +24,6 @@ public class GetQaListBridge implements GetQaListPort { }); return qas; } + + } diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaoneBridge.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaoneBridge.java new file mode 100644 index 0000000..16ef880 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaoneBridge.java @@ -0,0 +1,21 @@ +package com.example.qa.adapter.out.persistence.bridge; + +import com.example.qa.adapter.out.persistence.convertor.QaConvertor; +import com.example.qa.adapter.out.persistence.entity.QaEntity; +import com.example.qa.adapter.out.persistence.mapper.QaMapper; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.port.GetQaonePort; +import com.example.qa.service.domain.valueobject.QaId; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Component; + +@Component +public class GetQaoneBridge implements GetQaonePort { + @Resource + private QaMapper qaMapper; + @Override + public Qa getQa(long id) { + QaEntity qaEntity = qaMapper.selectById(id); + return QaConvertor.toDomain(qaEntity); + } +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaoneUseCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaoneUseCase.java new file mode 100644 index 0000000..8b003c3 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaoneUseCase.java @@ -0,0 +1,9 @@ +package com.example.qa.service.application.port.in; + +import com.example.qa.service.domain.Qa; + +import com.example.qa.service.domain.valueobject.QaId; + +public interface GetQaoneUseCase { + Qa getQa(Long id); +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GeQaoneService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GeQaoneService.java new file mode 100644 index 0000000..7e30f39 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GeQaoneService.java @@ -0,0 +1,19 @@ +package com.example.qa.service.application.service; + +import com.example.qa.service.application.port.in.GetQaoneUseCase; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.port.GetQaonePort; +import com.example.qa.service.domain.valueobject.QaId; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Component; + +@Component +public class GeQaoneService implements GetQaoneUseCase { + @Resource + private GetQaonePort getQaonePort; + @Override + public Qa getQa(Long id) + { + return getQaonePort.getQa(id); + } +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaonePort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaonePort.java new file mode 100644 index 0000000..e0353b5 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaonePort.java @@ -0,0 +1,10 @@ +package com.example.qa.service.domain.port; + +import com.example.qa.service.domain.Qa; + +import com.example.qa.service.domain.valueobject.QaId; + +public interface GetQaonePort { + + Qa getQa(long id); +} -- Gitee From adc111050081ed52b9c10c800a3167234f6ad329 Mon Sep 17 00:00:00 2001 From: yeguiyang Date: Wed, 10 Sep 2025 22:49:43 +0800 Subject: [PATCH 04/12] =?UTF-8?q?docs(qa-service):=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [skip ci] --- .../qa/adapter/in/web/demos/web/controller/QaController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java index 6f3e291..0026db5 100644 --- a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java @@ -23,7 +23,7 @@ public class QaController { /** * author: yeguiyang - * 获取所有问答 + * 获取所有问答() * @return */ @GetMapping("/get") -- Gitee From abdfd6ac97cadba1cf5aff793f87dd9c3c6702d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E7=85=9C=E5=9F=8E?= <2777362942@qq.com> Date: Wed, 10 Sep 2025 22:59:50 +0800 Subject: [PATCH 05/12] =?UTF-8?q?feat(qa-service):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=89=80=E6=9C=89=E9=97=AE=E7=AD=94=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [skip ci] --- .idea/compiler.xml | 1 - .idea/encodings.xml | 3 +-- .idea/gradle.xml | 7 ------ .idea/misc.xml | 23 ------------------- .../demos/web/controller/QaController.java | 14 +++++++++++ .../bridge/DeleteAllQasBridge.java | 18 +++++++++++++++ .../port/in/DeleteAllQasUseCase.java | 5 ++++ .../service/DeleteAllQasService.java | 19 +++++++++++++++ .../com/example/qa/service/domain/Qa.java | 4 ++++ .../service/domain/port/DeleteAllQasPort.java | 5 ++++ 10 files changed, 66 insertions(+), 33 deletions(-) delete mode 100644 .idea/gradle.xml create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/DeleteAllQasBridge.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/DeleteAllQasUseCase.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/DeleteAllQasService.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteAllQasPort.java diff --git a/.idea/compiler.xml b/.idea/compiler.xml index b8cc292..fd35b9d 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/encodings.xml b/.idea/encodings.xml index f36de08..1b31288 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,6 +1,6 @@ - + @@ -43,6 +43,5 @@ - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 514d7a6..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 94dc7f3..1c1a792 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,33 +7,10 @@ - - - - - - 用户定义 - - - - - - - \ No newline at end of file diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java index 0026db5..618ad30 100644 --- a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java @@ -1,11 +1,13 @@ package com.example.qa.adapter.in.web.demos.web.controller; +import com.example.qa.service.application.port.in.DeleteAllQasUseCase; import com.example.qa.service.application.port.in.GetQaListUseCase; import com.example.qa.service.application.port.in.GetQaoneUseCase; import com.example.qa.service.domain.Qa; import com.example.qa.service.domain.valueobject.QaId; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -21,6 +23,7 @@ public class QaController { private final GetQaListUseCase getQaListUseCase; private final GetQaoneUseCase getQaoneUseCase; + private final DeleteAllQasUseCase deleteAllQasUseCase; /** * author: yeguiyang * 获取所有问答() @@ -44,4 +47,15 @@ public class QaController { log.info("getQa"); return getQaoneUseCase.getQa( id); } + + /** + * author: suyucheng + * 删除所有问答 + */ + @DeleteMapping("/delete-all") + public void deleteAllQas() + { + log.info("deleteAllQas"); + deleteAllQasUseCase.deleteAllQas(); + } } diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/DeleteAllQasBridge.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/DeleteAllQasBridge.java new file mode 100644 index 0000000..67b8d7b --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/DeleteAllQasBridge.java @@ -0,0 +1,18 @@ +package com.example.qa.adapter.out.persistence.bridge; + +import com.example.qa.adapter.out.persistence.mapper.QaMapper; +import com.example.qa.service.domain.port.DeleteAllQasPort; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Component; + +@Component +public class DeleteAllQasBridge implements DeleteAllQasPort { + + @Resource + private QaMapper qaMapper; + + @Override + public void deleteAllQas() { + qaMapper.delete(null); + } +} \ No newline at end of file diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/DeleteAllQasUseCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/DeleteAllQasUseCase.java new file mode 100644 index 0000000..5d25d7e --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/DeleteAllQasUseCase.java @@ -0,0 +1,5 @@ +package com.example.qa.service.application.port.in; + +public interface DeleteAllQasUseCase { + void deleteAllQas(); +} \ No newline at end of file diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/DeleteAllQasService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/DeleteAllQasService.java new file mode 100644 index 0000000..2561ac1 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/DeleteAllQasService.java @@ -0,0 +1,19 @@ +package com.example.qa.service.application.service; + +import com.example.qa.service.application.port.in.DeleteAllQasUseCase; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.port.DeleteAllQasPort; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Component; + +@Component +public class DeleteAllQasService implements DeleteAllQasUseCase { + + @Resource + private DeleteAllQasPort deleteAllQasPort; + + @Override + public void deleteAllQas() { + Qa.deleteAllQas(deleteAllQasPort); + } +} \ No newline at end of file diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java index 44f30ac..fcd10d6 100644 --- a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java @@ -1,5 +1,6 @@ package com.example.qa.service.domain; +import com.example.qa.service.domain.port.DeleteAllQasPort; import com.example.qa.service.domain.port.GetQaListPort; import com.example.qa.service.domain.valueobject.Answer; import com.example.qa.service.domain.valueobject.QaId; @@ -29,4 +30,7 @@ public class Qa { public static List getQas(GetQaListPort getQaListPort) { return getQaListPort.getQas(); } + public static void deleteAllQas(DeleteAllQasPort deleteAllQasPort) { + deleteAllQasPort.deleteAllQas(); + } } diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteAllQasPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteAllQasPort.java new file mode 100644 index 0000000..854a127 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteAllQasPort.java @@ -0,0 +1,5 @@ +package com.example.qa.service.domain.port; + +public interface DeleteAllQasPort { + void deleteAllQas(); +} \ No newline at end of file -- Gitee From d3c55d33fe47471f0abbf4941735c245cb08e310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8B=BE=E8=87=B3=E5=90=8D=E7=91=B0?= <1481605717@qq.com> Date: Wed, 10 Sep 2025 23:14:17 +0800 Subject: [PATCH 06/12] =?UTF-8?q?feat(qa-service):=20=E5=88=A0=E9=99=A4qa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根据id删除单个qa [skip ci] --- .../demos/web/controller/QaController.java | 15 +++++++++++++++ .../persistence/bridge/DeleteOneQaBridge.java | 19 +++++++++++++++++++ .../port/in/DeleteOneQaUseCase.java | 5 +++++ .../application/service/DeleteOneService.java | 16 ++++++++++++++++ .../service/domain/port/DeleteOneQaPort.java | 5 +++++ 5 files changed, 60 insertions(+) create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/DeleteOneQaBridge.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/DeleteOneQaUseCase.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/DeleteOneService.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteOneQaPort.java diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java index 618ad30..8193029 100644 --- a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java @@ -1,5 +1,6 @@ package com.example.qa.adapter.in.web.demos.web.controller; +import com.example.qa.service.application.port.in.DeleteOneQaUseCase; import com.example.qa.service.application.port.in.DeleteAllQasUseCase; import com.example.qa.service.application.port.in.GetQaListUseCase; import com.example.qa.service.application.port.in.GetQaoneUseCase; @@ -12,6 +13,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -21,6 +23,7 @@ import java.util.List; @RequiredArgsConstructor public class QaController { private final GetQaListUseCase getQaListUseCase; + private final DeleteOneQaUseCase deleteOneQaUseCase; private final GetQaoneUseCase getQaoneUseCase; private final DeleteAllQasUseCase deleteAllQasUseCase; @@ -58,4 +61,16 @@ public class QaController { log.info("deleteAllQas"); deleteAllQasUseCase.deleteAllQas(); } + /** + * author: wujiajun + * 删除单个数据 + * @return + */ + @DeleteMapping("/deletebyid/{id}") + public void deleteOneQa(@PathVariable("id") Long id) + { + log.info("deleteOneQa"); + deleteOneQaUseCase.deleteOneQa(id); + } + } diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/DeleteOneQaBridge.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/DeleteOneQaBridge.java new file mode 100644 index 0000000..d89f603 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/DeleteOneQaBridge.java @@ -0,0 +1,19 @@ +package com.example.qa.adapter.out.persistence.bridge; + +import com.example.qa.adapter.out.persistence.mapper.QaMapper; +import com.example.qa.service.domain.port.DeleteOneQaPort; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class DeleteOneQaBridge implements DeleteOneQaPort { + @Resource + private QaMapper qaMapper; + @Override + public void deleteOneQa(Long id) { + int result = qaMapper.deleteById(id); + log.info("result:{}",result); + } +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/DeleteOneQaUseCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/DeleteOneQaUseCase.java new file mode 100644 index 0000000..f10d7f1 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/DeleteOneQaUseCase.java @@ -0,0 +1,5 @@ +package com.example.qa.service.application.port.in; + +public interface DeleteOneQaUseCase { + void deleteOneQa(Long id); +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/DeleteOneService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/DeleteOneService.java new file mode 100644 index 0000000..33da309 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/DeleteOneService.java @@ -0,0 +1,16 @@ +package com.example.qa.service.application.service; + +import com.example.qa.service.application.port.in.DeleteOneQaUseCase; +import com.example.qa.service.domain.port.DeleteOneQaPort; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Component; + +@Component +public class DeleteOneService implements DeleteOneQaUseCase { + @Resource + private DeleteOneQaPort deleteOneQaPort; + @Override + public void deleteOneQa(Long id) { + deleteOneQaPort.deleteOneQa(id); + } +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteOneQaPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteOneQaPort.java new file mode 100644 index 0000000..b856a1f --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteOneQaPort.java @@ -0,0 +1,5 @@ +package com.example.qa.service.domain.port; + +public interface DeleteOneQaPort { + void deleteOneQa(Long id); +} -- Gitee From 5b48909526d0fadabd95424d987ca577aed1b868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=8F=E5=85=8B=E6=96=AF?= <13415370+foooooxxxx@user.noreply.gitee.com> Date: Wed, 10 Sep 2025 23:32:07 +0800 Subject: [PATCH 07/12] =?UTF-8?q?feat(qa-service):=20qa=E6=A0=B9=E6=8D=AEi?= =?UTF-8?q?d=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [skip ci] --- .../demos/web/controller/QaController.java | 18 ++++++++++ .../in/web/demos/web/dto/QasUpdateDto.java | 17 ++++++++++ .../out/persistence/bridge/UpdateQaBrige.java | 27 +++++++++++++++ .../application/command/UpdateQasCommand.java | 14 ++++++++ .../application/port/in/GetQaListUseCase.java | 3 ++ .../application/port/in/UpdateQasUseCase.java | 7 ++++ .../application/service/GetQaListService.java | 3 ++ .../service/UpdateQasUseService.java | 33 +++++++++++++++++++ .../qa/service/domain/port/UpdateQaPort.java | 7 ++++ 9 files changed, 129 insertions(+) create mode 100644 qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/dto/QasUpdateDto.java create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/UpdateQaBrige.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/UpdateQasCommand.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/UpdateQasUseCase.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/UpdateQasUseService.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/UpdateQaPort.java diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java index 8193029..118620f 100644 --- a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java @@ -1,13 +1,17 @@ package com.example.qa.adapter.in.web.demos.web.controller; +import com.example.qa.adapter.in.web.demos.web.dto.QasUpdateDto; +import com.example.qa.service.application.command.UpdateQasCommand; import com.example.qa.service.application.port.in.DeleteOneQaUseCase; import com.example.qa.service.application.port.in.DeleteAllQasUseCase; import com.example.qa.service.application.port.in.GetQaListUseCase; +import com.example.qa.service.application.port.in.UpdateQasUseCase; import com.example.qa.service.application.port.in.GetQaoneUseCase; import com.example.qa.service.domain.Qa; import com.example.qa.service.domain.valueobject.QaId; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -23,6 +27,7 @@ import java.util.List; @RequiredArgsConstructor public class QaController { private final GetQaListUseCase getQaListUseCase; + private final UpdateQasUseCase updateQasUseCase; private final DeleteOneQaUseCase deleteOneQaUseCase; private final GetQaoneUseCase getQaoneUseCase; @@ -39,6 +44,19 @@ public class QaController { return getQaListUseCase.getQas(); } + @PostMapping("/update") + public void updateQas(@RequestBody QasUpdateDto qasUpdateDto) + { + log.info("updateQas"); + UpdateQasCommand updateQasCommand=UpdateQasCommand.builder() + .id(qasUpdateDto.getId()) + .question(qasUpdateDto.getQuestion()) + .answer(qasUpdateDto.getAnswer()) + .build(); + updateQasUseCase.updateQas(updateQasCommand); + } + + /** * author: liwenchao * 获取单个问答 diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/dto/QasUpdateDto.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/dto/QasUpdateDto.java new file mode 100644 index 0000000..f723c22 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/dto/QasUpdateDto.java @@ -0,0 +1,17 @@ +package com.example.qa.adapter.in.web.demos.web.dto; + +import lombok.Data; + +/** + * @program: qa-sys + * @description: + * @author: fks + * @create: 2025-09-10 22:56 + **/ +@Data +public class QasUpdateDto { + Integer id; + String question; + String answer; + +} diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/UpdateQaBrige.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/UpdateQaBrige.java new file mode 100644 index 0000000..8894078 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/UpdateQaBrige.java @@ -0,0 +1,27 @@ +package com.example.qa.adapter.out.persistence.bridge; + +import com.example.qa.adapter.out.persistence.convertor.QaConvertor; +import com.example.qa.adapter.out.persistence.mapper.QaMapper; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.port.UpdateQaPort; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * @program: qa-sys + * @description: + * @author: fks + * @create: 2025-09-10 23:13 + **/ +@Slf4j +@Component +public class UpdateQaBrige implements UpdateQaPort { + @Resource + QaMapper qaMapper; + @Override + public void updateQa(Qa qa) { + int result = qaMapper.updateById(QaConvertor.toEntity(qa)); + log.info("result:{}",result); + } +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/UpdateQasCommand.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/UpdateQasCommand.java new file mode 100644 index 0000000..9ee58b6 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/UpdateQasCommand.java @@ -0,0 +1,14 @@ +package com.example.qa.service.application.command; + +import lombok.Builder; + +/** + * @program: qa-sys + * @description: + * @author: fks + * @create: 2025-09-10 23:00 + **/ +@Builder +public record UpdateQasCommand(Integer id, + String question, + String answer) {} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaListUseCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaListUseCase.java index 839e056..b3ad625 100644 --- a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaListUseCase.java +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaListUseCase.java @@ -1,9 +1,12 @@ package com.example.qa.service.application.port.in; +import com.example.qa.service.application.command.UpdateQasCommand; import com.example.qa.service.domain.Qa; import java.util.List; public interface GetQaListUseCase { List getQas(); + + } diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/UpdateQasUseCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/UpdateQasUseCase.java new file mode 100644 index 0000000..f335aa0 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/UpdateQasUseCase.java @@ -0,0 +1,7 @@ +package com.example.qa.service.application.port.in; + +import com.example.qa.service.application.command.UpdateQasCommand; + +public interface UpdateQasUseCase { + Void updateQas(UpdateQasCommand qasUpdateDto); +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaListService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaListService.java index 71e428e..80c10fa 100644 --- a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaListService.java +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaListService.java @@ -1,5 +1,6 @@ package com.example.qa.service.application.service; +import com.example.qa.service.application.command.UpdateQasCommand; import com.example.qa.service.application.port.in.GetQaListUseCase; import com.example.qa.service.domain.Qa; import com.example.qa.service.domain.port.GetQaListPort; @@ -16,4 +17,6 @@ public class GetQaListService implements GetQaListUseCase { List qas = Qa.getQas(getQaListPort); return qas; } + + } diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/UpdateQasUseService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/UpdateQasUseService.java new file mode 100644 index 0000000..eb7410b --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/UpdateQasUseService.java @@ -0,0 +1,33 @@ +package com.example.qa.service.application.service; + +import com.example.qa.service.application.command.UpdateQasCommand; +import com.example.qa.service.application.port.in.UpdateQasUseCase; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.port.UpdateQaPort; +import com.example.qa.service.domain.valueobject.Answer; +import com.example.qa.service.domain.valueobject.QaId; +import com.example.qa.service.domain.valueobject.Question; +import jakarta.annotation.Resource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @program: qa-sys + * @description: + * @author: fks + * @create: 2025-09-10 23:09 + **/ +@Component +public class UpdateQasUseService implements UpdateQasUseCase { + @Resource + private UpdateQaPort updateQaPort; + @Override + public Void updateQas(UpdateQasCommand command) { + Qa qa = new Qa( + new Answer(command.answer()), + new QaId(command.id().longValue()), + new Question(command.question())); + updateQaPort.updateQa(qa); + return null; + } +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/UpdateQaPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/UpdateQaPort.java new file mode 100644 index 0000000..974c5f6 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/UpdateQaPort.java @@ -0,0 +1,7 @@ +package com.example.qa.service.domain.port; + +import com.example.qa.service.domain.Qa; + +public interface UpdateQaPort { + void updateQa(Qa qa); +} -- Gitee From fa78750a6b9466354624c799af8700f166e4b9a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=8F=E5=85=8B=E6=96=AF?= <13415370+foooooxxxx@user.noreply.gitee.com> Date: Wed, 10 Sep 2025 23:35:09 +0800 Subject: [PATCH 08/12] =?UTF-8?q?docs(qa-service):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B3=A8=E9=87=8Aqa=E6=A0=B9=E6=8D=AEid=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [skip ci] --- .../qa/adapter/in/web/demos/web/controller/QaController.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java index 118620f..69f5f32 100644 --- a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java @@ -44,6 +44,11 @@ public class QaController { return getQaListUseCase.getQas(); } + /** + * author: 冯楷晟 + * 根据id更新问答 + * @return + */ @PostMapping("/update") public void updateQas(@RequestBody QasUpdateDto qasUpdateDto) { -- Gitee From 6c229c9dc0457e9b6fcdb0ceb12b740a89b3d530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?snfx=E5=BC=A0?= <1844395214@qq.com> Date: Wed, 10 Sep 2025 23:57:45 +0800 Subject: [PATCH 09/12] =?UTF-8?q?feat(qa-service):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=97=AE=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [skip ci] --- .../demos/web/controller/QaController.java | 18 ++++++++++++ .../controller/dto/CreateQaRequestDTO.java | 8 +++++ .../persistence/bridge/CreateQaBridge.java | 24 +++++++++++++++ qa-service/qa-service-application/pom.xml | 6 ++++ .../application/command/CreateQaCommand.java | 12 ++++++++ .../application/port/in/CreateQaCase.java | 8 +++++ .../application/service/CreateQaService.java | 29 +++++++++++++++++++ .../com/example/qa/service/domain/Qa.java | 6 ++++ .../qa/service/domain/port/CreateQaPort.java | 7 +++++ 9 files changed, 118 insertions(+) create mode 100644 qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/dto/CreateQaRequestDTO.java create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/CreateQaBridge.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/CreateQaCommand.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/CreateQaCase.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/CreateQaService.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateQaPort.java diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java index 69f5f32..2ec20cd 100644 --- a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java @@ -1,5 +1,8 @@ package com.example.qa.adapter.in.web.demos.web.controller; +import com.example.qa.adapter.in.web.demos.web.controller.dto.CreateQaRequestDTO; +import com.example.qa.service.application.command.CreateQaCommand; +import com.example.qa.service.application.port.in.CreateQaCase; import com.example.qa.adapter.in.web.demos.web.dto.QasUpdateDto; import com.example.qa.service.application.command.UpdateQasCommand; import com.example.qa.service.application.port.in.DeleteOneQaUseCase; @@ -12,6 +15,7 @@ import com.example.qa.service.domain.valueobject.QaId; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -32,6 +36,7 @@ public class QaController { private final GetQaoneUseCase getQaoneUseCase; private final DeleteAllQasUseCase deleteAllQasUseCase; + private final CreateQaCase createQaCase; /** * author: yeguiyang * 获取所有问答() @@ -43,6 +48,19 @@ public class QaController { log.info("getQas"); return getQaListUseCase.getQas(); } + /** + * author: zhangyi + * 新增问答 + * @return + */ + @PostMapping("/add") + public Qa createQa(@RequestBody CreateQaRequestDTO createQaRequestDTO){ + CreateQaCommand command= CreateQaCommand.builder() + .question(createQaRequestDTO.question()) + .answer(createQaRequestDTO.answer()) + .build(); + return createQaCase.createQa(command); + } /** * author: 冯楷晟 diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/dto/CreateQaRequestDTO.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/dto/CreateQaRequestDTO.java new file mode 100644 index 0000000..4d248f1 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/dto/CreateQaRequestDTO.java @@ -0,0 +1,8 @@ +package com.example.qa.adapter.in.web.demos.web.controller.dto; + + +public record CreateQaRequestDTO (String question, + String answer +){ + +} diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/CreateQaBridge.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/CreateQaBridge.java new file mode 100644 index 0000000..6781851 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/CreateQaBridge.java @@ -0,0 +1,24 @@ +package com.example.qa.adapter.out.persistence.bridge; + +import com.example.qa.adapter.out.persistence.convertor.QaConvertor; +import com.example.qa.adapter.out.persistence.entity.QaEntity; +import com.example.qa.adapter.out.persistence.mapper.QaMapper; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.port.CreateQaPort; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class CreateQaBridge implements CreateQaPort { + @Resource + private QaMapper qaMapper; + @Override + public Qa createQa(Qa qa) { + QaEntity qaEntity = QaConvertor.toEntity(qa); + int result = qaMapper.insert(qaEntity); + log.info("result:{}",result); + return qa; + } +} diff --git a/qa-service/qa-service-application/pom.xml b/qa-service/qa-service-application/pom.xml index bccb7b1..b65c070 100644 --- a/qa-service/qa-service-application/pom.xml +++ b/qa-service/qa-service-application/pom.xml @@ -34,6 +34,12 @@ qa-service-domain 0.0.1-SNAPSHOT + + com.example + qa-service-application + 0.0.1-SNAPSHOT + compile + diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/CreateQaCommand.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/CreateQaCommand.java new file mode 100644 index 0000000..140d393 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/CreateQaCommand.java @@ -0,0 +1,12 @@ +package com.example.qa.service.application.command; + +import lombok.Builder; + +@Builder +public record CreateQaCommand( + Long id, + String question, + String answer + +) { +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/CreateQaCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/CreateQaCase.java new file mode 100644 index 0000000..2639907 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/CreateQaCase.java @@ -0,0 +1,8 @@ +package com.example.qa.service.application.port.in; + +import com.example.qa.service.application.command.CreateQaCommand; +import com.example.qa.service.domain.Qa; + +public interface CreateQaCase { + Qa createQa(CreateQaCommand createQaCommand); +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/CreateQaService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/CreateQaService.java new file mode 100644 index 0000000..29327e8 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/CreateQaService.java @@ -0,0 +1,29 @@ +package com.example.qa.service.application.service; + +import com.example.qa.service.application.command.CreateQaCommand; +import com.example.qa.service.application.port.in.CreateQaCase; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.port.CreateQaPort; +import com.example.qa.service.domain.valueobject.Answer; +import com.example.qa.service.domain.valueobject.Question; + + +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class CreateQaService implements CreateQaCase { + @Resource + private CreateQaPort createQaPort; + @Override + public Qa createQa(CreateQaCommand createQaCommand) { + Qa qa = new Qa( + new Question(createQaCommand.question()), + new Answer(createQaCommand.answer()) + ); + log.info("question:{}",qa.getQuestion()); + return createQaPort.createQa(qa); + } +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java index fcd10d6..de96993 100644 --- a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java @@ -27,6 +27,12 @@ public class Qa { this.id = id; this.question = question; } + + public Qa(Question question, Answer answer) { + this.question = question; + this.answer = answer; + } + public static List getQas(GetQaListPort getQaListPort) { return getQaListPort.getQas(); } diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateQaPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateQaPort.java new file mode 100644 index 0000000..5ac3602 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateQaPort.java @@ -0,0 +1,7 @@ +package com.example.qa.service.domain.port; + +import com.example.qa.service.domain.Qa; + +public interface CreateQaPort { + Qa createQa(Qa qa); +} -- Gitee From 682a13203bfcde0dddfd53919c5748343aec7aa8 Mon Sep 17 00:00:00 2001 From: yeguiyang Date: Thu, 11 Sep 2025 00:09:38 +0800 Subject: [PATCH 10/12] =?UTF-8?q?fix(qa-service):=20=E4=BF=AE=E5=A4=8D-?= =?UTF-8?q?=E6=96=B0=E5=A2=9Eqa=E6=8F=92=E5=85=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [skip ci] --- .idea/misc.xml | 3 + .../qa/service/common/demos/web/IdWorker.java | 199 ++++++++++++++++++ .../com/example/qa/service/domain/Qa.java | 5 + 3 files changed, 207 insertions(+) create mode 100644 qa-service/qa-service-common/src/main/java/com/example/qa/service/common/demos/web/IdWorker.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 1c1a792..7c06679 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,4 +13,7 @@ + +
\ No newline at end of file diff --git a/qa-service/qa-service-common/src/main/java/com/example/qa/service/common/demos/web/IdWorker.java b/qa-service/qa-service-common/src/main/java/com/example/qa/service/common/demos/web/IdWorker.java new file mode 100644 index 0000000..c6d3735 --- /dev/null +++ b/qa-service/qa-service-common/src/main/java/com/example/qa/service/common/demos/web/IdWorker.java @@ -0,0 +1,199 @@ +package com.example.qa.service.common.demos.web; + +import java.lang.management.ManagementFactory; +import java.net.InetAddress; +import java.net.NetworkInterface; + +/** + * @author wuyunbin + *

名称:IdWorker.java

+ *

描述:分布式自增长ID

+ *
+ *     Twitter的 Snowflake JAVA实现方案
+ * 
+ * 核心代码为其IdWorker这个类实现,其原理结构如下,我分别用一个0表示一位,用—分割开部分的作用: + * 1||0---0000000000 0000000000 0000000000 0000000000 0 --- 00000 ---00000 ---000000000000 + * 在上面的字符串中,第一位为未使用(实际上也可作为long的符号位),接下来的41位为毫秒级时间, + * 然后5位datacenter标识位,5位机器ID(并不算标识符,实际是为线程标识), + * 然后12位该毫秒内的当前毫秒内的计数,加起来刚好64位,为一个Long型。 + * 这样的好处是,整体上按照时间自增排序,并且整个分布式系统内不会产生ID碰撞(由datacenter和机器ID作区分), + * 并且效率较高,经测试,snowflake每秒能够产生26万ID左右,完全满足需要。 + *

+ * 64位ID (42(毫秒)+5(机器ID)+5(业务编码)+12(重复累加)) + * @author Polim + */ +public class IdWorker { + /** + * 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动) + */ + private final static long TWEPOCH = 1288834974657L; + + /** + * 机器标识位数 + */ + private final static long WORKER_ID_BITS = 5L; + + /** + * 数据中心标识位数 + */ + private final static long DATA_CENTER_ID_BITS = 5L; + + /** + * 机器ID最大值 + */ + private final static long MAX_WORKER_ID = -1L ^ (-1L << WORKER_ID_BITS); + + /** + * 数据中心ID最大值 + */ + private final static long MAX_DATACENTER_ID = -1L ^ (-1L << DATA_CENTER_ID_BITS); + + /** + * 毫秒内自增位 + */ + private final static long SEQUENCE_BITS = 12L; + + /** + * 机器ID偏左移12位 + */ + private final static long WORKER_ID_SHIFT = SEQUENCE_BITS; + + /** + * 数据中心ID左移17位 + */ + private final static long DATACENTER_ID_SHIFT = SEQUENCE_BITS + WORKER_ID_BITS; + + /** + * 时间毫秒左移22位 + */ + private final static long TIMESTAMP_LEFT_SHIFT = SEQUENCE_BITS + WORKER_ID_BITS + DATA_CENTER_ID_BITS; + + private final static long SEQUENCE_MASK = ~(-1L << SEQUENCE_BITS); + + /** + * 上次生产id时间戳 + */ + private static long lastTimestamp = -1L; + + /** + * 0,并发控制 + */ + private long sequence = 0L; + + private final long workerId; + + /** + * 数据标识id部分 + */ + private final long datacenterId; + + public IdWorker() { + this.datacenterId = getDatacenterId(); + this.workerId = getMaxWorkerId(datacenterId); + } + + /** + * @param workerId 工作机器ID + * @param datacenterId 序列号 + */ + public IdWorker(long workerId, long datacenterId) { + if (workerId > MAX_WORKER_ID || workerId < 0) { + throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", MAX_WORKER_ID)); + } + if (datacenterId > MAX_DATACENTER_ID || datacenterId < 0) { + throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", MAX_DATACENTER_ID)); + } + this.workerId = workerId; + this.datacenterId = datacenterId; + } + + /** + * 获取下一个ID + * + * @return + */ + public synchronized long nextId() { + long timestamp = timeGen(); + if (timestamp < lastTimestamp) { + throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp)); + } + + if (lastTimestamp == timestamp) { + // 当前毫秒内,则+1 + sequence = (sequence + 1) & SEQUENCE_MASK; + if (sequence == 0) { + // 当前毫秒内计数满了,则等待下一秒 + timestamp = tilNextMillis(lastTimestamp); + } + } else { + sequence = 0L; + } + lastTimestamp = timestamp; + // ID偏移组合生成最终的ID,并返回ID + + return ((timestamp - TWEPOCH) << TIMESTAMP_LEFT_SHIFT) + | (datacenterId << DATACENTER_ID_SHIFT) + | (workerId << WORKER_ID_SHIFT) | sequence; + } + + private long tilNextMillis(final long lastTimestamp) { + long timestamp = this.timeGen(); + while (timestamp <= lastTimestamp) { + timestamp = this.timeGen(); + } + return timestamp; + } + + private long timeGen() { + return System.currentTimeMillis(); + } + + /** + *

+ * 获取 MAX_WORKER_ID + *

+ */ + protected static long getMaxWorkerId(long datacenterId) { + StringBuilder mpid = new StringBuilder(); + mpid.append(datacenterId); + String name = ManagementFactory.getRuntimeMXBean().getName(); + if (!name.isEmpty()) { + /* + * GET jvmPid + */ + mpid.append(name.split("@")[0]); + } + /* + * MAC + PID 的 hashcode 获取16个低位 + */ + return (mpid.toString().hashCode() & 0xffff) % (IdWorker.MAX_WORKER_ID + 1); + } + + /** + *

+ * 数据标识id部分 + *

+ */ + protected static long getDatacenterId() { + long id = 0L; + try { + InetAddress ip = InetAddress.getLocalHost(); + NetworkInterface network = NetworkInterface.getByInetAddress(ip); + if (network == null) { + id = 1L; + } else { + byte[] mac = network.getHardwareAddress(); + id = ((0x000000FF & (long) mac[mac.length - 1]) + | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6; + id = id % (IdWorker.MAX_DATACENTER_ID + 1); + } + } catch (Exception e) { + System.out.println(" getDatacenterId: " + e.getMessage()); + } + return id; + } + + + + +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java index de96993..ccd1eab 100644 --- a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java @@ -1,5 +1,6 @@ package com.example.qa.service.domain; +import com.example.qa.service.common.demos.web.IdWorker; import com.example.qa.service.domain.port.DeleteAllQasPort; import com.example.qa.service.domain.port.GetQaListPort; import com.example.qa.service.domain.valueobject.Answer; @@ -29,9 +30,13 @@ public class Qa { } public Qa(Question question, Answer answer) { + this.id = this.genId(); this.question = question; this.answer = answer; } + public QaId genId(){ + return new QaId(new IdWorker().nextId()); + } public static List getQas(GetQaListPort getQaListPort) { return getQaListPort.getQas(); -- Gitee From 8872b467f277a4e15e09cf701bb45758e7b5abd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=8F=E5=85=8B=E6=96=AF?= <13415370+foooooxxxx@user.noreply.gitee.com> Date: Tue, 16 Sep 2025 23:13:17 +0800 Subject: [PATCH 11/12] =?UTF-8?q?feat(qa-service):=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=92=8Ckimi=E7=9A=84=E8=81=8A=E5=A4=A9=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通过question获取和kimi的聊天信息 [skip ci] --- .../demos/web/controller/QaController.java | 16 ++-- .../port/in/GetChatContentCase.java | 10 +++ .../application/port/in/GetQaoneUseCase.java | 2 + .../service/GetChatContentService.java | 74 +++++++++++++++++++ .../src/main/resources/application.properties | 3 + qa-service/qa-service-domain/pom.xml | 4 + .../domain/ChatCompletionRequestDTO.java | 19 +++++ .../domain/ChatCompletionResponseDTO.java | 21 ++++++ .../com/example/qa/service/domain/Choice.java | 16 ++++ .../example/qa/service/domain/Message.java | 15 ++++ .../service/domain/config/MoonShotConfig.java | 14 ++++ .../qa/service/domain/config/RestConfig.java | 13 ++++ 12 files changed, 201 insertions(+), 6 deletions(-) create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetChatContentCase.java create mode 100644 qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetChatContentService.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/ChatCompletionRequestDTO.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/ChatCompletionResponseDTO.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Choice.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Message.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/config/MoonShotConfig.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/config/RestConfig.java diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java index 2ec20cd..6416fa5 100644 --- a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/demos/web/controller/QaController.java @@ -2,14 +2,10 @@ package com.example.qa.adapter.in.web.demos.web.controller; import com.example.qa.adapter.in.web.demos.web.controller.dto.CreateQaRequestDTO; import com.example.qa.service.application.command.CreateQaCommand; -import com.example.qa.service.application.port.in.CreateQaCase; +import com.example.qa.service.application.port.in.*; import com.example.qa.adapter.in.web.demos.web.dto.QasUpdateDto; import com.example.qa.service.application.command.UpdateQasCommand; -import com.example.qa.service.application.port.in.DeleteOneQaUseCase; -import com.example.qa.service.application.port.in.DeleteAllQasUseCase; -import com.example.qa.service.application.port.in.GetQaListUseCase; -import com.example.qa.service.application.port.in.UpdateQasUseCase; -import com.example.qa.service.application.port.in.GetQaoneUseCase; +import com.example.qa.service.domain.Choice; import com.example.qa.service.domain.Qa; import com.example.qa.service.domain.valueobject.QaId; import lombok.RequiredArgsConstructor; @@ -37,6 +33,7 @@ public class QaController { private final DeleteAllQasUseCase deleteAllQasUseCase; private final CreateQaCase createQaCase; + private final GetChatContentCase getChatContentCase; /** * author: yeguiyang * 获取所有问答() @@ -92,6 +89,13 @@ public class QaController { return getQaoneUseCase.getQa( id); } + @GetMapping("/getChatContent") + public List getChatContent(@RequestParam("question") String question) + { + log.info("getChatContent"); + return getChatContentCase.getChatContent(question); + } + /** * author: suyucheng * 删除所有问答 diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetChatContentCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetChatContentCase.java new file mode 100644 index 0000000..293e783 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetChatContentCase.java @@ -0,0 +1,10 @@ +package com.example.qa.service.application.port.in; + +import com.example.qa.service.domain.Choice; + +import java.util.List; + +public interface GetChatContentCase { + + List getChatContent(String question); +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaoneUseCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaoneUseCase.java index 8b003c3..f5836ee 100644 --- a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaoneUseCase.java +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaoneUseCase.java @@ -6,4 +6,6 @@ import com.example.qa.service.domain.valueobject.QaId; public interface GetQaoneUseCase { Qa getQa(Long id); + + } diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetChatContentService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetChatContentService.java new file mode 100644 index 0000000..e5e59aa --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetChatContentService.java @@ -0,0 +1,74 @@ +package com.example.qa.service.application.service; + +import com.example.qa.service.application.port.in.GetChatContentCase; +import com.example.qa.service.domain.ChatCompletionRequestDTO; +import com.example.qa.service.domain.ChatCompletionResponseDTO; +import com.example.qa.service.domain.Choice; +import com.example.qa.service.domain.Message; +import com.example.qa.service.domain.config.MoonShotConfig; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import java.util.Arrays; +import java.util.List; + +/** + * @program: qa-sys + * @description: + * @author: fks + * @create: 2025-09-16 22:51 + **/ +@Component +@Slf4j +public class GetChatContentService implements GetChatContentCase { + @Resource + private RestTemplate restTemplate; + + @Resource + private MoonShotConfig moonShotConfig; + @Override + public List getChatContent(String question) { + log.info("demo"); + //创建请求头 + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("Authorization", "Bearer " + moonShotConfig.getKey()); + //创建请求体 + ChatCompletionRequestDTO request = new ChatCompletionRequestDTO(); + request.setModel(moonShotConfig.getModel()); + request.setTemperature(0.6); + //创建消息列表 + Message systemMessage = new Message(); + systemMessage.setRole("system"); + systemMessage.setContent("你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。"); + + Message userMessage=new Message(); + userMessage.setRole("user"); + userMessage.setContent(question); + + request.setMessages(Arrays.asList( + systemMessage,userMessage + )); + + //创建Http实体 + HttpEntity response= restTemplate.exchange( + moonShotConfig.getUrl(), + HttpMethod.POST, + new HttpEntity<>(request, headers), + ChatCompletionResponseDTO.class + ); + + log.info("response:{}",response); + + List choices = response.getBody().getChoices(); + + return choices; + } +} diff --git a/qa-service/qa-service-bootstrap/src/main/resources/application.properties b/qa-service/qa-service-bootstrap/src/main/resources/application.properties index 9e6a2fb..897bb1f 100644 --- a/qa-service/qa-service-bootstrap/src/main/resources/application.properties +++ b/qa-service/qa-service-bootstrap/src/main/resources/application.properties @@ -6,6 +6,9 @@ spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +moonshot.url=https://api.moonshot.cn/v1/chat/completions +moonshot.key=sk-jWpzVWAR2tJfj6kf1ofzZnE3dNV5RklEOCxaN9il2HMhxEEq +moonshot.model=kimi-k2-0905-preview ## Nacos\u8BA4\u8BC1\u4FE1\u606F #spring.cloud.nacos.discovery.username=nacos #spring.cloud.nacos.discovery.password=nacos diff --git a/qa-service/qa-service-domain/pom.xml b/qa-service/qa-service-domain/pom.xml index a561c5e..e86a2db 100644 --- a/qa-service/qa-service-domain/pom.xml +++ b/qa-service/qa-service-domain/pom.xml @@ -20,6 +20,10 @@ spring-boot-starter + + org.springframework.boot + spring-boot-starter-web + org.springframework.boot spring-boot-starter-test diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/ChatCompletionRequestDTO.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/ChatCompletionRequestDTO.java new file mode 100644 index 0000000..d04a1ad --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/ChatCompletionRequestDTO.java @@ -0,0 +1,19 @@ +package com.example.qa.service.domain; + +import lombok.Data; + +import java.util.List; + +/** + * @program: qa-sys + * @description: + * @author: fks + * @create: 2025-09-16 23:00 + **/ + +@Data +public class ChatCompletionRequestDTO { + private String model; + private List messages; + private double temperature; +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/ChatCompletionResponseDTO.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/ChatCompletionResponseDTO.java new file mode 100644 index 0000000..1b9e52c --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/ChatCompletionResponseDTO.java @@ -0,0 +1,21 @@ +package com.example.qa.service.domain; + +import lombok.Data; + +import java.util.List; + +/** + * @program: qa-sys + * @description: + * @author: fks + * @create: 2025-09-16 23:00 + **/ + +@Data +public class ChatCompletionResponseDTO { + private String id; + private String object; + private long created; + private String model; + private List choices; +} \ No newline at end of file diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Choice.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Choice.java new file mode 100644 index 0000000..9cfb8c3 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Choice.java @@ -0,0 +1,16 @@ +package com.example.qa.service.domain; + +import lombok.Data; + +/** + * @program: qa-sys + * @description: + * @author: fks + * @create: 2025-09-16 22:53 + **/ +@Data +public class Choice { + private int index; + private Message message; + private String finish_reason; +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Message.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Message.java new file mode 100644 index 0000000..4f82ced --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Message.java @@ -0,0 +1,15 @@ +package com.example.qa.service.domain; + +import lombok.Data; + +/** + * @program: qa-sys + * @description: + * @author: fks + * @create: 2025-09-16 22:53 + **/ +@Data +public class Message { + private String role; + private String content; +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/config/MoonShotConfig.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/config/MoonShotConfig.java new file mode 100644 index 0000000..8ed0fa9 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/config/MoonShotConfig.java @@ -0,0 +1,14 @@ +package com.example.qa.service.domain.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Data +@Configuration +@ConfigurationProperties(prefix = "moonshot") +public class MoonShotConfig { + private String url; + private String key; + private String model; +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/config/RestConfig.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/config/RestConfig.java new file mode 100644 index 0000000..7704bd7 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/config/RestConfig.java @@ -0,0 +1,13 @@ +package com.example.qa.service.domain.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class RestConfig { + @Bean + public RestTemplate getRestTemplate(){ + return new RestTemplate(); + } +} -- Gitee From b42e69eeeeb6a9ac90349daf79d6b61827c00a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=8F=E5=85=8B=E6=96=AF?= <13415370+foooooxxxx@user.noreply.gitee.com> Date: Wed, 17 Sep 2025 22:38:32 +0800 Subject: [PATCH 12/12] =?UTF-8?q?feat(qa-service):=20=E9=80=9A=E8=BF=87mq?= =?UTF-8?q?=E5=B0=86=E8=81=8A=E5=A4=A9=E5=86=85=E5=AE=B9=E5=AD=98=E5=88=B0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通过mq将聊天内容存到数据库 [skip ci] --- .../CreateChatContentBridgeContent.java | 35 ++++++++++++++ .../persistence/entity/ChatContentEntity.java | 24 ++++++++++ .../persistence/mapper/ChatContentMapper.java | 7 +++ .../service/GetChatContentService.java | 9 +++- .../src/main/resources/application.properties | 10 ++++ qa-service/qa-service-domain/pom.xml | 10 +++- .../service/domain/config/RabbitConfig.java | 48 +++++++++++++++++++ .../service/domain/listener/chatListener.java | 22 +++++++++ .../domain/port/CreateChatContentPort.java | 9 ++++ 9 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/CreateChatContentBridgeContent.java create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/entity/ChatContentEntity.java create mode 100644 qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/mapper/ChatContentMapper.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/config/RabbitConfig.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/listener/chatListener.java create mode 100644 qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateChatContentPort.java diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/CreateChatContentBridgeContent.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/CreateChatContentBridgeContent.java new file mode 100644 index 0000000..1933360 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/CreateChatContentBridgeContent.java @@ -0,0 +1,35 @@ +package com.example.qa.adapter.out.persistence.bridge; + +import com.example.qa.adapter.out.persistence.entity.ChatContentEntity; +import com.example.qa.adapter.out.persistence.mapper.ChatContentMapper; +import com.example.qa.adapter.out.persistence.mapper.QaMapper; +import com.example.qa.service.domain.Message; +import com.example.qa.service.domain.port.CreateChatContentPort; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * @program: qa-sys + * @description: + * @author: fks + * @create: 2025-09-17 22:06 + **/ +@Slf4j +@Component +public class CreateChatContentBridgeContent implements CreateChatContentPort { + + @Resource + private ChatContentMapper chatContentMapper; + + @Override + public void createChatContent(Message message) { + ChatContentEntity chatContentEntity = new ChatContentEntity(); + chatContentEntity.setRole(message.getRole()); + chatContentEntity.setContent(message.getContent()); + chatContentMapper.insert(chatContentEntity); + } +} diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/entity/ChatContentEntity.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/entity/ChatContentEntity.java new file mode 100644 index 0000000..1bd6b98 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/entity/ChatContentEntity.java @@ -0,0 +1,24 @@ +package com.example.qa.adapter.out.persistence.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @program: qa-sys + * @description: + * @author: fks + * @create: 2025-09-17 22:14 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("chat_content") +public class ChatContentEntity { + @TableId + private Integer id; + private String role; + private String content; +} diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/mapper/ChatContentMapper.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/mapper/ChatContentMapper.java new file mode 100644 index 0000000..5625e67 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/mapper/ChatContentMapper.java @@ -0,0 +1,7 @@ +package com.example.qa.adapter.out.persistence.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.example.qa.adapter.out.persistence.entity.ChatContentEntity; + +public interface ChatContentMapper extends BaseMapper { +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetChatContentService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetChatContentService.java index e5e59aa..695b2c7 100644 --- a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetChatContentService.java +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetChatContentService.java @@ -8,6 +8,7 @@ import com.example.qa.service.domain.Message; import com.example.qa.service.domain.config.MoonShotConfig; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -18,6 +19,7 @@ import org.springframework.web.client.RestTemplate; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; /** * @program: qa-sys @@ -31,6 +33,8 @@ public class GetChatContentService implements GetChatContentCase { @Resource private RestTemplate restTemplate; + @Resource + private RabbitTemplate rabbitTemplate; @Resource private MoonShotConfig moonShotConfig; @Override @@ -68,7 +72,10 @@ public class GetChatContentService implements GetChatContentCase { log.info("response:{}",response); List choices = response.getBody().getChoices(); - +// List messages = choices.stream().map(Choice::getMessage).collect(Collectors.toList()); + Message message = choices.get(0).getMessage(); + log.info("messages:{}",message); + rabbitTemplate.convertAndSend("test", message); return choices; } } diff --git a/qa-service/qa-service-bootstrap/src/main/resources/application.properties b/qa-service/qa-service-bootstrap/src/main/resources/application.properties index 897bb1f..b9d0097 100644 --- a/qa-service/qa-service-bootstrap/src/main/resources/application.properties +++ b/qa-service/qa-service-bootstrap/src/main/resources/application.properties @@ -9,6 +9,16 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver moonshot.url=https://api.moonshot.cn/v1/chat/completions moonshot.key=sk-jWpzVWAR2tJfj6kf1ofzZnE3dNV5RklEOCxaN9il2HMhxEEq moonshot.model=kimi-k2-0905-preview + +# RabbitMQ配置 +spring.rabbitmq.host=192.168.98.129 +spring.rabbitmq.port=5672 +spring.rabbitmq.virtual-host=/hmall +spring.rabbitmq.username=hmall +spring.rabbitmq.password=123 + +# 信任所有反序列化类 +spring.amqp.deserialization.trust.all=true ## Nacos\u8BA4\u8BC1\u4FE1\u606F #spring.cloud.nacos.discovery.username=nacos #spring.cloud.nacos.discovery.password=nacos diff --git a/qa-service/qa-service-domain/pom.xml b/qa-service/qa-service-domain/pom.xml index e86a2db..8202a53 100644 --- a/qa-service/qa-service-domain/pom.xml +++ b/qa-service/qa-service-domain/pom.xml @@ -19,7 +19,15 @@ org.springframework.boot spring-boot-starter - + + org.springframework.amqp + spring-rabbit-test + test + + + org.springframework.boot + spring-boot-starter-amqp + org.springframework.boot spring-boot-starter-web diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/config/RabbitConfig.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/config/RabbitConfig.java new file mode 100644 index 0000000..9291b49 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/config/RabbitConfig.java @@ -0,0 +1,48 @@ +package com.example.qa.service.domain.config; + + +import org.springframework.amqp.core.Message; +import org.springframework.amqp.core.Queue; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper; +import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; +import org.springframework.amqp.support.converter.MessageConverter; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.HashMap; +import java.util.Map; + +@Configuration +public class RabbitConfig { + //让springboot启动时自动创建队列 + + @Bean + public Queue queue() { + return new Queue("test"); + } + + + @Bean + public MessageConverter messageConverter() { + Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter(); + // 配置类型映射器以支持 Student 类的反序列化 + DefaultJackson2JavaTypeMapper typeMapper = new DefaultJackson2JavaTypeMapper(); + Map> idClassMapping = new HashMap<>(); + // 添加 Student 类的映射 如果有更多的类需要转换,则继续添加 + idClassMapping.put("com.example.qa.service.domain", Message.class); + typeMapper.setIdClassMapping(idClassMapping); + typeMapper.setTrustedPackages("com.example.qa.service.domain"); + converter.setJavaTypeMapper(typeMapper); + + return converter; + } + + @Bean + public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) { + RabbitTemplate template = new RabbitTemplate(connectionFactory); + template.setMessageConverter(messageConverter()); + return template; + } +} \ No newline at end of file diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/listener/chatListener.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/listener/chatListener.java new file mode 100644 index 0000000..81f1f59 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/listener/chatListener.java @@ -0,0 +1,22 @@ +package com.example.qa.service.domain.listener; + + +import com.example.qa.service.domain.Message; +import com.example.qa.service.domain.port.CreateChatContentPort; +import jakarta.annotation.Resource; +import org.springframework.amqp.rabbit.annotation.RabbitHandler; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +@RabbitListener(queues = "test") +public class chatListener { + @Resource + private CreateChatContentPort createChatContentPort; + @RabbitHandler + public void handler(Message message){ + createChatContentPort.createChatContent(message); + } +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateChatContentPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateChatContentPort.java new file mode 100644 index 0000000..0bbe234 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateChatContentPort.java @@ -0,0 +1,9 @@ +package com.example.qa.service.domain.port; + +import com.example.qa.service.domain.Message; + +import java.util.List; + +public interface CreateChatContentPort { + void createChatContent(Message message); +} -- Gitee