<?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.ValuationTableMapper">
    <resultMap id="BaseResultMap" type="com.simuwang.base.pojo.dos.ValuationTableDO">
        <id column="id" property="id"/>
        <result column="fund_id" property="fundId"/>
        <result column="title" property="title"/>
        <result column="valuation_date" property="valuationDate"/>
        <result column="head_info" property="headInfo"/>
        <result column="tail_info" property="tailInfo"/>
        <result column="original_file" property="originalFile"/>
        <result column="converted_file" property="convertedFile"/>
        <result column="file_url" property="fileUrl"/>
        <result column="table_type" property="tableType"/>
        <result column="is_analyzed" property="isAnalyzed"/>
        <result column="total_market_value" property="totalMarketValue"/>
        <result column="net_assets_value" property="netAssetsValue"/>
        <result column="nav" property="nav"/>
        <result column="increment" property="increment"/>
        <result column="from_email" property="fromEmail"/>
        <result column="has_stock" property="hasStock"/>
        <result column="has_bond" property="hasBond"/>
        <result column="has_future" property="hasFuture"/>
        <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>

    <update id="unValid">
        update  PPW_EMAIL.valuation_table
        set isvalid = 0
        where fund_id = #{fundId}
          and valuation_date = #{valuationDate}
    </update>

    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.simuwang.base.pojo.dos.ValuationTableDO" useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into PPW_EMAIL.valuation_table (fund_id,
        title, valuation_date, nav,
        head_info, tail_info, original_file,
        converted_file, file_url, table_type,
        isvalid, creatorid, createtime,
        updaterid, updatetime, is_analyzed,
        total_market_value,net_assets_value,increment,from_email)
        values (#{fundId,jdbcType=VARCHAR},
        #{title,jdbcType=VARCHAR}, #{valuationDate,jdbcType=DATE}, #{nav,jdbcType=DECIMAL},
        #{headInfo,jdbcType=VARCHAR}, #{tailInfo,jdbcType=VARCHAR}, #{originalFile,jdbcType=VARCHAR},
        #{convertedFile,jdbcType=VARCHAR}, #{fileUrl,jdbcType=VARCHAR}, #{tableType,jdbcType=TINYINT},
        #{isvalid,jdbcType=INTEGER}, #{creatorId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
        #{updaterId,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP}, #{isAnalyzed,jdbcType=TINYINT},
        #{totalMarketValue,jdbcType=DECIMAL},#{netAssetsValue,jdbcType=DECIMAL},#{increment,jdbcType=DECIMAL},
        #{fromEmail,jdbcType=TINYINT})
    </insert>

    <update id="updateUpdateAnalyzed">
        update PPW_EMAIL.valuation_table
        set is_analyzed = 1,
            has_stock = #{hasStock},
            has_bond = #{hasBond},
            has_future = #{hasFuture}
        where valuation_date = #{valuationDate}
          and fund_id = #{fundId}
          and isvalid = 1
    </update>

</mapper>