package com.pj.project.tb_business;

import com.pj.utils.cache.RedisUtil;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class BusinessMessageManager {
    private static String MES_PREFIX = "b_m:";
    private static long EXP_TIME_SECOND = 24 * 60;

    public static void set(String customerId, String content) {
        List<Object> list = RedisUtil.forListGet(MES_PREFIX + customerId);
        List<String>checkList=list.stream().map(Object::toString).collect(Collectors.toList());
        if (checkList.contains(content)) {
            return;
        }
        RedisUtil.forListAdd(MES_PREFIX + customerId, content);
    }

    public static List<String> get(String customerId) {
        List<Object> list = RedisUtil.forListGet(MES_PREFIX + customerId);
        RedisUtil.forListRemove(MES_PREFIX+customerId);
        return list == null ? Collections.emptyList() : list.stream().map(Object::toString).collect(Collectors.toList());
    }
}
