1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| public abstract class AbstractRaffleStrategy implements IRaffleStrategy {
protected IStrategyRepository repository; protected IStrategyDispatch strategyDispatch; protected final DefaultChainFactory defaultChainFactory; protected final DefaultTreeFactory defaultTreeFactory;
public AbstractRaffleStrategy(IStrategyRepository repository, IStrategyDispatch strategyDispatch, DefaultChainFactory defaultChainFactory, DefaultTreeFactory defaultTreeFactory) { this.repository = repository; this.strategyDispatch = strategyDispatch; this.defaultChainFactory = defaultChainFactory; this.defaultTreeFactory = defaultTreeFactory; }
@Override public RaffleAwardEntity performRaffle(RaffleFactorEntity raffleFactorEntity) { String userId = raffleFactorEntity.getUserId(); Long strategyId = raffleFactorEntity.getStrategyId(); if (null == strategyId || StringUtils.isBlank(userId)) { throw new AppException(ResponseCode.ILLEGAL_PARAMETER.getCode(), ResponseCode.ILLEGAL_PARAMETER.getInfo()); }
DefaultChainFactory.StrategyAwardVO chainStrategyAwardVO = raffleLogicChain(userId, strategyId); log.info("抽奖策略计算-责任链 {} {} {} {}", userId, strategyId, chainStrategyAwardVO.getAwardId(), chainStrategyAwardVO.getLogicModel()); if (!DefaultChainFactory.LogicModel.RULE_DEFAULT.getCode().equals(chainStrategyAwardVO.getLogicModel())) { return buildRaffleAwardEntity(strategyId, chainStrategyAwardVO.getAwardId(), null); }
DefaultTreeFactory.StrategyAwardVO treeStrategyAwardVO = raffleLogicTree(userId, strategyId, chainStrategyAwardVO.getAwardId()); log.info("抽奖策略计算-规则树 {} {} {} {}", userId, strategyId, treeStrategyAwardVO.getAwardId(), treeStrategyAwardVO.getAwardRuleValue());
return buildRaffleAwardEntity(strategyId, treeStrategyAwardVO.getAwardId(), treeStrategyAwardVO.getAwardRuleValue()); }
private RaffleAwardEntity buildRaffleAwardEntity(Long strategyId, Integer awardId, String awardConfig) { StrategyAwardEntity strategyAward = repository.queryStrategyAwardEntity(strategyId, awardId); return RaffleAwardEntity.builder() .awardId(awardId) .awardConfig(awardConfig) .sort(strategyAward.getSort()) .build(); }
public abstract DefaultChainFactory.StrategyAwardVO raffleLogicChain(String userId, Long strategyId);
public abstract DefaultTreeFactory.StrategyAwardVO raffleLogicTree(String userId, Long strategyId, Integer awardId);
}
|