package com.sky.ioc.mapper.carbon;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.ioc.entity.domain.carbon.Carbon;
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 CarbonMapper extends BaseMapper<Carbon> {
    @Select("<script> " +
            "select coalesce(sum(discharge),0) from carbon where  1=1 " +
            "<if test='iocParam!=null and iocParam.timeRange!=null '>" +
            "and time between #{iocParam.timeRange.startDate} and #{iocParam.timeRange.endDate} " +
            "</if>" +
            "<if test='iocParam!=null and iocParam.deptId!=null '>" +
            "and dept_id = #{iocParam.deptId} " +
            "</if>" +
            "</script>")
    Long getDischargeByTime(@Param("iocParam")IocParam iocParam);


    @Select("<script> " +
            "select coalesce(sum(de_emission),0) from carbon where  1=1 " +
            "<if test='iocParam!=null and iocParam.timeRange!=null '>" +
            "and time between #{iocParam.timeRange.startDate} and #{iocParam.timeRange.endDate} " +
            "</if>" +
            "<if test='iocParam!=null and iocParam.deptId!=null '>" +
            "and dept_id = #{iocParam.deptId} " +
            "</if>" +
            "</script>")
    Long getDeEmissionByTime(@Param("iocParam")IocParam iocParam);

    @Select("<script> " +
            "select coalesce(sum(discharge),0) from carbon where  source_type = #{sourceType} " +
            "<if test='iocParam!=null and iocParam.timeRange!=null '>" +
            "and time between #{iocParam.timeRange.startDate} and #{iocParam.timeRange.endDate} " +
            "</if>" +
            "<if test='iocParam!=null and iocParam.deptId!=null '>" +
            "and dept_id = #{iocParam.deptId} " +
            "</if>" +
            "</script>")
    Long getDischargeBySourceType(@Param("iocParam")IocParam iocParam,@Param("sourceType") String sourceType);
}
