EDEN-MACE 1.5.0 更新,使用模板方法新增账务

栏目: 软件资讯 · 发布时间: 6年前

内容简介: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 更新,使用模板方法新增账务》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Beautiful Code

Beautiful Code

Greg Wilson、Andy Oram / O'Reilly Media / 2007-7-6 / GBP 35.99

In this unique work, leading computer scientists discuss how they found unusual, carefully designed solutions to difficult problems. This book lets the reader look over the shoulder of major coding an......一起来看看 《Beautiful Code》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

URL 编码/解码
URL 编码/解码

URL 编码/解码