feat: 修改问题跳转逻辑,使用第4题的选择结果来决定跳转,移除后端工作领域判断逻辑

This commit is contained in:
胡海星 2025-02-23 15:30:26 +08:00
parent 480008777b
commit 67a6a13b1d
32 changed files with 426 additions and 347 deletions

View File

@ -20,6 +20,8 @@
- WAR包目录`$DOCKER_DATA_DIR/tomcat/webapps`
- 应用上下文路径:`/llm-survey-api`
- 复制文件时,使用 `command cp` 命令
- 查看日志始终只查看应用的业务日志
- 部署完成后应该稍等几秒查看下业务日志看看发布有没有错误
## 4. 数据库规则
- 数据库名称:`llm_survey`

View File

@ -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<Question, Long> {
*/
Optional<Question> findByQuestionNumber(Integer questionNumber);
/**
* 根据工作领域查询问题列表
*
* @param workArea 工作领域
* @return 问题列表
*/
List<Question> findByWorkArea(WorkArea workArea);
/**
* 查询通用问题列表不针对特定工作领域
*

View File

@ -16,12 +16,4 @@ public interface UserDao extends BaseDao<User, Long> {
* @return 用户对象
*/
Optional<User> findByPhone(String phone);
/**
* 根据工作领域查询用户列表
*
* @param workArea 工作领域
* @return 用户列表
*/
List<User> findByWorkArea(WorkArea workArea);
}

View File

@ -1 +0,0 @@
<result property="selectedOptions" column="selected_options" typeHandler="ltd.qubit.survey.common.mybatis.JsonTypeHandler"/>

View File

@ -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<String, Integer> next;
/**
* 是否是最后一题
*/
private Boolean isLast;
/**
* 创建时间

View File

@ -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<Question, Long> {
*/
Optional<Question> findByQuestionNumber(Integer questionNumber);
/**
* 根据工作领域查询问题列表
*
* @param workArea 工作领域
* @return 问题列表
*/
List<Question> findByWorkArea(WorkArea workArea);
/**
* 查询通用问题列表不针对特定工作领域
*

View File

@ -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<User, Long> {
*/
Optional<User> findByPhone(String phone);
/**
* 根据工作领域查询用户列表
*
* @param workArea 工作领域
* @return 用户列表
*/
List<User> findByWorkArea(WorkArea workArea);
/**
* 用户注册
*

View File

@ -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<Question> findByWorkArea(WorkArea workArea) {
return questionDao.findByWorkArea(workArea);
}
@Override
public List<Question> findCommonQuestions() {
return questionDao.findCommonQuestions();
@ -75,6 +69,11 @@ public class QuestionServiceImpl implements QuestionService {
@Override
public Optional<Question> getNextQuestion(Long userId, Integer currentQuestionNumber, List<String> selectedOptions) {
// 如果当前问题序号为0返回第一个问题
if (currentQuestionNumber == 0) {
return findByQuestionNumber(1);
}
// 获取当前问题
Optional<Question> 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<String, Integer> logic = objectMapper.readValue(nextQuestionLogic,
new TypeReference<Map<String, Integer>>() {});
// 根据选项确定下一个问题序号
for (String option : selectedOptions) {
if (logic.containsKey(option)) {
return findByQuestionNumber(logic.get(option));
}
Map<String, Integer> 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;
}

View File

@ -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()));
}
}
}

View File

@ -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<User> findByWorkArea(WorkArea workArea) {
return userDao.findByWorkArea(workArea);
}
@Override
public User register(User user) {
// 检查手机号是否已注册

View File

@ -7,22 +7,23 @@
<result property="number" column="number"/>
<result property="content" column="content"/>
<result property="type" column="type"/>
<result property="workArea" column="work_area"/>
<result property="isRequired" column="is_required"/>
<result property="next" column="next" typeHandler="ltd.qubit.survey.common.mybatis.JsonTypeHandler"/>
<result property="isLast" column="is_last"/>
<result property="createdAt" column="created_at"/>
</resultMap>
<!-- 基础列 -->
<sql id="baseColumns">
`id`, `number`, `content`, `type`, `work_area`, `is_required`, `next`, `created_at`
`id`, `number`, `content`, `type`, `is_required`, `next`, `is_last`, `created_at`
</sql>
<!-- 插入 -->
<insert id="insert" parameterType="ltd.qubit.survey.model.Question" useGeneratedKeys="true" keyProperty="id">
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})
</insert>
<!-- 更新 -->
@ -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}
</update>
@ -63,19 +64,10 @@
WHERE `number` = #{number}
</select>
<!-- 根据工作领域查询 -->
<select id="findByWorkArea" parameterType="string" resultMap="questionMap">
SELECT <include refid="baseColumns"/>
FROM `question`
WHERE `work_area` = #{workArea}
ORDER BY `number`
</select>
<!-- 查询通用问题 -->
<select id="findCommonQuestions" resultMap="questionMap">
SELECT <include refid="baseColumns"/>
FROM `question`
WHERE `work_area` IS NULL
ORDER BY `number`
</select>

View File

@ -55,12 +55,4 @@
FROM `user`
WHERE `phone` = #{phone}
</select>
<!-- 根据工作领域查询 -->
<select id="findByWorkArea" parameterType="string" resultMap="userMap">
SELECT <include refid="baseColumns"/>
FROM `user`
WHERE `work_area` = #{workArea}
ORDER BY `id`
</select>
</mapper>

View File

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="ltd.qubit.survey.dao.OptionDao">
<!-- 结果映射 -->
<resultMap id="baseOptionMap" type="ltd.qubit.survey.model.Option">
<resultMap id="optionMap" type="ltd.qubit.survey.model.Option">
<id property="id" column="id"/>
<result property="questionId" column="question_id"/>
<result property="optionCode" column="option_code"/>
@ -13,18 +13,18 @@
<!-- 基础列 -->
<sql id="baseColumns">
id, question_id, option_code, content, requires_text, created_at
`id`, `question_id`, `option_code`, `content`, `requires_text`, `created_at`
</sql>
<!-- 插入 -->
<insert id="insert" parameterType="ltd.qubit.survey.model.Option" useGeneratedKeys="true" keyProperty="id">
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>
<!-- 批量插入 -->
<insert id="batchInsert" parameterType="java.util.List">
INSERT INTO options (question_id, option_code, content, requires_text)
INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`)
VALUES
<foreach collection="list" item="item" separator=",">
(#{item.questionId}, #{item.optionCode}, #{item.content}, #{item.requiresText})
@ -33,51 +33,51 @@
<!-- 更新 -->
<update id="update" parameterType="ltd.qubit.survey.model.Option">
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}
</update>
<!-- 删除 -->
<delete id="deleteById" parameterType="long">
DELETE FROM options WHERE id = #{id}
DELETE FROM `option` WHERE `id` = #{id}
</delete>
<!-- 根据问题ID删除 -->
<delete id="deleteByQuestionId" parameterType="long">
DELETE FROM options WHERE question_id = #{questionId}
DELETE FROM `option` WHERE `question_id` = #{questionId}
</delete>
<!-- 根据ID查询 -->
<select id="findById" parameterType="long" resultMap="baseOptionMap">
<select id="findById" parameterType="long" resultMap="optionMap">
SELECT <include refid="baseColumns"/>
FROM options
WHERE id = #{id}
FROM `option`
WHERE `id` = #{id}
</select>
<!-- 查询所有 -->
<select id="findAll" resultMap="baseOptionMap">
<select id="findAll" resultMap="optionMap">
SELECT <include refid="baseColumns"/>
FROM options
ORDER BY question_id, option_code
FROM `option`
ORDER BY `question_id`, `option_code`
</select>
<!-- 根据问题ID查询 -->
<select id="findByQuestionId" parameterType="long" resultMap="baseOptionMap">
<select id="findByQuestionId" parameterType="long" resultMap="optionMap">
SELECT <include refid="baseColumns"/>
FROM options
WHERE question_id = #{questionId}
ORDER BY option_code
FROM `option`
WHERE `question_id` = #{questionId}
ORDER BY `option_code`
</select>
<!-- 根据问题ID和选项代码查询 -->
<select id="findByQuestionIdAndCode" resultMap="baseOptionMap">
<select id="findByQuestionIdAndOptionCode" resultMap="optionMap">
SELECT <include refid="baseColumns"/>
FROM options
WHERE question_id = #{questionId}
AND option_code = #{optionCode}
FROM `option`
WHERE `question_id` = #{questionId}
AND `option_code` = #{optionCode}
</select>
</mapper>

View File

@ -4,83 +4,76 @@
<!-- 结果映射 -->
<resultMap id="questionMap" type="ltd.qubit.survey.model.Question">
<id property="id" column="id"/>
<result property="questionNumber" column="question_number"/>
<result property="number" column="number"/>
<result property="content" column="content"/>
<result property="questionType" column="question_type"/>
<result property="workArea" column="work_area"/>
<result property="type" column="type"/>
<result property="isRequired" column="is_required"/>
<result property="nextQuestionLogic" column="next_question_logic"/>
<result property="next" column="next" typeHandler="ltd.qubit.survey.common.mybatis.JsonTypeHandler"/>
<result property="isLast" column="is_last"/>
<result property="createdAt" column="created_at"/>
</resultMap>
<!-- 基础列 -->
<sql id="baseColumns">
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`
</sql>
<!-- 插入 -->
<insert id="insert" parameterType="ltd.qubit.survey.model.Question" useGeneratedKeys="true" keyProperty="id">
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})
</insert>
<!-- 更新 -->
<update id="update" parameterType="ltd.qubit.survey.model.Question">
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}
</update>
<!-- 删除 -->
<delete id="deleteById" parameterType="long">
DELETE FROM questions WHERE id = #{id}
DELETE FROM `question` WHERE `id` = #{id}
</delete>
<!-- 根据ID查询 -->
<select id="findById" parameterType="long" resultMap="questionMap">
SELECT <include refid="baseColumns"/>
FROM questions
WHERE id = #{id}
FROM `question`
WHERE `id` = #{id}
</select>
<!-- 查询所有 -->
<select id="findAll" resultMap="questionMap">
SELECT <include refid="baseColumns"/>
FROM questions
ORDER BY question_number
FROM `question`
ORDER BY `number`
</select>
<!-- 根据问题序号查询 -->
<select id="findByQuestionNumber" parameterType="int" resultMap="questionMap">
SELECT <include refid="baseColumns"/>
FROM questions
WHERE question_number = #{questionNumber}
</select>
<!-- 根据工作领域查询 -->
<select id="findByWorkArea" parameterType="string" resultMap="questionMap">
SELECT <include refid="baseColumns"/>
FROM questions
WHERE work_area = #{workArea}
ORDER BY question_number
FROM `question`
WHERE `number` = #{number}
</select>
<!-- 查询通用问题 -->
<select id="findCommonQuestions" resultMap="questionMap">
SELECT <include refid="baseColumns"/>
FROM questions
WHERE work_area IS NULL
ORDER BY question_number
FROM `question`
ORDER BY `number`
</select>
<!-- 获取下一个问题序号 -->
<select id="getNextQuestionNumber" resultType="int">
SELECT COALESCE(MAX(question_number) + 1, 1)
FROM questions
SELECT COALESCE(MAX(`number`) + 1, 1)
FROM `question`
</select>
</mapper>

View File

@ -13,18 +13,18 @@
<!-- 基础列 -->
<sql id="baseColumns">
id, user_id, question_id, selected_options, text_answer, created_at
`id`, `user_id`, `question_id`, `selected_options`, `text_answer`, `created_at`
</sql>
<!-- 插入 -->
<insert id="insert" parameterType="ltd.qubit.survey.model.SurveyResponse" useGeneratedKeys="true" keyProperty="id">
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>
<!-- 批量插入 -->
<insert id="batchInsert" parameterType="java.util.List">
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
<foreach collection="list" item="item" separator=",">
(#{item.userId}, #{item.questionId},
@ -35,59 +35,59 @@
<!-- 更新 -->
<update id="update" parameterType="ltd.qubit.survey.model.SurveyResponse">
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}
</update>
<!-- 删除 -->
<delete id="deleteById" parameterType="long">
DELETE FROM survey_responses WHERE id = #{id}
DELETE FROM `survey_response` WHERE `id` = #{id}
</delete>
<!-- 根据用户ID删除 -->
<delete id="deleteByUserId" parameterType="long">
DELETE FROM survey_responses WHERE user_id = #{userId}
DELETE FROM `survey_response` WHERE `user_id` = #{userId}
</delete>
<!-- 根据ID查询 -->
<select id="findById" parameterType="long" resultMap="responseMap">
SELECT <include refid="baseColumns"/>
FROM survey_responses
WHERE id = #{id}
FROM `survey_response`
WHERE `id` = #{id}
</select>
<!-- 查询所有 -->
<select id="findAll" resultMap="responseMap">
SELECT <include refid="baseColumns"/>
FROM survey_responses
ORDER BY user_id, question_id
FROM `survey_response`
ORDER BY `user_id`, `question_id`
</select>
<!-- 根据用户ID查询 -->
<select id="findByUserId" parameterType="long" resultMap="responseMap">
SELECT <include refid="baseColumns"/>
FROM survey_responses
WHERE user_id = #{userId}
ORDER BY question_id
FROM `survey_response`
WHERE `user_id` = #{userId}
ORDER BY `question_id`
</select>
<!-- 根据问题ID查询 -->
<select id="findByQuestionId" parameterType="long" resultMap="responseMap">
SELECT <include refid="baseColumns"/>
FROM survey_responses
WHERE question_id = #{questionId}
ORDER BY user_id
FROM `survey_response`
WHERE `question_id` = #{questionId}
ORDER BY `user_id`
</select>
<!-- 根据用户ID和问题ID查询 -->
<select id="findByUserIdAndQuestionId" resultMap="responseMap">
SELECT <include refid="baseColumns"/>
FROM survey_responses
WHERE user_id = #{userId}
AND question_id = #{questionId}
FROM `survey_response`
WHERE `user_id` = #{userId}
AND `question_id` = #{questionId}
</select>
</mapper>

View File

@ -6,63 +6,53 @@
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="phone" column="phone"/>
<result property="workArea" column="work_area"/>
<result property="positionType" column="position_type"/>
<result property="createdAt" column="created_at"/>
</resultMap>
<!-- 基础列 -->
<sql id="baseColumns">
id, name, phone, work_area, position_type, created_at
`id`, `name`, `phone`, `position_type`, `created_at`
</sql>
<!-- 插入 -->
<insert id="insert" parameterType="ltd.qubit.survey.model.User" useGeneratedKeys="true" keyProperty="id">
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})
</insert>
<!-- 更新 -->
<update id="update" parameterType="ltd.qubit.survey.model.User">
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}
</update>
<!-- 删除 -->
<delete id="deleteById" parameterType="long">
DELETE FROM users WHERE id = #{id}
DELETE FROM `user` WHERE `id` = #{id}
</delete>
<!-- 根据ID查询 -->
<select id="findById" parameterType="long" resultMap="userMap">
SELECT <include refid="baseColumns"/>
FROM users
WHERE id = #{id}
FROM `user`
WHERE `id` = #{id}
</select>
<!-- 查询所有 -->
<select id="findAll" resultMap="userMap">
SELECT <include refid="baseColumns"/>
FROM users
ORDER BY id
FROM `user`
ORDER BY `id`
</select>
<!-- 根据手机号查询 -->
<select id="findByPhone" parameterType="string" resultMap="userMap">
SELECT <include refid="baseColumns"/>
FROM users
WHERE phone = #{phone}
</select>
<!-- 根据工作领域查询 -->
<select id="findByWorkArea" parameterType="string" resultMap="userMap">
SELECT <include refid="baseColumns"/>
FROM users
WHERE work_area = #{workArea}
ORDER BY id
FROM `user`
WHERE `phone` = #{phone}
</select>
</mapper>

View File

@ -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

View File

@ -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`
@ -364,3 +371,6 @@ UPDATE `question` SET `next` = JSON_OBJECT('*', 25) WHERE `number` = 24;
-- 第一个开放性问题跳转到第二个
UPDATE `question` SET `next` = JSON_OBJECT('*', 26) WHERE `number` = 25;
-- 设置最后一题标记
UPDATE `question` SET `is_last` = TRUE WHERE `number` = 26;

View File

@ -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
});
}

View File

@ -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,

View File

@ -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 {

View File

@ -8,41 +8,66 @@
/>
<div v-if="!surveyStore.isCompleted" class="survey-content">
<div v-if="surveyStore.currentQuestion" class="question-card">
<van-cell-group inset>
<van-cell>
<template #title>
<div class="question-title">
{{ surveyStore.currentQuestionNumber }}. {{ surveyStore.currentQuestion.content }}
</div>
</template>
</van-cell>
<van-radio-group v-model="selectedOption">
<van-cell-group>
<van-cell
v-for="option in surveyStore.questionOptions"
:key="option.id"
clickable
@click="selectedOption = option.id"
>
<template #title>
<van-radio :name="option.id">{{ option.content }}</van-radio>
</template>
</van-cell>
</van-cell-group>
</van-radio-group>
</van-cell-group>
<div class="action-buttons">
<div v-if="surveyStore.currentQuestion" class="question-container">
<h2 class="question-title">
{{ surveyStore.currentQuestionNumber }}. {{ surveyStore.currentQuestion.content }}
<span v-if="surveyStore.currentQuestion.type === 'MULTIPLE_CHOICE'" class="question-type">(多选)</span>
</h2>
<van-checkbox-group v-if="surveyStore.currentQuestion.type === 'MULTIPLE_CHOICE'" v-model="selectedOptions" class="options-container">
<van-cell-group inset>
<van-cell
v-for="option in surveyStore.currentOptions"
:key="option.optionCode"
clickable
@click="toggleOption(option.optionCode)"
>
<template #title>
<span>{{ option.optionCode }}. {{ option.content }}</span>
</template>
<template #right-icon>
<van-checkbox
:name="option.optionCode"
@click.stop
/>
</template>
</van-cell>
</van-cell-group>
</van-checkbox-group>
<van-radio-group v-else-if="surveyStore.currentQuestion.type === 'SINGLE_CHOICE'" v-model="selectedOption" class="options-container">
<van-cell-group inset>
<van-cell
v-for="option in surveyStore.currentOptions"
:key="option.optionCode"
clickable
@click="selectedOption = option.optionCode"
>
<template #title>
<span>{{ option.optionCode }}. {{ option.content }}</span>
</template>
<template #right-icon>
<van-radio :name="option.optionCode" />
</template>
</van-cell>
</van-cell-group>
</van-radio-group>
<div v-else-if="surveyStore.currentQuestion.type === 'TEXT'" class="text-input-container">
<van-field
v-model="textAnswer"
type="textarea"
rows="4"
autosize
placeholder="请输入您的答案"
:rules="[{ required: surveyStore.currentQuestion.isRequired, message: '请输入答案' }]"
/>
</div>
<div class="button-container">
<van-button
round
block
type="primary"
:disabled="!selectedOption"
block
:disabled="!isValidSelection"
@click="onNextQuestion"
>
下一题
{{ surveyStore.currentQuestion?.isLast ? '完成' : '下一题' }}
</van-button>
</div>
</div>
@ -51,25 +76,29 @@
</div>
<div v-else class="survey-completed">
<van-empty description="问卷已完成">
<van-empty description="感谢您完成问卷调查!">
<template #image>
<van-icon name="success" size="64" color="#07c160" />
</template>
<div class="completion-message">
<p>您的反馈对我们非常重要</p>
<p>我们将根据调查结果持续改进和优化</p>
</div>
</van-empty>
<van-button
round
type="primary"
class="restart-button"
@click="onRestartSurvey"
class="home-button"
@click="router.replace('/')"
>
重新开始
返回首页
</van-button>
</div>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import { ref, onMounted, computed } from 'vue';
import { useRouter } from 'vue-router';
import { useUserStore } from '@/stores/user';
import { useSurveyStore } from '@/stores/survey';
@ -80,8 +109,33 @@ const userStore = useUserStore();
const surveyStore = useSurveyStore();
const selectedOption = ref('');
const selectedOptions = ref([]);
const textAnswer = ref('');
const responses = ref([]);
//
const isValidSelection = computed(() => {
const questionType = surveyStore.currentQuestion?.type;
if (questionType === 'MULTIPLE_CHOICE') {
return selectedOptions.value.length > 0;
} else if (questionType === 'SINGLE_CHOICE') {
return selectedOption.value !== '';
} else if (questionType === 'TEXT') {
return textAnswer.value.trim() !== '';
}
return false;
});
//
function toggleOption(optionCode) {
const index = selectedOptions.value.indexOf(optionCode);
if (index === -1) {
selectedOptions.value.push(optionCode);
} else {
selectedOptions.value.splice(index, 1);
}
}
//
function onBack() {
router.back();
@ -89,47 +143,71 @@ function onBack() {
//
async function onNextQuestion() {
if (!selectedOption.value) {
const questionType = surveyStore.currentQuestion.type;
if (questionType === 'MULTIPLE_CHOICE' && selectedOptions.value.length === 0) {
showToast('请至少选择一个选项');
return;
} else if (questionType === 'SINGLE_CHOICE' && !selectedOption.value) {
showToast('请选择一个选项');
return;
} else if (questionType === 'TEXT' && !textAnswer.value.trim()) {
showToast('请输入答案');
return;
}
try {
let currentSelection = [];
if (questionType === 'MULTIPLE_CHOICE') {
currentSelection = selectedOptions.value;
} else if (questionType === 'SINGLE_CHOICE') {
currentSelection = [selectedOption.value];
}
//
responses.value.push({
questionId: surveyStore.currentQuestion.id,
optionId: selectedOption.value,
selectedOptions: currentSelection,
textAnswer: questionType === 'TEXT' ? textAnswer.value.trim() : null
});
//
const nextQuestion = await surveyStore.fetchNextQuestion(
userStore.userId,
selectedOption.value
);
//
if (!nextQuestion) {
await surveyStore.submitSurveyResponses(userStore.userId, responses.value);
showToast('问卷提交成功');
//
if (surveyStore.currentQuestion.isLast) {
try {
await surveyStore.submitSurveyResponses(userStore.userId, responses.value);
showToast('问卷提交成功');
surveyStore.isCompleted.value = true;
return;
} catch (error) {
console.error('提交问卷失败:', error);
showToast(error.response?.data?.message || '提交失败,请重试');
return;
}
}
//
selectedOption.value = '';
//
try {
await surveyStore.fetchNextQuestion(userStore.userId, currentSelection);
//
selectedOption.value = '';
selectedOptions.value = [];
textAnswer.value = '';
} catch (error) {
console.error('获取下一题失败:', error);
showToast(error.response?.data?.message || '获取下一题失败,请重试');
}
} catch (error) {
console.error('获取下一个问题失败:', error);
console.error('问卷处理失败:', error);
showToast(error.response?.data?.message || '操作失败,请重试');
}
}
//
function onRestartSurvey() {
surveyStore.resetSurvey();
responses.value = [];
initSurvey();
}
//
async function initSurvey() {
try {
surveyStore.resetSurvey(); //
responses.value = [];
//
await surveyStore.fetchNextQuestion(userStore.userId);
} catch (error) {
console.error('初始化问卷失败:', error);
@ -157,20 +235,27 @@ onMounted(() => {
padding: 20px;
}
.question-card {
.question-container {
margin-bottom: 20px;
}
.question-title {
font-size: 16px;
font-size: 18px;
font-weight: bold;
line-height: 1.5;
margin-bottom: 16px;
padding: 0 16px;
}
.action-buttons {
.options-container {
margin-top: 20px;
}
.button-container {
margin-top: 24px;
padding: 0 16px;
}
.survey-completed {
padding: 40px 20px;
text-align: center;
@ -180,4 +265,28 @@ onMounted(() => {
margin-top: 20px;
width: 80%;
}
.question-type {
font-size: 14px;
color: #666;
margin-left: 8px;
}
.text-input-container {
padding: 16px;
background-color: #fff;
border-radius: 8px;
margin: 0 16px;
}
.completion-message {
margin: 16px 0;
color: #666;
line-height: 1.6;
}
.home-button {
margin-top: 24px;
width: 80%;
}
</style>