123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <?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.jeeplus.modules.exam.mapper.EduUserTestsMapper">
-
- <sql id="eduUserTestsColumns">
- a.id AS "id",
- a.user_id AS "user.id",
- a.paper_id AS "paperId",
- a.paper_name AS "paperName",
- a.test_date AS "testDate",
- a.points AS "points",
- a.tests_type AS "testsType",
- a.question_ids AS "questionIds"
- </sql>
-
- <sql id="eduUserTestsJoins">
-
- </sql>
-
-
- <select id="get" resultType="EduUserTests" >
- SELECT
- <include refid="eduUserTestsColumns"/>
- FROM edu_user_tests a
- <include refid="eduUserTestsJoins"/>
- WHERE a.id = #{id}
- </select>
-
- <select id="findList" resultType="EduUserTests" >
- SELECT
- <include refid="eduUserTestsColumns"/>
- <if test="testsType == '2'">
- ,b.score AS "score",
- b.exam_time AS "examTime"
- </if>
- FROM edu_user_tests a
- <if test="testsType == '2'">
- ,edu_paper b
- </if>
- <where>
- 1=1
- <if test="testsType == '2'">
- and a.paper_id = b.id
- </if>
- <if test="paperId !=null and paperId!='' ">
- and a.paper_id = #{paperId}
- </if>
- <if test="user != null and user != ''">
- and a.user_id = #{user.id}
- </if>
- <if test="questionIds != null and questionIds != ''">
- AND a.question_ids LIKE concat('%',#{questionIds},'%')
- </if>
- <if test="testsType != null and testsType != ''">
- and a.tests_type = #{testsType}
- </if>
- ${dataScope}
- </where>
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- order by a.test_date desc
- </otherwise>
- </choose>
- </select>
- <select id="findAllList" resultType="EduUserTests" >
- SELECT
- <include refid="eduUserTestsColumns"/>,
- /*如果空 则为随机测试 设置随机测试分数与时间*/
- ifnull(b.exam_time, 10) as "examTime",
- ifnull(b.score,10) as "score"
- FROM edu_user_tests a
- left join edu_paper b on a.paper_id = b.id
- <where>
- ${dataScope}
- </where>
- ORDER BY a.test_date DESC
- </select>
- <select id="findPassRate" resultType="EduUserTests" >
- select
- u.id,u.paper_id,u.paper_name,p.score,
- SUM(case when u.points>=(score*0.6) then 1 else 0 end )jg,
- SUM(case when u.points<(score*0.6) then 1 else 0 end ) bjg,
- CONCAT(FORMAT((SUM(case when u.points>=(score*0.6) then 1 else 0 end )/(SUM(case when u.points>=(score*0.6) then 1 else 0 end )+
- SUM(case when u.points<(score*0.6) then 1 else 0 end )))*100,2),'%') as jgl
- from edu_user_tests u LEFT JOIN edu_paper p on u.paper_id = p.id
- <where>
- 1=1
- ${dataScope}
- <if test="paperName !=null and paperName!='' ">
- and u.paper_name LIKE concat('%',#{paperName},'%')
- </if>
- </where>
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- GROUP BY u.paper_id
- order by u.test_date desc
- </otherwise>
- </choose>
- </select>
- <select id="findPassUser" resultType="EduUserTests" >
- select u.id,u.paper_id,u.paper_name,p.score,s.name,u.points,u.user_id
- from edu_user_tests u LEFT JOIN edu_paper p on u.paper_id = p.id
- LEFT JOIN sys_user s on u.user_id = s.id
- <where>
- 1=1
- ${dataScope}
- <if test="name !=null and name!='' ">
- and s.name LIKE concat('%',#{name},'%')
- </if>
- and u.points>=(score*0.6) and u.paper_id=#{paperId}
- </where>
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- order by u.test_date desc
- </otherwise>
- </choose>
- </select>
- <select id="findFailUser" resultType="EduUserTests" >
- select u.id,u.paper_id,u.paper_name,p.score,s.name,u.points,u.user_id
- from edu_user_tests u LEFT JOIN edu_paper p on u.paper_id = p.id
- LEFT JOIN sys_user s on u.user_id = s.id
- <where>
- 1=1
- ${dataScope}
- <if test="name !=null and name!='' ">
- and s.name LIKE concat('%',#{name},'%')
- </if>
- and u.points<(score*0.6) and u.paper_id=#{paperId}
- </where>
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- order by u.test_date desc
- </otherwise>
- </choose>
- </select>
- <insert id="insert" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
- INSERT INTO edu_user_tests(
- id,
- user_id,
- paper_id,
- paper_name,
- test_date,
- points,
- tests_type,
- question_ids
- ) VALUES (
- #{id},
- #{user.id},
- #{paperId},
- #{paperName},
- #{testDate},
- #{points},
- #{testsType},
- #{questionIds}
- )
- </insert>
-
- <update id="update">
- UPDATE edu_user_tests SET
- user_id = #{user.id},
- paper_id = #{paperId},
- paper_name = #{paperName},
- test_date = #{testDate},
- points = #{points},
- tests_type = #{testsType},
- question_ids = #{questionIds}
- WHERE id = #{id}
- </update>
-
-
- <!--物理删除-->
- <update id="delete">
- DELETE FROM edu_user_tests
- WHERE id = #{id}
- </update>
-
- <!--逻辑删除-->
- <update id="deleteByLogic">
- UPDATE edu_user_tests SET
- del_flag = #{DEL_FLAG_DELETE}
- WHERE id = #{id}
- </update>
-
-
- <!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
- <select id="findUniqueByProperty" resultType="EduUserTests" statementType="STATEMENT">
- select * FROM edu_user_tests where ${propertyName} = '${value}'
- </select>
-
- </mapper>
|