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 PrintMapper {

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

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

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

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

    @Select("<script> " +
            "SELECT coalesce(sum(paper),0) FROM print  where 1=1 " +
            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
            "<![CDATA[ and print_time >= #{iocParam.timeRange.startDate} AND print_time <= #{iocParam.timeRange.endDate} ]]> " +
            "</if>" +
            "</script>")
    Integer getTotalPaper(@Param("iocParam") IocParam iocParam);

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


}
