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

    <resultMap id="valveandplotMap" type="com.tofly.xrtygis.entity.Valveandplot">
        <id property="id" column="ID"/>
        <result property="valveId" column="VALVE_ID"/>
        <result property="plotId" column="PLOT_ID"/>
        <result property="createDate" column="CREATE_DATE"/>
        <result property="createUser" column="CREATE_USER"/>
        <association property="plotName" column="PLOT_ID"
                     select="getPlotName"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
    </resultMap>

    <select id="getPlotName" resultType="string">
        select name
        from TF_YWPN_PLOT_W
        where ID = #{id}
          and rownum = 1
    </select>

    <insert id="insertValveAndPlot">
        insert into TF_YWPN_VALVEANDPLOT_W (ID, VALVE_ID, PLOT_ID, CREATE_DATE, CREATE_USER)
        <foreach collection="saveList" item="vap" separator=" union all ">
            select
            #{vap.id},
            #{vap.valveId},
            #{vap.plotId},
            sysdate,
            #{vap.createUser}
            from DUAL
        </foreach>
    </insert>

    <select id="valveIdGetPlot" resultType="map">
        select distinct PLOT_ID, NAME
        from TF_YWPN_VALVEANDPLOT_W v
        left join TF_YWPN_PLOT_W p on v.PLOT_ID = p.ID
        where VALVE_ID in
        <foreach collection="idList" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

</mapper>
