package com.dxhy.common.service.impl;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.dxhy.common.constant.RedisConstant;
import com.dxhy.common.service.DictdetaServcice;
import com.dxhy.common.util.redis.RedisUtils;
import com.dxhy.common.vo.DictdetaModel;

/**
 * @author jiaohongyang
 */
@Service("dictdetaServcice")
@Slf4j
public class DictdetaServciceImpl implements DictdetaServcice {
    @Resource
    private RedisUtils redisUtils;

    @Override
    public List<DictdetaModel> selectDictdeta(String code) {
        String dictJson = redisUtils.get(RedisConstant.KEY_DICT + code);
        return JSON.parseArray(dictJson, DictdetaModel.class);
    }

    @Override
    public String queryDictName(String type,String code) {
        String dictJson = redisUtils.get(RedisConstant.KEY_DICT + type);
        List<DictdetaModel> dictdetaModels = JSON.parseArray(dictJson, DictdetaModel.class);
        Map<String, String> collect = dictdetaModels.stream().collect(Collectors.toMap(DictdetaModel::getDictcode, DictdetaModel::getDictname));
        String dictName = collect.get(code);
        if(StringUtils.isNotBlank(dictName)){
            return dictName;
        } else {
            return "";
        }
    }

}
