<?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.workstudy.mapper.QgzxStuPostMapper">

    <resultMap type="QgzxStuPost" id="QgzxStuPostResult">
        <result property="id"    column="id"    />
        <result property="postId"    column="post_id"    />
        <result property="stuNo"    column="stu_no"    />
        <result property="canTime"    column="can_time"    />
        <result property="helpHis"    column="help_his"    />
        <result property="familyCondition"    column="family_condition"    />
        <result property="bankCard"    column="bank_card"    />
        <result property="idCard" column="id_card"/>
        <result property="bankAddr" column="bank_addr"/>
        <result property="stuPhone" column="stu_phone"/>
        <result property="stuDorm" column="stu_dorm"/>
        <result property="familyAddr" column="family_addr"/>
        <result property="applyMaterial" column="apply_material"/>
        <result property="applyReason" column="apply_reason"/>
        <result property="applySign" column="apply_sign"/>
        <result property="applyStatus" column="apply_status"/>
        <result property="workStatus" column="work_status"/>
        <result property="zdlsSign" column="zdls_sign"/>
        <result property="zdlsCmt" column="zdls_cmt"/>
        <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="delFlag" column="del_flag"/>
        <result property="status" column="status"/>

        <result property="applyTime" column="apply_time"/>
        <result property="returnMsg" column="return_msg"/>
        <result property="zdlsNo" column="zdls_no"/>

    </resultMap>

    <sql id="selectQgzxStuPostVo">
        select id,
               post_id,
               apply_time,
               stu_no,
               can_time,
               help_his,
               family_condition,
               bank_card,
               id_card,
               bank_addr,
               stu_phone,
               stu_dorm,
               family_addr,
               apply_material,
               apply_reason,
               apply_sign,
               apply_status,
               work_status,
               zdls_sign,
               zdls_cmt,
               create_by,
               create_time,
               update_by,
               update_time,
               del_flag,
               status,
               return_msg,
               zdls_no
        from qgzx_stu_post
    </sql>

    <select id="selectQgzxStuPostList" parameterType="QgzxStuPost" resultMap="QgzxStuPostResult">
        <include refid="selectQgzxStuPostVo"/>
        <where>
            <if test="postId != null ">and post_id = #{postId}</if>
            <if test="stuNo != null  and stuNo != ''">and stu_no = #{stuNo}</if>
            <if test="canTime != null ">and can_time = #{canTime}</if>
            <if test="helpHis != null  and helpHis != ''">and help_his = #{helpHis}</if>
            <if test="familyCondition != null  and familyCondition != ''">and family_condition = #{familyCondition}</if>
            <if test="bankCard != null  and bankCard != ''">and bank_card = #{bankCard}</if>
            <if test="idCard != null  and idCard != ''">and id_card = #{idCard}</if>
            <if test="bankAddr != null  and bankAddr != ''">and bank_addr = #{bankAddr}</if>
            <if test="stuPhone != null  and stuPhone != ''">and stu_phone = #{stuPhone}</if>
            <if test="stuDorm != null  and stuDorm != ''">and stu_dorm = #{stuDorm}</if>
            <if test="familyAddr != null  and familyAddr != ''">and family_addr = #{familyAddr}</if>
            <if test="applyMaterial != null  and applyMaterial != ''">and apply_material = #{applyMaterial}</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="applyStatus != null  and applyStatus != ''">and apply_status = #{applyStatus}</if>
            <if test="workStatus != null  and workStatus != ''">and work_status = #{workStatus}</if>
            <if test="zdlsSign != null  and zdlsSign != ''">and zdls_sign = #{zdlsSign}</if>
            <if test="zdlsCmt != null  and zdlsCmt != ''">and zdls_cmt = #{zdlsCmt}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
        </where>
    </select>

    <select id="getQgzxStuPostList" parameterType="StuPostListFindVo" resultType="StuPostListFindVo" >
        SELECT
            a.id,
            a.post_id,
            a.stu_no,
            e.`name` stu_name,
            a.can_time,
            a.family_condition,
            a.stu_phone,
            a.family_addr,
            a.work_status,
            a.zdls_no,
            b.post_name,
            b.dept_code,
            d.dept_name,
            c.`name` zdlsName
        FROM
            qgzx_stu_post a
                LEFT JOIN qgzx_post b ON a.post_id = b.id
                LEFT JOIN qgzx_teacher c ON a.zdls_no = c.employee_id
                LEFT JOIN sys_dept d ON b.dept_code = d.dept_code
                LEFT JOIN srs_student e ON a.stu_no = e.stu_no
        <where>
            <if test="postId != null">and a.post_id = #{postId}</if>
            <if test="workStatus != null  and workStatus != ''">and work_status = #{workStatus}</if>
            <if test="stuNo != null  and stuNo != ''">and a.stu_no = #{stuNo}</if>
            <if test="stuName != null  and stuName != ''">and e.`name` like concat('%', #{stuName}, '%') </if>
            <if test="postName != null  and postName != ''">and b.post_name  like concat('%', #{postName}, '%')</if>
            <if test="deptName != null  and deptName != ''">and d.dept_name  like concat('%', #{deptName}, '%') </if>
            <if test="zdlsName != null  and zdlsName != ''">and c.`name` like concat('%', #{zdlsName}, '%')</if>
        </where>
        order by d.dept_name
    </select>

    <select id="selectQgzxStuPostById" parameterType="Long" resultMap="QgzxStuPostResult">
        <include refid="selectQgzxStuPostVo"/>
        where id = #{id}
    </select>

    <insert id="insertQgzxStuPost" parameterType="QgzxStuPost" useGeneratedKeys="true" keyProperty="id">
        insert into qgzx_stu_post
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="postId != null">post_id,</if>
            <if test="stuNo != null">stu_no,</if>
            <if test="canTime != null">can_time,</if>
            <if test="helpHis != null">help_his,</if>
            <if test="familyCondition != null">family_condition,</if>
            <if test="bankCard != null">bank_card,</if>
            <if test="idCard != null">id_card,</if>
            <if test="bankAddr != null">bank_addr,</if>
            <if test="stuPhone != null">stu_phone,</if>
            <if test="stuDorm != null">stu_dorm,</if>
            <if test="familyAddr != null">family_addr,</if>
            <if test="applyMaterial != null">apply_material,</if>
            <if test="applyReason != null">apply_reason,</if>
            <if test="applySign != null">apply_sign,</if>
            <if test="applyStatus != null">apply_status,</if>
            <if test="workStatus != null">work_status,</if>
            <if test="zdlsSign != null">zdls_sign,</if>
            <if test="zdlsCmt != null">zdls_cmt,</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="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="status != null">status,</if>
            <if test="applyTime != null">apply_time,</if>
            <if test="returnMsg != null and returnMsg != ''">return_msg,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="postId != null">#{postId},</if>
            <if test="stuNo != null">#{stuNo},</if>
            <if test="canTime != null">#{canTime},</if>
            <if test="helpHis != null">#{helpHis},</if>
            <if test="familyCondition != null">#{familyCondition},</if>
            <if test="bankCard != null">#{bankCard},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="bankAddr != null">#{bankAddr},</if>
            <if test="stuPhone != null">#{stuPhone},</if>
            <if test="stuDorm != null">#{stuDorm},</if>
            <if test="familyAddr != null">#{familyAddr},</if>
            <if test="applyMaterial != null">#{applyMaterial},</if>
            <if test="applyReason != null">#{applyReason},</if>
            <if test="applySign != null">#{applySign},</if>
            <if test="applyStatus != null">#{applyStatus},</if>
            <if test="workStatus != null">#{workStatus},</if>
            <if test="zdlsSign != null">#{zdlsSign},</if>
            <if test="zdlsCmt != null">#{zdlsCmt},</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="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="status != null">#{status},</if>
            <if test="applyTime != null">#{applyTime},</if>
            <if test="returnMsg != null and returnMsg != ''">#{returnMsg},</if>
        </trim>
    </insert>

    <update id="updateQgzxStuPost" parameterType="QgzxStuPost">
        update qgzx_stu_post
        <trim prefix="SET" suffixOverrides=",">
            <if test="postId != null">post_id = #{postId},</if>
            <if test="stuNo != null">stu_no = #{stuNo},</if>
            <if test="canTime != null">can_time = #{canTime},</if>
            <if test="helpHis != null">help_his = #{helpHis},</if>
            <if test="familyCondition != null">family_condition = #{familyCondition},</if>
            <if test="bankCard != null">bank_card = #{bankCard},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="bankAddr != null">bank_addr = #{bankAddr},</if>
            <if test="stuPhone != null">stu_phone = #{stuPhone},</if>
            <if test="stuDorm != null">stu_dorm = #{stuDorm},</if>
            <if test="familyAddr != null">family_addr = #{familyAddr},</if>
            <if test="applyMaterial != null">apply_material = #{applyMaterial},</if>
            <if test="applyReason != null">apply_reason = #{applyReason},</if>
            <if test="applySign != null">apply_sign = #{applySign},</if>
            <if test="applyStatus != null">apply_status = #{applyStatus},</if>
            <if test="workStatus != null">work_status = #{workStatus},</if>
            <if test="zdlsSign != null">zdls_sign = #{zdlsSign},</if>
            <if test="zdlsCmt != null">zdls_cmt = #{zdlsCmt},</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="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="status != null">status = #{status},</if>
            <if test="applyTime != null">apply_time = #{applyTime},</if>
            <if test="returnMsg != null and returnMsg != ''">return_msg = #{returnMsg},</if>
            <if test="zdlsNo != null and zdlsNo != ''">zdls_no = #{zdlsNo},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateInstructor" parameterType="QgzxStuPostDto">
        update qgzx_stu_post
        <trim prefix="SET" suffixOverrides=",">
            <if test="zdlsSign != null">zdls_sign = #{zdlsSign},</if>
            <if test="zdlsNo != null and zdlsNo != ''">zdls_no = #{zdlsNo},</if>
        </trim>
        where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteQgzxStuPostById" parameterType="Long">
        delete
        from qgzx_stu_post
        where id = #{id}
    </delete>

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

    <select id="listView" parameterType="QgzxStuPost" resultType="QgzxStuPost">
        select a.id,a.post_id,a.stu_no,a.can_time,a.help_his,a.family_condition,a.bank_addr,a.bank_card,a.id_card,
        a.stu_phone,a.family_addr,a.apply_material,a.apply_reason,a.apply_sign,a.apply_status,a.apply_time,
        a.work_status,a.fdy_no,a.fdy_sign,a.fdy_cmt,a.zdls_no,a.zdls_sign,a.zdls_cmt,a.zzb_no,a.zzb_cmt,a.zzb_sign,
        a.fdy_time,a.zdls_time,a.zzb_time,f.name as fdy_name,g.name as zzb_name,
        b.post_name,e.`name` as zdls_name,b.zdls_phone,b.post_type,b.fzr_name,c.dept_name,
        d.stu_name,d.class_name,d.gender,d.dept_name as stu_dept,a.return_msg,a.stu_dorm
        from qgzx_stu_post as a
        left join qgzx_post as b on a.post_id = b.id
        left join sys_dept as c on b.dept_code = c.dept_code
        left join view_stu_info as d on a.stu_no = d.stu_no
        left join qgzx_teacher as e on a.zdls_no = e.employee_id
        left join qgzx_teacher as f on a.fdy_no = f.employee_id
        left join qgzx_teacher as g on a.zzb_no = g.employee_id
        <where>
            <if test="id != null ">and a.id = #{id}</if>
            <if test="postId != null ">and a.post_id = #{postId}</if>
            <if test="stuNo != null  and stuNo != ''">and a.stu_no = #{stuNo}</if>
            <if test="fdyNo != null  and fdyNo != ''">and d.t_no = #{fdyNo}</if>
            <if test="zdlsNo != null  and zdlsNo != ''">and a.zdls_no = #{zdlsNo}</if>
            <if test="familyCondition != null  and familyCondition != ''">and a.family_condition = #{familyCondition}
            </if>
            <if test="bankCard != null  and bankCard != ''">and a.bank_card = #{bankCard}</if>
            <if test="idCard != null  and idCard != ''">and a.id_card = #{idCard}</if>
            <if test="stuPhone != null  and stuPhone != ''">and a.stu_phone = #{stuPhone}</if>
            <if test="stuDorm != null  and stuDorm != ''">and a.stu_dorm like concat('%',#{stuDorm},'%')</if>
            <if test="applyStatus != null  and applyStatus != ''">and a.apply_status = #{applyStatus}</if>
            <if test="workStatus != null  and workStatus != ''">and a.work_status = #{workStatus}</if>
            <if test="applyTime != null">and a.apply_time like concat( date_format(#{applyTime}, '%Y-%m-%d'),'%')</if>
            <if test="postName != null  and postName != ''">and b.post_name like concat('%',#{postName},'%')</if>
            <if test="deptName != null  and deptName != ''">and c.dept_name like concat('%',#{deptName},'%')</if>
            <if test="fzrName != null  and fzrName != ''">and b.fzr_name like concat('%',#{fzrName},'%')</if>
            <if test="zdlsName != null  and zdlsName != ''">and e.`name` like concat('%',#{zdlsName},'%')</if>
            <if test="stuName != null  and stuName != ''">and d.stu_name like concat('%',#{stuName},'%')</if>
        </where>
        order by a.id desc
    </select>

    <select id="listTeacher" parameterType="cphTeacher" resultType="cphTeacher">
        select t.teacher_id,
               t.name,
               t.gender,
               t.age,
               t.employee_id,
               t.dept_id,
               t.phone_number,
               t.status,
               t.create_time,
               t.update_time,
               d.dept_name
        from qgzx_teacher t
                 left join sys_dept d on t.dept_id = d.dept_id
        <where>
            <if test="name != null  and name != ''">and name like concat('%',#{name},'%')</if>
            <if test="deptName != null  and deptName != ''">and d.dept_name like concat('%',#{deptName},'%')</if>
            <if test="gender != null  and gender != ''">and gender = #{gender}</if>
            <if test="age != null ">and age = #{age}</if>
            <if test="employeeId != null  and employeeId != ''">and employee_id like concat('%',#{employeeId},'%')
            </if>
            <if test="deptId != null  and deptId != ''">and t.dept_id = #{deptId}</if>
            <if test="phoneNumber != null  and phoneNumber != ''">and phone_number = #{phoneNumber}</if>
            <if test="status != null ">and status = #{status}</if>
        </where>
    </select>

</mapper>
