<?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.zehong.system.mapper.TTransferPostRecordMapper">
    
    <resultMap type="TTransferPostRecord" id="TTransferPostRecordResult">
        <result property="recordId"    column="record_id"    />
        <result property="applyId"    column="apply_id"    />
        <result property="gruopNum"    column="gruop_num"    />
        <result property="captainId"    column="captain_id"    />
        <result property="transferGroupNum"    column="transfer_group_num"    />
        <result property="transferCaptainId"    column="transfer_captain_id"    />
        <result property="transferStatus"    column="transfer_status"    />
        <result property="suggestion"    column="suggestion"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTTransferPostRecordVo">
        select record_id, apply_id, gruop_num, captain_id, transfer_group_num, transfer_captain_id, transfer_status, suggestion, create_time, update_time, remark from t_transfer_post_record
    </sql>

    <select id="selectTTransferPostRecordList" parameterType="TTransferPostRecord" resultMap="TTransferPostRecordResult">
        <include refid="selectTTransferPostRecordVo"/>
        <where>  
            <if test="applyId != null "> and apply_id = #{applyId}</if>
            <if test="gruopNum != null  and gruopNum != ''"> and gruop_num = #{gruopNum}</if>
            <if test="captainId != null "> and captain_id = #{captainId}</if>
            <if test="transferGroupNum != null  and transferGroupNum != ''"> and transfer_group_num = #{transferGroupNum}</if>
            <if test="transferCaptainId != null "> and transfer_captain_id = #{transferCaptainId}</if>
            <if test="transferStatus != null  and transferStatus != ''"> and transfer_status = #{transferStatus}</if>
            <if test="suggestion != null  and suggestion != ''"> and suggestion = #{suggestion}</if>
        </where>
        ORDER BY create_time DESC
    </select>
    <select id="xiaolist" parameterType="TTransferPostRecord" resultMap="TTransferPostRecordResult">
        SELECT r.*,p.`person_name` AS personName,d1.`dict_label` AS groupName,d2.`dict_label` AS transferGroupName
        FROM t_transfer_post_record r
        LEFT JOIN t_line_patrol_person p ON r.`apply_id` = p.`person_id`
        LEFT JOIN sys_dict_data d1 ON d1.`dict_value` = r.`gruop_num` AND d1.`dict_type`="t_line_patrol_group"
        LEFT JOIN sys_dict_data d2 ON d2.`dict_value` = r.`transfer_group_num` AND d2.`dict_type`="t_line_patrol_group"
        <where>
            <if test="applyId != null "> and r.apply_id = #{applyId}</if>
            <if test="gruopNum !='-1'">
                and (r.gruop_num = #{gruopNum} or r.transfer_group_num =#{gruopNum})
            </if>
            <if test="captainId != null "> and r.captain_id = #{captainId}</if>
            <if test="transferGroupNum != null  and transferGroupNum != ''"> and r.transfer_group_num = #{transferGroupNum}</if>
            <if test="transferCaptainId != null "> and r.transfer_captain_id = #{transferCaptainId}</if>
            <if test="transferStatus ==0"> and r.transfer_status = #{transferStatus}</if>
            <if test="transferStatus ==1"> and r.transfer_status != 0</if>
            <if test="suggestion != null  and suggestion != ''"> and r.suggestion = #{suggestion}</if>
        </where>
        order by r.create_time desc
    </select>
    <select id="selectTTransferPostRecordById" parameterType="Long" resultMap="TTransferPostRecordResult">
        <include refid="selectTTransferPostRecordVo"/>
        where record_id = #{recordId}
    </select>
        
    <insert id="insertTTransferPostRecord" parameterType="TTransferPostRecord" useGeneratedKeys="true" keyProperty="recordId">
        insert into t_transfer_post_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="applyId != null">apply_id,</if>
            <if test="gruopNum != null">gruop_num,</if>
            <if test="captainId != null">captain_id,</if>
            <if test="transferGroupNum != null">transfer_group_num,</if>
            <if test="transferCaptainId != null">transfer_captain_id,</if>
            <if test="transferStatus != null">transfer_status,</if>
            <if test="suggestion != null">suggestion,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="applyId != null">#{applyId},</if>
            <if test="gruopNum != null">#{gruopNum},</if>
            <if test="captainId != null">#{captainId},</if>
            <if test="transferGroupNum != null">#{transferGroupNum},</if>
            <if test="transferCaptainId != null">#{transferCaptainId},</if>
            <if test="transferStatus != null">#{transferStatus},</if>
            <if test="suggestion != null">#{suggestion},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTTransferPostRecord" parameterType="TTransferPostRecord">
        update t_transfer_post_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="applyId != null">apply_id = #{applyId},</if>
            <if test="gruopNum != null">gruop_num = #{gruopNum},</if>
            <if test="captainId != null">captain_id = #{captainId},</if>
            <if test="transferGroupNum != null">transfer_group_num = #{transferGroupNum},</if>
            <if test="transferCaptainId != null">transfer_captain_id = #{transferCaptainId},</if>
            <if test="transferStatus != null">transfer_status = #{transferStatus},</if>
            <if test="suggestion != null">suggestion = #{suggestion},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where record_id = #{recordId}
    </update>

    <delete id="deleteTTransferPostRecordById" parameterType="Long">
        delete from t_transfer_post_record where record_id = #{recordId}
    </delete>

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