FeeDiscountInnerServiceSMOImpl.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package com.java110.fee.smo.impl;
  2. import com.java110.core.base.smo.BaseServiceSMO;
  3. import com.java110.dto.PageDto;
  4. import com.java110.dto.fee.FeeDetailDto;
  5. import com.java110.dto.fee.FeeDto;
  6. import com.java110.dto.feeDiscount.ComputeDiscountDto;
  7. import com.java110.dto.feeDiscount.FeeDiscountDto;
  8. import com.java110.dto.payFeeConfigDiscount.PayFeeConfigDiscountDto;
  9. import com.java110.fee.dao.IFeeDiscountServiceDao;
  10. import com.java110.fee.discount.IComputeDiscount;
  11. import com.java110.intf.fee.IFeeDiscountInnerServiceSMO;
  12. import com.java110.intf.fee.IFeeInnerServiceSMO;
  13. import com.java110.intf.fee.IPayFeeConfigDiscountInnerServiceSMO;
  14. import com.java110.po.feeDiscount.FeeDiscountPo;
  15. import com.java110.utils.factory.ApplicationContextFactory;
  16. import com.java110.utils.util.Assert;
  17. import com.java110.utils.util.BeanConvertUtil;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.RequestBody;
  20. import org.springframework.web.bind.annotation.RestController;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. /**
  24. * @ClassName FloorInnerServiceSMOImpl
  25. * @Description 费用折扣内部服务实现类
  26. * @Author wuxw
  27. * @Date 2019/4/24 9:20
  28. * @Version 1.0
  29. * add by wuxw 2019/4/24
  30. **/
  31. @RestController
  32. public class FeeDiscountInnerServiceSMOImpl extends BaseServiceSMO implements IFeeDiscountInnerServiceSMO {
  33. @Autowired
  34. private IFeeDiscountServiceDao feeDiscountServiceDaoImpl;
  35. @Autowired
  36. private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
  37. @Autowired
  38. private IPayFeeConfigDiscountInnerServiceSMO payFeeConfigDiscountInnerServiceSMOImpl;
  39. @Override
  40. public int saveFeeDiscount(@RequestBody FeeDiscountPo feeDiscountPo) {
  41. int saveFlag = 1;
  42. feeDiscountServiceDaoImpl.saveFeeDiscountInfo(BeanConvertUtil.beanCovertMap(feeDiscountPo));
  43. return saveFlag;
  44. }
  45. @Override
  46. public int updateFeeDiscount(@RequestBody FeeDiscountPo feeDiscountPo) {
  47. int saveFlag = 1;
  48. feeDiscountServiceDaoImpl.updateFeeDiscountInfo(BeanConvertUtil.beanCovertMap(feeDiscountPo));
  49. return saveFlag;
  50. }
  51. @Override
  52. public int deleteFeeDiscount(@RequestBody FeeDiscountPo feeDiscountPo) {
  53. int saveFlag = 1;
  54. feeDiscountPo.setStatusCd("1");
  55. feeDiscountServiceDaoImpl.updateFeeDiscountInfo(BeanConvertUtil.beanCovertMap(feeDiscountPo));
  56. return saveFlag;
  57. }
  58. @Override
  59. public List<FeeDiscountDto> queryFeeDiscounts(@RequestBody FeeDiscountDto feeDiscountDto) {
  60. //校验是否传了 分页信息
  61. int page = feeDiscountDto.getPage();
  62. if (page != PageDto.DEFAULT_PAGE) {
  63. feeDiscountDto.setPage((page - 1) * feeDiscountDto.getRow());
  64. }
  65. List<FeeDiscountDto> feeDiscounts = BeanConvertUtil.covertBeanList(feeDiscountServiceDaoImpl.getFeeDiscountInfo(BeanConvertUtil.beanCovertMap(feeDiscountDto)), FeeDiscountDto.class);
  66. return feeDiscounts;
  67. }
  68. /**
  69. * 计算折扣
  70. *
  71. * @param feeDetailDto
  72. * @return
  73. */
  74. public List<ComputeDiscountDto> computeDiscount(@RequestBody FeeDetailDto feeDetailDto) {
  75. List<ComputeDiscountDto> computeDiscountDtos = new ArrayList<>();
  76. FeeDto feeDto = new FeeDto();
  77. feeDto.setFeeId(feeDetailDto.getFeeId());
  78. feeDto.setCommunityId(feeDetailDto.getCommunityId());
  79. feeDto.setState(FeeDto.STATE_DOING);
  80. List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
  81. Assert.listOnlyOne(feeDtos, "费用不存在");
  82. PayFeeConfigDiscountDto payFeeConfigDiscountDto = new PayFeeConfigDiscountDto();
  83. payFeeConfigDiscountDto.setConfigId(feeDtos.get(0).getConfigId());
  84. payFeeConfigDiscountDto.setRow(feeDetailDto.getRow());
  85. payFeeConfigDiscountDto.setPage(feeDetailDto.getRow());
  86. payFeeConfigDiscountDto.setCommunityId(feeDetailDto.getCommunityId());
  87. List<PayFeeConfigDiscountDto> payFeeConfigDiscountDtos =
  88. payFeeConfigDiscountInnerServiceSMOImpl.queryPayFeeConfigDiscounts(payFeeConfigDiscountDto);
  89. if (payFeeConfigDiscountDtos == null || payFeeConfigDiscountDtos.size() < 1) {
  90. return computeDiscountDtos;
  91. }
  92. for (PayFeeConfigDiscountDto tmpPayFeeConfigDiscountDto : payFeeConfigDiscountDtos) {
  93. doCompute(tmpPayFeeConfigDiscountDto, Double.parseDouble(feeDetailDto.getCycles()), computeDiscountDtos);
  94. }
  95. return computeDiscountDtos;
  96. }
  97. private void doCompute(PayFeeConfigDiscountDto tmpPayFeeConfigDiscountDto, double cycles, List<ComputeDiscountDto> computeDiscountDtos) {
  98. FeeDiscountDto feeDiscountDto = new FeeDiscountDto();
  99. feeDiscountDto.setCommunityId(tmpPayFeeConfigDiscountDto.getCommunityId());
  100. feeDiscountDto.setDiscountId(tmpPayFeeConfigDiscountDto.getDiscountId());
  101. List<FeeDiscountDto> feeDiscountDtos = queryFeeDiscounts(feeDiscountDto);
  102. if (feeDiscountDtos == null || feeDiscountDtos.size() < 1) {
  103. return;
  104. }
  105. IComputeDiscount computeDiscount = (IComputeDiscount) ApplicationContextFactory.getBean(feeDiscountDtos.get(0).getBeanImpl());
  106. ComputeDiscountDto computeDiscountDto = computeDiscount.compute(feeDiscountDtos.get(0));
  107. computeDiscountDtos.add(computeDiscountDto);
  108. }
  109. @Override
  110. public int queryFeeDiscountsCount(@RequestBody FeeDiscountDto feeDiscountDto) {
  111. return feeDiscountServiceDaoImpl.queryFeeDiscountsCount(BeanConvertUtil.beanCovertMap(feeDiscountDto));
  112. }
  113. public IFeeDiscountServiceDao getFeeDiscountServiceDaoImpl() {
  114. return feeDiscountServiceDaoImpl;
  115. }
  116. public void setFeeDiscountServiceDaoImpl(IFeeDiscountServiceDao feeDiscountServiceDaoImpl) {
  117. this.feeDiscountServiceDaoImpl = feeDiscountServiceDaoImpl;
  118. }
  119. }