package com.ruoyi.benyun.utils.statistics;

import com.ruoyi.benyun.entity.AttentionPoolStatistics;
import com.ruoyi.benyun.mapper.AttentionPoolDao;
import com.ruoyi.benyun.mapper.AttentionPoolStatisticsDao;
import com.ruoyi.benyun.mapper.BusinessOpportunitiesDao;
import com.ruoyi.benyun.mapper.FollowUpDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;
import java.util.UUID;

@Component
public class AttentionPoolStat {
    @Autowired
    AttentionPoolDao poolDao;
    @Autowired
    BusinessOpportunitiesDao opportunitiesDao;
    @Autowired
    FollowUpDao followUpDao;
    @Autowired
    AttentionPoolStatisticsDao statisticsDao;

    public void insert(){
        List<String> ins = poolDao.selectAllUser();
        for (String userId : ins){
            AttentionPoolStatistics statistics = new AttentionPoolStatistics();
            statistics.setStatId(UUID.randomUUID().toString().replace("-",""));
            statistics.setAttentionCount(poolDao.selectCount(userId));
            statistics.setClueCount(opportunitiesDao.selectCount(userId));
            statistics.setOnlineCount(followUpDao.selectCountByWay(userId,"线上电话"));
            statistics.setOfflineCount(followUpDao.selectCountByWay(userId,"线下实地"));
            statistics.setUserId(userId);
            statistics.setStatTime(LocalDateTime.now(ZoneId.of("Asia/Shanghai")));
            statisticsDao.insert(statistics);
        }
    }
}
