From ee8a712a522a84540db7a6e4d687ea3600bef805 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 01 十二月 2020 10:10:30 +0800
Subject: [PATCH] 优化代码

---
 service-api/src/main/java/com/java110/api/bmo/fee/impl/FeeBMOImpl.java |   77 +++++++++++++++++++++++++++++---------
 1 files changed, 58 insertions(+), 19 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 4b6962f..d604a1e 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
@@ -8,7 +8,6 @@
 import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.core.smo.IComputeFeeSMO;
 import com.java110.dto.RoomDto;
-import com.java110.dto.fee.FeeAttrDto;
 import com.java110.dto.fee.FeeConfigDto;
 import com.java110.dto.fee.FeeDto;
 import com.java110.dto.machine.CarInoutDto;
@@ -126,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();
@@ -137,7 +136,9 @@
         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;
@@ -150,8 +151,7 @@
             endCalender.setTime(endTime);
             BigDecimal receivedAmount = new BigDecimal(Double.parseDouble(paramInJson.getString("receivedAmount")));
             cycles = receivedAmount.divide(feePrice, 2, BigDecimal.ROUND_HALF_EVEN);
-            hours = new Double(cycles.doubleValue() * DateUtil.getCurrentMonthDay() * 24).intValue();
-            endCalender.add(Calendar.HOUR, hours);
+            endCalender = getTargetEndTime(endCalender, cycles.doubleValue());
             targetEndTime = endCalender.getTime();
             paramInJson.put("tmpCycles", cycles.doubleValue());
             businessFeeDetail.put("cycles", cycles.doubleValue());
@@ -167,11 +167,11 @@
         paramInJson.put("feeInfo", feeDto);
 
         business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put(PayFeeDetailPo.class.getSimpleName(), businessFeeDetail);
-
-        feeReceiptDetailPo.setAmount(businessFeeDetail.getString("receivableAmount"));
+        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());
@@ -185,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;
     }
 
 
@@ -229,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")));
         }
@@ -271,6 +292,10 @@
         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"));
@@ -289,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())) {
@@ -329,7 +355,7 @@
                 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)) {
+            } else if ("5005".equals(computingFormula)) {
                 if (StringUtil.isEmpty(feeDto.getCurDegrees())) {
                     //throw new IllegalArgumentException("鎶勮〃鏁版嵁寮傚父");
                 } else {
@@ -344,7 +370,7 @@
                 }
             } else if ("6006".equals(computingFormula)) {
                 feePrice = new BigDecimal(Double.parseDouble(feeDto.getAmount()));
-            }else {
+            } else {
                 throw new IllegalArgumentException("鏆備笉鏀寔璇ョ被鍏紡");
             }
         } else if ("6666".equals(feeDto.getPayerObjType())) {//杞︿綅鐩稿叧
@@ -471,6 +497,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"));
@@ -577,6 +606,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);
@@ -588,8 +622,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);
@@ -632,7 +666,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);
@@ -643,9 +683,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