<?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.huashe.park.core.mapper.ConsPileHoleInfoMapper">
    
    <resultMap type="ConsPileHoleInfo" id="ConsPileHoleInfoResult">
        <result property="id"    column="id"    />
        <result property="holeNum"    column="hole_num"    />
        <result property="deltaX"    column="delta_x"    />
        <result property="deltaY"    column="delta_y"    />
        <result property="lng"    column="lng"    />
        <result property="lat"    column="lat"    />
        <result property="consStatus"    column="cons_status"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="desDept"    column="des_dept"    />
        <result property="diameter"    column="diameter"    />
        <result property="consUnitId" column="cons_unit_id"/>
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectConsPileHoleInfoVo">
        select id,
               hole_num,
               delta_x,
               delta_y,
               lng,
               lat,
               cons_status,
               start_time,
               end_time,
               des_dept,
               diameter,
               cons_unit_id,
               update_time,
               create_time,
               create_by,
               update_by
        from cons_pile_hole_info
    </sql>

    <select id="selectConsPileHoleInfoList" parameterType="ConsPileHoleInfo" resultMap="ConsPileHoleInfoResult">
        <include refid="selectConsPileHoleInfoVo"/>
        <where>  
            <if test="holeNum != null  and holeNum != ''"> and hole_num = #{holeNum}</if>
            <if test="consStatus != null  and consStatus != ''"> and cons_status = #{consStatus}</if>
        </where>
    </select>
    
    <select id="selectConsPileHoleInfoById" parameterType="Long" resultMap="ConsPileHoleInfoResult">
        <include refid="selectConsPileHoleInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertConsPileHoleInfo" parameterType="ConsPileHoleInfo" useGeneratedKeys="true" keyProperty="id">
        insert into cons_pile_hole_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="holeNum != null and holeNum != ''">hole_num,</if>
            <if test="deltaX != null">delta_x,</if>
            <if test="deltaY != null">delta_y,</if>
            <if test="lng != null">lng,</if>
            <if test="lat != null">lat,</if>
            <if test="consStatus != null">cons_status,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="desDept != null">des_dept,</if>
            <if test="diameter != null">diameter,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="holeNum != null and holeNum != ''">#{holeNum},</if>
            <if test="deltaX != null">#{deltaX},</if>
            <if test="deltaY != null">#{deltaY},</if>
            <if test="lng != null">#{lng},</if>
            <if test="lat != null">#{lat},</if>
            <if test="consStatus != null">#{consStatus},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="desDept != null">#{desDept},</if>
            <if test="diameter != null">#{diameter},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>
    <insert id="batchInsertConsPileHoleInfo" parameterType="List" useGeneratedKeys="true" keyProperty="id">
        insert into cons_pile_hole_info
        (
        hole_num,
        delta_x,
        delta_y,
        lng,
        lat,
        cons_status,
        start_time,
        end_time,
        des_dept,
        diameter,
        cons_unit_id,
        update_time,
        create_time
        )
        values
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item.holeNum},
            #{item.deltaX},
            #{item.deltaY},
            #{item.lng},
            #{item.lat},
            #{item.consStatus},
            #{item.startTime},
            #{item.endTime},
            #{item.desDept},
            #{item.diameter},
            #{item.consUnitId},
            now(),
            now()
        </foreach>
        on duplicate key update
        delta_x= values(delta_x),
        delta_y= values(delta_y),
        lng= values(lng),
        lat= values(lat),
        des_dept= values(des_dept),
        diameter= values(diameter),
        update_time = now()
    </insert>
    <update id="updateConsPileHoleInfo" parameterType="ConsPileHoleInfo">
        update cons_pile_hole_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="holeNum != null and holeNum != ''">hole_num = #{holeNum},</if>
            <if test="deltaX != null">delta_x = #{deltaX},</if>
            <if test="deltaY != null">delta_y = #{deltaY},</if>
            <if test="lng != null">lng = #{lng},</if>
            <if test="lat != null">lat = #{lat},</if>
            <if test="consStatus != null">cons_status = #{consStatus},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="desDept != null">des_dept = #{desDept},</if>
            <if test="diameter != null">diameter = #{diameter},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteConsPileHoleInfoById" parameterType="Long">
        delete from cons_pile_hole_info where id = #{id}
    </delete>

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

    <delete id="deleteConsPileHoleInfoByConsUnitId" parameterType="Long">
        delete
        from cons_pile_hole_info
        where cons_unit_id = #{consUnitId}
          and cons_status != '00'
    </delete>
</mapper>