From 1157a16f1be979f062ef49f7b76a545ecc231dc9 Mon Sep 17 00:00:00 2001 From: cmg <527198563@qq.com> Date: 星期五, 16 八月 2024 11:01:00 +0800 Subject: [PATCH] 杭州全民健康数据 --- src/main/java/com/hx/util/MapUtil.java | 41 +++++++++++++++++++++++++++++++++++++---- 1 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hx/util/MapUtil.java b/src/main/java/com/hx/util/MapUtil.java index 22ae85c..392bae2 100644 --- a/src/main/java/com/hx/util/MapUtil.java +++ b/src/main/java/com/hx/util/MapUtil.java @@ -1,5 +1,6 @@ package com.hx.util; +import java.math.BigDecimal; import java.util.Map; /** @@ -34,12 +35,12 @@ */ public static int getInt(Map<String, Object> map, String key) { - if(map == null || StringUtils.isEmpty(key)) + if(map == null || StringUtils.isEmpty(key) || null == map.get(key) || StringUtils.isEmpty(map.get(key).toString())) { return -1; } - return null == map.get(key) ? -1 : Integer.parseInt(map.get(key).toString()); + return Integer.parseInt(map.get(key).toString()); } /** @@ -50,11 +51,43 @@ */ public static int getIntZero(Map<String, Object> map, String key) { - if(map == null || StringUtils.isEmpty(key)) + if(map == null || StringUtils.isEmpty(key) || null == map.get(key) || StringUtils.isEmpty(map.get(key).toString())) { return 0; } - return null == map.get(key) ? 0 : Integer.parseInt(map.get(key).toString()); + return Integer.parseInt(map.get(key).toString()); + } + + /** + * 浠巑ap涓幏鍙栨暟瀛楃被鍨嬪璞� + * @param map + * @param key + * @return + */ + public static BigDecimal getBigDecimal(Map<String, Object> map, String key) + { + if(map == null || StringUtils.isEmpty(key)) + { + return BigDecimal.ZERO; + } + + return null == map.get(key) ? BigDecimal.ZERO : new BigDecimal(map.get(key).toString()); + } + + /** + * 鑾峰彇娴偣鏁帮紝榛樿杩斿洖0 + * @param map + * @param key + * @return + */ + public static Double getDoubleZero(Map<String, Object> map, String key) + { + if(map == null || StringUtils.isEmpty(key)) + { + return 0D; + } + + return null == map.get(key) ? 0D : Double.parseDouble(map.get(key).toString()); } } -- Gitblit v1.8.0