@Test public void test_unfreezePoint_all() { rec.setTotal(BigDecimal.valueOf(200L).setScale(DecimalUtils.SCALE_2)) .setAvailable(BigDecimal.valueOf(100L).setScale(DecimalUtils.SCALE_2)) .setFrozen(BigDecimal.valueOf(30L).setScale(DecimalUtils.SCALE_2)) .setTotalCost(BigDecimal.valueOf(100L).setScale(DecimalUtils.SCALE_2)) .setFrozenCost(BigDecimal.valueOf(15L).setScale(DecimalUtils.SCALE_2)); PointRecCalcResult result = calculator.unfreezePoint(rec, BigDecimal.valueOf(30L), null); log.info("result = {}", result); Assertions.assertEquals(rec.getId(), result.getRec4Update().getId()); Assertions.assertEquals(BigDecimal.valueOf(130L).setScale(DecimalUtils.SCALE_2), rec.getAvailable() ); Assertions.assertEquals(BigDecimal.valueOf(130L).setScale(DecimalUtils.SCALE_2), result.getRec4Update().getAvailable() ); Assertions.assertEquals(DecimalUtils.ZERO, rec.getFrozen()); Assertions.assertEquals(DecimalUtils.ZERO, result.getRec4Update().getFrozen()); Assertions.assertEquals(DecimalUtils.ZERO, rec.getFrozenCost()); Assertions.assertEquals(DecimalUtils.ZERO, result.getRec4Update().getFrozenCost()); Assertions.assertEquals(BigDecimal.valueOf(15L).setScale(DecimalUtils.SCALE_2), result.getDeltaCost()); }
public PointRecCalcResult unfreezePoint(PointRecPo rec, BigDecimal delta, BigDecimal deltaCost) { PointRecPo rec4Update = new PointRecPo(); rec4Update.setId(rec.getId()); if (DecimalUtils.lt(rec.getFrozen(), delta)) { log.warn("no enough frozen point. rec = {}, delta = {}", rec, delta); throw new HyenaNoPointException("no enough frozen point", Level.WARN); } else if (DecimalUtils.gt(rec.getFrozen(), delta)) { BigDecimal frozen = rec.getFrozen().subtract(delta); BigDecimal available = rec.getAvailable().add(delta); if (deltaCost == null) { deltaCost = this.costCalculator.accountCost4Unfreeze(rec, delta); } rec.setAvailable(available).setFrozen(frozen) .setFrozenCost(rec.getFrozenCost().subtract(deltaCost)); } else { BigDecimal available = rec.getAvailable().add(rec.getFrozen()); if (deltaCost == null) { deltaCost = rec.getFrozenCost(); } rec.setFrozen(DecimalUtils.ZERO).setAvailable(available) .setFrozenCost(DecimalUtils.ZERO); } rec4Update.setFrozen(rec.getFrozen()) .setAvailable(rec.getAvailable()) .setFrozenCost(rec.getFrozenCost()); return new PointRecCalcResult(rec4Update, deltaCost); }
PointRecCalculator { public PointRecCalcResult unfreezePoint(PointRecPo rec, BigDecimal delta, BigDecimal deltaCost) { PointRecPo rec4Update = new PointRecPo(); rec4Update.setId(rec.getId()); if (DecimalUtils.lt(rec.getFrozen(), delta)) { log.warn("no enough frozen point. rec = {}, delta = {}", rec, delta); throw new HyenaNoPointException("no enough frozen point", Level.WARN); } else if (DecimalUtils.gt(rec.getFrozen(), delta)) { BigDecimal frozen = rec.getFrozen().subtract(delta); BigDecimal available = rec.getAvailable().add(delta); if (deltaCost == null) { deltaCost = this.costCalculator.accountCost4Unfreeze(rec, delta); } rec.setAvailable(available).setFrozen(frozen) .setFrozenCost(rec.getFrozenCost().subtract(deltaCost)); } else { BigDecimal available = rec.getAvailable().add(rec.getFrozen()); if (deltaCost == null) { deltaCost = rec.getFrozenCost(); } rec.setFrozen(DecimalUtils.ZERO).setAvailable(available) .setFrozenCost(DecimalUtils.ZERO); } rec4Update.setFrozen(rec.getFrozen()) .setAvailable(rec.getAvailable()) .setFrozenCost(rec.getFrozenCost()); return new PointRecCalcResult(rec4Update, deltaCost); } }
PointRecCalculator { public PointRecCalcResult unfreezePoint(PointRecPo rec, BigDecimal delta, BigDecimal deltaCost) { PointRecPo rec4Update = new PointRecPo(); rec4Update.setId(rec.getId()); if (DecimalUtils.lt(rec.getFrozen(), delta)) { log.warn("no enough frozen point. rec = {}, delta = {}", rec, delta); throw new HyenaNoPointException("no enough frozen point", Level.WARN); } else if (DecimalUtils.gt(rec.getFrozen(), delta)) { BigDecimal frozen = rec.getFrozen().subtract(delta); BigDecimal available = rec.getAvailable().add(delta); if (deltaCost == null) { deltaCost = this.costCalculator.accountCost4Unfreeze(rec, delta); } rec.setAvailable(available).setFrozen(frozen) .setFrozenCost(rec.getFrozenCost().subtract(deltaCost)); } else { BigDecimal available = rec.getAvailable().add(rec.getFrozen()); if (deltaCost == null) { deltaCost = rec.getFrozenCost(); } rec.setFrozen(DecimalUtils.ZERO).setAvailable(available) .setFrozenCost(DecimalUtils.ZERO); } rec4Update.setFrozen(rec.getFrozen()) .setAvailable(rec.getAvailable()) .setFrozenCost(rec.getFrozenCost()); return new PointRecCalcResult(rec4Update, deltaCost); }  }
PointRecCalculator { public PointRecCalcResult unfreezePoint(PointRecPo rec, BigDecimal delta, BigDecimal deltaCost) { PointRecPo rec4Update = new PointRecPo(); rec4Update.setId(rec.getId()); if (DecimalUtils.lt(rec.getFrozen(), delta)) { log.warn("no enough frozen point. rec = {}, delta = {}", rec, delta); throw new HyenaNoPointException("no enough frozen point", Level.WARN); } else if (DecimalUtils.gt(rec.getFrozen(), delta)) { BigDecimal frozen = rec.getFrozen().subtract(delta); BigDecimal available = rec.getAvailable().add(delta); if (deltaCost == null) { deltaCost = this.costCalculator.accountCost4Unfreeze(rec, delta); } rec.setAvailable(available).setFrozen(frozen) .setFrozenCost(rec.getFrozenCost().subtract(deltaCost)); } else { BigDecimal available = rec.getAvailable().add(rec.getFrozen()); if (deltaCost == null) { deltaCost = rec.getFrozenCost(); } rec.setFrozen(DecimalUtils.ZERO).setAvailable(available) .setFrozenCost(DecimalUtils.ZERO); } rec4Update.setFrozen(rec.getFrozen()) .setAvailable(rec.getAvailable()) .setFrozenCost(rec.getFrozenCost()); return new PointRecCalcResult(rec4Update, deltaCost); }  PointRecCalcResult freezePoint(PointRecPo rec, BigDecimal delta); PointRecCalcResult unfreezePoint(PointRecPo rec, BigDecimal delta, BigDecimal deltaCost); PointRecCalcResult decreasePoint(PointRecPo rec, BigDecimal delta); PointRecPo refundPoint(PointRecPo rec, BigDecimal delta, BigDecimal cost); PointRecCalcResult cancelPoint(PointRecPo rec, BigDecimal delta); }
PointRecCalculator { public PointRecCalcResult unfreezePoint(PointRecPo rec, BigDecimal delta, BigDecimal deltaCost) { PointRecPo rec4Update = new PointRecPo(); rec4Update.setId(rec.getId()); if (DecimalUtils.lt(rec.getFrozen(), delta)) { log.warn("no enough frozen point. rec = {}, delta = {}", rec, delta); throw new HyenaNoPointException("no enough frozen point", Level.WARN); } else if (DecimalUtils.gt(rec.getFrozen(), delta)) { BigDecimal frozen = rec.getFrozen().subtract(delta); BigDecimal available = rec.getAvailable().add(delta); if (deltaCost == null) { deltaCost = this.costCalculator.accountCost4Unfreeze(rec, delta); } rec.setAvailable(available).setFrozen(frozen) .setFrozenCost(rec.getFrozenCost().subtract(deltaCost)); } else { BigDecimal available = rec.getAvailable().add(rec.getFrozen()); if (deltaCost == null) { deltaCost = rec.getFrozenCost(); } rec.setFrozen(DecimalUtils.ZERO).setAvailable(available) .setFrozenCost(DecimalUtils.ZERO); } rec4Update.setFrozen(rec.getFrozen()) .setAvailable(rec.getAvailable()) .setFrozenCost(rec.getFrozenCost()); return new PointRecCalcResult(rec4Update, deltaCost); }  PointRecCalcResult freezePoint(PointRecPo rec, BigDecimal delta); PointRecCalcResult unfreezePoint(PointRecPo rec, BigDecimal delta, BigDecimal deltaCost); PointRecCalcResult decreasePoint(PointRecPo rec, BigDecimal delta); PointRecPo refundPoint(PointRecPo rec, BigDecimal delta, BigDecimal cost); PointRecCalcResult cancelPoint(PointRecPo rec, BigDecimal delta);  }