From 946af5cbe523f5de12c21f62e96d59226684507c Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期日, 04 二月 2024 18:30:55 +0800
Subject: [PATCH] 111

---
 server/service/src/main/java/com/doumee/service/business/impl/ApplyChangeServiceImpl.java |   92 +++++++++++++++++++++------------------------
 1 files changed, 43 insertions(+), 49 deletions(-)

diff --git a/server/service/src/main/java/com/doumee/service/business/impl/ApplyChangeServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/ApplyChangeServiceImpl.java
index e2cfd75..8795586 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/ApplyChangeServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/ApplyChangeServiceImpl.java
@@ -194,6 +194,9 @@
             dealDetailsDUdata(update);
         }
 
+//        if(1==1){
+//            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+//        }
 
         Constants.ApplyLogType applyLogType = Constants.ApplyLogType.CA_PLATFORM_APPROVE;
         String info = "";
@@ -361,7 +364,6 @@
                         .leftJoin(ApplyChange.class, ApplyChange::getId, ApplyChagneDetail::getApplyChangeId)
                         .leftJoin(InsuranceApply.class, InsuranceApply::getId, ApplyChange::getApplyId)
                         .leftJoin(Solutions.class, Solutions::getId, InsuranceApply::getSolutionId)
-                        .leftJoin(Solutions.class, Solutions::getId, ApplyChange::getSolutionsId)
                         .leftJoin(Worktype.class, Worktype::getId, ApplyChagneDetail::getWorktypeId)
                         .leftJoin(DispatchUnit.class, DispatchUnit::getId, ApplyChagneDetail::getDuId)
                         .eq(ApplyChagneDetail::getApplyChangeId, update.getId())
@@ -380,17 +382,10 @@
         //鍔犱繚涓氬姟 浣跨敤鐨勫姞淇濋噾棰�
         ApplyChangeCyclePriceDTO applyChangeCyclePriceDTO_add = new ApplyChangeCyclePriceDTO();
         applyChangeCyclePriceDTO_add.setApplyId(update.getApplyId());
-        applyChangeCyclePriceDTO_add.setValidTime(DateUtil.getMontageDate(update.getStartTime(), 1));
+        applyChangeCyclePriceDTO_add.setValidTime(DateUtil.getMontageDate(update.getApplyStartTime(), 1));
         //鍔犱繚 娣诲姞鐨勯噾棰�
         CountCyclePriceVO countCyclePriceVO_add = this.getChangeCountCyclePriceVO(applyChangeCyclePriceDTO_add);
 
-
-        //鍑忎繚涓氬姟 浣跨敤鐨勫噺淇濋噾棰�
-        ApplyChangeCyclePriceDTO applyChangeCyclePriceDTO_reduce = new ApplyChangeCyclePriceDTO();
-        applyChangeCyclePriceDTO_reduce.setApplyId(update.getApplyId());
-        applyChangeCyclePriceDTO_reduce.setValidTime(DateUtil.getMontageDate(update.getStartTime(), 3));
-        //鍑忎繚 闇�瑕佸噺灏戠殑閲戦
-        CountCyclePriceVO countCyclePriceVO_reduce = this.getChangeCountCyclePriceVO(applyChangeCyclePriceDTO_reduce);
 
 
         for (ApplyChagneDetail detail : detailList) {
@@ -409,26 +404,24 @@
                 add.setDuId(detail.getDuId());
                 add.setStartTime(update.getApplyStartTime());
                 add.setEndTime(detail.getEndTime());
-                add.setFee(new BigDecimal(0));
-//                add.setFee(Constants.countDetailFee(detail.getSolutionTimeUnit(),detail.getSolutionPrice(), add.getStartTime(),add.getEndTime()));
-                if (DateUtil.daysBetweenDates(add.getStartTime(), new Date()) >= 0) {
-                    add.setStartTime(DateUtil.getMontageDate(update.getApplyStartTime(), 1));
-                    add.setEndTime(DateUtil.getMontageDate(detail.getEndTime(), 2));
+                add.setStartTime(DateUtil.getMontageDate(update.getApplyStartTime(), 1));
+                add.setEndTime(DateUtil.getMontageDate(detail.getEndTime(), 2));
+                add.setFee(countCyclePriceVO_add.getCyclePrice());
 
-                    add.setFee(countCyclePriceVO_add.getCyclePrice());
-                    if (DateUtil.daysBetweenDates(DateUtil.getMontageDate(add.getStartTime(), 2), new Date()) >= 0) {
-                        Integer days = DateUtil.daysBetweenDates(new Date(), DateUtil.getMontageDate(add.getStartTime(), 2)) + 1;
-                        //濡傛灉宸蹭骇鐢熻垂鐢紝璁$畻宸蹭骇鐢熻垂鐢�
-                        add.setCurrentFee(this.getApplyPrice(update.getApplyId(), days));
-                    }
-//                addList.add(add);
-                    applyDetailJoinMapper.insert(add);
-                    totalFee.add(add.getFee());
-                    currentFee.add(add.getCurrentFee());
+                if (DateUtil.daysBetweenDates(DateUtil.getMontageDate(detail.getStartTime(), 2), new Date()) >= 0) {
+                    Integer days = DateUtil.daysBetweenDates(DateUtil.getMontageDate(new Date(), 2), detail.getStartTime()) + 1;
+                    //濡傛灉宸蹭骇鐢熻垂鐢紝璁$畻宸蹭骇鐢熻垂鐢�
+                    add.setCurrentFee(this.getApplyPrice(update.getApplyId(), days));
+                }else{
+                    add.setCurrentFee(BigDecimal.ZERO);
+                }
+                applyDetailJoinMapper.insert(add);
+                totalFee = totalFee.add(add.getFee());
+                currentFee = currentFee.add(add.getCurrentFee());
 
-                    MemberInsurance memberInsurance = new MemberInsurance(detail, update, update.getEditor(), add.getId());
-                    memberInsuranceList.add(memberInsurance);
-                } else {
+                MemberInsurance memberInsurance = new MemberInsurance(detail, update, update.getEditor(), add.getId());
+                memberInsuranceList.add(memberInsurance);
+            } else {
                     //鍑忎繚鎿嶄綔
                     //鏌ヨ鍛樺伐鏄湪涓诲崟涓� 鏄惁瀛樺湪鐢熸晥涓殑鏁版嵁
                     ApplyDetail oldModel = applyDetailJoinMapper.selectOne(new QueryWrapper<ApplyDetail>().lambda()
@@ -439,21 +432,20 @@
                     if (oldModel == null || oldModel.getStartTime() == null || oldModel.getStartTime().getTime() > update.getApplyStartTime().getTime()) {
                         throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵逛笉璧凤紝鐢ㄦ埛銆�" + detail.getMemberName() + "銆戝師淇濆崟淇℃伅鏈夎锛屽綋鍓嶇敵璇蜂笉鏀寔鍑忎繚澶勭悊锛�");
                     }
-                    //閫�淇濋渶瑕侀��鍥炵殑璐圭敤
+                    //鍑忎繚涓氬姟 浣跨敤鐨勫噺淇濋噾棰�
+                    ApplyChangeCyclePriceDTO applyChangeCyclePriceDTO_reduce = new ApplyChangeCyclePriceDTO();
+                    applyChangeCyclePriceDTO_reduce.setApplyId(update.getApplyId());
+                    applyChangeCyclePriceDTO_reduce.setValidTime(DateUtil.getMontageDate(update.getApplyStartTime(), 2));
+                    //鍑忎繚 闇�瑕佸噺灏戠殑閲戦 鍗� 閫�淇濋渶瑕侀��鍥炵殑璐圭敤
+                    CountCyclePriceVO countCyclePriceVO_reduce = this.getChangeCountCyclePriceVO(applyChangeCyclePriceDTO_reduce);
                     BigDecimal updateFee = countCyclePriceVO_reduce.getCyclePrice().multiply(new BigDecimal(-1));
-                    BigDecimal updateCurrentFee = oldModel.getFee().subtract(updateFee);
-
-//                BigDecimal updateCurrentFee = new BigDecimal(0);
-//                if(DateUtil.daysBetweenDates(update.getApplyStartTime(),new Date() )>0){
-//                    //濡傛灉鐢熸晥鏃堕棿 鏄粖澶╀箣鍓嶏紝閫�鍥炲凡浜х敓璐圭敤锛岃绠楀凡浜х敓璐圭敤(鎬昏垂鐢�-宸蹭骇鐢熻垂鐢�)
-//                    updateCurrentFee = updateFee.subtract(oldModel.getCurrentFee());
-//                }
-
-//                    BigDecimal updateFee = (Constants.countDetailFee(detail.getSolutionTimeUnit(), detail.getSolutionPrice(), oldModel.getStartTime(), update.getApplyStartTime()));
-//                    BigDecimal updateCurrentFee = new BigDecimal(0);
-                    if (DateUtil.daysBetweenDates(update.getApplyStartTime(), new Date()) > 0) {
-                        //濡傛灉鐢熸晥鏃堕棿 鏄粖澶╀箣鍓嶏紝閫�鍥炲凡浜х敓璐圭敤锛岃绠楀凡浜х敓璐圭敤(鎬昏垂鐢�-宸蹭骇鐢熻垂鐢�)
-                        updateCurrentFee = updateFee.subtract(Constants.formatBigdecimal(oldModel.getCurrentFee()));
+                    //褰撳鎵规椂闂� 澶т簬 鐢宠鐨勬椂闂存椂 璁$畻瀹為檯鍑忓皯閲戦 鍥犱负宸叉墸閲戦浼氬ぇ浜� 搴旀墸閲戦
+                    BigDecimal updateCurrentFee = BigDecimal.ZERO;
+                    if (DateUtil.daysBetweenDates(DateUtil.getMontageDate(new Date(), 2),update.getApplyStartTime()) > 0) {
+                        applyChangeCyclePriceDTO_reduce.setValidTime(DateUtil.getMontageDate(new Date(), 2));
+                        //鑾峰彇 澶т簬瀹℃壒鏃ユ湡瀵艰嚧 澶氬噺鐨勯噾棰�
+                        CountCyclePriceVO timeoutCountCyclePriceVOReduce = this.getChangeCountCyclePriceVO(applyChangeCyclePriceDTO_reduce);
+                        updateCurrentFee = timeoutCountCyclePriceVOReduce.getCyclePrice().subtract(countCyclePriceVO_reduce.getCyclePrice());
                     }
                     applyDetailJoinMapper.update(null, new UpdateWrapper<ApplyDetail>().lambda()
                             .setSql(" fee = ifnull(fee,0)+" + updateFee)
@@ -463,8 +455,8 @@
                             .set(ApplyDetail::getEditDate, update.getEditDate())
                             .eq(ApplyDetail::getId, oldModel.getApplyId())
                     );
-                    totalFee.add(updateFee);
-                    currentFee.add(updateCurrentFee);
+                    totalFee = totalFee.add(updateFee);
+                    currentFee = currentFee.add(updateCurrentFee);
 
                     //淇敼 鍛樺伐鎶曚繚鏄庣粏璁板綍 鍘嗗彶鏁版嵁
                     memberInsuranceJoinMapper.update(null, new UpdateWrapper<MemberInsurance>().lambda()
@@ -472,12 +464,9 @@
                             .set(MemberInsurance::getEndTime, update.getApplyStartTime())
                             .eq(MemberInsurance::getRelationId, oldModel.getId())
                     );
-
-                }
             }
 
             if (memberInsuranceList != null && memberInsuranceList.size() > 0) {
-//            applyDetailJoinMapper.insertBatchSomeColumn(addList);
                 memberInsuranceJoinMapper.insertBatchSomeColumn(memberInsuranceList);
             }
             if (totalFee.compareTo(new BigDecimal(0)) != 0) {
@@ -636,6 +625,10 @@
         applyChangeFee.setFee(fee);
         applyChangeMapper.updateById(applyChangeFee);
 
+//        if(1==1){
+//            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+//        }
+
 
 
         Constants.ApplyLogType applyLogType = Constants.ApplyLogType.CA_COMPANY_COMMIT;
@@ -782,7 +775,7 @@
                 throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "璇ヤ紒涓氬垎閰嶄繚闄╂柟妗堟棤娉曡繘琛屽噺淇�");
             }
             //鍑忎繚鏄庣粏鏁版嵁 璁$畻閲戦  鏍规嵁鎵瑰崟鏃堕棿 鍓嶄竴澶� 璁$畻
-            applyChangeCyclePriceDTO.setValidTime(DateUtil.getMontageDate(applyChange.getValidTime(),3));
+            applyChangeCyclePriceDTO.setValidTime(DateUtil.getMontageDate(applyChange.getValidTime(),2));
             CountCyclePriceVO countCyclePriceVO =  this.getChangeCountCyclePriceVO(applyChangeCyclePriceDTO);
             BigDecimal detailFee = countCyclePriceVO.getCyclePrice();
             this.delChangeDetail(applyChange,delDetailList,insuranceApply,solutions,loginUserInfo,detailFee);
@@ -822,7 +815,8 @@
      * @param delDetailList
      * @param loginUserInfo
      */
-    public void delChangeDetail(ApplyChange applyChange ,List<ApplyChagneDetail> delDetailList,InsuranceApply insuranceApply,Solutions solutions,LoginUserInfo loginUserInfo,BigDecimal detailFee){
+    public void delChangeDetail(ApplyChange applyChange ,List<ApplyChagneDetail> delDetailList,InsuranceApply insuranceApply,Solutions solutions,
+                                LoginUserInfo loginUserInfo,BigDecimal detailFee){
         for (ApplyChagneDetail applyChagneDetail : delDetailList) {
             if (Objects.isNull(applyChagneDetail.getMemberId())) {
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍑忎繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝繀濉」缂哄け");
@@ -859,7 +853,7 @@
             applyChagneDetail.setApplyChangeId(applyChange.getId());
             applyChagneDetail.setType(Constants.ONE);
 
-            applyChagneDetail.setStartTime(DateUtil.getMontageDate(applyChange.getApplyStartTime(),1));
+            applyChagneDetail.setStartTime(applyDetail.getStartTime());
             applyChagneDetail.setEndTime(DateUtil.getMontageDate(applyChange.getApplyStartTime(),3));
 
             applyChagneDetail.setFee( detailFee.multiply(new BigDecimal(-1)));

--
Gitblit v1.9.3