<?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.xjrsoft.module.teacher.mapper.TeacherAwardItemMapper">
    <select id="getStatisticsPage" parameterType="com.xjrsoft.module.teacher.dto.TeacherAwardStatisticsPageDto" resultType="com.xjrsoft.module.teacher.vo.TeacherAwardStatisticsPageVo">
        SELECT t1.id, t1.user_name, t1.name,t1.code,t3.name AS gender_cn,t1.mobile,
        (SELECT SUM(a2.score) FROM teacher_award a1
        INNER JOIN teacher_award_item a2 ON a1.teacher_award_item_id = a2.id
        WHERE a1.status = 1 AND a1.delete_mark = 0 AND a2.delete_mark = 0
        AND a1.applicant_user_id = t1.id
        ) AS score FROM xjr_user t1
        INNER JOIN base_teacher t2 ON t1.id = t2.user_id
        left join xjr_user_dept_relation t4 on t4.user_id = t1.id
        LEFT JOIN xjr_dictionary_detail t3 ON t1.gender = t3.code
        WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
        <if test="dto.userName != null and dto.userName != '' ">
            and t1.user_name like concat('%', #{dto.userName}, '%')
        </if>
        <if test="dto.name != null and dto.name != '' ">
            and t1.name like concat('%', #{dto.name}, '%')
        </if>
        <if test="dto.deptId != null">
            and t4.dept_id = #{dto.deptId}
        </if>
    </select>
</mapper>