<?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.QgzxPostMapper">
    
    <resultMap type="QgzxPost" id="QgzxPostResult">
        <result property="id"    column="id"    />
        <result property="postName"    column="post_name"    />
        <result property="deptCode"    column="dept_code"    />
        <result property="postCount"    column="post_count"    />
        <result property="fzrName"    column="fzr_name"    />
        <result property="fzrNo"    column="fzr_no"    />
        <result property="zdlsName"    column="zdls_name"    />
        <result property="zdlsNo"    column="zdls_no"    />
        <result property="zdlsPhone"    column="zdls_phone"    />
        <result property="willMoney"    column="will_money"    />
        <result property="willMoneyTotal"    column="will_money_total"    />
        <result property="workNeed"    column="work_need"    />
        <result property="skillNeed"    column="skill_need"    />
        <result property="weekTime"    column="week_time"    />
        <result property="campusName"    column="campus_name"    />
        <result property="workAddr"    column="work_addr"    />
        <result property="postType"    column="post_type"    />
        <result property="remark"    column="remark"    />
        <result property="applyNo"    column="apply_no"    />
        <result property="applyStatus"    column="apply_status"    />
        <result property="applyTime"    column="apply_time"    />
        <result property="applyReason"    column="apply_reason"    />
        <result property="deptCmt"    column="dept_cmt"    />
        <result property="deptSign"    column="dept_sign"    />
        <result property="highCmt"    column="high_cmt"    />
        <result property="highSign"    column="high_sign"    />
        <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="deptNo"    column="dept_no"    />
        <result property="highNo"    column="high_no"    />
        <result property="returnMsg" column="return_msg"/>
    </resultMap>

    <sql id="selectQgzxPostVo">
        select id,
               return_msg,
               post_name,
               dept_no,
               high_no,
               dept_code,
               post_count,
               fzr_name,
               fzr_no,
               zdls_name,
               zdls_no,
               zdls_phone,
               will_money,
               will_money_total,
               work_need,
               skill_need,
               week_time,
               campus_name,
               work_addr,
               post_type,
               remark,
               apply_no,
               apply_status,
               apply_time,
               apply_reason,
               dept_cmt,
               dept_sign,
               high_cmt,
               high_sign,
               create_by,
               create_time,
               update_by,
               update_time,
               del_flag,
               status
        from qgzx_post
    </sql>

    <select id="selectQgzxPostList" parameterType="QgzxPost" resultMap="QgzxPostResult">
        <include refid="selectQgzxPostVo"/>
        <where>  
            <if test="postName != null  and postName != ''"> and post_name like concat('%', #{postName}, '%')</if>
            <if test="deptCode != null  and deptCode != ''"> and dept_code = #{deptCode}</if>
            <if test="postCount != null  and postCount != ''"> and post_count = #{postCount}</if>
            <if test="fzrName != null  and fzrName != ''"> and fzr_name like concat('%', #{fzrName}, '%')</if>
            <if test="fzrNo != null  and fzrNo != ''"> and fzr_no = #{fzrNo}</if>
            <if test="zdlsName != null  and zdlsName != ''"> and zdls_name like concat('%', #{zdlsName}, '%')</if>
            <if test="zdlsNo != null  and zdlsNo != ''"> and zdls_no = #{zdlsNo}</if>
            <if test="zdlsPhone != null  and zdlsPhone != ''"> and zdls_phone = #{zdlsPhone}</if>
            <if test="willMoney != null "> and will_money = #{willMoney}</if>
            <if test="willMoneyTotal != null "> and will_money_total = #{willMoneyTotal}</if>
            <if test="workNeed != null  and workNeed != ''"> and work_need = #{workNeed}</if>
            <if test="skillNeed != null  and skillNeed != ''"> and skill_need = #{skillNeed}</if>
            <if test="weekTime != null "> and week_time = #{weekTime}</if>
            <if test="campusName != null  and campusName != ''"> and campus_name like concat('%', #{campusName}, '%')</if>
            <if test="workAddr != null  and workAddr != ''"> and work_addr = #{workAddr}</if>
            <if test="postType != null  and postType != ''"> and post_type = #{postType}</if>
            <if test="applyNo != null  and applyNo != ''"> and apply_no = #{applyNo}</if>
            <if test="applyStatus != null  and applyStatus != ''"> and apply_status = #{applyStatus}</if>
            <if test="applyTime != null "> and apply_time = #{applyTime}</if>
            <if test="applyReason != null  and applyReason != ''"> and apply_reason = #{applyReason}</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="highCmt != null  and highCmt != ''"> and high_cmt = #{highCmt}</if>
            <if test="highSign != null  and highSign != ''"> and high_sign = #{highSign}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="deptNo != null  and deptNo != ''"> and dept_no = #{deptNo}</if>
            <if test="highNo != null  and highNo != ''"> and high_no = #{highNo}</if>
        </where>
    </select>
    
    <select id="selectQgzxPostById" parameterType="Long" resultMap="QgzxPostResult">
        <include refid="selectQgzxPostVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertQgzxPost" parameterType="QgzxPost" useGeneratedKeys="true" keyProperty="id">
        insert into qgzx_post
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="postName != null">post_name,</if>
            <if test="deptCode != null">dept_code,</if>
            <if test="postCount != null">post_count,</if>
            <if test="fzrName != null">fzr_name,</if>
            <if test="fzrNo != null">fzr_no,</if>
            <if test="zdlsName != null">zdls_name,</if>
            <if test="zdlsNo != null">zdls_no,</if>
            <if test="zdlsPhone != null">zdls_phone,</if>
            <if test="willMoney != null">will_money,</if>
            <if test="willMoneyTotal != null">will_money_total,</if>
            <if test="workNeed != null">work_need,</if>
            <if test="skillNeed != null">skill_need,</if>
            <if test="weekTime != null">week_time,</if>
            <if test="campusName != null">campus_name,</if>
            <if test="workAddr != null">work_addr,</if>
            <if test="postType != null">post_type,</if>
            <if test="remark != null">remark,</if>
            <if test="applyNo != null">apply_no,</if>
            <if test="applyStatus != null">apply_status,</if>
            <if test="applyTime != null">apply_time,</if>
            <if test="applyReason != null">apply_reason,</if>
            <if test="deptCmt != null">dept_cmt,</if>
            <if test="deptSign != null">dept_sign,</if>
            <if test="highCmt != null">high_cmt,</if>
            <if test="highSign != null">high_sign,</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="deptNo != null">dept_no,</if>
            <if test="highNo != null">high_no,</if>
            <if test="returnMsg != null">return_msg,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="postName != null">#{postName},</if>
            <if test="deptCode != null">#{deptCode},</if>
            <if test="postCount != null">#{postCount},</if>
            <if test="fzrName != null">#{fzrName},</if>
            <if test="fzrNo != null">#{fzrNo},</if>
            <if test="zdlsName != null">#{zdlsName},</if>
            <if test="zdlsNo != null">#{zdlsNo},</if>
            <if test="zdlsPhone != null">#{zdlsPhone},</if>
            <if test="willMoney != null">#{willMoney},</if>
            <if test="willMoneyTotal != null">#{willMoneyTotal},</if>
            <if test="workNeed != null">#{workNeed},</if>
            <if test="skillNeed != null">#{skillNeed},</if>
            <if test="weekTime != null">#{weekTime},</if>
            <if test="campusName != null">#{campusName},</if>
            <if test="workAddr != null">#{workAddr},</if>
            <if test="postType != null">#{postType},</if>
            <if test="remark != null">#{remark},</if>
            <if test="applyNo != null">#{applyNo},</if>
            <if test="applyStatus != null">#{applyStatus},</if>
            <if test="applyTime != null">#{applyTime},</if>
            <if test="applyReason != null">#{applyReason},</if>
            <if test="deptCmt != null">#{deptCmt},</if>
            <if test="deptSign != null">#{deptSign},</if>
            <if test="highCmt != null">#{highCmt},</if>
            <if test="highSign != null">#{highSign},</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="deptNo != null">#{deptNo},</if>
            <if test="highNo != null">#{highNo},</if>
            <if test="returnMsg != null">#{returnMsg},</if>
         </trim>
    </insert>

    <update id="updateQgzxPost" parameterType="QgzxPost">
        update qgzx_post
        <trim prefix="SET" suffixOverrides=",">
            <if test="postName != null">post_name = #{postName},</if>
            <if test="deptCode != null">dept_code = #{deptCode},</if>
            <if test="postCount != null">post_count = #{postCount},</if>
            <if test="fzrName != null">fzr_name = #{fzrName},</if>
            <if test="fzrNo != null">fzr_no = #{fzrNo},</if>
            <if test="zdlsName != null">zdls_name = #{zdlsName},</if>
            <if test="zdlsNo != null">zdls_no = #{zdlsNo},</if>
            <if test="zdlsPhone != null">zdls_phone = #{zdlsPhone},</if>
            <if test="willMoney != null">will_money = #{willMoney},</if>
            <if test="willMoneyTotal != null">will_money_total = #{willMoneyTotal},</if>
            <if test="workNeed != null">work_need = #{workNeed},</if>
            <if test="skillNeed != null">skill_need = #{skillNeed},</if>
            <if test="weekTime != null">week_time = #{weekTime},</if>
            <if test="campusName != null">campus_name = #{campusName},</if>
            <if test="workAddr != null">work_addr = #{workAddr},</if>
            <if test="postType != null">post_type = #{postType},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="applyNo != null">apply_no = #{applyNo},</if>
            <if test="applyStatus != null">apply_status = #{applyStatus},</if>
            <if test="applyTime != null">apply_time = #{applyTime},</if>
            <if test="applyReason != null">apply_reason = #{applyReason},</if>
            <if test="deptCmt != null">dept_cmt = #{deptCmt},</if>
            <if test="deptSign != null">dept_sign = #{deptSign},</if>
            <if test="highCmt != null">high_cmt = #{highCmt},</if>
            <if test="highSign != null">high_sign = #{highSign},</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="deptNo != null">dept_no = #{deptNo},</if>
            <if test="highNo != null">high_no = #{highNo},</if>
            <if test="returnMsg != null">return_msg = #{returnMsg},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQgzxPostById" parameterType="Long">
        delete from qgzx_post where id = #{id}
    </delete>

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

    <select id="listView" parameterType="QgzxPost" resultType="QgzxPost">
        select a.*,b.dept_id,b.dept_name,c.name as dept_no_name,d.name as high_no_name,
        (
        select count(aa.id) from qgzx_stu_post as aa where aa.post_id = a.id and aa.work_status = '是'
        ) as work_stus,
        case a.apply_status
        when 0
        then "保存"
        when 1
        then "已提交待审核"
        when 2
        then "部门审核通过"
        when 3
        then "资助办审核通过"
        when 6
        then "学工审核通过"
        when 10
        then "拒绝"
        when 11
        then "驳回"
        when 14
        then "已重新提交"
        else "无" end as apply_status_ex
        from qgzx_post as a
        left join sys_dept as b on a.dept_code = b.dept_code
        left join qgzx_teacher as c on a.dept_no = c.employee_id
        left join qgzx_teacher as d on a.high_no = d.employee_id
        <where>
            <if test="postName != null  and postName != ''"> and post_name like concat('%', #{postName}, '%')</if>
            <if test="deptCode != null  and deptCode != ''"> and a.dept_code = #{deptCode}</if>
            <if test="deptName != null  and deptName != ''"> and b.dept_name like concat('%',#{deptName},'%')</if>
            <if test="deptId != null  and deptId != ''"> and b.dept_id = #{deptId}</if>
            <if test="postCount != null  and postCount != ''"> and post_count = #{postCount}</if>
            <if test="fzrName != null  and fzrName != ''"> and fzr_name like concat('%', #{fzrName}, '%')</if>
            <if test="fzrNo != null  and fzrNo != ''"> and fzr_no = #{fzrNo}</if>
            <if test="zdlsName != null  and zdlsName != ''"> and zdls_name like concat('%', #{zdlsName}, '%')</if>
            <if test="zdlsNo != null  and zdlsNo != ''"> and zdls_no = #{zdlsNo}</if>
            <if test="zdlsPhone != null  and zdlsPhone != ''"> and zdls_phone = #{zdlsPhone}</if>
            <if test="willMoney != null "> and will_money = #{willMoney}</if>
            <if test="willMoneyTotal != null "> and will_money_total = #{willMoneyTotal}</if>
            <if test="workNeed != null  and workNeed != ''"> and work_need = #{workNeed}</if>
            <if test="campusName != null  and campusName != ''"> and campus_name like concat('%', #{campusName}, '%')</if>
            <if test="workAddr != null  and workAddr != ''"> and work_addr like concat('%', #{workAddr}, '%')</if>
            <if test="postType != null  and postType != ''"> and post_type = #{postType}</if>
            <if test="applyNo != null  and applyNo != ''"> and apply_no = #{applyNo}</if>
            <if test="applyStatus != null  and applyStatus != ''"> and apply_status = #{applyStatus}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="applyTime != null"> and apply_time like concat( date_format(#{applyTime}, '%Y-%m-%d'),'%')</if>
        </where>
        order by a.id desc
    </select>
</mapper>