From 8749db96edc44e76a9b2ecaf0332e8c0f34fbb5b Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 08 八月 2023 14:58:59 +0800
Subject: [PATCH] 优化代码

---
 service-fee/src/main/java/com/java110/fee/feeMonth/PayFeeMonthHelp.java |  225 +++++++++++++++++++-------------------------------------
 1 files changed, 77 insertions(+), 148 deletions(-)

diff --git a/service-fee/src/main/java/com/java110/fee/feeMonth/PayFeeMonthHelp.java b/service-fee/src/main/java/com/java110/fee/feeMonth/PayFeeMonthHelp.java
index be4bddb..8e92b02 100644
--- a/service-fee/src/main/java/com/java110/fee/feeMonth/PayFeeMonthHelp.java
+++ b/service-fee/src/main/java/com/java110/fee/feeMonth/PayFeeMonthHelp.java
@@ -5,14 +5,12 @@
 import com.java110.dto.fee.FeeAttrDto;
 import com.java110.dto.fee.FeeDetailDto;
 import com.java110.dto.fee.FeeDto;
-import com.java110.dto.payFeeDetailMonth.PayFeeDetailMonthDto;
-import com.java110.dto.payFeeDetailMonth.PayFeeMonthOwnerDto;
+import com.java110.dto.payFee.PayFeeDetailMonthDto;
+import com.java110.dto.payFee.PayFeeMonthOwnerDto;
 import com.java110.intf.community.IRoomInnerServiceSMO;
 import com.java110.intf.fee.IPayFeeDetailMonthInnerServiceSMO;
-import com.java110.po.payFeeDetailMonth.PayFeeDetailMonthPo;
-import com.java110.utils.util.BeanConvertUtil;
+import com.java110.po.payFee.PayFeeDetailMonthPo;
 import com.java110.utils.util.DateUtil;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -54,62 +52,19 @@
 
         Double feePrice = Double.parseDouble(feePriceAll.get("feePrice").toString());
         //todo 濡傛灉鏄竴娆℃�ц垂鐢� 闄や互
-        if (!FeeDto.FEE_FLAG_ONCE.equals(feeDto.getPayerObjType())) {
-            return feePrice;
-        }
-        double maxMonth = Math.ceil(computeFeeSMOImpl.dayCompare(feeDto.getStartTime(), feeDto.getEndTime()));
-        if (maxMonth <= 0) {
-            return feePrice;
-
-        }
-        BigDecimal feePriceDec = new BigDecimal(feePrice).divide(new BigDecimal(maxMonth), 2, BigDecimal.ROUND_HALF_UP);
-        feePrice = feePriceDec.doubleValue();
+//        if (!FeeDto.FEE_FLAG_ONCE.equals(feeDto.getPayerObjType())) {
+//            return feePrice;
+//        }
+//        double maxMonth = Math.ceil(computeFeeSMOImpl.dayCompare(feeDto.getStartTime(), feeDto.getEndTime()));
+//        if (maxMonth <= 0) {
+//            return feePrice;
+//
+//        }
+//        BigDecimal feePriceDec = new BigDecimal(feePrice).divide(new BigDecimal(maxMonth), 2, BigDecimal.ROUND_HALF_UP);
+//        feePrice = feePriceDec.doubleValue();
         return feePrice;
     }
 
-
-    public Double getReceivableAmount(List<FeeDetailDto> feeDetailDtos, Double feePrice, Date curDate, FeeDto feeDto) {
-        FeeDetailDto feeDetailDto = getCurFeeDetail(feeDetailDtos, curDate);
-
-        if (feeDetailDto == null && curDate.getTime() < feeDto.getEndTime().getTime()) {
-            return 0.00;
-        }
-
-        return feePrice;
-    }
-
-    @Override
-    public Double getReceivedAmount(List<FeeDetailDto> feeDetailDtos, Double feePrice, Date curDate, FeeDto feeDto) {
-        //todo 杩欑鎯呭喌涓嬪簲璇� 瀹炴敹涓�0
-        if (curDate.getTime() >= feeDto.getEndTime().getTime()) {
-            return 0.00;
-        }
-        //todo 濡傛灉 fee 涓虹┖
-        if (feeDetailDtos == null) {
-            return feePrice;
-        }
-        FeeDetailDto feeDetailDto = getCurFeeDetail(feeDetailDtos, curDate);
-
-        if (feeDetailDto == null && curDate.getTime() < feeDto.getEndTime().getTime()) {
-            return 0.00;
-        }
-
-        if (feeDetailDto == null) {
-            return feePrice;
-        }
-
-        double maxMonth = Math.ceil(computeFeeSMOImpl.dayCompare(feeDetailDto.getStartTime(), feeDetailDto.getEndTime()));
-
-        if (maxMonth < 1) {
-            return Double.parseDouble(feeDetailDto.getReceivedAmount());
-        }
-
-        BigDecimal totalRecDec = new BigDecimal(feeDetailDto.getReceivedAmount());
-        //姣忔湀骞冲潎鍊�
-        BigDecimal priRecDec = totalRecDec.divide(new BigDecimal(maxMonth), 4, BigDecimal.ROUND_HALF_UP);
-
-        return priRecDec.doubleValue();
-    }
 
     @Override
     public Double getDiscountAmount(Double feePrice, double receivedAmount, Date curDate, FeeDto feeDto) {
@@ -123,36 +78,14 @@
         return discountAmountDec.doubleValue();
     }
 
-    @Override
-    public String getFeeDetailId(List<FeeDetailDto> feeDetailDtos, Date curDate) {
-        FeeDetailDto feeDetailDto = getCurFeeDetail(feeDetailDtos, curDate);
-
-        if (feeDetailDto == null) {
-            return "-1";
-        }
-        return feeDetailDto.getDetailId();
-    }
-
-    @Override
-    public String getFeeFeeTime(List<FeeDetailDto> feeDetailDtos, String detailId) {
-
-        if (feeDetailDtos == null || feeDetailDtos.size() < 1) {
-            return null;
-        }
-        for (FeeDetailDto feeDetailDto : feeDetailDtos) {
-            if (feeDetailDto.getDetailId().equals(detailId)) {
-                return DateUtil.getFormatTimeStringA(feeDetailDto.getCreateTime());
-            }
-        }
-        return null;
-    }
 
     /**
-     *  澶勭悊宸茬粡浜よ繃璐圭殑璁板綍澶勭悊
+     * 澶勭悊宸茬粡浜よ繃璐圭殑璁板綍澶勭悊
+     *
      * @param feeDto
      * @param payFeeMonthOwnerDto
      */
-    @Autowired
+    @Override
     public void waitDispersedFeeDetail(FeeDto feeDto, PayFeeMonthOwnerDto payFeeMonthOwnerDto) {
         PayFeeDetailMonthDto payFeeDetailMonthDto = new PayFeeDetailMonthDto();
         payFeeDetailMonthDto.setCommunityId(feeDto.getCommunityId());
@@ -163,6 +96,7 @@
             return;
         }
 
+
         for (FeeDetailDto feeDetailDto : feeDetailDtos) {
             // todo 閫愭潯鍘荤鏁�
             doDispersedFeeDetail(feeDetailDto, feeDto, payFeeMonthOwnerDto);
@@ -172,17 +106,15 @@
 
     /**
      * 澶勭悊 娆犺垂 绂绘暎
+     *
      * @param feeDto
      * @param payFeeMonthOwnerDto
      * @param feePrice
      * @param deadlineTime
      */
-    @Autowired
+    @Override
     public void waitDispersedOweFee(FeeDto feeDto, PayFeeMonthOwnerDto payFeeMonthOwnerDto, Double feePrice, Date deadlineTime) {
-        // todo 璐圭敤宸茬粡缁撴潫
-        if(FeeDto.STATE_FINISH.equals(feeDto.getState())){
-            return ;
-        }
+
 
         // todo 娓呯悊 detailId 涓�-1 鐨勬暟鎹�
         PayFeeDetailMonthPo payFeeDetailMonthPo = new PayFeeDetailMonthPo();
@@ -191,12 +123,28 @@
         payFeeDetailMonthPo.setDetailId("-1");
         payFeeDetailMonthInnerServiceSMOImpl.deletePayFeeDetailMonth(payFeeDetailMonthPo);
 
+        // todo 璐圭敤宸茬粡缁撴潫
+        if (FeeDto.STATE_FINISH.equals(feeDto.getState())) {
+            return;
+        }
+
         List<PayFeeDetailMonthPo> payFeeDetailMonthPos = new ArrayList<>();
         // todo 澶勭悊 寮�濮嬫椂闂村拰缁撴潫鏃堕棿
         Date startTime = DateUtil.timeToDate(feeDto.getEndTime());
         Date endTime = DateUtil.timeToDate(deadlineTime);
 
         BigDecimal receivableAmount = new BigDecimal(feePrice);
+
+        BigDecimal dayReceivableAmount = null;
+
+        //todo 涓�娆℃�ц垂鐢� 鏃ュ簲鏀惰绠�
+        if (FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())) {
+            int day = DateUtil.daysBetween(endTime, startTime);
+            if (day < 1) {
+                day = 1;
+            }
+            dayReceivableAmount = receivableAmount.divide(new BigDecimal(day), 8, BigDecimal.ROUND_HALF_UP);// 鏃� 搴旀敹
+        }
 
         // todo 瀵绘壘绗竴涓嚜鐒舵湀 涓�鏃�
         Calendar firstMonthDayCal = Calendar.getInstance();
@@ -210,20 +158,27 @@
         int curDay = 0;
         int curMonthMaxDay = 30;
         BigDecimal curMonthReceivableAmount = null;
-        BigDecimal dayReceivableAmount = null;
-        while (firstMonthDayTime.getTime() > endTime.getTime()) {
-            curDay = DateUtil.daysBetween(firstMonthDayTime, startMonthDayTime);
 
+        while (firstMonthDayTime.getTime() < endTime.getTime()) {
+            curDay = DateUtil.daysBetween(firstMonthDayTime, startMonthDayTime);
             // todo 璁$畻褰撴湀澶╂暟
             Calendar calendar = Calendar.getInstance();
             calendar.setTime(startMonthDayTime);
             curMonthMaxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
-            dayReceivableAmount = receivableAmount.divide(new BigDecimal(curMonthMaxDay), 4, BigDecimal.ROUND_HALF_UP);// 鏃� 瀹炴敹
-            // todo 璁$畻 搴旀敹
-            curMonthReceivableAmount = new BigDecimal(curDay).multiply(dayReceivableAmount).setScale(4, BigDecimal.ROUND_HALF_UP);
 
+            // todo 濡傛灉涓嶆槸鏁存湀锛屽垯杞崲涓烘寜澶╄绠�
+//            if (curDay != curMonthMaxDay) {
+                //todo 鍛ㄦ湡鎬ц垂鐢� 鏃ュ簲鏀堕噸鏂扮畻
+                if (!FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())) {
+                    dayReceivableAmount = receivableAmount.divide(new BigDecimal(curMonthMaxDay), 8, BigDecimal.ROUND_HALF_UP);// 鏃� 瀹炴敹
+                }
+                // todo 璁$畻 搴旀敹
+                curMonthReceivableAmount = new BigDecimal(curDay).multiply(dayReceivableAmount).setScale(4, BigDecimal.ROUND_HALF_UP);
+//            } else { // todo 濡傛灉鏄暣鏈� 閭e氨鎸夋湀璁$畻锛屼互鍏� 杞崲鎴愬ぉ鍐� 涔樹互澶╂暟鍚庣殑璇樊
+//                curMonthReceivableAmount = receivableAmount;
+//            }
             // todo 淇濆瓨鏁版嵁鍒皃ay_fee_detail_month
-            toSavePayFeeDetailMonth(curMonthReceivableAmount.doubleValue(), 0, null, feeDto, payFeeMonthOwnerDto,payFeeDetailMonthPos,startMonthDayTime);
+            toSavePayFeeDetailMonth(curMonthReceivableAmount.doubleValue(), 0, null, feeDto, payFeeMonthOwnerDto, payFeeDetailMonthPos, startMonthDayTime, deadlineTime);
 
             // todo 灏唖tartTime 淇敼涓� 涓嬫湀1鏃ユ椂闂�
             startMonthDayTime = firstMonthDayTime;
@@ -238,22 +193,29 @@
         }
 
         curDay = DateUtil.daysBetween(endTime, startMonthDayTime);
-
         // todo 璁$畻褰撴湀澶╂暟
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(startMonthDayTime);
         curMonthMaxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
-        dayReceivableAmount = receivableAmount.divide(new BigDecimal(curMonthMaxDay), 4, BigDecimal.ROUND_HALF_UP);// 鏃� 瀹炴敹
-        // todo 璁$畻 搴旀敹
-        curMonthReceivableAmount = new BigDecimal(curDay).multiply(dayReceivableAmount).setScale(4, BigDecimal.ROUND_HALF_UP);
-
+        // todo 濡傛灉涓嶆槸鏁存湀锛屽垯杞崲涓烘寜澶╄绠�
+        if (curDay != curMonthMaxDay) {
+            //todo 鍛ㄦ湡鎬ц垂鐢� 鏃ュ簲鏀堕噸鏂扮畻
+            if (!FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())) {
+                dayReceivableAmount = receivableAmount.divide(new BigDecimal(curMonthMaxDay), 4, BigDecimal.ROUND_HALF_UP);// 鏃� 瀹炴敹
+            }
+            // todo 璁$畻 搴旀敹
+            curMonthReceivableAmount = new BigDecimal(curDay).multiply(dayReceivableAmount).setScale(4, BigDecimal.ROUND_HALF_UP);
+        } else { // todo 濡傛灉鏄暣鏈� 閭e氨鎸夋湀璁$畻锛屼互鍏� 杞崲鎴愬ぉ鍐� 涔樹互澶╂暟鍚庣殑璇樊
+            curMonthReceivableAmount = receivableAmount;
+        }
         // todo 淇濆瓨鏁版嵁鍒皃ay_fee_detail_month
-        toSavePayFeeDetailMonth(curMonthReceivableAmount.doubleValue(), 0, null, feeDto, payFeeMonthOwnerDto,payFeeDetailMonthPos,startMonthDayTime);
+        toSavePayFeeDetailMonth(curMonthReceivableAmount.doubleValue(), 0, null, feeDto, payFeeMonthOwnerDto, payFeeDetailMonthPos, startMonthDayTime, deadlineTime);
         payFeeDetailMonthInnerServiceSMOImpl.savePayFeeDetailMonths(payFeeDetailMonthPos);
 
     }
 
-    private void doDispersedFeeDetail(FeeDetailDto feeDetailDto, FeeDto feeDto, PayFeeMonthOwnerDto payFeeMonthOwnerDto) {
+    private void doDispersedFeeDetail(FeeDetailDto feeDetailDto, FeeDto feeDto, PayFeeMonthOwnerDto
+            payFeeMonthOwnerDto) {
         List<PayFeeDetailMonthPo> payFeeDetailMonthPos = new ArrayList<>();
 
         // todo 鍘婚櫎 寮�濮嬫椂闂村拰 缁撴潫鏃堕棿鐨� 灏忔椂 鍒嗛挓 绉�
@@ -268,8 +230,8 @@
         BigDecimal receivableAmount = new BigDecimal(Double.parseDouble(feeDetailDto.getReceivableAmount()));
         BigDecimal receivedAmount = new BigDecimal(Double.parseDouble(feeDetailDto.getReceivedAmount()));
 
-        BigDecimal dayReceivableAmount = receivableAmount.divide(new BigDecimal(day), 4, BigDecimal.ROUND_HALF_UP);// 鏃� 搴旀敹
-        BigDecimal dayReceivedAmount = receivedAmount.divide(new BigDecimal(day), 4, BigDecimal.ROUND_HALF_UP);// 鏃� 瀹炴敹
+        BigDecimal dayReceivableAmount = receivableAmount.divide(new BigDecimal(day), 8, BigDecimal.ROUND_HALF_UP);// 鏃� 搴旀敹
+        BigDecimal dayReceivedAmount = receivedAmount.divide(new BigDecimal(day), 8, BigDecimal.ROUND_HALF_UP);// 鏃� 瀹炴敹
 
         // todo 瀵绘壘绗竴涓嚜鐒舵湀 涓�鏃�
         Calendar firstMonthDayCal = Calendar.getInstance();
@@ -283,7 +245,7 @@
         int curDay = 0;
         BigDecimal curMonthReceivableAmount = null;
         BigDecimal curMonthReceivedAmount = null;
-        while (firstMonthDayTime.getTime() > endTime.getTime()) {
+        while (firstMonthDayTime.getTime() < endTime.getTime()) {
             curDay = DateUtil.daysBetween(firstMonthDayTime, startMonthDayTime);
             // todo 璁$畻 搴旀敹
             curMonthReceivableAmount = new BigDecimal(curDay).multiply(dayReceivableAmount).setScale(4, BigDecimal.ROUND_HALF_UP);
@@ -291,7 +253,7 @@
             curMonthReceivedAmount = new BigDecimal(curDay).multiply(dayReceivedAmount).setScale(4, BigDecimal.ROUND_HALF_UP);
 
             // todo 淇濆瓨鏁版嵁鍒皃ay_fee_detail_month
-            toSavePayFeeDetailMonth(curMonthReceivableAmount.doubleValue(), curMonthReceivedAmount.doubleValue(), feeDetailDto, feeDto, payFeeMonthOwnerDto,payFeeDetailMonthPos,startMonthDayTime);
+            toSavePayFeeDetailMonth(curMonthReceivableAmount.doubleValue(), curMonthReceivedAmount.doubleValue(), feeDetailDto, feeDto, payFeeMonthOwnerDto, payFeeDetailMonthPos, startMonthDayTime, endTime);
 
             // todo 灏唖tartTime 淇敼涓� 涓嬫湀1鏃ユ椂闂�
             startMonthDayTime = firstMonthDayTime;
@@ -312,7 +274,7 @@
         curMonthReceivedAmount = new BigDecimal(curDay).multiply(dayReceivedAmount).setScale(4, BigDecimal.ROUND_HALF_UP);
 
         // todo 淇濆瓨鏁版嵁鍒皃ay_fee_detail_month
-        toSavePayFeeDetailMonth(curMonthReceivableAmount.doubleValue(), curMonthReceivedAmount.doubleValue(), feeDetailDto, feeDto, payFeeMonthOwnerDto,payFeeDetailMonthPos,startMonthDayTime);
+        toSavePayFeeDetailMonth(curMonthReceivableAmount.doubleValue(), curMonthReceivedAmount.doubleValue(), feeDetailDto, feeDto, payFeeMonthOwnerDto, payFeeDetailMonthPos, startMonthDayTime, endTime);
         payFeeDetailMonthInnerServiceSMOImpl.savePayFeeDetailMonths(payFeeDetailMonthPos);
 
     }
@@ -331,16 +293,17 @@
                                          FeeDto feeDto,
                                          PayFeeMonthOwnerDto payFeeMonthOwnerDto,
                                          List<PayFeeDetailMonthPo> payFeeDetailMonthPos,
-                                         Date curTime) {
+                                         Date curTime,
+                                         Date deadlineTime) {
 
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(curTime);
         PayFeeDetailMonthPo tmpPayFeeDetailMonthPo = new PayFeeDetailMonthPo();
         tmpPayFeeDetailMonthPo.setFeeId(feeDto.getFeeId());
         tmpPayFeeDetailMonthPo.setCommunityId(feeDto.getCommunityId());
-        if(feeDetailDto == null){
+        if (feeDetailDto == null) {
             tmpPayFeeDetailMonthPo.setDetailId("-1");
-        }else{ // todo 浜よ垂璁板綍 淇濆瓨鏃�
+        } else { // todo 浜よ垂璁板綍 淇濆瓨鏃�
             tmpPayFeeDetailMonthPo.setDetailId(feeDetailDto.getDetailId());
         }
         tmpPayFeeDetailMonthPo.setDetailYear(calendar.get(Calendar.YEAR) + "");
@@ -352,7 +315,7 @@
                 getDiscountAmount(Double.parseDouble(tmpPayFeeDetailMonthPo.getReceivableAmount()),
                         Double.parseDouble(tmpPayFeeDetailMonthPo.getReceivedAmount()),
                         calendar.getTime(), feeDto) + "");
-        tmpPayFeeDetailMonthPo.setMonthId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_monthId));
+        tmpPayFeeDetailMonthPo.setMonthId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_monthId, true));
         tmpPayFeeDetailMonthPo.setRemark("绋嬪簭璁$畻鐢熸垚");
         tmpPayFeeDetailMonthPo.setObjName(payFeeMonthOwnerDto.getObjName());
         tmpPayFeeDetailMonthPo.setObjId(payFeeMonthOwnerDto.getObjId());
@@ -360,9 +323,10 @@
         tmpPayFeeDetailMonthPo.setOwnerName(payFeeMonthOwnerDto.getOwnerName());
         tmpPayFeeDetailMonthPo.setLink(payFeeMonthOwnerDto.getLink());
         tmpPayFeeDetailMonthPo.setCurMonthTime(DateUtil.getFormatTimeStringB(calendar.getTime()));
-        if(feeDetailDto == null){
+        tmpPayFeeDetailMonthPo.setDeadlineTime(DateUtil.getFormatTimeStringA(deadlineTime));
+        if (feeDetailDto == null) {
             tmpPayFeeDetailMonthPo.setPayFeeTime(null);
-        }else{ // todo 浜よ垂璁板綍 淇濆瓨鏃�
+        } else { // todo 浜よ垂璁板綍 淇濆瓨鏃�
             tmpPayFeeDetailMonthPo.setPayFeeTime(DateUtil.getFormatTimeStringA(feeDetailDto.getCreateTime()));
         }
         tmpPayFeeDetailMonthPo.setState("W"); // todo 杩欓噷鏆傛椂鍐欐锛岀洰鍓嶇敤涓嶅埌锛岀畻鏄鐣欏瓧娈�
@@ -370,41 +334,6 @@
         tmpPayFeeDetailMonthPo.setConfigId(feeDto.getConfigId());
         payFeeDetailMonthPos.add(tmpPayFeeDetailMonthPo);
 
-    }
-
-    /**
-     * 鑾峰彇褰撳墠缂磋垂璁板綍
-     *
-     * @param feeDetailDtos
-     * @param curDate
-     * @return
-     */
-    private FeeDetailDto getCurFeeDetail(List<FeeDetailDto> feeDetailDtos, Date curDate) {
-        if (feeDetailDtos == null || feeDetailDtos.size() < 1) {
-            return null;
-        }
-        List<FeeDetailDto> tFeeDetailDtos = new ArrayList<>();
-        for (FeeDetailDto feeDetailDto : feeDetailDtos) {
-            if (feeDetailDto.getStartTime().getTime() <= curDate.getTime() && feeDetailDto.getEndTime().getTime() > curDate.getTime()) {
-                tFeeDetailDtos.add(BeanConvertUtil.covertBean(feeDetailDto,FeeDetailDto.class));
-            }
-        }
-
-        if (tFeeDetailDtos.size() < 1) {
-            return null;
-        }
-        if (tFeeDetailDtos.size() == 1) {
-            return tFeeDetailDtos.get(0);
-        }
-        //todo 杩欑搴旇鏄暟鎹紓甯� 涔熷氨鏄竴涓湀璐圭敤鍙樻洿鍚庨噸澶嶇即璐�
-        BigDecimal cReceivedAmount = new BigDecimal(0.00);
-        for (FeeDetailDto feeDetailDto : tFeeDetailDtos) {
-            cReceivedAmount = cReceivedAmount.add(new BigDecimal(Double.parseDouble(feeDetailDto.getReceivedAmount()))).setScale(4, BigDecimal.ROUND_HALF_UP);
-        }
-
-        tFeeDetailDtos.get(0).setReceivedAmount(cReceivedAmount.doubleValue() + "");
-
-        return tFeeDetailDtos.get(0);
     }
 
 

--
Gitblit v1.8.0