package com.ruoyi.benyun.service.impl;

import com.ruoyi.benyun.mapper.BusinessOpportunitiesDao;
import com.ruoyi.benyun.mapper.FollowUpDao;
import com.ruoyi.benyun.service.DatabackService;
import com.ruoyi.benyun.mapper.AttentionPoolDao;
import com.ruoyi.benyun.mapper.AttentionPoolStatisticsDao;
import com.ruoyi.benyun.entity.AttentionPoolStatistics;
import com.ruoyi.benyun.entity.bo.AttentionPoolStatisticsBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DatabackServiceImpl implements DatabackService {
    @Autowired
    AttentionPoolStatisticsDao attentionPoolStatisticsDao;
    @Autowired
    AttentionPoolDao attentionPoolDao;
    @Autowired
    BusinessOpportunitiesDao businessOpportunitiesDao;
    @Autowired
    FollowUpDao followUpDao;

    @Override
    public AttentionPoolStatisticsBo searchAbout(String userId) {
        int attentionCount = attentionPoolDao.searchCountByUserId(userId);
        int clueCount = businessOpportunitiesDao.searchCountByUserId(userId);
        int onlineCount = followUpDao.searchCountByUserIdAndWay(userId, "线上电话");
        int offlineCount = followUpDao.searchCountByUserIdAndWay(userId, "实地考察");
        AttentionPoolStatisticsBo bo = new AttentionPoolStatisticsBo();
        bo.setAttentionCount(attentionCount);
        bo.setClueCount(clueCount);
        bo.setOnlineCount(onlineCount);
        bo.setOfflineCount(offlineCount);
        return bo;
    }

    @Override
    public List<AttentionPoolStatisticsBo> searchTrand(String userId) {
        List<AttentionPoolStatistics> list = attentionPoolStatisticsDao.searchAllByUserId(userId);
        List<AttentionPoolStatisticsBo> boList = new ArrayList<>();
        for (AttentionPoolStatistics aps : list){
            AttentionPoolStatisticsBo apsb = new AttentionPoolStatisticsBo();
            apsb.setAttentionCount(aps.getAttentionCount());
            apsb.setClueCount(aps.getClueCount());
            apsb.setOnlineCount(aps.getOnlineCount());
            apsb.setOfflineCount(aps.getOfflineCount());
            apsb.setTime(aps.getStatTime());
            boList.add(apsb);
        }
        return boList;
    }
}
