package com.xunmei.core.resumption.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xunmei.common.core.utils.DateHelper;
import com.xunmei.core.resumption.domain.AppRule;
import com.xunmei.core.resumption.domain.Resumption;
import com.xunmei.core.resumption.dto.ResumptionTaskDataDto;
import com.xunmei.core.resumption.dto.TaskDetailsDto;
import com.xunmei.core.resumption.mapper.AppRuleMapper;
import com.xunmei.core.resumption.mapper.ResumptionMapper;
import com.xunmei.core.resumption.service.IAppRuleService;
import com.xunmei.core.resumption.service.ResumptionService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ResumptionServiceImpl extends ServiceImpl<ResumptionMapper, Resumption> implements ResumptionService {
    @Autowired
    private ResumptionMapper resumptionMapper;
    @Override
    public List<Map<String, Object>> findDayTaskList(int year, int quarter, String dateTime, Long roleId, Long orgid) {
        return resumptionMapper.findDayTaskList(year,quarter,dateTime, roleId, orgid);
    }
    @Override
    public List<Map<String, Object>> findMonthTaskList(int year, int month, int type, Long roleId, Long orgid, int quarter) {
        return resumptionMapper.findMonthTaskList(year, month, type, roleId, orgid, quarter);
    }
    @Override
    public List<Map<String, Object>> findYearTaskList(int year, int type, Long roleId, Long orgid, int quarter) {
        return resumptionMapper.findYearTaskList(year, type, roleId, orgid,quarter);
    }
    @Override
    public Resumption findOneByTaskIdAndDate(TaskDetailsDto request) {
        DateHelper dateTime = new DateHelper(request.getDateTime());
        int year =dateTime.getYear();
        int quarter =dateTime.getQuarter() ;
        //如果是年任务季度设为1
        if(request.getType()==5){
            quarter = 1;
        }
        return resumptionMapper.findOneByTaskIdAndDate(request.getTaskId(),year,quarter);
    }
    @Override
    public Resumption findOneByTaskIdAndDate(ResumptionTaskDataDto request) {
        final DateHelper dateTime = new DateHelper(request.getDateTime());
        int year =dateTime.getYear();
        int quarter =dateTime.getQuarter() ;
        //如果是年任务季度设为1
        if(request.getType()==5){
            quarter = 1;
        }
        return resumptionMapper.findOneByTaskIdAndDate(request.getTaskid(),year,quarter);
    }
    @Override
    public List<Map<String, Object>> findOneByTaskId(TaskDetailsDto request) {
        final DateHelper dateTime = new DateHelper(request.getDateTime());
        int year =dateTime.getYear();
        int quarter =dateTime.getQuarter() ;
        //如果是年任务季度设为1
        if(request.getType()==5){
            quarter = 1;
        }
        return resumptionMapper.findOneByTaskId(request.getTaskId(), year, quarter);
    }
    @Override
    public void updateResumption(Resumption resumption){
        resumptionMapper.updateResumption(resumption);
    }

}
