From 15ef66d5eb25490cb4684c32598ca25f54cd9c4b Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期四, 20 六月 2024 14:07:54 +0800
Subject: [PATCH] git ch

---
 server/service/src/main/java/com/doumee/service/business/impl/ApplyChangeServiceImpl.java |  286 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 261 insertions(+), 25 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 e3e32ca..7c44394 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
@@ -25,12 +25,14 @@
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.doumee.service.business.InsuranceApplyService;
 import com.doumee.service.business.SmsEmailService;
 import com.doumee.service.business.third.SignService;
 import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.SecurityUtils;
+import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -349,7 +351,6 @@
         info = info.replace("${param}",param.getCheckInfo());
         ApplyLog log = new ApplyLog(update,applyLogType.getName(), info,update.getId(),applyLogType.getKey(),JSONObject.toJSONString(model), JSONObject.toJSONString(update));
         applyLogMapper.insert(log);
-
         return  1;
 
     }
@@ -578,7 +579,182 @@
 //                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏈煡璇㈠埌鏂规鏈�鏂扮増鏈俊鎭�");
 //            }
 //        }
-        for (ApplyChagneDetail detail : detailList) {
+        List<ApplyChagneDetail> addList = detailList.stream().filter(f->Constants.equalsInteger(f.getType(),Constants.ZERO)).collect(Collectors.toList());
+        List<ApplyChagneDetail> reduceList = detailList.stream().filter(f->Constants.equalsInteger(f.getType(),Constants.ONE)).collect(Collectors.toList());
+        //鍑忎繚涓氬姟
+        for (ApplyChagneDetail detail:reduceList) {
+            Member member = memberMapper.selectById(detail.getMemberId());
+            if(Objects.isNull(member)){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鍛樺伐鏁版嵁");
+            }
+            //鍑忎繚鎿嶄綔
+            //鏌ヨ鍛樺伐鏄湪涓诲崟涓� 鏄惁瀛樺湪鐢熸晥涓殑鏁版嵁
+            ApplyDetail oldModel = applyDetailJoinMapper.selectOne(new QueryWrapper<ApplyDetail>().lambda()
+                    .eq(ApplyDetail::getApplyId, update.getApplyId())
+                    .eq(ApplyDetail::getMemberId, detail.getMemberId())
+                    .orderByDesc(ApplyDetail::getCreateDate)
+                    .last("limit 1"));
+            if (oldModel == null || oldModel.getStartTime() == null || oldModel.getStartTime().getTime() > update.getApplyStartTime().getTime()) {
+                throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵逛笉璧凤紝鐢ㄦ埛銆�" + detail.getMemberName() + "銆戝師淇濆崟淇℃伅鏈夎锛屽綋鍓嶇敵璇蜂笉鏀寔鍑忎繚澶勭悊锛�");
+            }
+            if(!(oldModel.getStartTime().getTime()<update.getDelValidTime().getTime()&& oldModel.getEndTime().getTime()>=update.getDelValidTime().getTime())){
+                throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵逛笉璧凤紝鐢ㄦ埛銆�" + detail.getMemberName() + "銆戝噺淇濇棩鏈熸湭鍦ㄤ繚鍗曡褰曟棩鏈熶腑锛�");
+            }
+
+            Date delValidTime = oldModel.getStartTime().compareTo(update.getDelValidTime())!=0?
+                    DateUtil.getMontageDate(update.getDelValidTime(), 3):
+                    DateUtil.getMontageDate(update.getDelValidTime(), 2);
+
+            BigDecimal sumFee = Objects.isNull(insuranceApply.getServerCost())?
+                    solutions.getPrice():
+                    solutions.getPrice().add(insuranceApply.getServerCost());
+            // 鍑忎繚鍚� 鎬昏垂鐢�
+            BigDecimal updateFee =  Constants.reduceFee(
+                    solutions,
+                    sumFee
+                    ,insuranceApply.getStartTime(),insuranceApply.getFinalEndTime(),oldModel.getStartTime(),delValidTime
+            ) ;
+            //褰撳鎵规椂闂� 澶т簬 鐢宠鐨勬椂闂存椂 璁$畻瀹為檯鍑忓皯閲戦 鍥犱负宸叉墸閲戦浼氬ぇ浜� 搴旀墸閲戦
+            BigDecimal updateCurrentFee = BigDecimal.ZERO;
+            if (DateUtil.daysBetweenDates(DateUtil.getMontageDate(new Date(), 2),oldModel.getStartTime()) > 0) {
+                //// 2024骞�5鏈�8鏃�17:37:23 淇敼 璁$畻浜х敓璐圭敤
+                updateCurrentFee = Constants.produceFee(solutions,sumFee,insuranceApply.getStartTime(),insuranceApply.getEndTime(),
+                        oldModel.getStartTime()
+                );
+            }
+
+            UpdateWrapper<ApplyDetail> updateWrapper = new UpdateWrapper<ApplyDetail>();
+            updateWrapper.lambda()
+                    .setSql(" fee = " + updateFee)
+                    .setSql(" current_fee = " + updateCurrentFee)
+                    .set(ApplyDetail::getEndTime, delValidTime)
+                    .set(ApplyDetail::getEditor, update.getEditor())
+                    .set(ApplyDetail::getEditDate, update.getEditDate())
+                    .eq(ApplyDetail::getId, oldModel.getId());
+
+            if(Constants.equalsInteger(solutions.getDelOnlyReplace(),Constants.ONE)
+                    && Constants.equalsInteger(solutions.getTimeUnit(),solutions.getInsureCycleUnit())){
+                if(delValidTime.getTime()<=oldModel.getStartTime().getTime()){
+                    updateFee  = BigDecimal.ZERO;
+                    updateWrapper.lambda().set(ApplyDetail::getFee,updateFee)
+                            .set(ApplyDetail::getChangeStatus,Constants.TWO);
+                }else{
+                    //鏍囪鏁版嵁宸茶鏇挎崲
+                    updateWrapper.lambda().set(ApplyDetail::getReduceMoney,solutions.getPrice().multiply(new BigDecimal(-1)))
+                            .set(ApplyDetail::getChangeStatus,Constants.ONE);
+                }
+                detail.setApplyDetailId(oldModel.getId());
+            }
+
+
+            applyDetailJoinMapper.update(null, updateWrapper);
+            totalFee = totalFee.add(updateFee).subtract(oldModel.getFee());
+            currentFee = currentFee.add(updateCurrentFee);
+
+            //淇敼 鍛樺伐鎶曚繚鏄庣粏璁板綍 鍘嗗彶鏁版嵁
+            memberInsuranceJoinMapper.update(null, new UpdateWrapper<MemberInsurance>().lambda()
+                    .setSql(" fee = " + updateFee)
+                    .set(MemberInsurance::getEndTime, delValidTime)
+                    .eq(MemberInsurance::getRelationId, oldModel.getId())
+            );
+
+            //淇敼涓氬姟鏄庣粏琛屾暟鎹疄闄呮壒鍗曟棩鏈�
+            applyChangeDetailJoinMapper.update(null,new UpdateWrapper<ApplyChagneDetail>().lambda()
+                    .set(ApplyChagneDetail::getFee,updateFee.subtract(oldModel.getFee()))
+                    .set( ApplyChagneDetail::getEndTime, delValidTime)
+                    .eq(ApplyChagneDetail::getId,detail.getId())
+            );
+
+            member.setApplyId(update.getApplyId());
+            member.setDuId(detail.getDuId());
+            member.setWorktypeId(detail.getWorktypeId());
+            member.setStartTime(detail.getStartTime());
+            member.setEndTime(detail.getEndTime());
+            memberMapper.updateById(member);
+        }
+
+        //鍔犱繚涓氬姟
+        for (int i = 0; i < addList.size(); i++) {
+            ApplyChagneDetail detail  = addList.get(i);
+            Member member = memberMapper.selectById(detail.getMemberId());
+            if (Objects.isNull(member)) {
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "鏈煡璇㈠埌鍛樺伐鏁版嵁");
+            }
+            //鏌ヨ浜哄憳淇℃伅鏄惁瀛樺湪鐩稿悓鐨勬柟妗堜笅鏄惁瀛樺湪 鍐茬獊鏁版嵁
+            InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getId(),
+                    member.getIdcardNo(),member.getName(),detail.getStartTime(),detail.getEndTime(),
+                    applyDetailJoinMapper);
+
+            //鏌ヨ鍔犱繚浜哄憳鏄惁瀛樺湪 鍐茬獊鐨� 淇濆崟鏄庣粏鏁版嵁
+            if(applyDetailJoinMapper.selectCount(new QueryWrapper<ApplyDetail>()
+                    .lambda()
+                    .eq(ApplyDetail::getApplyId,update.getApplyId())
+                    .eq(ApplyDetail::getIdcardNo,detail.getIdcardNo())
+                    .le(ApplyDetail::getStartTime,DateUtil.getMontageDate(update.getApplyStartTime(),1))
+                    .ge(ApplyDetail::getEndTime,DateUtil.getMontageDate(detail.getEndTime(),2))
+            )>Constants.ZERO){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "褰撳墠淇濆崟涓嬶紝鍔犱繚浜哄憳銆�" + detail.getMemberName() + "銆戝瓨鍦ㄦ棩鏈熷啿绐佺殑鏁版嵁");
+            }
+            //鍔犱繚
+            ApplyDetail add = new ApplyDetail();
+            add.setApplyId(update.getApplyId());
+            add.setValidCode(update.getValidCode());
+            add.setFee(detail.getFee());
+            add.setIsdeleted(Constants.ZERO);
+            add.setCreator(update.getEditor());
+            add.setCreateDate(update.getEditDate());
+            add.setMemberId(detail.getMemberId());
+            add.setMemberName(detail.getMemberName());
+            add.setWorktypeId(detail.getWorktypeId());
+            add.setIsdeleted(Constants.ZERO);
+            add.setIdcardNo(detail.getIdcardNo());
+            add.setSex(Constants.getSexByIdCard(detail.getIdcardNo()));
+            add.setMemberName(detail.getMemberName());
+            add.setRemark(detail.getRemark());
+            add.setDuId(detail.getDuId());
+            add.setStartTime(DateUtil.getMontageDate(update.getApplyStartTime(), 1));
+            add.setEndTime(DateUtil.getMontageDate(detail.getEndTime(), 2));
+            add.setFee(Constants.addFee(solutions,solutions.getPrice(),insuranceApply.getStartTime(),insuranceApply.getFinalEndTime(),update.getApplyStartTime(),insuranceApply.getEndTime()));
+            add.setChangeStatus(Constants.ZERO);
+            if(Constants.equalsInteger(solutions.getDelOnlyReplace(),Constants.ONE)
+                    && Constants.equalsInteger(solutions.getTimeUnit(),solutions.getInsureCycleUnit())){
+                add.setReduceId(reduceList.get(i).getId());
+            }
+            if(new Date().compareTo(DateUtil.getMontageDate(detail.getStartTime(), 2))>=0){
+                //2024骞�5鏈�8鏃�17:37:23 淇敼 璁$畻浜х敓璐圭敤
+                add.setCurrentFee(
+                        Constants.produceFee(solutions,add.getFee(),add.getStartTime(),add.getEndTime(),add.getStartTime())
+                );
+            }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(),solutions.getId());
+            memberInsurance.setStartTime(add.getStartTime());
+            memberInsurance.setEndTime(add.getEndTime());
+            memberInsurance.setRelationType(Constants.ONE);
+            memberInsuranceList.add(memberInsurance);
+
+            applyChangeDetailJoinMapper.update(null,new UpdateWrapper<ApplyChagneDetail>().lambda()
+                    .set(ApplyChagneDetail::getFee,add.getFee())
+                    .set(ApplyChagneDetail::getStartTime,DateUtil.getMontageDate(update.getApplyStartTime(), 1))
+                    .eq(ApplyChagneDetail::getId,detail.getId())
+            );
+
+            member.setApplyId(update.getApplyId());
+            member.setDuId(detail.getDuId());
+            member.setWorktypeId(detail.getWorktypeId());
+            member.setStartTime(detail.getStartTime());
+            member.setEndTime(detail.getEndTime());
+            memberMapper.updateById(member);
+        }
+
+
+
+        /*for (ApplyChagneDetail detail : detailList) {
             Member member = memberMapper.selectById(detail.getMemberId());
             if(Objects.isNull(member)){
                 throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鍛樺伐鏁版嵁");
@@ -639,9 +815,6 @@
                         .eq(ApplyChagneDetail::getId,detail.getId())
                 );
 
-//                if(1==1){
-//                    throw new BusinessException(ResponseStatus.SERVER_ERROR);
-//                }
 
             } else {
                     //鍑忎繚鎿嶄綔
@@ -680,15 +853,30 @@
                         );
                     }
 
-                    applyDetailJoinMapper.update(null, new UpdateWrapper<ApplyDetail>().lambda()
+                    UpdateWrapper<ApplyDetail> updateWrapper = new UpdateWrapper<ApplyDetail>();
+                    updateWrapper.lambda()
                             .setSql(" fee = " + updateFee)
                             .setSql(" current_fee = " + updateCurrentFee)
                             .set(ApplyDetail::getEndTime, delValidTime)
                             .set(ApplyDetail::getEditor, update.getEditor())
                             .set(ApplyDetail::getEditDate, update.getEditDate())
+                            .eq(ApplyDetail::getId, oldModel.getId());
 
-                            .eq(ApplyDetail::getId, oldModel.getId())
-                    );
+                    if(Constants.equalsInteger(solutions.getDelOnlyReplace(),Constants.ONE)
+                            && Constants.equalsInteger(solutions.getTimeUnit(),solutions.getInsureCycleUnit())){
+                        if(delValidTime.getTime()<=oldModel.getStartTime().getTime()){
+                            updateFee  = BigDecimal.ZERO;
+                            updateWrapper.lambda().set(ApplyDetail::getFee,updateFee)
+                                    .set(ApplyDetail::getChangeStatus,Constants.TWO);
+                        }else{
+                            //鏍囪鏁版嵁宸茶鏇挎崲
+                            updateWrapper.lambda().set(ApplyDetail::getReduceMoney,solutions.getPrice().multiply(new BigDecimal(-1)))
+                                    .set(ApplyDetail::getChangeStatus,Constants.ONE);
+                        }
+                    }
+
+
+                    applyDetailJoinMapper.update(null, updateWrapper);
                     totalFee = totalFee.add(updateFee).subtract(oldModel.getFee());
                     currentFee = currentFee.add(updateCurrentFee);
 
@@ -714,7 +902,8 @@
             member.setEndTime(detail.getEndTime());
             memberMapper.updateById(member);
 
-        }
+        }*/
+
         if (memberInsuranceList != null && memberInsuranceList.size() > 0) {
             memberInsuranceJoinMapper.insertBatchSomeColumn(memberInsuranceList);
         }
@@ -911,6 +1100,12 @@
             }else{
                 applyChange.setDelValidTime(applyChange.getValidTime());
             }
+            //浠呮敮鎸佹浛鎹�  淇濊瘉鍔犲噺淇濇棩鏈熶负鍚屼竴澶�
+            if(Constants.equalsInteger(solutions.getDelOnlyReplace(),Constants.ONE)){
+                applyChange.setApplyStartTime(
+                        applyChange.getDelValidTime()
+                );
+            }
         }else{
             applyChange.setApplyStartTime(applyChange.getValidTime());
         }
@@ -1010,9 +1205,35 @@
         )>Constants.ZERO){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀛樺湪杩涜涓殑鍔犲噺淇�/鎹㈠巶鐢宠");
         };
+
+        if(applyChange.getType().equals(Constants.ZERO)){
+            if(Objects.nonNull(solutions.getAddValidDays())){
+                applyChange.setApplyStartTime(
+                        DateUtil.afterDateByType(applyChange.getValidTime(),0,solutions.getAddValidDays())
+                );
+            }else{
+                applyChange.setApplyStartTime(applyChange.getValidTime());
+            }
+            if(Objects.nonNull(solutions.getDelValidDays())){
+                applyChange.setDelValidTime(
+                        DateUtil.afterDateByType(applyChange.getValidTime(),0,solutions.getDelValidDays())
+                );
+            }else{
+                applyChange.setDelValidTime(applyChange.getValidTime());
+            }
+            //浠呮敮鎸佹浛鎹�  淇濊瘉鍔犲噺淇濇棩鏈熶负鍚屼竴澶�
+            if(Constants.equalsInteger(solutions.getDelOnlyReplace(),Constants.ONE)){
+                applyChange.setApplyStartTime(
+                        applyChange.getDelValidTime()
+                );
+            }
+
+        }else{
+            applyChange.setApplyStartTime(applyChange.getValidTime());
+        }
+
         applyChange.setEditDate(new Date());
         applyChange.setEditor(loginUserInfo.getId());
-        applyChange.setApplyStartTime(applyChange.getValidTime());
         applyChange.setStatus(Constants.ZERO);
         //鍒犻櫎鍘嗗彶鏁版嵁
         applyChagneDetailJoinMapper.delete(new QueryWrapper<ApplyChagneDetail>().lambda().eq(ApplyChagneDetail::getApplyChangeId,applyChange.getId()));
@@ -1037,10 +1258,13 @@
     }
 
 
-    public BigDecimal dealApplyChangeData(ApplyChange applyChange,InsuranceApply insuranceApply,CompanySolution companySolution,Solutions solutions,LoginUserInfo loginUserInfo,BigDecimal fee){
-        if(Objects.nonNull(solutions.getDelOnlyReplace())&& solutions.getDelOnlyReplace().equals(Constants.ONE)){
-            if(applyChange.getDelDetailList().size() > applyChange.getAddDetailList().size()){
-                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "璇ヤ繚闄╂柟妗堜粎鏀寔鏇挎崲锛堝噺淇濅汉鏁颁笉寰楀ぇ浜庡姞淇濅汉鏁帮級");
+    public BigDecimal dealApplyChangeData(ApplyChange applyChange,InsuranceApply insuranceApply
+            ,CompanySolution companySolution,Solutions solutions,LoginUserInfo loginUserInfo,BigDecimal fee){
+        if(Constants.equalsInteger(applyChange.getType(),Constants.ZERO)){
+            if(Objects.nonNull(solutions.getDelOnlyReplace())&& solutions.getDelOnlyReplace().equals(Constants.ONE)){
+                if(applyChange.getDelDetailList().size() > applyChange.getAddDetailList().size()){
+                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "璇ヤ繚闄╂柟妗堜粎鏀寔鏇挎崲锛堝噺淇濅汉鏁颁笉寰楀ぇ浜庡姞淇濅汉鏁帮級");
+                }
             }
         }
         //鏌ヨ淇濋櫓鏂规涓嬬殑鎵�鏈夋淳閬e崟浣�
@@ -1069,7 +1293,9 @@
         ApplyChangeCyclePriceDTO applyChangeCyclePriceDTO = new ApplyChangeCyclePriceDTO();
         applyChangeCyclePriceDTO.setApplyId(insuranceApply.getId());
 
-        
+
+        //鍑忎繚鏁版嵁
+        List<ApplyChagneDetail> delDetailList = applyChange.getDelDetailList();
         //鍔犱繚鏁版嵁
         List<ApplyChagneDetail> addDetailList = applyChange.getAddDetailList();
 
@@ -1084,22 +1310,16 @@
                 throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"瀵逛笉璧凤紝浜哄憳褰曞叆鏁版嵁瀛樺湪鐩稿悓鏁版嵁锛�");
             }
 
-            //鍔犱繚鏄庣粏鏁版嵁 璁$畻閲戦  鏍规嵁鎵瑰崟鏃堕棿 璁$畻
-//            applyChangeCyclePriceDTO.setValidTime(DateUtil.getMontageDate(applyChange.getValidTime(),1));
-//            CountCyclePriceVO countCyclePriceVO =  this.getChangeCountCyclePriceVO(applyChangeCyclePriceDTO);
-//            BigDecimal detailFee = countCyclePriceVO.getCyclePrice();
             BigDecimal sumPrice = Objects.isNull(insuranceApply.getServerCost())?solutions.getPrice():solutions.getPrice().add(insuranceApply.getServerCost());
             BigDecimal detailFee = Constants.addFee(solutions,
                     sumPrice
                     ,insuranceApply.getStartTime(),insuranceApply.getFinalEndTime(),
                     applyChange.getApplyStartTime(),insuranceApply.getEndTime());
 
-            this.addChangeDetail(applyChange,addDetailList,duWorktypeList,duSolutionList,insuranceApply,solutions,loginUserInfo,detailFee);
+            this.addChangeDetail(applyChange,addDetailList,duWorktypeList,duSolutionList,insuranceApply,solutions,loginUserInfo,detailFee,delDetailList.size());
             fee = addDetailList.stream().map(ApplyChagneDetail::getFee).reduce(BigDecimal.ZERO,BigDecimal::add);
         }
 
-        //鍑忎繚鏁版嵁
-        List<ApplyChagneDetail> delDetailList = applyChange.getDelDetailList();
         if (CollectionUtils.isNotEmpty(delDetailList)) {
             //楠岃瘉鏄惁瀛樺湪閲嶅鏁版嵁
             List<String> idcarNo = delDetailList.stream().map(m->m.getIdcardNo()).collect(Collectors.toList());
@@ -1113,6 +1333,7 @@
             this.delChangeDetail(applyChange,delDetailList,insuranceApply,solutions,loginUserInfo, BigDecimal.ZERO,
                     DateUtil.getMontageDate(applyChange.getDelValidTime(),3));
             fee = fee.add(delDetailList.stream().map(ApplyChagneDetail::getFee).reduce(BigDecimal.ZERO,BigDecimal::add));
+//            fee = fee.add(delDetailList.stream().map(ApplyChagneDetail::getReduceMoney).reduce(BigDecimal.ZERO,BigDecimal::add));
         }
 
        
@@ -1206,6 +1427,9 @@
             if (applyChange.getValidTime().compareTo(applyDetail.getEndTime()) > 0) {
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍑忎繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戜繚鍗曚繚闅滄棩鏈熻嚦锛氥��" + applyDetail.getEndTime() + "銆戞棤娉曢�氳繃鏈鐢宠");
             }
+            if(!Constants.equalsInteger(applyDetail.getChangeStatus(),Constants.ZERO)){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鍑忎繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戜繚鍗曚俊鎭紓甯�,鏁版嵁宸茶鍑忎繚鏃犳硶鍐嶆鍑忎繚");
+            }
             applyChagneDetail.setPrice(applyDetail.getPrice());
             applyChagneDetail.setCreateDate(new Date());
             applyChagneDetail.setCreator(loginUserInfo.getId());
@@ -1258,14 +1482,20 @@
      */
     public void addChangeDetail(ApplyChange applyChange ,List<ApplyChagneDetail> addDetailList,
                                 List<DuWorktype> duWorktypeList,List<DuSolution> duSolutionList,
-                                InsuranceApply insuranceApply,Solutions solutions,LoginUserInfo loginUserInfo,BigDecimal detailFee){
-        for (ApplyChagneDetail applyChagneDetail : addDetailList) {
+                                InsuranceApply insuranceApply,Solutions solutions,LoginUserInfo loginUserInfo,BigDecimal detailFee,Integer delSize){
+        for (int i = 0; i < addDetailList.size(); i++) {
+            ApplyChagneDetail applyChagneDetail = addDetailList.get(i);
             if (    Objects.isNull(applyChagneDetail.getDuId())
                     || Objects.isNull(applyChagneDetail.getWorktypeId())
                     || StringUtils.isBlank(applyChagneDetail.getIdcardNo())
             ) {
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍔犱繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝繀濉」缂哄け");
             }
+            //鏌ヨ浜哄憳淇℃伅鏄惁瀛樺湪鐩稿悓鐨勬柟妗堜笅鏄惁瀛樺湪 鍐茬獊鏁版嵁
+            InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getId(),
+                    applyChagneDetail.getMemberIdcardNo(),applyChagneDetail.getMemberName(),insuranceApply.getStartTime(),insuranceApply.getEndTime(),
+                    applyDetailJoinMapper);
+
             //鏌ヨ鍔犱繚浜哄憳鏄惁瀛樺湪 鍐茬獊鐨� 淇濆崟鏄庣粏鏁版嵁
             if(applyDetailJoinMapper.selectCount(new QueryWrapper<ApplyDetail>()
                     .lambda()
@@ -1380,7 +1610,13 @@
                 throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(), "銆�" + applyChagneDetail.getMemberName() + "銆戝憳宸ュ伐绉嶄俊鎭湭鏌ヨ鍒帮紒");
             }
             applyChagneDetail.setMemberId(member.getId());
-            applyChagneDetail.setFee(detailFee);
+            //濡傛灉鏄噺淇濅笟鍔′负浠呮浛鎹� 涓� 鏂规鐨勬墸璐瑰懆鏈熷拰鎬诲懆鏈熺浉绛� 鍒欏鐞嗗噺淇濊垂鐢�
+            if(Constants.equalsInteger(solutions.getDelOnlyReplace(),Constants.ONE)
+                    && Constants.equalsInteger(solutions.getTimeUnit(),solutions.getInsureCycleUnit()) && delSize> i){
+                applyChagneDetail.setFee(BigDecimal.ZERO);
+            }else{
+                applyChagneDetail.setFee(detailFee);
+            }
             applyChagneDetailJoinMapper.insert(applyChagneDetail);
         }
     }

--
Gitblit v1.9.3