package cn.cecep.talroad.service.impl.effective;

import cn.cecep.talroad.common.core.utils.DateUtils;
import cn.cecep.talroad.domain.effective.PcNationalCityRankingOther;
import cn.cecep.talroad.mapper.effective.PcNationalCityRankingOtherMapper;
import cn.cecep.talroad.service.effective.PcNationalCityRankingOtherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class PcNationalCityRankingOtherServiceImpl extends ServiceImpl<PcNationalCityRankingOtherMapper, PcNationalCityRankingOther> implements PcNationalCityRankingOtherService{

    @Autowired
    private PcNationalCityRankingOtherMapper pcNationalCityRankingOtherMapper;

    @Override
    public int updateBatch(List<PcNationalCityRankingOther> list) {
        return baseMapper.updateBatch(list);
    }
    @Override
    public int updateBatchSelective(List<PcNationalCityRankingOther> list) {
        return baseMapper.updateBatchSelective(list);
    }
    @Override
    public int batchInsert(List<PcNationalCityRankingOther> list) {
        return baseMapper.batchInsert(list);
    }

    @Override
    public void doProcessCityRankDay() {
        String lastDayDate = DateUtils.parseDateToStr("yyyy-MM-dd",new Date());
        List<PcNationalCityRankingOther> cityList = pcNationalCityRankingOtherMapper.selectDayRankData(lastDayDate);
        AtomicInteger rank = new AtomicInteger();
        if(cityList!=null&&cityList.size()>0){
            cityList.forEach(r->{
                rank.getAndIncrement();
                r.setIndexProvinceCity(String.valueOf(rank.get()));
            });
            pcNationalCityRankingOtherMapper.updateBatchRank(cityList);
        }
    }

    @Override
    public void doProcessCityRankMonth() {
        String lastMonthDate = DateUtils.parseDateToStr("yyyy-MM",new Date());
        List<PcNationalCityRankingOther> cityList = pcNationalCityRankingOtherMapper.selectMonthRankData(lastMonthDate);
        AtomicInteger rank = new AtomicInteger();
        if(cityList!=null&&cityList.size()>0){
            cityList.forEach(r->{
                rank.getAndIncrement();
                r.setIndexProvinceCity(String.valueOf(rank.get()));
            });
            pcNationalCityRankingOtherMapper.updateBatchRank(cityList);
        }
    }

    @Override
    public void doProcessCityRankYear() {
        String lastYearDate = DateUtils.parseDateToStr("yyyy",new Date());
        List<PcNationalCityRankingOther> cityList = pcNationalCityRankingOtherMapper.selectYearRankData(lastYearDate);
        AtomicInteger rank = new AtomicInteger();
        if(cityList!=null&&cityList.size()>0){
            cityList.forEach(r->{
                rank.getAndIncrement();
                r.setIndexProvinceCity(String.valueOf(rank.get()));
            });
            pcNationalCityRankingOtherMapper.updateBatchRank(cityList);
        }
    }
}
