From 8befc3dddb49edd0d6c09ab6e4c182a6df8b0b87 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期五, 30 九月 2022 18:58:06 +0800
Subject: [PATCH] 优化代码

---
 service-fee/src/main/java/com/java110/fee/cmd/fee/ListFeeCmd.java |  146 +++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 137 insertions(+), 9 deletions(-)

diff --git a/service-fee/src/main/java/com/java110/fee/cmd/fee/ListFeeCmd.java b/service-fee/src/main/java/com/java110/fee/cmd/fee/ListFeeCmd.java
index 745d509..f18d147 100644
--- a/service-fee/src/main/java/com/java110/fee/cmd/fee/ListFeeCmd.java
+++ b/service-fee/src/main/java/com/java110/fee/cmd/fee/ListFeeCmd.java
@@ -3,17 +3,28 @@
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.context.ICmdDataFlowContext;
-import com.java110.core.event.cmd.AbstractServiceCmdListener;
+import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.CmdEvent;
+import com.java110.core.factory.CommunitySettingFactory;
 import com.java110.core.log.LoggerFactory;
 import com.java110.core.smo.IComputeFeeSMO;
+import com.java110.dto.FloorDto;
+import com.java110.dto.RoomDto;
+import com.java110.dto.UnitDto;
 import com.java110.dto.fee.FeeDto;
 import com.java110.dto.owner.OwnerCarDto;
+import com.java110.dto.owner.OwnerRoomRelDto;
 import com.java110.dto.parking.ParkingSpaceDto;
+import com.java110.intf.community.IFloorInnerServiceSMO;
 import com.java110.intf.community.IParkingSpaceInnerServiceSMO;
+import com.java110.intf.community.IRoomInnerServiceSMO;
+import com.java110.intf.community.IUnitInnerServiceSMO;
+import com.java110.intf.fee.IFeeAttrInnerServiceSMO;
 import com.java110.intf.fee.IFeeConfigInnerServiceSMO;
 import com.java110.intf.fee.IFeeInnerServiceSMO;
 import com.java110.intf.user.IOwnerCarInnerServiceSMO;
+import com.java110.intf.user.IOwnerRoomRelV1InnerServiceSMO;
+import com.java110.utils.cache.MappingCache;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
@@ -34,7 +45,8 @@
 import java.util.Map;
 
 @Java110Cmd(serviceCode = "fee.listFee")
-public class ListFeeCmd extends AbstractServiceCmdListener {
+public class ListFeeCmd extends Cmd {
+
     private static Logger logger = LoggerFactory.getLogger(ListFeeCmd.class);
 
     @Autowired
@@ -50,7 +62,34 @@
     private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
 
     @Autowired
+    private IFeeAttrInnerServiceSMO feeAttrInnerServiceSMOImpl;
+
+    @Autowired
     private IComputeFeeSMO computeFeeSMOImpl;
+
+    @Autowired
+    private IFloorInnerServiceSMO floorInnerServiceSMOImpl;
+
+    @Autowired
+    private IUnitInnerServiceSMO unitInnerServiceSMOImpl;
+
+    @Autowired
+    private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
+
+    @Autowired
+    private IOwnerRoomRelV1InnerServiceSMO ownerRoomRelV1InnerServiceSMOImpl;
+
+    //鍩�
+    public static final String DOMAIN_COMMON = "DOMAIN.COMMON";
+
+    //閿�
+    public static final String TOTAL_FEE_PRICE = "TOTAL_FEE_PRICE";
+
+    //閿�
+    public static final String RECEIVED_AMOUNT_SWITCH = "RECEIVED_AMOUNT_SWITCH";
+
+    //绂佺敤鐢佃剳绔彁浜ゆ敹璐规寜閽�
+    public static final String OFFLINE_PAY_FEE_SWITCH = "OFFLINE_PAY_FEE_SWITCH";
 
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
@@ -60,13 +99,56 @@
 
     @Override
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
+        if (reqJson.containsKey("roomNum") && !StringUtil.isEmpty(reqJson.getString("roomNum"))) {
+            String[] roomNums = reqJson.getString("roomNum").split("-", 3);
+            if (roomNums == null || roomNums.length != 3) {
+                throw new IllegalArgumentException("鎴垮眿缂栧彿鏍煎紡閿欒锛�");
+            }
+            String floorNum = roomNums[0];
+            String unitNum = roomNums[1];
+            String roomNum = roomNums[2];
+            FloorDto floorDto = new FloorDto();
+            floorDto.setFloorNum(floorNum);
+            floorDto.setCommunityId(reqJson.getString("communityId"));
+            List<FloorDto> floorDtos = floorInnerServiceSMOImpl.queryFloors(floorDto);
+            if (floorDtos != null && floorDtos.size() > 0) {
+                for (FloorDto floor : floorDtos) {
+                    UnitDto unitDto = new UnitDto();
+                    unitDto.setFloorId(floor.getFloorId());
+                    unitDto.setUnitNum(unitNum);
+                    List<UnitDto> unitDtos = unitInnerServiceSMOImpl.queryUnits(unitDto);
+                    if (unitDtos != null && unitDtos.size() > 0) {
+                        for (UnitDto unit : unitDtos) {
+                            RoomDto roomDto = new RoomDto();
+                            roomDto.setUnitId(unit.getUnitId());
+                            roomDto.setRoomNum(roomNum);
+                            roomDto.setCommunityId(reqJson.getString("communityId"));
+                            List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
+                            Assert.listOnlyOne(roomDtos, "鏌ヨ鎴垮眿閿欒锛�");
+                            reqJson.put("payerObjId", roomDtos.get(0).getRoomId());
+                        }
+                    }
+                }
+            }
+        }
 
         FeeDto feeDto = BeanConvertUtil.covertBean(reqJson, FeeDto.class);
-
-        int count = feeInnerServiceSMOImpl.queryFeesCount(feeDto);
-
         List<ApiFeeDataVo> fees = new ArrayList<>();
-
+        if (reqJson.containsKey("ownerId") && !StringUtil.isEmpty(reqJson.getString("ownerId"))) {
+            OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
+            ownerRoomRelDto.setRoomId(reqJson.getString("payerObjId"));
+            ownerRoomRelDto.setOwnerId(reqJson.getString("ownerId"));
+            List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelV1InnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
+            if (ownerRoomRelDtos == null || ownerRoomRelDtos.size() < 1) {
+                ApiFeeVo apiFeeVo = new ApiFeeVo();
+                apiFeeVo.setTotal(0);
+                apiFeeVo.setRecords((int) Math.ceil((double) 0 / (double) reqJson.getInteger("row")));
+                apiFeeVo.setFees(fees);
+                ResponseEntity<String> responseEntity = new ResponseEntity<String>(JSONObject.toJSONString(apiFeeVo), HttpStatus.OK);
+                cmdDataFlowContext.setResponseEntity(responseEntity);
+            }
+        }
+        int count = feeInnerServiceSMOImpl.queryFeesCount(feeDto);
         if (count > 0) {
             List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);//鏌ヨ璐圭敤椤圭洰
             computeFeePrice(feeDtos);//璁$畻璐圭敤
@@ -102,12 +184,35 @@
     }
 
     private void computeFeePrice(List<FeeDto> feeDtos) {
+
+        if (feeDtos == null || feeDtos.size() < 1) {
+            return;
+        }
+        String val = CommunitySettingFactory.getValue(feeDtos.get(0).getCommunityId(), TOTAL_FEE_PRICE);
+        if (StringUtil.isEmpty(val)) {
+            val = MappingCache.getValue(DOMAIN_COMMON, TOTAL_FEE_PRICE);
+        }
+
+        //鍏堝彇鍗曞皬鍖虹殑濡傛灉娌℃湁閰嶇疆 鍙� 鍏ㄥ眬鐨�
+        String received_amount_switch = CommunitySettingFactory.getValue(feeDtos.get(0).getCommunityId(), RECEIVED_AMOUNT_SWITCH);
+        if (StringUtil.isEmpty(received_amount_switch)) {
+            received_amount_switch = MappingCache.getValue(DOMAIN_COMMON, RECEIVED_AMOUNT_SWITCH);
+        }
+
+        //鍏堝彇鍗曞皬鍖虹殑濡傛灉娌℃湁閰嶇疆 鍙� 鍏ㄥ眬鐨�
+        String offlinePayFeeSwitch = CommunitySettingFactory.getValue(feeDtos.get(0).getCommunityId(), OFFLINE_PAY_FEE_SWITCH);
+        if (StringUtil.isEmpty(offlinePayFeeSwitch)) {
+            offlinePayFeeSwitch = MappingCache.getValue(DOMAIN_COMMON, OFFLINE_PAY_FEE_SWITCH);
+        }
+
         for (FeeDto feeDto : feeDtos) {
             try {
                 // 杞暟 * 鍛ㄦ湡 * 30 + 寮�濮嬫椂闂� = 鐩爣 鍒版湡鏃堕棿
                 Map<String, Object> targetEndDateAndOweMonth = computeFeeSMOImpl.getTargetEndDateAndOweMonth(feeDto);
                 Date targetEndDate = (Date) targetEndDateAndOweMonth.get("targetEndDate");
                 double oweMonth = (double) targetEndDateAndOweMonth.get("oweMonth");
+                feeDto.setCycle(feeDto.getPaymentCycle());
+                feeDto.setDeadlineTime(targetEndDate);
                 if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(feeDto.getPayerObjType())) { //鎴垮眿鐩稿叧
                     computeFeePriceByRoom(feeDto, oweMonth);
                 } else if (FeeDto.PAYER_OBJ_TYPE_CAR.equals(feeDto.getPayerObjType())) {//杞︿綅鐩稿叧
@@ -115,7 +220,16 @@
                 } else if (FeeDto.PAYER_OBJ_TYPE_CONTRACT.equals(feeDto.getPayerObjType())) {//杞︿綅鐩稿叧
                     computeFeePriceByContract(feeDto, oweMonth);
                 }
-                feeDto.setDeadlineTime(targetEndDate);
+
+                feeDto.setVal(val);
+                //鍏抽棴 绾夸笅鏀堕摱鍔熻兘
+                if (StringUtil.isEmpty(received_amount_switch)) {
+                    feeDto.setReceivedAmountSwitch("1");//榛樿鍚敤瀹炴敹娆捐緭鍏ユ
+                } else {
+                    feeDto.setReceivedAmountSwitch(received_amount_switch);
+                }
+                feeDto.setOfflinePayFeeSwitch(offlinePayFeeSwitch);
+
             } catch (Exception e) {
                 logger.error("鏌ヨ璐圭敤淇℃伅 锛岃垂鐢ㄤ俊鎭敊璇�", e);
             }
@@ -142,6 +256,8 @@
         DecimalFormat df = new DecimalFormat("0.00");
         Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto);
         feeDto.setFeePrice(Double.parseDouble(feePriceAll.get("feePrice").toString()));
+        feeDto.setFeeTotalPrice(Double.parseDouble(feePriceAll.get("feeTotalPrice").toString()));
+
         BigDecimal curFeePrice = new BigDecimal(feeDto.getFeePrice());
         curFeePrice = curFeePrice.multiply(new BigDecimal(oweMonth));
         feeDto.setAmountOwed(df.format(curFeePrice));
@@ -152,6 +268,9 @@
             feeDto.setAmountOwed(df.format(curFeePrice));
             feeDto.setDeadlineTime(DateUtil.getCurrentDate());
         }
+
+        //鑰冭檻绉熼噾閫掑
+        computeFeeSMOImpl.dealRentRate(feeDto);
     }
 
     /**
@@ -164,17 +283,23 @@
         DecimalFormat df = new DecimalFormat("0.00");
         Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto);
         feeDto.setFeePrice(Double.parseDouble(feePriceAll.get("feePrice").toString()));
+        feeDto.setFeeTotalPrice(Double.parseDouble(feePriceAll.get("feeTotalPrice").toString()));
         BigDecimal curFeePrice = new BigDecimal(feeDto.getFeePrice());
         curFeePrice = curFeePrice.multiply(new BigDecimal(oweMonth));
         feeDto.setAmountOwed((df.format(curFeePrice)));
         //鍔ㄦ�佽垂鐢�
         if ("4004".equals(computingFormula)
                 && FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())
-                && !FeeDto.STATE_FINISH.equals(feeDto.getState())) {
-            feeDto.setAmountOwed(df.format(curFeePrice) + "");
+                && !FeeDto.STATE_FINISH.equals(feeDto.getState())
+                && feeDto.getDeadlineTime() == null) {
             feeDto.setDeadlineTime(DateUtil.getCurrentDate());
         }
+
+        //鑰冭檻绉熼噾閫掑
+        computeFeeSMOImpl.dealRentRate(feeDto);
+
     }
+
 
     /**
      * 鏍规嵁鍚堝悓鏉ョ畻鍗曚环
@@ -186,6 +311,7 @@
         DecimalFormat df = new DecimalFormat("0.00");
         Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto);
         feeDto.setFeePrice(Double.parseDouble(feePriceAll.get("feePrice").toString()));
+        feeDto.setFeeTotalPrice(Double.parseDouble(feePriceAll.get("feeTotalPrice").toString()));
         BigDecimal curFeePrice = new BigDecimal(feeDto.getFeePrice());
         curFeePrice = curFeePrice.multiply(new BigDecimal(oweMonth));
         feeDto.setAmountOwed(df.format(curFeePrice));
@@ -196,5 +322,7 @@
             feeDto.setAmountOwed(df.format(curFeePrice) + "");
             feeDto.setDeadlineTime(DateUtil.getCurrentDate());
         }
+        //鑰冭檻绉熼噾閫掑
+        computeFeeSMOImpl.dealRentRate(feeDto);
     }
 }

--
Gitblit v1.8.0