cgf
2025-08-09 569bd97e623c596ac2db49aa65c88966380b6562
service-fee/src/main/java/com/java110/fee/smo/impl/FeeDiscountInnerServiceSMOImpl.java
@@ -2,24 +2,22 @@
import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.applyRoomDiscount.ApplyRoomDiscountDto;
import com.java110.dto.room.ApplyRoomDiscountDto;
import com.java110.dto.fee.FeeDetailDto;
import com.java110.dto.fee.FeeDto;
import com.java110.dto.feeDiscount.ComputeDiscountDto;
import com.java110.dto.feeDiscount.FeeDiscountDto;
import com.java110.dto.feeDiscount.FeeDiscountRuleDto;
import com.java110.dto.feeDiscount.FeeDiscountSpecDto;
import com.java110.dto.payFeeConfigDiscount.PayFeeConfigDiscountDto;
import com.java110.dto.fee.ComputeDiscountDto;
import com.java110.dto.fee.FeeDiscountDto;
import com.java110.dto.fee.FeeDiscountRuleDto;
import com.java110.dto.fee.FeeDiscountSpecDto;
import com.java110.dto.payFee.PayFeeConfigDiscountDto;
import com.java110.dto.work.WorkCopyDto;
import com.java110.fee.dao.IFeeDiscountServiceDao;
import com.java110.fee.discount.IComputeDiscount;
import com.java110.intf.fee.*;
import com.java110.po.feeDiscount.FeeDiscountPo;
import com.java110.po.fee.FeeDiscountPo;
import com.java110.utils.cache.MappingCache;
import com.java110.utils.factory.ApplicationContextFactory;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.MoneyUtil;
import com.java110.utils.util.StringUtil;
import com.java110.utils.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@@ -165,7 +163,7 @@
        //根据费用项查询折扣(该费用项下的所有折扣信息)
        List<PayFeeConfigDiscountDto> payFeeConfigDiscountDtos =
                payFeeConfigDiscountInnerServiceSMOImpl.queryPayFeeConfigDiscounts(payFeeConfigDiscountDto);
        if (payFeeConfigDiscountDtos == null || payFeeConfigDiscountDtos.size() < 1) {
        if (ListUtil.isNull(payFeeConfigDiscountDtos)) {
            computeApplyRoomDiscount(feeDetailDto, simpleDateFormat, c, computeDiscountDtos);
            //取出开关映射的值
            String value = MappingCache.getValue(DOMAIN_COMMON, DISCOUNT_MODE);
@@ -199,19 +197,28 @@
            feeDiscountDto.setDiscountId(tmpPayFeeConfigDiscountDto.getDiscountId());
            //查询打折表
            List<FeeDiscountDto> feeDiscountInfo = BeanConvertUtil.covertBeanList(feeDiscountServiceDaoImpl.getFeeDiscountInfo(BeanConvertUtil.beanCovertMap(feeDiscountDto)), FeeDiscountDto.class);
            Assert.listOnlyOne(feeDiscountInfo, "查询打折表错误!");
            //Assert.listOnlyOne(feeDiscountInfo, "查询打折表错误!");
            if(ListUtil.isNull(feeDiscountInfo)){
                continue;
            }
            FeeDiscountRuleDto feeDiscountRuleDto = new FeeDiscountRuleDto();
            feeDiscountRuleDto.setRuleId(feeDiscountInfo.get(0).getRuleId());
            //查询打折规则表
            List<FeeDiscountRuleDto> feeDiscountRuleDtos = feeDiscountRuleInnerServiceSMOImpl.queryFeeDiscountRules(feeDiscountRuleDto);
            Assert.listOnlyOne(feeDiscountRuleDtos, "查询打折规则表错误!");
            //Assert.listOnlyOne(feeDiscountRuleDtos, "查询打折规则表错误!");
            if(ListUtil.isNull(feeDiscountRuleDtos)){
                continue;
            }
            if (!StringUtil.isEmpty(feeDiscountRuleDtos.get(0).getBeanImpl()) && feeDiscountRuleDtos.get(0).getBeanImpl().equals("reductionMonthFeeRule")) { //赠送规则
                FeeDiscountSpecDto feeDiscountSpecDto = new FeeDiscountSpecDto();
                feeDiscountSpecDto.setDiscountId(tmpPayFeeConfigDiscountDto.getDiscountId());
                feeDiscountSpecDto.setSpecId(SPEC_RATE);
                //查询打折规格
                List<FeeDiscountSpecDto> feeDiscountSpecDtos = feeDiscountSpecInnerServiceSMOImpl.queryFeeDiscountSpecs(feeDiscountSpecDto);
                Assert.listOnlyOne(feeDiscountSpecDtos, "查询打折规格表错误!");
                //Assert.listOnlyOne(feeDiscountSpecDtos, "查询打折规格表错误!");
                if(ListUtil.isNull(feeDiscountSpecDtos)){
                    continue;
                }
                //获取赠送月份
                String specValue = feeDiscountSpecDtos.get(0).getSpecValue();
                Calendar cal = Calendar.getInstance();
@@ -262,19 +269,25 @@
            //房屋id
            applyRoomDiscountDto.setRoomId(feeDetailDto.getPayerObjId());
            //开始时间
            applyRoomDiscountDto.setStartTime(simpleDateFormat.format(feeDetailDto.getStartTime()));
//            applyRoomDiscountDto.setStartTime(simpleDateFormat.format(feeDetailDto.getStartTime()));
            //结束时间
            c.setTime(feeDetailDto.getStartTime());
            c.add(Calendar.DAY_OF_MONTH, 2);//开始时间,添加1,2天的冗余,只要比5小即可
            applyRoomDiscountDto.setStartTime(simpleDateFormat.format(c.getTime()));//重新设置开始时间
//            c.add(Calendar.DAY_OF_MONTH, 2);//开始时间,添加1,2天的冗余,只要比5小即可
//            applyRoomDiscountDto.setStartTime(simpleDateFormat.format(c.getTime()));//重新设置开始时间
            double month = Double.parseDouble(feeDetailDto.getCycles());
//            if(month == 105){
//                return;
//            }
            c.add(Calendar.MONTH, (int) month);
            c.add(Calendar.DAY_OF_MONTH, -5);//这里根据设置时间荣誉5天
//            c.add(Calendar.DAY_OF_MONTH, -5);//这里根据设置时间荣誉5天
            Date endTime = c.getTime();
            applyRoomDiscountDto.setEndTime(simpleDateFormat.format(endTime));
//            applyRoomDiscountDto.setEndTime(simpleDateFormat.format(endTime));
            applyRoomDiscountDto.setFeeId(feeDetailDto.getFeeId());
            //查询折扣申请表
            List<ApplyRoomDiscountDto> applyRoomDiscountDtos = applyRoomDiscountInnerServiceSMOImpl.queryApplyRoomDiscounts(applyRoomDiscountDto);
            //判断查询的折扣申请表是否有数据
            if (applyRoomDiscountDtos != null && applyRoomDiscountDtos.size() > 0) {
                //获取优惠id
@@ -284,11 +297,51 @@
                PayFeeConfigDiscountDto payFeeConfigDiscount = new PayFeeConfigDiscountDto();
                payFeeConfigDiscount.setCommunityId(applyRoomDiscountDtos.get(0).getCommunityId());
                payFeeConfigDiscount.setDiscountId(discountId);
                doCompute(payFeeConfigDiscount, Double.parseDouble(feeDetailDto.getCycles()), computeDiscountDtos, feeDetailDto.getFeeId());
                if(applyRoomDiscountDtos.get(0).getStartTime() == null){
                    payFeeConfigDiscount.setStartTime(feeDetailDto.getStartTime());
                }else if(DateUtil.getDateFromStringB(applyRoomDiscountDtos.get(0).getStartTime()).before(feeDetailDto.getStartTime())){
                    payFeeConfigDiscount.setStartTime(feeDetailDto.getStartTime());
                }else{
                    payFeeConfigDiscount.setStartTime(DateUtil.getDateFromStringB(applyRoomDiscountDtos.get(0).getStartTime()));
                }
                if(applyRoomDiscountDtos.get(0).getEndTime() == null){
                    payFeeConfigDiscount.setEndTime(endTime);
                }else if(DateUtil.getDateFromStringB(applyRoomDiscountDtos.get(0).getEndTime()).after(feeDetailDto.getEndTime())){
                    payFeeConfigDiscount.setEndTime(feeDetailDto.getEndTime());
                }else{
                    payFeeConfigDiscount.setEndTime(DateUtil.getDateFromStringB(applyRoomDiscountDtos.get(0).getEndTime()));
                }
                double cycle =
                        DateUtil.dayCompare(
                                payFeeConfigDiscount.getStartTime(),
                                payFeeConfigDiscount.getEndTime()
                        );
                doComputeB(payFeeConfigDiscount, cycle, computeDiscountDtos, feeDetailDto.getFeeId());
            }
        }
    }
    private void doComputeB(PayFeeConfigDiscountDto tmpPayFeeConfigDiscountDto, double cycles, List<ComputeDiscountDto> computeDiscountDtos, String feeId) {
        FeeDiscountDto feeDiscountDto = new FeeDiscountDto();
        feeDiscountDto.setCommunityId(tmpPayFeeConfigDiscountDto.getCommunityId());
        feeDiscountDto.setDiscountId(tmpPayFeeConfigDiscountDto.getDiscountId());
        List<FeeDiscountDto> feeDiscountDtos = queryFeeDiscounts(feeDiscountDto);
        if (feeDiscountDtos == null || feeDiscountDtos.size() < 1) {
            return;
        }
        for (FeeDiscountDto tmpFeeDiscountDto : feeDiscountDtos) {
            tmpFeeDiscountDto.setFeeId(feeId);
            tmpFeeDiscountDto.setCycles(cycles);
        }
        IComputeDiscount computeDiscount = (IComputeDiscount) ApplicationContextFactory.getBean(feeDiscountDtos.get(0).getBeanImpl());
        ComputeDiscountDto computeDiscountDto = computeDiscount.compute(feeDiscountDtos.get(0));
        if (computeDiscountDto == null) {
            return;
        }
        computeDiscountDtos.add(computeDiscountDto);
    }
    private void doCompute(PayFeeConfigDiscountDto tmpPayFeeConfigDiscountDto, double cycles, List<ComputeDiscountDto> computeDiscountDtos, String feeId) {
        FeeDiscountDto feeDiscountDto = new FeeDiscountDto();
        feeDiscountDto.setCommunityId(tmpPayFeeConfigDiscountDto.getCommunityId());