Qas = Qa.getQas(getQaListPort);
+ return Qas;
+ }
+}
+
+ /**
+ * @author ZhengYuan
+ * @param GetQaListService
+ * @return
+ */
\ No newline at end of file
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..2123551
--- /dev/null
+++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/UpdateQaService.java
@@ -0,0 +1,34 @@
+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.Email;
+import com.example.qa.service.domain.valueobject.QaAge;
+import com.example.qa.service.domain.valueobject.QaId;
+import com.example.qa.service.domain.valueobject.QaName;
+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()), // 保持ID用于定位更新对象
+ new QaQuestion(command.question()), // 替换用户姓名为问题内容
+ new QaAnswer(command.answer()) // 替换用户年龄、邮箱为答案内容
+ );
+ return updateQaPort.updateQa(qa);
+ }
+}
+ /**
+ * 更新信息
+ * @author qinshijie && liuxin
+ * @param UpdateQaUseCase
+ * @return
+ */
\ No newline at end of file
diff --git a/qa-service/qa-service-bootstrap/pom.xml b/qa-service/qa-service-bootstrap/pom.xml
new file mode 100644
index 0000000..56ff6f5
--- /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.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..74d741e
--- /dev/null
+++ b/qa-service/qa-service-bootstrap/src/main/java/com/example/qa/service/bootstrap/QaServiceBootstrapApplication.java
@@ -0,0 +1,21 @@
+package com.example.qa.service.bootstrap;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+ /**
+ * @author ChenYiZhao
+ * @param QaServiceBootstrapApplication {
+ * @return
+ */
+
+@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..e073491
--- /dev/null
+++ b/qa-service/qa-service-bootstrap/src/main/resources/application.properties
@@ -0,0 +1,27 @@
+server.port=28080
+
+spring.application.name=user-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/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..316c8ea
--- /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.user.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/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..8f767f4
--- /dev/null
+++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java
@@ -0,0 +1,50 @@
+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.Email;
+import com.example.qa.service.domain.valueobject.qaAge;
+import com.example.qa.service.domain.valueobject.qaId;
+import com.example.qa.service.domain.valueobject.qaName;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+import java.util.List;
+
+@Setter
+@Getter
+@ToString
+public class Qa {
+ private QaId id;
+ private QaQuestion question;
+ private QaAnswer answer;
+
+ public Qa() {
+ }
+
+ public Qa(QaId id, QaQuestion question, QaAnswer answer) {
+ this.id = id;
+ this.question = question;
+ this.answer = answer;
+ }
+
+ public Qa(QaId id, QaQuestion question, QaAnswer 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());
+ }
+}
+/**
+ * @author ChenYiZhao
+ * @param Qa
+ * @return
+ */
\ No newline at end of file
diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateUserPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateUserPort.java
new file mode 100644
index 0000000..f03b131
--- /dev/null
+++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateUserPort.java
@@ -0,0 +1,12 @@
+package com.example.qa.service.domain.port;
+
+import com.example.qa.service.domain.Qa;
+
+public interface CreateQaPort {
+ Qa createQa(Qa qa);
+}
+/**
+ * @author XieQiWei
+ * @param CreateQaPort
+ * @return
+ * */
\ No newline at end of file
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..748baa9
--- /dev/null
+++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteQaPort.java
@@ -0,0 +1,11 @@
+package com.example.qa.service.domain.port;
+
+/**
+ * @author ChenYiZhao
+ * @param DeleteQaPort
+ * @return
+ */
+
+public interface DeleteQaPort {
+ void deleteQa(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..713f940
--- /dev/null
+++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaListPort.java
@@ -0,0 +1,15 @@
+package com.example.qa.service.domain.port;
+
+import com.example.qa.service.domain.qa;
+
+import java.util.List;
+
+public interface GetQaListPort {
+ List getqas();
+}
+
+ /**
+ * @author ZhengYuan
+ * @param GetQaListPort
+ * @return
+ */
\ No newline at end of file
diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetUserByIdPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetUserByIdPort.java
new file mode 100644
index 0000000..02f0f56
--- /dev/null
+++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetUserByIdPort.java
@@ -0,0 +1,12 @@
+package com.example.qa.service.domain.port;
+
+import com.example.qa.service.domain.qa;
+
+public interface GetqaByIdPort {
+ qa getqaById(Long id);
+}
+/**
+ * @author zhangxuanwei
+ * @param GetqaByIdPort
+ * @return
+ */
\ No newline at end of file
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..b4aabf4
--- /dev/null
+++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/UpdateQaPort.java
@@ -0,0 +1,13 @@
+package com.example.qa.service.domain.port;
+
+import com.example.qa.service.domain.Qa;
+
+public interface UpdateQaPort {
+ Qa updateQa(Qa qa);
+}
+ /**
+ * 更新信息
+ * @author qinshijie && liuxin
+ * @param UpdateQaPort
+ * @return
+ */
\ No newline at end of file
diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaAnswer.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaAnswer.java
new file mode 100644
index 0000000..94070dd
--- /dev/null
+++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaAnswer.java
@@ -0,0 +1,7 @@
+package com.example.qa.service.domain.valueobject;
+
+public record Answer(String answer) {
+ public int 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..7763efa
--- /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 Id(long id) {
+
+ public long getValue(){
+ return id;
+ }
+
+}
diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaQuestion.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaQuestion.java
new file mode 100644
index 0000000..52814d7
--- /dev/null
+++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaQuestion.java
@@ -0,0 +1,7 @@
+package com.example.qa.service.domain.valueobject;
+
+public record Question(String question) {
+ public String getValue() {
+ return question;
+ }
+}
--
Gitee