package com.ruoyi.system.service.impl;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.WebsiteAvailabilityMonitor;
import com.ruoyi.system.mapper.WebsiteAvailabilityMonitorMapper;
import com.ruoyi.system.service.IWebsiteAvailabilityMonitorService;
import com.ruoyi.websocket.WebSocketUsers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

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

import static com.ruoyi.common.core.domain.AjaxResult.success;


@Service
public class WebsiteAvailabilityMonitorServiceImpl implements IWebsiteAvailabilityMonitorService {

    @Autowired
    private WebsiteAvailabilityMonitorMapper websiteAvailabilityMonitorMapper;

    @Override
    public List<WebsiteAvailabilityMonitor> selectWebsiteAvailabilityMonitorList() {
        return websiteAvailabilityMonitorMapper.selectWebsiteAvailabilityMonitorList();
    }

    /**
     * 网站可用性实时监测-数据推送接口
     */
    @Override
    public void insertBatch(List<WebsiteAvailabilityMonitor> list) {
        if (!CollectionUtils.isEmpty(list)) {
            websiteAvailabilityMonitorMapper.deleteWebsiteAvailabilityMonitorAll();
        }
        websiteAvailabilityMonitorMapper.insertBatch(list);
        WebSocketUsers.sendMessageToUsersByText(JSON.toJSONString(success(AjaxResult.Type.TYPE_FOURTEEN,list)));
    }

}
