package com.boman.web.core.mapper;

import org.apache.ibatis.annotations.SelectProvider;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Date;

public interface LeaveMapper {

    @SelectProvider(type = LeaveMapper.SqlProvider.class, method = "statisticLeave")
    Integer statisticLeave();

    class SqlProvider {

        public String statisticLeave() {
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            return "SELECT (SELECT count(*) FROM leavefrom f WHERE f.status = 2 and '" + sdf.format(date) + "' "
                    + " BETWEEN date_format(f.leavefrom_start_time, \"%Y-%m-%d\" ) "
                    + " and date_format( f.leavefrom_end_time, \"%Y-%m-%d\" )) "
                    + " + (SELECT count(*) FROM boman_temp_leaveform t WHERE  t.status = 2 and  '" + sdf.format(date) + "' "
                    + " BETWEEN date_format(t.leavefrom_start_time, \"%Y-%m-%d\" ) "
                    + " and date_format(t.leavefrom_end_time, \"%Y-%m-%d\" )) as count "
                    + " FROM DUAL";
        }
    }
}
