<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.edu.whu.boot.statistics.mapper.ProgressStatMapper">


    <select id="getTasks" resultType="String">
        select task_name from task
    </select>

    <select id="getTaskXmlName" resultType="String">
        SELECT file_name FROM "xml"
        WHERE id = (SELECT xml_id FROM task WHERE task_name = #{tskName})
    </select>

    <select id="getTaskXmlNameById" resultType="String">
        SELECT file_name FROM "xml"
        WHERE id = (SELECT xml_id FROM task WHERE id = #{taskId})
    </select>

    <select id="getTaskDBName" resultType="String" parameterType="String">
        SELECT database_name FROM task WHERE task_name = #{tskName}
    </select>

    <select id="getTaskDBNameById" resultType="String" parameterType="Integer">
        SELECT database_name FROM task WHERE id = #{taskId}
    </select>

    <select id="getCount" resultType="Integer">
        SELECT "count"(1) FROM ${tblName}
        where status = 1 or status = 2
    </select>

    <select id="getCountInAPeriod" resultType="Integer">
        SELECT count(1) FROM ${tblName} WHERE status != 0 and "create_time" BETWEEN ${startTime} AND ${endTime}
    </select>

    <select id="statDaily" resultType="HashMap">
        SELECT to_char("create_time", 'YYYY-MM-DD') as "date", "count"(1) FROM ${tblName}
        WHERE (status = 1 or status = 2) and "create_time" BETWEEN ${startTime} AND ${endTime} group by "date" order by "date"
    </select>

    <select id="statMonthly" resultType="HashMap">
        SELECT to_char("create_time", 'YYYY-MM') as "date", "count"(1) FROM ${tblName}
        WHERE (status = 1 or status = 2) and "create_time" BETWEEN ${startTime} AND ${endTime} group by "date" order by "date"
    </select>

</mapper>