package com.sky.ioc.mapper;

import com.sky.ioc.entity.params.IocParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface BusMapper {

    @Select("<script>" +
            "SELECT  coalesce(avg(cost),0)  from bus where 1=1 " +
            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
            "<![CDATA[ and time >= #{iocParam.timeRange.startDate} AND time <= #{iocParam.timeRange.endDate} ]]> " +
            "</if>"+
            "</script>")
    Double getAvgCostByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);

    @Select("<script> " +
            "SELECT count(DISTINCT name) FROM bus  where 1=1 " +
            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
            "<![CDATA[ and time >= #{iocParam.timeRange.startDate} AND time <= #{iocParam.timeRange.endDate} ]]> " +
            "</if>" +
            "</script>")
    Integer getTotalBusByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);

    @Select("<script> " +
            "SELECT count(1) FROM bus  where 1=1 " +
            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
            "<![CDATA[ and time >= #{iocParam.timeRange.startDate} AND time <= #{iocParam.timeRange.endDate} ]]> " +
            "</if>" +
            "</script>")
    Integer getTotalByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);

    @Select("<script>" +
            "SELECT  coalesce(sum(hours),0)  from bus where 1=1 " +
            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
            "<![CDATA[ and time >= #{iocParam.timeRange.startDate} AND time <= #{iocParam.timeRange.endDate} ]]> " +
            "</if>"+
            "</script>")
    Double getTotalHoursByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);

    @Select("<script>" +
            "SELECT  coalesce(sum(carbon),0)  from bus where 1=1 " +
            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
            "<![CDATA[ and time >= #{iocParam.timeRange.startDate} AND time <= #{iocParam.timeRange.endDate} ]]> " +
            "</if>"+
            "</script>")
    Double getTotalCarbonByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);

}
