shiyunteng
1 天以前 8de09297dcc5393cc8542f29318b17f5696d4f8d
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package com.by4cloud.platformx.business.vo;
 
import lombok.Data;
 
import java.math.BigDecimal;
 
@Data
public class HomeZgsVo {
 
    private BigDecimal hbbr;
 
    private BigDecimal hbby;
 
    private BigDecimal hbbn;
 
    private BigDecimal xbbr;
 
    private BigDecimal xbby;
 
    private BigDecimal xbbn;
 
    private BigDecimal dbbr;
 
    private BigDecimal dbby;
 
    private BigDecimal dbbn;
 
    private BigDecimal hdbr;
 
    private BigDecimal hdby;
 
    private BigDecimal hdbn;
 
    private BigDecimal xnbr;
 
    private BigDecimal xnby;
 
    private BigDecimal xnbn;
 
    private BigDecimal znbr;
 
    private BigDecimal znby;
 
    private BigDecimal znbn;
 
    private BigDecimal hwbr;
 
    private BigDecimal hwby;
 
    private BigDecimal hwbn;
 
    /**
     * 当前对象减去另一个同类型对象的所有 BigDecimal 字段
     * @param other 被减数对象
     * @return 新的 HomeZbjtVo 对象,包含相减后的结果
     */
    public HomeZgsVo subtract(HomeZgsVo other) {
        if (other == null) {
            // 如果减数为空,返回当前对象的副本(或根据业务逻辑返回当前对象)
            return this.copy();
        }
 
        HomeZgsVo result = new HomeZgsVo();
 
        // 对每个字段执行减法运算
        // 注意:处理 null 值,防止 NullPointerException
        result.setHbbr(safeSubtract(this.hbbr,other.hbbr));
        result.setHbby(safeSubtract(this.hbby,other.hbby));
        result.setHbbn(safeSubtract(this.hbbn,other.hbbn));
        result.setXbbr(safeSubtract(this.xbbr,other.xbbr));
        result.setXbby(safeSubtract(this.xbby,other.xbby));
        result.setXbbn(safeSubtract(this.xbbn,other.xbbn));
        result.setDbbr(safeSubtract(this.dbbr,other.dbbr));
        result.setDbby(safeSubtract(this.dbby,other.dbby));
        result.setDbbn(safeSubtract(this.dbbn,other.dbbn));
        result.setHwbr(safeSubtract(this.hwbr,other.hwbr));
        result.setHwby(safeSubtract(this.hwby,other.hwby));
        result.setHwbn(safeSubtract(this.hwbn,other.hwbn));
        // ... 对其他所有 BigDecimal 字段执行相同操作
 
        return result;
    }
 
    /**
     * 安全减法工具方法:处理 null 值情况
     * 规则:null 视为 0
     */
    private BigDecimal safeSubtract(BigDecimal minuend, BigDecimal subtrahend) {
        BigDecimal val1 = minuend == null ? BigDecimal.ZERO : minuend;
        BigDecimal val2 = subtrahend == null ? BigDecimal.ZERO : subtrahend;
        return val1.subtract(val2);
    }
 
    /**
     * 辅助方法:复制当前对象(用于减数为null时的返回)
     */
    public HomeZgsVo copy() {
        HomeZgsVo copy = new HomeZgsVo();
        copy.setHbbr(this.hbbr);
        copy.setHbby(this.hbby);
        copy.setHbbn(this.hbbn);
        copy.setXbbr(this.xbbr);
        copy.setXbby(this.xbby);
        copy.setXbbn(this.xbby);
        copy.setDbbr(this.dbbr);
        copy.setDbby(this.dbby);
        copy.setDbbn(this.dbbn);
        copy.setHwbr(this.hwbr);
        copy.setHwby(this.hwby);
        copy.setHwbn(this.hwbn);
        copy.setHdbr(this.hdbr);
        copy.setHdby(this.hdby);
        copy.setHdbn(this.hdbn);
        copy.setXnbr(this.xnbr);
        copy.setXnby(this.xnby);
        copy.setXnbn(this.xnbr);
        copy.setZnbr(this.znbr);
        copy.setZnby(this.znby);
        copy.setZnbn(this.znbn);
        // ... 复制其他字段
        return copy;
    }
 
    /**
     * 当前对象减去另一个同类型对象的所有 BigDecimal 字段
     * @param other 被减数对象
     * @return 新的 HomeZbjtVo 对象,包含相减后的结果
     */
    public HomeZgsVo add(HomeZgsVo other) {
        if (other == null) {
            // 如果减数为空,返回当前对象的副本(或根据业务逻辑返回当前对象)
            return this.copy();
        }
 
        HomeZgsVo result = new HomeZgsVo();
 
        // 对每个字段执行减法运算
        // 注意:处理 null 值,防止 NullPointerException
        result.setHbbr(safeAdd(this.hbbr,other.hbbr));
        result.setHbby(safeAdd(this.hbby,other.hbby));
        result.setHbbn(safeAdd(this.hbbn,other.hbbn));
        result.setXbbr(safeAdd(this.xbbr,other.xbbr));
        result.setXbby(safeAdd(this.xbby,other.xbby));
        result.setXbbn(safeAdd(this.xbbn,other.xbbn));
        result.setDbbr(safeAdd(this.dbbr,other.dbbr));
        result.setDbby(safeAdd(this.dbby,other.dbby));
        result.setDbbn(safeAdd(this.dbbn,other.dbbn));
        result.setHwbr(safeAdd(this.hwbr,other.hwbr));
        result.setHwby(safeAdd(this.hwby,other.hwby));
        result.setHwbn(safeAdd(this.hwbn,other.hwbn));
        result.setHdbr(safeAdd(this.hdbr,other.hdbr));
        result.setHdby(safeAdd(this.hdby,other.hdby));
        result.setHdbn(safeAdd(this.hdbn,other.hdbn));
        result.setXnbr(safeAdd(this.xnbr,other.xnbr));
        result.setXnby(safeAdd(this.xnby,other.xnby));
        result.setXnbn(safeAdd(this.xnbn,other.xnbn));
        result.setZnbr(safeAdd(this.znbr,other.znbr));
        result.setZnby(safeAdd(this.znby,other.znby));
        result.setZnbn(safeAdd(this.znbn,other.znbn));
        // ... 对其他所有 BigDecimal 字段执行相同操作
 
        return result;
    }
 
    /**
     * 安全减法工具方法:处理 null 值情况
     * 规则:null 视为 0
     */
    private BigDecimal safeAdd(BigDecimal minuend, BigDecimal subtrahend) {
        BigDecimal val1 = minuend == null ? BigDecimal.ZERO : minuend;
        BigDecimal val2 = subtrahend == null ? BigDecimal.ZERO : subtrahend;
        return val1.add(val2);
    }
 
}