package com.qy.worksheetsystem.service.impl;

import com.qy.worksheetsystem.model.mapper.CTWORAttendanceTypeMapper;
import com.qy.worksheetsystem.service.CTWORAttendanceTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class CTWORAttendanceTypeServiceImpl implements CTWORAttendanceTypeService {
    @Value("${HR.HolidayPolicy}")
    private String HolidayPolicy;
    @Resource
    private CTWORAttendanceTypeMapper ctworAttendanceTypeMapper;

    @Override
    public List<Map<String, String>> selectIDName() {
        return ctworAttendanceTypeMapper.selectIDName();
    }

    @Override
    public List<Map<String, String>> getAttendanceType(String number) {
        return ctworAttendanceTypeMapper.getAttendanceType(number,HolidayPolicy);
    }
    @Override
    public List<Map<String, String>> getAttendanceTypeV2(String number,String state) {
        long startTime = System.currentTimeMillis();
        log.info("com.qy.worksheetsystem.service.serviceImpl.CTWORAttendanceTypeServiceImpl.getAttendanceTypeV2:startTime:"+startTime+"");
        LocalDate newDate = LocalDate.now();
        Month month = newDate.getMonth();
        LocalDate reportDate = LocalDate.of(newDate.getYear(),month,month.length(newDate.isLeapYear()));

        List<Map<String, String>> list = ctworAttendanceTypeMapper.getAttendanceTypeV2(number,HolidayPolicy,
                reportDate.format(DateTimeFormatter.ISO_LOCAL_DATE),state);
        long endTime = System.currentTimeMillis();
        log.info("com.qy.worksheetsystem.service.serviceImpl.CTWORAttendanceTypeServiceImpl.getAttendanceTypeV2:endTime:"+endTime+"");
        return list;

    }
    @Override
    public Map<String, Object> getHolidayLimit(String number) {
        return ctworAttendanceTypeMapper.getHolidayLimit(number,HolidayPolicy);
    }
}
