package com.gyee.frame.service.websocket.task;


import com.gyee.frame.common.websocket.WebSocketConfig;
import com.gyee.frame.common.websocket.WebsocketMessageService;
import com.gyee.frame.service.websocket.GenreSetPushService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

@Component
public class GenreSetPushTask {
    @Resource
    private GenreSetPushService genreSetPushService;
    @Resource
    private WebsocketMessageService websocketMessageService;

    private final String QS = "0";
    private final String FD = "-1";
    private final String GF = "-2";

    public void genreSetTask(String destination) throws Exception {

        Map<String, Object> map = new HashMap<>();


        Set<Map.Entry<String, CopyOnWriteArraySet<String>>> set = WebSocketConfig.websocketparamcacheMap.entrySet();
        for (Iterator<Map.Entry<String, CopyOnWriteArraySet<String>>> it = set.iterator(); it.hasNext();) {
            Map.Entry<String, CopyOnWriteArraySet<String>> entry = (Map.Entry<String, CopyOnWriteArraySet<String>>) it.next();
            // System.out.println(entry.getKey() + "--->" + entry.getValue());
            if(entry.getKey().indexOf(destination)!=-1)
            {
                String id=entry.getKey().substring(entry.getKey().indexOf(WebSocketConfig.PARAM)+6);

                map = genreSetPushService.findBasicDataInfo(id);
                websocketMessageService.SendAlertToAll(entry.getKey(),map);
            }
        }

        websocketMessageService.SendAlertToAll(destination, map);

    }
}
