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
package com.by4cloud.platformx.business.vo;
 
import lombok.Data;
 
import java.math.BigDecimal;
 
@Data
public class HomeZbjtVo {
 
    private BigDecimal sgbbr;
 
    private BigDecimal sgbby;
 
    private BigDecimal sgbbn;
 
    private BigDecimal smjbr;
 
    private BigDecimal smjby;
 
    private BigDecimal smjbn;
 
    private BigDecimal jxcbr;
 
    private BigDecimal jxcby;
 
    private BigDecimal jxcbn;
 
    private BigDecimal tfbr;
 
    private BigDecimal tfby;
 
    private BigDecimal tfbn;
 
    private BigDecimal ymjbr;
 
    private BigDecimal ymjby;
 
    private BigDecimal ymjbn;
 
    /**
     * 当前对象减去另一个同类型对象的所有 BigDecimal 字段
     * @param other 被减数对象
     * @return 新的 HomeZbjtVo 对象,包含相减后的结果
     */
    public HomeZbjtVo subtract(HomeZbjtVo other) {
        if (other == null) {
            // 如果减数为空,返回当前对象的副本(或根据业务逻辑返回当前对象)
            return this.copy();
        }
 
        HomeZbjtVo result = new HomeZbjtVo();
 
        // 对每个字段执行减法运算
        // 注意:处理 null 值,防止 NullPointerException
        result.setSgbbr(safeSubtract(this.sgbbr, other.sgbbr));
        result.setSgbby(safeSubtract(this.sgbby, other.sgbby));
        result.setSgbbn(safeSubtract(this.sgbbn, other.sgbbn));
        result.setSmjbr(safeSubtract(this.smjbr, other.smjbr));
        result.setSmjby(safeSubtract(this.smjby, other.smjby));
        result.setSmjbn(safeSubtract(this.smjbn, other.smjbn));
        result.setJxcbr(safeSubtract(this.jxcbr, other.jxcbr));
        result.setJxcby(safeSubtract(this.jxcby, other.jxcby));
        result.setJxcbn(safeSubtract(this.jxcbn, other.jxcbn));
        result.setTfbr(safeSubtract(this.tfbr, other.tfbr));
        result.setTfby(safeSubtract(this.tfby, other.tfby));
        result.setTfbn(safeSubtract(this.tfbn, other.tfbn));
        result.setYmjbr(safeSubtract(this.ymjbr, other.ymjbr));
        result.setYmjby(safeSubtract(this.ymjby, other.ymjby));
        result.setYmjbn(safeSubtract(this.ymjby, other.ymjby));
        // ... 对其他所有 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 HomeZbjtVo copy() {
        HomeZbjtVo copy = new HomeZbjtVo();
        copy.setSgbbr(this.sgbbr);
        copy.setSgbby(this.sgbby);
        copy.setSgbbn(this.sgbbn);
        copy.setSmjbr(this.smjbr);
        copy.setSmjby(this.smjby);
        copy.setSmjbn(this.smjbn);
        copy.setJxcbr(this.jxcbr);
        copy.setJxcby(this.jxcby);
        copy.setJxcbn(this.jxcbn);
        copy.setTfbr(this.tfbr);
        copy.setTfby(this.tfby);
        copy.setTfbn(this.tfbn);
        copy.setYmjbr(this.ymjbr);
        copy.setYmjby(this.ymjby);
        copy.setYmjbn(this.ymjby);
        // ... 复制其他字段
        return copy;
    }
 
 
    /**
     * 当前对象减去另一个同类型对象的所有 BigDecimal 字段
     * @param other 被减数对象
     * @return 新的 HomeZbjtVo 对象,包含相减后的结果
     */
    public HomeZbjtVo add(HomeZbjtVo other) {
        if (other == null) {
            // 如果减数为空,返回当前对象的副本(或根据业务逻辑返回当前对象)
            return this.copy();
        }
 
        HomeZbjtVo result = new HomeZbjtVo();
 
        // 对每个字段执行减法运算
        // 注意:处理 null 值,防止 NullPointerException
        result.setSgbbr(safeAdd(this.sgbbr, other.sgbbr));
        result.setSgbby(safeAdd(this.sgbby, other.sgbby));
        result.setSgbbn(safeAdd(this.sgbbn, other.sgbbn));
        result.setSmjbr(safeAdd(this.smjbr, other.smjbr));
        result.setSmjby(safeAdd(this.smjby, other.smjby));
        result.setSmjbn(safeAdd(this.smjbn, other.smjbn));
        result.setJxcbr(safeAdd(this.jxcbr, other.jxcbr));
        result.setJxcby(safeAdd(this.jxcby, other.jxcby));
        result.setJxcbn(safeAdd(this.jxcbn, other.jxcbn));
        result.setTfbr(safeAdd(this.tfbr, other.tfbr));
        result.setTfby(safeAdd(this.tfby, other.tfby));
        result.setTfbn(safeAdd(this.tfbn, other.tfbn));
        result.setYmjbr(safeAdd(this.ymjbr, other.ymjbr));
        result.setYmjby(safeAdd(this.ymjby, other.ymjby));
        result.setYmjbn(safeAdd(this.ymjby, other.ymjby));
        // ... 对其他所有 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);
    }
 
}