From 08d8b029b10706b135713424e9b2a1b6e3839372 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期日, 23 八月 2020 22:40:01 +0800
Subject: [PATCH] Merge branch 'master' of https://github.com/java110/MicroCommunity

---
 service-fee/src/main/java/com/java110/fee/bmo/impl/QueryOweFeeImpl.java |  309 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 308 insertions(+), 1 deletions(-)

diff --git a/service-fee/src/main/java/com/java110/fee/bmo/impl/QueryOweFeeImpl.java b/service-fee/src/main/java/com/java110/fee/bmo/impl/QueryOweFeeImpl.java
index a2c8e8f..95ea105 100644
--- a/service-fee/src/main/java/com/java110/fee/bmo/impl/QueryOweFeeImpl.java
+++ b/service-fee/src/main/java/com/java110/fee/bmo/impl/QueryOweFeeImpl.java
@@ -1,24 +1,31 @@
 package com.java110.fee.bmo.impl;
 
+import com.alibaba.fastjson.JSONArray;
 import com.java110.dto.RoomDto;
 import com.java110.dto.fee.BillDto;
 import com.java110.dto.fee.BillOweFeeDto;
 import com.java110.dto.fee.FeeConfigDto;
 import com.java110.dto.fee.FeeDto;
+import com.java110.dto.owner.OwnerDto;
 import com.java110.dto.parking.ParkingSpaceDto;
 import com.java110.fee.bmo.IQueryOweFee;
 import com.java110.intf.community.IParkingSpaceInnerServiceSMO;
 import com.java110.intf.community.IRoomInnerServiceSMO;
 import com.java110.intf.fee.IFeeConfigInnerServiceSMO;
 import com.java110.intf.fee.IFeeInnerServiceSMO;
+import com.java110.intf.user.IOwnerInnerServiceSMO;
 import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.StringUtil;
 import com.java110.vo.ResultVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
 
 @Service
@@ -36,6 +43,9 @@
 
     @Autowired
     private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
+
+    @Autowired
+    private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
 
 
     @Override
@@ -62,6 +72,268 @@
 
 
         return ResultVo.createResponseEntity(tmpFeeDtos);
+    }
+
+    @Override
+    public ResponseEntity<String> queryAllOwneFee(FeeDto feeDto) {
+        ResponseEntity<String> responseEntity = null;
+
+        if (!freshFeeDtoParam(feeDto)) {
+            return ResultVo.createResponseEntity(1, 0, new JSONArray());
+        }
+
+        if (FeeConfigDto.BILL_TYPE_EVERY.equals(feeDto.getBillType())) {
+            responseEntity = computeEveryOweFee(feeDto);
+        } else {
+            responseEntity = computeBillOweFee(feeDto);
+        }
+        return responseEntity;
+    }
+
+    private boolean freshFeeDtoParam(FeeDto feeDto) {
+
+        if (StringUtil.isEmpty(feeDto.getPayerObjId())) {
+            return true;
+        }
+
+        if (!feeDto.getPayerObjId().contains("#")) {
+            return false;
+        }
+        if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(feeDto.getPayerObjType())) {
+            String[] nums = feeDto.getPayerObjId().split("#");
+            if (nums.length != 3) {
+                return false;
+            }
+            RoomDto roomDto = new RoomDto();
+            roomDto.setFloorId(nums[0]);
+            roomDto.setUnitNum(nums[1]);
+            roomDto.setRoomNum(nums[2]);
+            roomDto.setCommunityId(feeDto.getCommunityId());
+            List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
+
+            if (roomDtos == null || roomDtos.size() < 1) {
+                return false;
+            }
+            feeDto.setPayerObjId(roomDtos.get(0).getRoomId());
+
+        } else {
+            String[] nums = feeDto.getPayerObjId().split("#");
+            if (nums.length != 2) {
+                return false;
+            }
+            ParkingSpaceDto parkingSpaceDto = new ParkingSpaceDto();
+            parkingSpaceDto.setAreaNum(nums[0]);
+            parkingSpaceDto.setNum(nums[1]);
+            parkingSpaceDto.setCommunityId(feeDto.getCommunityId());
+            List<ParkingSpaceDto> parkingSpaceDtos = parkingSpaceInnerServiceSMOImpl.queryParkingSpaces(parkingSpaceDto);
+
+            if (parkingSpaceDtos == null || parkingSpaceDtos.size() < 1) {
+                return false;
+            }
+            feeDto.setPayerObjId(parkingSpaceDtos.get(0).getPsId());
+        }
+
+        return true;
+    }
+
+    /**
+     * 璐﹀崟璐圭敤
+     *
+     * @param feeDto
+     * @return
+     */
+    private ResponseEntity<String> computeBillOweFee(FeeDto feeDto) {
+        int count = feeInnerServiceSMOImpl.computeBillOweFeeCount(feeDto);
+        List<FeeDto> feeDtos = null;
+        if (count > 0) {
+            feeDtos = feeInnerServiceSMOImpl.computeBillOweFee(feeDto);
+        } else {
+            feeDtos = new ArrayList<>();
+        }
+        return ResultVo.createResponseEntity((int) Math.ceil((double) count / (double) feeDto.getRow()), count, feeDtos);
+    }
+
+    /**
+     * 瀹炴椂璐圭敤
+     *
+     * @param feeDto
+     * @return
+     */
+    private ResponseEntity<String> computeEveryOweFee(FeeDto feeDto) {
+
+        int count = feeInnerServiceSMOImpl.computeEveryOweFeeCount(feeDto);
+        List<FeeDto> feeDtos = null;
+        if (count > 0) {
+            feeDtos = feeInnerServiceSMOImpl.computeEveryOweFee(feeDto);
+            computeFeePrices(feeDtos);
+
+        } else {
+            feeDtos = new ArrayList<>();
+        }
+        return ResultVo.createResponseEntity((int) Math.ceil((double) count / (double) feeDto.getRow()), count, feeDtos);
+    }
+
+    private void computeFeePrices(List<FeeDto> feeDtos) {
+
+        List<FeeDto> roomFees = new ArrayList<>();
+        List<FeeDto> psFees = new ArrayList<>();
+        List<String> roomIds = new ArrayList<>();
+        List<String> psIds = new ArrayList<>();
+
+        for (FeeDto fee : feeDtos) {
+            if ("3333".equals(fee.getPayerObjType())) { //鎴垮眿鐩稿叧
+                roomFees.add(fee);
+                roomIds.add(fee.getPayerObjId());
+            } else if ("6666".equals(fee.getPayerObjType())) {//杞︿綅鐩稿叧
+                psFees.add(fee);
+                psIds.add(fee.getPayerObjId());
+            }
+        }
+
+        if (roomFees.size() > 0) {
+            computeRoomFee(roomFees, roomIds);
+        }
+
+        if (psFees.size() > 0) {
+            computePsFee(psFees, psIds);
+        }
+    }
+
+    /**
+     * 璁$畻鍋滆溅璐�
+     *
+     * @param psFees
+     */
+    private void computePsFee(List<FeeDto> psFees, List<String> psIds) {
+        ParkingSpaceDto parkingSpaceDto = new ParkingSpaceDto();
+        parkingSpaceDto.setCommunityId(psFees.get(0).getCommunityId());
+        parkingSpaceDto.setPsIds(psIds.toArray(new String[psIds.size()]));
+        List<ParkingSpaceDto> parkingSpaceDtos = parkingSpaceInnerServiceSMOImpl.queryParkingSpaces(parkingSpaceDto);
+
+        if (parkingSpaceDtos == null || parkingSpaceDtos.size() < 1) { //鏁版嵁鏈夐棶棰�
+            return;
+        }
+        for (ParkingSpaceDto tmpParkingSpaceDto : parkingSpaceDtos) {
+            for (FeeDto feeDto : psFees) {
+                dealFeePs(tmpParkingSpaceDto, feeDto);
+            }
+        }
+
+        OwnerDto ownerDto = new OwnerDto();
+        ownerDto.setOwnerIds(psIds.toArray(new String[psIds.size()]));
+        ownerDto.setCommunityId(psFees.get(0).getCommunityId());
+        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwnersByParkingSpace(ownerDto);
+
+        for (OwnerDto tmpOwnerDto : ownerDtos) {
+            for (FeeDto feeDto : psFees) {
+                dealFeeOwner(tmpOwnerDto, feeDto);
+            }
+        }
+    }
+
+    private void dealFeePs(ParkingSpaceDto tmpParkingSpaceDto, FeeDto feeDto) {
+        if (!tmpParkingSpaceDto.getPsId().equals(feeDto.getPayerObjId())) {
+            return;
+        }
+        feeDto.setRoomName(tmpParkingSpaceDto.getAreaNum() + "鍋滆溅鍦�" + tmpParkingSpaceDto.getNum() + "杞︿綅");
+
+        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(tmpParkingSpaceDto.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 ("4004".equals(computingFormula)) {
+            feePrice = Double.parseDouble(feeDto.getAmount());
+        } else {
+            feePrice = 0.00;
+        }
+
+        feeDto.setFeePrice(feePrice);
+        double month = dayCompare(feeDto.getEndTime(), DateUtil.getCurrentDate());
+        BigDecimal price = new BigDecimal(feeDto.getFeePrice());
+        price = price.multiply(new BigDecimal(month));
+        feeDto.setAmountOwed(price.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue() + "");
+    }
+
+    /**
+     * 璁$畻鎴垮眿璐�
+     *
+     * @param roomFees
+     */
+    private void computeRoomFee(List<FeeDto> roomFees, List<String> roomIds) {
+        RoomDto roomDto = new RoomDto();
+        roomDto.setCommunityId(roomFees.get(0).getCommunityId());
+        roomDto.setRoomIds(roomIds.toArray(new String[roomIds.size()]));
+        List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
+
+        if (roomDtos == null || roomDtos.size() < 1) { //鏁版嵁鏈夐棶棰�
+            return;
+        }
+
+        for (RoomDto tmpRoomDto : roomDtos) {
+            for (FeeDto feeDto : roomFees) {
+                dealFeeRoom(tmpRoomDto, feeDto);
+            }
+        }
+
+        OwnerDto ownerDto = new OwnerDto();
+        ownerDto.setRoomIds(roomIds.toArray(new String[roomIds.size()]));
+        ownerDto.setCommunityId(roomFees.get(0).getCommunityId());
+        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
+
+        for (OwnerDto tmpOwnerDto : ownerDtos) {
+            for (FeeDto feeDto : roomFees) {
+                dealFeeOwner(tmpOwnerDto, feeDto);
+            }
+        }
+
+    }
+
+    private void dealFeeOwner(OwnerDto tmpOwnerDto, FeeDto feeDto) {
+
+        if (!tmpOwnerDto.getRoomId().equals(feeDto.getPayerObjId())) {
+            return;
+        }
+
+        feeDto.setOwnerName(tmpOwnerDto.getName());
+        feeDto.setOwnerTel(tmpOwnerDto.getLink());
+    }
+
+    private void dealFeeRoom(RoomDto tmpRoomDto, FeeDto feeDto) {
+
+        if (!tmpRoomDto.getRoomId().equals(feeDto.getPayerObjId())) {
+            return;
+        }
+        feeDto.setRoomName(tmpRoomDto.getFloorNum() + "鏍�" + tmpRoomDto.getUnitNum() + "鍗曞厓" + tmpRoomDto.getRoomNum() + "瀹�");
+
+        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(tmpRoomDto.getBuiltUpArea()));
+            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 ("4004".equals(computingFormula)) {
+            feePrice = Double.parseDouble(feeDto.getAmount());
+        } else {
+            feePrice = 0.00;
+        }
+        feeDto.setFeePrice(feePrice);
+
+        double month = dayCompare(feeDto.getEndTime(), DateUtil.getCurrentDate());
+        BigDecimal price = new BigDecimal(feeDto.getFeePrice());
+        price = price.multiply(new BigDecimal(month));
+        feeDto.setAmountOwed(price.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue() + "");
+
     }
 
     /**
@@ -135,8 +407,11 @@
         } else {
             feePrice = 0.00;
         }
-
         feeDto.setFeePrice(feePrice);
+        double month = dayCompare(feeDto.getEndTime(), DateUtil.getCurrentDate());
+        BigDecimal price = new BigDecimal(feeDto.getFeePrice());
+        price = price.multiply(new BigDecimal(month));
+        feeDto.setFeePrice(price.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
 
 
     }
@@ -173,6 +448,38 @@
         }
 
         feeDto.setFeePrice(feePrice);
+        double month = dayCompare(feeDto.getEndTime(), DateUtil.getCurrentDate());
+        BigDecimal price = new BigDecimal(feeDto.getFeePrice());
+        price = price.multiply(new BigDecimal(month));
+        feeDto.setFeePrice(price.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+    }
+
+
+    /**
+     * 璁$畻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();
+        long days = (t2 - t1) / (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