<?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="com.njcn.csharmonic.mapper.CsHarmonicMapper">

    <select id="getHarmonicCounts" resultType="com.njcn.csharmonic.pojo.vo.HarmonicVO">
        SELECT
            COUNT(1) AS harmonicNums,
            COUNT(DISTINCT TIME) AS overDays,
            COUNT(DISTINCT line_id) AS overLineNums
        FROM
            cs_harmonic
        WHERE
            TIME BETWEEN #{startTime} AND #{endTime}
            AND line_id IN
            <foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
    </select>

    <select id="getOverDays" resultType="java.lang.String">
        SELECT
            DISTINCT time
        FROM
            cs_harmonic
        WHERE
            TIME BETWEEN #{startTime} AND #{endTime}
            AND line_id IN
            <foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        order by time asc
    </select>

    <select id="getLineHarmonicOverDays" resultType="com.njcn.csharmonic.pojo.vo.HarmonicVO$LineHarmonicOverDays">
        SELECT
            line_id lineId,
            GROUP_CONCAT(DISTINCT time ORDER BY time SEPARATOR ', ') AS timeString
        FROM cs_harmonic
        WHERE TIME BETWEEN #{startTime} AND #{endTime}
        AND line_id IN
        <foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
        GROUP BY line_id
    </select>

</mapper>
