package com.jojubanking.boot.module.system.dal.mysql.usecount;

import com.jojubanking.boot.framework.mybatis.core.mapper.BaseMapperX;
import com.jojubanking.boot.module.system.dal.dataobject.usecount.UseCountDO;
import com.jojubanking.boot.module.system.dal.dataobject.usecount.UseCountToDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface UseCountXMapper extends BaseMapperX<UseCountToDO> {

    @Select("select *, count(*) as tlsum " +
            "from users_use_count " +
            "where create_time BETWEEN CONCAT(CURDATE(),' 00:00:00') AND CONCAT(CURDATE(),' 23:59:59') " +
            "GROUP BY interface_identification")
    List<UseCountToDO> selectCountTo();

    @Select("select *, count(*) as tlsum " +
            "from users_use_count " +
            "where create_time BETWEEN CONCAT( SUBDATE(CURDATE(), 1),' 00:00:00') AND CONCAT( SUBDATE(CURDATE(), 1),' 23:59:59')" +
            "GROUP BY interface_identification")
    List<UseCountToDO> selectCountTo1();

    @Select("select *, count(*) as tlsum " +
            "from users_use_count " +
            "where create_time BETWEEN CONCAT( SUBDATE(CURDATE(), 2),' 00:00:00') AND CONCAT( SUBDATE(CURDATE(), 2),' 23:59:59')" +
            "GROUP BY interface_identification")
    List<UseCountToDO> selectCountTo2();

    @Select("select *, count(*) as tlsum " +
            "from users_use_count " +
            "where create_time BETWEEN CONCAT( SUBDATE(CURDATE(), 3),' 00:00:00') AND CONCAT( SUBDATE(CURDATE(), 3),' 23:59:59')" +
            "GROUP BY interface_identification")
    List<UseCountToDO> selectCountTo3();

    @Select("select *, count(*) as tlsum " +
            "from users_use_count " +
            "where create_time BETWEEN CONCAT( SUBDATE(CURDATE(), 4),' 00:00:00') AND CONCAT( SUBDATE(CURDATE(), 4),' 23:59:59')" +
            "GROUP BY interface_identification")
    List<UseCountToDO> selectCountTo4();

    @Select("select *, count(*) as tlsum " +
            "from users_use_count " +
            "where create_time BETWEEN CONCAT( SUBDATE(CURDATE(), 5),' 00:00:00') AND CONCAT( SUBDATE(CURDATE(), 5),' 23:59:59')" +
            "GROUP BY interface_identification")
    List<UseCountToDO> selectCountTo5();

    @Select("select *, count(*) as tlsum " +
            "from users_use_count " +
            "where create_time BETWEEN CONCAT( SUBDATE(CURDATE(), 6),' 00:00:00') AND CONCAT( SUBDATE(CURDATE(), 6),' 23:59:59')" +
            "GROUP BY interface_identification")
    List<UseCountToDO> selectCountTo6();

    @Select("select *, COALESCE(count(*), 0) as tlsum " +
            "from users_use_count " +
            " WHERE create_time BETWEEN #{startDate} AND #{endDate} " +
            "GROUP BY interface_identification")
    List<UseCountToDO> selectCountToSection(@Param("startDate") Date startDate, @Param("endDate") Date endDate);
}
