龚焕茏
2024-06-04 db7ff10c4090564126bf78447fb038406812f321
feat:题目查询、新增,内容直接存题目表
11个文件已修改
109 ■■■■ 已修改文件
src/main/java/com/ycl/jxkg/controller/admin/QuestionController.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ycl/jxkg/controller/student/QuestionAnswerController.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ycl/jxkg/domain/base/AbsEntity.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ycl/jxkg/domain/entity/ExamPaperQuestionCustomerAnswer.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ycl/jxkg/domain/entity/Question.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ycl/jxkg/domain/vo/admin/question/QuestionResponseVO.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ycl/jxkg/service/QuestionService.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ycl/jxkg/service/impl/ExamPaperAnswerServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ycl/jxkg/service/impl/QuestionServiceImpl.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/ExamPaperQuestionCustomerAnswerMapper.xml 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/QuestionMapper.xml 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ycl/jxkg/controller/admin/QuestionController.java
@@ -1,19 +1,18 @@
package com.ycl.jxkg.controller.admin;
import com.github.pagehelper.PageInfo;
import com.ycl.jxkg.base.BaseApiController;
import com.ycl.jxkg.base.Result;
import com.ycl.jxkg.base.SystemCode;
import com.ycl.jxkg.domain.entity.Question;
import com.ycl.jxkg.domain.entity.TextContent;
import com.ycl.jxkg.domain.enums.QuestionTypeEnum;
import com.ycl.jxkg.domain.question.QuestionObject;
import com.ycl.jxkg.service.QuestionService;
import com.ycl.jxkg.service.TextContentService;
import com.ycl.jxkg.utils.*;
import com.ycl.jxkg.domain.vo.admin.question.QuestionEditRequestVO;
import com.ycl.jxkg.domain.vo.admin.question.QuestionPageRequestVO;
import com.ycl.jxkg.domain.vo.admin.question.QuestionResponseVO;
import com.github.pagehelper.PageInfo;
import com.ycl.jxkg.service.QuestionService;
import com.ycl.jxkg.service.TextContentService;
import com.ycl.jxkg.utils.*;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
@@ -31,14 +30,12 @@
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public Result<PageInfo<QuestionResponseVO>> pageList(@RequestBody QuestionPageRequestVO model) {
        PageInfo<Question> pageInfo = questionService.page(model);
        PageInfo<QuestionResponseVO> pageInfo = questionService.page(model);
        PageInfo<QuestionResponseVO> page = PageInfoHelper.copyMap(pageInfo, q -> {
            QuestionResponseVO vo = new QuestionResponseVO();
            BeanUtils.copyProperties(q, vo);
            vo.setCreateTime(DateTimeUtil.dateFormat(q.getCreateTime()));
            vo.setScore(ExamUtil.scoreToVM(q.getScore()));
            TextContent textContent = textContentService.getById(q.getInfoTextContentId());
            QuestionObject questionObject = JsonUtil.toJsonObject(textContent.getContent(), QuestionObject.class);
            vo.setScore(ExamUtil.scoreToVM(Integer.valueOf(q.getScore())));
            QuestionObject questionObject = JsonUtil.toJsonObject(q.getContent(), QuestionObject.class);
            String clearHtml = HtmlUtil.clear(questionObject.getTitleContent());
            vo.setShortTitle(clearHtml);
            return vo;
src/main/java/com/ycl/jxkg/controller/student/QuestionAnswerController.java
@@ -43,8 +43,7 @@
            QuestionPageStudentResponseVO vo = new QuestionPageStudentResponseVO();
            BeanUtils.copyProperties(q, vo);
            vo.setCreateTime(DateTimeUtil.dateFormat(q.getCreateTime()));
            TextContent textContent = textContentService.getById(q.getQuestionTextContentId());
            QuestionObject questionObject = JsonUtil.toJsonObject(textContent.getContent(), QuestionObject.class);
            QuestionObject questionObject = JsonUtil.toJsonObject(q.getQuestionContent(), QuestionObject.class);
            String clearHtml = HtmlUtil.clear(questionObject.getTitleContent());
            vo.setShortTitle(clearHtml);
            vo.setSubjectName(subject.getName());
src/main/java/com/ycl/jxkg/domain/base/AbsEntity.java
@@ -1,9 +1,6 @@
package com.ycl.jxkg.domain.base;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.util.Date;
@@ -28,7 +25,8 @@
//    @TableField(value = "gmt_update", fill = FieldFill.INSERT_UPDATE)
//    private Date gmtUpdate;
    @TableField(value = "deleted", fill = FieldFill.INSERT)
    @TableField(value = "deleted", fill = FieldFill.INSERT, select = false)
    @TableLogic
    private Integer deleted;
}
src/main/java/com/ycl/jxkg/domain/entity/ExamPaperQuestionCustomerAnswer.java
@@ -58,8 +58,8 @@
    /**
     * 问题内容
     */
    @TableField("question_text_content_id")
    private Integer questionTextContentId;
    @TableField("questionContent")
    private String questionContent;
    /**
     * 做题答案
src/main/java/com/ycl/jxkg/domain/entity/Question.java
@@ -56,8 +56,8 @@
    /**
     * 题目 填空、 题干、解析、答案等信息
     */
    @TableField("info_text_content_id")
    private Integer infoTextContentId;
    @TableField("content")
    private String content;
    /**
     * 创建人
src/main/java/com/ycl/jxkg/domain/vo/admin/question/QuestionResponseVO.java
@@ -10,14 +10,20 @@
    private Integer questionType;
    private Integer textContentId;
    private String questionTypeName;
    private String content;
    private String createTime;
    private Integer subjectId;
    private String subjectName;
    private Integer createUser;
    private String createUserName;
    private String score;
    private Integer status;
src/main/java/com/ycl/jxkg/service/QuestionService.java
@@ -5,12 +5,13 @@
import com.ycl.jxkg.domain.vo.admin.question.QuestionEditRequestVO;
import com.ycl.jxkg.domain.vo.admin.question.QuestionPageRequestVO;
import com.github.pagehelper.PageInfo;
import com.ycl.jxkg.domain.vo.admin.question.QuestionResponseVO;
import java.util.List;
public interface QuestionService extends IService<Question> {
    PageInfo<Question> page(QuestionPageRequestVO requestVM);
    PageInfo<QuestionResponseVO> page(QuestionPageRequestVO requestVM);
    Question insertFullQuestion(QuestionEditRequestVO model, Integer userId);
src/main/java/com/ycl/jxkg/service/impl/ExamPaperAnswerServiceImpl.java
@@ -192,7 +192,7 @@
        examPaperQuestionCustomerAnswer.setCreateTime(now);
        examPaperQuestionCustomerAnswer.setCreateUser(user.getId());
        examPaperQuestionCustomerAnswer.setQuestionType(question.getQuestionType());
        examPaperQuestionCustomerAnswer.setQuestionTextContentId(question.getInfoTextContentId());
        examPaperQuestionCustomerAnswer.setQuestionContent(question.getContent());
        if (null == customerQuestionAnswer) {
            examPaperQuestionCustomerAnswer.setCustomerScore(0);
        } else {
src/main/java/com/ycl/jxkg/service/impl/QuestionServiceImpl.java
@@ -8,6 +8,7 @@
import com.ycl.jxkg.domain.enums.QuestionTypeEnum;
import com.ycl.jxkg.domain.question.QuestionItemObject;
import com.ycl.jxkg.domain.question.QuestionObject;
import com.ycl.jxkg.domain.vo.admin.question.QuestionResponseVO;
import com.ycl.jxkg.mapper.QuestionMapper;
import com.ycl.jxkg.service.QuestionService;
import com.ycl.jxkg.service.SubjectService;
@@ -39,7 +40,7 @@
    @Override
    public PageInfo<Question> page(QuestionPageRequestVO requestVM) {
    public PageInfo<QuestionResponseVO> page(QuestionPageRequestVO requestVM) {
        return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() ->
                questionMapper.page(requestVM)
        );
@@ -53,10 +54,7 @@
        Integer gradeLevel = subjectService.levelBySubjectId(model.getSubjectId());
        //题干、解析、选项等 插入
        TextContent infoTextContent = new TextContent();
        infoTextContent.setCreateTime(now);
        setQuestionInfoFromVM(infoTextContent, model);
        textContentService.save(infoTextContent);
        String questionObject = setQuestionInfoFromVM(model);
        Question question = new Question();
        question.setSubjectId(model.getSubjectId());
@@ -67,7 +65,7 @@
        question.setCorrectFromVM(model.getCorrect(), model.getCorrectArray());
        question.setScore(ExamUtil.scoreFromVM(model.getScore()));
        question.setDifficult(model.getDifficult());
        question.setInfoTextContentId(infoTextContent.getId());
        question.setContent(questionObject);
        question.setCreateUser(userId);
        questionMapper.insert(question);
        return question;
@@ -83,13 +81,10 @@
        question.setScore(ExamUtil.scoreFromVM(model.getScore()));
        question.setDifficult(model.getDifficult());
        question.setCorrectFromVM(model.getCorrect(), model.getCorrectArray());
        questionMapper.updateById(question);
        //题干、解析、选项等 更新
        TextContent infoTextContent = textContentService.getById(question.getInfoTextContentId());
        setQuestionInfoFromVM(infoTextContent, model);
        textContentService.updateById(infoTextContent);
        String questionObject = setQuestionInfoFromVM(model);
        question.setContent(questionObject);
        questionMapper.updateById(question);
        return question;
    }
@@ -103,8 +98,7 @@
    @Override
    public QuestionEditRequestVO getQuestionEditRequestVM(Question question) {
        //题目映射
        TextContent questionInfoTextContent = textContentService.getById(question.getInfoTextContentId());
        QuestionObject questionObject = JsonUtil.toJsonObject(questionInfoTextContent.getContent(), QuestionObject.class);
        QuestionObject questionObject = JsonUtil.toJsonObject(question.getContent(), QuestionObject.class);
        QuestionEditRequestVO questionEditRequestVO = new QuestionEditRequestVO();
        BeanUtils.copyProperties(question, questionEditRequestVO);
        questionEditRequestVO.setTitle(questionObject.getTitleContent());
@@ -146,7 +140,7 @@
        return questionEditRequestVO;
    }
    public void setQuestionInfoFromVM(TextContent infoTextContent, QuestionEditRequestVO model) {
    public String setQuestionInfoFromVM(QuestionEditRequestVO model) {
        List<QuestionItemObject> itemObjects = model.getItems().stream().map(i ->
                {
                    QuestionItemObject item = new QuestionItemObject();
@@ -162,7 +156,7 @@
        questionObject.setAnalyze(model.getAnalyze());
        questionObject.setTitleContent(model.getTitle());
        questionObject.setCorrect(model.getCorrect());
        infoTextContent.setContent(JsonUtil.toJsonStr(questionObject));
        return JsonUtil.toJsonStr(questionObject);
    }
    @Override
src/main/resources/mapper/ExamPaperQuestionCustomerAnswerMapper.xml
@@ -10,7 +10,7 @@
        <result column="subject_id" jdbcType="INTEGER" property="subjectId"/>
        <result column="customer_score" jdbcType="INTEGER" property="customerScore"/>
        <result column="question_score" jdbcType="INTEGER" property="questionScore"/>
        <result column="question_text_content_id" jdbcType="INTEGER" property="questionTextContentId"/>
        <result column="question_content" jdbcType="VARCHAR" property="questionContent"/>
        <result column="answer" jdbcType="VARCHAR" property="answer"/>
        <result column="text_content_id" jdbcType="INTEGER" property="textContentId"/>
        <result column="do_right" jdbcType="BIT" property="doRight"/>
@@ -21,7 +21,7 @@
    <sql id="Base_Column_List">
        id
        , question_id, exam_paper_id, exam_paper_answer_id, question_type, subject_id,
    customer_score, question_score, question_text_content_id, answer, text_content_id,
    customer_score, question_score, question_content, answer, text_content_id,
    do_right, create_user, create_time, item_order
    </sql>
@@ -51,7 +51,7 @@
        subject_id, create_time, create_user,
        text_content_id, exam_paper_id, question_type,
        answer, customer_score, exam_paper_answer_id ,
        do_right,question_text_content_id,item_order)
        do_right,question_content,item_order)
        values
        <foreach collection="list" item="item" index="index"
                 separator=",">
src/main/resources/mapper/QuestionMapper.xml
@@ -9,7 +9,7 @@
        <result column="grade_level" jdbcType="INTEGER" property="gradeLevel"/>
        <result column="difficult" jdbcType="INTEGER" property="difficult"/>
        <result column="correct" jdbcType="VARCHAR" property="correct"/>
        <result column="info_text_content_id" jdbcType="INTEGER" property="infoTextContentId"/>
        <result column="content" jdbcType="VARCHAR" property="content"/>
        <result column="create_user" jdbcType="INTEGER" property="createUser"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
@@ -17,32 +17,36 @@
    </resultMap>
    <sql id="Base_Column_List">
        id
        , question_type, subject_id, score, grade_level, difficult, correct, info_text_content_id,
        , question_type, subject_id, score, grade_level, difficult, correct, content,
    create_user, status, create_time, deleted
    </sql>
    <select id="page" resultMap="BaseResultMap" parameterType="com.ycl.jxkg.domain.vo.admin.question.QuestionPageRequestVO">
    <select id="page" resultType="com.ycl.jxkg.domain.vo.admin.question.QuestionResponseVO" parameterType="com.ycl.jxkg.domain.vo.admin.question.QuestionPageRequestVO">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_question
        tq.*,
        CASE WHEN tq.question_type = 1 THEN '单选题' WHEN tq.question_type = 2 THEN '多选题' WHEN tq.question_type = 3 THEN '判断题' WHEN tq.question_type = 4 THEN '填空题' WHEN tq.question_type = 5 THEN '简答题' END AS questionTypeName,
        ts.name AS subjectName,
        tu.real_name AS createUserName
        FROM t_question tq
        LEFT JOIN t_subject ts ON tq.subject_id = ts.id
        LEFT JOIN t_user tu ON tq.create_user = tu.id
        <where>
            and deleted=0
            and tq.deleted=0
            <if test="id != null ">
                and id= #{id}
                and tq.id= #{id}
            </if>
            <if test="level != null ">
                and grade_level= #{level}
                and tq.grade_level= #{level}
            </if>
            <if test="subjectId != null ">
                and subject_id= #{subjectId}
                and tq.subject_id= #{subjectId}
            </if>
            <if test="questionType != null ">
                and question_type= #{questionType}
                and tq.question_type= #{questionType}
            </if>
            <if test="content != null">
                and info_text_content_id in (SELECT id FROM t_text_content WHERE content like concat('%',#{content},'%')
                )
                and instr(tq.content, #{content})
            </if>
        </where>
    </select>