<?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.mindskip.xzs.repository.ExamTemplatesUserCountMapper">
|
<resultMap id="BaseResultMap" type="com.mindskip.xzs.domain.ExamTemplatesUserCount">
|
<id column="id" jdbcType="INTEGER" property="id"/>
|
<result column="exam_paper_id" jdbcType="INTEGER" property="examPaperId"/>
|
<result column="user_id" jdbcType="INTEGER" property="userId"/>
|
<result column="exam_templates_id" jdbcType="INTEGER" property="examTemplatesId"/>
|
</resultMap>
|
|
<sql id="Base_Column_List">
|
id
|
, exam_paper_id, user_id, exam_templates_id
|
</sql>
|
|
<insert id="add" parameterType="com.mindskip.xzs.domain.ExamTemplatesUserCount" useGeneratedKeys="true" keyProperty="id">
|
insert into t_exam_templates_user_count (exam_paper_id, user_id, exam_templates_id)
|
values (#{examPaperId}, #{userId}, #{examTemplatesId})
|
</insert>
|
|
<select id="list" resultType="com.mindskip.xzs.domain.vo.ExamTemplatesUserCountVO" parameterType="com.mindskip.xzs.viewmodel.admin.exam.ExamPaperPageRequestVM">
|
SELECT
|
e.id as id,
|
count(u.user_id) as count,
|
u.user_id as userId
|
FROM
|
t_exam_templates e
|
left join `t_exam_templates_user_count` u on u.exam_templates_id = e.id <if test="userId != null">and u.user_id = #{userId}</if>
|
<where>
|
<if test="templatesId != null">
|
and u.exam_templates_id = #{templatesId}
|
</if>
|
|
<if test="status != null">
|
and e.status = 0
|
</if>
|
<if test="status == null">
|
and e.status is null
|
</if>
|
</where>
|
GROUP BY u.exam_templates_id, u.user_id
|
</select>
|
|
<select id="getByTemplatesIds" resultMap="BaseResultMap">
|
select * from t_exam_templates_user_count
|
where exam_templates_id in
|
<foreach item="id" collection="ids" open="(" separator=","
|
close=")">
|
#{id}
|
</foreach>
|
</select>
|
|
<select id="getByUserIds" resultMap="BaseResultMap">
|
select * from t_exam_templates_user_count
|
where user_id in
|
<foreach item="id" collection="ids" open="(" separator=","
|
close=")">
|
#{id}
|
</foreach>
|
</select>
|
|
<select id="getByUserIdAndTemplatesId" resultMap="BaseResultMap" parameterType="com.mindskip.xzs.domain.vo.ExamTemplatesUserCountVO">
|
select * from t_exam_templates_user_count
|
where user_id = #{userId} and exam_templates_id = #{id}
|
</select>
|
|
<select id="getCountByUserIdAndTemplatesId" resultType="java.lang.Integer" parameterType="com.mindskip.xzs.domain.vo.ExamTemplatesUserCountVO">
|
select count(*) from t_exam_templates_user_count a
|
inner join t_exam_paper_answer b on a.exam_paper_id = b.exam_paper_id and (b.invalid = 0 or b.invalid is null)
|
where user_id = #{userId} and exam_templates_id = #{id}
|
</select>
|
|
<select id="getByTemplates" resultMap="BaseResultMap">
|
select * from t_exam_templates_user_count
|
where exam_templates_id = #{id}
|
</select>
|
|
<select id="getByExamTemplates" resultType="com.mindskip.xzs.domain.vo.UserCountExcelVO" parameterType="java.lang.Integer">
|
SELECT t.`name`as name,d.`name` as departmentName,u.real_name as userName,SUBSTRING_INDEX(a.user_score/10,".",1) as userScore,SUBSTRING_INDEX(a.paper_score/10,".",1) as paperScore,ee.count as count,a.do_time as doTime
|
from t_exam_templates_user_count c
|
LEFT JOIN (select user_id as id,exam_templates_id,count(*) as count from t_exam_templates_user_count GROUP BY exam_templates_id,user_id) ee on ee.exam_templates_id = c.exam_templates_id and ee.id = c.user_id
|
LEFT JOIN t_exam_templates t on c.exam_templates_id = t.id
|
INNER JOIN t_exam_paper_answer a on (c.exam_paper_id = a.exam_paper_id and c.user_id = a.create_user)
|
LEFT JOIN t_user u on a.create_user = u.id
|
LEFT JOIN t_department d on d.id = u.user_level
|
where c.exam_templates_id = #{id}
|
</select>
|
|
<select id="getByExamTemplatesUser" resultType="com.mindskip.xzs.domain.vo.UserCountExcelVO" parameterType="java.lang.Integer">
|
SELECT t.`name`as name,d.`name` as departmentName,u.real_name as userName,SUBSTRING_INDEX(a.user_score/10,".",1) as userScore,SUBSTRING_INDEX(a.paper_score/10,".",1) as paperScore,a.do_time as doTime
|
from t_exam_templates_user c
|
LEFT JOIN t_exam_templates t on c.templates_id = t.id
|
left join t_exam_templates_user_count o on c.templates_id = o.exam_templates_id
|
LEFT JOIN t_exam_paper_answer a on (o.exam_paper_id = a.exam_paper_id and o.user_id = a.create_user)
|
LEFT JOIN t_user u on a.create_user = u.id
|
LEFT JOIN t_department d on d.id = u.user_level
|
where c.templates_id = #{id}
|
</select>
|
|
</mapper>
|