<?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.srs.flowable.mapper.RelieveMapper">

    <resultMap type="StuDisciplinaryRelieve" id="RtStuDisciplinaryRelieveResult">
        <result property="relieveId" column="relieve_id"/>
        <result property="penaltyNumber" column="penalty_number"/>
        <result property="relieveNumber"    column="relieve_number"    />
        <result property="stuNo" column="stu_no"/>
        <result property="stuName" column="stu_name"/>
        <result property="stuId" column="stu_id"/>
        <result property="penaltyType" column="penalty_type"/>
        <result property="penaltyStatus" column="penalty_status"/>
        <result property="violationDate" column="violation_date"/>
        <result property="dispositionDescription" column="disposition_description"/>
        <result property="applicationDismissal" column="application_dismissal"/>
        <result property="ideologicalEducation" column="ideological_education"/>
        <result property="submissionStatus" column="submission_status"/>
        <result property="processInstanceId" column="process_instance_id"/>
        <result property="deployId" column="deploy_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="gender" column="gender"/>
        <result property="departmentName" column="department_Name"/>
        <result property="gradeName" column="grade_name"/>
        <result property="className" column="class_name"/>
        <result property="mz" column="mz"/>
        <result property="birthday" column="birthday"/>
        <result property="jg" column="jg"/>
        <result property="hksz2" column="hksz2"/>
        <result property="relieveService"    column="relieve_service"    />
    </resultMap>

    <sql id="selectRtStuDisciplinaryRelieveVo">
        select relieve_id, penalty_number, relieve_number, stu_no, stu_name, stu_id, penalty_type, penalty_status,
               violation_date, disposition_description, application_dismissal, ideological_education, submission_status,
               process_instance_id, deploy_id, create_by, create_time, update_by, update_time, remark, gender, department_Name,
               grade_name, class_name, mz, birthday, jg, hksz2, relieve_service from rt_stu_disciplinary_relieve
    </sql>



    <update id="updateRtStuDisciplinaryRelieve" parameterType="RtStuDisciplinaryRelieve">
        update rt_stu_disciplinary_relieve
        <trim prefix="SET" suffixOverrides=",">
            <if test="penaltyNumber != null">penalty_number = #{penaltyNumber},</if>
            <if test="relieveNumber != null">relieve_number = #{relieveNumber},</if>
            <if test="stuNo != null">stu_no = #{stuNo},</if>
            <if test="stuName != null">stu_name = #{stuName},</if>
            <if test="stuId != null">stu_id = #{stuId},</if>
            <if test="penaltyType != null">penalty_type = #{penaltyType},</if>
            <if test="penaltyStatus != null">penalty_status = #{penaltyStatus},</if>
            <if test="violationDate != null">violation_date = #{violationDate},</if>
            <if test="dispositionDescription != null">disposition_description = #{dispositionDescription},</if>
            <if test="applicationDismissal != null">application_dismissal = #{applicationDismissal},</if>
            <if test="ideologicalEducation != null">ideological_education = #{ideologicalEducation},</if>
            <if test="submissionStatus != null">submission_status = #{submissionStatus},</if>
            <if test="processInstanceId != null">process_instance_id = #{processInstanceId},</if>
            <if test="deployId != null">deploy_id = #{deployId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="departmentName != null">department_Name = #{departmentName},</if>
            <if test="gradeName != null">grade_name = #{gradeName},</if>
            <if test="className != null">class_name = #{className},</if>
            <if test="mz != null">mz = #{mz},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="jg != null">jg = #{jg},</if>
            <if test="hksz2 != null">hksz2 = #{hksz2},</if>
            <if test="relieveService != null">relieve_service = #{relieveService},</if>
        </trim>
        where relieve_id = #{relieveId}
    </update>


    <select id="getApprovalByDeptIdAndRoleKey" resultType="java.lang.Long">
        SELECT a.user_id
        FROM sys_user a
                 LEFT JOIN sys_user_role b ON a.user_id = b.user_id
                 LEFT JOIN sys_role c ON b.role_id = c.role_id
        WHERE a.dept_id = #{deptId}
          and c.role_key = #{roleKey}
    </select>


    <select id="getApprovalByRoleKey" resultType="java.lang.Long">
        SELECT a.user_id
        FROM sys_user a
                 LEFT JOIN sys_user_role b ON a.user_id = b.user_id
                 LEFT JOIN sys_role c ON b.role_id = c.role_id
        WHERE c.role_key = #{roleKey}
    </select>

    <select id="getCounselorInfo" resultType="java.util.Map">
        SELECT e.user_id userId, e.dept_id deptId
        FROM sys_user a
                 LEFT JOIN srs_student d ON a.user_name = d.stu_no
                 LEFT JOIN srs_class b ON d.class_id = b.class_id
                 LEFT JOIN cph_teacher c ON b.teacher_id = c.teacher_id
                 LEFT JOIN sys_user e ON c.employee_id = e.user_name
        WHERE a.user_id = #{stuUserId}
    </select>

    <select id="selectRtStuDisciplinaryRelieveByRelieveId" parameterType="Long" resultMap="RtStuDisciplinaryRelieveResult">
        <include refid="selectRtStuDisciplinaryRelieveVo"/>
        where relieve_id = #{relieveId}
    </select>


</mapper>