package com.mortals.xhx.module.dept.service.impl;
import com.mortals.framework.util.DateUtils;
import com.mortals.xhx.common.code.SummaryTopTypeEnum;
import com.mortals.xhx.module.dept.model.vo.DeptSummaryTopQuery;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.dept.dao.DeptPerformStatDao;
import com.mortals.xhx.module.dept.model.DeptPerformStatEntity;
import com.mortals.xhx.module.dept.service.DeptPerformStatService;
import lombok.extern.slf4j.Slf4j;

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

/**
* DeptPerformStatService
* 部门绩效分数统计 service实现
*
* @author zxfei
* @date 2023-05-16
*/
@Service("deptPerformStatService")
@Slf4j
public class DeptPerformStatServiceImpl extends AbstractCRUDServiceImpl<DeptPerformStatDao, DeptPerformStatEntity, Long> implements DeptPerformStatService {


    @Override
    public List<DeptPerformStatEntity> getSummaryTopList(DeptSummaryTopQuery query) throws AppException {
        LocalDate now = LocalDate.now();
        List<DeptPerformStatEntity> result = null;
        if(query == null){
            query = new DeptSummaryTopQuery();
            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;
    }
}