qas = Qa.getQas(getQaListPort);
+ return qas;
+ }
+}
diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/UpdateQaService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/UpdateQaService.java
new file mode 100644
index 0000000..e6e801a
--- /dev/null
+++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/UpdateQaService.java
@@ -0,0 +1,26 @@
+package com.example.qa.service.application.service;
+
+import com.example.qa.service.application.command.UpdateQaCommand;
+import com.example.qa.service.application.port.in.UpdateQaUseCase;
+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.stereotype.Service;
+
+@Service
+public class UpdateQaService implements UpdateQaUseCase {
+ @Resource
+ private UpdateQaPort updateQaPort;
+
+ @Override
+ public Qa updateQa(UpdateQaCommand command) {
+ Qa qa = new Qa(
+ new QaId(command.id()),
+ new Question(command.question()),
+ new Answer(command.answer()));
+ return updateQaPort.updateQa(qa);
+ }
+}
diff --git a/qa-service/qa-service-bootstrap/pom.xml b/qa-service/qa-service-bootstrap/pom.xml
new file mode 100644
index 0000000..0ddd8f7
--- /dev/null
+++ b/qa-service/qa-service-bootstrap/pom.xml
@@ -0,0 +1,86 @@
+
+
+ 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
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+
+
+
+
+
+
+ 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.qa.service.bootstrap.qaServiceBootstrapApplication
+ 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..2646857
--- /dev/null
+++ b/qa-service/qa-service-bootstrap/src/main/resources/application.properties
@@ -0,0 +1,27 @@
+server.port=28080
+
+spring.application.name=qa-service
+
+
+# Nacos认证信息
+spring.cloud.nacos.discovery.username=nacos
+spring.cloud.nacos.discovery.password=nacos
+# Nacos 服务发现与注册配置,其中子属性 server-addr 指定 Nacos 服务器主机和端口
+spring.cloud.nacos.discovery.server-addr=192.168.168.128:8848
+# 注册到 nacos 的指定 namespace,默认为 public
+spring.cloud.nacos.discovery.namespace=public
+
+# Nacos帮助文档: https://nacos.io/zh-cn/docs/concepts.html
+# Nacos认证信息
+spring.cloud.nacos.config.username=nacos
+spring.cloud.nacos.config.password=nacos
+spring.cloud.nacos.config.contextPath=/nacos
+# 设置配置中心服务端地址
+spring.cloud.nacos.config.server-addr=192.168.168.128:8848
+# Nacos 配置中心的namespace。需要注意,如果使用 public 的 namcespace ,请不要填写这个值,直接留空即可
+# spring.cloud.nacos.config.namespace=
+spring.config.import=nacos:${spring.application.name}.properties?refresh=true
+
+
+
+
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..e616cba
--- /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
+
+ 21
+ UTF-8
+ UTF-8
+ 3.0.2
+
+
+
+ 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/IdWorker.java b/qa-service/qa-service-common/src/main/java/com/example/qa/service/common/IdWorker.java
new file mode 100644
index 0000000..ac96e23
--- /dev/null
+++ b/qa-service/qa-service-common/src/main/java/com/example/qa/service/common/IdWorker.java
@@ -0,0 +1,199 @@
+package com.example.qa.service.common;
+
+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 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..8760abb
--- /dev/null
+++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java
@@ -0,0 +1,44 @@
+package com.example.qa.service.domain;
+
+import com.example.qa.service.common.IdWorker;
+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(QaId id, Question question, Answer answer) {
+ this.id = id;
+ this.question = question;
+ this.answer = answer;
+ }
+
+ public Qa( Question question, Answer answer) {
+ this.id= genId() ;
+ this.question = question;
+ this.answer = answer;
+ }
+
+ public static List getQas(GetQaListPort getQaListPort){
+ return getQaListPort.getQas();
+ }
+
+ public QaId genId(){
+ return new QaId(new IdWorker().nextId());
+ }
+}
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);
+}
diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteQaPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteQaPort.java
new file mode 100644
index 0000000..d7b8363
--- /dev/null
+++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteQaPort.java
@@ -0,0 +1,5 @@
+package com.example.qa.service.domain.port;
+
+public interface DeleteQaPort {
+ void deleteQa(Long id);
+}
diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaByIdPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaByIdPort.java
new file mode 100644
index 0000000..1068e1c
--- /dev/null
+++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaByIdPort.java
@@ -0,0 +1,7 @@
+package com.example.qa.service.domain.port;
+
+import com.example.qa.service.domain.Qa;
+
+public interface GetQaByIdPort {
+ Qa getQaById(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 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/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..9cf9aed
--- /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 {
+ Qa 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 0000000..18f0139
--- /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..ea201ec
--- /dev/null
+++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaId.java
@@ -0,0 +1,9 @@
+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..aee0aba
--- /dev/null
+++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/Question.java
@@ -0,0 +1,5 @@
+package com.example.qa.service.domain.valueobject;
+
+public record Question(String question) {
+ public String getValue(){return question;}
+}
--
Gitee