package com.game.business.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.game.business.domain.AppUserCount;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface AppUserCountMapper extends BaseMapper<AppUserCount> {

    @Select(" <script>" +
            " select a.* from app_user_count as a INNER JOIN" +
            " (WITH RECURSIVE useragent AS" +
            " (" +
            " SELECT *" +
            " FROM app_user_agent" +
            " WHERE pid = #{pid}" +
            " UNION ALL" +
            " SELECT o.*" +
            " FROM app_user_agent o" +
            " JOIN useragent s ON o.pid = s.user_id" +
            " )" +
            " SELECT user_id FROM useragent ) as b on a.user_id = b.user_id where a.str_date between #{beginTime} and #{endTime}" +
            " union all" +
            " select c.* from app_user_count as c where c.user_id = #{pid} and c.str_date between #{beginTime} and #{endTime} " +
            " </script>")
    public List<AppUserCount> selectTeamUserCount(@Param("pid") Long pid,@Param("beginTime") String beginTime,@Param("endTime") String endTime);


    public int updateCount(AppUserCount appUserCount);

}
