<?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.ruoyi.system.mapper.DailyScenicMapper">
    
    <resultMap type="DailyScenic" id="DailyScenicResult">
        <result property="dailyScenicId"    column="daily_scenic_id"    />
        <result property="scenicId"    column="scenic_id"    />
        <result property="uMrTime"    column="u_mr_time"    />
        <result property="bought"    column="bought"    />
        <result property="interactions"    column="interactions"    />
        <result property="shares"    column="shares"    />
        <result property="income"    column="income"    />
        <result property="date"    column="date"    />
    </resultMap>

    <resultMap id="MRTimeDtoResult" type="MRTimeDto">
<!--        <result property="scenic"    column="scenic"    />-->
        <result property="date"    column="date"    />
        <result property="mrTime"    column="u_mr_time"    />
    </resultMap>

    <sql id="selectDailyScenicVo">
        select daily_scenic_id, scenic_id, u_mr_time, bought, interactions, shares, income, date from daily_scenic
    </sql>

    <select id="selectDailyScenicList" parameterType="DailyScenic" resultMap="DailyScenicResult">
        <include refid="selectDailyScenicVo"/>
        <where>  
            <if test="scenicId != null "> and scenic_id = #{scenicId}</if>
            <if test="uMrTime != null "> and u_mr_time = #{uMrTime}</if>
            <if test="bought != null "> and bought = #{bought}</if>
            <if test="interactions != null "> and interactions = #{interactions}</if>
            <if test="shares != null "> and shares = #{shares}</if>
            <if test="income != null "> and income = #{income}</if>
            <if test="date != null "> and date = #{date}</if>
        </where>
    </select>
    
    <select id="selectDailyScenicByDailyScenicId" parameterType="Long" resultMap="DailyScenicResult">
        <include refid="selectDailyScenicVo"/>
        where daily_scenic_id = #{dailyScenicId}
    </select>
    <select id="getMRTime" resultMap="MRTimeDtoResult">

    select u_mr_time, date
    from daily_scenic
    where scenic_id = #{scenicId}
    and date between #{startDate} and #{endDate}
    </select>

    <insert id="insertDailyScenic" parameterType="DailyScenic" useGeneratedKeys="true" keyProperty="dailyScenicId">
        insert into daily_scenic
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="scenicId != null">scenic_id,</if>
            <if test="uMrTime != null">u_mr_time,</if>
            <if test="bought != null">bought,</if>
            <if test="interactions != null">interactions,</if>
            <if test="shares != null">shares,</if>
            <if test="income != null">income,</if>
            <if test="date != null">date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="scenicId != null">#{scenicId},</if>
            <if test="uMrTime != null">#{uMrTime},</if>
            <if test="bought != null">#{bought},</if>
            <if test="interactions != null">#{interactions},</if>
            <if test="shares != null">#{shares},</if>
            <if test="income != null">#{income},</if>
            <if test="date != null">#{date},</if>
         </trim>
    </insert>

    <update id="updateDailyScenic" parameterType="DailyScenic">
        update daily_scenic
        <trim prefix="SET" suffixOverrides=",">
            <if test="scenicId != null">scenic_id = #{scenicId},</if>
            <if test="uMrTime != null">u_mr_time = #{uMrTime},</if>
            <if test="bought != null">bought = #{bought},</if>
            <if test="interactions != null">interactions = #{interactions},</if>
            <if test="shares != null">shares = #{shares},</if>
            <if test="income != null">income = #{income},</if>
            <if test="date != null">date = #{date},</if>
        </trim>
        where daily_scenic_id = #{dailyScenicId}
    </update>

    <delete id="deleteDailyScenicByDailyScenicId" parameterType="Long">
        delete from daily_scenic where daily_scenic_id = #{dailyScenicId}
    </delete>

    <delete id="deleteDailyScenicByDailyScenicIds" parameterType="String">
        delete from daily_scenic where daily_scenic_id in 
        <foreach item="dailyScenicId" collection="array" open="(" separator="," close=")">
            #{dailyScenicId}
        </foreach>
    </delete>
</mapper>