package com.sunyard.ssp.modules.monitor.transaction.mapper;

import com.sunyard.ssp.modules.monitor.transaction.entity.StatisticalParam;
import com.sunyard.ssp.modules.monitor.transaction.entity.StatisticalResult;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StatisticalMapper {

//    @Select("<script>" +
//            " select SUM(SUCCESS_COUNT) as successCount,SUM(FAIL_COUNT) as failCount from SC_BUSINESS_STATISTICS\n" +
//            "        <where>\n" +
//            "            <if test=\"statisticalParam.server != null and statisticalParam.server != ''\">\n" +
//            "                and SERVER = #{statisticalParam.server}\n" +
//            "            </if>\n" +
//            "            <if test=\"statisticalParam.channelId != null\">\n" +
//            "                and CHANNEL_ID = #{statisticalParam.channelId}\n" +
//            "            </if>\n" +
//            "            <if test=\"statisticalParam.solutionId != null\">\n" +
//            "                and SOLUTION__ID = #{statisticalParam.solutionId}\n" +
//            "            </if>\n" +
//            "            <if test=\"statisticalParam.startTime != null and statisticalParam.endTime != null\">\n" +
//            "                and \"CURRENT_TIME\" between to_date(#{statisticalParam.startTime},'YYYY-MM-DD HH24:MI:SS') and to_date(#{statisticalParam.endTime},'YYYY-MM-DD HH24:MI:SS')\n" +
//            "            </if>\n" +
//            "        </where>" +
//            "</script>")
    StatisticalResult countPieChart(@Param("statisticalParam") StatisticalParam statisticalParam);

//    @Select("<script>" +
//            "        select to_char(\"CURRENT_TIME\",'${statisticalParam.timeIntervalFormat}') as statisticalTime,\n" +
//            "        SUM(SUCCESS_COUNT) as successCount,\n" +
//            "        SUM(FAIL_COUNT) as failCount \n" +
//            "        from SC_BUSINESS_STATISTICS\n" +
//            "        <where>\n" +
//            "            <if test=\"statisticalParam.server != null and statisticalParam.server != ''\">\n" +
//            "                and SERVER = #{statisticalParam.server}\n" +
//            "            </if>\n" +
//            "            <if test=\"statisticalParam.channelId != null\">\n" +
//            "                and CHANNEL_ID = #{statisticalParam.channelId}\n" +
//            "            </if>\n" +
//            "            <if test=\"statisticalParam.solutionNumber != null\">\n" +
//            "                and SOLUTION_NUMBER = #{statisticalParam.solutionNumber}\n" +
//            "            </if>\n" +
//            "            <if test=\"statisticalParam.sqlStatisticalTime != null and statisticalParam.sqlStatisticalTimeFormat !=null\">\n" +
//            "                and to_char(TRUNC(\"CURRENT_TIME\"),'${statisticalParam.sqlStatisticalTimeFormat}') =  (SELECT TO_CHAR (#{statisticalParam.sqlStatisticalTime}, '${statisticalParam.sqlStatisticalTimeFormat}') FROM DUAL)\n" +
//            "            </if>\n" +
//            "        </where>\n" +
//            "        group by to_char(\"CURRENT_TIME\",'${statisticalParam.timeIntervalFormat}')\n" +
//            "        order by to_char(\"CURRENT_TIME\",'${statisticalParam.timeIntervalFormat}')" +
//            "</script>")
    List<StatisticalResult> countLineChartByTimeInterval(@Param("statisticalParam") StatisticalParam statisticalParam);

//    @Select("<script>" +
//            " select to_char(\"CURRENT_TIME\",'${statisticalParam.timeIntervalFormat}') as statisticalTime ,SUM(SUCCESS_COUNT) as successCount,SUM(FAIL_COUNT) as failCount\n" +
//            "        from SC_BUSINESS_STATISTICS\n" +
//            "        <where>\n" +
//            "            <if test=\"statisticalParam.group != null and statisticalParam.group != ''\">\n" +
//            "                and \"GROUP\" = #{statisticalParam.group}\n" +
//            "            </if>\n" +
//            "            <if test=\"statisticalParam.sqlStatisticalTime != null and statisticalParam.sqlStatisticalTimeFormat !=null\">\n" +
//            "                and to_char(TRUNC(\"CURRENT_TIME\"),'${statisticalParam.sqlStatisticalTimeFormat}') =  (SELECT TO_CHAR (#{statisticalParam.sqlStatisticalTime}, '${statisticalParam.sqlStatisticalTimeFormat}') FROM DUAL)\n" +
//            "            </if>\n" +
//            "        </where>\n" +
//            "        group by to_char(\"CURRENT_TIME\",'${statisticalParam.timeIntervalFormat}')\n" +
//            "        order by to_char(\"CURRENT_TIME\",'${statisticalParam.timeIntervalFormat}')" +
//            "</script>")
    List<StatisticalResult> countLineChartByKeyGroup(@Param("statisticalParam") StatisticalParam statisticalParam);
}
