package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.UnableToAccessWebsiteListToday;
import com.ruoyi.system.domain.VisitingWebsiteRanking;
import com.ruoyi.system.domain.WebSiteTenDaysHits;
import com.ruoyi.system.domain.WebsiteAvailabilityMonitor;
import com.ruoyi.system.dto.VisitingWebsiteRankingDTO;
import com.ruoyi.system.mapper.VisitingWebsiteRankingMapper;
import com.ruoyi.system.mapper.WebsiteAvailabilityMonitorMapper;
import com.ruoyi.system.service.IVisitingWebsiteRankingService;
import com.ruoyi.system.service.IWebsiteAvailabilityMonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class VisitingWebsiteRankingServiceImpl implements IVisitingWebsiteRankingService {


    @Autowired
    private VisitingWebsiteRankingMapper visitingWebsiteRankingMapper;


    @Override
    public Map<String, List<String>> selectVisitingWebsiteRankingList() {
        List<String> deptNamesList = new ArrayList<>();
        List<String> deptDatasList = new ArrayList<>();
        List<VisitingWebsiteRanking> list = visitingWebsiteRankingMapper.selectVisitingWebsiteRankingList();
        for (VisitingWebsiteRanking var : list) {
            deptNamesList.add(var.getDeptNames());
            deptDatasList.add(var.getDeptDatas());
        }
        Map<String, List<String>> returnMap = new HashMap<>();
        returnMap.put("deptNames",deptNamesList);
        returnMap.put("deptDatas",deptDatasList);
        return returnMap;
    }

    @Override
    public void insertBatch(VisitingWebsiteRankingDTO dto) {
        if (!CollectionUtils.isEmpty(dto.getDeptDatas()) && !CollectionUtils.isEmpty(dto.getDeptNames())) {
            visitingWebsiteRankingMapper.deleteVisitingWebsiteRankingAll();
        }
        List<VisitingWebsiteRanking> saveList = new ArrayList<>();
        for (int i = 0; i < dto.getDeptNames().size(); i++) {
            VisitingWebsiteRanking visitingWebsiteRanking = new VisitingWebsiteRanking();
            visitingWebsiteRanking.setDeptNames(dto.getDeptNames().get(i));
            visitingWebsiteRanking.setDeptDatas(dto.getDeptDatas().get(i));
            saveList.add(visitingWebsiteRanking);
        }
        visitingWebsiteRankingMapper.insertBatch(saveList);
    }
}
