package com.ruoyi.system.service.impl;

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.dto.WebSiteTenDaysHitsDTO;
import com.ruoyi.system.mapper.VisitingWebsiteRankingMapper;
import com.ruoyi.system.mapper.WebSiteTenDaysHitsMapper;
import com.ruoyi.system.service.IVisitingWebsiteRankingService;
import com.ruoyi.system.service.IWebSiteTenDaysHitsService;
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 WebSiteTenDaysHitsServiceImpl implements IWebSiteTenDaysHitsService {


    @Autowired
    private WebSiteTenDaysHitsMapper webSiteTenDaysHitsMapper;


    @Override
    public Map<String, List<String>> selectWebSiteTenDaysHitsList() {
        List<String> timeNamesList = new ArrayList<>();
        List<String> timeDatasList = new ArrayList<>();
        List<WebSiteTenDaysHits> list = webSiteTenDaysHitsMapper.selectWebSiteTenDaysHitsList();
        for (WebSiteTenDaysHits var : list) {
            timeNamesList.add(var.getTimeNames());
            timeDatasList.add(var.getTimeDatas());
        }
        Map<String, List<String>> returnMap = new HashMap<>();
        returnMap.put("timeNames",timeNamesList);
        returnMap.put("timeDatas",timeDatasList);
        return returnMap;
    }

    @Override
    public void insertBatch(WebSiteTenDaysHitsDTO dto) {
        if (!CollectionUtils.isEmpty(dto.getTimeDatas()) && !CollectionUtils.isEmpty(dto.getTimeNames())) {
            webSiteTenDaysHitsMapper.deleteWebSiteTenDaysHitsAll();
        }
        List<WebSiteTenDaysHits> saveList = new ArrayList<>();
        for (int i = 0; i < dto.getTimeNames().size(); i++) {
            WebSiteTenDaysHits webSiteTenDaysHits = new WebSiteTenDaysHits();
            webSiteTenDaysHits.setTimeNames(dto.getTimeNames().get(i));
            webSiteTenDaysHits.setTimeDatas(dto.getTimeDatas().get(i));
            saveList.add(webSiteTenDaysHits);
        }
        webSiteTenDaysHitsMapper.insertBatch(saveList);
    }
}
