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/core/utils/DateUtil.java                             |    3 
 server/service/src/main/java/com/doumee/service/business/impl/ApplyChangeServiceImpl.java    |  286 ++++++++++++++++++++++++++--
 server/service/src/main/java/com/doumee/core/utils/Constants.java                            |   10 
 server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java |   84 ++++++++
 server/service/src/main/java/com/doumee/service/business/impl/UnionChangeServiceImpl.java    |  113 +++++++---
 server/service/src/main/java/com/doumee/dao/business/model/UnionApply.java                   |    4 
 server/company/src/main/java/com/doumee/api/business/ApplyChangeController.java              |    4 
 server/service/src/main/java/com/doumee/service/business/InsuranceApplyService.java          |    3 
 server/service/src/main/java/com/doumee/service/business/impl/UnionApplyServiceImpl.java     |   40 +++
 9 files changed, 470 insertions(+), 77 deletions(-)

diff --git a/server/company/src/main/java/com/doumee/api/business/ApplyChangeController.java b/server/company/src/main/java/com/doumee/api/business/ApplyChangeController.java
index 094e276..1d187d8 100644
--- a/server/company/src/main/java/com/doumee/api/business/ApplyChangeController.java
+++ b/server/company/src/main/java/com/doumee/api/business/ApplyChangeController.java
@@ -13,6 +13,7 @@
 import com.doumee.dao.business.model.ApplyChange;
 import com.doumee.dao.business.vo.CountCyclePriceVO;
 import com.doumee.service.business.ApplyChangeService;
+import com.doumee.service.business.InsuranceApplyService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.shiro.SecurityUtils;
@@ -37,6 +38,9 @@
     @Autowired
     private ApplyChangeService applyChangeService;
 
+    @Autowired
+    private InsuranceApplyService insuranceApplyService;
+
     @PreventRepeat
     @ApiOperation("鏂板缓")
     @PostMapping("/create")
diff --git a/server/service/src/main/java/com/doumee/core/utils/Constants.java b/server/service/src/main/java/com/doumee/core/utils/Constants.java
index 15a4398..bfa4a49 100644
--- a/server/service/src/main/java/com/doumee/core/utils/Constants.java
+++ b/server/service/src/main/java/com/doumee/core/utils/Constants.java
@@ -386,7 +386,7 @@
         if(StringUtils.isBlank(idCard)){
             return 2;
         }
-        Pattern pattern = Pattern.compile("\\d{17}[\\d|x]"); // 瀹氫箟韬唤璇佸彿鐮佹牸寮忕殑姝e垯琛ㄨ揪寮�
+        Pattern pattern = Pattern.compile("\\d{17}[\\d|x|X]"); // 瀹氫箟韬唤璇佸彿鐮佹牸寮忕殑姝e垯琛ㄨ揪寮�
         Matcher matcher = pattern.matcher(idCard);
         Integer sex = 0;
         if (matcher.matches()) {
@@ -401,6 +401,7 @@
         }
         return sex;
     }
+
 
     /**
      * 鐘舵�� 0宸蹭繚瀛樸��1寰呭鏍搞��2瀹℃牳閫氳繃銆�3閫�鍥炰慨鏀广��4瀹℃牳椹冲洖銆�5寰呮湇鍔℃満鏋勭‘璁ゃ��6鏈嶅姟鏈烘瀯鎷掔粷銆�7宸插垎閰嶆湇鍔℃満鏋勩��8璇婃柇涓�
@@ -759,9 +760,9 @@
     }
 
     public static void main(String[] args) {
-
-        System.out.println(IdcardUtil.isValidCard("340621199310134818"));
-        System.out.println(IdcardUtil.isValidCard("341621199310134818"));
+        System.out.println(Constants.getSexByIdCard("41052119910310001X"));
+//        System.out.println(IdcardUtil.isValidCard("340621199310134818"));
+//        System.out.println(IdcardUtil.isValidCard("341621199310134818"));
 
 //        System.out.println("{\"companyName\":\"搴斿疂绉戞妧\",\"endtime\":\"2024-03-01 17:19:00\",\"erpId\":\"4D40185D5BC74A13821BE46EAF8B4179\",\"erpWithVisitDTOList\":[],\"faceImg\":\"20240304/1709518170325_742.jpg\",\"idcardNo\":\"342501199609300535\",\"idcardType\":0,\"name\":\"榛勬檵\",\"phone\":\"17756328697\",\"reason\":\"鎺㈤櫓\",\"receptMemberId\":\"E7E514BD7DE3F27CE0530B630A0AEAE0\",\"starttime\":\"2024-03-01 13:18:00\"}");
     }
@@ -2379,4 +2380,5 @@
         }
     }
 
+
 }
diff --git a/server/service/src/main/java/com/doumee/core/utils/DateUtil.java b/server/service/src/main/java/com/doumee/core/utils/DateUtil.java
index 57536d2..20fe9a5 100644
--- a/server/service/src/main/java/com/doumee/core/utils/DateUtil.java
+++ b/server/service/src/main/java/com/doumee/core/utils/DateUtil.java
@@ -3150,7 +3150,8 @@
     }
 
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Exception{
+        System.out.println(DateUtil.getPlusTime(new Date()));;
     }
 
     /**
diff --git a/server/service/src/main/java/com/doumee/dao/business/model/UnionApply.java b/server/service/src/main/java/com/doumee/dao/business/model/UnionApply.java
index 80ad3ac..9905811 100644
--- a/server/service/src/main/java/com/doumee/dao/business/model/UnionApply.java
+++ b/server/service/src/main/java/com/doumee/dao/business/model/UnionApply.java
@@ -132,6 +132,10 @@
     @TableField(exist = false)
     private Integer serviceDays;
 
+    @ApiModelProperty(value = "鍙煡璇㈠緟澶勭悊鐨勭敵璇峰崟锛�1=鍔犲噺淇濓紱2=鎹㈠巶")
+    @TableField(exist = false)
+    private Integer hasApplying;
+
     @ApiModelProperty(value = "鎶曚繚浜烘暟")
     @TableField(exist = false)
     private Integer insureNum;
diff --git a/server/service/src/main/java/com/doumee/service/business/InsuranceApplyService.java b/server/service/src/main/java/com/doumee/service/business/InsuranceApplyService.java
index 9ccbdde..b76cb10 100644
--- a/server/service/src/main/java/com/doumee/service/business/InsuranceApplyService.java
+++ b/server/service/src/main/java/com/doumee/service/business/InsuranceApplyService.java
@@ -7,9 +7,11 @@
 import com.doumee.dao.business.dto.InsuranceApplyQueryDTO;
 import com.doumee.dao.business.dto.SmsCheckDTO;
 import com.doumee.dao.business.model.InsuranceApply;
+import com.doumee.dao.business.model.Member;
 import com.doumee.dao.business.vo.CountCyclePriceVO;
 import com.jzq.common.bean.sign.NotifyDataReq;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -27,6 +29,7 @@
      */
     Integer create(InsuranceApply insuranceApply);
     Integer updateData(InsuranceApply insuranceApply);
+    void checkMemberSolution(Integer solutionId,String idCode,String memberName,Date startTime,Date endTime);
 
     /**
      * 涓婚敭鍒犻櫎
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);
         }
     }
diff --git a/server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java
index d72bf05..ddcd07f 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java
@@ -308,6 +308,10 @@
         if(CollectionUtils.isNotEmpty(applyDetailList)){
             List<MemberInsurance> memberInsuranceList = new ArrayList<>();
             for (ApplyDetail applyDetail:applyDetailList) {
+
+                //鏌ヨ浜哄憳淇℃伅鏄惁瀛樺湪鐩稿悓鐨勬柟妗堜笅鏄惁瀛樺湪 鍐茬獊鏁版嵁
+                this.checkMemberSolution(applyDetail.getSolutionId(),applyDetail.getIdcardNo(),applyDetail.getMemberName(),update.getStartTime(),update.getEndTime());
+
                 MemberInsurance memberInsurance = new MemberInsurance(applyDetail,user.getId());
                 memberInsurance.setRelationType(Constants.ZERO);
                 memberInsuranceList.add(memberInsurance);
@@ -1944,6 +1948,8 @@
                     member.setWorktypeId(applyDetail.getWorktypeId());
                     addMemberList.add(member);
                 }
+                //鏌ヨ浜哄憳淇℃伅鏄惁瀛樺湪鐩稿悓鐨勬柟妗堜笅鏄惁瀛樺湪 鍐茬獊鏁版嵁
+                this.checkMemberSolution(solutions.getId(),member.getIdcardNo(),member.getName(),insuranceApply.getStartTime(),insuranceApply.getEndTime());
             }
             if(CollectionUtils.isNotEmpty(addMemberList)){
                 memberJoinMapper.insertBatchSomeColumn(addMemberList);
@@ -1959,6 +1965,7 @@
                 ){
                     throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝鎶曚繚鍛樺伐淇℃伅鏁版嵁缂哄け锛岃鎸夌収瑕佹眰濉啓鍛樺伐鐨勬湁鏁堜俊鎭紒");
                 }
+                applyDetail.setChangeStatus(Constants.ZERO);
                 applyDetail.setCreateDate(new Date());
                 applyDetail.setCreator(loginUserInfo.getId());
                 applyDetail.setIsdeleted(Constants.ZERO);
@@ -2029,6 +2036,75 @@
         }
     }
 
+
+    /**
+     * 鏌ヨ 浼氬憳淇℃伅鍦ㄦ柟妗堜笅鏄惁瀛樺湪鍐茬獊鏁版嵁
+     * @param solutionId
+     * @param startTime
+     * @param endTime
+     */
+    @Override
+    public void checkMemberSolution(Integer solutionId,String idCode,String memberName,Date startTime,Date endTime){
+        try {
+            List<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectJoinList(ApplyDetail.class,
+                    new MPJLambdaWrapper<ApplyDetail>()
+                            .selectAll(ApplyDetail.class)
+                            .selectAs(InsuranceApply::getCode,ApplyDetail::getApplyCode)
+                            .leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyDetail::getApplyId)
+                            .eq(ApplyDetail::getIdcardNo,idCode)
+                            .eq(InsuranceApply::getSolutionId,solutionId)
+                            .notIn(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD
+                                    ,Constants.InsuranceApplyStatus.PLATFORM_RETURN
+                                    ,Constants.InsuranceApplyStatus.FAIL_RETURN
+                                    ,Constants.InsuranceApplyStatus.CLOSE
+                                    ,Constants.InsuranceApplyStatus.WTB_RETURN
+                                    ,Constants.InsuranceApplyStatus.WTB_CLOSED )
+                            .apply(" ( " +
+                                    " '"+DateUtil.getPlusTime(startTime)+"'  <= t.start_time AND t.start_time < '"+DateUtil.getPlusTime(endTime)+"' " +
+                                    " or " +
+                                    "  ( '"+DateUtil.getPlusTime(startTime)+"' < t.end_time AND t.end_time < '"+DateUtil.getPlusTime(endTime)+"' )  " +
+                                    " or " +
+                                    " ( '"+DateUtil.getPlusTime(startTime)+"' > t.start_time AND '"+DateUtil.getPlusTime(endTime)+"' < t.end_time )" +
+                                    " ) " ));
+            if(applyDetailList.size() >Constants.ZERO){
+                ApplyDetail applyDetail = applyDetailList.get(Constants.ZERO);
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ敤鎴枫��"+memberName+" "+idCode+"銆戝湪淇濆崟銆�"+applyDetail.getApplyCode()+"銆戜笅宸插瓨鍦ㄤ笌鏈鎻愭姤鍐茬獊鐨勬棩鏈�");
+            };
+        }catch (Exception e){
+
+        }
+    }
+
+    public static void checkStaticMemberSolution(Integer solutionId,String idCode,String memberName,Date startTime,Date endTime,ApplyDetailJoinMapper applyDetailJoinMapper){
+        try {
+            List<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectJoinList(ApplyDetail.class,
+                    new MPJLambdaWrapper<ApplyDetail>()
+                            .selectAll(ApplyDetail.class)
+                            .selectAs(InsuranceApply::getCode,ApplyDetail::getApplyCode)
+                            .leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyDetail::getApplyId)
+                            .eq(ApplyDetail::getIdcardNo,idCode)
+                            .eq(InsuranceApply::getSolutionId,solutionId)
+                            .notIn(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD
+                                    ,Constants.InsuranceApplyStatus.PLATFORM_RETURN
+                                    ,Constants.InsuranceApplyStatus.FAIL_RETURN
+                                    ,Constants.InsuranceApplyStatus.CLOSE
+                                    ,Constants.InsuranceApplyStatus.WTB_RETURN
+                                    ,Constants.InsuranceApplyStatus.WTB_CLOSED )
+                            .apply(" ( " +
+                                    " '"+DateUtil.getPlusTime(startTime)+"'  <= t.start_time AND t.start_time < '"+DateUtil.getPlusTime(endTime)+"' " +
+                                    " or " +
+                                    "  ( '"+DateUtil.getPlusTime(startTime)+"' < t.end_time AND t.end_time < '"+DateUtil.getPlusTime(endTime)+"' )  " +
+                                    " or " +
+                                    " ( '"+DateUtil.getPlusTime(startTime)+"' > t.start_time AND '"+DateUtil.getPlusTime(endTime)+"' < t.end_time )" +
+                                    " ) " ));
+            if(applyDetailList.size() >Constants.ZERO){
+                ApplyDetail applyDetail = applyDetailList.get(Constants.ZERO);
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ敤鎴枫��"+memberName+" "+idCode+"銆戝湪淇濆崟銆�"+applyDetail.getApplyCode()+"銆戜笅宸插瓨鍦ㄤ笌鏈鎻愭姤鍐茬獊鐨勬棩鏈�");
+            };
+        }catch (Exception e){
+
+        }
+    }
 
     @Override
     public void deleteById(Integer id) {
@@ -2124,7 +2200,7 @@
         queryWrapper.selectAs(Solutions::getTimeUnit,InsuranceApply::getTimeUnit);
         queryWrapper.select(" DATEDIFF( t.END_TIME ,now()  ) AS loseEfficacyDays  ");
         queryWrapper.select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.apply_id = t.id   ) as insureNum");
-        queryWrapper.select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.apply_id = t.id and ad.END_TIME > now() ) as guaranteeNum");
+        queryWrapper.select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad inner join insurance_apply a on ad.apply_id = a.id  and a.status in ( 5 , 27 )  where ad.apply_id = t.id and ad.END_TIME > now() ) as guaranteeNum");
         if(!Objects.isNull(pageWrap.getModel())&&!Objects.isNull(pageWrap.getModel().getType())){
             queryWrapper.select(" ifnull(( select sum(td.fee) from taxes ts inner join tax_detial td on td.TAX_ID = ts.id  where ts.status != 2 and td.INSURANCE_APPLY_ID = t.id ),0) as taxesMoney");
             queryWrapper.select(" ( select td.CREATE_DATE from taxes ts inner join tax_detial td on td.TAX_ID = ts.id  where ts.status = 1 and td.INSURANCE_APPLY_ID = t.id order by td.CREATE_DATE desc limit 1 ) as taxesLast ");
@@ -2251,6 +2327,7 @@
         queryWrapper.selectAs(Solutions::getName,InsuranceApply::getSolutionsName);
         queryWrapper.selectAs(Solutions::getType,InsuranceApply::getSolutionType);
         queryWrapper.select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.apply_id = t.id ) as insureNum");
+        queryWrapper.select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad inner join insurance_apply a on ad.apply_id = a.id  and a.status in ( 5 , 27 )  where ad.apply_id = t.id and ad.END_TIME > now() ) as guaranteeNum");
         queryWrapper.select(" ( select max(ac.APPLY_START_TIME) from apply_change ac  where ac.apply_id = t.id and ac.status = 2 ) as lastChangeDate");
         queryWrapper.select(" ( select sum(td.fee) from taxes ts inner join tax_detial td on td.TAX_ID = ts.id  where ts.status != 2 and td.INSURANCE_APPLY_ID = t.id ) as taxesMoney ");
         queryWrapper.select(" ( select td.CREATE_DATE from taxes ts inner join tax_detial td on td.TAX_ID = ts.id  where ts.status != 2 and td.INSURANCE_APPLY_ID = t.id order by td.CREATE_DATE desc limit 1 ) as taxesLast ");
@@ -2396,7 +2473,7 @@
                 .selectAs(Company::getName,InsuranceApply::getCompanyName)
                 .select(" ( select max(ac.APPLY_START_TIME) from apply_change ac  where ac.apply_id = t.id and ac.status = 2 ) as lastChangeDate")
                 .select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.apply_id = t.id ) as insureNum")
-                .select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.apply_id = t.id and ad.END_TIME > now() ) as guaranteeNum")
+                .select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad inner join insurance_apply a on ad.apply_id = a.id  and a.status in ( 5 , 27 )  where ad.apply_id = t.id and ad.END_TIME > now() ) as guaranteeNum")
                 .select(" t3.name as shopName")
                 .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                 .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
@@ -2520,7 +2597,7 @@
                 .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                 .selectAs(Solutions::getType,InsuranceApply::getSolutionType)
                 .selectAs(Company::getName,InsuranceApply::getCompanyName)
-                .select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.apply_id = t.id and ad.END_TIME > now() ) as guaranteeNum")
+                .select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad inner join insurance_apply a on ad.apply_id = a.id  and a.status in ( 5 , 27 )  where ad.apply_id = t.id and ad.END_TIME > now() ) as guaranteeNum")
                 .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                 .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                 .eq(InsuranceApply::getId,model.getId())
@@ -2713,6 +2790,7 @@
                 BigDecimal sumAmount = BigDecimal.ZERO;
                 List<ApplyDetail> applyDetailList = applyDetailMapper
                         .selectList(new QueryWrapper<ApplyDetail>().lambda()
+                                .eq(ApplyDetail::getChangeStatus,Constants.ZERO)
                                 .eq(ApplyDetail::getApplyId,insuranceApply.getId()));
                 if(CollectionUtils.isNotEmpty(applyDetailList)){
                     for (ApplyDetail applyDetail: applyDetailList) {
diff --git a/server/service/src/main/java/com/doumee/service/business/impl/UnionApplyServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/UnionApplyServiceImpl.java
index d702a41..ce57608 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/UnionApplyServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/UnionApplyServiceImpl.java
@@ -157,11 +157,13 @@
                 .selectAs(Solutions::getSpecialAgreement,UnionApply::getSpecialAgreement)
                 .selectAs(Solutions::getSpecialInfo,UnionApply::getSpecialInfo);
         queryWrapper.select("(select count(distinct(b.MEMBER_ID)) from apply_detail b where b.isdeleted=0 and b.union_apply_id=t.id) as insureNum ");
-        queryWrapper.select("(select count(distinct(b.MEMBER_ID)) from apply_detail b where b.isdeleted=0   and b.END_TIME > now() and b.union_apply_id=t.id) as guaranteeNum ");
+        queryWrapper.select(" ( select count(DISTINCT(b.MEMBER_ID)) from apply_detail b inner join insurance_apply a on b.apply_id = a.id  and a.status in ( 5 , 27 )  where b.union_apply_id=t.id and b.END_TIME > now() ) as guaranteeNum");
 
         if(pageWrap.getModel().getQueryFlag() == 1){
             queryWrapper.select("(select count(1) from apply_change a inner join insurance_apply b on a.apply_id = b.id  where b.union_apply_id=t.id " +
                     "and a.status = "+Constants.ApplyChangeStatus.CHECHED_PASSED.getKey()+" and a.type = 0  ) as addApplyNum ");
+
+
         }else  if(pageWrap.getModel().getQueryFlag() ==2){
             queryWrapper.select("(select count(1) from apply_change a inner join insurance_apply b on a.apply_id = b.id  where b.union_apply_id=t.id " +
                     "and a.status = "+Constants.ApplyChangeStatus.CHECHED_PASSED.getKey()+" and a.type = 1  ) as changeApplyNum ");
@@ -177,11 +179,26 @@
         if(Constants.equalsInteger(user.getType(),Constants.TWO)){
             queryWrapper.eq(UnionApply::getCompanyId, user.getCompanyId());
         }
+
         if (pageWrap.getModel().getId() != null) {
             queryWrapper.eq(UnionApply::getId, pageWrap.getModel().getId());
         }
         if (pageWrap.getModel().getSolutionId() != null) {
             queryWrapper.eq(UnionApply::getSolutionId, pageWrap.getModel().getSolutionId());
+        }
+        if (pageWrap.getModel().getHasApplying() != null) {
+            if(Constants.equalsInteger(pageWrap.getModel().getHasApplying() ,Constants.ONE)){
+                queryWrapper.exists(
+                        " ( select 1  from apply_change a inner join insurance_apply b on a.apply_id = b.id  where b.union_apply_id= t.id " +
+                                "        and a.status = "+Constants.ApplyChangeStatus.CHECHED_PASSED.getKey()+" and a.type = 0  ) "
+                );
+            }else if(Constants.equalsInteger(pageWrap.getModel().getHasApplying() ,Constants.TWO)){
+                queryWrapper.exists(
+                        " ( select 1  from apply_change a inner join insurance_apply b on a.apply_id = b.id  where b.union_apply_id= t.id " +
+                                "        and a.status = "+Constants.ApplyChangeStatus.CHECHED_PASSED.getKey()+" and a.type = 1   ) "
+                );
+            }
+
         }
         if (pageWrap.getModel().getCreator() != null) {
             queryWrapper.eq(UnionApply::getCreator, pageWrap.getModel().getCreator());
@@ -318,7 +335,7 @@
                         .selectAs(Solutions::getName,UnionApply::getSolutionName)
                         .selectAs(Company::getName,UnionApply::getCompanyName)
                         .select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.UNION_APPLY_ID = t.id ) as insureNum")
-                        .select("(select count(distinct(b.MEMBER_ID)) from apply_detail b where b.isdeleted=0   and b.END_TIME > now() and b.union_apply_id=t.id) as guaranteeNum ")
+                .select(" ( select count(DISTINCT(b.MEMBER_ID)) from apply_detail b inner join insurance_apply a on b.apply_id = a.id  and a.status in ( 5 , 27 )  where b.union_apply_id=t.id and b.END_TIME > now() ) as guaranteeNum")
                         .select(" ( select group_concat(DISTINCT(cd.name)) from insurance_apply ad left join company cd on ad.company_id = cd.id where ad.UNION_APPLY_ID = t.id ) as companyNames")
                         .leftJoin(Solutions.class,Solutions::getId,UnionApply::getSolutionId)
                         .leftJoin(Company.class,Company::getId,UnionApply::getCompanyId)
@@ -460,8 +477,11 @@
 
         Integer maxDays = DateUtil.calculateBetween(saveUnionApplyDTO.getStartDate(),saveUnionApplyDTO.getEndDate(),0);
 
-        List<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectList(new QueryWrapper<ApplyDetail>().lambda()
+        List<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectJoinList(ApplyDetail.class,new MPJLambdaWrapper<ApplyDetail>()
                 .select(ApplyDetail::getId,ApplyDetail::getPrice,ApplyDetail::getStartTime,ApplyDetail::getEndTime,ApplyDetail::getFee)
+                .selectAs(Member::getIdcardNo,ApplyDetail::getIdcardNo)
+                .selectAs(Member::getName,ApplyDetail::getMemberName)
+                .leftJoin(Member.class,Member::getId,ApplyDetail::getMemberId)
                 .in(ApplyDetail::getApplyId,saveUnionApplyDTO.getApplyIds())
                 .eq(ApplyDetail::getIsdeleted,Constants.ZERO));
         if(applyDetailList.size()==0){
@@ -469,14 +489,16 @@
         }
         BigDecimal fee = BigDecimal.ZERO;
         for (ApplyDetail applyDetail:applyDetailList) {
+            //鏌ヨ浜哄憳淇℃伅鏄惁瀛樺湪鐩稿悓鐨勬柟妗堜笅鏄惁瀛樺湪 鍐茬獊鏁版嵁
+            InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getId(),
+                    applyDetail.getIdcardNo(),applyDetail.getMemberName(),unionApply.getStartTime(),unionApply.getEndTime(),
+                    applyDetailJoinMapper);
+
             fee =fee.add(
                     Constants.reduceFee(solutions,solutions.getPrice(),applyDetail.getStartTime(),applyDetail.getEndTime(),saveUnionApplyDTO.getStartDate(),saveUnionApplyDTO.getEndDate())
             );
         }
         unionApply.setFee(fee);
-
-//        unionApply.setFee(applyDetailList.stream()
-//                .map(i->Constants.formatBigdecimal(i.getPrice()).multiply(new BigDecimal(maxDays))).reduce(BigDecimal.ZERO,BigDecimal::add));
 
         unionApplyMapper.insert(unionApply);
 
@@ -856,6 +878,12 @@
                 List<MemberInsurance> memberInsuranceList = new ArrayList<>();
                 for (ApplyDetail applyDetail:applyDetailList.stream()
                         .filter(m->Constants.equalsInteger(m.getApplyId(),(insuranceApply.getId()))).collect(Collectors.toList())) {
+
+                    //鏌ヨ浜哄憳淇℃伅鏄惁瀛樺湪鐩稿悓鐨勬柟妗堜笅鏄惁瀛樺湪 鍐茬獊鏁版嵁
+                    InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getId(),
+                            applyDetail.getIdcardNo(),applyDetail.getMemberName(),unionApply.getStartTime(),unionApply.getEndTime(),
+                            applyDetailJoinMapper);
+
                     applyDetail.setPrice(price);
                     applyDetail.setFee(price.multiply(new BigDecimal(maxDays)).add(serverCost));
                     applyDetail.setStartTime(unionApplyBXDDTO.getStartTime());
diff --git a/server/service/src/main/java/com/doumee/service/business/impl/UnionChangeServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/UnionChangeServiceImpl.java
index ef47549..84d727f 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/UnionChangeServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/UnionChangeServiceImpl.java
@@ -176,6 +176,7 @@
                             .ne(ApplyChagneDetail::getType,Constants.TWO)
                             .eq(ApplyChagneDetail::getUnionChangeId,unionChange.getId()));
             BigDecimal fee = applyChangeList.stream().map(m->m.getFee()).reduce(BigDecimal.ZERO,BigDecimal::add);
+//            fee = fee.add(applyChangeList.stream().map(m->Objects.nonNull(m.getReduceMoney())?m.getReduceMoney():BigDecimal.ZERO).reduce(BigDecimal.ZERO,BigDecimal::add));
 //            for (ApplyChagneDetail applyChagneDetail:applyChangeList) {
 //                Integer maxDays = DateUtil.calculateBetween(unionChange.getApplyStartTime(),applyChagneDetail.getEndTime(),0);
 //                if(applyChagneDetail.getType().equals(Constants.ONE)){
@@ -796,7 +797,6 @@
                                 .eq(ApplyChagneDetail::getApplyChangeId,applyChange.getId()));
                 this.dealApplyChangeDetail(applyChange,allList,solutions);
                 applyChangeJoinMapper.updateById(applyChange);
-
                 //瀛樺偍鎵瑰崟瀹屾垚淇℃伅
                 Constants.ApplyLogType applyLogType = Constants.ApplyLogType.CA_PLATFORM_APPROVE;
                 String info = "";
@@ -827,9 +827,9 @@
                 ,unionChange.getId(),applyLogType.getKey(),null, JSONObject.toJSONString(unionChange));
         applyLogMapper.insert(log);
 
-//        if(true){
-//            throw new BusinessException(ResponseStatus.NOT_ALLOWED);
-//        }
+        if(true){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED);
+        }
     }
 
 
@@ -841,19 +841,36 @@
         bigDecimalVO.setTotalFee(BigDecimal.ZERO);
         bigDecimalVO.setCurrentFee(BigDecimal.ZERO);
         InsuranceApply insuranceApply = insuranceApplyMapper.selectById(applyChange.getApplyId());
-        for (ApplyChagneDetail detail:applyChagneDetailList) {
+
+
+        List<ApplyChagneDetail> addList = applyChagneDetailList.stream().filter(f->Constants.equalsInteger(f.getType(),Constants.ZERO)).collect(Collectors.toList());
+        List<ApplyChagneDetail> reduceList = applyChagneDetailList.stream().filter(f->Constants.equalsInteger(f.getType(),Constants.ONE)).collect(Collectors.toList());
+        List<ApplyChagneDetail> changeList = applyChagneDetailList.stream().filter(f->Constants.equalsInteger(f.getType(),Constants.TWO)).collect(Collectors.toList());
+        for (ApplyChagneDetail detail:reduceList) {
             Member member = memberMapper.selectById(detail.getMemberId());
             if(Objects.isNull(member)){
                 throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鍛樺伐鏁版嵁");
             }
-            if (Constants.equalsInteger(detail.getType(), Constants.ZERO)) {
-               this.addChangeDetailData(applyChange,detail,insuranceApply,solutions,bigDecimalVO);
-            }else if(Constants.equalsInteger(detail.getType(),Constants.ONE)){
-                this.reduceChangeDetailData(applyChange,detail,insuranceApply,solutions,bigDecimalVO);
-            }else{
-                this.otherChangeDetailData(applyChange,detail,insuranceApply);
-            }
+            this.reduceChangeDetailData(applyChange,detail,insuranceApply,solutions,bigDecimalVO);
         }
+
+        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(),"鏈煡璇㈠埌鍛樺伐鏁版嵁");
+            }
+            this.addChangeDetailData(applyChange,detail,insuranceApply,solutions,bigDecimalVO,reduceList,i);
+        }
+
+        for (ApplyChagneDetail detail:changeList) {
+            Member member = memberMapper.selectById(detail.getMemberId());
+            if(Objects.isNull(member)){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鍛樺伐鏁版嵁");
+            }
+            this.otherChangeDetailData(applyChange,detail,insuranceApply);
+        }
+
         //濡傛灉淇濆崟閲戦鍙戠敓缂栫爜锛屾洿鏂版�讳繚鍗曢噾棰�
         insuranceApplyMapper.update(null, new UpdateWrapper<InsuranceApply>().lambda()
                 .setSql(bigDecimalVO.getTotalFee().compareTo(new BigDecimal(0)) != 0," fee = ifnull(fee,0)+" + bigDecimalVO.getTotalFee())
@@ -872,17 +889,12 @@
      * @param detail
      */
     public void addChangeDetailData(ApplyChange applyChange, ApplyChagneDetail detail,InsuranceApply insuranceApply,Solutions solutions
-            , BigDecimalVO bigDecimalVO){
-        //鏌ヨ鍔犱繚浜哄憳鏄惁瀛樺湪 鍐茬獊鐨� 淇濆崟鏄庣粏鏁版嵁
-        if(applyDetailJoinMapper.selectCount(new QueryWrapper<ApplyDetail>()
-                .lambda()
-                .eq(ApplyDetail::getApplyId,applyChange.getApplyId())
-                .eq(ApplyDetail::getIdcardNo,detail.getIdcardNo())
-                .le(ApplyDetail::getStartTime,DateUtil.getMontageDate(applyChange.getApplyStartTime(),1))
-                .ge(ApplyDetail::getEndTime,DateUtil.getMontageDate(detail.getEndTime(),2))
-        )>Constants.ZERO){
-            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "褰撳墠淇濆崟涓嬶紝鍔犱繚浜哄憳銆�" + detail.getMemberName() + "銆戝瓨鍦ㄦ棩鏈熷啿绐佺殑鏁版嵁");
-        }
+            , BigDecimalVO bigDecimalVO,List<ApplyChagneDetail> reduceList,Integer i){
+        //鏌ヨ浜哄憳淇℃伅鏄惁瀛樺湪鐩稿悓鐨勬柟妗堜笅鏄惁瀛樺湪 鍐茬獊鏁版嵁
+        InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getId(),
+                detail.getIdcardNo(),detail.getMemberName(),DateUtil.getMontageDate(applyChange.getApplyStartTime(),1),DateUtil.getMontageDate(detail.getEndTime(),2),
+                applyDetailJoinMapper);
+
         //鍔犱繚
         ApplyDetail add = new ApplyDetail();
         BigDecimal fee = Objects.isNull(insuranceApply.getServerCost())?
@@ -916,17 +928,23 @@
         add.setEndTime(DateUtil.getMontageDate(detail.getEndTime(), 2));
         add.setRemark(detail.getRemark());
         add.setUnionApplyId(insuranceApply.getUnionApplyId());
+        add.setChangeStatus(Constants.ZERO);
+        if(Constants.equalsInteger(solutions.getDelOnlyReplace(),Constants.ONE)
+                && Constants.equalsInteger(solutions.getTimeUnit(),solutions.getInsureCycleUnit())  && i < reduceList.size() ){
+            add.setReduceId(reduceList.get(i).getApplyDetailId());
+        }
         applyDetailJoinMapper.insert(add);
-
-        detail.setFee(add.getFee());
+        detail.setFee(Objects.isNull(add.getReduceId())?add.getFee():BigDecimal.ZERO);
+        bigDecimalVO.setTotalFee(bigDecimalVO.getTotalFee().add(add.getFee()));
+        //濡傛灉涓嶆槸鏇挎崲涓氬姟鐨勫姞淇濇暟鎹� 鍒欐坊鍔犲疄闄呬骇鐢熻垂鐢�
+        if(Objects.isNull(add.getReduceId())){
+            bigDecimalVO.setCurrentFee(bigDecimalVO.getCurrentFee().add(add.getCurrentFee()));
+        }
         applyChagneDetailJoinMapper.update(null,new UpdateWrapper<ApplyChagneDetail>().lambda()
-                .set(ApplyChagneDetail::getFee,add.getFee())
+                .set(ApplyChagneDetail::getFee,detail.getFee())
                 .set(ApplyChagneDetail::getStartTime,DateUtil.getMontageDate(applyChange.getApplyStartTime(), 1))
                 .eq(ApplyChagneDetail::getId,detail.getId())
         );
-        bigDecimalVO.setTotalFee(bigDecimalVO.getTotalFee().add(add.getFee()));
-        bigDecimalVO.setCurrentFee(bigDecimalVO.getCurrentFee().add(add.getCurrentFee()));
-
         MemberInsurance memberInsurance = new MemberInsurance(detail, applyChange, applyChange.getEditor(), add.getId(),applyChange.getSolutionsId());
         memberInsurance.setStartTime(add.getStartTime());
         memberInsurance.setEndTime(add.getEndTime());
@@ -985,19 +1003,37 @@
                 pullFee = reduceFee;
             }
         }
-
-        bigDecimalVO.setTotalFee(bigDecimalVO.getTotalFee().add(reduceFee).subtract(oldModel.getFee()));
-        bigDecimalVO.setCurrentFee(bigDecimalVO.getCurrentFee().add(pullFee).subtract(oldModel.getCurrentFee()));
-
-        applyDetailJoinMapper.update(null, new UpdateWrapper<ApplyDetail>().lambda()
-                .setSql(" fee =  " + reduceFee)
-                .setSql(" current_fee =  " + pullFee)
+        UpdateWrapper<ApplyDetail> updateWrapper = new UpdateWrapper<ApplyDetail>();
+        updateWrapper.lambda()
+                .setSql(" fee = " + reduceFee)
+                .setSql(" current_fee = " + pullFee)
                 .set(ApplyDetail::getEndTime, reduceDate)
                 .set(ApplyDetail::getEditor, applyChange.getEditor())
                 .set(ApplyDetail::getEditDate, applyChange.getEditDate())
-                .eq(ApplyDetail::getId, oldModel.getId())
-        );
+                .eq(ApplyDetail::getId, oldModel.getId());
+        BigDecimal reduceMoney = BigDecimal.ZERO;
+        if(Constants.equalsInteger(solutions.getDelOnlyReplace(),Constants.ONE)
+                && Constants.equalsInteger(solutions.getTimeUnit(),solutions.getInsureCycleUnit())){
+            if(reduceDate.getTime()<=oldModel.getStartTime().getTime()){
+                reduceFee  = BigDecimal.ZERO;
+                updateWrapper.lambda().set(ApplyDetail::getFee,reduceFee)
+                        .set(ApplyDetail::getChangeStatus,Constants.TWO);
+            }else{
+                reduceMoney = solutions.getPrice().multiply(new BigDecimal(-1));
+                //鏍囪鏁版嵁宸茶鏇挎崲
+                updateWrapper.lambda().set(ApplyDetail::getReduceMoney,reduceMoney)
+                        .set(ApplyDetail::getChangeStatus,Constants.ONE);
+            }
+            detail.setApplyDetailId(oldModel.getId());
+        }
+        bigDecimalVO.setTotalFee(bigDecimalVO.getTotalFee().add(reduceFee).subtract(oldModel.getFee()).add(reduceMoney));
+        bigDecimalVO.setCurrentFee(bigDecimalVO.getCurrentFee().add(pullFee).subtract(oldModel.getCurrentFee()));
+//        //濡傛灉鍑忎繚鐨勬暟鎹� 宸茬粡缁撴潫 鍒欐鏁版嵁瑕佸幓鎺� 鍑忛櫎鐨勫疄闄呭樊鍊� reduceMoney
+//        if(System.currentTimeMillis()>detail.getEndTime().getTime()){
+//            bigDecimalVO.setCurrentFee(bigDecimalVO.getCurrentFee().add(reduceMoney));
+//        }
 
+        applyDetailJoinMapper.update(null, updateWrapper);
         //淇敼 鍛樺伐鎶曚繚鏄庣粏璁板綍 鍘嗗彶鏁版嵁
         memberInsuranceJoinMapper.update(null, new UpdateWrapper<MemberInsurance>().lambda()
                 .setSql(" fee = " + reduceFee)
@@ -1021,6 +1057,7 @@
                 .set(ApplyChagneDetail::getEndTime,reduceDate)
                 .eq(ApplyChagneDetail::getId,detail.getId())
         );
+        detail.setApplyDetailId(oldModel.getId());
     }
 
     public void otherChangeDetailData(ApplyChange applyChange,ApplyChagneDetail detail,InsuranceApply insuranceApply){

--
Gitblit v1.9.3