From 9b143ce6f7cb9c72183bc6526ed4ac4f3d2e484b Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 15 十二月 2020 12:37:58 +0800
Subject: [PATCH] 优化菜单发布问题

---
 service-api/src/main/java/com/java110/api/bmo/fee/impl/FeeBMOImpl.java |  136 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 103 insertions(+), 33 deletions(-)

diff --git a/service-api/src/main/java/com/java110/api/bmo/fee/impl/FeeBMOImpl.java b/service-api/src/main/java/com/java110/api/bmo/fee/impl/FeeBMOImpl.java
index 653a1a5..84127e4 100644
--- a/service-api/src/main/java/com/java110/api/bmo/fee/impl/FeeBMOImpl.java
+++ b/service-api/src/main/java/com/java110/api/bmo/fee/impl/FeeBMOImpl.java
@@ -6,6 +6,7 @@
 import com.java110.api.bmo.fee.IFeeBMO;
 import com.java110.core.context.DataFlowContext;
 import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.core.smo.IComputeFeeSMO;
 import com.java110.dto.RoomDto;
 import com.java110.dto.fee.FeeConfigDto;
 import com.java110.dto.fee.FeeDto;
@@ -24,7 +25,6 @@
 import com.java110.po.fee.PayFeePo;
 import com.java110.po.feeReceipt.FeeReceiptPo;
 import com.java110.po.feeReceiptDetail.FeeReceiptDetailPo;
-import com.java110.core.smo.IComputeFeeSMO;
 import com.java110.utils.constant.BusinessTypeConstant;
 import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.constant.ResponseConstant;
@@ -125,7 +125,7 @@
         business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S);
         JSONObject businessFeeDetail = new JSONObject();
         businessFeeDetail.putAll(paramInJson);
-        businessFeeDetail.put("detailId", "-1");
+        businessFeeDetail.put("detailId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
         businessFeeDetail.put("primeRate", "1.00");
         //璁$畻 搴旀敹閲戦
         FeeDto feeDto = new FeeDto();
@@ -136,51 +136,48 @@
         if (feeDtos == null || feeDtos.size() != 1) {
             throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "鏌ヨ璐圭敤淇℃伅澶辫触锛屾湭鏌ュ埌鏁版嵁鎴栨煡鍒板鏉℃暟鎹�");
         }
-
+        if (!businessFeeDetail.containsKey("state")) {
+            businessFeeDetail.put("state", "1400");
+        }
         feeDto = feeDtos.get(0);
         businessFeeDetail.put("startTime", DateUtil.getFormatTimeString(feeDto.getEndTime(), DateUtil.DATE_FORMATE_STRING_A));
         int hours = 0;
         Date targetEndTime = null;
+        BigDecimal cycles = null;
+        BigDecimal feePrice = new BigDecimal(computeFeeSMOImpl.getFeePrice(feeDto));
         if ("-101".equals(paramInJson.getString("cycles"))) {
             Date endTime = feeDto.getEndTime();
             Calendar endCalender = Calendar.getInstance();
             endCalender.setTime(endTime);
-            hours = new Double(Double.parseDouble(paramInJson.getString("tmpCycles")) * DateUtil.getCurrentMonthDay() * 24).intValue();
-            endCalender.add(Calendar.HOUR, hours);
-            targetEndTime = endCalender.getTime();
-        } else {
-            targetEndTime = computeFeeSMOImpl.getFeeEndTimeByCycles(feeDto, paramInJson.getString("cycles"));
-        }
-        businessFeeDetail.put("endTime", DateUtil.getFormatTimeString(targetEndTime, DateUtil.DATE_FORMATE_STRING_A));
-        paramInJson.put("feeInfo", feeDto);
-
-        BigDecimal feePrice = new BigDecimal(computeFeeSMOImpl.getFeePrice(feeDto));
-
-        BigDecimal cycles = null;
-        //BigDecimal receivableAmount = feePrice;
-        if ("-101".equals(paramInJson.getString("cycles"))) {//鑷畾涔夌即璐�
             BigDecimal receivedAmount = new BigDecimal(Double.parseDouble(paramInJson.getString("receivedAmount")));
-            cycles = receivedAmount.divide(feePrice, 2, BigDecimal.ROUND_HALF_EVEN);
-            paramInJson.put("tmpCycles", cycles);
+            cycles = receivedAmount.divide(feePrice, 4, BigDecimal.ROUND_HALF_EVEN);
+            endCalender = getTargetEndTime(endCalender, cycles.doubleValue());
+            targetEndTime = endCalender.getTime();
+            paramInJson.put("tmpCycles", cycles.doubleValue());
             businessFeeDetail.put("cycles", cycles.doubleValue());
             businessFeeDetail.put("receivableAmount", receivedAmount.doubleValue());
         } else {
+            targetEndTime = computeFeeSMOImpl.getFeeEndTimeByCycles(feeDto, paramInJson.getString("cycles"));
             cycles = new BigDecimal(Double.parseDouble(paramInJson.getString("cycles")));
             double tmpReceivableAmount = cycles.multiply(feePrice).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
             businessFeeDetail.put("receivableAmount", tmpReceivableAmount);
         }
 
-        business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put(PayFeeDetailPo.class.getSimpleName(), businessFeeDetail);
+        businessFeeDetail.put("endTime", DateUtil.getFormatTimeString(targetEndTime, DateUtil.DATE_FORMATE_STRING_A));
+        paramInJson.put("feeInfo", feeDto);
 
-        feeReceiptDetailPo.setAmount(businessFeeDetail.getString("receivableAmount"));
+        business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put(PayFeeDetailPo.class.getSimpleName(), businessFeeDetail);
+        paramInJson.put("detailId", businessFeeDetail.getString("detailId"));
+        feeReceiptDetailPo.setAmount(businessFeeDetail.getString("receivedAmount"));
         feeReceiptDetailPo.setCommunityId(feeDto.getCommunityId());
         feeReceiptDetailPo.setCycle(businessFeeDetail.getString("cycles"));
-        feeReceiptDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
+        feeReceiptDetailPo.setDetailId(businessFeeDetail.getString("detailId"));
         feeReceiptDetailPo.setEndTime(businessFeeDetail.getString("endTime"));
         feeReceiptDetailPo.setFeeId(feeDto.getFeeId());
         feeReceiptDetailPo.setFeeName(StringUtil.isEmpty(feeDto.getImportFeeName()) ? feeDto.getFeeName() : feeDto.getImportFeeName());
         feeReceiptDetailPo.setStartTime(businessFeeDetail.getString("startTime"));
         feeReceiptDetailPo.setReceiptId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_receiptId));
+        computeFeeSMOImpl.freshFeeReceiptDetail(feeDto, feeReceiptDetailPo);
         feeReceiptPo.setAmount(feeReceiptDetailPo.getAmount());
         feeReceiptPo.setCommunityId(feeReceiptDetailPo.getCommunityId());
         feeReceiptPo.setReceiptId(feeReceiptDetailPo.getReceiptId());
@@ -188,6 +185,25 @@
         feeReceiptPo.setObjId(feeDto.getPayerObjId());
         feeReceiptPo.setObjName(computeFeeSMOImpl.getFeeObjName(feeDto));
         return business;
+    }
+
+    private static Calendar getTargetEndTime(Calendar endCalender, Double cycles) {
+        if (StringUtil.isInteger(cycles.toString())) {
+            endCalender.add(Calendar.MONTH, new Double(cycles).intValue());
+
+            return endCalender;
+        }
+
+        if (cycles >= 1) {
+            endCalender.add(Calendar.MONTH, new Double(Math.floor(cycles)).intValue());
+            cycles = cycles - Math.floor(cycles);
+        }
+        //int hours = new Double(cycles * DateUtil.getCurrentMonthDay() * 24).intValue();
+        int futureDay = endCalender.getActualMaximum(Calendar.DAY_OF_MONTH);
+        int hours = new Double(cycles * futureDay * 24).intValue();
+        endCalender.add(Calendar.HOUR, hours);
+
+        return endCalender;
     }
 
 
@@ -232,8 +248,10 @@
         endCalender.setTime(endTime);
         int hours = 0;
         if ("-101".equals(paramInJson.getString("cycles"))) {
-            hours = new Double(Double.parseDouble(paramInJson.getString("tmpCycles")) * DateUtil.getCurrentMonthDay() * 24).intValue();
-            endCalender.add(Calendar.HOUR, hours);
+//            hours = new Double(Double.parseDouble(paramInJson.getString("tmpCycles")) * DateUtil.getCurrentMonthDay() * 24).intValue();
+//            endCalender.add(Calendar.HOUR, hours);
+
+            endCalender = getTargetEndTime(endCalender, Double.parseDouble(paramInJson.getString("tmpCycles")));
         } else {
             endCalender.add(Calendar.MONTH, Integer.parseInt(paramInJson.getString("cycles")));
         }
@@ -272,8 +290,12 @@
         business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S);
         JSONObject businessFeeDetail = new JSONObject();
         businessFeeDetail.putAll(paramInJson);
-        businessFeeDetail.put("detailId", "-1");
+        businessFeeDetail.put("detailId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
         businessFeeDetail.put("primeRate", "1.00");
+
+        if (!businessFeeDetail.containsKey("state")) {
+            businessFeeDetail.put("state", "1400");
+        }
         //璁$畻 搴旀敹閲戦
         FeeDto feeDto = new FeeDto();
         feeDto.setFeeId(paramInJson.getString("feeId"));
@@ -292,8 +314,9 @@
         endCalender.setTime(endTime);
         int hours = 0;
         if ("-101".equals(paramInJson.getString("cycles"))) {
-            hours = new Double(Double.parseDouble(paramInJson.getString("tmpCycles")) * DateUtil.getCurrentMonthDay() * 24).intValue();
-            endCalender.add(Calendar.HOUR, hours);
+//            hours = new Double(Double.parseDouble(paramInJson.getString("tmpCycles")) * DateUtil.getCurrentMonthDay() * 24).intValue();
+//            endCalender.add(Calendar.HOUR, hours);
+            endCalender = getTargetEndTime(endCalender, Double.parseDouble(paramInJson.getString("tmpCycles")));
         } else {
             endCalender.add(Calendar.MONTH, Integer.parseInt(paramInJson.getString("cycles")));
             if (FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())) {
@@ -332,6 +355,21 @@
                 feePrice = additionalAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN);
             } else if ("4004".equals(computingFormula)) {
                 feePrice = new BigDecimal(Double.parseDouble(feeDto.getAmount()));
+            } else if ("5005".equals(computingFormula)) {
+                if (StringUtil.isEmpty(feeDto.getCurDegrees())) {
+                    //throw new IllegalArgumentException("鎶勮〃鏁版嵁寮傚父");
+                } else {
+                    BigDecimal curDegree = new BigDecimal(Double.parseDouble(feeDto.getCurDegrees()));
+                    BigDecimal preDegree = new BigDecimal(Double.parseDouble(feeDto.getPreDegrees()));
+                    BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
+                    BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
+                    BigDecimal sub = curDegree.subtract(preDegree);
+                    feePrice = sub.multiply(squarePrice)
+                            .add(additionalAmount)
+                            .setScale(2, BigDecimal.ROUND_HALF_EVEN);
+                }
+            } else if ("6006".equals(computingFormula)) {
+                feePrice = new BigDecimal(Double.parseDouble(feeDto.getAmount()));
             } else {
                 throw new IllegalArgumentException("鏆備笉鏀寔璇ョ被鍏紡");
             }
@@ -355,6 +393,21 @@
                 //feePrice = Double.parseDouble(feeDto.getAdditionalAmount());
                 BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
                 feePrice = additionalAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN);
+            } else if ("5005".equals(computingFormula)) {
+                if (StringUtil.isEmpty(feeDto.getCurDegrees())) {
+                    throw new IllegalArgumentException("鎶勮〃鏁版嵁寮傚父");
+                } else {
+                    BigDecimal curDegree = new BigDecimal(Double.parseDouble(feeDto.getCurDegrees()));
+                    BigDecimal preDegree = new BigDecimal(Double.parseDouble(feeDto.getPreDegrees()));
+                    BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
+                    BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
+                    BigDecimal sub = curDegree.subtract(preDegree);
+                    feePrice = sub.multiply(squarePrice)
+                            .add(additionalAmount)
+                            .setScale(2, BigDecimal.ROUND_HALF_EVEN);
+                }
+            } else if ("6006".equals(computingFormula)) {
+                feePrice = new BigDecimal(Double.parseDouble(feeDto.getAmount()));
             } else if ("4004".equals(computingFormula)) {
                 feePrice = new BigDecimal(Double.parseDouble(feeDto.getAmount()));
             } else {
@@ -365,10 +418,14 @@
         BigDecimal receivableAmount = feePrice;
         BigDecimal cycles = new BigDecimal(Double.parseDouble(paramInJson.getString("cycles")));
         double tmpReceivableAmount = cycles.multiply(receivableAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
-
+        double discountPrice = paramInJson.getDouble("discountPrice");
         businessFeeDetail.put("receivableAmount", tmpReceivableAmount);
+        businessFeeDetail.put("receivedAmount",
+                new BigDecimal(tmpReceivableAmount).subtract(new BigDecimal(discountPrice)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
         business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put(PayFeeDetailPo.class.getSimpleName(), businessFeeDetail);
         paramInJson.put("receivableAmount", tmpReceivableAmount);
+        paramInJson.put("receivedAmount", businessFeeDetail.getString("receivedAmount"));
+        paramInJson.put("detailId", businessFeeDetail.getString("detailId"));
         return business;
     }
 
@@ -444,6 +501,9 @@
         businessFeeDetail.putAll(paramInJson);
         businessFeeDetail.put("detailId", "-1");
         businessFeeDetail.put("primeRate", "1.00");
+        if (!businessFeeDetail.containsKey("state")) {
+            businessFeeDetail.put("state", "1400");
+        }
         //璁$畻 搴旀敹閲戦
         FeeDto feeDto = new FeeDto();
         feeDto.setFeeId(paramInJson.getString("feeId"));
@@ -550,6 +610,11 @@
      */
     public JSONObject addFee(OwnerCarDto ownerCarDto, JSONObject paramInJson, DataFlowContext dataFlowContext) {
 
+        String time = DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A);
+
+        if (paramInJson.containsKey("startTime")) {
+            time = paramInJson.getString("startTime");
+        }
 
         JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
         business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_SAVE_FEE_INFO);
@@ -561,8 +626,8 @@
         businessUnit.put("feeTypeCd", paramInJson.getString("feeTypeCd"));
         businessUnit.put("incomeObjId", paramInJson.getString("storeId"));
         businessUnit.put("amount", "-1.00");
-        businessUnit.put("startTime", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
-        businessUnit.put("endTime", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
+        businessUnit.put("startTime", time);
+        businessUnit.put("endTime", time);
         businessUnit.put("communityId", paramInJson.getString("communityId"));
         businessUnit.put("payerObjId", ownerCarDto.getCarId());
         businessUnit.put("payerObjType", FeeDto.PAYER_OBJ_TYPE_CAR);
@@ -605,7 +670,13 @@
      */
     public JSONObject addRoomFee(RoomDto roomDto, JSONObject paramInJson, DataFlowContext dataFlowContext) {
 
+        String time = DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A);
 
+        if (paramInJson.containsKey("feeEndDate")) {
+            time = paramInJson.getString("feeEndDate");
+        } else if (paramInJson.containsKey("startTime")) {
+            time = paramInJson.getString("startTime");
+        }
         JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
         business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_SAVE_FEE_INFO);
         business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ + 1);
@@ -616,9 +687,8 @@
         businessUnit.put("feeTypeCd", paramInJson.getString("feeTypeCd"));
         businessUnit.put("incomeObjId", paramInJson.getString("storeId"));
         businessUnit.put("amount", "-1.00");
-        businessUnit.put("startTime", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
-        businessUnit.put("endTime", paramInJson.containsKey("feeEndDate") ? paramInJson.getString("feeEndDate")
-                : DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
+        businessUnit.put("startTime", time);
+        businessUnit.put("endTime", time);
         businessUnit.put("communityId", paramInJson.getString("communityId"));
         businessUnit.put("payerObjId", roomDto.getRoomId());
         businessUnit.put("payerObjType", "3333");

--
Gitblit v1.8.0