From deb3baf0fb04c3a9f5b0d4b5bd9fb3237908d576 Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期一, 19 二月 2024 18:38:12 +0800
Subject: [PATCH] 111

---
 server/service/src/main/java/com/doumee/service/business/impl/ApplyChangeServiceImpl.java |  338 ++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 219 insertions(+), 119 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 9eb88b1..00a2029 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
@@ -171,6 +171,7 @@
         update.setStatus(Constants.ApplyChangeStatus.APPROVE.getKey());
         update.setCheckDate(update.getEditDate());
         update.setCheckInfo(param.getCheckInfo());
+        update.setApplyId(model.getApplyId());
         update.setCheckUserId(user.getId());
         update.setId(model.getId());
         update.setValidCode(param.getValidCode());
@@ -194,6 +195,9 @@
             dealDetailsDUdata(update);
         }
 
+//        if(1==1){
+//            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+//        }
 
         Constants.ApplyLogType applyLogType = Constants.ApplyLogType.CA_PLATFORM_APPROVE;
         String info = "";
@@ -279,7 +283,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())
@@ -287,63 +290,101 @@
         if(detailList ==null || detailList.size()==0){
             return;
         }
+        //瀹為檯鎵瑰崟鐢熸晥鏃ユ湡
+        Date applyStartTime = DateUtil.getMontageDate(update.getApplyStartTime(),1);
         for(ApplyChagneDetail detail : detailList){
             //鏌ヨ鍛樺伐鏄湪涓诲崟涓� 鏄惁瀛樺湪鐢熸晥涓殑鏁版嵁
             ApplyDetail oldModel = applyDetailJoinMapper.selectOne(new QueryWrapper<ApplyDetail>().lambda()
                     .eq(ApplyDetail::getApplyId, update.getApplyId())
                     .eq(ApplyDetail::getMemberId, detail.getMemberId())
+                    .le(ApplyDetail::getStartTime,applyStartTime)
+                    .ge(ApplyDetail::getEndTime,applyStartTime)
                     .orderByDesc(ApplyDetail::getCreateDate)
                     .last("limit 1"));
             if(oldModel == null  ){
-                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝鐢ㄦ埛銆�"+detail.getMemberName()+"銆戝師淇濆崟淇℃伅鏈夎锛屽綋鍓嶇敵璇蜂笉鏀寔鍑忎繚澶勭悊锛�");
+                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝鐢ㄦ埛銆�"+detail.getMemberName()+"銆戝師淇濆崟淇℃伅鏈夎锛屾壒鍗曟棩鏈熸湭鍦ㄤ繚鍗曟棩鏈熷唴锛�");
             }
             Date endDate = oldModel.getEndTime();
-            //褰撳墠鏃ユ湡澶т簬鎵瑰崟鏃ユ湡 闇�瑕佸洖婊氭暟鎹疄闄呮暟鎹�
-            Boolean flag = DateUtil.getMontageDate(new Date(),2).compareTo(DateUtil.getMontageDate(update.getStartTime(),2))>0;
-            //鎹㈠巶鍚庡巻鍙茶褰曠殑璐圭敤 fee
-            Integer days = DateUtil.daysBetweenDates(DateUtil.getMontageDate(update.getStartTime(),2),DateUtil.getMontageDate(oldModel.getStartTime(),1)) + 1;
-            BigDecimal oldFee = this.getApplyPrice(update.getApplyId(),days);
-            BigDecimal fee = oldModel.getFee();
-            BigDecimal oldCurrentFee = oldModel.getCurrentFee();
-            applyDetailJoinMapper.update(null, new UpdateWrapper<ApplyDetail>().lambda()
-                    .set(ApplyDetail::getEditor,update.getEditor())
-                    .set(ApplyDetail::getEditDate,update.getEditDate())
-                    .set(ApplyDetail::getEndTime,DateUtil.getMontageDate(update.getStartTime(),2))
-                    .set(ApplyDetail::getFee,oldFee)
-                    .set(flag,ApplyDetail::getCurrentFee,oldFee)
-                    .eq(ApplyDetail::getId,oldModel.getApplyId())
-            );
 
-            //淇敼 鍛樺伐鎶曚繚鏄庣粏璁板綍 鍘嗗彶鏁版嵁
-            memberInsuranceJoinMapper.update(null,new UpdateWrapper<MemberInsurance>().lambda()
-                    .set(MemberInsurance::getEndTime,update.getApplyStartTime())
-                            .set(MemberInsurance::getFee,oldFee)
-                    .eq(MemberInsurance::getRelationId,oldModel.getId())
-            );
+            //濡傛灉瀹為檯鎵瑰崟鏃ユ湡 鍜� 鍘熻褰曟棩鏈熺浉绛� 鍒欑洿鎺ヤ慨鏀硅褰曟淳閬e崟浣嶄笌宸ョ淇℃伅
+            if(applyStartTime.compareTo(oldModel.getStartTime())!=Constants.ZERO){
+                //褰撳墠鏃ユ湡澶т簬鎵瑰崟鏃ユ湡 闇�瑕佸洖婊氭暟鎹疄闄呮暟鎹�
+                Boolean flag = DateUtil.getMontageDate(new Date(),2).compareTo(DateUtil.getMontageDate(update.getApplyStartTime(),2))>0;
+                //鎹㈠巶鍚庡巻鍙茶褰曠殑璐圭敤 fee
+                Integer days = DateUtil.daysBetweenDates(DateUtil.getMontageDate(update.getApplyStartTime(),3),DateUtil.getMontageDate(oldModel.getStartTime(),1))+1;
+                BigDecimal oldFee = this.getApplyPrice(update.getApplyId(),days);
+                BigDecimal fee = oldModel.getFee();
+                BigDecimal oldCurrentFee = oldModel.getCurrentFee();
 
-            ApplyDetail applyDetail = new ApplyDetail();
-            applyDetail.setApplyId(oldModel.getApplyId());
-            applyDetail.setCreateDate(new Date());
-            applyDetail.setCreator(update.getEditor());
-            applyDetail.setMemberId(oldModel.getMemberId());
-            applyDetail.setStartTime(DateUtil.getMontageDate(update.getApplyStartTime(),1));
-            applyDetail.setEndTime(endDate);
-            applyDetail.setDuId(detail.getDuId());
-            applyDetail.setWorktypeId(detail.getWorktypeId());
-            applyDetail.setIdcardNo(oldModel.getIdcardNo());
-            applyDetail.setFee(fee.subtract(oldFee));
-            if(flag){
-                applyDetail.setCurrentFee(oldCurrentFee.multiply(oldFee));
+                applyDetailJoinMapper.update(null, new UpdateWrapper<ApplyDetail>().lambda()
+                        .set(ApplyDetail::getEditor,update.getEditor())
+                        .set(ApplyDetail::getEditDate,update.getEditDate())
+                        .set(ApplyDetail::getEndTime,DateUtil.getMontageDate(update.getApplyStartTime(),3))
+                        .set(ApplyDetail::getFee,oldFee)
+                        .set(flag,ApplyDetail::getCurrentFee,oldFee)
+                        .eq(ApplyDetail::getId,oldModel.getId())
+                );
+
+                //淇敼 鍛樺伐鎶曚繚鏄庣粏璁板綍 鍘嗗彶鏁版嵁
+                memberInsuranceJoinMapper.update(null,new UpdateWrapper<MemberInsurance>().lambda()
+                        .set(MemberInsurance::getEndTime,update.getApplyStartTime())
+                        .set(MemberInsurance::getFee,oldFee)
+                        .eq(MemberInsurance::getRelationId,oldModel.getId())
+                );
+
+                ApplyDetail applyDetail = new ApplyDetail();
+                applyDetail.setApplyId(oldModel.getApplyId());
+                applyDetail.setCreateDate(new Date());
+                applyDetail.setCreator(update.getEditor());
+                applyDetail.setMemberId(oldModel.getMemberId());
+                applyDetail.setStartTime(DateUtil.getMontageDate(update.getApplyStartTime(),1));
+                applyDetail.setEndTime(endDate);
+                applyDetail.setDuId(detail.getDuId());
+                applyDetail.setWorktypeId(detail.getWorktypeId());
+                applyDetail.setIdcardNo(oldModel.getIdcardNo());
+                applyDetail.setFee(fee.subtract(oldFee));
+                if(flag){
+                    applyDetail.setCurrentFee(oldCurrentFee.multiply(oldFee));
+                }else{
+                    applyDetail.setCurrentFee(BigDecimal.ZERO);
+                }
+                applyDetail.setSex(oldModel.getSex());
+                applyDetail.setMemberName(oldModel.getMemberName());
+                applyDetail.setFromId(detail.getId());
+                applyDetailJoinMapper.insert(applyDetail);
+
+                MemberInsurance memberInsurance = new MemberInsurance(applyDetail,update.getId());
+                memberInsuranceJoinMapper.insert(memberInsurance);
             }else{
-                applyDetail.setCurrentFee(BigDecimal.ZERO);
-            }
-            applyDetail.setSex(oldModel.getSex());
-            applyDetail.setMemberName(oldModel.getMemberName());
-            applyDetail.setFromId(detail.getId());
-            applyDetailJoinMapper.insert(applyDetail);
 
-            MemberInsurance memberInsurance = new MemberInsurance(applyDetail,update.getId());
-            memberInsuranceJoinMapper.insert(memberInsurance);
+                applyDetailJoinMapper.update(null, new UpdateWrapper<ApplyDetail>().lambda()
+                        .set(ApplyDetail::getEditor,update.getEditor())
+                        .set(ApplyDetail::getEditDate,update.getEditDate())
+                        .set(ApplyDetail::getDuId,detail.getDuId())
+                        .set(ApplyDetail::getWorktypeId,detail.getWorktypeId())
+                        .eq(ApplyDetail::getId,oldModel.getId())
+                );
+
+                //鍛樺伐鎶曚繚鏄庣粏璁板綍 鍘嗗彶鏁版嵁
+                memberInsuranceJoinMapper.update(null,new UpdateWrapper<MemberInsurance>().lambda()
+                        .set(MemberInsurance::getDuId,detail.getDuId())
+                        .set(MemberInsurance::getDuName,detail.getDuName())
+                        .set(MemberInsurance::getWorktypeId,detail.getWorktypeId())
+                        .set(MemberInsurance::getWorktypeName,detail.getWorkTypeName())
+                        .eq(MemberInsurance::getRelationId,oldModel.getId())
+                );
+            }
+
+            Member member = memberMapper.selectById(detail.getMemberId());
+            if(Objects.isNull(member)){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鍛樺伐鏁版嵁");
+            }
+            member.setApplyId(update.getApplyId());
+            member.setDuId(detail.getDuId());
+            member.setWorktypeId(detail.getWorktypeId());
+            member.setStartTime(detail.getStartTime());
+            member.setEndTime(detail.getEndTime());
+            memberMapper.updateById(member);
         }
     }
     /**
@@ -361,7 +402,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,20 +420,17 @@
         //鍔犱繚涓氬姟 浣跨敤鐨勫姞淇濋噾棰�
         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) {
+            Member member = memberMapper.selectById(detail.getMemberId());
+            if(Objects.isNull(member)){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鍛樺伐鏁版嵁");
+            }
             if (Constants.equalsInteger(detail.getType(), Constants.ZERO)) {
                 //鍔犱繚
                 ApplyDetail add = new ApplyDetail();
@@ -409,26 +446,25 @@
                 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());
 
-                    MemberInsurance memberInsurance = new MemberInsurance(detail, update, update.getEditor(), add.getId());
-                    memberInsuranceList.add(memberInsurance);
-                } else {
+                if(new Date().compareTo(DateUtil.getMontageDate(detail.getStartTime(), 2))>=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 {
                     //鍑忎繚鎿嶄綔
                     //鏌ヨ鍛樺伐鏄湪涓诲崟涓� 鏄惁瀛樺湪鐢熸晥涓殑鏁版嵁
                     ApplyDetail oldModel = applyDetailJoinMapper.selectOne(new QueryWrapper<ApplyDetail>().lambda()
@@ -439,32 +475,31 @@
                     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)
                             .setSql(" current_fee = " + updateCurrentFee)
-                            .set(ApplyDetail::getEndTime, update.getApplyStartTime())
+                            .set(ApplyDetail::getEndTime, DateUtil.getMontageDate(update.getApplyStartTime(), 3))
                             .set(ApplyDetail::getEditor, update.getEditor())
                             .set(ApplyDetail::getEditDate, update.getEditDate())
-                            .eq(ApplyDetail::getId, oldModel.getApplyId())
+                            .eq(ApplyDetail::getId, oldModel.getId())
                     );
-                    totalFee.add(updateFee);
-                    currentFee.add(updateCurrentFee);
+                    totalFee = totalFee.add(updateFee);
+                    currentFee = currentFee.add(updateCurrentFee);
 
                     //淇敼 鍛樺伐鎶曚繚鏄庣粏璁板綍 鍘嗗彶鏁版嵁
                     memberInsuranceJoinMapper.update(null, new UpdateWrapper<MemberInsurance>().lambda()
@@ -472,26 +507,28 @@
                             .set(MemberInsurance::getEndTime, update.getApplyStartTime())
                             .eq(MemberInsurance::getRelationId, oldModel.getId())
                     );
-
-                }
             }
+
+            member.setApplyId(update.getApplyId());
+            member.setDuId(detail.getDuId());
+            member.setWorktypeId(detail.getWorktypeId());
+            member.setStartTime(detail.getStartTime());
+            member.setEndTime(detail.getEndTime());
+            memberMapper.updateById(member);
 
             if (memberInsuranceList != null && memberInsuranceList.size() > 0) {
-//            applyDetailJoinMapper.insertBatchSomeColumn(addList);
                 memberInsuranceJoinMapper.insertBatchSomeColumn(memberInsuranceList);
             }
-            if (totalFee.compareTo(new BigDecimal(0)) != 0) {
-                //濡傛灉淇濆崟閲戦鍙戠敓缂栫爜锛屾洿鏂版�讳繚鍗曢噾棰�
-                insuranceApplyMapper.update(null, new UpdateWrapper<InsuranceApply>().lambda()
-                        .setSql(" fee = ifnull(fee,0)+" + totalFee)
-                        .setSql(" current_fee = ifnull(current_fee,0)+" + currentFee)
-                        .set(InsuranceApply::getEditor, update.getEditor())
-                        .set(InsuranceApply::getEditDate, update.getEditDate())
-                        .eq(InsuranceApply::getId, update.getApplyId())
-                );
-
-            }
-
+        }
+        if (totalFee.compareTo(new BigDecimal(0)) != 0) {
+            //濡傛灉淇濆崟閲戦鍙戠敓缂栫爜锛屾洿鏂版�讳繚鍗曢噾棰�
+            insuranceApplyMapper.update(null, new UpdateWrapper<InsuranceApply>().lambda()
+                    .setSql(" fee = ifnull(fee,0)+" + totalFee)
+                    .setSql(" current_fee = ifnull(current_fee,0)+" + currentFee)
+                    .set(InsuranceApply::getEditor, update.getEditor())
+                    .set(InsuranceApply::getEditDate, update.getEditDate())
+                    .eq(InsuranceApply::getId, update.getApplyId())
+            );
         }
     }
 
@@ -610,7 +647,7 @@
         }
         CompanySolution companySolution = companySolutionMapper.selectOne(new QueryWrapper<CompanySolution>().lambda()
                 .eq(CompanySolution::getCompanyId,loginUserInfo.getCompanyId())
-                .eq(CompanySolution::getSolutionBaseId,solutions.getId())
+                .eq(CompanySolution::getSolutionId,solutions.getId())
                 .eq(CompanySolution::getIsdeleted,Constants.ZERO)
                 .last(" limit 1 ")
         );
@@ -622,8 +659,20 @@
                 && DateUtil.compareDate( applyChange.getValidTime(),insuranceApply.getEndTime()) >= Constants.ZERO)) {
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "鐢宠鏃ユ湡鏈浜庝繚鍗曟棩鏈熷唴锛屾棤娉曡繘琛岃鎿嶄綔");
         }
+        //鏌ヨ淇濆崟涓嬫槸鍚﹀瓨鍦ㄨ繘琛屼腑鐨勫姞鍑忎繚/鎹㈠巶鍗曟嵁
+        if(applyChangeMapper.selectCount(new QueryWrapper<ApplyChange>().lambda()
+                .eq(ApplyChange::getApplyId,insuranceApply.getId())
+                .notIn(ApplyChange::getStatus,Constants.ApplyChangeStatus.APPROVE.getKey(),Constants.ApplyChangeStatus.CLOSE.getKey())
+
+        )>Constants.ZERO){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀛樺湪杩涜涓殑鍔犲噺淇�/鎹㈠巶鐢宠");
+        };
+
+
         applyChange.setCreateDate(new Date());
         applyChange.setCreator(loginUserInfo.getId());
+        applyChange.setEditor(loginUserInfo.getId());
+        applyChange.setEditDate(new Date());
         applyChange.setIsdeleted(Constants.ZERO);
         applyChange.setApplyStartTime(applyChange.getValidTime());
         applyChange.setStatus(Constants.ZERO);
@@ -636,11 +685,15 @@
         applyChangeFee.setFee(fee);
         applyChangeMapper.updateById(applyChangeFee);
 
+//        if(1==1){
+//            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+//        }
+
 
 
         Constants.ApplyLogType applyLogType = Constants.ApplyLogType.CA_COMPANY_COMMIT;
         String info =applyLogType.getInfo();
-//        info = info.replace("${param}", update.getCheckInfo());
+        info = info.replace("${param}", "");
         ApplyLog log = new ApplyLog(applyChange,applyLogType.getName(),info,applyChange.getId(),applyLogType.getKey(), null, null);
         applyLogMapper.insert(log);
         
@@ -706,7 +759,14 @@
                 && DateUtil.compareDate( applyChange.getValidTime(),insuranceApply.getEndTime()) >= Constants.ZERO)) {
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "鐢宠鏃ユ湡鏈浜庝繚鍗曟棩鏈熷唴锛屾棤娉曡繘琛岃鎿嶄綔");
         }
-
+        //鏌ヨ淇濆崟涓嬫槸鍚﹀瓨鍦ㄨ繘琛屼腑鐨勫姞鍑忎繚/鎹㈠巶鍗曟嵁
+        if(applyChangeMapper.selectCount(new QueryWrapper<ApplyChange>().lambda()
+                .eq(ApplyChange::getApplyId,insuranceApply.getId())
+                .ne(ApplyChange::getId,applyChange.getId())
+                .notIn(ApplyChange::getStatus,Constants.ApplyChangeStatus.APPROVE.getKey(),Constants.ApplyChangeStatus.CLOSE.getKey())
+        )>Constants.ZERO){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀛樺湪杩涜涓殑鍔犲噺淇�/鎹㈠巶鐢宠");
+        };
         applyChange.setEditDate(new Date());
         applyChange.setEditor(loginUserInfo.getId());
         applyChange.setApplyStartTime(applyChange.getValidTime());
@@ -718,10 +778,9 @@
         applyChange.setFee(fee);
         applyChangeMapper.updateById(applyChange);
 
-
         Constants.ApplyLogType applyLogType = Constants.ApplyLogType.CA_UPLOAD_AGAIN;
         String info =applyLogType.getInfo();
-//        info = info.replace("${param}", update.getCheckInfo());
+        info = info.replace("${param}", "");
         ApplyLog log = new ApplyLog(applyChange,applyLogType.getName(),info,applyChange.getId(),applyLogType.getKey(), null, null);
         applyLogMapper.insert(log);
 
@@ -782,7 +841,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 +881,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,8 +919,15 @@
             applyChagneDetail.setApplyChangeId(applyChange.getId());
             applyChagneDetail.setType(Constants.ONE);
 
-            applyChagneDetail.setStartTime(DateUtil.getMontageDate(applyDetail.getStartTime(),1));
+            applyChagneDetail.setStartTime(applyDetail.getStartTime());
             applyChagneDetail.setEndTime(DateUtil.getMontageDate(applyChange.getApplyStartTime(),3));
+
+            member.setApplyId(insuranceApply.getId());
+            member.setDuId(applyChagneDetail.getDuId());
+            member.setWorktypeId(applyChagneDetail.getWorktypeId());
+            member.setStartTime(applyChagneDetail.getStartTime());
+            member.setEndTime(applyChagneDetail.getEndTime());
+            memberMapper.updateById(member);
 
             applyChagneDetail.setFee( detailFee.multiply(new BigDecimal(-1)));
             applyChagneDetailJoinMapper.insert(applyChagneDetail);
@@ -886,6 +953,13 @@
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍔犱繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝繀濉」缂哄け");
             }
 
+            applyChagneDetail.setCreateDate(new Date());
+            applyChagneDetail.setCreator(loginUserInfo.getId());
+            applyChagneDetail.setIsdeleted(Constants.ZERO);
+            applyChagneDetail.setApplyChangeId(applyChange.getId());
+            applyChagneDetail.setStartTime(DateUtil.getMontageDate(applyChange.getApplyStartTime(),1));
+            applyChagneDetail.setEndTime(DateUtil.getMontageDate(insuranceApply.getEndTime(),2));
+            applyChagneDetail.setType(Constants.ZERO);
             Member member = new Member();
             if(Objects.isNull(applyChagneDetail.getMemberId())){
                 //鏌ヨ鏄惁瀛樺湪璇ョ敤鎴�
@@ -907,11 +981,15 @@
                     member.setApplyId(insuranceApply.getId());
                     member.setDuId(applyChagneDetail.getDuId());
                     member.setWorktypeId(applyChagneDetail.getWorktypeId());
+                    member.setStartTime(applyChagneDetail.getStartTime());
+                    member.setEndTime(applyChagneDetail.getEndTime());
                     memberMapper.insert(member);
                 }else{
                     member.setApplyId(insuranceApply.getId());
                     member.setDuId(applyChagneDetail.getDuId());
                     member.setWorktypeId(applyChagneDetail.getWorktypeId());
+                    member.setStartTime(applyChagneDetail.getStartTime());
+                    member.setEndTime(applyChagneDetail.getEndTime());
                     memberMapper.updateById(member);
                 }
             }else{
@@ -922,8 +1000,19 @@
                 member.setApplyId(insuranceApply.getId());
                 member.setDuId(applyChagneDetail.getDuId());
                 member.setWorktypeId(applyChagneDetail.getWorktypeId());
+                member.setStartTime(applyChagneDetail.getStartTime());
+                member.setEndTime(applyChagneDetail.getEndTime());
                 memberMapper.updateById(member);
             }
+
+            //鏍规嵁鍛樺伐韬唤璇佽繘琛屽垽鏂勾榫�
+            long age = Constants.getAgeByIdCard(member.getIdcardNo());
+            if(Objects.isNull(age)
+                    || age > solutions.getMaxAge()
+                    || age < solutions.getMinAge()){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+applyChagneDetail.getMemberName()+"銆戝憳宸ュ勾榫勮秴鍑烘柟妗堥厤缃� 鏂规閰嶇疆銆�"+solutions.getMinAge()+" - "+solutions.getMaxAge()+"銆戝瓨鍦ㄥ紓甯告暟鎹紒");
+            }
+
             //鏌ヨ鍛樺伐鏄惁瀛樺湪  0寰呯缃� 1宸茬绔� 鐨勬绫讳笟鍔′繚鏁版嵁 鍚屼竴涓诲崟涓�
             if (applyChagneDetailJoinMapper.selectJoinCount(
                     new MPJLambdaWrapper<ApplyChagneDetail>()
@@ -934,6 +1023,8 @@
             ) > Constants.ZERO) {
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍔犱繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝瓨鍦ㄧ敵璇蜂腑鐨勫姞鍑忎繚/鎹㈠巶鍗曟嵁");
             }
+
+
             //鏌ヨ鍛樺伐鏄湪涓诲崟涓� 鏄惁瀛樺湪鐢熸晥涓殑鏁版嵁
             if(!Objects.isNull(applyChagneDetail.getMemberId())){
                 if (applyDetailJoinMapper.selectCount(new QueryWrapper<ApplyDetail>().lambda()
@@ -954,13 +1045,6 @@
                 throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(), "銆�" + applyChagneDetail.getMemberName() + "銆戝憳宸ュ伐绉嶄俊鎭湭鏌ヨ鍒帮紒");
             }
             applyChagneDetail.setMemberId(member.getId());
-            applyChagneDetail.setCreateDate(new Date());
-            applyChagneDetail.setCreator(loginUserInfo.getId());
-            applyChagneDetail.setIsdeleted(Constants.ZERO);
-            applyChagneDetail.setApplyChangeId(applyChange.getId());
-            applyChagneDetail.setStartTime(DateUtil.getMontageDate(applyChange.getStartTime(),1));
-            applyChagneDetail.setEndTime(DateUtil.getMontageDate(insuranceApply.getEndTime(),2));
-            applyChagneDetail.setType(Constants.ZERO);
             applyChagneDetail.setFee(detailFee);
             applyChagneDetailJoinMapper.insert(applyChagneDetail);
         }
@@ -994,6 +1078,7 @@
                     new MPJLambdaWrapper<ApplyChagneDetail>()
                             .leftJoin(ApplyChange.class, ApplyChange::getId, ApplyChagneDetail::getApplyChangeId)
                             .eq(ApplyChagneDetail::getMemberId, applyChagneDetail.getMemberId())
+                            .eq(ApplyChange::getApplyId, applyChange.getApplyId())
                             .in(ApplyChange::getStatus, Constants.ZERO, Constants.ONE)
             ) > Constants.ZERO) {
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鎹㈠巶浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝瓨鍦ㄧ敵璇蜂腑鐨勫姞鍑忎繚/鎹㈠巶鍗曟嵁");
@@ -1020,12 +1105,27 @@
                     .collect(Collectors.toList()).size() <= Constants.ZERO) {
                 throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(), "鎹㈠巶浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝憳宸ュ伐绉嶄俊鎭湭鏌ヨ鍒帮紒");
             }
+            if(applyChagneDetail.getOldDuId().equals(applyChagneDetail.getDuId())
+            && applyChagneDetail.getOldWorktypeId().equals(applyChagneDetail.getWorktypeId())){
+                throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(), "鎹㈠巶浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戞崲鍘傛暟鎹浉鍚岋紒");
+            }
             applyChagneDetail.setCreateDate(new Date());
             applyChagneDetail.setCreator(loginUserInfo.getId());
             applyChagneDetail.setIsdeleted(Constants.ZERO);
             applyChagneDetail.setApplyChangeId(applyChange.getId());
             applyChagneDetail.setType(Constants.TWO);
+            applyChagneDetail.setStartTime(applyDetail.getStartTime());
+            applyChagneDetail.setEndTime(applyDetail.getEndTime());
+
             applyChagneDetailJoinMapper.insert(applyChagneDetail);
+
+            member.setApplyId(applyChange.getApplyId());
+            member.setDuId(applyChagneDetail.getDuId());
+            member.setWorktypeId(applyChagneDetail.getWorktypeId());
+            member.setStartTime(applyChagneDetail.getStartTime());
+            member.setEndTime(applyChagneDetail.getEndTime());
+            memberMapper.updateById(member);
+
         }
     }
 

--
Gitblit v1.9.3