LateFeeZaoZhuangPropertyByDayRule.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright 2017-2020 吴学文 and java110 team.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.java110.fee.discount.impl;
  17. import com.java110.core.smo.IComputeFeeSMO;
  18. import com.java110.dto.fee.FeeDto;
  19. import com.java110.dto.feeDiscount.ComputeDiscountDto;
  20. import com.java110.dto.feeDiscount.FeeDiscountDto;
  21. import com.java110.dto.feeDiscount.FeeDiscountSpecDto;
  22. import com.java110.fee.discount.IComputeDiscount;
  23. import com.java110.intf.fee.IFeeInnerServiceSMO;
  24. import com.java110.utils.util.DateUtil;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Component;
  27. import java.math.BigDecimal;
  28. import java.util.Date;
  29. import java.util.List;
  30. import java.util.Map;
  31. /**
  32. * 枣庄 需求
  33. * select * from fee_discount_rule t where t.rule_id = '102020003';
  34. * 这里的实现类修改为 lateFeeZaoZhuangPropertyByDayRule
  35. * @desc add by 吴学文 12:43
  36. */
  37. @Component(value = "lateFeeZaoZhuangPropertyByDayRule")
  38. public class LateFeeZaoZhuangPropertyByDayRule implements IComputeDiscount {
  39. /**
  40. * 89002020980001 102020001 月份
  41. * 89002020980002 102020001 打折率
  42. */
  43. private static final String SPEC_RATE = "89002020980005"; // 打折率
  44. @Autowired
  45. private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
  46. @Autowired
  47. private IComputeFeeSMO computeFeeSMOImpl;
  48. @Override
  49. public ComputeDiscountDto compute(FeeDiscountDto feeDiscountDto) {
  50. List<FeeDiscountSpecDto> feeDiscountSpecDtos = feeDiscountDto.getFeeDiscountSpecs();
  51. if (feeDiscountSpecDtos.size() < 1) {
  52. return null;
  53. }
  54. double rate = 0.0;
  55. for (FeeDiscountSpecDto feeDiscountSpecDto : feeDiscountSpecDtos) {
  56. if (SPEC_RATE.equals(feeDiscountSpecDto.getSpecId())) {
  57. rate = Double.parseDouble(feeDiscountSpecDto.getSpecValue());
  58. }
  59. }
  60. FeeDto feeDto = new FeeDto();
  61. feeDto.setCommunityId(feeDiscountDto.getCommunityId());
  62. feeDto.setFeeId(feeDiscountDto.getFeeId());
  63. List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
  64. Date curTime = DateUtil.getCurrentDate();
  65. Date endTime = feeDtos.get(0).getEndTime();
  66. if (endTime.getTime() > curTime.getTime()) {
  67. ComputeDiscountDto computeDiscountDto = new ComputeDiscountDto();
  68. computeDiscountDto.setDiscountId(feeDiscountDto.getDiscountId());
  69. computeDiscountDto.setDiscountType(FeeDiscountDto.DISCOUNT_TYPE_V);
  70. computeDiscountDto.setRuleId(feeDiscountDto.getRuleId());
  71. computeDiscountDto.setRuleName(feeDiscountDto.getRuleName());
  72. computeDiscountDto.setDiscountName(feeDiscountDto.getDiscountName());
  73. computeDiscountDto.setDiscountPrice(0.0);
  74. computeDiscountDto.setFeeDiscountSpecs(feeDiscountSpecDtos);
  75. return computeDiscountDto;
  76. }
  77. //查询费用
  78. int day = DateUtil.daysBetween(curTime, endTime);
  79. if (day < 1) {
  80. ComputeDiscountDto computeDiscountDto = new ComputeDiscountDto();
  81. computeDiscountDto.setDiscountId(feeDiscountDto.getDiscountId());
  82. computeDiscountDto.setDiscountType(FeeDiscountDto.DISCOUNT_TYPE_V);
  83. computeDiscountDto.setRuleId(feeDiscountDto.getRuleId());
  84. computeDiscountDto.setRuleName(feeDiscountDto.getRuleName());
  85. computeDiscountDto.setDiscountName(feeDiscountDto.getDiscountName());
  86. computeDiscountDto.setDiscountPrice(0.0);
  87. computeDiscountDto.setFeeDiscountSpecs(feeDiscountSpecDtos);
  88. return computeDiscountDto;
  89. }
  90. Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDtos.get(0));
  91. BigDecimal priceDec = new BigDecimal(feePriceAll.get("feePrice").toString());
  92. BigDecimal dayDec = new BigDecimal(day);
  93. // double discountPrice = priceDec.divide(new BigDecimal(30), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(rate)).multiply(dayDec).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
  94. BigDecimal money = new BigDecimal(0);
  95. BigDecimal yearFee = null;
  96. BigDecimal monthFee = null;
  97. BigDecimal dayMoney = null;
  98. for (int i = 1; i < day + 1; i++) {
  99. yearFee = priceDec.multiply(new BigDecimal(12));
  100. monthFee = yearFee.divide(new BigDecimal(365), 2, BigDecimal.ROUND_HALF_UP);
  101. dayMoney = monthFee.multiply(new BigDecimal(i - 1));
  102. dayMoney = dayMoney.multiply(new BigDecimal(rate));
  103. money = money.add(dayMoney).setScale(2, BigDecimal.ROUND_HALF_EVEN);
  104. }
  105. double discountPrice = money.doubleValue();
  106. // System.out.println(money);
  107. ComputeDiscountDto computeDiscountDto = new ComputeDiscountDto();
  108. computeDiscountDto.setDiscountId(feeDiscountDto.getDiscountId());
  109. computeDiscountDto.setDiscountType(FeeDiscountDto.DISCOUNT_TYPE_V);
  110. computeDiscountDto.setRuleId(feeDiscountDto.getRuleId());
  111. computeDiscountDto.setRuleName(feeDiscountDto.getRuleName());
  112. computeDiscountDto.setDiscountName(feeDiscountDto.getDiscountName());
  113. computeDiscountDto.setDiscountPrice(discountPrice * -1);
  114. computeDiscountDto.setFeeDiscountSpecs(feeDiscountSpecDtos);
  115. return computeDiscountDto;
  116. }
  117. public static void main(String[] args) throws Exception {
  118. int day = 316;
  119. double money = 0.0;
  120. for (int i = 1; i < day + 1; i++) {
  121. money += ((124.51 / 30 * (i - 1) + money) * 0.003);
  122. System.out.println("第" + i + "天 违约金 = " + money + ",计算公式为:(124.51/30 * (" + i + "-1) + " + money + ") * 0.003");
  123. }
  124. System.out.println(money);
  125. }
  126. }