diff --git a/.idea/compiler.xml b/.idea/compiler.xml index a1757ae52c775b88df6c02cfd7eb346687391f4e..fd35b9daf9e5f0f5daa7b8faad9a8db6874cec93 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,7 +2,24 @@ - + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml index da0415a0f5aad2f6109ef1e7ffdcdd1165577665..1b312887a62c4ab1dfec5da0cfcc5061ff9af84a 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,4 +1,47 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index c4be5fbe7a7713108f730e4ba7e92ee22d7d9ecc..0000000000000000000000000000000000000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 7280f0035ff554996c5802bd753f698672e5a12b..7c06679020265950e3579183e847624fa5c81798 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,19 @@ - - \ No newline at end of file diff --git a/qa-service/pom.xml b/qa-service/pom.xml index 0b70349fcbb4e8f68efabbf1733a3d46456fd39c..a335e7785acc6b754e344a9bf3bed389f3b96074 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 0000000000000000000000000000000000000000..26ebd4bf408a35d58359c95d4ce5b92dc5d7f042 --- /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 0000000000000000000000000000000000000000..549e00a2a96fa9d7c5dbc9859664a78d980158c2 --- /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 0000000000000000000000000000000000000000..cc4dfacad9a8669b5940ae701813c0296fccc8dc --- /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 0000000000000000000000000000000000000000..549e00a2a96fa9d7c5dbc9859664a78d980158c2 --- /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 0000000000000000000000000000000000000000..600d9053dff3b8f1664cae864d9fa3d058c0fb69 --- /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 0000000000000000000000000000000000000000..2ec20cd577ee8ca0297f8a917f6316ede85f41fa --- /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,117 @@ +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; +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.*; +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; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Slf4j +@RequestMapping("/qa") +@RestController +@RequiredArgsConstructor +public class QaController { + private final GetQaListUseCase getQaListUseCase; + private final UpdateQasUseCase updateQasUseCase; + private final DeleteOneQaUseCase deleteOneQaUseCase; + private final GetQaoneUseCase getQaoneUseCase; + + private final DeleteAllQasUseCase deleteAllQasUseCase; + private final CreateQaCase createQaCase; + /** + * author: yeguiyang + * 获取所有问答() + * @return + */ + @GetMapping("/get") + public List getQas() + { + 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: 冯楷晟 + * 根据id更新问答 + * @return + */ + @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 + * 获取单个问答 + * @return + */ + @GetMapping("/getone/{id}") + public Qa getQa(@PathVariable("id") long id) + { + log.info("getQa"); + return getQaoneUseCase.getQa( id); + } + + /** + * author: suyucheng + * 删除所有问答 + */ + @DeleteMapping("/delete-all") + public void deleteAllQas() + { + 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-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 0000000000000000000000000000000000000000..4d248f1ced3fb7c378cd1963c22c70d4f3acd51c --- /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-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 0000000000000000000000000000000000000000..f723c223434144e88ee79c43e6823c4700845dcc --- /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/pom.xml b/qa-service/qa-service-adapter/qa-adapter-out/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..afd42e25d9d57a6209724f92cd1b0042be6e65c5 --- /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 0000000000000000000000000000000000000000..549e00a2a96fa9d7c5dbc9859664a78d980158c2 --- /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 0000000000000000000000000000000000000000..1ae4d28282a4ac64265f35f8a30591c4cce85b1a --- /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/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 0000000000000000000000000000000000000000..678185151c16d9af413855ccb2a410cdad6e0ec5 --- /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-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 0000000000000000000000000000000000000000..67b8d7bf639e8f2b811a6ac8fb83d6cdaa3a323e --- /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-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 0000000000000000000000000000000000000000..d89f603e1823f8c7a861a1394a4aa1c119628470 --- /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-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 0000000000000000000000000000000000000000..7d814153d2bcb5ee0442ac830db3d49a0faf6b23 --- /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,29 @@ +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/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 0000000000000000000000000000000000000000..16ef8808f7c240964f3f2ad7fe61f5d12f950880 --- /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-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 0000000000000000000000000000000000000000..8894078785ebce8d323182e3a95a8664107781af --- /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-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 0000000000000000000000000000000000000000..9b52dd63e046ae687564826279d6e707e0782644 --- /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 0000000000000000000000000000000000000000..f82648cdc3fb3c64d964403987fa97ebdb964f7c --- /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 0000000000000000000000000000000000000000..4c2f4ab14cb6fb33c02a99adeb871b6c14a81983 --- /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 0000000000000000000000000000000000000000..549e00a2a96fa9d7c5dbc9859664a78d980158c2 --- /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 0000000000000000000000000000000000000000..b65c07053b3f64439cad3d56e828e50b30e0403a --- /dev/null +++ b/qa-service/qa-service-application/pom.xml @@ -0,0 +1,61 @@ + + + 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 + + + com.example + qa-service-application + 0.0.1-SNAPSHOT + compile + + + + + + + + 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/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 0000000000000000000000000000000000000000..140d393b31dd0ef10b7ef08e1f2e1a6f3f10e484 --- /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/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 0000000000000000000000000000000000000000..9ee58b6f2452135f4a1f60265d2d4b31757aa884 --- /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/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 0000000000000000000000000000000000000000..263990704b85e3c626d7c610a9f46fe1b0c4c85b --- /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/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 0000000000000000000000000000000000000000..5d25d7e2cc16d76e6b3e29d16e0bf3dc82c12e5c --- /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/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 0000000000000000000000000000000000000000..f10d7f1ea98ea68c842ffe5a4cbcbdfcb1438c04 --- /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/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 0000000000000000000000000000000000000000..b3ad62580c5b63e8c22144ed1cbfc253614faaa8 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaListUseCase.java @@ -0,0 +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/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 0000000000000000000000000000000000000000..8b003c39381e67b17520db728af1bce54eb1935c --- /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/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 0000000000000000000000000000000000000000..f335aa0b0587086f1a21a97a40782cf2f259a865 --- /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/CreateQaService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/CreateQaService.java new file mode 100644 index 0000000000000000000000000000000000000000..29327e82e30799d85867260ccfb64f53d3e57e87 --- /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-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 0000000000000000000000000000000000000000..2561ac19943d0de02d5c12bc81667a1e2309ce64 --- /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-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 0000000000000000000000000000000000000000..33da30982b47052aed1669da8ecca55a437ff81c --- /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-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 0000000000000000000000000000000000000000..7e30f393e887fccf72ee2e870279ef9a3d56d9e5 --- /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-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 0000000000000000000000000000000000000000..80c10fae8030bfc66c952da9f1cc6654f2f75332 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaListService.java @@ -0,0 +1,22 @@ +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; +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-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 0000000000000000000000000000000000000000..eb7410bc8fb1884db50e4b94ec6b3716a8ea0f26 --- /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-bootstrap/.gitignore b/qa-service/qa-service-bootstrap/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..549e00a2a96fa9d7c5dbc9859664a78d980158c2 --- /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 0000000000000000000000000000000000000000..4069b26996ba4cd6064a021bdbffe77e209f96f8 --- /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 0000000000000000000000000000000000000000..714d3f969228260d37ee452aa12d7197e49ab1ce --- /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 0000000000000000000000000000000000000000..9e6a2fbc58451f61b3b4b09c79827b5220bff857 --- /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 0000000000000000000000000000000000000000..89bb8ba4ff248cd6e3b8b5e2f89af4e3062a37a8 --- /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 0000000000000000000000000000000000000000..153ddf1989c7fe0269bdf4085b4e7e054849d3e5 --- /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 0000000000000000000000000000000000000000..549e00a2a96fa9d7c5dbc9859664a78d980158c2 --- /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 0000000000000000000000000000000000000000..aeb6c42c5fb48ae3ab82e6342a124854796acf8e --- /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-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 0000000000000000000000000000000000000000..c6d3735e2ce4cff18fa66756f1171b0d89d3b25e --- /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/.gitignore b/qa-service/qa-service-domain/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..549e00a2a96fa9d7c5dbc9859664a78d980158c2 --- /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 0000000000000000000000000000000000000000..a561c5ec49651a814240624e8b0e399d547efd40 --- /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 0000000000000000000000000000000000000000..ccd1eab5b5e8e73f08a12e2067ea2856713cf611 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java @@ -0,0 +1,47 @@ +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; +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 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(); + } + 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/CreateQaPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateQaPort.java new file mode 100644 index 0000000000000000000000000000000000000000..5ac360216929316528165938960ff997c51193d3 --- /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); +} 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 0000000000000000000000000000000000000000..854a127d36279d9340dc822bbf9e8a3899c0b334 --- /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 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 0000000000000000000000000000000000000000..b856a1f54610d5d262ec3560232ca444541fce86 --- /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); +} 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 0000000000000000000000000000000000000000..ad52920908cbfe38e267bd39cb6f600e25e54454 --- /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/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 0000000000000000000000000000000000000000..e0353b55ddc584c8448b598953376d2883f147bb --- /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); +} 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 0000000000000000000000000000000000000000..974c5f6e0321fcecb19769e31afcefda4881ed0b --- /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); +} 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 0000000000000000000000000000000000000000..4d0e1d456207970fb214c33663e629aed7276d7c --- /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 0000000000000000000000000000000000000000..69700f02e5dd3207f6f915a4442cc48917064dc4 --- /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 0000000000000000000000000000000000000000..27bbf25cdd7eb94e72c19b986e77322d32c31070 --- /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; + } +}