package com.nokia.tsl_data.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface CemMobileExperienceListMapper {
    
    @Select("select count(1) from tsl_data.cem_mobile_experience_list where month_id = #{month_id} and day_id = #{day_id}")
    int countForDay(@Param("month_id") String monthId, @Param("day_id") String dayId);

    default int countForDay(String day) {
        return countForDay(day.substring(0, 6), day.substring(6));
    }

    @Select("select day_id1 as day_id , code_cust_area as city, count(1) as num\n" + //
            " from tsl_data.cem_mobile_experience_list cmel\n" + //
            " where month_id = #{monthId} and day_id = #{dayId} and code_cust_area != '异地'\n" + //
            " group by day_id1, code_cust_area\n" + //
            " order by day_id1, code_cust_area")
    List<Map<String, Object>> selectCityCountForStat(@Param("monthId") String monthId, @Param("dayId") String dayId);

    default List<Map<String, Object>> selectCityCountForStat(String day){
        return selectCityCountForStat(day.substring(0,6), day.substring(6));
    } 

    @Select("select day_id1 as day_id, count(1) as num \n" + //
            " from tsl_data.cem_mobile_experience_list cmel\n" + //
            " where month_id = #{monthId} and day_id = #{dayId} and code_cust_area != '异地'\n" + //
            " group by day_id1 " + //
            " order by day_id1 ")
    List<Map<String, Object>> selectAllCountForStat(@Param("monthId") String monthId, @Param("dayId") String dayId);

    default List<Map<String, Object>> selectAllCountForStat(String day){
        return selectAllCountForStat(day.substring(0,6), day.substring(6));
    }

    @Select("select code_cust_area as city, count(1) as num\n" + //
            " from tsl_data.cem_mobile_experience_list cmel\n" + //
            " where month_id = #{monthId} and day_id = #{dayId} and code_cust_area != '异地'\n" + //
            " group by code_cust_area\n" + //
            " order by code_cust_area")
    List<Map<String, Object>> selectCityAllForStat(@Param("monthId") String monthId, @Param("dayId") String dayId);

    default List<Map<String, Object>> selectCityAllForStat(String day){
        return selectCityAllForStat(day.substring(0,6), day.substring(6));
    } 

    @Select("select count(1)\n" + //
            " from tsl_data.cem_mobile_experience_list cmel\n" + //
            " where month_id = #{monthId} and day_id = #{dayId} and code_cust_area != '异地'")
    int selectCountForStat(@Param("monthId") String monthId, @Param("dayId") String dayId);

    default int selectCountForStat(String day){
        return selectCountForStat(day.substring(0,6), day.substring(6));
    }
}
