@Test public void test_accountCost4Unfreeze() { PointRecPo rec = new PointRecPo(); BigDecimal delta = BigDecimal.valueOf(45).setScale(DecimalUtils.SCALE_2); rec.setTotalCost(DecimalUtils.ZERO); BigDecimal result = this.calculator.accountCost4Unfreeze(rec, delta); Assertions.assertEquals(DecimalUtils.ZERO, result); rec.setFrozen(BigDecimal.valueOf(45L).setScale(DecimalUtils.SCALE_2)) .setTotalCost(BigDecimal.valueOf(100L).setScale(DecimalUtils.SCALE_2)) .setUsedCost(BigDecimal.valueOf(30L).setScale(DecimalUtils.SCALE_2)) .setFrozenCost(BigDecimal.valueOf(70L).setScale(DecimalUtils.SCALE_2)) .setRefundCost(DecimalUtils.ZERO); BigDecimal expect = BigDecimal.valueOf(70L).setScale(DecimalUtils.SCALE_2); result = this.calculator.accountCost4Unfreeze(rec, delta); Assertions.assertEquals(expect, result); rec.setTotal(BigDecimal.valueOf(200L).setScale(DecimalUtils.SCALE_2)) .setFrozen(BigDecimal.valueOf(55L).setScale(DecimalUtils.SCALE_2)) .setTotalCost(BigDecimal.valueOf(100L).setScale(DecimalUtils.SCALE_2)) .setUsedCost(BigDecimal.valueOf(40L).setScale(DecimalUtils.SCALE_2)) .setFrozenCost(DecimalUtils.ZERO).setRefundCost(DecimalUtils.ZERO); expect = BigDecimal.valueOf(22.5).setScale(DecimalUtils.SCALE_2); result = this.calculator.accountCost4Unfreeze(rec, delta); Assertions.assertEquals(expect, result); }
public BigDecimal accountCost4Unfreeze(PointRecPo rec, BigDecimal delta) { BigDecimal cost = DecimalUtils.ZERO; if (rec.getTotalCost() == null || DecimalUtils.lte(rec.getTotalCost(), DecimalUtils.ZERO)) { return cost; } else if (DecimalUtils.lte(rec.getFrozen(), delta)) { cost = rec.getFrozenCost(); } else { cost = delta.multiply(rec.getTotalCost()).divide(rec.getTotal()) .setScale(DecimalUtils.SCALE_2, RoundingMode.HALF_UP); } return cost; }
CostCalculator { public BigDecimal accountCost4Unfreeze(PointRecPo rec, BigDecimal delta) { BigDecimal cost = DecimalUtils.ZERO; if (rec.getTotalCost() == null || DecimalUtils.lte(rec.getTotalCost(), DecimalUtils.ZERO)) { return cost; } else if (DecimalUtils.lte(rec.getFrozen(), delta)) { cost = rec.getFrozenCost(); } else { cost = delta.multiply(rec.getTotalCost()).divide(rec.getTotal()) .setScale(DecimalUtils.SCALE_2, RoundingMode.HALF_UP); } return cost; } }
CostCalculator { public BigDecimal accountCost4Unfreeze(PointRecPo rec, BigDecimal delta) { BigDecimal cost = DecimalUtils.ZERO; if (rec.getTotalCost() == null || DecimalUtils.lte(rec.getTotalCost(), DecimalUtils.ZERO)) { return cost; } else if (DecimalUtils.lte(rec.getFrozen(), delta)) { cost = rec.getFrozenCost(); } else { cost = delta.multiply(rec.getTotalCost()).divide(rec.getTotal()) .setScale(DecimalUtils.SCALE_2, RoundingMode.HALF_UP); } return cost; }  }
CostCalculator { public BigDecimal accountCost4Unfreeze(PointRecPo rec, BigDecimal delta) { BigDecimal cost = DecimalUtils.ZERO; if (rec.getTotalCost() == null || DecimalUtils.lte(rec.getTotalCost(), DecimalUtils.ZERO)) { return cost; } else if (DecimalUtils.lte(rec.getFrozen(), delta)) { cost = rec.getFrozenCost(); } else { cost = delta.multiply(rec.getTotalCost()).divide(rec.getTotal()) .setScale(DecimalUtils.SCALE_2, RoundingMode.HALF_UP); } return cost; }  BigDecimal getAvailableCost(PointRecPo rec); BigDecimal accountPoint(PointRecPo rec, BigDecimal cost); BigDecimal accountCost(PointRecPo rec, BigDecimal delta); BigDecimal accountCost4Unfreeze(PointRecPo rec, BigDecimal delta); }
CostCalculator { public BigDecimal accountCost4Unfreeze(PointRecPo rec, BigDecimal delta) { BigDecimal cost = DecimalUtils.ZERO; if (rec.getTotalCost() == null || DecimalUtils.lte(rec.getTotalCost(), DecimalUtils.ZERO)) { return cost; } else if (DecimalUtils.lte(rec.getFrozen(), delta)) { cost = rec.getFrozenCost(); } else { cost = delta.multiply(rec.getTotalCost()).divide(rec.getTotal()) .setScale(DecimalUtils.SCALE_2, RoundingMode.HALF_UP); } return cost; }  BigDecimal getAvailableCost(PointRecPo rec); BigDecimal accountPoint(PointRecPo rec, BigDecimal cost); BigDecimal accountCost(PointRecPo rec, BigDecimal delta); BigDecimal accountCost4Unfreeze(PointRecPo rec, BigDecimal delta);  }