diff --git a/.cursorrules b/.cursorrules index e27756b..e462219 100644 --- a/.cursorrules +++ b/.cursorrules @@ -20,6 +20,8 @@ - WAR包目录:`$DOCKER_DATA_DIR/tomcat/webapps` - 应用上下文路径:`/llm-survey-api` - 复制文件时,使用 `command cp` 命令 +- 查看日志始终只查看应用的业务日志 +- 部署完成后应该稍等几秒查看下业务日志看看发布有没有错误 ## 4. 数据库规则 - 数据库名称:`llm_survey` diff --git a/backend/src/main/java/ltd/qubit/survey/dao/QuestionDao.java b/backend/src/main/java/ltd/qubit/survey/dao/QuestionDao.java index b4071d2..bd5cea4 100644 --- a/backend/src/main/java/ltd/qubit/survey/dao/QuestionDao.java +++ b/backend/src/main/java/ltd/qubit/survey/dao/QuestionDao.java @@ -3,7 +3,6 @@ package ltd.qubit.survey.dao; import java.util.List; import java.util.Optional; import ltd.qubit.survey.model.Question; -import ltd.qubit.survey.model.WorkArea; /** * 问题DAO接口 @@ -17,14 +16,6 @@ public interface QuestionDao extends BaseDao { */ Optional findByQuestionNumber(Integer questionNumber); - /** - * 根据工作领域查询问题列表 - * - * @param workArea 工作领域 - * @return 问题列表 - */ - List findByWorkArea(WorkArea workArea); - /** * 查询通用问题列表(不针对特定工作领域) * diff --git a/backend/src/main/java/ltd/qubit/survey/dao/UserDao.java b/backend/src/main/java/ltd/qubit/survey/dao/UserDao.java index 99916f2..7e12669 100644 --- a/backend/src/main/java/ltd/qubit/survey/dao/UserDao.java +++ b/backend/src/main/java/ltd/qubit/survey/dao/UserDao.java @@ -16,12 +16,4 @@ public interface UserDao extends BaseDao { * @return 用户对象 */ Optional findByPhone(String phone); - - /** - * 根据工作领域查询用户列表 - * - * @param workArea 工作领域 - * @return 用户列表 - */ - List findByWorkArea(WorkArea workArea); } \ No newline at end of file diff --git a/backend/src/main/java/ltd/qubit/survey/mapper/SurveyResponseMapper.xml b/backend/src/main/java/ltd/qubit/survey/mapper/SurveyResponseMapper.xml deleted file mode 100644 index aecc2ca..0000000 --- a/backend/src/main/java/ltd/qubit/survey/mapper/SurveyResponseMapper.xml +++ /dev/null @@ -1 +0,0 @@ - \ 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 163c795..142ce7b 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,7 @@ package ltd.qubit.survey.model; import java.time.Instant; +import java.util.Map; import lombok.Data; /** @@ -41,7 +42,12 @@ public class Question { /** * 跳转逻辑(JSON格式) */ - private String next; + private Map next; + + /** + * 是否是最后一题 + */ + private Boolean isLast; /** * 创建时间 diff --git a/backend/src/main/java/ltd/qubit/survey/service/QuestionService.java b/backend/src/main/java/ltd/qubit/survey/service/QuestionService.java index 9901aec..758534a 100644 --- a/backend/src/main/java/ltd/qubit/survey/service/QuestionService.java +++ b/backend/src/main/java/ltd/qubit/survey/service/QuestionService.java @@ -3,7 +3,6 @@ package ltd.qubit.survey.service; import java.util.List; import java.util.Optional; import ltd.qubit.survey.model.Question; -import ltd.qubit.survey.model.WorkArea; import org.springframework.transaction.annotation.Transactional; /** @@ -19,14 +18,6 @@ public interface QuestionService extends BaseService { */ Optional findByQuestionNumber(Integer questionNumber); - /** - * 根据工作领域查询问题列表 - * - * @param workArea 工作领域 - * @return 问题列表 - */ - List findByWorkArea(WorkArea workArea); - /** * 查询通用问题列表(不针对特定工作领域) * diff --git a/backend/src/main/java/ltd/qubit/survey/service/UserService.java b/backend/src/main/java/ltd/qubit/survey/service/UserService.java index af07437..81515cd 100644 --- a/backend/src/main/java/ltd/qubit/survey/service/UserService.java +++ b/backend/src/main/java/ltd/qubit/survey/service/UserService.java @@ -3,7 +3,6 @@ package ltd.qubit.survey.service; import java.util.List; import java.util.Optional; import ltd.qubit.survey.model.User; -import ltd.qubit.survey.model.WorkArea; import org.springframework.transaction.annotation.Transactional; /** @@ -19,14 +18,6 @@ public interface UserService extends BaseService { */ Optional findByPhone(String phone); - /** - * 根据工作领域查询用户列表 - * - * @param workArea 工作领域 - * @return 用户列表 - */ - List findByWorkArea(WorkArea workArea); - /** * 用户注册 * diff --git a/backend/src/main/java/ltd/qubit/survey/service/impl/QuestionServiceImpl.java b/backend/src/main/java/ltd/qubit/survey/service/impl/QuestionServiceImpl.java index b02522f..d157a6e 100644 --- a/backend/src/main/java/ltd/qubit/survey/service/impl/QuestionServiceImpl.java +++ b/backend/src/main/java/ltd/qubit/survey/service/impl/QuestionServiceImpl.java @@ -11,7 +11,6 @@ import lombok.RequiredArgsConstructor; import ltd.qubit.survey.dao.QuestionDao; import ltd.qubit.survey.model.Question; import ltd.qubit.survey.model.User; -import ltd.qubit.survey.model.WorkArea; import ltd.qubit.survey.service.QuestionService; import ltd.qubit.survey.service.UserService; import org.springframework.stereotype.Service; @@ -29,8 +28,8 @@ public class QuestionServiceImpl implements QuestionService { @Override public Question create(Question question) { // 如果没有指定问题序号,则自动生成 - if (question.getQuestionNumber() == null) { - question.setQuestionNumber(questionDao.getNextQuestionNumber()); + if (question.getNumber() == null) { + question.setNumber(questionDao.getNextQuestionNumber()); } question.setCreatedAt(Instant.now()); questionDao.insert(question); @@ -63,11 +62,6 @@ public class QuestionServiceImpl implements QuestionService { return questionDao.findByQuestionNumber(questionNumber); } - @Override - public List findByWorkArea(WorkArea workArea) { - return questionDao.findByWorkArea(workArea); - } - @Override public List findCommonQuestions() { return questionDao.findCommonQuestions(); @@ -75,6 +69,11 @@ public class QuestionServiceImpl implements QuestionService { @Override public Optional getNextQuestion(Long userId, Integer currentQuestionNumber, List selectedOptions) { + // 如果当前问题序号为0,返回第一个问题 + if (currentQuestionNumber == 0) { + return findByQuestionNumber(1); + } + // 获取当前问题 Optional currentQuestion = findByQuestionNumber(currentQuestionNumber); if (currentQuestion.isEmpty()) { @@ -82,21 +81,17 @@ public class QuestionServiceImpl implements QuestionService { } // 如果当前问题有跳转逻辑,则根据选项判断下一个问题 - String nextQuestionLogic = currentQuestion.get().getNextQuestionLogic(); - if (nextQuestionLogic != null && !nextQuestionLogic.isEmpty()) { - try { - // 解析跳转逻辑JSON - Map logic = objectMapper.readValue(nextQuestionLogic, - new TypeReference>() {}); - - // 根据选项确定下一个问题序号 - for (String option : selectedOptions) { - if (logic.containsKey(option)) { - return findByQuestionNumber(logic.get(option)); - } + Map next = currentQuestion.get().getNext(); + if (next != null && !next.isEmpty() && selectedOptions != null && !selectedOptions.isEmpty()) { + // 根据选项确定下一个问题序号 + for (String option : selectedOptions) { + if (next.containsKey(option)) { + return findByQuestionNumber(next.get(option)); } - } catch (Exception e) { - // JSON解析错误,继续使用默认的下一个问题 + } + // 如果有通配符跳转规则 + if (next.containsKey("*")) { + return findByQuestionNumber(next.get("*")); } } @@ -115,13 +110,10 @@ public class QuestionServiceImpl implements QuestionService { } // 添加通用问题 - questions.addAll(findCommonQuestions()); - - // 添加针对用户工作领域的问题 - questions.addAll(findByWorkArea(user.get().getWorkArea())); + questions.addAll(findAll()); // 按问题序号排序 - questions.sort((q1, q2) -> q1.getQuestionNumber().compareTo(q2.getQuestionNumber())); + questions.sort((q1, q2) -> q1.getNumber().compareTo(q2.getNumber())); return questions; } diff --git a/backend/src/main/java/ltd/qubit/survey/service/impl/SurveyResponseServiceImpl.java b/backend/src/main/java/ltd/qubit/survey/service/impl/SurveyResponseServiceImpl.java index d3e831b..3b6fb0c 100644 --- a/backend/src/main/java/ltd/qubit/survey/service/impl/SurveyResponseServiceImpl.java +++ b/backend/src/main/java/ltd/qubit/survey/service/impl/SurveyResponseServiceImpl.java @@ -89,7 +89,7 @@ public class SurveyResponseServiceImpl implements SurveyResponseService { .anyMatch(response -> response.getQuestionId().equals(question.getId())); if (!answered) { throw new IllegalArgumentException( - String.format("问题 %d 为必答题,请填写答案", question.getQuestionNumber())); + String.format("问题 %d 为必答题,请填写答案", question.getNumber())); } } } diff --git a/backend/src/main/java/ltd/qubit/survey/service/impl/UserServiceImpl.java b/backend/src/main/java/ltd/qubit/survey/service/impl/UserServiceImpl.java index 88ee60f..f149c3e 100644 --- a/backend/src/main/java/ltd/qubit/survey/service/impl/UserServiceImpl.java +++ b/backend/src/main/java/ltd/qubit/survey/service/impl/UserServiceImpl.java @@ -6,7 +6,6 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; import ltd.qubit.survey.dao.UserDao; import ltd.qubit.survey.model.User; -import ltd.qubit.survey.model.WorkArea; import ltd.qubit.survey.service.UserService; import org.springframework.stereotype.Service; @@ -51,11 +50,6 @@ public class UserServiceImpl implements UserService { return userDao.findByPhone(phone); } - @Override - public List findByWorkArea(WorkArea workArea) { - return userDao.findByWorkArea(workArea); - } - @Override public User register(User user) { // 检查手机号是否已注册 diff --git a/backend/src/main/resources/mybatis/mapper/QuestionMapper.xml b/backend/src/main/resources/mybatis/mapper/QuestionMapper.xml index 79c07ed..93e87dd 100644 --- a/backend/src/main/resources/mybatis/mapper/QuestionMapper.xml +++ b/backend/src/main/resources/mybatis/mapper/QuestionMapper.xml @@ -7,22 +7,23 @@ - + - `id`, `number`, `content`, `type`, `work_area`, `is_required`, `next`, `created_at` + `id`, `number`, `content`, `type`, `is_required`, `next`, `is_last`, `created_at` - INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `next`) - VALUES (#{number}, #{content}, #{type}, #{workArea}, #{isRequired}, - #{next,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler}) + INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `next`, `is_last`) + VALUES (#{number}, #{content}, #{type}, #{isRequired}, + #{next,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler}, + #{isLast}) @@ -31,9 +32,9 @@ SET `number` = #{number}, `content` = #{content}, `type` = #{type}, - `work_area` = #{workArea}, `is_required` = #{isRequired}, - `next` = #{next,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler} + `next` = #{next,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler}, + `is_last` = #{isLast} WHERE `id` = #{id} @@ -63,19 +64,10 @@ WHERE `number` = #{number} - - - diff --git a/backend/src/main/resources/mybatis/mapper/UserMapper.xml b/backend/src/main/resources/mybatis/mapper/UserMapper.xml index 431e6fd..43db318 100644 --- a/backend/src/main/resources/mybatis/mapper/UserMapper.xml +++ b/backend/src/main/resources/mybatis/mapper/UserMapper.xml @@ -55,12 +55,4 @@ FROM `user` WHERE `phone` = #{phone} - - - \ No newline at end of file diff --git a/backend/target/classes/ltd/qubit/survey/dao/QuestionDao.class b/backend/target/classes/ltd/qubit/survey/dao/QuestionDao.class index 9da36f7..0d2eb01 100644 Binary files a/backend/target/classes/ltd/qubit/survey/dao/QuestionDao.class and b/backend/target/classes/ltd/qubit/survey/dao/QuestionDao.class differ diff --git a/backend/target/classes/ltd/qubit/survey/dao/UserDao.class b/backend/target/classes/ltd/qubit/survey/dao/UserDao.class index 60e72fc..0f1583f 100644 Binary files a/backend/target/classes/ltd/qubit/survey/dao/UserDao.class and b/backend/target/classes/ltd/qubit/survey/dao/UserDao.class differ diff --git a/backend/target/classes/ltd/qubit/survey/model/Question.class b/backend/target/classes/ltd/qubit/survey/model/Question.class index c94dc66..c8a21b0 100644 Binary files a/backend/target/classes/ltd/qubit/survey/model/Question.class and b/backend/target/classes/ltd/qubit/survey/model/Question.class differ diff --git a/backend/target/classes/ltd/qubit/survey/model/User.class b/backend/target/classes/ltd/qubit/survey/model/User.class index 0999f2d..6564144 100644 Binary files a/backend/target/classes/ltd/qubit/survey/model/User.class and b/backend/target/classes/ltd/qubit/survey/model/User.class differ diff --git a/backend/target/classes/ltd/qubit/survey/service/QuestionService.class b/backend/target/classes/ltd/qubit/survey/service/QuestionService.class index b8db983..4d918e0 100644 Binary files a/backend/target/classes/ltd/qubit/survey/service/QuestionService.class and b/backend/target/classes/ltd/qubit/survey/service/QuestionService.class differ diff --git a/backend/target/classes/ltd/qubit/survey/service/UserService.class b/backend/target/classes/ltd/qubit/survey/service/UserService.class index e3a712f..492a713 100644 Binary files a/backend/target/classes/ltd/qubit/survey/service/UserService.class and b/backend/target/classes/ltd/qubit/survey/service/UserService.class differ diff --git a/backend/target/classes/ltd/qubit/survey/service/impl/QuestionServiceImpl$1.class b/backend/target/classes/ltd/qubit/survey/service/impl/QuestionServiceImpl$1.class deleted file mode 100644 index 6aac21f..0000000 Binary files a/backend/target/classes/ltd/qubit/survey/service/impl/QuestionServiceImpl$1.class and /dev/null differ diff --git a/backend/target/classes/ltd/qubit/survey/service/impl/QuestionServiceImpl.class b/backend/target/classes/ltd/qubit/survey/service/impl/QuestionServiceImpl.class index e552375..3f92959 100644 Binary files a/backend/target/classes/ltd/qubit/survey/service/impl/QuestionServiceImpl.class and b/backend/target/classes/ltd/qubit/survey/service/impl/QuestionServiceImpl.class differ diff --git a/backend/target/classes/ltd/qubit/survey/service/impl/SurveyResponseServiceImpl.class b/backend/target/classes/ltd/qubit/survey/service/impl/SurveyResponseServiceImpl.class index c7f603c..6475d51 100644 Binary files a/backend/target/classes/ltd/qubit/survey/service/impl/SurveyResponseServiceImpl.class and b/backend/target/classes/ltd/qubit/survey/service/impl/SurveyResponseServiceImpl.class differ diff --git a/backend/target/classes/ltd/qubit/survey/service/impl/UserServiceImpl.class b/backend/target/classes/ltd/qubit/survey/service/impl/UserServiceImpl.class index 9b40fe5..546c175 100644 Binary files a/backend/target/classes/ltd/qubit/survey/service/impl/UserServiceImpl.class and b/backend/target/classes/ltd/qubit/survey/service/impl/UserServiceImpl.class differ diff --git a/backend/target/classes/mybatis/mapper/OptionMapper.xml b/backend/target/classes/mybatis/mapper/OptionMapper.xml index a0533ce..da7f3c3 100644 --- a/backend/target/classes/mybatis/mapper/OptionMapper.xml +++ b/backend/target/classes/mybatis/mapper/OptionMapper.xml @@ -2,7 +2,7 @@ - + @@ -13,18 +13,18 @@ - id, question_id, option_code, content, requires_text, created_at + `id`, `question_id`, `option_code`, `content`, `requires_text`, `created_at` - INSERT INTO options (question_id, option_code, content, requires_text) + INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (#{questionId}, #{optionCode}, #{content}, #{requiresText}) - INSERT INTO options (question_id, option_code, content, requires_text) + INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (#{item.questionId}, #{item.optionCode}, #{item.content}, #{item.requiresText}) @@ -33,51 +33,51 @@ - UPDATE options - SET question_id = #{questionId}, - option_code = #{optionCode}, - content = #{content}, - requires_text = #{requiresText} - WHERE id = #{id} + UPDATE `option` + SET `question_id` = #{questionId}, + `option_code` = #{optionCode}, + `content` = #{content}, + `requires_text` = #{requiresText} + WHERE `id` = #{id} - DELETE FROM options WHERE id = #{id} + DELETE FROM `option` WHERE `id` = #{id} - DELETE FROM options WHERE question_id = #{questionId} + DELETE FROM `option` WHERE `question_id` = #{questionId} - SELECT - FROM options - WHERE id = #{id} + FROM `option` + WHERE `id` = #{id} - SELECT - FROM options - ORDER BY question_id, option_code + FROM `option` + ORDER BY `question_id`, `option_code` - SELECT - FROM options - WHERE question_id = #{questionId} - ORDER BY option_code + FROM `option` + WHERE `question_id` = #{questionId} + ORDER BY `option_code` - SELECT - FROM options - WHERE question_id = #{questionId} - AND option_code = #{optionCode} + FROM `option` + WHERE `question_id` = #{questionId} + AND `option_code` = #{optionCode} \ No newline at end of file diff --git a/backend/target/classes/mybatis/mapper/QuestionMapper.xml b/backend/target/classes/mybatis/mapper/QuestionMapper.xml index 4d3d902..93e87dd 100644 --- a/backend/target/classes/mybatis/mapper/QuestionMapper.xml +++ b/backend/target/classes/mybatis/mapper/QuestionMapper.xml @@ -4,83 +4,76 @@ - + - - + - + + - id, question_number, content, question_type, work_area, is_required, next_question_logic, created_at + `id`, `number`, `content`, `type`, `is_required`, `next`, `is_last`, `created_at` - INSERT INTO questions (question_number, content, question_type, work_area, is_required, next_question_logic) - VALUES (#{questionNumber}, #{content}, #{questionType}, #{workArea}, #{isRequired}, #{nextQuestionLogic}) + INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `next`, `is_last`) + VALUES (#{number}, #{content}, #{type}, #{isRequired}, + #{next,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler}, + #{isLast}) - UPDATE questions - SET question_number = #{questionNumber}, - content = #{content}, - question_type = #{questionType}, - work_area = #{workArea}, - is_required = #{isRequired}, - next_question_logic = #{nextQuestionLogic} - WHERE id = #{id} + UPDATE `question` + SET `number` = #{number}, + `content` = #{content}, + `type` = #{type}, + `is_required` = #{isRequired}, + `next` = #{next,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler}, + `is_last` = #{isLast} + WHERE `id` = #{id} - DELETE FROM questions WHERE id = #{id} + DELETE FROM `question` WHERE `id` = #{id} - - - \ No newline at end of file diff --git a/backend/target/classes/mybatis/mapper/SurveyResponseMapper.xml b/backend/target/classes/mybatis/mapper/SurveyResponseMapper.xml index a3b78aa..c954675 100644 --- a/backend/target/classes/mybatis/mapper/SurveyResponseMapper.xml +++ b/backend/target/classes/mybatis/mapper/SurveyResponseMapper.xml @@ -13,18 +13,18 @@ - id, user_id, question_id, selected_options, text_answer, created_at + `id`, `user_id`, `question_id`, `selected_options`, `text_answer`, `created_at` - INSERT INTO survey_responses (user_id, question_id, selected_options, text_answer) + INSERT INTO `survey_response` (`user_id`, `question_id`, `selected_options`, `text_answer`) VALUES (#{userId}, #{questionId}, #{selectedOptions,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler}, #{textAnswer}) - INSERT INTO survey_responses (user_id, question_id, selected_options, text_answer) + INSERT INTO `survey_response` (`user_id`, `question_id`, `selected_options`, `text_answer`) VALUES (#{item.userId}, #{item.questionId}, @@ -35,59 +35,59 @@ - UPDATE survey_responses - SET user_id = #{userId}, - question_id = #{questionId}, - selected_options = #{selectedOptions,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler}, - text_answer = #{textAnswer} - WHERE id = #{id} + UPDATE `survey_response` + SET `user_id` = #{userId}, + `question_id` = #{questionId}, + `selected_options` = #{selectedOptions,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler}, + `text_answer` = #{textAnswer} + WHERE `id` = #{id} - DELETE FROM survey_responses WHERE id = #{id} + DELETE FROM `survey_response` WHERE `id` = #{id} - DELETE FROM survey_responses WHERE user_id = #{userId} + DELETE FROM `survey_response` WHERE `user_id` = #{userId} \ No newline at end of file diff --git a/backend/target/classes/mybatis/mapper/UserMapper.xml b/backend/target/classes/mybatis/mapper/UserMapper.xml index da8010d..43db318 100644 --- a/backend/target/classes/mybatis/mapper/UserMapper.xml +++ b/backend/target/classes/mybatis/mapper/UserMapper.xml @@ -6,63 +6,53 @@ - - id, name, phone, work_area, position_type, created_at + `id`, `name`, `phone`, `position_type`, `created_at` - INSERT INTO users (name, phone, work_area, position_type) - VALUES (#{name}, #{phone}, #{workArea}, #{positionType}) + INSERT INTO `user` (`name`, `phone`, `position_type`) + VALUES (#{name}, #{phone}, #{positionType}) - UPDATE users - SET name = #{name}, - phone = #{phone}, - work_area = #{workArea}, - position_type = #{positionType} - WHERE id = #{id} + UPDATE `user` + SET `name` = #{name}, + `phone` = #{phone}, + `position_type` = #{positionType} + WHERE `id` = #{id} - DELETE FROM users WHERE id = #{id} + DELETE FROM `user` WHERE `id` = #{id} - - - \ No newline at end of file diff --git a/backend/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/backend/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index 2b1fcaa..a92df7b 100644 --- a/backend/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/backend/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -15,7 +15,6 @@ ltd/qubit/survey/utils/CustomObjectMapper.class ltd/qubit/survey/model/User.class ltd/qubit/survey/service/QuestionService.class ltd/qubit/survey/common/mybatis/JsonTypeHandler.class -ltd/qubit/survey/service/impl/QuestionServiceImpl$1.class ltd/qubit/survey/service/UserService.class ltd/qubit/survey/dao/BaseDao.class ltd/qubit/survey/service/impl/OptionServiceImpl.class diff --git a/database/init_database.sql b/database/init_database.sql index fc6597a..a13e2c7 100644 --- a/database/init_database.sql +++ b/database/init_database.sql @@ -3,6 +3,12 @@ CREATE DATABASE IF NOT EXISTS `llm_survey` DEFAULT CHARACTER SET utf8mb4 COLLATE USE `llm_survey`; +-- 删除旧表(如果存在) +DROP TABLE IF EXISTS `survey_response`; +DROP TABLE IF EXISTS `option`; +DROP TABLE IF EXISTS `question`; +DROP TABLE IF EXISTS `user`; + -- 创建用户表 CREATE TABLE IF NOT EXISTS `user` ( `id` BIGINT PRIMARY KEY AUTO_INCREMENT, @@ -22,6 +28,7 @@ CREATE TABLE IF NOT EXISTS `question` ( `work_area` VARCHAR(20) DEFAULT NULL COMMENT '针对的工作领域', `is_required` BOOLEAN NOT NULL DEFAULT TRUE COMMENT '是否必答', `next` JSON DEFAULT NULL COMMENT '跳转逻辑', + `is_last` BOOLEAN NOT NULL DEFAULT FALSE COMMENT '是否是最后一题', `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', UNIQUE KEY `uk_number` (`number`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='问题表'; @@ -59,8 +66,8 @@ TRUNCATE TABLE `user`; SET FOREIGN_KEY_CHECKS = 1; -- 插入通用认知问题 -INSERT INTO `question` (`number`, `content`, `type`, `is_required`) -VALUES (1, '您对大模型(如ChatGPT、通义千问、DeepSeek)的了解程度:', 'SINGLE_CHOICE', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`) +VALUES (1, '您对大模型(如ChatGPT、通义千问、DeepSeek)的了解程度:', 'SINGLE_CHOICE', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`) VALUES (LAST_INSERT_ID(), 'A', '从未接触过'), @@ -68,8 +75,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`) VALUES (LAST_INSERT_ID(), 'C', '在工作中尝试过基础应用'), (LAST_INSERT_ID(), 'D', '深度研究过技术原理'); -INSERT INTO `question` (`number`, `content`, `type`, `is_required`) -VALUES (2, '您觉得大模型可以做到下面哪些事?', 'MULTIPLE_CHOICE', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`) +VALUES (2, '您觉得大模型可以做到下面哪些事?', 'MULTIPLE_CHOICE', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '精准知识问答', FALSE), @@ -80,8 +87,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'F', '流程自动化', FALSE), (LAST_INSERT_ID(), 'G', '其他', TRUE); -INSERT INTO `question` (`number`, `content`, `type`, `is_required`) -VALUES (3, '您最关注大模型应用的哪些风险?', 'MULTIPLE_CHOICE', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`) +VALUES (3, '您最关注大模型应用的哪些风险?', 'MULTIPLE_CHOICE', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '数据隐私泄露', FALSE), @@ -90,8 +97,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'D', '技术使用门槛高', FALSE), (LAST_INSERT_ID(), 'E', '其他', TRUE); -INSERT INTO `question` (`number`, `content`, `type`, `is_required`) -VALUES (4, '您的主要工作内容是:', 'SINGLE_CHOICE', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`) +VALUES (4, '您的主要工作内容是:', 'SINGLE_CHOICE', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`) VALUES (LAST_INSERT_ID(), 'A', '研发(产品、开发、算法、测试、运维等)'), @@ -106,8 +113,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`) VALUES (LAST_INSERT_ID(), 'J', '公司高管(战略规划、组织架构、制度建设等)'); -- 研发部门专属问题 -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (5, '您在开发过程中最耗时的重复性工作:', 'MULTIPLE_CHOICE', 'RD', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (5, '您在开发过程中最耗时的重复性工作:', 'MULTIPLE_CHOICE', 'RD', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '文档编写(如需求文档、技术文档等)', FALSE), @@ -117,8 +124,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'E', '系统监控与维护', FALSE), (LAST_INSERT_ID(), 'F', '其他', TRUE); -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (6, '您希望大模型如何与现有系统集成:', 'MULTIPLE_CHOICE', 'RD', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (6, '您希望大模型如何与现有系统集成:', 'MULTIPLE_CHOICE', 'RD', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '回答技术问题', FALSE), @@ -131,8 +138,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'H', '其他', TRUE); -- 项目管理专属问题 -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (7, '项目管理中最常遇到的挑战是:', 'MULTIPLE_CHOICE', 'PROJECT', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (7, '项目管理中最常遇到的挑战是:', 'MULTIPLE_CHOICE', 'PROJECT', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '项目进度跟踪与更新', FALSE), @@ -140,8 +147,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'C', '项目报告生成', FALSE), (LAST_INSERT_ID(), 'D', '其他', TRUE); -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (8, '您希望如何利用大模型提升项目管理效率:', 'MULTIPLE_CHOICE', 'PROJECT', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (8, '您希望如何利用大模型提升项目管理效率:', 'MULTIPLE_CHOICE', 'PROJECT', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '自动生成立项报告、进度报告、总结报告等', FALSE), @@ -151,8 +158,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'E', '其他', TRUE); -- 保险专属问题 -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (9, '理赔处理中的主要瓶颈是:', 'MULTIPLE_CHOICE', 'INSURANCE', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (9, '理赔处理中的主要瓶颈是:', 'MULTIPLE_CHOICE', 'INSURANCE', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '理赔文档处理', FALSE), @@ -161,8 +168,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'D', '理赔规则理解与应用', FALSE), (LAST_INSERT_ID(), 'E', '其他', TRUE); -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (10, '大模型可以优化哪些保险工作环节:', 'MULTIPLE_CHOICE', 'INSURANCE', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (10, '大模型可以优化哪些保险工作环节:', 'MULTIPLE_CHOICE', 'INSURANCE', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '新员工入职培训', FALSE), @@ -173,8 +180,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'F', '其他', TRUE); -- 财务专属问题 -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (11, '日常工作中最重复的任务是:', 'MULTIPLE_CHOICE', 'FINANCE', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (11, '日常工作中最重复的任务是:', 'MULTIPLE_CHOICE', 'FINANCE', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '财务数据整理与报表生成', FALSE), @@ -182,8 +189,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'C', '财务审计与合规检查', FALSE), (LAST_INSERT_ID(), 'D', '其他', TRUE); -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (12, '大模型能如何协助提升财务工作效率:', 'MULTIPLE_CHOICE', 'FINANCE', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (12, '大模型能如何协助提升财务工作效率:', 'MULTIPLE_CHOICE', 'FINANCE', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '各种报表格式的自动转换', FALSE), @@ -193,8 +200,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'E', '其他', TRUE); -- 客服专属问题 -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (13, '客户咨询中最常遇到的重复性问题:', 'MULTIPLE_CHOICE', 'CUSTOMER_SERVICE', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (13, '客户咨询中最常遇到的重复性问题:', 'MULTIPLE_CHOICE', 'CUSTOMER_SERVICE', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '参保资格咨询', FALSE), @@ -202,8 +209,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'C', '材料补交通知', FALSE), (LAST_INSERT_ID(), 'D', '其他', TRUE); -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (14, '您希望大模型如何辅助客服工作:', 'MULTIPLE_CHOICE', 'CUSTOMER_SERVICE', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (14, '您希望大模型如何辅助客服工作:', 'MULTIPLE_CHOICE', 'CUSTOMER_SERVICE', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '自动生成客户回复模板', FALSE), @@ -212,8 +219,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'D', '其他', TRUE); -- 运营专属问题 -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (15, '在运营工作中,最需要自动化支持的任务是:', 'MULTIPLE_CHOICE', 'OPERATION', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (15, '在运营工作中,最需要自动化支持的任务是:', 'MULTIPLE_CHOICE', 'OPERATION', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '热点讯息的获取和跟踪', FALSE), @@ -222,8 +229,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'D', '活动效果评估与预测', FALSE), (LAST_INSERT_ID(), 'E', '其他', TRUE); -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (16, '大模型可以如何帮助提升运营效率:', 'MULTIPLE_CHOICE', 'OPERATION', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (16, '大模型可以如何帮助提升运营效率:', 'MULTIPLE_CHOICE', 'OPERATION', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '自动抓取热点讯息', FALSE), @@ -233,8 +240,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'E', '其他', TRUE); -- 市场拓展专属问题 -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (17, '在市场拓展和商务沟通中,您最常遇到的挑战是:', 'MULTIPLE_CHOICE', 'MARKET', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (17, '在市场拓展和商务沟通中,您最常遇到的挑战是:', 'MULTIPLE_CHOICE', 'MARKET', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '市场分析和竞争对手跟踪', FALSE), @@ -242,8 +249,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'C', '商务沟通中的信息处理与反馈跟踪', FALSE), (LAST_INSERT_ID(), 'D', '其他', TRUE); -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (18, '您希望大模型如何帮助提升市场拓展效率:', 'MULTIPLE_CHOICE', 'MARKET', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (18, '您希望大模型如何帮助提升市场拓展效率:', 'MULTIPLE_CHOICE', 'MARKET', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '自动生成市场分析报告与趋势预测', FALSE), @@ -252,8 +259,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'D', '其他', TRUE); -- 人力资源专属问题 -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (19, '人事部门最耗时的日常任务是:', 'MULTIPLE_CHOICE', 'HR', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (19, '人事部门最耗时的日常任务是:', 'MULTIPLE_CHOICE', 'HR', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '招聘简历筛选与面试安排', FALSE), @@ -261,8 +268,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'C', '绩效评估与报告生成', FALSE), (LAST_INSERT_ID(), 'D', '其他', TRUE); -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (20, '您希望大模型如何协助提升人事工作效率:', 'MULTIPLE_CHOICE', 'HR', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (20, '您希望大模型如何协助提升人事工作效率:', 'MULTIPLE_CHOICE', 'HR', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '自动筛选招聘简历并推荐候选人', FALSE), @@ -271,8 +278,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'D', '其他', TRUE); -- 综合管理专属问题 -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (21, '在行政工作中,最耗时的任务是:', 'MULTIPLE_CHOICE', 'ADMIN', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (21, '在行政工作中,最耗时的任务是:', 'MULTIPLE_CHOICE', 'ADMIN', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '合同审查与管理', FALSE), @@ -280,8 +287,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'C', '文档管理与更新', FALSE), (LAST_INSERT_ID(), 'D', '其他', TRUE); -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (22, '您希望大模型如何协助提升行政工作效率:', 'MULTIPLE_CHOICE', 'ADMIN', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (22, '您希望大模型如何协助提升行政工作效率:', 'MULTIPLE_CHOICE', 'ADMIN', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '自动生成合同和协议模板', FALSE), @@ -290,8 +297,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'D', '其他', TRUE); -- 公司高管专属问题 -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (23, '您认为大模型在哪些战略层面的决策中可以发挥作用?', 'MULTIPLE_CHOICE', 'EXECUTIVE', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (23, '您认为大模型在哪些战略层面的决策中可以发挥作用?', 'MULTIPLE_CHOICE', 'EXECUTIVE', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '市场趋势预测与分析', FALSE), @@ -299,8 +306,8 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'C', '业务流程优化与重组', FALSE), (LAST_INSERT_ID(), 'D', '其他', TRUE); -INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`) -VALUES (24, '在公司管理工作中,您最希望大模型协助哪些任务?', 'MULTIPLE_CHOICE', 'EXECUTIVE', TRUE); +INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) +VALUES (24, '在公司管理工作中,您最希望大模型协助哪些任务?', 'MULTIPLE_CHOICE', 'EXECUTIVE', TRUE, FALSE); INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (LAST_INSERT_ID(), 'A', '数据分析与报告自动生成', FALSE), @@ -309,11 +316,11 @@ INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) (LAST_INSERT_ID(), 'D', '其他', TRUE); -- 开放建议问题 -INSERT INTO `question` (`number`, `content`, `type`, `is_required`) -VALUES (25, '您对大模型培训的具体期待:', 'TEXT', FALSE); +INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`) +VALUES (25, '您对大模型培训的具体期待:', 'TEXT', FALSE, FALSE); -INSERT INTO `question` (`number`, `content`, `type`, `is_required`) -VALUES (26, '您认为公司引入AI需提前防范的风险:', 'TEXT', FALSE); +INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`) +VALUES (26, '您认为公司引入AI需提前防范的风险:', 'TEXT', FALSE, TRUE); -- 设置问题跳转逻辑 UPDATE `question` @@ -363,4 +370,7 @@ UPDATE `question` SET `next` = JSON_OBJECT('*', 25) WHERE `number` = 22; UPDATE `question` SET `next` = JSON_OBJECT('*', 25) WHERE `number` = 24; -- 第一个开放性问题跳转到第二个 -UPDATE `question` SET `next` = JSON_OBJECT('*', 26) WHERE `number` = 25; \ No newline at end of file +UPDATE `question` SET `next` = JSON_OBJECT('*', 26) WHERE `number` = 25; + +-- 设置最后一题标记 +UPDATE `question` SET `is_last` = TRUE WHERE `number` = 26; \ No newline at end of file diff --git a/frontend/src/api/survey.js b/frontend/src/api/survey.js index 646ef11..5963517 100644 --- a/frontend/src/api/survey.js +++ b/frontend/src/api/survey.js @@ -17,15 +17,24 @@ export function getQuestionOptions(questionId) { } // 获取下一个问题 -export function getNextQuestion(userId, currentQuestionNumber, selectedOptions) { +export function getNextQuestion(userId, selectedOptions, currentQuestionNumber) { + console.log('API调用参数:', { userId, selectedOptions, currentQuestionNumber }); + const params = { + userId + }; + + // 只有在不是第一次请求时才添加这些参数 + if (selectedOptions) { + params.selectedOptions = selectedOptions.join(','); + } + if (currentQuestionNumber !== undefined) { + params.currentQuestionNumber = currentQuestionNumber; + } + return request({ url: '/question/next', method: 'get', - params: { - userId, - currentQuestionNumber, - selectedOptions, - }, + params }); } diff --git a/frontend/src/stores/survey.js b/frontend/src/stores/survey.js index f388aea..96ebc52 100644 --- a/frontend/src/stores/survey.js +++ b/frontend/src/stores/survey.js @@ -13,14 +13,15 @@ export const useSurveyStore = defineStore('survey', () => { const currentQuestion = ref(null); const questionOptions = ref([]); const userResponses = ref([]); - const currentQuestionNumber = ref(0); + const currentQuestionNumber = ref(null); + const currentOptions = ref([]); const isCompleted = ref(false); // 获取用户的问题列表 async function fetchUserQuestions(userId) { try { const response = await getUserQuestions(userId); - return response.data; + return response; } catch (error) { showToast('获取问题列表失败:' + error.message); throw error; @@ -30,10 +31,13 @@ export const useSurveyStore = defineStore('survey', () => { // 获取问题的选项列表 async function fetchQuestionOptions(questionId) { try { - const response = await getQuestionOptions(questionId); - questionOptions.value = response.data; - return response.data; + console.log('获取问题选项,问题ID:', questionId); + const options = await getQuestionOptions(questionId); + console.log('获取到的选项:', options); + currentOptions.value = options; + return options; } catch (error) { + console.error('获取问题选项失败:', error); showToast('获取问题选项失败:' + error.message); throw error; } @@ -42,19 +46,35 @@ export const useSurveyStore = defineStore('survey', () => { // 获取下一个问题 async function fetchNextQuestion(userId, selectedOptions) { try { - // 如果是初始化(currentQuestionNumber为0),则从第3题开始 - const questionNumber = currentQuestionNumber.value === 0 ? 3 : currentQuestionNumber.value; - const response = await getNextQuestion(userId, questionNumber, selectedOptions); - if (response) { - currentQuestion.value = response; - currentQuestionNumber.value = response.questionNumber; - await fetchQuestionOptions(response.id); + console.log('获取下一个问题,参数:', { userId, selectedOptions, currentQuestionNumber: currentQuestionNumber.value }); + + // 如果没有当前问题号,说明是新开始的问卷 + const isNewSurvey = !currentQuestionNumber.value; + + const question = await getNextQuestion( + userId, + selectedOptions, + isNewSurvey ? undefined : currentQuestionNumber.value + ); + console.log('获取到的问题:', question); + + if (question) { + currentQuestion.value = question; + currentQuestionNumber.value = question.number; + + // 获取问题的选项 + console.log('开始获取问题选项'); + const options = await getQuestionOptions(question.id); + console.log('获取到的选项:', options); + currentOptions.value = options; } else { + console.log('没有更多问题了'); isCompleted.value = true; } - return response; + + return question; } catch (error) { - showToast('获取下一个问题失败:' + error.message); + console.error('获取下一个问题失败:', error); throw error; } } @@ -64,7 +84,7 @@ export const useSurveyStore = defineStore('survey', () => { try { const response = await submitSurvey(userId, responses); userResponses.value = responses; - return response.data; + return response; } catch (error) { showToast('提交问卷失败:' + error.message); throw error; @@ -75,8 +95,8 @@ export const useSurveyStore = defineStore('survey', () => { async function fetchUserResponses(userId) { try { const response = await getUserResponses(userId); - userResponses.value = response.data; - return response.data; + userResponses.value = response; + return response; } catch (error) { showToast('获取问卷答案失败:' + error.message); throw error; @@ -87,8 +107,13 @@ export const useSurveyStore = defineStore('survey', () => { function resetSurvey() { currentQuestion.value = null; questionOptions.value = []; - currentQuestionNumber.value = 0; + userResponses.value = []; + currentQuestionNumber.value = null; + currentOptions.value = []; isCompleted.value = false; + // 清除本地存储中的问卷相关数据 + localStorage.removeItem('surveyProgress'); + localStorage.removeItem('surveyResponses'); } return { @@ -96,6 +121,7 @@ export const useSurveyStore = defineStore('survey', () => { questionOptions, userResponses, currentQuestionNumber, + currentOptions, isCompleted, fetchUserQuestions, fetchQuestionOptions, diff --git a/frontend/src/stores/user.js b/frontend/src/stores/user.js index 88d4ad1..e94dc16 100644 --- a/frontend/src/stores/user.js +++ b/frontend/src/stores/user.js @@ -2,6 +2,7 @@ import { defineStore } from 'pinia'; import { ref } from 'vue'; import { register, checkPhone, getUserInfo } from '@/api/user'; import { showToast } from 'vant'; +import { useSurveyStore } from './survey'; export const useUserStore = defineStore('user', () => { const userId = ref(localStorage.getItem('userId') || ''); @@ -87,10 +88,10 @@ export const useUserStore = defineStore('user', () => { // 退出登录 function logout() { - userId.value = ''; - userInfo.value = null; + const surveyStore = useSurveyStore(); + userId.value = null; localStorage.removeItem('userId'); - console.log('用户已登出'); + surveyStore.resetSurvey(); } return { diff --git a/frontend/src/views/SurveyView.vue b/frontend/src/views/SurveyView.vue index 0d78fd9..baa6dfc 100644 --- a/frontend/src/views/SurveyView.vue +++ b/frontend/src/views/SurveyView.vue @@ -8,41 +8,66 @@ />
-
- - - - - - - - - - - - - - -
+
+

+ {{ surveyStore.currentQuestionNumber }}. {{ surveyStore.currentQuestion.content }} + (多选) +

+ + + + + + + + + + + + + + + + +
+ +
+
- 下一题 + {{ surveyStore.currentQuestion?.isLast ? '完成' : '下一题' }}
@@ -51,25 +76,29 @@
- + +
+

您的反馈对我们非常重要

+

我们将根据调查结果持续改进和优化

+
- 重新开始 + 返回首页