重构实战-1.原则:有boolean的if else 可将if 和 else 封装为方法。2. 查看传入的Bean用了哪些数据,是否可减少数据。
2016-01-15 21:52
459 查看
最终效果: // 计算保险费并生成保险费域的FeeShareBenefitBO
FeeShareBenefitBO fee = null;
if (shareBenefitHistory == null) {
shareBenefitLogger.debug(LogUtil.f("shareBenefitHistory:{},", JsonUtil.toJson(shareBenefitHistory)));
//部分历史数据没有shareBenefitHistory
fee = calcFeeShareBenefitBO(refundFeeBo, shareBenefitHistory);
} else {
fee = calcFeeShareBenefitBO(originalPay, shareBenefitResultOld, refundFeeBo);
}
最初效果:
long calcRefundInsure = calcRefundInsure(refundFeeBo, getPayTotoalRemoveRisk(prRefOriginalPay),
shareBenefitRule);
FeeShareBenefitBO fee = new FeeShareBenefitBO();
long shared = 0;
long tipShared = 0;
long insureFromCShared = 0;
long insureFromTipShared = 0;
long refundInsure = 0;
if (shareBenefitHistory != null) {
//1.计算普通退款中保险费要退多少
if (refundFeeBo.getShared() > shareBenefitHistory.getTotalCommonShare()) {
//退款比之前分润的大,保险费要退
insureFromCShared = refundFeeBo.getShared() - shareBenefitHistory.getTotalCommonShare();
shared = shareBenefitHistory.getTotalCommonShare();
} else {
shared = refundFeeBo.getShared();
}
//2.计算小费退款中保险费要退多少
if (refundFeeBo.getTipShared() > shareBenefitHistory.getTotalTipShare()) {
//退款比之前分润的大,保险费要退
insureFromTipShared = refundFeeBo.getTipShared() - shareBenefitHistory.getTotalTipShare();
tipShared = shareBenefitHistory.getTotalTipShare();
} else {
tipShared = refundFeeBo.getTipShared();
}
refundInsure = insureFromCShared + insureFromTipShared;
// refundInsure+tipShared+shared=最初订单域的小费+普通分润总额
} else {
long calcRefundInsure = calcRefundInsure(refundFeeBo, getPayTotoalRemoveRisk(prRefOriginalPay),
shareBenefitRule);
long refundInsureLeft = 0;
if (refundFeeBo.getShared() > calcRefundInsure) {
refundInsureLeft = 0;
shared = refundFeeBo.getShared() - calcRefundInsure;
} else {
shared = 0;
refundInsureLeft = calcRefundInsure - refundFeeBo.getShared();
}
tipShared = refundFeeBo.getTipShared() - refundInsureLeft;
refundInsure = calcRefundInsure;
// refundInsure+tipShared+shared=最初订单域的小费+普通分润总额
}
fee.setCommonShared(shared);
fee.setInsure(refundInsure);
fee.setTipShared(tipShared);
fee.setUnshared(refundFeeBo.getUnshared());
return fee;
}
ShareBenefitHistoryDO shareBenefitHistory = shareBenefitHistoryService.getShareBenefitHistory(prRefOriginalPay
.getPayId());
private FeeShareBenefitBO calacFeeShareBenefitBO(FeeBO refundFeeBo, ShareBenefitHistoryDO shareBenefitHistory,
long calcRefundInsure) {
FeeShareBenefitBO fee = new FeeShareBenefitBO();
long shared = 0;
long tipShared = 0;
long insureFromCShared = 0;
long insureFromTipShared = 0;
long refundInsure = 0;
if (shareBenefitHistory != null) {
//1.计算普通退款中保险费要退多少
if (refundFeeBo.getShared() > shareBenefitHistory.getTotalCommonShare()) {
//退款比之前分润的大,保险费要退
insureFromCShared = refundFeeBo.getShared() - shareBenefitHistory.getTotalCommonShare();
shared = shareBenefitHistory.getTotalCommonShare();
} else {
shared = refundFeeBo.getShared();
}
//2.计算小费退款中保险费要退多少
if (refundFeeBo.getTipShared() > shareBenefitHistory.getTotalTipShare()) {
//退款比之前分润的大,保险费要退
insureFromTipShared = refundFeeBo.getTipShared() - shareBenefitHistory.getTotalTipShare();
tipShared = shareBenefitHistory.getTotalTipShare();
} else {
tipShared = refundFeeBo.getTipShared();
}
refundInsure = insureFromCShared + insureFromTipShared;
// refundInsure+tipShared+shared=最初订单域的小费+普通分润总额
} else {
long refundInsureLeft = 0;
if (refundFeeBo.getShared() > calcRefundInsure) {
refundInsureLeft = 0;
shared = refundFeeBo.getShared() - calcRefundInsure;
} else {
shared = 0;
refundInsureLeft = calcRefundInsure - refundFeeBo.getShared();
}
tipShared = refundFeeBo.getTipShared() - refundInsureLeft;
refundInsure = calcRefundInsure;
// refundInsure+tipShared+shared=最初订单域的小费+普通分润总额
}
fee.setCommonShared(shared);
fee.setInsure(refundInsure);
fee.setTipShared(tipShared);
fee.setUnshared(refundFeeBo.getUnshared());
return fee;
}
FeeShareBenefitBO fee = null;
if (shareBenefitHistory == null) {
shareBenefitLogger.debug(LogUtil.f("shareBenefitHistory:{},", JsonUtil.toJson(shareBenefitHistory)));
//部分历史数据没有shareBenefitHistory
fee = calcFeeShareBenefitBO(refundFeeBo, shareBenefitHistory);
} else {
fee = calcFeeShareBenefitBO(originalPay, shareBenefitResultOld, refundFeeBo);
}
最初效果:
long calcRefundInsure = calcRefundInsure(refundFeeBo, getPayTotoalRemoveRisk(prRefOriginalPay),
shareBenefitRule);
FeeShareBenefitBO fee = new FeeShareBenefitBO();
long shared = 0;
long tipShared = 0;
long insureFromCShared = 0;
long insureFromTipShared = 0;
long refundInsure = 0;
if (shareBenefitHistory != null) {
//1.计算普通退款中保险费要退多少
if (refundFeeBo.getShared() > shareBenefitHistory.getTotalCommonShare()) {
//退款比之前分润的大,保险费要退
insureFromCShared = refundFeeBo.getShared() - shareBenefitHistory.getTotalCommonShare();
shared = shareBenefitHistory.getTotalCommonShare();
} else {
shared = refundFeeBo.getShared();
}
//2.计算小费退款中保险费要退多少
if (refundFeeBo.getTipShared() > shareBenefitHistory.getTotalTipShare()) {
//退款比之前分润的大,保险费要退
insureFromTipShared = refundFeeBo.getTipShared() - shareBenefitHistory.getTotalTipShare();
tipShared = shareBenefitHistory.getTotalTipShare();
} else {
tipShared = refundFeeBo.getTipShared();
}
refundInsure = insureFromCShared + insureFromTipShared;
// refundInsure+tipShared+shared=最初订单域的小费+普通分润总额
} else {
long calcRefundInsure = calcRefundInsure(refundFeeBo, getPayTotoalRemoveRisk(prRefOriginalPay),
shareBenefitRule);
long refundInsureLeft = 0;
if (refundFeeBo.getShared() > calcRefundInsure) {
refundInsureLeft = 0;
shared = refundFeeBo.getShared() - calcRefundInsure;
} else {
shared = 0;
refundInsureLeft = calcRefundInsure - refundFeeBo.getShared();
}
tipShared = refundFeeBo.getTipShared() - refundInsureLeft;
refundInsure = calcRefundInsure;
// refundInsure+tipShared+shared=最初订单域的小费+普通分润总额
}
fee.setCommonShared(shared);
fee.setInsure(refundInsure);
fee.setTipShared(tipShared);
fee.setUnshared(refundFeeBo.getUnshared());
return fee;
}
ShareBenefitHistoryDO shareBenefitHistory = shareBenefitHistoryService.getShareBenefitHistory(prRefOriginalPay
.getPayId());
private FeeShareBenefitBO calacFeeShareBenefitBO(FeeBO refundFeeBo, ShareBenefitHistoryDO shareBenefitHistory,
long calcRefundInsure) {
FeeShareBenefitBO fee = new FeeShareBenefitBO();
long shared = 0;
long tipShared = 0;
long insureFromCShared = 0;
long insureFromTipShared = 0;
long refundInsure = 0;
if (shareBenefitHistory != null) {
//1.计算普通退款中保险费要退多少
if (refundFeeBo.getShared() > shareBenefitHistory.getTotalCommonShare()) {
//退款比之前分润的大,保险费要退
insureFromCShared = refundFeeBo.getShared() - shareBenefitHistory.getTotalCommonShare();
shared = shareBenefitHistory.getTotalCommonShare();
} else {
shared = refundFeeBo.getShared();
}
//2.计算小费退款中保险费要退多少
if (refundFeeBo.getTipShared() > shareBenefitHistory.getTotalTipShare()) {
//退款比之前分润的大,保险费要退
insureFromTipShared = refundFeeBo.getTipShared() - shareBenefitHistory.getTotalTipShare();
tipShared = shareBenefitHistory.getTotalTipShare();
} else {
tipShared = refundFeeBo.getTipShared();
}
refundInsure = insureFromCShared + insureFromTipShared;
// refundInsure+tipShared+shared=最初订单域的小费+普通分润总额
} else {
long refundInsureLeft = 0;
if (refundFeeBo.getShared() > calcRefundInsure) {
refundInsureLeft = 0;
shared = refundFeeBo.getShared() - calcRefundInsure;
} else {
shared = 0;
refundInsureLeft = calcRefundInsure - refundFeeBo.getShared();
}
tipShared = refundFeeBo.getTipShared() - refundInsureLeft;
refundInsure = calcRefundInsure;
// refundInsure+tipShared+shared=最初订单域的小费+普通分润总额
}
fee.setCommonShared(shared);
fee.setInsure(refundInsure);
fee.setTipShared(tipShared);
fee.setUnshared(refundFeeBo.getUnshared());
return fee;
}
相关文章推荐
- #Android##bug#ConcurrentModificationException
- 后端服务(综合)
- UML用例图
- Java集合框架详解
- mysql概要(八)视图
- Android手机数据保存方式
- “我的”界面cell创建简便方法
- 数据库触发器
- 解决 java.io.IOException: The output jar is empty. Did you specify the proper '-keep' options?
- Chrome扩展开发之二——Chrome扩展中脚本的运行机制和通信方式
- Mycat学习笔记 第一篇. MySql 读写分离与日志分析——主从单结点
- BZOJ1036 [ZJOI2008]树的统计Count
- TCP/IP协议栈与数据包封装
- C#基础练习(使用委托窗体传值)
- C#基础练习(使用委托窗体传值)
- 初学Shiro 1:Shiro的简单流程
- 我的ABZ计划
- Codeforces Round #339 (Div. 2) A
- KVO/KVC系列概论
- 【Unity开发】简单的Wav文件压缩