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

    <resultMap type="CphLakeApply" id="CphLakeApplyResult">
        <result property="id"    column="id"    />
        <result property="stuNo"    column="stu_no"    />
        <result property="typeCode"    column="type_code"    />
        <result property="stuYearId"    column="stu_year_id"    />
        <result property="zzmm"    column="zzmm"    />
        <result property="classPost"    column="class_post"    />
        <result property="bankCard"    column="bank_card"    />
        <result property="bankAddr"    column="bank_addr"    />
        <result property="goodHis"    column="good_his"    />
        <result property="mainHis"    column="main_his"    />
        <result property="classtwoSure"    column="classtwo_sure"    />
        <result property="youthPercent"    column="youth_percent"    />
        <result property="applyStatus"    column="apply_status"    />
        <result property="applyTime"    column="apply_time"    />
        <result property="fdyComment"    column="fdy_comment"    />
        <result property="xwComment"    column="xw_comment"    />
        <result property="jwcComment"    column="jwc_comment"    />
        <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="selectCphLakeApplyVo">
        select id, stu_no, type_code, stu_year_id, zzmm, class_post, bank_card, bank_addr, good_his, main_his, classtwo_sure, youth_percent, apply_status, apply_time, fdy_comment, xw_comment, jwc_comment, create_by, create_time, update_by, update_time from cph_lake_apply
    </sql>

    <select id="selectCphLakeApplyList" parameterType="CphLakeApply" resultMap="CphLakeApplyResult">
        <include refid="selectCphLakeApplyVo"/>
        <where>
            <if test="stuNo != null  and stuNo != ''"> and stu_no = #{stuNo}</if>
            <if test="typeCode != null  and typeCode != ''"> and type_code = #{typeCode}</if>
            <if test="stuYearId != null "> and stu_year_id = #{stuYearId}</if>
            <if test="zzmm != null  and zzmm != ''"> and zzmm = #{zzmm}</if>
            <if test="classPost != null  and classPost != ''"> and class_post = #{classPost}</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="goodHis != null  and goodHis != ''"> and good_his = #{goodHis}</if>
            <if test="mainHis != null  and mainHis != ''"> and main_his = #{mainHis}</if>
            <if test="classtwoSure != null  and classtwoSure != ''"> and classtwo_sure = #{classtwoSure}</if>
            <if test="youthPercent != null  and youthPercent != ''"> and youth_percent = #{youthPercent}</if>
            <if test="applyStatus != null  and applyStatus != ''"> and apply_status = #{applyStatus}</if>
            <if test="applyTime != null "> and apply_time = #{applyTime}</if>
            <if test="fdyComment != null  and fdyComment != ''"> and fdy_comment = #{fdyComment}</if>
            <if test="xwComment != null  and xwComment != ''"> and xw_comment = #{xwComment}</if>
            <if test="jwcComment != null  and jwcComment != ''"> and jwc_comment = #{jwcComment}</if>
        </where>
    </select>

    <select id="exportView" resultType="CphLakeApplyVo" parameterType="CphSearch">
        SELECT a.*,b.type_name,c.`name` as stu_name,d.class_name,e.major_name,e.major_type_name,
               f.dept_name,g.`name` as teacher_name,h.stu_year_name, NOW() as import_time,i.sport_score,
               case
                   when a.apply_status = 1 then '已提交待辅导员审核'
                   when a.apply_status = 6 then '学工审核通过'
                   when a.apply_status = 10 then '驳回'
                   when a.apply_status = 11 then '拒绝'
                   when a.apply_status = 12 then '作废'
                   when a.apply_status = 2 then '辅导员审核通过'
                   when a.apply_status = 3 then '学院审核通过'
                   else '无状态' end as apply_status_ex,
               (select class_count from view_stu_class_count where class_id = d.class_id) as class_count,
               (select major_count from view_stu_major_count where major_id = d.major_id and grade_id = d.grade_id) as major_count,
               i.cph_class_rank,i.stu_major_rank

        from cph_lake_apply as a
                 left join cph_lake_type as b on a.type_code = b.type_code
                 left join srs_student as c on a.stu_no = c.stu_no
                 left join srs_class as d on c.class_id = d.class_id
                 left join srs_majors as e on d.major_id = e.major_id
                 left join sys_dept as f on e.college_id = f.dept_id
                 left join cph_teacher as g on d.teacher_id = g.teacher_id
                 left join srs_stu_year as h on a.stu_year_id = h.id
                 left join view_stu_cph_rank as i on a.stu_no = i.stu_no and a.stu_year_id = i.stu_year_id
        <where>
            <if test="stuNo != null  and stuNo != ''"> and a.stu_no = #{stuNo}</if>
            <if test="stuName != null  and stuName != ''"> and c.`name` like concat('%', #{stuName}, '%')</if>
            <if test="classId != null  and classId != ''"> and d.class_id = #{classId}</if>
            <if test="majorId != null  and majorId != ''"> and d.major_id = #{majorId}</if>
            <if test="deptId != null  and deptId != ''"> and f.dept_id = #{deptId}</if>
            <if test="tNo != null  and tNo != ''"> and g.employee_id = #{tNo}</if>
            <if test="code != null  and code != ''"> and a.type_code = #{code}</if>
            <if test="status != null  and status != ''"> and a.apply_status = #{status}</if>
            <if test="stuYearId != null  and stuYearId != ''"> and a.stu_year_id = #{stuYearId}</if>
        </where>
        ORDER BY a.id desc , a.apply_status asc

    </select>

    <select id="listView" resultType="CphLakeApplyVo" parameterType="CphSearch">
        SELECT a.*,i.nick_name as fdy_no_name,j.nick_name as xw_no_name,k.nick_name as xg_no_name,b.type_name,c.`name` as stu_name,d.class_name,e.major_name,
        f.dept_name,g.`name` as teacher_name,h.stu_year_name, NOW() as import_time,e.major_type_name,
        case
        when a.apply_status = 1 then '已提交待辅导员审核'
        when a.apply_status = 6 then '学工审核通过'
        when a.apply_status = 10 then '驳回'
        when a.apply_status = 11 then '拒绝'
        when a.apply_status = 12 then '作废'
        when a.apply_status = 2 then '辅导员审核通过'
        when a.apply_status = 3 then '学院审核通过'
        else '无状态' end as apply_status_ex
        from cph_lake_apply as a
        left join cph_lake_type as b on a.type_code = b.type_code
        left join srs_student as c on a.stu_no = c.stu_no
        left join srs_class as d on c.class_id = d.class_id
        left join srs_majors as e on d.major_id = e.major_id
        left join sys_dept as f on e.college_id = f.dept_id
        left join cph_teacher as g on d.teacher_id = g.teacher_id
        left join srs_stu_year as h on a.stu_year_id = h.id
        left join sys_user as i on a.fdy_no = i.user_name
        left join sys_user as j on a.xw_no = j.user_name
        left join sys_user as k on a.xg_no = k.user_name
        <where>
            <if test="stuNo != null  and stuNo != ''"> and a.stu_no = #{stuNo}</if>
            <if test="stuName != null  and stuName != ''"> and c.`name` like concat('%', #{stuName}, '%')</if>
            <if test="classId != null  and classId != ''"> and d.class_id = #{classId}</if>
            <if test="majorId != null  and majorId != ''"> and d.major_id = #{majorId}</if>
            <if test="deptId != null  and deptId != ''"> and f.dept_id = #{deptId}</if>
            <if test="tNo != null  and tNo != ''"> and g.employee_id = #{tNo}</if>
            <if test="code != null  and code != ''"> and a.type_code = #{code}</if>
            <if test="status != null  and status != ''"> and a.apply_status = #{status}</if>
            <if test="stuYearId != null  and stuYearId != ''"> and a.stu_year_id = #{stuYearId}</if>
        </where>
        ORDER BY a.id desc , a.apply_status asc
    </select>

    <select id="selectCphLakeApplyById" parameterType="Long" resultMap="CphLakeApplyResult">
        <include refid="selectCphLakeApplyVo"/>
        where id = #{id}
    </select>

    <insert id="insertCphLakeApply" parameterType="CphLakeApply" useGeneratedKeys="true" keyProperty="id">
        insert into cph_lake_apply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">stu_no,</if>
            <if test="typeCode != null">type_code,</if>
            <if test="stuYearId != null">stu_year_id,</if>
            <if test="zzmm != null">zzmm,</if>
            <if test="classPost != null">class_post,</if>
            <if test="bankCard != null">bank_card,</if>
            <if test="bankAddr != null">bank_addr,</if>
            <if test="goodHis != null">good_his,</if>
            <if test="mainHis != null">main_his,</if>
            <if test="classtwoSure != null">classtwo_sure,</if>
            <if test="youthPercent != null">youth_percent,</if>
            <if test="applyStatus != null">apply_status,</if>
            <if test="applyTime != null">apply_time,</if>
            <if test="fdyComment != null">fdy_comment,</if>
            <if test="xwComment != null">xw_comment,</if>
            <if test="jwcComment != null">jwc_comment,</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="typeCode != null">#{typeCode},</if>
            <if test="stuYearId != null">#{stuYearId},</if>
            <if test="zzmm != null">#{zzmm},</if>
            <if test="classPost != null">#{classPost},</if>
            <if test="bankCard != null">#{bankCard},</if>
            <if test="bankAddr != null">#{bankAddr},</if>
            <if test="goodHis != null">#{goodHis},</if>
            <if test="mainHis != null">#{mainHis},</if>
            <if test="classtwoSure != null">#{classtwoSure},</if>
            <if test="youthPercent != null">#{youthPercent},</if>
            <if test="applyStatus != null">#{applyStatus},</if>
            <if test="applyTime != null">#{applyTime},</if>
            <if test="fdyComment != null">#{fdyComment},</if>
            <if test="xwComment != null">#{xwComment},</if>
            <if test="jwcComment != null">#{jwcComment},</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="updateCphLakeApply" parameterType="CphLakeApply">
        update cph_lake_apply
        <trim prefix="SET" suffixOverrides=",">
            <if test="stuNo != null">stu_no = #{stuNo},</if>
            <if test="typeCode != null">type_code = #{typeCode},</if>
            <if test="stuYearId != null">stu_year_id = #{stuYearId},</if>
            <if test="zzmm != null">zzmm = #{zzmm},</if>
            <if test="classPost != null">class_post = #{classPost},</if>
            <if test="bankCard != null">bank_card = #{bankCard},</if>
            <if test="bankAddr != null">bank_addr = #{bankAddr},</if>
            <if test="goodHis != null">good_his = #{goodHis},</if>
            <if test="mainHis != null">main_his = #{mainHis},</if>
            <if test="classtwoSure != null">classtwo_sure = #{classtwoSure},</if>
            <if test="youthPercent != null">youth_percent = #{youthPercent},</if>
            <if test="applyStatus != null">apply_status = #{applyStatus},</if>
            <if test="applyTime != null">apply_time = #{applyTime},</if>
            <if test="fdyComment != null">fdy_comment = #{fdyComment},</if>
            <if test="xwComment != null">xw_comment = #{xwComment},</if>
            <if test="jwcComment != null">jwc_comment = #{jwcComment},</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="deleteCphLakeApplyById" parameterType="Long">
        delete from cph_lake_apply where id = #{id}
    </delete>

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