package com.nokia.hb.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nokia.hb.dao.entity.PerCfgCell;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author baomidou
 * @since 2023-02-27
 */
@Mapper
public interface PerCfgCellMapper extends BaseMapper<PerCfgCell> {
    /**
     * 按地区查询
     *
     * @param citys      地市
     * @param quxians    区县
     * @param indicators 指标
     * @param timeType   时间单位
     * @param startTime  开始时间
     * @param endTime    结束时间
     * @return {@link List}<{@link Map}<{@link String}, {@link Object}>>
     */
    @Select("<script>"
            + "select a.cellname, a.city, a.quxian, a.vendor, b.*"
            + " from (select eci, cellname, city, quxian, vendor from pm_parse.per_cfg_cell"
                + " where city in"
                + " <foreach open=\"(\" close=\")\" collection=\"citys\" item=\"item\" separator=\",\">"
                + "   #{item}"
                + " </foreach>"
                + " and quxian in"
                + " <foreach open=\"(\" close=\")\" collection=\"quxians\" item=\"item\" separator=\",\">"
                + "   #{item}"
                + " </foreach> ) a"
            + " inner join (select ${indicators} from pm_parse.pm_4g_${timeType}"
            + " where sdate <![CDATA[ >= ]]> #{startTime}"
            + " and sdate <![CDATA[ <= ]]> #{endTime}) b"
            + " on a.eci = b.eci"
            + " order by b.sdate desc"
            + " </script>")
    List<Map<String, Object>> searchByCity(@Param("citys") Set<String> citys, @Param("quxians") Set<String> quxians,
                                           @Param("indicators") String indicators, @Param("timeType") String timeType,
                                           @Param("startTime") LocalDateTime startTime,
                                           @Param("endTime") LocalDateTime endTime);

    /**
     * 按eci查询
     *
     * @param ecis       eci列表
     * @param indicators 指标
     * @param timeType   时间单位
     * @param startTime  开始时间
     * @param endTime    结束时间
     * @return {@link List}<{@link Map}<{@link String}, {@link Object}>>
     */
    @Select("<script>"
            + "select a.cellname, a.city, a.quxian, a.vendor, b.*"
            + " from (select eci, cellname, city, quxian, vendor from pm_parse.per_cfg_cell"
                + " where eci in"
                + " <foreach open=\"(\" close=\")\" collection=\"ecis\" item=\"item\" separator=\",\">"
                + "   #{item}"
                + " </foreach> ) a"
            + " inner join (select ${indicators} from pm_parse.pm_4g_${timeType}"
            + " where sdate <![CDATA[ >= ]]> #{startTime}"
            + " and sdate <![CDATA[ <= ]]> #{endTime}) b"
            + " on a.eci = b.eci"
            + " order by b.sdate desc"
            + " </script>")
    List<Map<String, Object>> searchByEci(@Param("ecis") Set<String> ecis, @Param("indicators") String indicators,
                                          @Param("timeType") String timeType, @Param("startTime") LocalDateTime startTime,
                                          @Param("endTime") LocalDateTime endTime);
}
