<?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.DailyUserMapper">
    
    <resultMap type="DailyUser" id="DailyUserResult">
        <result property="dailyUserId"    column="daily_user_id"    />
        <result property="userId"    column="user_id"    />
        <result property="onlineTime"    column="online_time"    />
        <result property="mrTime"    column="mr_time"    />
        <result property="consumption"    column="consumption"    />
        <result property="tWork"    column="t_work"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="date"    column="date"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectDailyUserVo">
        select daily_user_id, user_id, online_time, mr_time, consumption, t_work, create_time, update_time, date, del_flag from daily_user
    </sql>

    <select id="selectDailyUserList" parameterType="DailyUser" resultMap="DailyUserResult">
        <include refid="selectDailyUserVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="onlineTime != null "> and online_time = #{onlineTime}</if>
            <if test="mrTime != null "> and mr_time = #{mrTime}</if>
            <if test="consumption != null "> and consumption = #{consumption}</if>
            <if test="tWork != null "> and t_work = #{tWork}</if>
            <if test="date != null "> and date = #{date}</if>
        </where>
    </select>
    
    <select id="selectDailyUserByDailyUserId" parameterType="Long" resultMap="DailyUserResult">
        <include refid="selectDailyUserVo"/>
        where daily_user_id = #{dailyUserId}
    </select>
    
    <select id="selectByUserIdAndDate" resultMap="DailyUserResult">
        select * from daily_user where user_id = #{userId} and date = #{date}
    </select>
    <select id="getTotalOnlineTime" resultType="java.lang.Long">
        select sum(online_time) from daily_user where date = #{date}
    </select>
    <select id="getTotalMRTime" resultType="java.lang.Long">
        select sum(mr_time) from daily_user where date = #{date}
    </select>
    <select id="getTotalBought" resultType="java.lang.Long">
        select sum(bought) from daily_source where data = #{date}
    </select>
    <select id="getStDailyUser" resultType="com.ruoyi.system.domain.dto.DailyUserDto">
        select sum(online_time) as onlineTime, sum(mr_time) as mrTime, sum(consumption) as consumption, sum(t_work) as tWork from daily_user where date = #{date}
    </select>

    <insert id="insertDailyUser" parameterType="DailyUser" useGeneratedKeys="true" keyProperty="dailyUserId">
        insert into daily_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="onlineTime != null">online_time,</if>
            <if test="mrTime != null">mr_time,</if>
            <if test="consumption != null">consumption,</if>
            <if test="tWork != null">t_work,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="date != null">date,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="onlineTime != null">#{onlineTime},</if>
            <if test="mrTime != null">#{mrTime},</if>
            <if test="consumption != null">#{consumption},</if>
            <if test="tWork != null">#{tWork},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="date != null">#{date},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateDailyUser" parameterType="DailyUser">
        update daily_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="onlineTime != null">online_time = #{onlineTime},</if>
            <if test="mrTime != null">mr_time = #{mrTime},</if>
            <if test="consumption != null">consumption = #{consumption},</if>
            <if test="tWork != null">t_work = #{tWork},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="date != null">date = #{date},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where daily_user_id = #{dailyUserId}
    </update>
    <update id="updateByUserIdAndDate" parameterType="DailyUser">
        update daily_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="onlineTime != null">online_time = #{onlineTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where user_id = #{userId} and date = #{date}

    </update>

    <delete id="deleteDailyUserByDailyUserId" parameterType="Long">
        delete from daily_user where daily_user_id = #{dailyUserId}
    </delete>

    <delete id="deleteDailyUserByDailyUserIds" parameterType="String">
        delete from daily_user where daily_user_id in 
        <foreach item="dailyUserId" collection="array" open="(" separator="," close=")">
            #{dailyUserId}
        </foreach>
    </delete>
</mapper>