内容简介:EDEN-MACE 是一套灵活的管理佣金的分销管理系统,它涵盖并且总结了目前流行的分销模式,让分销更加简单。 开源地址:https://gitee.com/codingdb/distribution_management 原来的账务的管理,使用策略模式+工厂模式...
EDEN-MACE 是一套灵活的管理佣金的分销管理系统,它涵盖并且总结了目前流行的分销模式,让分销更加简单。
开源地址:https://gitee.com/codingdb/distribution_management
原来的账务的管理,使用策略模式+工厂模式,导致每次新增一个账户之后就会复制大量的重复代码,这样会导致代码大量的冗余。
根据上面的问题,将策略模式换成了模板模式+工厂模式,每次新增一个账户的时候就可以只增加改动的部分即可。
下面演示新增一个交易账户需要做的事(只有最后一段需要新增,第一部分为静态工厂方法初始化,第二部分为模板方法调用,当然省略了部分部分代码,省略的代码为原来的公共代码)
public AmountTemplateFactoryContext(String type) {
switch (type){
case "0":
amountTemplate = new TradeAmountServiceImpl();
break;
case "1":
amountTemplate = new LevelAmountServiceImpl();
break;
case "2":
amountTemplate = new InviteAmountServiceImpl();
break;
default:
break;
}
}
public abstract void addMoney(DisMemberAmount memberAmount,BigDecimal amount,DisAmountSituation situation);
@DataSource(name = DSEnum.DATA_SOURCE_BIZ)
public final void addMoney(String userId, BigDecimal amount, String sourceName, String type) {
....
addMoney(memberAmount,amount,situation);
...
}
public abstract void frozenAmount(DisMemberAmount memberAmount,BigDecimal amount);
@DataSource(name = DSEnum.DATA_SOURCE_BIZ)
public final void frozenAmount(String userId, BigDecimal amount) {
...
frozenAmount(memberAmount,amount);
...
}
public abstract void reduceMoney(DisMemberAmount memberAmount,BigDecimal amount,DisAmountSituation situation);
@DataSource(name = DSEnum.DATA_SOURCE_BIZ)
public final void reduceMoney(String userId, BigDecimal amount) {
....
reduceMoney(memberAmount,amount,situation);
...
}
public abstract void returnMoney(DisMemberAmount memberAmount,BigDecimal amount);
@DataSource(name = DSEnum.DATA_SOURCE_BIZ)
public final void returnMoney(String userId, BigDecimal amount) {
...
returnMoney(memberAmount,amount);
...
}
public class TradeAmountServiceImpl extends AmountTemplate{
@Override
public void addMoney(DisMemberAmount memberAmount, BigDecimal amount,DisAmountSituation situation) {
BigDecimal afterThirdAmount=new BigDecimal(0);
BigDecimal beforeThirdAmount=new BigDecimal(0);
afterThirdAmount=memberAmount.getTradeTotalAmount().add(amount);
beforeThirdAmount=memberAmount.getTradeTotalAmount();
memberAmount.setTradeTotalAmount(memberAmount.getTradeTotalAmount().add(amount));
memberAmount.setTradeAvaibleAmount(memberAmount.getTradeAvaibleAmount().add(amount));
situation.setSpecificBeforeChangeAmount(beforeThirdAmount);
situation.setSpecificAfterChangeAmount(afterThirdAmount);
}
@Override
public void frozenAmount(DisMemberAmount memberAmount, BigDecimal amount) {
BigDecimal avaibleThirdAmount=new BigDecimal(0);
avaibleThirdAmount=memberAmount.getTradeAvaibleAmount();
if(avaibleThirdAmount.compareTo(amount)==-1){
throw new BussinessException(BizExceptionEnum.LOW_MONEY);
}
memberAmount.setTradeAvaibleAmount(memberAmount.getTradeAvaibleAmount().subtract(amount));
memberAmount.setTradeFrozenAmount(memberAmount.getTradeFrozenAmount().add(amount));
}
@Override
public void reduceMoney(DisMemberAmount memberAmount, BigDecimal amount,DisAmountSituation situation) {
BigDecimal avaibleThirdAmount=new BigDecimal(0);
avaibleThirdAmount=memberAmount.getTradeFrozenAmount();
if(avaibleThirdAmount.compareTo(amount)==-1){
throw new BussinessException(BizExceptionEnum.LOW_MONEY);
}
BigDecimal beforeThirdAmount=new BigDecimal(0);
beforeThirdAmount=memberAmount.getTradeTotalAmount();
memberAmount.setTradeFrozenAmount(memberAmount.getTradeFrozenAmount().subtract(amount));
memberAmount.setTradeTotalAmount(beforeThirdAmount.subtract(amount));
situation.setSpecificBeforeChangeAmount(beforeThirdAmount);
situation.setSpecificAfterChangeAmount(beforeThirdAmount.subtract(amount));
}
@Override
public void returnMoney(DisMemberAmount memberAmount, BigDecimal amount) {
BigDecimal avaibleThirdAmount=new BigDecimal(0);
avaibleThirdAmount=memberAmount.getTradeFrozenAmount();
if(avaibleThirdAmount.compareTo(amount)==-1){
throw new BussinessException(BizExceptionEnum.LOW_MONEY);
}
memberAmount.setTradeAvaibleAmount(memberAmount.getTradeAvaibleAmount().add(amount));
memberAmount.setTradeFrozenAmount(memberAmount.getTradeFrozenAmount().subtract(amount));
}
}
以上所述就是小编给大家介绍的《EDEN-MACE 1.5.0 更新,使用模板方法新增账务》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- EDEN-MACE 1.5.0 更新,使用模板方法新增账务
- EDEN-MACE 1.6.0 发布,新增分布式锁,保证账务安全性
- 线上账务系统余额并发更新问题记录
- 多业务线亿级体量,携程是怎么做账务中台的
- 超越 “双十一”:ebay 百万 TPS 支付账务系统的设计与实现
- WookTeam 1.2 发布,新增知识库markdown编辑器,新增知识库协作更新通知
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。