package com.prolog.rdc.tms.app.util;

import cn.hutool.core.collection.CollectionUtil;
import com.google.common.collect.Lists;
import com.prolog.rdc.tms.model.dto.message.SendMessageDTO;

import java.util.List;

/**
 * @author hongbo.pan
 * @date 2022/11/21
 */
public class MessageUtil {

    private static final ThreadLocal<List<SendMessageDTO>> threadLocal = new ThreadLocal<>();

    private MessageUtil() {}


    public static void addMessage(SendMessageDTO sendMessageDTO) {
        List<SendMessageDTO> list = threadLocal.get();
        if (CollectionUtil.isEmpty(list)) {
            list = Lists.newArrayList();
        }
        list.add(sendMessageDTO);
        threadLocal.set(list);
    }

    public static List<SendMessageDTO> getMessage() {
        return threadLocal.get();
    }

    public static void remove() {
        threadLocal.remove();
    }
}
