1 Star 0 Fork 27

西木-Lee / barry-wallet

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

数字钱包系统

系统主要功能为账户资金交易,可用于会员虚拟钱包,实体消费卡,积分等有交易需求的系统

介绍

系统设计灵活易于扩展,采用多种设计模式,可简单适配不同业务场景,点击《企业中台化落地:从战略分析到战术实践及架构演进过程》

程序结构图

特性

  • 交易方式 WalletService:简单实现多种交易方式需求
  • 交易行为 Behavior:用行为定义交易后产生的结果变化,如增加/减少金额,属性变化等
  • 交易策略 CheckPolicy:不同策略组合实现不同的交易行为需求

使用指南

1. 增加交易方式

wallet-service项目的service中增加现实类

  1. 继承DefaultService抽象类
  2. 在构造方法中构建交易对象TradeRecord
  3. tradeType()中配置交易类型
  4. behavior()中创建交易行为对象
  5. checkPolicies()中组合该交易类型的交易规则策略
public class LockService extends DefaultService {

    public LockService(Wallet wallet) {
        super(TradeRecord.builder().wallet(wallet).build());
    }

    @Override
    protected TradeConfig tradeConfig() {
        return new TradeConfig() {
            @Override
            public TradeType tradeType() {
                return TradeType.LOCK;
            }

            @Override
            public Behavior behavior() {
                return new LockBehavior(getWallet());
            }

            @Override
            public List<CheckPolicy> checkPolicies() {
                return CheckPolicyBuilder.builder()
                        .add(new NoAvailableStatusAllowed(getWallet()))
                        .build();
            }
        };
    }
}

2. 增加交易行为

wallet-domain项目的behavior中增加行为现实类

  1. 继承DefaultBehavior抽象类
  2. 重写doAction(),增加操作逻辑
  3. 设置getInOutFlag()资金进出状态
public class LockBehavior extends DefaultBehavior {

    public LockBehavior(Wallet wallet) {
        super(wallet);
    }

    /**
     * 执行
     */
    @Override
    public void doAction() {
        super.doAction();
        wallet.setWalletStatus(WalletStatus.LOCKED);
    }

    /**
     * 进出状态
     *
     */
    @Override
    public InOutFlag getInOutFlag() {
        return InOutFlag.NONE;
    }
}

3. 增加交易规则策略

wallet-domain项目的policy中增加行为现实类

  1. 实现CheckPolicy接口
  2. check()中设置具体业务规则
public class NoAvailableStatusAllowed implements CheckPolicy {

    /**
     * 钱包
     */
    private final Wallet wallet;

    public NoAvailableStatusAllowed(Wallet wallet) {
        this.wallet = wallet;
    }

    /**
     * 检查
     *
     */
    @Override
    public void check() {

        if (!WalletStatus.AVAILABLE.equals(wallet.getWalletStatus())){
            throw new BizException("钱包状态不可用");
        }
    }
}

License 授权协议

这个项目 MIT 协议, 请点击 LICENSE.md 了解更多细节。

MIT License Copyright (c) 2020 barry异想世界 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

数字钱包系统,使用策略、组合、模板等设计模式构建灵活扩展面向DDD的设计架构 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/lixyu/barry-wallet.git
git@gitee.com:lixyu/barry-wallet.git
lixyu
barry-wallet
barry-wallet
master

搜索帮助

14c37bed 8189591 565d56ea 8189591