<?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.TLinePatrolPersonMapper">
    
    <resultMap type="TLinePatrolPerson" id="TLinePatrolPersonResult">
        <result property="personId"    column="person_id"    />
        <result property="personName"    column="person_name"    />
        <result property="phoneNum"    column="phone_num"    />
        <result property="personPost"    column="person_post"    />
        <result property="groupNum"    column="group_num"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="personAccount"    column="person_account"    />
        <result property="personPassword"    column="person_password"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTLinePatrolPersonVo">
        select person_id, person_name, phone_num, person_post, group_num, beyond_enterprise_id, person_account, person_password, create_time, update_time, is_del, remarks from t_line_patrol_person
    </sql>

    <select id="selectTLinePatrolPersonList" parameterType="TLinePatrolPerson" resultMap="TLinePatrolPersonResult">
        <include refid="selectTLinePatrolPersonVo"/>
        <where>  
            <if test="personName != null  and personName != ''"> and person_name like concat('%', #{personName}, '%')</if>
            <if test="phoneNum != null  and phoneNum != ''"> and phone_num = #{phoneNum}</if>
            <if test="personPost != null  and personPost != ''"> and person_post = #{personPost}</if>
            <if test="groupNum != null  and groupNum != ''"> and group_num = #{groupNum}</if>
            <if test="beyondEnterpriseId != null "> and beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="personAccount != null  and personAccount != ''"> and person_account = #{personAccount}</if>
            <if test="personPassword != null  and personPassword != ''"> and person_password = #{personPassword}</if>
            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>
    <select id="appPersonList" parameterType="TLinePatrolPerson" resultMap="TLinePatrolPersonResult">
        SELECT p.*,d.`dict_label` AS groupName
        FROM t_line_patrol_person p
        LEFT JOIN sys_dict_data d ON p.group_num = d.`dict_value` AND d.`dict_type` ='t_line_patrol_group'
        <where>
            <if test="personName != null  and personName != ''"> and p.person_name like concat('%', #{personName}, '%')</if>
            <if test="phoneNum != null  and phoneNum != ''"> and p.phone_num = #{phoneNum}</if>
            <if test="personPost != null  and personPost != ''"> and p.person_post = #{personPost}</if>
            <if test="groupNum != null  and groupNum != ''"> and p.group_num = #{groupNum}</if>
            <if test="beyondEnterpriseId != null "> and p.beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="personAccount != null  and personAccount != ''"> and p.person_account = #{personAccount}</if>
            and p.person_post > 1
        </where>
        order by group_num,person_post

    </select>
    <select id="selectTLinePatrolPersonById" parameterType="Long" resultMap="TLinePatrolPersonResult">
        <include refid="selectTLinePatrolPersonVo"/>
        where person_id = #{personId}
    </select>
        
    <insert id="insertTLinePatrolPerson" parameterType="TLinePatrolPerson" useGeneratedKeys="true" keyProperty="personId">
        insert into t_line_patrol_person
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="personName != null">person_name,</if>
            <if test="phoneNum != null">phone_num,</if>
            <if test="personPost != null">person_post,</if>
            <if test="groupNum != null">group_num,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="personAccount != null">person_account,</if>
            <if test="personPassword != null">person_password,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="personName != null">#{personName},</if>
            <if test="phoneNum != null">#{phoneNum},</if>
            <if test="personPost != null">#{personPost},</if>
            <if test="groupNum != null">#{groupNum},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="personAccount != null">#{personAccount},</if>
            <if test="personPassword != null">#{personPassword},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTLinePatrolPerson" parameterType="TLinePatrolPerson">
        update t_line_patrol_person
        <trim prefix="SET" suffixOverrides=",">
            <if test="personName != null">person_name = #{personName},</if>
            <if test="phoneNum != null">phone_num = #{phoneNum},</if>
            <if test="personPost != null">person_post = #{personPost},</if>
            <if test="groupNum != null">group_num = #{groupNum},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="personAccount != null">person_account = #{personAccount},</if>
            <if test="personPassword != null">person_password = #{personPassword},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where person_id = #{personId}
    </update>

    <delete id="deleteTLinePatrolPersonById" parameterType="Long">
        delete from t_line_patrol_person where person_id = #{personId}
    </delete>

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