<?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.TWorkTaskPatrolCardMapper">
    
    <resultMap type="TWorkTaskPatrolCard" id="TWorkTaskPatrolCardResult">
        <result property="cardId"    column="card_id"    />
        <result property="patrolId"    column="patrol_id"    />
        <result property="memberId"    column="member_id"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="picture"    column="picture"    />
        <result property="video"    column="video"    />
        <result property="cardContent"    column="card_content"    />
        <result property="createTime"    column="create_time"    />
        <result property="isReport"    column="is_report"    />
    </resultMap>

    <sql id="selectTWorkTaskPatrolCardVo">
        select card_id, patrol_id, member_id, longitude, latitude, picture,video, card_content, create_time, is_report from t_work_task_patrol_card
    </sql>

    <select id="selectTWorkTaskPatrolCardList" parameterType="TWorkTaskPatrolCard" resultMap="TWorkTaskPatrolCardResult">
        <include refid="selectTWorkTaskPatrolCardVo"/>
        <where>  
            <if test="patrolId != null "> and patrol_id = #{patrolId}</if>
            <if test="memberId != null "> and member_id = #{memberId}</if>
            <if test="longitude != null  and longitude != ''"> and longitude = #{longitude}</if>
            <if test="latitude != null  and latitude != ''"> and latitude = #{latitude}</if>
            <if test="picture != null  and picture != ''"> and picture = #{picture}</if>
            <if test="cardContent != null  and cardContent != ''"> and card_content = #{cardContent}</if>
            <if test="isReport != null "> and is_report = #{isReport}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectTWorkTaskPatrolCardById" parameterType="Long" resultMap="TWorkTaskPatrolCardResult">
        <include refid="selectTWorkTaskPatrolCardVo"/>
        where card_id = #{cardId}
    </select>
        
    <insert id="insertTWorkTaskPatrolCard" parameterType="TWorkTaskPatrolCard" useGeneratedKeys="true" keyProperty="cardId">
        insert into t_work_task_patrol_card
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="patrolId != null">patrol_id,</if>
            <if test="memberId != null">member_id,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="picture != null">picture,</if>
            <if test="video != null">video,</if>
            <if test="cardContent != null">card_content,</if>
            <if test="createTime != null">create_time,</if>
            <if test="isReport != null">is_report,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="patrolId != null">#{patrolId},</if>
            <if test="memberId != null">#{memberId},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="picture != null">#{picture},</if>
            <if test="video != null">#{video},</if>
            <if test="cardContent != null">#{cardContent},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="isReport != null">#{isReport},</if>
         </trim>
    </insert>

    <update id="updateTWorkTaskPatrolCard" parameterType="TWorkTaskPatrolCard">
        update t_work_task_patrol_card
        <trim prefix="SET" suffixOverrides=",">
            <if test="patrolId != null">patrol_id = #{patrolId},</if>
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="picture != null">picture = #{picture},</if>
            <if test="video != null">video = #{video},</if>
            <if test="cardContent != null">card_content = #{cardContent},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="isReport != null">is_report = #{isReport},</if>
        </trim>
        where card_id = #{cardId}
    </update>

    <delete id="deleteTWorkTaskPatrolCardById" parameterType="Long">
        delete from t_work_task_patrol_card where card_id = #{cardId}
    </delete>

    <delete id="deleteTWorkTaskPatrolCardByIds" parameterType="String">
        delete from t_work_task_patrol_card where card_id in 
        <foreach item="cardId" collection="array" open="(" separator="," close=")">
            #{cardId}
        </foreach>
    </delete>
</mapper>