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

    <resultMap id="rxsmsmessageMap" type="com.tofly.xrtygis.entity.Rxsmsmessage">
        <id property="id" column="ID"/>
        <result property="lsbh" column="LSBH"/>
        <result property="txlx" column="TXLX"/>
        <result property="txnr" column="TXNR"/>
        <result property="fszt" column="FSZT"/>
        <result property="clry" column="CLRY"/>
        <result property="clsj" column="CLSJ"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="createDate" column="CREATE_DATE"/>
        <result property="islock" column="ISLOCK"/>
        <result property="bz" column="BZ"/>
        <result property="mobile" column="MOBILE"/>
        <association property="fsztName" column="FSZT"
                     select="getFsztName"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"></association>
    </resultMap>
    <select id="getFsztName" resultType="string">
        select decode(#{fszt} , '0','待发','1','成功','2','失败')
        from dual
    </select>

    <insert id="insertNoteRecord">
        insert into TF_YWPN_RXSMSMESSAGE_W(ID,LSBH,TXNR,FSZT,CREATE_USER,CREATE_DATE,ISLOCK,BZ,MOBILE)
        <foreach collection="map.entrySet()" index="key" item="value" separator="union all">
            select
            #{key},
            #{msg.lsbh},
            #{msg.txnr},
            #{msg.fszt},
            #{msg.createUser},
            #{msg.createDate},
            #{msg.islock},
            #{msg.bz},
            #{value}
            from dual
        </foreach>
    </insert>
    <insert id="insertMessage">
        insert into TF_YWPN_RXSMSMESSAGE_W(ID,LSBH,TXLX,TXNR,FSZT,CREATE_USER,CREATE_DATE,ISLOCK,MOBILE)
        <foreach collection="list" item="l" separator="union all">
            select
            #{l.id},
            #{l.lsbh},
            #{l.txlx},
            #{l.txnr},
            #{l.fszt},
            #{l.createUser},
            #{l.createDate},
            #{l.islock},
            #{l.mobile}
            from dual
        </foreach>
    </insert>

    <update id="updateMessage">
        <foreach collection="messageList" open="begin" close=";end;" item="msg" separator=";">
            update TF_YWPN_RXSMSMESSAGE_W
            <set>
                BZ = #{msg.bz} ,
                FSZT = #{msg.fszt} ,
                ISLOCK = #{msg.islock}
            </set>
            where ID = #{msg.id}
        </foreach>
    </update>

    <!--查询得到某个表的最大ID-->
    <select id="getMaxId" resultType="long">
        select nvl(max(id), 0) + 1
        from ${tableName}
    </select>
    <select id="getStopWaterInfo" resultType="java.lang.String">
        SELECT TXNR FROM TF_YWPN_RXSMSMESSAGE_W
        WHERE TO_CHAR(CREATE_DATE , 'yyyyMMdd')= #{currentDate} AND MOBILE= #{mobile}
        AND TXLX = '1' AND FSZT = '1'
    </select>

</mapper>
