<?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.TPipeMapper">
    
    <resultMap type="TPipe" id="TPipeResult">
        <result property="pipeId"    column="pipe_id"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="pipeName"    column="pipe_name"    />
        <result property="pipeCode"    column="pipe_code"    />
        <result property="pipeAddr"    column="pipe_addr"    />
        <result property="coordinates"    column="coordinates"    />
        <result property="pipeLength"    column="pipe_length"    />
        <result property="pipeType"    column="pipe_type"    />
        <result property="pipePressure"    column="pipe_pressure"    />
        <result property="iconUrl"    column="icon_url"    />
        <result property="installationTime"    column="installation_time"    />
        <result property="inspectionTime"    column="inspection_time"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTPipeVo">
        select pipe_id, enterprise_id, pipe_name, pipe_code, pipe_addr, coordinates, pipe_length, pipe_type, pipe_pressure, icon_url, installation_time, inspection_time, remarks from t_pipe
    </sql>

    <select id="selectTPipeList" parameterType="TPipe" resultMap="TPipeResult">
        <include refid="selectTPipeVo"/>
        <where>  
            <if test="enterpriseId != null and enterpriseId != 0"> and enterprise_id = #{enterpriseId}</if>
            <if test="pipeName != null  and pipeName != ''"> and pipe_name like concat('%', #{pipeName}, '%')</if>
            <if test="pipeCode != null  and pipeCode != ''"> and pipe_code like concat('%', #{pipeCode}, '%')</if>
            <if test="pipeAddr != null  and pipeAddr != ''"> and pipe_addr = #{pipeAddr}</if>
            <if test="coordinates != null  and coordinates != ''"> and coordinates = #{coordinates}</if>
            <if test="pipeType != null  and pipeType != ''"> and pipe_type = #{pipeType}</if>
            <if test="pipePressure != null  and pipePressure != ''"> and pipe_pressure = #{pipePressure}</if>
            <if test="iconUrl != null  and iconUrl != ''"> and icon_url = #{iconUrl}</if>
            <if test="installationTime != null "> and installation_time = #{installationTime}</if>
            <if test="inspectionTime != null "> and inspection_time = #{inspectionTime}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>
    
    <select id="selectTPipeById" parameterType="int" resultMap="TPipeResult">
        <include refid="selectTPipeVo"/>
        where pipe_id = #{pipeId}
    </select>

    <select id="selectTPipeByCode" parameterType="String" resultMap="TPipeResult">
        <include refid="selectTPipeVo"/>
        where pipe_code = #{pipeCode}
    </select>

    <select id="countPipeLength" resultType="double">
        select sum(pipe_length) from t_pipe
    </select>
        
    <insert id="insertTPipe" parameterType="TPipe" useGeneratedKeys="true" keyProperty="pipeId">
        insert into t_pipe
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="enterpriseId != null and enterpriseId != 0">enterprise_id,</if>
            <if test="pipeName != null">pipe_name,</if>
            <if test="pipeCode != null">pipe_code,</if>
            <if test="pipeAddr != null">pipe_addr,</if>
            <if test="coordinates != null">coordinates,</if>
            <if test="pipeLength != null">pipe_length,</if>
            <if test="pipeType != null">pipe_type,</if>
            <if test="pipePressure != null">pipe_pressure,</if>
            <if test="iconUrl != null">icon_url,</if>
            <if test="installationTime != null">installation_time,</if>
            <if test="inspectionTime != null">inspection_time,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="enterpriseId != null and enterpriseId != 0">#{enterpriseId},</if>
            <if test="pipeName != null">#{pipeName},</if>
            <if test="pipeCode != null">#{pipeCode},</if>
            <if test="pipeAddr != null">#{pipeAddr},</if>
            <if test="coordinates != null">#{coordinates},</if>
            <if test="pipeLength != null">#{pipeLength},</if>
            <if test="pipeType != null">#{pipeType},</if>
            <if test="pipePressure != null">#{pipePressure},</if>
            <if test="iconUrl != null">#{iconUrl},</if>
            <if test="installationTime != null">#{installationTime},</if>
            <if test="inspectionTime != null">#{inspectionTime},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTPipe" parameterType="TPipe">
        update t_pipe
        <trim prefix="SET" suffixOverrides=",">
            <if test="enterpriseId != null and enterpriseId != 0">enterprise_id = #{enterpriseId},</if>
            <if test="pipeName != null">pipe_name = #{pipeName},</if>
            <if test="pipeCode != null">pipe_code = #{pipeCode},</if>
            <if test="pipeAddr != null">pipe_addr = #{pipeAddr},</if>
            <if test="coordinates != null">coordinates = #{coordinates},</if>
            <if test="pipeLength != null">pipe_length = #{pipeLength},</if>
            <if test="pipeType != null">pipe_type = #{pipeType},</if>
            <if test="pipePressure != null">pipe_pressure = #{pipePressure},</if>
            <if test="iconUrl != null">icon_url = #{iconUrl},</if>
            <if test="installationTime != null">installation_time = #{installationTime},</if>
            <if test="inspectionTime != null">inspection_time = #{inspectionTime},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where pipe_id = #{pipeId}
    </update>

    <delete id="deleteTPipeById" parameterType="Long">
        delete from t_pipe where pipe_id = #{pipeId}
    </delete>

    <delete id="deleteTPipeByIds" parameterType="String">
        delete from t_pipe where pipe_id in 
        <foreach item="pipeId" collection="array" open="(" separator="," close=")">
            #{pipeId}
        </foreach>
    </delete>
</mapper>