shiyunteng
2026-10-23 c5ea85558fea4d82b5368073c598a30f905c4bdc
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.by4cloud.platformx.business.vo;
 
import cn.hutool.core.util.StrUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
 
import java.math.BigDecimal;
 
@Data
public class AnnualPlanTotalVo {
 
    @Schema(description = "1月金额")
    private BigDecimal janAmount;
 
    @Schema(description = "2月金额")
    private BigDecimal febAmount;
 
    @Schema(description = "3月金额")
    private BigDecimal marAmount;
 
    @Schema(description = "4月金额")
    private BigDecimal aprAmount;
 
    @Schema(description = "5月金额")
    private BigDecimal mayAmount;
 
    @Schema(description = "6月金额")
    private BigDecimal junAmount;
 
    @Schema(description = "7月金额")
    private BigDecimal julAmount;
 
    @Schema(description = "8月金额")
    private BigDecimal augAmount;
 
    @Schema(description = "9月金额")
    private BigDecimal sepAmount;
 
    @Schema(description = "10月金额")
    private BigDecimal octAmount;
 
    @Schema(description = "11月金额")
    private BigDecimal novAmount;
 
    @Schema(description = "12月金额")
    private BigDecimal decAmount;
 
 
    public BigDecimal getTotalAmount() {
        // 使用 Optional 或三元运算符处理 null 值,防止 NullPointerException
        BigDecimal b1 = janAmount == null ? BigDecimal.ZERO : janAmount;
        BigDecimal b2 = febAmount == null ? BigDecimal.ZERO : febAmount;
        BigDecimal b3 = marAmount == null ? BigDecimal.ZERO : marAmount;
        BigDecimal b4 = aprAmount == null ? BigDecimal.ZERO : aprAmount;
        BigDecimal b5 = mayAmount == null ? BigDecimal.ZERO : mayAmount;
        BigDecimal b6 = junAmount == null ? BigDecimal.ZERO : junAmount;
        BigDecimal b7 = julAmount == null ? BigDecimal.ZERO : julAmount;
        BigDecimal b8 = augAmount == null ? BigDecimal.ZERO : augAmount;
        BigDecimal b9 = sepAmount == null ? BigDecimal.ZERO : sepAmount;
        BigDecimal b10 = octAmount == null ? BigDecimal.ZERO : octAmount;
        BigDecimal b11 = novAmount == null ? BigDecimal.ZERO : novAmount;
        BigDecimal b12 = decAmount == null ? BigDecimal.ZERO : decAmount;
 
        return b1.add(b2).add(b3).add(b4).add(b5).add(b6).add(b7).add(b8).add(b9).add(b10).add(b11).add(b12);
    }
 
    public BigDecimal getMonthAmount(String month) {
        // 使用 Optional 或三元运算符处理 null 值,防止 NullPointerException
        if (StrUtil.equals("1",month)||StrUtil.equals("01",month)){
            return janAmount;
        }
        if (StrUtil.equals("2",month)||StrUtil.equals("02",month)){
            return febAmount;
        }
        if (StrUtil.equals("3",month)||StrUtil.equals("03",month)){
            return marAmount;
        }
        if (StrUtil.equals("4",month)||StrUtil.equals("04",month)){
            return aprAmount;
        }
        if (StrUtil.equals("5",month)||StrUtil.equals("05",month)){
            return mayAmount;
        }
        if (StrUtil.equals("6",month)||StrUtil.equals("06",month)){
            return junAmount;
        }
        if (StrUtil.equals("7",month)||StrUtil.equals("07",month)){
            return julAmount;
        }
        if (StrUtil.equals("8",month)||StrUtil.equals("08",month)){
            return augAmount;
        }
        if (StrUtil.equals("9",month)||StrUtil.equals("09",month)){
            return sepAmount;
        }
        if (StrUtil.equals("10",month)){
            return octAmount;
        }
        if (StrUtil.equals("11",month)){
            return novAmount;
        }
        if (StrUtil.equals("12",month)){
            return decAmount;
        }
        return new BigDecimal("0");
    }
}