From d9c64cb28f38e7f1a4150cb0ebe3df06f1c5fca1 Mon Sep 17 00:00:00 2001 From: Haixing Hu Date: Sun, 23 Feb 2025 11:49:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E5=8A=9F=E8=83=BD=E5=BC=80=E5=8F=91=EF=BC=8C?= =?UTF-8?q?=E5=8C=85=E6=8B=AC=E7=94=A8=E6=88=B7=E6=B3=A8=E5=86=8C=E3=80=81?= =?UTF-8?q?=E9=97=AE=E5=8D=B7=E8=B0=83=E6=9F=A5=E7=AD=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cursorrules | 15 +- backend/pom.xml | 5 + .../jackson/databind/JsonTypeHandler.java | 51 - .../common/mybatis/InstantTypeHandler.java | 39 + .../java/ltd/qubit/survey/model/Option.java | 4 +- .../java/ltd/qubit/survey/model/Question.java | 4 +- .../qubit/survey/model/SurveyResponse.java | 4 +- .../java/ltd/qubit/survey/model/User.java | 4 +- .../service/impl/OptionServiceImpl.java | 6 +- .../service/impl/QuestionServiceImpl.java | 4 +- .../impl/SurveyResponseServiceImpl.java | 8 +- .../survey/service/impl/UserServiceImpl.java | 4 +- .../survey/utils/CustomObjectMapper.java | 29 + .../mybatis/mapper/SurveyResponseMapper.xml | 8 +- .../main/resources/mybatis/mybatis-config.xml | 3 + .../resources/spring/applicationContext.xml | 14 +- .../ltd/qubit/survey/model/Option.class | Bin 4324 -> 4306 bytes .../ltd/qubit/survey/model/Question.class | Bin 5675 -> 5657 bytes .../qubit/survey/model/SurveyResponse.class | Bin 4562 -> 4544 bytes .../classes/ltd/qubit/survey/model/User.class | Bin 4420 -> 4402 bytes .../service/impl/OptionServiceImpl.class | Bin 4260 -> 4224 bytes .../service/impl/QuestionServiceImpl.class | Bin 6905 -> 6887 bytes .../impl/SurveyResponseServiceImpl.class | Bin 6941 -> 6893 bytes .../survey/service/impl/UserServiceImpl.class | Bin 3286 -> 3268 bytes .../mybatis/mapper/SurveyResponseMapper.xml | 8 +- .../target/classes/mybatis/mybatis-config.xml | 3 + .../classes/spring/applicationContext.xml | 14 +- .../compile/default-compile/createdFiles.lst | 3 +- .../compile/default-compile/inputFiles.lst | 3 +- frontend/.eslintrc.js | 18 + frontend/.prettierrc | 7 + frontend/.yarn/install-state.gz | Bin 0 -> 318448 bytes frontend/.yarnrc.yml | 2 + frontend/index.html | 13 + frontend/package.json | 38 + frontend/src/App.vue | 27 + frontend/src/api/survey.js | 47 + frontend/src/api/user.js | 26 + frontend/src/main.js | 12 + frontend/src/router/index.js | 43 + frontend/src/stores/survey.js | 105 + frontend/src/stores/user.js | 61 + frontend/src/utils/request.js | 32 + frontend/src/views/HomeView.vue | 106 + frontend/src/views/RegisterView.vue | 181 + frontend/src/views/SurveyView.vue | 183 + frontend/vite.config.js | 48 + frontend/yarn.lock | 3595 +++++++++++++++++ 48 files changed, 4672 insertions(+), 105 deletions(-) delete mode 100644 backend/src/main/java/com/fasterxml/jackson/databind/JsonTypeHandler.java create mode 100644 backend/src/main/java/ltd/qubit/survey/common/mybatis/InstantTypeHandler.java create mode 100644 backend/src/main/java/ltd/qubit/survey/utils/CustomObjectMapper.java create mode 100644 frontend/.eslintrc.js create mode 100644 frontend/.prettierrc create mode 100644 frontend/.yarn/install-state.gz create mode 100644 frontend/.yarnrc.yml create mode 100644 frontend/index.html create mode 100644 frontend/package.json create mode 100644 frontend/src/App.vue create mode 100644 frontend/src/api/survey.js create mode 100644 frontend/src/api/user.js create mode 100644 frontend/src/main.js create mode 100644 frontend/src/router/index.js create mode 100644 frontend/src/stores/survey.js create mode 100644 frontend/src/stores/user.js create mode 100644 frontend/src/utils/request.js create mode 100644 frontend/src/views/HomeView.vue create mode 100644 frontend/src/views/RegisterView.vue create mode 100644 frontend/src/views/SurveyView.vue create mode 100644 frontend/vite.config.js create mode 100644 frontend/yarn.lock diff --git a/.cursorrules b/.cursorrules index 06a625d..e27756b 100644 --- a/.cursorrules +++ b/.cursorrules @@ -59,4 +59,17 @@ ## 10. 版本控制 - 使用Git进行版本控制 - 遵循语义化版本规范 -- 重要配置文件加入版本控制 \ No newline at end of file +- 重要配置文件加入版本控制 + +## 11. 文件操作 +- 当需要复制文件时,使用 `command cp` 命令 +- 如果发现目录不存在,首先确认自己当前目录是否正确 +- 如果需要创建目录,使用 `command mkdir -p` 命令 +- 不要尝试重新安装开发依赖工具,比如jdk, node,python等 + +## 前端开发 +- 前端使用vue3开发 +- 代码必须严格遵守 eslint 规则 +- 前端项目使用yarn打包,用最新的4.x版 +- 前端项目根目录下需要有`.yarn.yml`配置文件 +- 前端启动开发服务器,需要把切换到前端目录以及启动开发服务器两个命令合并执行 \ No newline at end of file diff --git a/backend/pom.xml b/backend/pom.xml index 1405523..5819900 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -83,6 +83,11 @@ jackson-databind ${jackson.version} + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.version} + diff --git a/backend/src/main/java/com/fasterxml/jackson/databind/JsonTypeHandler.java b/backend/src/main/java/com/fasterxml/jackson/databind/JsonTypeHandler.java deleted file mode 100644 index b7ceb08..0000000 --- a/backend/src/main/java/com/fasterxml/jackson/databind/JsonTypeHandler.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.fasterxml.jackson.databind; - -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.apache.ibatis.type.BaseTypeHandler; -import org.apache.ibatis.type.JdbcType; - -/** - * 自定义的 JSON 类型处理器 - */ -public class JsonTypeHandler extends BaseTypeHandler { - private static final ObjectMapper MAPPER = new ObjectMapper(); - - @Override - public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) - throws SQLException { - try { - ps.setString(i, MAPPER.writeValueAsString(parameter)); - } catch (Exception e) { - throw new SQLException("Error converting JSON to String", e); - } - } - - @Override - public Object getNullableResult(ResultSet rs, String columnName) throws SQLException { - return parse(rs.getString(columnName)); - } - - @Override - public Object getNullableResult(ResultSet rs, int columnIndex) throws SQLException { - return parse(rs.getString(columnIndex)); - } - - @Override - public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { - return parse(cs.getString(columnIndex)); - } - - private Object parse(String json) throws SQLException { - try { - if (json == null || json.isEmpty()) { - return null; - } - return MAPPER.readValue(json, Object.class); - } catch (Exception e) { - throw new SQLException("Error converting String to JSON", e); - } - } -} \ No newline at end of file diff --git a/backend/src/main/java/ltd/qubit/survey/common/mybatis/InstantTypeHandler.java b/backend/src/main/java/ltd/qubit/survey/common/mybatis/InstantTypeHandler.java new file mode 100644 index 0000000..327f4ea --- /dev/null +++ b/backend/src/main/java/ltd/qubit/survey/common/mybatis/InstantTypeHandler.java @@ -0,0 +1,39 @@ +package ltd.qubit.survey.common.mybatis; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.time.Instant; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; + +/** + * Instant类型处理器 + */ +public class InstantTypeHandler extends BaseTypeHandler { + @Override + public void setNonNullParameter(PreparedStatement ps, int i, Instant parameter, JdbcType jdbcType) + throws SQLException { + ps.setTimestamp(i, Timestamp.from(parameter)); + } + + @Override + public Instant getNullableResult(ResultSet rs, String columnName) throws SQLException { + Timestamp timestamp = rs.getTimestamp(columnName); + return timestamp != null ? timestamp.toInstant() : null; + } + + @Override + public Instant getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + Timestamp timestamp = rs.getTimestamp(columnIndex); + return timestamp != null ? timestamp.toInstant() : null; + } + + @Override + public Instant getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + Timestamp timestamp = cs.getTimestamp(columnIndex); + return timestamp != null ? timestamp.toInstant() : null; + } +} \ No newline at end of file diff --git a/backend/src/main/java/ltd/qubit/survey/model/Option.java b/backend/src/main/java/ltd/qubit/survey/model/Option.java index 40301ee..f704614 100644 --- a/backend/src/main/java/ltd/qubit/survey/model/Option.java +++ b/backend/src/main/java/ltd/qubit/survey/model/Option.java @@ -1,6 +1,6 @@ package ltd.qubit.survey.model; -import java.time.LocalDateTime; +import java.time.Instant; import lombok.Data; /** @@ -36,5 +36,5 @@ public class Option { /** * 创建时间 */ - private LocalDateTime createdAt; + private Instant createdAt; } \ No newline at end of file diff --git a/backend/src/main/java/ltd/qubit/survey/model/Question.java b/backend/src/main/java/ltd/qubit/survey/model/Question.java index 2e06c26..3df9dbd 100644 --- a/backend/src/main/java/ltd/qubit/survey/model/Question.java +++ b/backend/src/main/java/ltd/qubit/survey/model/Question.java @@ -1,6 +1,6 @@ package ltd.qubit.survey.model; -import java.time.LocalDateTime; +import java.time.Instant; import lombok.Data; /** @@ -46,5 +46,5 @@ public class Question { /** * 创建时间 */ - private LocalDateTime createdAt; + private Instant createdAt; } \ No newline at end of file diff --git a/backend/src/main/java/ltd/qubit/survey/model/SurveyResponse.java b/backend/src/main/java/ltd/qubit/survey/model/SurveyResponse.java index e961eea..e360f78 100644 --- a/backend/src/main/java/ltd/qubit/survey/model/SurveyResponse.java +++ b/backend/src/main/java/ltd/qubit/survey/model/SurveyResponse.java @@ -1,6 +1,6 @@ package ltd.qubit.survey.model; -import java.time.LocalDateTime; +import java.time.Instant; import java.util.List; import lombok.Data; @@ -37,5 +37,5 @@ public class SurveyResponse { /** * 创建时间 */ - private LocalDateTime createdAt; + private Instant createdAt; } \ No newline at end of file diff --git a/backend/src/main/java/ltd/qubit/survey/model/User.java b/backend/src/main/java/ltd/qubit/survey/model/User.java index 86c8192..6dca0fa 100644 --- a/backend/src/main/java/ltd/qubit/survey/model/User.java +++ b/backend/src/main/java/ltd/qubit/survey/model/User.java @@ -1,6 +1,6 @@ package ltd.qubit.survey.model; -import java.time.LocalDateTime; +import java.time.Instant; import lombok.Data; /** @@ -36,5 +36,5 @@ public class User { /** * 创建时间 */ - private LocalDateTime createdAt; + private Instant createdAt; } \ No newline at end of file diff --git a/backend/src/main/java/ltd/qubit/survey/service/impl/OptionServiceImpl.java b/backend/src/main/java/ltd/qubit/survey/service/impl/OptionServiceImpl.java index 82680b8..9727847 100644 --- a/backend/src/main/java/ltd/qubit/survey/service/impl/OptionServiceImpl.java +++ b/backend/src/main/java/ltd/qubit/survey/service/impl/OptionServiceImpl.java @@ -1,6 +1,6 @@ package ltd.qubit.survey.service.impl; -import java.time.LocalDateTime; +import java.time.Instant; import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; @@ -19,7 +19,7 @@ public class OptionServiceImpl implements OptionService { @Override public Option create(Option option) { - option.setCreatedAt(LocalDateTime.now()); + option.setCreatedAt(Instant.now()); optionDao.insert(option); return option; } @@ -58,7 +58,7 @@ public class OptionServiceImpl implements OptionService { @Override public List