<?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.simuwang.base.mapper.NavMapper">
    <resultMap id="BaseResultMap" type="com.simuwang.base.pojo.dos.NavDO">
        <id column="id" property="id"/>
        <result column="fund_id" property="fundId"/>
        <result column="price_date" property="priceDate"/>
        <result column="nav" property="nav"/>
        <result column="cumulative_nav" property="cumulativeNav"/>
        <result column="cumulative_nav_withdrawal" property="cumulativeNavWithdrawal"/>
        <result column="isvalid" property="isvalid"/>
        <result column="creatorid" property="creatorId"/>
        <result column="createtime" property="createTime"/>
        <result column="updaterid" property="updaterId"/>
        <result column="updatetime" property="updateTime"/>
    </resultMap>

    <insert id="batchInsert" parameterType="com.simuwang.base.pojo.dos.NavDO">
        insert into PPW_EMAIL.nav(fund_id,price_date,nav,cumulative_nav,cumulative_nav_withdrawal,
                                  isvalid, creatorid, createtime, updaterid, updatetime)
        values
        <foreach collection="itemDoList" item="itemDo" index="index" separator=",">
            (#{itemDo.fundId},#{itemDo.priceDate},#{itemDo.nav},#{itemDo.cumulativeNav},#{itemDo.cumulativeNavWithdrawal},
            #{itemDo.isvalid}, #{itemDo.creatorId}, #{itemDo.createTime}, #{itemDo.updaterId}, #{itemDo.updateTime})
        </foreach>

    </insert>

    <insert id="batchUpdate">
        <foreach collection="itemDoList" item="itemDo" index="index" open="" close="" separator=";">
            update PPW_EMAIL.nav
            <set>
                nav = #{itemDo.nav},
                cumulative_nav_withdrawal = #{itemDo.cumulativeNavWithdrawal},
                updatetime=#{itemDo.updateTime}
            </set>
            where isvalid = 1
            and fund_id = #{itemDo.fundId}
            and price_date = #{itemDo.priceDate}
        </foreach>
    </insert>
    <insert id="saveNav" parameterType="com.simuwang.base.pojo.dos.NavDO">
        insert into PPW_EMAIL.nav(fund_id,price_date,nav,cumulative_nav,cumulative_nav_withdrawal,
        isvalid, creatorid, createtime, updaterid, updatetime)
        values
            (#{fundId},#{priceDate},#{nav},#{cumulativeNav},#{cumulativeNavWithdrawal},
            #{isvalid}, #{creatorId}, #{createTime}, #{updaterId}, #{updateTime})
    </insert>
    <update id="updateNav" parameterType="com.simuwang.base.pojo.dos.NavDO">
        update PPW_EMAIL.nav
        <set>
            nav = #{nav},
            cumulative_nav_withdrawal = #{cumulativeNavWithdrawal},
            updatetime=#{updateTime}
        </set>
        where isvalid = 1
        and id=#{id}
    </update>
    <delete id="deleteNav">
        update PPW_EMAIL.nav set isvalid =0,updatetime=sysdate() where fund_id=#{fundId} and price_date=#{priceDate} and isvalid =1
    </delete>

    <select id="queryFundNavByDate" resultType="java.lang.String">
        select price_date
        from PPW_EMAIL.nav
        where isvalid = 1
          and fund_id = #{fundId}
        and price_date in
        <foreach collection="priceDateList" index="index" item="priceDate" separator="," open="(" close=")">
            #{priceDate}
        </foreach>
    </select>
    <select id="queryFundNav" resultMap="BaseResultMap"
            parameterType="com.simuwang.base.pojo.dos.NavDO">
        SELECT id, fund_id,price_date,nav,cumulative_nav,cumulative_nav_withdrawal,
               isvalid, creatorid, createtime, updaterid, updatetime
        from PPW_EMAIL.nav
        where isvalid = 1
          and fund_id = #{fundId}
          and price_date=#{priceDate}
    </select>
    <select id="getAllFundId" resultType="java.lang.String">
        select distinct fund_id from PPW_EMAIL.nav where isvalid=1
    </select>
    <select id="selectNavByFundId" resultMap="BaseResultMap"
            parameterType="java.lang.String">
        SELECT id, fund_id,price_date,nav,cumulative_nav,cumulative_nav_withdrawal,
               isvalid, creatorid, createtime, updaterid, updatetime
        from PPW_EMAIL.nav
        where isvalid = 1
          and fund_id = #{fundId}
    </select>


</mapper>