DictionaryServiceImpl.java 1.02 KB
package vion.service.impl;

import com.github.yulichang.base.MPJBaseServiceImpl;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.lang.Opt;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;
import vion.constant.RedisKeyEnum;
import vion.mapper.DictionaryMapper;
import vion.model.Dictionary;
import vion.service.IDictionaryService;

import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class DictionaryServiceImpl extends MPJBaseServiceImpl<DictionaryMapper, Dictionary> implements IDictionaryService {

    private final RedissonClient redissonClient;

    @Override
    public void syncDict() {
        Opt.ofEmptyAble(this.list())
                .map(l -> l.stream().collect(Collectors.groupingBy(Dictionary::getType, Collectors.toMap(d -> d.getKey().toString(), Dictionary::getValue))))
                .ifPresent(m -> m.forEach((type, map) -> redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.getValByKey(type)).putAll(map)));
    }
}