<?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.comprehensive.mapper.CphNewGoodClassApplyMapper">

    <resultMap type="CphNewGoodClassApply" id="CphNewGoodClassApplyResult">
        <result property="id"    column="id"    />
        <result property="stuNo"    column="stu_no"    />
        <result property="classId"    column="class_id"    />
        <result property="classCode"    column="class_code"    />
        <result property="stuYearId"    column="stu_year_id"    />
        <result property="idCard"    column="id_card"    />
        <result property="bankCard"    column="bank_card"    />
        <result property="bankAddr"    column="bank_addr"    />
        <result property="applyStatus"    column="apply_status"    />
        <result property="fdyCmt"    column="fdy_cmt"    />
        <result property="xwCmt"    column="xw_cmt"    />
        <result property="jwcCmt"    column="jwc_cmt"    />
        <result property="goodHis"    column="good_his"    />
        <result property="mainHis"    column="main_his"    />
        <result property="fdyName"    column="fdy_name"    />
        <result property="bzrName"    column="bzr_name"    />
        <result property="fdyNo"    column="fdy_no"    />
        <result property="bzrNo"    column="bzr_no"    />
        <result property="applyTime"    column="apply_time"    />
        <result property="classCount"    column="class_count"    />
        <result property="fdyAuditNo"    column="fdy_audit_no"    />
        <result property="xwAuditNo"    column="xw_audit_no"    />
        <result property="jwcAuditNo"    column="jwc_audit_no"    />
        <result property="isSendMoney"    column="is_send_money"    />
        <result property="sendMoneyTime"    column="send_money_time"    />
        <result property="remark"    column="remark"    />
        <result property="testimonyMaterials"    column="testimony_materials"    />
    </resultMap>

    <sql id="selectCphNewGoodClassApplyVo">
        select id, stu_no, class_id, class_code, stu_year_id, id_card, bank_card, bank_addr, apply_status, fdy_cmt, xw_cmt, jwc_cmt,
               good_his, main_his, fdy_name, bzr_name, fdy_no, bzr_no, apply_time, class_count, fdy_audit_no, xw_audit_no, jwc_audit_no,
               is_send_money, send_money_time, remark ,testimony_materials from cph_new_good_class_apply
    </sql>

    <select id="selectCphNewGoodClassApplyList" parameterType="CphNewGoodClassApply" resultMap="CphNewGoodClassApplyResult">
        <include refid="selectCphNewGoodClassApplyVo"/>
        <where>
            <if test="stuNo != null  and stuNo != ''"> and stu_no = #{stuNo}</if>
            <if test="classId != null "> and class_id = #{classId}</if>
            <if test="classCode != null  and classCode != ''"> and class_code = #{classCode}</if>
            <if test="stuYearId != null "> and stu_year_id = #{stuYearId}</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="bankCard != null  and bankCard != ''"> and bank_card = #{bankCard}</if>
            <if test="bankAddr != null  and bankAddr != ''"> and bank_addr = #{bankAddr}</if>
            <if test="applyStatus != null  and applyStatus != ''"> and apply_status = #{applyStatus}</if>
            <if test="fdyCmt != null  and fdyCmt != ''"> and fdy_cmt = #{fdyCmt}</if>
            <if test="xwCmt != null  and xwCmt != ''"> and xw_cmt = #{xwCmt}</if>
            <if test="jwcCmt != null  and jwcCmt != ''"> and jwc_cmt = #{jwcCmt}</if>
            <if test="goodHis != null  and goodHis != ''"> and good_his = #{goodHis}</if>
            <if test="mainHis != null  and mainHis != ''"> and main_his = #{mainHis}</if>
            <if test="fdyName != null  and fdyName != ''"> and fdy_name like concat('%', #{fdyName}, '%')</if>
            <if test="bzrName != null  and bzrName != ''"> and bzr_name like concat('%', #{bzrName}, '%')</if>
            <if test="fdyNo != null  and fdyNo != ''"> and fdy_no = #{fdyNo}</if>
            <if test="bzrNo != null  and bzrNo != ''"> and bzr_no = #{bzrNo}</if>
            <if test="applyTime != null "> and apply_time = #{applyTime}</if>
            <if test="classCount != null "> and class_count = #{classCount}</if>
            <if test="fdyAuditNo != null  and fdyAuditNo != ''"> and fdy_audit_no = #{fdyAuditNo}</if>
            <if test="xwAuditNo != null  and xwAuditNo != ''"> and xw_audit_no = #{xwAuditNo}</if>
            <if test="jwcAuditNo != null  and jwcAuditNo != ''"> and jwc_audit_no = #{jwcAuditNo}</if>
            <if test="isSendMoney != null  and isSendMoney != ''"> and is_send_money = #{isSendMoney}</if>
            <if test="sendMoneyTime != null "> and send_money_time = #{sendMoneyTime}</if>
            <if test="testimonyMaterials != null and testimonyMaterials != ''"> and testimony_materials = #{testimonyMaterials}</if>
        </where>
    </select>

    <select id="selectCphNewGoodClassApplyById" parameterType="Long" resultMap="CphNewGoodClassApplyResult">
        <include refid="selectCphNewGoodClassApplyVo"/>
        where id = #{id}
    </select>

    <insert id="insertCphNewGoodClassApply" parameterType="CphNewGoodClassApply" useGeneratedKeys="true" keyProperty="id">
        insert into cph_new_good_class_apply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">stu_no,</if>
            <if test="classId != null">class_id,</if>
            <if test="classCode != null">class_code,</if>
            <if test="stuYearId != null">stu_year_id,</if>
            <if test="idCard != null">id_card,</if>
            <if test="bankCard != null">bank_card,</if>
            <if test="bankAddr != null">bank_addr,</if>
            <if test="applyStatus != null">apply_status,</if>
            <if test="fdyCmt != null">fdy_cmt,</if>
            <if test="xwCmt != null">xw_cmt,</if>
            <if test="jwcCmt != null">jwc_cmt,</if>
            <if test="goodHis != null">good_his,</if>
            <if test="mainHis != null">main_his,</if>
            <if test="fdyName != null">fdy_name,</if>
            <if test="bzrName != null">bzr_name,</if>
            <if test="fdyNo != null">fdy_no,</if>
            <if test="bzrNo != null">bzr_no,</if>
            <if test="applyTime != null">apply_time,</if>
            <if test="classCount != null">class_count,</if>
            <if test="fdyAuditNo != null">fdy_audit_no,</if>
            <if test="xwAuditNo != null">xw_audit_no,</if>
            <if test="jwcAuditNo != null">jwc_audit_no,</if>
            <if test="isSendMoney != null">is_send_money,</if>
            <if test="sendMoneyTime != null">send_money_time,</if>
            <if test="remark != null">remark,</if>
            <if test="testimonyMaterials != null">testimony_materials,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">#{stuNo},</if>
            <if test="classId != null">#{classId},</if>
            <if test="classCode != null">#{classCode},</if>
            <if test="stuYearId != null">#{stuYearId},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="bankCard != null">#{bankCard},</if>
            <if test="bankAddr != null">#{bankAddr},</if>
            <if test="applyStatus != null">#{applyStatus},</if>
            <if test="fdyCmt != null">#{fdyCmt},</if>
            <if test="xwCmt != null">#{xwCmt},</if>
            <if test="jwcCmt != null">#{jwcCmt},</if>
            <if test="goodHis != null">#{goodHis},</if>
            <if test="mainHis != null">#{mainHis},</if>
            <if test="fdyName != null">#{fdyName},</if>
            <if test="bzrName != null">#{bzrName},</if>
            <if test="fdyNo != null">#{fdyNo},</if>
            <if test="bzrNo != null">#{bzrNo},</if>
            <if test="applyTime != null">#{applyTime},</if>
            <if test="classCount != null">#{classCount},</if>
            <if test="fdyAuditNo != null">#{fdyAuditNo},</if>
            <if test="xwAuditNo != null">#{xwAuditNo},</if>
            <if test="jwcAuditNo != null">#{jwcAuditNo},</if>
            <if test="isSendMoney != null">#{isSendMoney},</if>
            <if test="sendMoneyTime != null">#{sendMoneyTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="testimonyMaterials != null">#{testimonyMaterials},</if>
        </trim>
    </insert>

    <update id="updateCphNewGoodClassApply" parameterType="CphNewGoodClassApply">
        update cph_new_good_class_apply
        <trim prefix="SET" suffixOverrides=",">
            <if test="stuNo != null">stu_no = #{stuNo},</if>
            <if test="classId != null">class_id = #{classId},</if>
            <if test="classCode != null">class_code = #{classCode},</if>
            <if test="stuYearId != null">stu_year_id = #{stuYearId},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="bankCard != null">bank_card = #{bankCard},</if>
            <if test="bankAddr != null">bank_addr = #{bankAddr},</if>
            <if test="applyStatus != null">apply_status = #{applyStatus},</if>
            <if test="fdyCmt != null">fdy_cmt = #{fdyCmt},</if>
            <if test="xwCmt != null">xw_cmt = #{xwCmt},</if>
            <if test="jwcCmt != null">jwc_cmt = #{jwcCmt},</if>
            <if test="goodHis != null">good_his = #{goodHis},</if>
            <if test="mainHis != null">main_his = #{mainHis},</if>
            <if test="fdyName != null">fdy_name = #{fdyName},</if>
            <if test="bzrName != null">bzr_name = #{bzrName},</if>
            <if test="fdyNo != null">fdy_no = #{fdyNo},</if>
            <if test="bzrNo != null">bzr_no = #{bzrNo},</if>
            <if test="applyTime != null">apply_time = #{applyTime},</if>
            <if test="classCount != null">class_count = #{classCount},</if>
            <if test="fdyAuditNo != null">fdy_audit_no = #{fdyAuditNo},</if>
            <if test="xwAuditNo != null">xw_audit_no = #{xwAuditNo},</if>
            <if test="jwcAuditNo != null">jwc_audit_no = #{jwcAuditNo},</if>
            <if test="isSendMoney != null">is_send_money = #{isSendMoney},</if>
            <if test="sendMoneyTime != null">send_money_time = #{sendMoneyTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="testimonyMaterials != null">testimony_materials = #{testimonyMaterials},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCphNewGoodClassApplyById" parameterType="Long">
        delete from cph_new_good_class_apply where id = #{id}
    </delete>

    <delete id="deleteCphNewGoodClassApplyByIds" parameterType="String">
        delete from cph_new_good_class_apply where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <select id="listView" parameterType="CphNewGoodClassApply" resultType="CphNewGoodClassApply">
        select a.*,i.nick_name as fdy_no_name,j.nick_name as xw_no_name,k.nick_name as xg_no_name,b.stu_name,c.class_name,d.stu_year_name,e.major_name,f.dept_name,e.major_type_name
        from cph_new_good_class_apply as a
        left join view_stu_info as b on a.stu_no = b.stu_no
        left join srs_class as c on a.class_id = c.class_id
        left join srs_majors as e on c.major_id = e.major_id
        left join sys_dept as f on e.college_id = f.dept_id
        left join srs_stu_year as d on a.stu_year_id = d.id
        left join sys_user as i on a.fdy_audit_no = i.user_name
        left join sys_user as j on a.xw_audit_no = j.user_name
        left join sys_user as k on a.jwc_audit_no = k.user_name
        <where>
            <if test="stuNo != null  and stuNo != ''"> and a.stu_no = #{stuNo}</if>
            <if test="stuName != null  and stuName != ''"> and b.stu_name like  concat('%',#{stuName},'%')</if>
            <if test="classId != null "> and a.class_id = #{classId}</if>
            <if test="stuYearId != null "> and a.stu_year_id = #{stuYearId}</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="bankCard != null  and bankCard != ''"> and bank_card = #{bankCard}</if>
            <if test="applyStatus != null  and applyStatus != ''"> and a.apply_status = #{applyStatus}</if>
            <if test="fdyName != null  and fdyName != ''"> and fdy_name like concat('%', #{fdyName}, '%')</if>
            <if test="bzrName != null  and bzrName != ''"> and bzr_name like concat('%', #{bzrName}, '%')</if>
            <if test="fdyNo != null  and fdyNo != ''"> and fdy_no = #{fdyNo}</if>
            <if test="bzrNo != null  and bzrNo != ''"> and bzr_no = #{bzrNo}</if>
            <if test="applyTime != null "> and apply_time = #{applyTime}</if>
            <if test="classCount != null "> and class_count = #{classCount}</if>

            <if test="majorId != null "> and e.major_id = #{majorId}</if>
            <if test="deptId != null "> and f.dept_id = #{deptId}</if>

            <if test="isSendMoney != null  and isSendMoney != ''"> and is_send_money = #{isSendMoney}</if>


        </where>

        order by a.id desc
    </select>

    <select id="exportView" parameterType="CphNewGoodClassApply" resultType="ExcelGoodClass">
        select a.*,b.stu_name,c.class_name,d.stu_year_name,e.major_name,f.dept_name,e.major_type_name,
        case a.apply_status
        when '1' then '已提交待辅导员审核'
        when '2' then '辅导员审核通过'
        when '3' then '学院审核通过'
        when '6' then '学工处审核通过'
        when '11' then '拒绝'
        else '无' end as apply_status_export
        from cph_new_good_class_apply as a
        left join view_stu_info as b on a.stu_no = b.stu_no
        left join srs_class as c on a.class_id = c.class_id
        left join srs_majors as e on c.major_id = e.major_id
        left join sys_dept as f on e.college_id = f.dept_id
        left join srs_stu_year as d on a.stu_year_id = d.id
        <where>
            <if test="stuNo != null  and stuNo != ''"> and a.stu_no = #{stuNo}</if>
            <if test="stuName != null  and stuName != ''"> and b.stu_name like  concat('%',#{stuName},'%')</if>
            <if test="classId != null "> and a.class_id = #{classId}</if>
            <if test="stuYearId != null "> and a.stu_year_id = #{stuYearId}</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="bankCard != null  and bankCard != ''"> and bank_card = #{bankCard}</if>
            <if test="applyStatus != null  and applyStatus != ''"> and a.apply_status = #{applyStatus}</if>
            <if test="fdyName != null  and fdyName != ''"> and fdy_name like concat('%', #{fdyName}, '%')</if>
            <if test="bzrName != null  and bzrName != ''"> and bzr_name like concat('%', #{bzrName}, '%')</if>
            <if test="fdyNo != null  and fdyNo != ''"> and fdy_no = #{fdyNo}</if>
            <if test="bzrNo != null  and bzrNo != ''"> and bzr_no = #{bzrNo}</if>
            <if test="applyTime != null "> and apply_time = #{applyTime}</if>
            <if test="classCount != null "> and class_count = #{classCount}</if>

            <if test="majorId != null "> and e.major_id = #{majorId}</if>
            <if test="deptId != null "> and f.dept_id = #{deptId}</if>

            <if test="isSendMoney != null  and isSendMoney != ''"> and is_send_money = #{isSendMoney}</if>


        </where>

        order by a.id desc
    </select>

    <select id="exportFdy"  parameterType="CphNewGoodClassApply" resultType="ExcelGoodClass">
        select a.*,b.stu_name,c.class_name,d.stu_year_name,e.major_name,f.dept_name,
        case a.apply_status
        when '1' then '已提交待辅导员审核'
        when '2' then '辅导员审核通过'
        when '3' then '学院审核通过'
        when '6' then '学工处审核通过'
        when '11' then '拒绝'
        else '无' end as apply_status_export
        from cph_new_good_class_apply as a
        left join view_stu_info as b on a.stu_no = b.stu_no
        left join srs_class as c on a.class_id = c.class_id
        left join srs_majors as e on c.major_id = e.major_id
        left join sys_dept as f on e.college_id = f.dept_id
        left join srs_stu_year as d on a.stu_year_id = d.id
        <where>
            b.t_no = #{fdyNo}
            <if test="stuNo != null  and stuNo != ''"> and a.stu_no = #{stuNo}</if>
            <if test="applyStatus != null  and applyStatus != ''"> and a.apply_status = #{applyStatus}</if>
            <if test="isSendMoney != null  and isSendMoney != ''"> and is_send_money = #{isSendMoney}</if>
            <if test="stuName != null  and stuName != ''"> and b.stu_name like  concat('%',#{stuName},'%')</if>
            <if test="classId != null "> and a.class_id = #{classId}</if>
            <if test="stuYearId != null "> and a.stu_year_id = #{stuYearId}</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="bankCard != null  and bankCard != ''"> and bank_card = #{bankCard}</if>
            <if test="applyStatus != null  and applyStatus != ''"> and a.apply_status = #{applyStatus}</if>
            <if test="bzrName != null  and bzrName != ''"> and bzr_name like concat('%', #{bzrName}, '%')</if>
            <if test="bzrNo != null  and bzrNo != ''"> and bzr_no = #{bzrNo}</if>
            <if test="applyTime != null "> and apply_time = #{applyTime}</if>
        </where>
    </select>

    <select id="listFdy" parameterType="CphNewGoodClassApply" resultType="CphNewGoodClassApply">
        select a.*,b.stu_name,c.class_name,d.stu_year_name,e.major_name,f.dept_name
        from cph_new_good_class_apply as a
        left join view_stu_info as b on a.stu_no = b.stu_no
        left join srs_class as c on a.class_id = c.class_id
        left join srs_majors as e on c.major_id = e.major_id
        left join sys_dept as f on e.college_id = f.dept_id
        left join srs_stu_year as d on a.stu_year_id = d.id
        <where>
            b.t_no = #{fdyNo}
            <if test="stuNo != null  and stuNo != ''"> and a.stu_no = #{stuNo}</if>
            <if test="applyStatus != null  and applyStatus != ''"> and a.apply_status = #{applyStatus}</if>
            <if test="isSendMoney != null  and isSendMoney != ''"> and is_send_money = #{isSendMoney}</if>

            <if test="stuName != null  and stuName != ''"> and b.stu_name like  concat('%',#{stuName},'%')</if>
            <if test="classId != null "> and a.class_id = #{classId}</if>
            <if test="stuYearId != null "> and a.stu_year_id = #{stuYearId}</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="bankCard != null  and bankCard != ''"> and bank_card = #{bankCard}</if>
            <if test="applyStatus != null  and applyStatus != ''"> and a.apply_status = #{applyStatus}</if>
            <if test="bzrName != null  and bzrName != ''"> and bzr_name like concat('%', #{bzrName}, '%')</if>
            <if test="bzrNo != null  and bzrNo != ''"> and bzr_no = #{bzrNo}</if>
            <if test="applyTime != null "> and apply_time = #{applyTime}</if>
        </where>
    </select>

    <select id="getStuClass" resultType="CphNewGoodClassApply" parameterType="String">
        select a.teacher_name as fdy_name,a.class_id,a.class_code,a.t_no as fdy_no,a.class_name, (select count(stu_no) from srs_student as a1 where a1.class_id = a.class_id and a1.`status` = '01') as class_count
        from view_stu_info as a
        where a.stu_no = #{stuNo}
    </select>

</mapper>
