<?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.TPatrolPositionMapper">
    
    <resultMap type="TPatrolPosition" id="TPatrolPositionResult">
        <result property="patrolId"    column="patrol_id"    />
        <result property="patrolName"    column="patrol_name"    />
        <result property="patrolType"    column="patrol_type"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="position"    column="position"    />
        <result property="patrolDetail"    column="patrol_detail"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectTPatrolPositionVo">
        select patrol_id, patrol_name, patrol_type, longitude, latitude, position, patrol_detail, dept_id, remarks, create_time, create_by, update_time, update_by, is_del from t_patrol_position
    </sql>

    <select id="selectTPatrolPositionList" parameterType="TPatrolPosition" resultMap="TPatrolPositionResult">
        <include refid="selectTPatrolPositionVo"/>
        <where>  
            <if test="patrolName != null  and patrolName != ''"> and patrol_name like concat('%', #{patrolName}, '%')</if>
            <if test="patrolType != null "> and patrol_type = #{patrolType}</if>
            <if test="longitude != null  and longitude != ''"> and longitude = #{longitude}</if>
            <if test="latitude != null  and latitude != ''"> and latitude = #{latitude}</if>
            <if test="position != null  and position != ''"> and position = #{position}</if>
            <if test="patrolDetail != null  and patrolDetail != ''"> and patrol_detail = #{patrolDetail}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectTPatrolPositionById" parameterType="Long" resultMap="TPatrolPositionResult">
        <include refid="selectTPatrolPositionVo"/>
        where patrol_id = #{patrolId}
    </select>
        
    <insert id="insertTPatrolPosition" parameterType="TPatrolPosition" useGeneratedKeys="true" keyProperty="patrolId">
        insert into t_patrol_position
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="patrolName != null">patrol_name,</if>
            <if test="patrolType != null">patrol_type,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="position != null">position,</if>
            <if test="patrolDetail != null">patrol_detail,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="patrolName != null">#{patrolName},</if>
            <if test="patrolType != null">#{patrolType},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="position != null">#{position},</if>
            <if test="patrolDetail != null">#{patrolDetail},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateTPatrolPosition" parameterType="TPatrolPosition">
        update t_patrol_position
        <trim prefix="SET" suffixOverrides=",">
            <if test="patrolName != null">patrol_name = #{patrolName},</if>
            <if test="patrolType != null">patrol_type = #{patrolType},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="position != null">position = #{position},</if>
            <if test="patrolDetail != null">patrol_detail = #{patrolDetail},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where patrol_id = #{patrolId}
    </update>

    <delete id="deleteTPatrolPositionById" parameterType="Long">
        delete from t_patrol_position where patrol_id = #{patrolId}
    </delete>

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