<?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.routine.mapper.RtStuDisciplinaryApplicationMapper">

    <resultMap type="RtStuDisciplinaryApplication" id="RtStuDisciplinaryApplicationResult">
        <result property="applicationId"    column="application_id"    />
        <result property="applicantId"    column="applicant_id"    />
        <result property="applicantName"    column="applicant_name"    />
        <result property="penaltyNumber"    column="penalty_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="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="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="politicalStatus"    column="political_status"    />
        <result property="hksz2"    column="hksz2"    />
        <result property="dispositionService"    column="disposition_service"    />
        <result property="letterService"    column="letter_service"    />
        <result property="disciplinaryDate"    column="disciplinary_date"    />
    </resultMap>

    <sql id="selectRtStuDisciplinaryApplicationVo">
        select application_id, applicant_id, applicant_name, penalty_number, stu_no, stu_name, stu_id, penalty_type,
               penalty_status, violation_date, expiration_date, evidence_upload, penalty_recommendation, violation_regulations,
               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,political_status,hksz2,disposition_service,letter_service,disciplinary_date from rt_stu_disciplinary_application
    </sql>

    <select id="selectRtStuDisciplinaryApplicationList" parameterType="RtStuDisciplinaryApplication" resultMap="RtStuDisciplinaryApplicationResult">
        <include refid="selectRtStuDisciplinaryApplicationVo"/>
        <where>
            <if test="applicantId != null "> and applicant_id = #{applicantId}</if>
            <if test="applicantName != null  and applicantName != ''"> and applicant_name like concat('%', #{applicantName}, '%')</if>
            <if test="penaltyNumber != null  and penaltyNumber != ''"> and penalty_number = #{penaltyNumber}</if>
            <if test="stuNo != null  and stuNo != ''"> and stu_no = #{stuNo}</if>
            <if test="stuName != null  and stuName != ''"> and stu_name like concat('%', #{stuName}, '%')</if>
            <if test="stuId != null "> and stu_id = #{stuId}</if>
            <if test="penaltyType != null "> and penalty_type = #{penaltyType}</if>
            <if test="penaltyStatus != null "> and penalty_status = #{penaltyStatus}</if>
            <if test="violationDate != null "> and violation_date = #{violationDate}</if>
            <if test="expirationDate != null "> and expiration_date = #{expirationDate}</if>
            <if test="evidenceUpload != null  and evidenceUpload != ''"> and evidence_upload = #{evidenceUpload}</if>
            <if test="penaltyRecommendation != null  and penaltyRecommendation != ''"> and penalty_recommendation = #{penaltyRecommendation}</if>
            <if test="violationRegulations != null  and violationRegulations != ''"> and violation_regulations = #{violationRegulations}</if>
            <if test="submissionStatus != null "> and submission_status = #{submissionStatus}</if>
            <if test="processInstanceId != null  and processInstanceId != ''"> and process_instance_id = #{processInstanceId}</if>
            <if test="deployId != null  and deployId != ''"> and deploy_id = #{deployId}</if>
            <if test="gender != null  and gender != ''"> and gender = #{gender}</if>
            <if test="departmentName != null  and departmentName != ''"> and department_Name like concat('%', #{departmentName}, '%')</if>
            <if test="gradeName != null  and gradeName != ''"> and grade_name like concat('%', #{gradeName}, '%')</if>
            <if test="className != null  and className != ''"> and class_name like concat('%', #{className}, '%')</if>
            <if test="mz != null  and mz != ''"> and mz = #{mz}</if>
            <if test="birthday != null  and birthday != ''"> and birthday = #{birthday}</if>
            <if test="jg != null  and jg != ''"> and jg = #{jg}</if>
            <if test="politicalStatus != null  and politicalStatus != ''"> and political_status = #{politicalStatus}</if>
            <if test="hksz2 != null  and hksz2 != ''"> and hksz2 = #{hksz2}</if>
        </where>
        ORDER BY create_time desc
    </select>

    <select id="selectRtStuDisciplinaryApplicationByApplicationId" parameterType="Long" resultMap="RtStuDisciplinaryApplicationResult">
        <include refid="selectRtStuDisciplinaryApplicationVo"/>
        where application_id = #{applicationId}
    </select>

    <select id="selectDisciplinaryApplicationByProcInsId"  parameterType="String" resultMap="RtStuDisciplinaryApplicationResult">
        <include refid="selectRtStuDisciplinaryApplicationVo"/>
        where process_instance_id = #{procInsId}
    </select>

    <select id="selectClassDisciplinaryNumber"
            resultType="com.srs.routine.domain.vo.ClassStuDisciplinaryDataStatistics">
        SELECT b.`name` stuName,c.class_name className,b.stu_no stuNo FROM rt_stu_disciplinary_application a
           LEFT JOIN srs_student b ON a.stu_no=b.stu_no
           LEFT JOIN srs_class c ON b.class_id=c.class_id
           LEFT JOIN cph_teacher d ON c.teacher_id=d.teacher_id
        WHERE d.employee_id=#{username} AND a.penalty_status=0
    </select>

    <select id="selectRtStuDisciplinaryApplicationByStuNo"
            resultType="com.srs.routine.domain.RtStuDisciplinaryApplication">
        <include refid="selectRtStuDisciplinaryApplicationVo"/>
        where stu_no = #{stuNo} AND penalty_status = 0
        LIMIT 1
    </select>

    <select id="selectStuDisciplinaryApplicationByPenaltyNumber"
            resultType="com.srs.routine.domain.vo.StuDisciplinaryPenaltyNumber">
        select  penalty_number,  penalty_type, violation_date ,expiration_date ,penalty_recommendation,violation_regulations from rt_stu_disciplinary_application
        WHERE penalty_number = #{penaltyNumber}
    </select>



    <select id="selectRtStuDisciplinaryApplicationListXW" parameterType="RtStuDisciplinaryApplication" resultMap="RtStuDisciplinaryApplicationResult">
        select application_id, applicant_id, applicant_name, penalty_number, stu_no, stu_name, stu_id, penalty_type,penalty_status,
               violation_date, expiration_date, evidence_upload, penalty_recommendation, violation_regulations,submission_status,
               process_instance_id, deploy_id, a.create_by, a.create_time, a.update_by, a.update_time, a.remark, a.gender,a.department_Name,
               a.grade_name, a.class_name, a.mz, a.birthday, a.jg,a.political_status,a.hksz2,a.disposition_service,a.letter_service,a.disciplinary_date from rt_stu_disciplinary_application a
         LEFT JOIN sys_user b ON a.applicant_id = b.user_id
         LEFT JOIN cph_teacher c ON b.user_name = c.employee_id
        <where>
            <if test="applicantId != null "> and applicant_id = #{applicantId}</if>
            <if test="applicantName != null  and applicantName != ''"> and applicant_name like concat('%', #{applicantName}, '%')</if>
            <if test="penaltyNumber != null  and penaltyNumber != ''"> and penalty_number = #{penaltyNumber}</if>
            <if test="stuNo != null  and stuNo != ''"> and a.stu_no = #{stuNo}</if>
            <if test="stuName != null  and stuName != ''"> and stu_name like concat('%', #{stuName}, '%')</if>
            <if test="stuId != null "> and stu_id = #{stuId}</if>
            <if test="penaltyType != null "> and penalty_type = #{penaltyType}</if>
            <if test="penaltyStatus != null "> and penalty_status = #{penaltyStatus}</if>
            <if test="violationDate != null "> and violation_date = #{violationDate}</if>
            <if test="expirationDate != null "> and expiration_date = #{expirationDate}</if>
            <if test="evidenceUpload != null  and evidenceUpload != ''"> and evidence_upload = #{evidenceUpload}</if>
            <if test="penaltyRecommendation != null  and penaltyRecommendation != ''"> and penalty_recommendation = #{penaltyRecommendation}</if>
            <if test="violationRegulations != null  and violationRegulations != ''"> and violation_regulations = #{violationRegulations}</if>
            <if test="submissionStatus != null "> and submission_status = #{submissionStatus}</if>
            <if test="processInstanceId != null  and processInstanceId != ''"> and process_instance_id = #{processInstanceId}</if>
            <if test="deployId != null  and deployId != ''"> and deploy_id = #{deployId}</if>
            <if test="deptId != null  and deptId != ''"> and c.dept_id = #{deptId}</if>
        </where>
        ORDER BY a.create_time desc
    </select>
    <select id="getviolationDate" resultType="java.lang.String" parameterType="String">
        select violation_date from rt_stu_disciplinary_application where stu_no=#{stuNo}
    </select>

    <insert id="insertRtStuDisciplinaryApplication" parameterType="RtStuDisciplinaryApplication" useGeneratedKeys="true" keyProperty="applicationId">
        insert into rt_stu_disciplinary_application
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="applicantId != null">applicant_id,</if>
            <if test="applicantName != null">applicant_name,</if>
            <if test="penaltyNumber != null">penalty_number,</if>
            <if test="stuNo != null">stu_no,</if>
            <if test="stuName != null">stu_name,</if>
            <if test="stuId != null">stu_id,</if>
            <if test="penaltyType != null">penalty_type,</if>
            <if test="penaltyStatus != null">penalty_status,</if>
            <if test="violationDate != null">violation_date,</if>
            <if test="expirationDate != null">expiration_date,</if>
            <if test="evidenceUpload != null">evidence_upload,</if>
            <if test="penaltyRecommendation != null">penalty_recommendation,</if>
            <if test="violationRegulations != null">violation_regulations,</if>
            <if test="submissionStatus != null">submission_status,</if>
            <if test="processInstanceId != null">process_instance_id,</if>
            <if test="deployId != null">deploy_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="gender != null">gender,</if>
            <if test="departmentName != null">department_Name,</if>
            <if test="gradeName != null">grade_name,</if>
            <if test="className != null">class_name,</if>
            <if test="mz != null">mz,</if>
            <if test="birthday != null">birthday,</if>
            <if test="jg != null">jg,</if>
            <if test="politicalStatus != null">political_status,</if>
            <if test="hksz2 != null">hksz2,</if>
            <if test="dispositionService != null">disposition_service,</if>
            <if test="letterService != null">letter_service,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="applicantId != null">#{applicantId},</if>
            <if test="applicantName != null">#{applicantName},</if>
            <if test="penaltyNumber != null">#{penaltyNumber},</if>
            <if test="stuNo != null">#{stuNo},</if>
            <if test="stuName != null">#{stuName},</if>
            <if test="stuId != null">#{stuId},</if>
            <if test="penaltyType != null">#{penaltyType},</if>
            <if test="penaltyStatus != null">#{penaltyStatus},</if>
            <if test="violationDate != null">#{violationDate},</if>
            <if test="expirationDate != null">#{expirationDate},</if>
            <if test="evidenceUpload != null">#{evidenceUpload},</if>
            <if test="penaltyRecommendation != null">#{penaltyRecommendation},</if>
            <if test="violationRegulations != null">#{violationRegulations},</if>
            <if test="submissionStatus != null">#{submissionStatus},</if>
            <if test="processInstanceId != null">#{processInstanceId},</if>
            <if test="deployId != null">#{deployId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="gender != null">#{gender},</if>
            <if test="departmentName != null">#{departmentName},</if>
            <if test="gradeName != null">#{gradeName},</if>
            <if test="className != null">#{className},</if>
            <if test="mz != null">#{mz},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="jg != null">#{jg},</if>
            <if test="politicalStatus != null">#{politicalStatus},</if>
            <if test="hksz2 != null">#{hksz2},</if>
            <if test="dispositionService != null">#{dispositionService},</if>
            <if test="letterService != null">#{letterService},</if>
        </trim>
    </insert>

    <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="politicalStatus != null">political_status = #{politicalStatus},</if>
            <if test="hksz2 != null">hksz2 = #{hksz2},</if>
            <if test="dispositionService != null">disposition_service = #{dispositionService},</if>
            <if test="letterService != null">letter_service = #{letterService},</if>
            <if test="disciplinaryDate != null">disciplinary_date = #{disciplinaryDate},</if>
        </trim>
        where application_id = #{applicationId}
    </update>

    <delete id="deleteRtStuDisciplinaryApplicationByApplicationId" parameterType="Long">
        delete from rt_stu_disciplinary_application where application_id = #{applicationId}
    </delete>

    <delete id="deleteRtStuDisciplinaryApplicationByApplicationIds" parameterType="String">
        delete from rt_stu_disciplinary_application where application_id in
        <foreach item="applicationId" collection="array" open="(" separator="," close=")">
            #{applicationId}
        </foreach>
    </delete>
</mapper>
