From b173d31976fc4731b7c247d4038de92134eba317 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期四, 29 六月 2023 11:42:17 +0800
Subject: [PATCH] Merge branch 'master' of http://git.homecommunity.cn/supervip/MicroCommunity

---
 service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeConfirmCmd.java |  210 ++++++++++++++++++++++++++++++++++------------------
 1 files changed, 136 insertions(+), 74 deletions(-)

diff --git a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeConfirmCmd.java b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeConfirmCmd.java
index 9d3882b..e46e50d 100644
--- a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeConfirmCmd.java
+++ b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeConfirmCmd.java
@@ -3,42 +3,41 @@
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
-import com.java110.core.context.DataFlowContext;
+import com.java110.core.annotation.Java110Transactional;
 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.GenerateCodeFactory;
 import com.java110.dto.account.AccountDto;
 import com.java110.dto.app.AppDto;
-import com.java110.dto.couponUser.CouponUserDto;
+import com.java110.dto.coupon.CouponUserDto;
 import com.java110.dto.fee.FeeAttrDto;
+import com.java110.dto.fee.FeeConfigDto;
 import com.java110.dto.fee.FeeDetailDto;
 import com.java110.dto.fee.FeeDto;
-import com.java110.dto.feeDiscount.ComputeDiscountDto;
+import com.java110.dto.fee.ComputeDiscountDto;
 import com.java110.dto.owner.OwnerCarDto;
-import com.java110.dto.payFeeDetailDiscount.PayFeeDetailDiscountDto;
+import com.java110.dto.parking.ParkingSpaceApplyDto;
 import com.java110.dto.repair.RepairDto;
 import com.java110.dto.repair.RepairUserDto;
-import com.java110.entity.order.Orders;
 import com.java110.fee.bmo.fee.IFeeBMO;
 import com.java110.intf.acct.IAccountInnerServiceSMO;
 import com.java110.intf.acct.ICouponUserDetailV1InnerServiceSMO;
 import com.java110.intf.acct.ICouponUserV1InnerServiceSMO;
-import com.java110.intf.community.IRepairUserInnerServiceSMO;
-import com.java110.intf.community.IRoomInnerServiceSMO;
+import com.java110.intf.community.*;
 import com.java110.intf.fee.*;
 import com.java110.intf.user.IOwnerCarInnerServiceSMO;
-import com.java110.po.accountDetail.AccountDetailPo;
-import com.java110.po.applyRoomDiscount.ApplyRoomDiscountPo;
+import com.java110.po.account.AccountDetailPo;
+import com.java110.po.room.ApplyRoomDiscountPo;
 import com.java110.po.car.OwnerCarPo;
-import com.java110.po.couponUser.CouponUserPo;
-import com.java110.po.couponUserDetail.CouponUserDetailPo;
+import com.java110.po.coupon.CouponUserPo;
+import com.java110.po.coupon.CouponUserDetailPo;
+import com.java110.po.fee.FeeAccountDetailPo;
 import com.java110.po.owner.RepairPoolPo;
 import com.java110.po.owner.RepairUserPo;
-import com.java110.po.payFeeDetailDiscount.PayFeeDetailDiscountPo;
+import com.java110.po.parking.ParkingSpaceApplyPo;
+import com.java110.po.payFee.PayFeeDetailDiscountPo;
 import com.java110.utils.cache.CommonCache;
-import com.java110.utils.constant.BusinessTypeConstant;
-import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
@@ -46,16 +45,15 @@
 import com.java110.utils.util.StringUtil;
 import com.java110.vo.ResultVo;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
 
 import java.math.BigDecimal;
 import java.text.DecimalFormat;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 
 @Java110Cmd(serviceCode = "fee.payFeeConfirm")
-public class PayFeeConfirmCmd extends AbstractServiceCmdListener {
+public class PayFeeConfirmCmd extends Cmd {
 
     @Autowired
     private IFeeBMO feeBMOImpl;
@@ -94,16 +92,20 @@
     @Autowired
     private IPayFeeDetailDiscountNewV1InnerServiceSMO payFeeDetailDiscountNewV1InnerServiceSMOImpl;
     @Autowired
-    private IRepairPoolNewV1InnerServiceSMO repairPoolNewV1InnerServiceSMOImpl;
+    private IRepairPoolV1InnerServiceSMO repairPoolNewV1InnerServiceSMOImpl;
     @Autowired
-    private IRepairUserNewV1InnerServiceSMO repairUserNewV1InnerServiceSMOImpl;
+    private IRepairUserV1InnerServiceSMO repairUserNewV1InnerServiceSMOImpl;
     @Autowired
     private ICouponUserV1InnerServiceSMO couponUserV1InnerServiceSMOImpl;
     @Autowired
     private ICouponUserDetailV1InnerServiceSMO couponUserDetailV1InnerServiceSMOImpl;
-
+    @Autowired
+    private IParkingSpaceApplyV1InnerServiceSMO parkingSpaceApplyV1InnerServiceSMOImpl;
     @Autowired
     private IAccountInnerServiceSMO accountInnerServiceSMOImpl;
+
+    @Autowired
+    private IFeeAccountDetailServiceSMO feeAccountDetailServiceSMOImpl;
 
     //榛樿搴忓垪
     protected static final int DEFAULT_SEQ = 1;
@@ -114,6 +116,7 @@
     }
 
     @Override
+    @Java110Transactional
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
         String paramIn = CommonCache.getAndRemoveValue("payFeePre" + reqJson.getString("oId"));
         JSONObject paramObj = JSONObject.parseObject(paramIn);
@@ -130,9 +133,11 @@
             paramObj.put("primeRate", "6");
             paramObj.put("remark", "绾夸笂灏忕▼搴忔敮浠�");
         }
+        paramObj.put("detailId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
 
         //澶勭悊鐜伴噾璐︽埛
         dealAccount(paramObj);
+
 
         //澶勭悊 浼樻儬鎶樻墸
         addDiscount(paramObj);
@@ -162,10 +167,6 @@
             if (flag < 1) {
                 throw new CmdException("鏇存柊寰俊娲惧崟姹犱俊鎭け璐�");
             }
-        }
-        //淇敼鎶ヤ慨娲惧崟鐘舵��
-        if (feeAttrDtos != null && feeAttrDtos.size() > 0) {
-
             RepairUserDto repairUserDto = new RepairUserDto();
             repairUserDto.setRepairId(feeAttrDtos.get(0).getValue());
             repairUserDto.setState(RepairUserDto.STATE_PAY_FEE);
@@ -180,7 +181,7 @@
             DecimalFormat df = new DecimalFormat("0.00");
             BigDecimal payment_amount = new BigDecimal(paramObj.getString("receivableAmount"));
             repairUserPo.setContext("宸叉敮浠�" + df.format(payment_amount) + "鍏�");
-            int flag = repairUserNewV1InnerServiceSMOImpl.updateRepairUserNew(repairUserPo);
+            flag = repairUserNewV1InnerServiceSMOImpl.updateRepairUserNew(repairUserPo);
             if (flag < 1) {
                 throw new CmdException("鏇存柊寰俊娲惧崟姹犱俊鎭け璐�");
             }
@@ -214,9 +215,12 @@
             //鑾峰彇bId
             String bId = feeDetailDtoList.get(0).getbId();
             //鑾峰彇浼樻儬
-            List<ComputeDiscountDto> computeDiscountDtos = (List<ComputeDiscountDto>) paramObj.get("computeDiscountDtos");
-            if (computeDiscountDtos != null) {
-                for (ComputeDiscountDto computeDiscountDto : computeDiscountDtos) {
+            //List<ComputeDiscountDto> computeDiscountDtos = (List<ComputeDiscountDto>) paramObj.get("computeDiscountDtos");
+            JSONArray computeDiscountDtos = paramObj.getJSONArray("computeDiscountDtos");
+            ComputeDiscountDto computeDiscountDto = null;
+            if (computeDiscountDtos != null && computeDiscountDtos.size() > 0) {
+                for (int accountIndex = 0; accountIndex < computeDiscountDtos.size(); accountIndex++) {
+                    computeDiscountDto = BeanConvertUtil.covertBean(computeDiscountDtos.getJSONObject(accountIndex), ComputeDiscountDto.class);
                     if (!StringUtil.isEmpty(computeDiscountDto.getArdId())) {
                         ApplyRoomDiscountPo applyRoomDiscountPo = new ApplyRoomDiscountPo();
                         //灏嗕笟鍔d鏇存柊鍒扮┖缃埧浼樻儬閲岄潰
@@ -231,59 +235,93 @@
             }
 
         }
+        //鍥炶皟鍒ゆ柇 杞︿綅鐢宠琛ㄦ槸鍚︽湁鏁版嵁锛屾湁鏁版嵁鍒欏埛鏂扮敵璇疯〃鐘舵�佷负 3003 瀹屾垚鐘舵�佸嵆鍙�
+        //鍒ゆ柇杞﹁締鏄惁宸茬粡鏈夌敵璇峰崟
+        ParkingSpaceApplyDto parkingSpaceApplyDto = new ParkingSpaceApplyDto();
+        parkingSpaceApplyDto.setFeeId(paramObj.getString("feeId"));
+        parkingSpaceApplyDto.setState("2002");//瀹℃牳涓�
+        List<ParkingSpaceApplyDto> parkingSpaceApplyDtos = parkingSpaceApplyV1InnerServiceSMOImpl.queryParkingSpaceApplys(parkingSpaceApplyDto);
+        if (parkingSpaceApplyDtos != null && parkingSpaceApplyDtos.size() > 0) {
+            ParkingSpaceApplyPo parkingSpaceApplyPo = new ParkingSpaceApplyPo();
+            parkingSpaceApplyPo.setApplyId(parkingSpaceApplyDtos.get(0).getApplyId());
+            parkingSpaceApplyPo.setState("3003");
+            int flag = parkingSpaceApplyV1InnerServiceSMOImpl.updateParkingSpaceApply(parkingSpaceApplyPo);
+            if (flag < 1) {
+                throw new CmdException("鏇存柊杞︿綅鐢宠琛ㄧ姸鎬佸け璐�");
+            }
+        }
 
         cmdDataFlowContext.setResponseEntity(ResultVo.success());
     }
 
     private void dealAccount(JSONObject paramObj) {
 
-        if(!paramObj.containsKey("deductionAmount") || paramObj.getDouble("deductionAmount") <=0){
-            return ;
+        if (!paramObj.containsKey("deductionAmount") || paramObj.getDouble("deductionAmount") <= 0) {
+            return;
         }
 
         BigDecimal deductionAmount = new BigDecimal(paramObj.getDouble("deductionAmount"));
 
-        List<AccountDto> accountDtos = (List<AccountDto>) paramObj.get("selectUserAccount");
+        JSONArray accountDtos = paramObj.getJSONArray("selectUserAccount");
         BigDecimal amount = null;
-        for(AccountDto accountDto : accountDtos){
-
+        AccountDto accountDto = null;
+        for (int accountIndex = 0; accountIndex < accountDtos.size(); accountIndex++) {
+            accountDto = BeanConvertUtil.covertBean(accountDtos.getJSONObject(accountIndex), AccountDto.class);
             amount = new BigDecimal(Double.parseDouble(accountDto.getAmount()));
             AccountDetailPo accountDetailPo = new AccountDetailPo();
             accountDetailPo.setAcctId(accountDto.getAcctId());
             accountDetailPo.setObjId(accountDto.getObjId());
-            if(amount.doubleValue()< deductionAmount.doubleValue()){
-                accountDetailPo.setAmount(amount.doubleValue()+"");
-                deductionAmount = deductionAmount.subtract(amount).setScale(2,BigDecimal.ROUND_HALF_UP);
-            }else{
-                accountDetailPo.setAmount(deductionAmount.doubleValue()+"");
-                deductionAmount = deductionAmount.subtract(deductionAmount).setScale(2,BigDecimal.ROUND_HALF_UP);
+            accountDetailPo.setObjType(accountDto.getObjType());
+            if (amount.doubleValue() < deductionAmount.doubleValue()) {
+                accountDetailPo.setAmount(amount.doubleValue() + "");
+                deductionAmount = deductionAmount.subtract(amount).setScale(2, BigDecimal.ROUND_HALF_UP);
+            } else {
+                accountDetailPo.setAmount(deductionAmount.doubleValue() + "");
+                deductionAmount = deductionAmount.subtract(deductionAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
             }
             int flag = accountInnerServiceSMOImpl.withholdAccount(accountDetailPo);
 
-            if(flag < 1){
-                throw  new CmdException("鎵f澶辫触");
+            if (flag < 1) {
+                throw new CmdException("鎵f澶辫触");
             }
         }
 
-        if(deductionAmount.doubleValue()>0){
+
+        if (deductionAmount.doubleValue() > 0) {
             throw new CmdException("璐︽埛閲戦涓嶈冻");
         }
+
+        // 鐜伴噾璐︽埛鎵f璁板綍锛岀敓鎴愭姷鎵f槑缁嗚褰�
+        FeeAccountDetailPo feeAccountDetailPo = new FeeAccountDetailPo();
+        feeAccountDetailPo.setFadId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fadId));
+        feeAccountDetailPo.setDetailId(paramObj.getString("detailId"));
+        feeAccountDetailPo.setCommunityId(paramObj.getString("communityId"));
+        feeAccountDetailPo.setState("1002"); //1001 鏃犳姷鎵� 1002 鐜伴噾璐︽埛鎶垫墸 1003 绉垎璐︽埛鎶垫墸 1004 浼樻儬鍒告姷鎵�
+        feeAccountDetailPo.setAmount(paramObj.getDouble("deductionAmount") + ""); //鐜伴噾鎶垫墸閲戦
+        feeAccountDetailServiceSMOImpl.saveFeeAccountDetail(feeAccountDetailPo);
+//        BigDecimal receivedAmountDec = new BigDecimal(payFeeDetailPo.getReceivedAmount());
+//        receivedAmountDec = receivedAmountDec.subtract(cashSum);
+//        payFeeDetailPo.setReceivedAmount(receivedAmountDec.doubleValue() + "");
+
+        paramObj.put("remark", paramObj.getString("remark") + "-鐜伴噾璐︽埛鎶垫墸" + paramObj.getDouble("deductionAmount") + "鍏�");
 
     }
 
     private void modifyCouponUser(JSONObject paramObj) {
-        if(!paramObj.containsKey("couponPrice") || paramObj.getDouble("couponPrice")<=0){
-            return ;
+        if (!paramObj.containsKey("couponPrice") || paramObj.getDouble("couponPrice") <= 0) {
+            return;
         }
-        FeeDto feeInfo = (FeeDto) paramObj.get("feeInfo");
-        List<CouponUserDto> couponUserDtos = (List<CouponUserDto>) paramObj.get("couponUserDtos");
+        //FeeDto feeInfo = (FeeDto) paramObj.get("feeInfo");
         CouponUserDto couponUserDto = null;
-        for (CouponUserDto couponUser : couponUserDtos) {
+        JSONArray couponUserDtos = paramObj.getJSONArray("couponUserDtos");
+        CouponUserDto couponUser = null;
+        for (int accountIndex = 0; accountIndex < couponUserDtos.size(); accountIndex++) {
+            couponUser = BeanConvertUtil.covertBean(couponUserDtos.getJSONObject(accountIndex), CouponUserDto.class);
             couponUserDto = new CouponUserDto();
             couponUserDto.setCouponId(couponUser.getCouponId());
             couponUserDto.setState(CouponUserDto.COUPON_STATE_RUN);
             List<CouponUserDto> couponUserDtos1 = couponUserV1InnerServiceSMOImpl.queryCouponUsers(couponUserDto);
-            if(couponUserDtos1==null || couponUserDtos1.size()<1){
+            if (couponUserDtos1 == null || couponUserDtos1.size() < 1) {
                 throw new CmdException("浼樻儬鍒歌浣跨敤");
             }
             CouponUserPo couponUserPo = new CouponUserPo();
@@ -299,8 +337,8 @@
             couponUserDetailPo.setUserId(couponUser.getUserId());
             couponUserDetailPo.setCouponName(couponUser.getCouponName());
             couponUserDetailPo.setUserName(couponUser.getUserName());
-            couponUserDetailPo.setObjId(feeInfo.getFeeId());
-            couponUserDetailPo.setObjType(feeInfo.getFeeTypeCd());
+            couponUserDetailPo.setObjId(paramObj.getString("feeId"));
+            couponUserDetailPo.setObjType(paramObj.getString("feeTypeCd"));
             couponUserDetailPo.setOrderId(paramObj.getString("oId"));
             fage = couponUserDetailV1InnerServiceSMOImpl.saveCouponUserDetail(couponUserDetailPo);
             if (fage < 1) {
@@ -308,15 +346,19 @@
             }
         }
 
+        paramObj.put("remark", paramObj.getString("remark") + "-浼樻儬鍔垫姷鎵�" + paramObj.getDouble("couponPrice") + "鍏�");
+
     }
 
     private void addDiscount(JSONObject paramObj) {
 
-        if (!paramObj.containsKey("discountPrice") || paramObj.getDouble("discountPrice") <=0) {
-            return ;
+        if (!paramObj.containsKey("discountPrice") || paramObj.getDouble("discountPrice") <= 0) {
+            return;
         }
-        List<ComputeDiscountDto> computeDiscountDtos = (List<ComputeDiscountDto>) paramObj.get("computeDiscountDtos");
-        for (ComputeDiscountDto computeDiscountDto : computeDiscountDtos) {
+        JSONArray computeDiscountDtos = paramObj.getJSONArray("computeDiscountDtos");
+        ComputeDiscountDto computeDiscountDto = null;
+        for (int accountIndex = 0; accountIndex < computeDiscountDtos.size(); accountIndex++) {
+            computeDiscountDto = BeanConvertUtil.covertBean(computeDiscountDtos.getJSONObject(accountIndex), ComputeDiscountDto.class);
             if (computeDiscountDto.getDiscountPrice() <= 0) {
                 continue;
             }
@@ -339,26 +381,46 @@
     }
 
     private void dealOwnerCartEndTime(JSONObject paramObj) {
+
+        FeeDto feeDto = new FeeDto();
+        feeDto.setFeeId(paramObj.getString("feeId"));
+        feeDto.setCommunityId(paramObj.getString("communityId"));
+        List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
+        if (feeDtos == null || feeDtos.size() < 1) {
+            return;
+        }
         //涓哄仠杞﹁垂鍗曠嫭澶勭悊
-        if (paramObj.containsKey("carPayerObjType")
-                && FeeDto.PAYER_OBJ_TYPE_CAR.equals(paramObj.getString("carPayerObjType"))) {
-            Date feeEndTime = (Date) paramObj.get("carFeeEndTime");
-            OwnerCarDto ownerCarDto = new OwnerCarDto();
-            ownerCarDto.setCommunityId(paramObj.getString("communityId"));
-            ownerCarDto.setCarId(paramObj.getString("carPayerObjId"));
-            List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
-            //杞︿綅璐圭敤缁
-            if (ownerCarDtos != null) {
-                for (OwnerCarDto tmpOwnerCarDto : ownerCarDtos) {
-                    if (tmpOwnerCarDto.getEndTime().getTime() < feeEndTime.getTime()) {
-                        OwnerCarPo ownerCarPo = new OwnerCarPo();
-                        ownerCarPo.setMemberId(tmpOwnerCarDto.getMemberId());
-                        ownerCarPo.setEndTime(DateUtil.getFormatTimeString(feeEndTime, DateUtil.DATE_FORMATE_STRING_A));
-                        int fage = ownerCarNewV1InnerServiceSMOImpl.updateOwnerCarNew(ownerCarPo);
-                        if (fage < 1) {
-                            throw new CmdException("鏇存柊璐圭敤淇℃伅澶辫触");
-                        }
-                    }
+        if (!FeeDto.PAYER_OBJ_TYPE_CAR.equals(feeDtos.get(0).getPayerObjType())) {
+            return;
+        }
+        Date feeEndTime = feeDtos.get(0).getEndTime();
+        OwnerCarDto ownerCarDto = new OwnerCarDto();
+        ownerCarDto.setCommunityId(paramObj.getString("communityId"));
+        ownerCarDto.setCarId(feeDtos.get(0).getPayerObjId());
+        List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
+
+
+        Calendar endTimeCalendar = null;
+        //杞︿綅璐圭敤缁
+        if (ownerCarDtos == null || ownerCarDtos.size() < 1) {
+            return;
+        }
+        for (OwnerCarDto tmpOwnerCarDto : ownerCarDtos) {
+            //鍚庝粯璐� 鎴栬�呬俊鐢ㄦ湡杞﹁締 鍔犱竴涓湀
+            if (FeeConfigDto.PAYMENT_CD_AFTER.equals(feeDtos.get(0).getPaymentCd())
+                    || OwnerCarDto.CAR_TYPE_CREDIT.equals(tmpOwnerCarDto.getCarType())) {
+                endTimeCalendar = Calendar.getInstance();
+                endTimeCalendar.setTime(feeEndTime);
+                endTimeCalendar.add(Calendar.MONTH, 1);
+                feeEndTime = endTimeCalendar.getTime();
+            }
+            if (tmpOwnerCarDto.getEndTime().getTime() < feeEndTime.getTime()) {
+                OwnerCarPo ownerCarPo = new OwnerCarPo();
+                ownerCarPo.setMemberId(tmpOwnerCarDto.getMemberId());
+                ownerCarPo.setEndTime(DateUtil.getFormatTimeString(feeEndTime, DateUtil.DATE_FORMATE_STRING_A));
+                int fage = ownerCarNewV1InnerServiceSMOImpl.updateOwnerCarNew(ownerCarPo);
+                if (fage < 1) {
+                    throw new CmdException("鏇存柊璐圭敤淇℃伅澶辫触");
                 }
             }
         }

--
Gitblit v1.8.0