<?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.xrtymis.mapper.FileMapper">

  <resultMap id="fileMap" type="com.tofly.xrtymis.entity.File">
                <id property="id" column="ID"/>
                                                                                                                                        <result property="tableName" column="TABLE_NAME"/>
                      <result property="tableId" column="TABLE_ID"/>
                      <result property="filePath" column="FILE_PATH"/>
                      <result property="statusFlag" column="STATUS_FLAG"/>
                      <result property="fileName" column="FILE_NAME"/>
                      <result property="otherName" column="OTHER_NAME"/>
                      <result property="fileFormat" column="FILE_FORMAT"/>
                      <result property="fileSize" column="FILE_SIZE"/>
                      <result property="createTime" column="CREATE_TIME"/>
                      <result property="createUser" column="CREATE_USER"/>
      <association property="createUserName" column="CREATE_USER" select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
  </resultMap>

    <select id="getFileByIds" resultType="string">
        select FILE_PATH from TF_YWPN_FILE_W where ID in
        <if test="fileIds != null and fileIds != '' ">
            <foreach collection="fileIds.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>

    <select id="getTempMaxId" parameterType="java.lang.String" resultType="java.lang.Long">
        select nvl(max(id), 0) + 1
        from ${tableName}
    </select>

    <insert id="addMessageList" parameterType="java.util.List">
        INSERT ALL
        <foreach item="item" index="index" collection="list">
            INTO TF_XRTY_NEW_UDB.TF_YWPN_MESSAGEPUSH_W
            (
            ID,
            TOPIC,
            MESSAGE,
            TYPE,
            TABLE_NAME,
            ROUTE_IP,
            CREATE_TIME,
            CREATE_USER,
            ROUTE_IP_APP
            ) VALUES
            (
            #{item.id},
            #{item.topic},
            #{item.message},
            #{item.type},
            #{item.tableName},
            #{item.routeIp},
            #{item.createTime},
            #{item.createUser},
            #{item.routeIpApp}
            )
        </foreach>
        SELECT 1 FROM DUAL
    </insert>

    <insert id="addMessageRecipientList" parameterType="java.util.List">
        INSERT ALL
        <foreach item="item" index="index" collection="list">
            INTO TF_XRTY_NEW_UDB.TF_YWPN_MESSAGERECIPIENT_W
            (
            ID,
            MESSAGE_ID,
            RECIPIENT,
            FLAG
            ) VALUES
            (
            #{item.id},
            #{item.messageId},
            #{item.recipient},
            #{item.flag}
            )
        </foreach>
        SELECT 1 FROM DUAL
    </insert>
</mapper>
