package com.lantone.common.service.impl;

import com.lantone.common.constant.AuthConstant;
import com.lantone.common.service.DictSetsService;
import com.lantone.common.service.RedisService;
import com.lantone.common.util.ListUtil;
import com.lantone.common.util.StringUtil;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 字典及医院个性化配置信息获取工具类
 * @author: rengb
 * @time: 2022/4/11 13:36
 */
public class DictSetsServiceImpl implements DictSetsService {

    @Autowired
    private RedisService redisService;

    @Override
    public Map<String, Map<String, String>> getDicMap(String returnType, List<String> groupTypes) {
        Map<String, Map<String, String>> outDicMap = new HashMap<>();
        Map<String, Map<String, Map<String, String>>> dicMap = redisService.get(AuthConstant.DIC_MAP_KEY);
        Map<String, Map<String, String>> returnDicMap = dicMap.get(returnType);
        if (MapUtils.isNotEmpty(returnDicMap) && ListUtil.isNotEmpty(groupTypes)) {
            groupTypes.stream().forEach(groupType -> {
                outDicMap.put(groupType, returnDicMap.get(groupType));
            });
        }
        return outDicMap;
    }

    @Override
    public Map<String, String> getOneDicMap(String returnType, String groupType) {
        Map<String, Map<String, Map<String, String>>> dicMap = redisService.get(AuthConstant.DIC_MAP_KEY);
        Map<String, Map<String, String>> returnDicMap = dicMap.get(returnType);
        if (MapUtils.isNotEmpty(returnDicMap) && StringUtil.isNotBlank(groupType)) {
            return returnDicMap.get(groupType);
        }
        return null;
    }

    @Override
    public Map<String, String> getHospitalCodeMap(String hospitalId, String code) {
        Map<String, Map<String, Map<String, String>>> hospitalSetMap = redisService.get(AuthConstant.HOSPITAL_SET_MAP_KEY);
        Map<String, Map<String, String>> codeMap = hospitalSetMap.get(hospitalId);
        if (org.apache.commons.collections4.MapUtils.isNotEmpty(codeMap) && StringUtil.isNotBlank(code)) {
            return codeMap.get(code);
        }
        return null;
    }

}