From 54e7f06671f70cee10f82576dbe412a14a957084 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期四, 12 五月 2022 17:25:08 +0800
Subject: [PATCH] 完成巡检 通知员工功能

---
 service-job/src/main/java/com/java110/job/task/fee/GenerateBillTemplate.java |  176 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 144 insertions(+), 32 deletions(-)

diff --git a/service-job/src/main/java/com/java110/job/task/fee/GenerateBillTemplate.java b/service-job/src/main/java/com/java110/job/task/fee/GenerateBillTemplate.java
old mode 100644
new mode 100755
index 3fd877c..3db8ad7
--- a/service-job/src/main/java/com/java110/job/task/fee/GenerateBillTemplate.java
+++ b/service-job/src/main/java/com/java110/job/task/fee/GenerateBillTemplate.java
@@ -1,24 +1,20 @@
 package com.java110.job.task.fee;
 
 import com.java110.core.factory.GenerateCodeFactory;
-import com.java110.core.smo.fee.IFeeConfigInnerServiceSMO;
-import com.java110.core.smo.fee.IFeeDetailInnerServiceSMO;
-import com.java110.core.smo.fee.IFeeInnerServiceSMO;
-import com.java110.core.smo.user.IOwnerCarInnerServiceSMO;
-import com.java110.core.smo.user.IOwnerRoomRelInnerServiceSMO;
-import com.java110.core.smo.community.IParkingSpaceInnerServiceSMO;
-import com.java110.core.smo.community.IRoomInnerServiceSMO;
 import com.java110.dto.RoomDto;
 import com.java110.dto.community.CommunityDto;
-import com.java110.dto.fee.BillDto;
-import com.java110.dto.fee.BillOweFeeDto;
-import com.java110.dto.fee.FeeConfigDto;
-import com.java110.dto.fee.FeeDetailDto;
-import com.java110.dto.fee.FeeDto;
+import com.java110.dto.fee.*;
 import com.java110.dto.owner.OwnerCarDto;
 import com.java110.dto.owner.OwnerRoomRelDto;
 import com.java110.dto.parking.ParkingSpaceDto;
 import com.java110.dto.task.TaskDto;
+import com.java110.intf.community.IParkingSpaceInnerServiceSMO;
+import com.java110.intf.community.IRoomInnerServiceSMO;
+import com.java110.intf.fee.IFeeConfigInnerServiceSMO;
+import com.java110.intf.fee.IFeeDetailInnerServiceSMO;
+import com.java110.intf.fee.IFeeInnerServiceSMO;
+import com.java110.intf.user.IOwnerCarInnerServiceSMO;
+import com.java110.intf.user.IOwnerRoomRelInnerServiceSMO;
 import com.java110.job.quartz.TaskSystemQuartz;
 import com.java110.utils.constant.ResponseConstant;
 import com.java110.utils.exception.TaskTemplateException;
@@ -28,6 +24,7 @@
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
@@ -97,6 +94,10 @@
         FeeConfigDto feeConfigDto = new FeeConfigDto();
         feeConfigDto.setCommunityId(communityDto.getCommunityId());
         feeConfigDto.setBillType(getCurTaskAttr(taskDto, TASK_ATTR_BILL_TYPE).getValue());
+
+        if (StringUtil.isEmpty(feeConfigDto.getBillType())) {
+            throw new IllegalArgumentException("閰嶇疆閿欒 鏈嬁鍒板睘鎬у��");
+        }
         List<FeeConfigDto> feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto);
 
         for (FeeConfigDto tmpFeeConfigDto : feeConfigDtos) {
@@ -118,17 +119,18 @@
      */
     private void GenerateBillByFeeConfig(TaskDto taskDto, FeeConfigDto feeConfigDto) throws Exception {
 
-
         //褰撳墠璐圭敤椤规槸鍚�
         BillDto tmpBillDto = new BillDto();
         tmpBillDto.setCurBill("T");
         tmpBillDto.setConfigId(feeConfigDto.getConfigId());
         tmpBillDto.setCommunityId(feeConfigDto.getCommunityId());
+        Date startTime = getDefaultStartTime(feeConfigDto.getBillType());
+        tmpBillDto.setCurBillTime(DateUtil.getFormatTimeString(startTime, DateUtil.DATE_FORMATE_STRING_A));
         List<BillDto> billDtos = feeInnerServiceSMOImpl.queryBills(tmpBillDto);
 
         //Assert.listOnlyOne(billDtos, "褰撳墠瀛樺湪澶氫釜鏈夋晥璐﹀崟" + feeConfigDto.getConfigId());
-        if (billDtos != null && billDtos.size() > 1) {
-            throw new TaskTemplateException(ResponseConstant.RESULT_CODE_ERROR, "褰撳墠瀛樺湪澶氫釜鏈夋晥璐﹀崟");
+        if (billDtos != null && billDtos.size() > 0) {
+            throw new TaskTemplateException(ResponseConstant.RESULT_CODE_ERROR, "宸茬粡鍑鸿繃璐︿簡");
         }
 
         String billId = GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_billId);
@@ -139,8 +141,15 @@
         billDto.setCommunityId(feeConfigDto.getCommunityId());
         billDto.setConfigId(feeConfigDto.getConfigId());
         billDto.setCurBill("T");
+        //鏌ヨ鍘嗗彶鏈夋晥璐﹀崟
+        tmpBillDto = new BillDto();
+        tmpBillDto.setCurBill("T");
+        tmpBillDto.setConfigId(feeConfigDto.getConfigId());
+        tmpBillDto.setCommunityId(feeConfigDto.getCommunityId());
+        billDtos = feeInnerServiceSMOImpl.queryBills(tmpBillDto);
 
-        Date startTime = billDtos == null ? getDefaultStartTime(feeConfigDto.getBillType()) : DateUtil.getDateFromString(billDtos.get(0).getBillTime(), DateUtil.DATE_FORMATE_STRING_A);
+        startTime = (billDtos == null || billDtos.size() < 1) ? getDefaultStartTime(feeConfigDto.getBillType())
+                : DateUtil.getDateFromString(billDtos.get(0).getBillTime(), DateUtil.DATE_FORMATE_STRING_A);
 
         FeeDto feeDto = new FeeDto();
         feeDto.setConfigId(feeConfigDto.getConfigId());
@@ -151,15 +160,22 @@
         if (feeDto == null || feeDtos.size() < 1) {
             return;
         }
-
+        billDto.setReceivable("0");
+        billDto.setReceipts("0");
+        billDto.setCurReceivable("0");
         for (FeeDto tmpFeeDto : feeDtos) {
-            generateFee(startTime, tmpFeeDto, billDto);
+            try {
+                generateFee(startTime, tmpFeeDto, billDto, feeConfigDto);
+            } catch (Exception e) {
+                logger.error("鐢熸垚璐圭敤澶辫触", e);
+            }
         }
+
 
         //鐢熸垚鏈璐﹀崟
         Date billEndTime = DateUtil.getCurrentDate();
-        billDto.setRemark(DateUtil.getFormatTimeString(startTime,DateUtil.DATE_FORMATE_STRING_A) +
-                "-"+DateUtil.getFormatTimeString(billEndTime,DateUtil.DATE_FORMATE_STRING_A) + "璐﹀崟鏁版嵁");
+        billDto.setRemark(DateUtil.getFormatTimeString(startTime, DateUtil.DATE_FORMATE_STRING_A) +
+                "-" + DateUtil.getFormatTimeString(billEndTime, DateUtil.DATE_FORMATE_STRING_A) + "璐﹀崟鏁版嵁");
         feeInnerServiceSMOImpl.insertBill(billDto);
 
     }
@@ -169,7 +185,7 @@
      *
      * @param feeDto
      */
-    private void generateFee(Date startTime, FeeDto feeDto, BillDto billDto) {
+    private void generateFee(Date startTime, FeeDto feeDto, BillDto billDto, FeeConfigDto feeConfigDto) {
         Date billEndTime = DateUtil.getCurrentDate();
         if ("2009001".equals(feeDto.getState())) { //鍒ゆ柇鏄惁缂磋垂缁撴潫
             FeeDetailDto feeDetailDto = new FeeDetailDto();
@@ -192,7 +208,14 @@
             return;
         }
 
-        computeFeePriceByRoom(feeDto);
+        if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(feeDto.getPayerObjType())) {
+            computeFeePriceByRoom(feeDto);
+        } else if (FeeDto.PAYER_OBJ_TYPE_PARKING_SPACE.equals(feeDto.getPayerObjType())) {
+            computeFeePriceByParkingSpace(feeDto);
+        } else {
+            return;//杩欎釜娌℃湁娆犺垂鍙畻
+            //throw new IllegalArgumentException("鏆備笉鏀寔璇ョ被鍨嬪嚭璐�" + feeDto.getFeeId());
+        }
 
         if (feeDto.getFeePrice() <= 0) {
             return;//杩欎釜娌℃湁娆犺垂鍙畻
@@ -202,14 +225,23 @@
         billOweFeeDto.setOweId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_oweId));
         billOweFeeDto.setFeeId(feeDto.getFeeId());
         billOweFeeDto.setBillId(billDto.getBillId());
-
-        int month = dayCompare(startTime, billEndTime);
+        double month = 0.0;
+        if (TASK_ATTR_VALUE_DAY.equals(feeConfigDto.getBillType())) {
+            month = dayCompare(feeDto.getEndTime(), billEndTime);
+        } else {
+            month = monthCompare(feeDto.getEndTime(), billEndTime);
+        }
         BigDecimal curFeePrice = new BigDecimal(feeDto.getFeePrice());
         curFeePrice = curFeePrice.multiply(new BigDecimal(month));
         billOweFeeDto.setAmountOwed(curFeePrice.doubleValue() + "");
-        month = dayCompare(feeDto.getEndTime(), billEndTime);
+        if (TASK_ATTR_VALUE_DAY.equals(feeConfigDto.getBillType())) {
+            month = dayCompare(feeDto.getEndTime(), billEndTime);
+        } else {
+            month = monthCompare(feeDto.getEndTime(), billEndTime);
+        }
         BigDecimal feePrice = new BigDecimal(feeDto.getFeePrice());
         feePrice = feePrice.multiply(new BigDecimal(month));
+
         billOweFeeDto.setBillAmountOwed(feePrice.doubleValue() + "");
         billOweFeeDto.setFeeEndTime(DateUtil.getFormatTimeString(feeDto.getEndTime(), DateUtil.DATE_FORMATE_STRING_A));
         billOweFeeDto.setCommunityId(feeDto.getCommunityId());
@@ -224,7 +256,7 @@
 
         feeInnerServiceSMOImpl.insertBillOweFees(billOweFeeDto);
 
-        double recFee = StringUtil.isEmpty(billDto.getReceipts()) ? 0.0 : Double.parseDouble(billDto.getReceipts());
+        double recFee = StringUtil.isEmpty(billDto.getReceivable()) ? 0.0 : Double.parseDouble(billDto.getReceivable());
 
         BigDecimal recFeeBig = new BigDecimal(recFee);
         BigDecimal newRecFee = recFeeBig.add(feePrice);
@@ -273,7 +305,7 @@
         List<ParkingSpaceDto> parkingSpaceDtos = parkingSpaceInnerServiceSMOImpl.queryParkingSpaces(parkingSpaceDto);
         if (parkingSpaceDtos == null || parkingSpaceDtos.size() < 1) {
             //杞︿綅鍙兘琚垹闄や簡
-            billOweFeeDto.setOweId("1");
+            billOweFeeDto.setOwnerId("1");
             billOweFeeDto.setOwnerName("鏈煡");
             billOweFeeDto.setOwnerTel("19999999999");
             billOweFeeDto.setPayerObjName("鏈煡");
@@ -293,13 +325,13 @@
 
         if (ownerCarDtos == null || ownerCarDtos.size() < 1) {
             //鎴垮眿鍙兘琚垹闄や簡
-            billOweFeeDto.setOweId("1");
+            billOweFeeDto.setOwnerId("1");
             billOweFeeDto.setOwnerName("鏈煡");
             billOweFeeDto.setOwnerTel("19999999999");
             return;
         }
 
-        billOweFeeDto.setOweId(ownerCarDtos.get(0).getOwnerId());
+        billOweFeeDto.setOwnerId(ownerCarDtos.get(0).getOwnerId());
         billOweFeeDto.setOwnerName(ownerCarDtos.get(0).getOwnerName());
         billOweFeeDto.setOwnerTel(ownerCarDtos.get(0).getLink());
     }
@@ -327,8 +359,13 @@
 
         RoomDto tmpRoomDto = roomDtos.get(0);
 
-        billOweFeeDto.setPayerObjName(tmpRoomDto.getFloorNum() + "鏍�" + tmpRoomDto.getUnitNum() + "鍗曞厓" + tmpRoomDto.getRoomNum() + "瀹�");
+        //billOweFeeDto.setPayerObjName(tmpRoomDto.getFloorNum() + "鏍�" + tmpRoomDto.getUnitNum() + "鍗曞厓" + tmpRoomDto.getRoomNum() + "瀹�");
 
+        if (RoomDto.ROOM_TYPE_ROOM.equals(tmpRoomDto.getRoomType())) {
+            billOweFeeDto.setPayerObjName(tmpRoomDto.getFloorNum() + "鏍�" + tmpRoomDto.getUnitNum() + "鍗曞厓" + tmpRoomDto.getRoomNum() + "瀹�");
+        } else {
+            billOweFeeDto.setPayerObjName(tmpRoomDto.getFloorNum() + "鏍�" + tmpRoomDto.getRoomNum() + "瀹�");
+        }
         OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
         ownerRoomRelDto.setByOwnerInfo(true);
         ownerRoomRelDto.setRoomId(tmpRoomDto.getRoomId());
@@ -342,7 +379,7 @@
             return;
         }
 
-        billOweFeeDto.setOweId(ownerRoomRelDtos.get(0).getOwnerId());
+        billOweFeeDto.setOwnerId(ownerRoomRelDtos.get(0).getOwnerId());
         billOweFeeDto.setOwnerName(ownerRoomRelDtos.get(0).getOwnerName());
         billOweFeeDto.setOwnerTel(ownerRoomRelDtos.get(0).getLink());
 
@@ -400,6 +437,54 @@
         } else if ("2002".equals(computingFormula)) { // 鍥哄畾璐圭敤
             BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
             feePrice = additionalAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        } else if ("3003".equals(computingFormula)) { // 鍥哄畾璐圭敤
+            BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
+            BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(roomDto.getRoomArea()));
+            BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
+            feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(3, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        } else if ("1101".equals(computingFormula)) { // 绉熼噾
+            BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(roomDto.getRoomRent()));
+            feePrice = additionalAmount.setScale(3, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        } else {
+            feePrice = -1.00;
+        }
+
+        feeDto.setFeePrice(feePrice);
+
+        //鏌ヨ涓氫富淇℃伅
+
+
+    }
+
+    /**
+     * 鏍规嵁杞︿綅鏉ョ畻鍗曚环
+     *
+     * @param feeDto
+     */
+    private void computeFeePriceByParkingSpace(FeeDto feeDto) {
+        ParkingSpaceDto parkingSpaceDto = new ParkingSpaceDto();
+        parkingSpaceDto.setCommunityId(feeDto.getCommunityId());
+        parkingSpaceDto.setPsId(feeDto.getPayerObjId());
+        List<ParkingSpaceDto> parkingSpaceDtos = parkingSpaceInnerServiceSMOImpl.queryParkingSpaces(parkingSpaceDto);
+
+        if (parkingSpaceDtos == null || parkingSpaceDtos.size() < 1) { //鏁版嵁鏈夐棶棰�
+            return;
+        }
+
+        String computingFormula = feeDto.getComputingFormula();
+        double feePrice = 0.00;
+        if ("1001".equals(computingFormula)) { //闈㈢Н*鍗曚环+闄勫姞璐�
+            BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
+            BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(parkingSpaceDtos.get(0).getArea()));
+            BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
+            feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        } else if ("2002".equals(computingFormula)) { // 鍥哄畾璐圭敤
+            BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
+            feePrice = additionalAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        } else if ("3003".equals(computingFormula)) { // 鍥哄畾璐圭敤
+            feePrice = 0;
+        } else if ("1101".equals(computingFormula)) { // 绉熼噾
+            feePrice = 0;
         } else {
             feePrice = -1.00;
         }
@@ -418,7 +503,7 @@
      * @param toDate
      * @return
      */
-    public static int dayCompare(Date fromDate, Date toDate) {
+    public static int monthCompare(Date fromDate, Date toDate) {
         Calendar from = Calendar.getInstance();
         from.setTime(fromDate);
         Calendar to = Calendar.getInstance();
@@ -431,4 +516,31 @@
         int month = toYear * 12 + toMonth - (fromYear * 12 + fromMonth);
         return month;
     }
+
+    /**
+     * 璁$畻2涓棩鏈熶箣闂寸浉宸殑  浠ュ勾銆佹湀銆佹棩涓哄崟浣嶏紝鍚勮嚜璁$畻缁撴灉鏄灏�
+     * 姣斿锛�2011-02-02 鍒�  2017-03-02
+     * 浠ュ勾涓哄崟浣嶇浉宸负锛�6骞�
+     * 浠ユ湀涓哄崟浣嶇浉宸负锛�73涓湀
+     * 浠ユ棩涓哄崟浣嶇浉宸负锛�2220澶�
+     *
+     * @param fromDate
+     * @param toDate
+     * @return
+     */
+    public static double dayCompare(Date fromDate, Date toDate) {
+        Calendar from = Calendar.getInstance();
+        from.setTime(fromDate);
+        Calendar to = Calendar.getInstance();
+        to.setTime(toDate);
+
+        long t1 = from.getTimeInMillis();
+        long t2 = to.getTimeInMillis();
+        double days = (t2 - t1) * 1.00 / (24 * 60 * 60 * 1000);
+
+        BigDecimal tmpDays = new BigDecimal(days);
+        BigDecimal monthDay = new BigDecimal(30);
+
+        return tmpDays.divide(monthDay, 2, RoundingMode.HALF_UP).doubleValue();
+    }
 }

--
Gitblit v1.8.0