<?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.DailySysMapper">
    
    <resultMap type="DailySys" id="DailySysResult">
        <result property="dailySysId"    column="daily_sys_id"    />
        <result property="tUser"    column="t_user"    />
        <result property="tOnlineTime"    column="t_online_time"    />
        <result property="tMrTime"    column="t_mr_time"    />
        <result property="tBought"    column="t_bought"    />
        <result property="tInteractions"    column="t_interactions"    />
        <result property="tShares"    column="t_shares"    />
        <result property="tWork"    column="t_work"    />
        <result property="tPassWork"    column="t_pass_work"    />
        <result property="tBackWork"    column="t_back_work"    />
        <result property="tIncome"    column="t_income"    />
        <result property="tRefund"    column="t_refund"    />
        <result property="dBought"    column="d_bought"    />
        <result property="date"    column="data"    />
    </resultMap>

    <resultMap id="SeUserCountResult" type="seUserCountDto">
        <result property="date" column="data"/>
        <result property="tUser" column="t_user"/>
    </resultMap>

    <resultMap id="SeUserWorkCountResult" type="seUserWorkCountDto">
        <result property="date" column="data"/>
        <result property="tWork" column="t_work"/>
    </resultMap>

    <resultMap id="seOnlineTimeDtoResult" type="SeOnlineTimeDto">
        <result property="date" column="data"/>
        <result property="tOnlineTime" column="t_online_time"/>
    </resultMap>

    <resultMap id="SysIncomeDtoResult" type="SysIncomeDto">
        <result property="date" column="data"/>
        <!--还要改进-->
        <result property="tIncome" column="t_income"/>
        <!--退款总额-->
        <result property="tRefund" column="t_refund"/>
    </resultMap>

    <resultMap id="SourceUseCountDtoResult" type="SourceUseCountDto">
        <result property="date" column="data"/>
        <result property="useCount" column="d_bought"/>

    </resultMap>

    <sql id="selectDailySysVo">
        select daily_sys_id, t_user, t_online_time, t_mr_time, t_bought, t_interactions, t_shares, t_work, t_pass_work, t_back_work, t_income, t_refund, data from daily_sys
    </sql>

    <select id="selectDailySysList" parameterType="DailySys" resultMap="DailySysResult">
        <include refid="selectDailySysVo"/>
        <where>  
            <if test="tUser != null "> and t_user = #{tUser}</if>
            <if test="tOnlineTime != null "> and t_online_time = #{tOnlineTime}</if>
            <if test="tMrTime != null "> and t_mr_time = #{tMrTime}</if>
            <if test="tBought != null "> and t_bought = #{tBought}</if>
            <if test="tInteractions != null "> and t_interactions = #{tInteractions}</if>
            <if test="tShares != null "> and t_shares = #{tShares}</if>
            <if test="tWork != null "> and t_work = #{tWork}</if>
            <if test="tPassWork != null "> and t_pass_work = #{tPassWork}</if>
            <if test="tBackWork != null "> and t_back_work = #{tBackWork}</if>
            <if test="tIncome != null "> and t_income = #{tIncome}</if>
            <if test="tRefund != null "> and t_refund = #{tRefund}</if>
            <if test="date != null "> and data = #{date}</if>
        </where>
    </select>
    
    <select id="selectDailySysByDailySysId" parameterType="Long" resultMap="DailySysResult">
        <include refid="selectDailySysVo"/>
        where daily_sys_id = #{dailySysId}
    </select>

    <select id="selectDailySysByDate" parameterType="java.time.LocalDate" resultMap="DailySysResult">
        <include refid="selectDailySysVo"/>
        where data = #{date}
    </select>

    <select id="selectDailySysListBetweenDate" parameterType="java.time.LocalDate" resultMap="SeUserCountResult">
        select t_user, data from daily_sys where data between #{startDate} and #{endDate}
    </select>

    <select id="selectDailySysWorkListBetweenDate" parameterType="java.time.LocalDate" resultMap="SeUserWorkCountResult">
        select t_work, data from daily_sys where data between #{startDate} and #{endDate}
    </select>

    <!-- 这里还不能直接套用-->
    <select id="gettOnlineTime" parameterType="java.time.LocalDate" resultMap="seOnlineTimeDtoResult">
        select t_online_time, data from daily_sys where data between #{startDate} and #{endDate}

    </select>
    <select id="getSysIncome" resultMap="SysIncomeDtoResult">
        select t_income,t_refund ,data from daily_sys where data between #{startDate} and #{endDate} order by data desc
    </select>
    <select id="getSourceUserCount" resultMap="SourceUseCountDtoResult">
        select d_bought, data from daily_sys where data between #{startDate} and #{endDate}

    </select>


    <insert id="insertDailySys" parameterType="DailySys" useGeneratedKeys="true" keyProperty="dailySysId">
        insert into daily_sys
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tUser != null">t_user,</if>
            <if test="tOnlineTime != null">t_online_time,</if>
            <if test="tMrTime != null">t_mr_time,</if>
            <if test="tBought != null">t_bought,</if>
            <if test="tInteractions != null">t_interactions,</if>
            <if test="tShares != null">t_shares,</if>
            <if test="tWork != null">t_work,</if>
            <if test="tPassWork != null">t_pass_work,</if>
            <if test="tBackWork != null">t_back_work,</if>
            <if test="tIncome != null">t_income,</if>
            <if test="tRefund != null">t_refund,</if>
            <if test="date != null">data,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tUser != null">#{tUser},</if>
            <if test="tOnlineTime != null">#{tOnlineTime},</if>
            <if test="tMrTime != null">#{tMrTime},</if>
            <if test="tBought != null">#{tBought},</if>
            <if test="tInteractions != null">#{tInteractions},</if>
            <if test="tShares != null">#{tShares},</if>
            <if test="tWork != null">#{tWork},</if>
            <if test="tPassWork != null">#{tPassWork},</if>
            <if test="tBackWork != null">#{tBackWork},</if>
            <if test="tIncome != null">#{tIncome},</if>
            <if test="tRefund != null">#{tRefund},</if>
            <if test="date != null">#{date},</if>
         </trim>
    </insert>

    <update id="updateDailySys" parameterType="DailySys">
        update daily_sys
        <trim prefix="SET" suffixOverrides=",">
            <if test="tUser != null">t_user = #{tUser},</if>
            <if test="tOnlineTime != null">t_online_time = #{tOnlineTime},</if>
            <if test="tMrTime != null">t_mr_time = #{tMrTime},</if>
            <if test="tBought != null">t_bought = #{tBought},</if>
            <if test="tInteractions != null">t_interactions = #{tInteractions},</if>
            <if test="tShares != null">t_shares = #{tShares},</if>
            <if test="tWork != null">t_work = #{tWork},</if>
            <if test="tPassWork != null">t_pass_work = #{tPassWork},</if>
            <if test="tBackWork != null">t_back_work = #{tBackWork},</if>
            <if test="tIncome != null">t_income = #{tIncome},</if>
            <if test="tRefund != null">t_refund = #{tRefund},</if>
            <if test="date != null">data = #{date},</if>
        </trim>
        where daily_sys_id = #{dailySysId}
    </update>

    <delete id="deleteDailySysByDailySysId" parameterType="Long">
        delete from daily_sys where daily_sys_id = #{dailySysId}
    </delete>

    <delete id="deleteDailySysByDailySysIds" parameterType="String">
        delete from daily_sys where daily_sys_id in 
        <foreach item="dailySysId" collection="array" open="(" separator="," close=")">
            #{dailySysId}
        </foreach>
    </delete>

</mapper>