<?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.xxfc.platform.vehicle.mapper.BranchCompanyVehicleCountMapper" >

    <select id="getAllCountInfo" parameterType="Map" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo">
        SELECT
        c.*,
        b.`name` AS companyName
        FROM
        branch_company_vehicle_count c
        LEFT JOIN branch_company b ON b.id = c.company_id
        <where>
            <if test = "companyId != null">
              and  c.company_id = #{companyId}
            </if>
            <if test="startTime != null and startTime != ''">
              and c.count_date &gt;= #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
              and  c.count_date &lt;= #{endTime}
            </if>
        </where>
        GROUP BY c.id
        ORDER BY c.company_id, c.count_date
    </select>

    <select id="countByMonth" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo" parameterType="Map">
        SELECT c.company_id, c.count_year, c.count_month, b.`name` as companyName, sum(c.vehicle_num) as vehicle_num from branch_company_vehicle_count c
        LEFT JOIN branch_company b on b.id = c.company_id
        <where>
            <if test = "companyId != null">
                and  c.company_id = #{companyId}
            </if>
            <if test="startTime != null and startTime != ''">
                and c.count_date &gt;= #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                and  c.count_date &lt;= #{endTime}
            </if>
        </where>
        GROUP BY c.company_id,c.count_year,c.count_month
    </select>

    <select id="countByWeek" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo" parameterType="Map">
        SELECT c.company_id, c.count_year, c.count_week, b.`name` as companyName, sum(c.vehicle_num) as vehicle_num from branch_company_vehicle_count c
        LEFT JOIN branch_company b on b.id = c.company_id
        <where>
            <if test = "companyId != null">
                and  c.company_id = #{companyId}
            </if>
            <if test="startTime != null and startTime != ''">
                and c.count_date &gt;= #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                and  c.count_date &lt;= #{endTime}
            </if>
        </where>
        GROUP BY c.company_id,c.count_year,c.count_week
    </select>

</mapper>