<?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.AssetMapper">
    <resultMap id="BaseResultMap" type="com.simuwang.base.pojo.dos.AssetDO">
        <id column="id" property="id"/>
        <result column="fund_id" property="fundId"/>
        <result column="price_date" property="priceDate"/>
        <result column="asset_net" property="assetNet"/>
        <result column="asset_share" property="assetShare"/>
        <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.AssetDO">
        insert into PPW_EMAIL.asset(fund_id,price_date,asset_net,asset_share,
                                              isvalid, creatorid, createtime, updaterid, updatetime)
        values
        <foreach collection="itemDoList" item="itemDo" index="index" separator=",">
            (#{itemDo.fundId},#{itemDo.priceDate},#{itemDo.assetNet},#{itemDo.assetShare},
            #{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.asset
            <set>
                asset_net = #{itemDo.assetNet},
                asset_share = #{itemDo.assetShare},
                updatetime=#{itemDo.updateTime}
            </set>
            where isvalid = 1
            and fund_id = #{itemDo.fundId}
            and price_date = #{itemDo.priceDate}
        </foreach>
    </insert>
    <delete id="deleteAsset">
        update PPW_EMAIL.asset 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.asset
        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="queryFundAsset" resultMap="BaseResultMap"
            parameterType="com.simuwang.base.pojo.dos.AssetDO">
        select id,fund_id,price_date,asset_net,asset_share,
               isvalid, creatorid, createtime, updaterid, updatetime
        from PPW_EMAIL.asset where isvalid=1 and fund_id=#{fundId} and price_date=#{priceDate}
    </select>

</mapper>