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

import cn.cecep.talroad.common.core.utils.DateUtils;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import cn.cecep.talroad.domain.effective.PcNationalCityRankingHour;
import cn.cecep.talroad.mapper.effective.PcNationalCityRankingHourMapper;
import cn.cecep.talroad.service.effective.PcNationalCityRankingHourService;
@Service
public class PcNationalCityRankingHourServiceImpl extends ServiceImpl<PcNationalCityRankingHourMapper, PcNationalCityRankingHour> implements PcNationalCityRankingHourService{

    @Autowired
    private  PcNationalCityRankingHourMapper pcNationalCityRankingHourMapper;

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

    @Override
    public void doProcessCityRankHour() {
        Date lastHour = DateUtils.addHours(new Date(),-1);
        Date lastHourDate = DateUtils.parseFormatDate("yyyy-MM-dd HH:00:00",lastHour);
        List<PcNationalCityRankingHour> rankList = pcNationalCityRankingHourMapper.selectHourRankData(lastHourDate);
        AtomicInteger rank = new AtomicInteger();
        if(rankList!=null&&rankList.size()>0){
            rankList.forEach(r->{
                rank.getAndIncrement();
                r.setIndexProvinceCity(String.valueOf(rank.get()));
            });

            pcNationalCityRankingHourMapper.updateBatchIndexProvince(rankList);
        }
    }
}
