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

    <resultMap id="dmaregionuserMap" type="com.tofly.xrtygis.entity.Dmaregionuser">
        <id property="id" column="ID"/>
        <result property="dmaId" column="DMA_ID"/>
        <result property="villageType" column="VILLAGE_TYPE"/>
        <result property="userNum" column="USER_NUM"/>
        <result property="avgFlow" column="AVG_FLOW"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="createTime" column="CREATE_TIME"/>
        <association property="typeName" column="VILLAGE_TYPE" select="getTypeName"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"></association>
    </resultMap>

    <select id="getTypeName" resultType="string">
        select decode(#{type}, '1', '高档小区', '2', '中档小区', '3', '拆迁安置')
        from dual
    </select>

    <insert id="insertBatch">
        insert into TF_YWPN_DMAREGIONUSER_W(ID,DMA_ID,VILLAGE_TYPE,USER_NUM,AVG_FLOW,CREATE_USER,CREATE_TIME)
        <foreach collection="userList" item="user" separator="union all">
            select
            #{user.id},
            #{user.dmaId},
            #{user.villageType},
            #{user.userNum},
            #{user.avgFlow},
            #{user.createUser},
            #{user.createTime}
            from dual
        </foreach>
    </insert>


</mapper>
