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