<?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.DisciplinaryMapper">

    <resultMap type="StuDisciplinaryApplication" id="RtStuDisciplinaryApplicationResult">
        <result property="applicationId"    column="application_id"    />
        <result property="applicantId"    column="applicant_id"    />
        <result property="penaltyNumber"    column="penalty_number"    />
        <result property="stuNo"    column="stu_no"    />
        <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="expirationDate"    column="expiration_date"    />
        <result property="evidenceUpload"    column="evidence_upload"    />
        <result property="penaltyRecommendation"    column="penalty_recommendation"    />
        <result property="violationRegulations"    column="violation_regulations"    />
        <result property="submissionStatus"    column="submission_status"    />
        <result property="processInstanceId"    column="process_instance_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"    />
    </resultMap>


    <sql id="selectRtStuDisciplinaryApplicationVo">
        select application_id, applicant_id, penalty_number, stu_no, stu_id, penalty_type, penalty_status, violation_date, expiration_date, evidence_upload, penalty_recommendation, violation_regulations, submission_status, process_instance_id, create_by, create_time, update_by, update_time, remark from rt_stu_disciplinary_application
    </sql>

    <update id="updateRtStuDisciplinaryApplication" parameterType="RtStuDisciplinaryApplication">
        update rt_stu_disciplinary_application
        <trim prefix="SET" suffixOverrides=",">
            <if test="applicantId != null">applicant_id = #{applicantId},</if>
            <if test="applicantName != null">applicant_name = #{applicantName},</if>
            <if test="penaltyNumber != null">penalty_number = #{penaltyNumber},</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="expirationDate != null">expiration_date = #{expirationDate},</if>
            <if test="evidenceUpload != null">evidence_upload = #{evidenceUpload},</if>
            <if test="penaltyRecommendation != null">penalty_recommendation = #{penaltyRecommendation},</if>
            <if test="violationRegulations != null">violation_regulations = #{violationRegulations},</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="dispositionService != null">disposition_service = #{dispositionService},</if>
        </trim>
        where application_id = #{applicationId}
    </update>

    <update id="updateStudentStatus" parameterType="Student">
        update srs_student
        <trim prefix="SET" suffixOverrides=",">
            <if test="classId != null">class_id = #{classId},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where stu_no = #{stuNo}
    </update>
    <delete id="deleteDormitoryStudent" parameterType="SrsDormitoryStudent">
        delete from srs_dormitory_student where stu_no=#{stuNo}
    </delete>

    <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="selectRtStuDisciplinaryApplicationByApplicationId" parameterType="Long" resultMap="RtStuDisciplinaryApplicationResult">
        <include refid="selectRtStuDisciplinaryApplicationVo"/>
        where penalty_number = #{penaltyNumber}
    </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>

    <!--知无涯 新增: 根据用户ID查询用户名的SQL实现 -->
    <select id="getUserNameByUserId" resultType="java.lang.String">
        SELECT user_name FROM sys_user WHERE user_id = #{userId}
    </select>

    <!-- 知无涯 新增：批量查询用户名的SQL实现 -->
    <select id="getUserNamesByUserIdList" resultType="java.lang.String">
        SELECT user_name FROM sys_user
        WHERE user_id IN
        <foreach item="userId" collection="userIdList" open="(" separator="," close=")">
            #{userId}
        </foreach>
        AND user_name IS NOT NULL AND user_name != ''
    </select>


</mapper>
