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);
|
}
|
|
}
|