package com.mortals.xhx.module.staff.service.impl;

import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.common.code.SummaryTopTypeEnum;
import com.mortals.xhx.module.staff.dao.StaffPerformStatDao;
import com.mortals.xhx.module.staff.model.StaffPerformStatEntity;
import com.mortals.xhx.module.staff.model.vo.StaffSummaryTopQuery;
import com.mortals.xhx.module.staff.service.StaffPerformStatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
* StaffPerformStatService
* 员工绩效统计 service实现
*
* @author zxfei
* @date 2023-05-17
*/
@Service("staffPerformStatService")
@Slf4j
public class StaffPerformStatServiceImpl extends AbstractCRUDServiceImpl<StaffPerformStatDao, StaffPerformStatEntity, Long> implements StaffPerformStatService {

    @Override
    public List<StaffPerformStatEntity> getSummaryTopList(StaffSummaryTopQuery query) throws AppException {
        LocalDate now = LocalDate.now();
        List<StaffPerformStatEntity> result = null;
        if(query == null){
            query = new StaffSummaryTopQuery();
            query.setSummaryType(SummaryTopTypeEnum.月.getValue());
        }
        if(query.getSummaryType() == SummaryTopTypeEnum.年.getValue()){
            if(query.getYear()==null){
                query.setYear(now.getYear());
            }
            result = dao.getYearSummaryList(query);
        }
        if(query.getSummaryType() == SummaryTopTypeEnum.月.getValue()){
            if(query.getYear()==null){
                query.setYear(now.getYear());
            }
            if(query.getMonth()==null){
                query.setMonth(now.getMonthValue());
            }
            result = dao.getMonthSummaryList(query);
        }
        if(query.getSummaryType() == SummaryTopTypeEnum.日.getValue()){
            if(query.getYear()==null){
                query.setYear(now.getYear());
            }
            if(query.getMonth()==null){
                query.setMonth(now.getMonthValue());
            }
            if(query.getDay()==null){
                query.setDay(now.getDayOfMonth());
            }
            result = dao.getDaySummaryList(query);
        }
        return result;
    }

    @Override
    public List<StaffPerformStatEntity> getExceptionList(StaffSummaryTopQuery query) throws AppException {
        LocalDate now = LocalDate.now();
        List<StaffPerformStatEntity> result = null;
        if(query == null){
            query = new StaffSummaryTopQuery();
            query.setSummaryType(SummaryTopTypeEnum.月.getValue());
        }
        if(query.getSummaryType() == SummaryTopTypeEnum.年.getValue()){
            if(query.getYear()==null){
                query.setYear(now.getYear());
            }
            result = dao.getYearExceptionList(query);
        }
        if(query.getSummaryType() == SummaryTopTypeEnum.月.getValue()){
            if(query.getYear()==null){
                query.setYear(now.getYear());
            }
            if(query.getMonth()==null){
                query.setMonth(now.getMonthValue());
            }
            result = dao.getMonthExceptionList(query);
        }
        if(query.getSummaryType() == SummaryTopTypeEnum.日.getValue()){
            if(query.getYear()==null){
                query.setYear(now.getYear());
            }
            if(query.getMonth()==null){
                query.setMonth(now.getMonthValue());
            }
            if(query.getDay()==null){
                query.setDay(now.getDayOfMonth());
            }
            result = dao.getDayExceptionList(query);
        }
        return result;
    }

}