DiscountFeeRule.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.feeDiscountSpec.FeeDiscountSpecDto;
  22. import com.java110.fee.discount.IComputeDiscount;
  23. import com.java110.intf.fee.IFeeInnerServiceSMO;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Component;
  26. import java.math.BigDecimal;
  27. import java.util.List;
  28. /**
  29. * 优惠打折 规则
  30. *
  31. * @desc add by 吴学文 10:27
  32. */
  33. @Component(value = "discountFeeRule")
  34. public class DiscountFeeRule implements IComputeDiscount {
  35. /**
  36. * 89002020980001 102020001 月份
  37. * 89002020980002 102020001 打折率
  38. */
  39. private static final String SPEC_MONTH = "89002020980001"; //月份
  40. private static final String SPEC_RATE = "89002020980002"; // 打折率
  41. @Autowired
  42. private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
  43. @Autowired
  44. private IComputeFeeSMO computeFeeSMOImpl;
  45. @Override
  46. public ComputeDiscountDto compute(FeeDiscountDto feeDiscountDto) {
  47. List<FeeDiscountSpecDto> feeDiscountSpecDtos = feeDiscountDto.getFeeDiscountSpecs();
  48. if (feeDiscountSpecDtos.size() < 1) {
  49. return null;
  50. }
  51. double month = 0.0;
  52. double rate = 0.0;
  53. for (FeeDiscountSpecDto feeDiscountSpecDto : feeDiscountSpecDtos) {
  54. if (SPEC_MONTH.equals(feeDiscountSpecDto.getSpecId())) {
  55. month = Double.parseDouble(feeDiscountSpecDto.getSpecValue());
  56. }
  57. if (SPEC_RATE.equals(feeDiscountSpecDto.getSpecId())) {
  58. rate = Double.parseDouble(feeDiscountSpecDto.getSpecValue());
  59. }
  60. }
  61. if (feeDiscountDto.getCycles() < month) {
  62. return null;
  63. }
  64. //查询费用
  65. FeeDto feeDto = new FeeDto();
  66. feeDto.setCommunityId(feeDiscountDto.getCommunityId());
  67. feeDto.setFeeId(feeDiscountDto.getFeeId());
  68. List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
  69. double price = computeFeeSMOImpl.getFeePrice(feeDtos.get(0));
  70. BigDecimal priceDec = new BigDecimal(price);
  71. BigDecimal cycleDec = new BigDecimal(feeDiscountDto.getCycles());
  72. double discountPrice = priceDec.multiply(cycleDec).multiply(new BigDecimal(1.0 - rate)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
  73. ComputeDiscountDto computeDiscountDto = new ComputeDiscountDto();
  74. computeDiscountDto.setDiscountId(feeDiscountDto.getDiscountId());
  75. computeDiscountDto.setDiscountType(FeeDiscountDto.DISCOUNT_TYPE_D);
  76. computeDiscountDto.setRuleId(feeDiscountDto.getRuleId());
  77. computeDiscountDto.setRuleName(feeDiscountDto.getRuleName());
  78. computeDiscountDto.setDiscountName(feeDiscountDto.getDiscountName());
  79. computeDiscountDto.setDiscountPrice(discountPrice);
  80. computeDiscountDto.setFeeDiscountSpecs(feeDiscountSpecDtos);
  81. return computeDiscountDto;
  82. }
  83. }