鞍钢鲅鱼圈能源管控系统后端代码
潘志宝
2025-04-13 d79903f517beb832aa77939e804d5fd6bd654b10
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
package com.iailab.module.ansteel.common.utils;
 
import com.alibaba.fastjson.JSONArray;
import com.iailab.module.ansteel.api.vo.PowerTransferDetRespVO;
import org.apache.commons.lang3.StringUtils;
 
import java.math.BigDecimal;
 
/**
 * @author PanZhibao
 * @Description
 * @createTime 2025年03月28日
 */
public class DecimalUtil {
 
    public static BigDecimal toBigDecimal(Object o) {
        if (o == null) {
            return null;
        }
        if (StringUtils.isBlank(o.toString())) {
            return null;
        }
        return new BigDecimal(o.toString());
    }
 
    public static BigDecimal toBigDecimal(Object o, int index) {
        if (o == null) {
            return null;
        }
        if (StringUtils.isBlank(o.toString())) {
            return null;
        }
        JSONArray array = JSONArray.parseArray(o.toString());
        if (array.size() <= index) {
            return null;
        }
        Object obj = array.get(index);
        return DecimalUtil.toBigDecimal(obj);
    }
 
    public static PowerTransferDetRespVO toPowerTransferDetRespVO(String title, Object o) {
        PowerTransferDetRespVO respVO = new PowerTransferDetRespVO();
        if (o == null) {
            return null;
        }
        respVO.setTitle(title);
        respVO.setStart(toBigDecimal(o, 0).intValue());
        respVO.setMins(toBigDecimal(o, 1).intValue());
        respVO.setAmount(toBigDecimal(o, 2));
        return respVO;
    }
}