<?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.tofly.xrtygis.mapper.DmaregionupipeMapper">

    <resultMap id="dmaregionupipeMap" type="com.tofly.xrtygis.entity.Dmaregionupipe">
        <id property="id" column="ID"/>
        <result property="dmaId" column="DMA_ID"/>
        <result property="material" column="MATERIAL"/>
        <result property="villageType" column="VILLAGE_TYPE"/>
        <result property="fixYear" column="FIX_YEAR"/>
        <result property="pipeLen" column="PIPE_LEN"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="userPipeLen" column="USER_PIPE_LEN"/>
        <result property="avgPressure" column="AVG_PRESSURE"/>
        <result property="pointNumber" column="POINT_NUMBER"/>
        <result property="otherWater" column="OTHER_WATER"/>
        <result property="materialType" column="MATERIAL_TYPE"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="materialName" column="MATERIAL"
                     select="getMaterialName"/>
    </resultMap>

    <select id="getMaterialName" resultType="java.lang.String">
        SELECT MNAME FROM  TF_YWPN_DMAPIETYPE_W WHERE MID = #{id}
    </select>

    <insert id="insertBatch">
        insert into TF_YWPN_DMAREGIONUPIPE_W(ID,DMA_ID,MATERIAL,FIX_YEAR,PIPE_LEN,CREATE_USER,CREATE_TIME,
                                             VILLAGE_TYPE,USER_PIPE_LEN,AVG_PRESSURE,POINT_NUMBER,OTHER_WATER,MATERIAL_TYPE)
        <foreach collection="pipeList" item="pipe" separator="union all">
            select
            #{pipe.id},
            #{pipe.dmaId},
            #{pipe.material},
            #{pipe.fixYear},
            #{pipe.pipeLen},
            #{pipe.createUser},
            #{pipe.createTime},
            #{pipe.villageType},
            #{pipe.userPipeLen},
            #{pipe.avgPressure},
            #{pipe.pointNumber},
            #{pipe.otherWater},
            #{pipe.materialType}
            from dual
        </foreach>
    </insert>


</mapper>
