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

    <resultMap type="TPipeInfo" id="TPipeInfoResult">
        <result property="pipeId"    column="pipe_id"    />
        <result property="pipeLength"    column="pipe_length"    />
        <result property="pipeDiameter"    column="pipe_diameter"    />
        <result property="pipePressure"    column="pipe_pressure"    />
        <result property="pipeMaterial"    column="pipe_material"    />
        <result property="pipeAddr"    column="pipe_addr"    />
        <result property="buriedDepth"    column="buried_depth"    />
        <result property="pipeTrend"    column="pipe_trend"    />
        <result property="buildDate"    column="build_date"    />
        <result property="buildUnit"    column="build_unit"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="beyondEnterpriseName"    column="beyond_enterprise_name"    />
        <result property="coordinates"    column="coordinates"    />
        <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="selectTPipeInfoVo">
        select pipe_id,pipe_length, pipe_diameter, pipe_pressure, pipe_material, pipe_addr, buried_depth, pipe_trend, build_date, build_unit, beyond_enterprise_id, beyond_enterprise_name, coordinates, create_by, create_time, update_by, update_time, is_del, remarks from t_pipe_info
    </sql>

    <select id="selectTPipeInfoList" parameterType="TPipeInfo" resultMap="TPipeInfoResult">
        <include refid="selectTPipeInfoVo"/>
        <where>
            is_del='0'
            <if test="pipeLength != null "> and pipe_length = #{pipeLength}</if>
            <if test="pipeDiameter != null "> and pipe_diameter = #{pipeDiameter}</if>
            <if test="pipePressure != null "> and pipe_pressure = #{pipePressure}</if>
            <if test="pipeMaterial != null  and pipeMaterial != ''"> and pipe_material = #{pipeMaterial}</if>
            <if test="pipeAddr != null  and pipeAddr != ''"> and pipe_addr = #{pipeAddr}</if>
            <if test="buriedDepth != null "> and buried_depth = #{buriedDepth}</if>
            <if test="pipeTrend != null  and pipeTrend != ''"> and pipe_trend = #{pipeTrend}</if>
            <if test="buildDate != null  and buildDate != ''"> and build_date = #{buildDate}</if>
            <if test="buildUnit != null  and buildUnit != ''"> and build_unit = #{buildUnit}</if>
            <if test="beyondEnterpriseId != null "> and beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="beyondEnterpriseName != null  and beyondEnterpriseName != ''"> and beyond_enterprise_name like concat('%', #{beyondEnterpriseName}, '%')</if>
            <if test="coordinates != null  and coordinates != ''"> and coordinates = #{coordinates}</if>
            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
        group by pipe_id desc
    </select>

    <select id="selectTPipeInfoById" parameterType="Long" resultMap="TPipeInfoResult">
        <include refid="selectTPipeInfoVo"/>
        where pipe_id = #{pipeId} and is_del='0'
    </select>

    <insert id="insertTPipeInfo" parameterType="TPipeInfo" useGeneratedKeys="true" keyProperty="pipeId">
        insert into t_pipe_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pipeLength != null">pipe_length,</if>
            <if test="pipeDiameter != null">pipe_diameter,</if>
            <if test="pipePressure != null">pipe_pressure,</if>
            <if test="pipeMaterial != null">pipe_material,</if>
            <if test="pipeAddr != null">pipe_addr,</if>
            <if test="buriedDepth != null">buried_depth,</if>
            <if test="pipeTrend != null">pipe_trend,</if>
            <if test="buildDate != null">build_date,</if>
            <if test="buildUnit != null">build_unit,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name,</if>
            <if test="coordinates != null">coordinates,</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="pipeLength != null">#{pipeLength},</if>
            <if test="pipeDiameter != null">#{pipeDiameter},</if>
            <if test="pipePressure != null">#{pipePressure},</if>
            <if test="pipeMaterial != null">#{pipeMaterial},</if>
            <if test="pipeAddr != null">#{pipeAddr},</if>
            <if test="buriedDepth != null">#{buriedDepth},</if>
            <if test="pipeTrend != null">#{pipeTrend},</if>
            <if test="buildDate != null">#{buildDate},</if>
            <if test="buildUnit != null">#{buildUnit},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">#{beyondEnterpriseName},</if>
            <if test="coordinates != null">#{coordinates},</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="updateTPipeInfo" parameterType="TPipeInfo">
        update t_pipe_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="pipeLength != null">pipe_length = #{pipeLength},</if>
            <if test="pipeDiameter != null">pipe_diameter = #{pipeDiameter},</if>
            <if test="pipePressure != null">pipe_pressure = #{pipePressure},</if>
            <if test="pipeMaterial != null">pipe_material = #{pipeMaterial},</if>
            <if test="pipeAddr != null">pipe_addr = #{pipeAddr},</if>
            <if test="buriedDepth != null">buried_depth = #{buriedDepth},</if>
            <if test="pipeTrend != null">pipe_trend = #{pipeTrend},</if>
            <if test="buildDate != null">build_date = #{buildDate},</if>
            <if test="buildUnit != null">build_unit = #{buildUnit},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name = #{beyondEnterpriseName},</if>
            <if test="coordinates != null">coordinates = #{coordinates},</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 pipe_id = #{pipeId}
    </update>

    <update id="deleteTPipeInfoById" parameterType="Long">
        update  t_pipe_info  set is_del='1' where pipe_id = #{pipeId}
    </update>

    <update id="deleteTPipeInfoByIds" parameterType="String">
        update  t_pipe_info set is_del='1'  where pipe_id in
        <foreach item="pipeId" collection="array" open="(" separator="," close=")">
            #{pipeId}
        </foreach>
    </update>
</mapper>