package com.ruoyi.common.utils;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.Map;

public class MapUtils {

    private static Map<String, Object> getSafeMap(Map<String, Object> source, String key) {
        Object obj = (source != null) ? source.get(key) : null;
        return (obj instanceof Map) ? (Map<String, Object>) obj : Collections.emptyMap();
    }

    public static String getSafeString(Map<String, Object> source, String key) {
        Object obj = (source != null) ? source.get(key) : null;
        return (obj != null) ? obj.toString() : "";
    }

    public static Number getNumber(Map<String, Object> source, String key) {
        Object value = (source != null) ? source.get(key) : null;
        if (value instanceof Number) {
            return (Number) value;
        } else if (value != null && !"".equals(value)) {
            try {
                return new BigDecimal(value.toString());
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

}
