123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.qxgmat.data.relation.UserQuestionRelationMapper">
- <resultMap id="IdMap" type="com.qxgmat.data.dao.entity.UserQuestion">
- <!--
- WARNING - @mbg.generated
- -->
- <id column="id" jdbcType="INTEGER" property="id" />
- </resultMap>
- <resultMap id="studyMap" type="com.qxgmat.data.relation.entity.UserRecordStatRelation">
- <!--
- WARNING - @mbg.generated
- -->
- <id column="user_time" jdbcType="INTEGER" property="userTime" />
- </resultMap>
- <resultMap id="limitMap" type="com.qxgmat.data.relation.entity.UserReportLimitRelation">
- <!--
- WARNING - @mbg.generated
- -->
- <id column="user_number" jdbcType="INTEGER" property="userNumber" />
- <id column="user_correct" jdbcType="INTEGER" property="userCorrect" />
- </resultMap>
- <sql id="Id_Column_List">
- <!--
- WARNING - @mbg.generated
- -->
- uq.`id`
- </sql>
- <select id="listExerciseError" resultMap="IdMap">
- <if test="keyword != null">
- <bind name="keywordLike" value="'%' + keyword + '%'" />
- </if>
- select max(uq.`id`) as `id`,
- max(uq.`create_time`) as `latest_time`,
- sum(uq.`is_correct`) / count(uq.id) as `correct`,
- sum(uq.`user_time`) / count(uq.id) as `time`,
- if(q.`question_type`='sc', 1, if(q.`question_type`='rc', 2, if(q.`question_type`='cr', 3,if(q.`question_type`='ds', 4, if(q.`question_type`='ps', 5,if(q.`question_type`='ir', 6, 7)))))) as `question_type`,
- max(uq.`no`) as `no`,
- max(ur.`origin_id`) as `pid`
- from `user_question` uq
- left join `user_report` ur on ur.`id`=uq.`report_id`
- left join `question` q on q.`id` = uq.`question_id`
- and (q.`question_module` = 'base' or q.`question_module` = 'sentence')
- <if test="questionTypes != null">
- and
- <foreach collection="questionTypes" item="item" index="index" open="(" close=")" separator=" or ">
- q.`question_type` = #{item}
- </foreach>
- </if>
- left join `question_no` qn on qn.`id` = uq.`question_no_id` and qn.`module` = 'exercise'
- and (q.`question_module` = 'base')
- <if test="structIds != null">
- and
- <foreach collection="structIds" item="item" index="index" open="(" close=")" separator=" or ">
- find_in_set(#{item}, qn.`module_struct`)
- </foreach>
- </if>
- left join `sentence_question` sq on sq.`question_id` = q.`id`
- and (q.`question_module` = 'sentence')
- left join `user_paper_question` upq on upq.`user_id` = #{userId,jdbcType=VARCHAR}
- and upq.`question_no_id` = qn.`id`
- and upq.`question_module` = uq.`question_module`
- and upq.`question_origin` = 'remove_error'
- left join `user_paper` up on up.`id` = uq.`paper_id`
- left join `preview_assign` pa on up.`paper_origin` = 'preview' and pa.`id` = up.`origin_id`
- <if test="courseModules != null">
- and pa.`course_module` in
- <foreach collection="courseModules" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- left join `preview_paper` pp on pa.`paper_id` = pp.`id`
- <if test="questionTypes != null">
- and
- <foreach collection="questionTypes" item="item" index="index" open="(" close=")" separator=" or ">
- pp.`question_type` = #{item}
- </foreach>
- </if>
- where
- q.`id` > 0 and qn.`id` > 0 and upq.`id` is null and uq.`user_id` = #{userId,jdbcType=VARCHAR}
- <if test="keyword != null">
- and (q.`stem` like #{keywordLike,jdbcType=VARCHAR}
- or qn.`title` like #{keywordLike,jdbcType=VARCHAR}
- or sq.`title` like #{keywordLike,jdbcType=VARCHAR})
- </if>
- <if test="structIds != null">
- and qn.`id` > 0
- </if>
- <if test="structIds == null">
- and (qn.`id` > 0 or sq.`id` > 0)
- </if>
- <if test="courseModules != null">
- and (pa.`id` > 0)
- </if>
- <if test="startTime != null">
- and uq.`create_time` > #{startTime,jdbcType=TIMESTAMP}
- </if>
- <if test="endTime != null">
- and uq.`create_time` < #{endTime,jdbcType=TIMESTAMP}
- </if>
- group by uq.`question_module`, uq.`question_no_id`, q.`question_type`
- <if test="order != null">
- order by ${order}
- </if>
- </select>
- <select id="listExaminationError" resultMap="IdMap">
- <if test="keyword != null">
- <bind name="keywordLike" value="'%' + keyword + '%'" />
- </if>
- select max(uq.`id`) as `id`,
- max(uq.`create_time`) as `latest_time`,
- sum(uq.`is_correct`) / count(uq.id) as `correct`,
- sum(uq.`user_time`) / count(uq.id) as `time`,
- if(q.`question_type`='sc', 1, if(q.`question_type`='rc', 2, if(q.`question_type`='cr', 3,if(q.`question_type`='ds', 4, if(q.`question_type`='ps', 5,if(q.`question_type`='ir', 6, 7)))))) as `question_type`,
- max(uq.`no`) as `no`,
- max(ur.`origin_id`) as `pid`
- from `user_question` uq
- left join `user_report` ur on ur.`id`=uq.`report_id`
- left join `question` q on q.`id` = uq.`question_id`
- and (q.`question_module` = 'base' or q.`question_module` = 'textbook')
- <if test="questionTypes != null">
- and
- <foreach collection="questionTypes" item="item" index="index" open="(" close=")" separator=" or ">
- q.`question_type` = #{item}
- </foreach>
- </if>
- left join `question_no` qn on qn.`id` = uq.`question_no_id` and qn.`module` = 'examination'
- and (q.`question_module` = 'base')
- <if test="structIds != null">
- and
- <foreach collection="structIds" item="item" index="index" open="(" close=")" separator=" or ">
- find_in_set(#{item}, qn.`module_struct`)
- </foreach>
- </if>
- left join `textbook_question` tq on tq.`question_id` = q.`id`
- and (q.`question_module` = 'textbook')
- <if test="libraryId != null and libraryId > 0">
- and tq.`library_id` = #{libraryId,jdbcType=VARCHAR}
- </if>
- <if test="year != null">
- and tq.`year` = #{year,jdbcType=VARCHAR}
- </if>
- left join `user_paper_question` upq on upq.`user_id` = #{userId,jdbcType=VARCHAR}
- and upq.`question_no_id` = qn.`id`
- and upq.`question_module` = uq.`question_module`
- and upq.`question_origin` = 'remove_error'
- where
- q.`id` > 0 and qn.`id` > 0 and upq.`id` = null and uq.`user_id` = #{userId,jdbcType=VARCHAR}
- <if test="keyword != null">
- and (q.`stem` like #{keywordLike,jdbcType=VARCHAR}
- or qn.`title` like #{keywordLike,jdbcType=VARCHAR}
- or tq.`title` like #{keywordLike,jdbcType=VARCHAR})
- </if>
- <if test="structIds != null">
- and qn.`id` > 0
- </if>
- <if test="structIds == null">
- and (qn.`id` > 0 or tq.`id` > 0)
- </if>
- <if test="libraryId != null">
- and (tq.`id` > 0)
- </if>
- <if test="year != null">
- and (tq.`id` > 0)
- </if>
- <if test="startTime != null">
- and uq.`create_time` > #{startTime,jdbcType=TIMESTAMP}
- </if>
- <if test="endTime != null">
- and uq.`create_time` < #{endTime,jdbcType=TIMESTAMP}
- </if>
- group by uq.`question_module`, uq.`question_no_id`, q.`question_type`
- <if test="order != null">
- order by ${order}
- </if>
- </select>
- <!--
- 用户最后一次
- https://blog.csdn.net/t_1007/article/details/52369261
- -->
- <select id="listLast" resultMap="IdMap">
- select
- <!--SUBSTRING_INDEX(GROUP_CONCAT(ur.`id` ORDER BY ur.`create_time` desc),',',1) as `id`-->
- max(uq.`id`) as `id`
- from `user_question` uq
- where uq.`user_id` = #{userId,jdbcType=VARCHAR} and uq.`question_id` IN
- <foreach collection="questionIds" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- group by uq.`question_id`
- </select>
- <!--
- 用户做题记录统计
- -->
- <select id="stat" resultMap="studyMap">
- select
- sum(uq.`user_time`) as `user_time`
- from `user_question` uq
- where
- uq.`user_id` = #{userId,jdbcType=VARCHAR}
- <if test="startTime != null">
- and uq.`create_time` > #{startTime,jdbcType=TIMESTAMP}
- </if>
- <if test="endTime != null">
- and uq.`create_time` < #{endTime,jdbcType=TIMESTAMP}
- </if>
- </select>
- <!--
- 全站做题记录统计
- -->
- <select id="statAvg" resultMap="studyMap">
- select
- sum(uq.`user_time`) /count(distinct(uq.`user_id`)) as `user_time`
- from `user_question` uq
- where
- 1
- <if test="startTime != null">
- and uq.`create_time` > #{startTime,jdbcType=TIMESTAMP}
- </if>
- <if test="endTime != null">
- and uq.`create_time` < #{endTime,jdbcType=TIMESTAMP}
- </if>
- </select>
- <!--
- 用户限时完成的统计记录
- -->
- <select id="statLimit" resultMap="limitMap">
- select
- sum(`id`) as `user_number`, sum(`is_correct`) as `user_correct`
- from `user_question`
- where
- `user_time` < `time`
- and `report_id` = #{reportId,jdbcType=INTEGER}
- </select>
- </mapper>
|