Administrator
5 days ago f2c1b2853b2f0d0a0efb95a9c8df95ec1da908ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.xcong.excoin.modules.okxNewPrice.utils;
 
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.CoinEnums;
import lombok.extern.slf4j.Slf4j;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Map;
 
/**
 * @author Administrator
 */
@Slf4j
public class WsMapBuild {
 
    public static boolean saveBigDecimalToMap(Map<String,BigDecimal> accountMap, String key, BigDecimal value) {
        try {
            accountMap.put(key, value);
            return true;
        } catch (Exception e) {
            log.error("保存账户数据到MAP 失败", e);
            return false;
        }
    }
 
    public static boolean saveStringToMap(Map<String,String> accountMap, String key, String value) {
        try {
            accountMap.put(key, value);
            return true;
        } catch (Exception e) {
            log.error("保存账户数据到MAP 失败", e);
            return false;
        }
    }
 
 
    /**
     * 安全地将字符串解析为 BigDecimal 类型
     *
     * @param value 字符串数值
     * @return 解析后的 BigDecimal 对象,若解析失败则返回 null
     */
    public static BigDecimal parseBigDecimalSafe(String value) {
        if (value == null || value.isEmpty()) {
            return new BigDecimal(0);
        }
        return new BigDecimal(value).setScale(Integer.parseInt(CoinEnums.TICKSZ.getCode()), RoundingMode.DOWN);
    }
 
    /**
     * 安全地将字符串解析为 BigDecimal 类型
     *
     * @param value 字符串数值
     * @return 解析后的 BigDecimal 对象,若解析失败则返回 null
     */
    public static String parseStringSafe(String value) {
        if (value == null || value.isEmpty()) {
            return "0";
        }
        return value;
    }
}