<?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.KnzzTufaApplyMapper">
    
    <resultMap type="KnzzTufaApply" id="KnzzTufaApplyResult">
        <result property="id"    column="id"    />
        <result property="stuNo"    column="stu_no"    />
        <result property="stuName"    column="stu_name"    />
        <result property="gender"    column="gender"    />
        <result property="mz"    column="mz"    />
        <result property="className"    column="class_name"    />
        <result property="stuPhone"    column="stu_phone"    />
        <result property="sfzh"    column="sfzh"    />
        <result property="helpHis"    column="help_his"    />
        <result property="bankCard"    column="bank_card"    />
        <result property="jthk"    column="jthk"    />
        <result property="hardCondition"    column="hard_condition"    />
        <result property="yearMoney"    column="year_money"    />
        <result property="monthMoney"    column="month_money"    />
        <result property="moneySource"    column="money_source"    />
        <result property="familyAddr"    column="family_addr"    />
        <result property="postCode"    column="post_code"    />
        <result property="familyMemberList"    column="family_member_list"    />
        <result property="applyReason"    column="apply_reason"    />
        <result property="applySign"    column="apply_sign"    />
        <result property="applyDate"    column="apply_date"    />
        <result property="hardFile"    column="hard_file"    />
        <result property="applyStatus"    column="apply_status"    />
        <result property="fdyCmt"    column="fdy_cmt"    />
        <result property="fdySign"    column="fdy_sign"    />
        <result property="fdyDate"    column="fdy_date"    />
        <result property="fdyNo"    column="fdy_no"    />
        <result property="deptCmt"    column="dept_cmt"    />
        <result property="deptSign"    column="dept_sign"    />
        <result property="deptDate"    column="dept_date"    />
        <result property="deptNo"    column="dept_no"    />
        <result property="xgCmt"    column="xg_cmt"    />
        <result property="xgSign"    column="xg_sign"    />
        <result property="xgDate"    column="xg_date"    />
        <result property="xgNo"    column="xg_no"    />
        <result property="leaderCmt"    column="leader_cmt"    />
        <result property="leaderSign"    column="leader_sign"    />
        <result property="leaderDate"    column="leader_date"    />
        <result property="leaderNo"    column="leader_no"    />
        <result property="stuYearId"    column="stu_year_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"    />
    </resultMap>

    <sql id="selectKnzzTufaApplyVo">
        select id, stu_no, stu_name, gender, mz, class_name, stu_phone, sfzh, help_his, bank_card, jthk, hard_condition, year_money, month_money, money_source, family_addr, post_code, family_member_list, apply_reason, apply_sign, apply_date, hard_file, apply_status, fdy_cmt, fdy_sign, fdy_date, fdy_no, dept_cmt, dept_sign, dept_date, dept_no, xg_cmt, xg_sign, xg_date, xg_no, leader_cmt, leader_sign, leader_date, leader_no, stu_year_id, create_by, create_time, update_by, update_time from knzz_tufa_apply
    </sql>

    <select id="selectKnzzTufaApplyList" parameterType="KnzzTufaApply" resultMap="KnzzTufaApplyResult">
        <include refid="selectKnzzTufaApplyVo"/>
        <where>  
            <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="gender != null  and gender != ''"> and gender = #{gender}</if>
            <if test="mz != null  and mz != ''"> and mz = #{mz}</if>
            <if test="className != null  and className != ''"> and class_name like concat('%', #{className}, '%')</if>
            <if test="stuPhone != null  and stuPhone != ''"> and stu_phone = #{stuPhone}</if>
            <if test="sfzh != null  and sfzh != ''"> and sfzh = #{sfzh}</if>
            <if test="helpHis != null  and helpHis != ''"> and help_his = #{helpHis}</if>
            <if test="bankCard != null  and bankCard != ''"> and bank_card = #{bankCard}</if>
            <if test="jthk != null  and jthk != ''"> and jthk = #{jthk}</if>
            <if test="hardCondition != null  and hardCondition != ''"> and hard_condition = #{hardCondition}</if>
            <if test="yearMoney != null  and yearMoney != ''"> and year_money = #{yearMoney}</if>
            <if test="monthMoney != null  and monthMoney != ''"> and month_money = #{monthMoney}</if>
            <if test="moneySource != null  and moneySource != ''"> and money_source = #{moneySource}</if>
            <if test="familyAddr != null  and familyAddr != ''"> and family_addr = #{familyAddr}</if>
            <if test="postCode != null  and postCode != ''"> and post_code = #{postCode}</if>
            <if test="familyMemberList != null  and familyMemberList != ''"> and family_member_list = #{familyMemberList}</if>
            <if test="applyReason != null  and applyReason != ''"> and apply_reason = #{applyReason}</if>
            <if test="applySign != null  and applySign != ''"> and apply_sign = #{applySign}</if>
            <if test="applyDate != null "> and apply_date = #{applyDate}</if>
            <if test="hardFile != null  and hardFile != ''"> and hard_file = #{hardFile}</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="fdySign != null  and fdySign != ''"> and fdy_sign = #{fdySign}</if>
            <if test="fdyDate != null "> and fdy_date = #{fdyDate}</if>
            <if test="fdyNo != null  and fdyNo != ''"> and fdy_no = #{fdyNo}</if>
            <if test="deptCmt != null  and deptCmt != ''"> and dept_cmt = #{deptCmt}</if>
            <if test="deptSign != null  and deptSign != ''"> and dept_sign = #{deptSign}</if>
            <if test="deptDate != null "> and dept_date = #{deptDate}</if>
            <if test="deptNo != null  and deptNo != ''"> and dept_no = #{deptNo}</if>
            <if test="xgCmt != null  and xgCmt != ''"> and xg_cmt = #{xgCmt}</if>
            <if test="xgSign != null  and xgSign != ''"> and xg_sign = #{xgSign}</if>
            <if test="xgDate != null "> and xg_date = #{xgDate}</if>
            <if test="xgNo != null  and xgNo != ''"> and xg_no = #{xgNo}</if>
            <if test="leaderCmt != null  and leaderCmt != ''"> and leader_cmt = #{leaderCmt}</if>
            <if test="leaderSign != null  and leaderSign != ''"> and leader_sign = #{leaderSign}</if>
            <if test="leaderDate != null "> and leader_date = #{leaderDate}</if>
            <if test="leaderNo != null  and leaderNo != ''"> and leader_no = #{leaderNo}</if>
            <if test="stuYearId != null "> and stu_year_id = #{stuYearId}</if>
        </where>
    </select>
    
    <select id="selectKnzzTufaApplyById" parameterType="Long" resultMap="KnzzTufaApplyResult">
        <include refid="selectKnzzTufaApplyVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertKnzzTufaApply" parameterType="KnzzTufaApply" useGeneratedKeys="true" keyProperty="id">
        insert into knzz_tufa_apply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">stu_no,</if>
            <if test="stuName != null">stu_name,</if>
            <if test="gender != null">gender,</if>
            <if test="mz != null">mz,</if>
            <if test="className != null">class_name,</if>
            <if test="stuPhone != null">stu_phone,</if>
            <if test="sfzh != null">sfzh,</if>
            <if test="helpHis != null">help_his,</if>
            <if test="bankCard != null">bank_card,</if>
            <if test="jthk != null">jthk,</if>
            <if test="hardCondition != null">hard_condition,</if>
            <if test="yearMoney != null">year_money,</if>
            <if test="monthMoney != null">month_money,</if>
            <if test="moneySource != null">money_source,</if>
            <if test="familyAddr != null">family_addr,</if>
            <if test="postCode != null">post_code,</if>
            <if test="familyMemberList != null">family_member_list,</if>
            <if test="applyReason != null">apply_reason,</if>
            <if test="applySign != null">apply_sign,</if>
            <if test="applyDate != null">apply_date,</if>
            <if test="hardFile != null">hard_file,</if>
            <if test="applyStatus != null">apply_status,</if>
            <if test="fdyCmt != null">fdy_cmt,</if>
            <if test="fdySign != null">fdy_sign,</if>
            <if test="fdyDate != null">fdy_date,</if>
            <if test="fdyNo != null">fdy_no,</if>
            <if test="deptCmt != null">dept_cmt,</if>
            <if test="deptSign != null">dept_sign,</if>
            <if test="deptDate != null">dept_date,</if>
            <if test="deptNo != null">dept_no,</if>
            <if test="xgCmt != null">xg_cmt,</if>
            <if test="xgSign != null">xg_sign,</if>
            <if test="xgDate != null">xg_date,</if>
            <if test="xgNo != null">xg_no,</if>
            <if test="leaderCmt != null">leader_cmt,</if>
            <if test="leaderSign != null">leader_sign,</if>
            <if test="leaderDate != null">leader_date,</if>
            <if test="leaderNo != null">leader_no,</if>
            <if test="stuYearId != null">stu_year_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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">#{stuNo},</if>
            <if test="stuName != null">#{stuName},</if>
            <if test="gender != null">#{gender},</if>
            <if test="mz != null">#{mz},</if>
            <if test="className != null">#{className},</if>
            <if test="stuPhone != null">#{stuPhone},</if>
            <if test="sfzh != null">#{sfzh},</if>
            <if test="helpHis != null">#{helpHis},</if>
            <if test="bankCard != null">#{bankCard},</if>
            <if test="jthk != null">#{jthk},</if>
            <if test="hardCondition != null">#{hardCondition},</if>
            <if test="yearMoney != null">#{yearMoney},</if>
            <if test="monthMoney != null">#{monthMoney},</if>
            <if test="moneySource != null">#{moneySource},</if>
            <if test="familyAddr != null">#{familyAddr},</if>
            <if test="postCode != null">#{postCode},</if>
            <if test="familyMemberList != null">#{familyMemberList},</if>
            <if test="applyReason != null">#{applyReason},</if>
            <if test="applySign != null">#{applySign},</if>
            <if test="applyDate != null">#{applyDate},</if>
            <if test="hardFile != null">#{hardFile},</if>
            <if test="applyStatus != null">#{applyStatus},</if>
            <if test="fdyCmt != null">#{fdyCmt},</if>
            <if test="fdySign != null">#{fdySign},</if>
            <if test="fdyDate != null">#{fdyDate},</if>
            <if test="fdyNo != null">#{fdyNo},</if>
            <if test="deptCmt != null">#{deptCmt},</if>
            <if test="deptSign != null">#{deptSign},</if>
            <if test="deptDate != null">#{deptDate},</if>
            <if test="deptNo != null">#{deptNo},</if>
            <if test="xgCmt != null">#{xgCmt},</if>
            <if test="xgSign != null">#{xgSign},</if>
            <if test="xgDate != null">#{xgDate},</if>
            <if test="xgNo != null">#{xgNo},</if>
            <if test="leaderCmt != null">#{leaderCmt},</if>
            <if test="leaderSign != null">#{leaderSign},</if>
            <if test="leaderDate != null">#{leaderDate},</if>
            <if test="leaderNo != null">#{leaderNo},</if>
            <if test="stuYearId != null">#{stuYearId},</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>
         </trim>
    </insert>

    <update id="updateKnzzTufaApply" parameterType="KnzzTufaApply">
        update knzz_tufa_apply
        <trim prefix="SET" suffixOverrides=",">
            <if test="stuNo != null">stu_no = #{stuNo},</if>
            <if test="stuName != null">stu_name = #{stuName},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="mz != null">mz = #{mz},</if>
            <if test="className != null">class_name = #{className},</if>
            <if test="stuPhone != null">stu_phone = #{stuPhone},</if>
            <if test="sfzh != null">sfzh = #{sfzh},</if>
            <if test="helpHis != null">help_his = #{helpHis},</if>
            <if test="bankCard != null">bank_card = #{bankCard},</if>
            <if test="jthk != null">jthk = #{jthk},</if>
            <if test="hardCondition != null">hard_condition = #{hardCondition},</if>
            <if test="yearMoney != null">year_money = #{yearMoney},</if>
            <if test="monthMoney != null">month_money = #{monthMoney},</if>
            <if test="moneySource != null">money_source = #{moneySource},</if>
            <if test="familyAddr != null">family_addr = #{familyAddr},</if>
            <if test="postCode != null">post_code = #{postCode},</if>
            <if test="familyMemberList != null">family_member_list = #{familyMemberList},</if>
            <if test="applyReason != null">apply_reason = #{applyReason},</if>
            <if test="applySign != null">apply_sign = #{applySign},</if>
            <if test="applyDate != null">apply_date = #{applyDate},</if>
            <if test="hardFile != null">hard_file = #{hardFile},</if>
            <if test="applyStatus != null">apply_status = #{applyStatus},</if>
            <if test="fdyCmt != null">fdy_cmt = #{fdyCmt},</if>
            <if test="fdySign != null">fdy_sign = #{fdySign},</if>
            <if test="fdyDate != null">fdy_date = #{fdyDate},</if>
            <if test="fdyNo != null">fdy_no = #{fdyNo},</if>
            <if test="deptCmt != null">dept_cmt = #{deptCmt},</if>
            <if test="deptSign != null">dept_sign = #{deptSign},</if>
            <if test="deptDate != null">dept_date = #{deptDate},</if>
            <if test="deptNo != null">dept_no = #{deptNo},</if>
            <if test="xgCmt != null">xg_cmt = #{xgCmt},</if>
            <if test="xgSign != null">xg_sign = #{xgSign},</if>
            <if test="xgDate != null">xg_date = #{xgDate},</if>
            <if test="xgNo != null">xg_no = #{xgNo},</if>
            <if test="leaderCmt != null">leader_cmt = #{leaderCmt},</if>
            <if test="leaderSign != null">leader_sign = #{leaderSign},</if>
            <if test="leaderDate != null">leader_date = #{leaderDate},</if>
            <if test="leaderNo != null">leader_no = #{leaderNo},</if>
            <if test="stuYearId != null">stu_year_id = #{stuYearId},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKnzzTufaApplyById" parameterType="Long">
        delete from knzz_tufa_apply where id = #{id}
    </delete>

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

    <select id="listView" parameterType="KnzzTufaApply" resultType="KnzzTufaApply">
        select a.*,c.stu_year_name,b.dept_name,d.`name` as fdy_name,e.`name` as xw_name,f.`name` as xg_name,g.`name` as leader_name
        from knzz_tufa_apply as a
                 left join view_stu_info as b on a.stu_no = b.stu_no
                 left join srs_stu_year as c on a.stu_year_id = c.id
                 left join cph_teacher as d on a.fdy_no = d.employee_id
                 left join qgzx_teacher as e on a.dept_no = d.employee_id
                 left join qgzx_teacher as f on a.xg_no = f.employee_id
                 left join qgzx_teacher as g on a.leader_no = g.employee_id
        <where>
            <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="fdyNo != null  and fdyNo != ''"> and b.t_no = #{fdyNo}</if>
            <if test="deptId != null "> and b.dept_id = #{deptId}</if>
            <if test="stuYearId != null "> and a.stu_year_id = #{stuYearId}</if>
            <if test="deptName != null  and deptName != ''"> and b.dept_name like concat('%',#{ deptName},'%')</if>
            <if test="stuName != null  and stuName != ''"> and b.stu_name like concat('%',#{stuName},'%')</if>
            <if test="className != null  and className != ''"> and b.class_name like concat('%',#{className},'%')</if>
        </where>
        order by a.id desc
    </select>


</mapper>