<?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.TLinePatrolMapper">

    <resultMap type="com.zehong.system.domain.TLinePatrol" id="TLinePatrolResult">
        <result property="id"    column="id"    />
        <result property="taskName"    column="task_name"    />
        <result property="linePatrolPerson"    column="line_patrol_person"    />
        <result property="linePatrolTime"    column="line_patrol_time"    />
        <result property="coordinates"    column="coordinates"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="beyondEnterpriseName"    column="beyond_enterprise_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTLinePatrolVo">
        select id, task_name, line_patrol_person, line_patrol_time, coordinates, beyond_enterprise_id, beyond_enterprise_name, create_time, remark from t_line_patrol
    </sql>

    <select id="selectTLinePatrolList" parameterType="com.zehong.system.domain.TLinePatrol" resultMap="TLinePatrolResult">
        <include refid="selectTLinePatrolVo"/>
        <where>
            <if test="id != null "> and id = #{id}</if>
            <if test="taskName != null  and taskName != ''"> and task_name like concat('%', #{taskName}, '%')</if>
            <if test="linePatrolPerson != null  and linePatrolPerson != ''"> and line_patrol_person = #{linePatrolPerson}</if>
            <if test="linePatrolTime != null  and linePatrolTime != ''"> and line_patrol_time = #{linePatrolTime}</if>
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != ''"> and beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="beyondEnterpriseName != null  and beyondEnterpriseName != ''"> and beyond_enterprise_name like concat('%', #{beyondEnterpriseName}, '%')</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
        </where>
    </select>

    <select id="selectTLinePatrolById" parameterType="Long" resultMap="TLinePatrolResult">
        <include refid="selectTLinePatrolVo"/>
        where id = #{id}
    </select>

    <insert id="insertTLinePatrol" parameterType="com.zehong.system.domain.TLinePatrol" useGeneratedKeys="true" keyProperty="id">
        insert into t_line_patrol
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskName != null">task_name,</if>
            <if test="linePatrolPerson != null">line_patrol_person,</if>
            <if test="linePatrolTime != null">line_patrol_time,</if>
            <if test="coordinates != null">coordinates,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskName != null">#{taskName},</if>
            <if test="linePatrolPerson != null">#{linePatrolPerson},</if>
            <if test="linePatrolTime != null">#{linePatrolTime},</if>
            <if test="coordinates != null">#{coordinates},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">#{beyondEnterpriseName},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateTLinePatrol" parameterType="com.zehong.system.domain.TLinePatrol">
        update t_line_patrol
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskName != null">task_name = #{taskName},</if>
            <if test="linePatrolPerson != null">line_patrol_person = #{linePatrolPerson},</if>
            <if test="linePatrolTime != null">line_patrol_time = #{linePatrolTime},</if>
            <if test="coordinates != null">coordinates = #{coordinates},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name = #{beyondEnterpriseName},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTLinePatrolById" parameterType="Long">
        delete from t_line_patrol where id = #{id}
    </delete>

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

    <insert id="insertBatch" parameterType="list">
        insert into t_line_patrol (task_name, line_patrol_person, line_patrol_time, coordinates, beyond_enterprise_id, beyond_enterprise_name, create_time, remark)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.taskName,jdbcType=VARCHAR}, #{item.linePatrolPerson}, #{item.linePatrolTime},
            #{item.coordinates},#{item.beyondEnterpriseId},#{item.beyondEnterpriseName},#{item.createTime},#{item.remark}
            )
        </foreach>
    </insert>
</mapper>