@Test public void test_accountPoint() { PointRecPo rec = new PointRecPo(); BigDecimal cost = BigDecimal.valueOf(45).setScale(DecimalUtils.SCALE_2); rec.setAvailable(DecimalUtils.ZERO); BigDecimal result = this.calculator.accountPoint(rec, cost); Assertions.assertEquals(DecimalUtils.ZERO, result); rec.setTotalCost(BigDecimal.valueOf(100L).setScale(DecimalUtils.SCALE_2)) .setUsedCost(BigDecimal.valueOf(80L).setScale(DecimalUtils.SCALE_2)) .setFrozenCost(DecimalUtils.ZERO) .setRefundCost(DecimalUtils.ZERO); result = this.calculator.accountPoint(rec, cost); Assertions.assertEquals(DecimalUtils.ZERO, result); rec.setTotal(BigDecimal.valueOf(200L).setScale(DecimalUtils.SCALE_2)) .setTotalCost(BigDecimal.valueOf(100L).setScale(DecimalUtils.SCALE_2)) .setUsedCost(BigDecimal.valueOf(50L).setScale(DecimalUtils.SCALE_2)) .setFrozenCost(DecimalUtils.ZERO).setRefundCost(DecimalUtils.ZERO); BigDecimal expect = BigDecimal.valueOf(90L).setScale(DecimalUtils.SCALE_2); result = this.calculator.accountPoint(rec, cost); Assertions.assertEquals(expect, result); }
public BigDecimal accountPoint(PointRecPo rec, BigDecimal cost) { BigDecimal point = DecimalUtils.ZERO; BigDecimal availableCost = this.getAvailableCost(rec); if (DecimalUtils.lte(availableCost, DecimalUtils.ZERO)) { point = DecimalUtils.ZERO; } else if (DecimalUtils.lte(availableCost, cost)) { point = rec.getAvailable(); } else { point = cost.multiply(rec.getTotal()).divide(rec.getTotalCost()) .setScale(DecimalUtils.SCALE_2, RoundingMode.HALF_UP); } return point; }
CostCalculator { public BigDecimal accountPoint(PointRecPo rec, BigDecimal cost) { BigDecimal point = DecimalUtils.ZERO; BigDecimal availableCost = this.getAvailableCost(rec); if (DecimalUtils.lte(availableCost, DecimalUtils.ZERO)) { point = DecimalUtils.ZERO; } else if (DecimalUtils.lte(availableCost, cost)) { point = rec.getAvailable(); } else { point = cost.multiply(rec.getTotal()).divide(rec.getTotalCost()) .setScale(DecimalUtils.SCALE_2, RoundingMode.HALF_UP); } return point; } }
CostCalculator { public BigDecimal accountPoint(PointRecPo rec, BigDecimal cost) { BigDecimal point = DecimalUtils.ZERO; BigDecimal availableCost = this.getAvailableCost(rec); if (DecimalUtils.lte(availableCost, DecimalUtils.ZERO)) { point = DecimalUtils.ZERO; } else if (DecimalUtils.lte(availableCost, cost)) { point = rec.getAvailable(); } else { point = cost.multiply(rec.getTotal()).divide(rec.getTotalCost()) .setScale(DecimalUtils.SCALE_2, RoundingMode.HALF_UP); } return point; }  }
CostCalculator { public BigDecimal accountPoint(PointRecPo rec, BigDecimal cost) { BigDecimal point = DecimalUtils.ZERO; BigDecimal availableCost = this.getAvailableCost(rec); if (DecimalUtils.lte(availableCost, DecimalUtils.ZERO)) { point = DecimalUtils.ZERO; } else if (DecimalUtils.lte(availableCost, cost)) { point = rec.getAvailable(); } else { point = cost.multiply(rec.getTotal()).divide(rec.getTotalCost()) .setScale(DecimalUtils.SCALE_2, RoundingMode.HALF_UP); } return point; }  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 accountPoint(PointRecPo rec, BigDecimal cost) { BigDecimal point = DecimalUtils.ZERO; BigDecimal availableCost = this.getAvailableCost(rec); if (DecimalUtils.lte(availableCost, DecimalUtils.ZERO)) { point = DecimalUtils.ZERO; } else if (DecimalUtils.lte(availableCost, cost)) { point = rec.getAvailable(); } else { point = cost.multiply(rec.getTotal()).divide(rec.getTotalCost()) .setScale(DecimalUtils.SCALE_2, RoundingMode.HALF_UP); } return point; }  BigDecimal getAvailableCost(PointRecPo rec); BigDecimal accountPoint(PointRecPo rec, BigDecimal cost); BigDecimal accountCost(PointRecPo rec, BigDecimal delta); BigDecimal accountCost4Unfreeze(PointRecPo rec, BigDecimal delta);  }