<?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.TInspectWorkPointRecordeMapper">
    
    <resultMap type="TInspectWorkPointRecorde" id="TInspectWorkPointRecordeResult">
        <result property="pointId"    column="point_id"    />
        <result property="workId"    column="work_id"    />
        <result property="patrolId"    column="patrol_id"    />
        <result property="patrolName"  column="patrol_name"/>
        <result property="punchPlace"    column="punch_place"    />
        <result property="patrolDetail"    column="patrol_detail"    />
        <result property="punchTime"    column="punch_time"    />
        <result property="pointStatus"    column="point_status"    />
        <result property="feedBook"    column="feed_book"    />
        <result property="isException"    column="is_exception"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTInspectWorkPointRecordeVo">
        select point_id, work_id, patrol_id, punch_place, patrol_detail, punch_time, point_status, feed_book, is_exception, create_by, create_time, update_by, update_time, is_del, remarks from t_inspect_work_point_recorde
    </sql>

    <select id="selectTInspectWorkPointRecordeList" parameterType="TInspectWorkPointRecorde" resultMap="TInspectWorkPointRecordeResult">
        select r.point_id, r.work_id, r.patrol_id, p.position as  punch_place, r.patrol_detail, r.punch_time,
        r.point_status, r.feed_book, r.is_exception, r.create_by, r.create_time, r.update_by,
        r.update_time, r.is_del, r.remarks ,p.patrol_name
        from t_inspect_work_point_recorde r
        LEFT JOIN t_patrol_position p on p.patrol_id = r.patrol_id
        <where>  
            <if test="pointStatus != null  and pointStatus != ''"> and point_status = #{pointStatus}</if>
            <if test="workId != null  and workId != ''"> and work_id = #{workId}</if>
        </where>
        order by punch_time desc
    </select>
    
    <select id="selectTInspectWorkPointRecordeById" parameterType="Long" resultMap="TInspectWorkPointRecordeResult">
        <include refid="selectTInspectWorkPointRecordeVo"/>
        where point_id = #{pointId}
    </select>
        
    <insert id="insertTInspectWorkPointRecorde" parameterType="TInspectWorkPointRecorde" useGeneratedKeys="true" keyProperty="pointId">
        insert into t_inspect_work_point_recorde
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workId != null">work_id,</if>
            <if test="patrolId != null">patrol_id,</if>
            <if test="punchPlace != null">punch_place,</if>
            <if test="patrolDetail != null">patrol_detail,</if>
            <if test="punchTime != null">punch_time,</if>
            <if test="pointStatus != null">point_status,</if>
            <if test="feedBook != null">feed_book,</if>
            <if test="isException != null">is_exception,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</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="workId != null">#{workId},</if>
            <if test="patrolId != null">#{patrolId},</if>
            <if test="punchPlace != null">#{punchPlace},</if>
            <if test="patrolDetail != null">#{patrolDetail},</if>
            <if test="punchTime != null">#{punchTime},</if>
            <if test="pointStatus != null">#{pointStatus},</if>
            <if test="feedBook != null">#{feedBook},</if>
            <if test="isException != null">#{isException},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTInspectWorkPointRecorde" parameterType="TInspectWorkPointRecorde">
        update t_inspect_work_point_recorde
        <trim prefix="SET" suffixOverrides=",">
            <if test="workId != null">work_id = #{workId},</if>
            <if test="patrolId != null">patrol_id = #{patrolId},</if>
            <if test="punchPlace != null">punch_place = #{punchPlace},</if>
            <if test="patrolDetail != null">patrol_detail = #{patrolDetail},</if>
            <if test="punchTime != null">punch_time = #{punchTime},</if>
            <if test="pointStatus != null">point_status = #{pointStatus},</if>
            <if test="feedBook != null">feed_book = #{feedBook},</if>
            <if test="isException != null">is_exception = #{isException},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</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 point_id = #{pointId}
    </update>

    <delete id="deleteTInspectWorkPointRecordeById" parameterType="Long">
        delete from t_inspect_work_point_recorde where point_id = #{pointId}
    </delete>

    <delete id="deleteTInspectWorkPointRecordeByIds" parameterType="String">
        delete from t_inspect_work_point_recorde where point_id in 
        <foreach item="pointId" collection="array" open="(" separator="," close=")">
            #{pointId}
        </foreach>
    </delete>
    <insert id="inserts" parameterType="java.util.List">
        INSERT INTO t_inspect_work_point_recorde (work_id,patrol_id,punch_place,create_by,create_time)
        VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.workId},#{item.patrolId},#{item.punchPlace},#{item.createBy},#{item.createTime})
        </foreach>

    </insert>
</mapper>