package com.zcxk.rmcp.web.service.impl.readrate;

import com.zcxk.core.common.pojo.UserCondition;
import com.zcxk.core.utils.DateUtil;
import com.zcxk.rmcp.api.dto.readrate.ReadRateDto;
import com.zcxk.rmcp.api.enums.ReadRateEnum;
import com.zcxk.rmcp.api.vo.ReadRateVo;
import com.zcxk.rmcp.api.vo.StatisticsReadRateVo;
import com.zcxk.rmcp.core.dao.ReadRateMonthMapper;
import com.zcxk.rmcp.web.service.AbstractReadRateService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * @author Andy
 * @version V1.0
 * @description: 统计月抄表率
 * @date 2021/7/26
 **/
@Service
public class ReadRateMonthServiceImpl extends AbstractReadRateService {

    @Resource
    private ReadRateMonthMapper readRateMonthMapper;

    @Override
    public List<StatisticsReadRateVo> statReadRateGroupCategory(UserCondition userCondition){
        return readRateMonthMapper.statReadRateGroupCategory(userCondition);
    }

    @Override
    public List<ReadRateVo> listReadRate(ReadRateDto dto, UserCondition userCondition) {
        LocalDate localDate = DateUtil.parseLocalDate(new Date());
        localDate = localDate.plusMonths(-1);
        String month =  (localDate.getMonthValue() +"").length() == 1 ? "0" + localDate.getMonthValue() : localDate.getMonthValue() +"";
        int queryDate = Integer.parseInt(localDate.getYear() + "" + month);
        return readRateMonthMapper.listReadRate(dto, queryDate, userCondition);
    }

    @Override
    public StatisticsReadRateVo countReadRate(ReadRateDto dto, UserCondition userCondition) {
        return readRateMonthMapper.countReadRate(dto, userCondition);
    }

    @Override
    public ReadRateEnum getStatDays() {
        return ReadRateEnum.MONTH;
    }

}
