From 50fb58286ed3b718c39a97e0987ee7561a295651 Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期五, 04 七月 2025 17:56:41 +0800
Subject: [PATCH] git ch

---
 server/service/src/main/java/com/doumee/service/business/impl/ApplyChangeServiceImpl.java |  372 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 303 insertions(+), 69 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 e7fa383..7372c36 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
@@ -2,7 +2,10 @@
 
 import cn.hutool.core.util.IdcardUtil;
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.extension.api.R;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+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.biz.system.SystemDictDataBiz;
 import com.doumee.core.annotation.excel.ExcelExporter;
 import com.doumee.core.constants.ResponseStatus;
@@ -14,37 +17,31 @@
 import com.doumee.core.utils.DateUtil;
 import com.doumee.core.utils.Utils;
 import com.doumee.dao.business.*;
-import com.doumee.dao.business.dto.*;
+import com.doumee.dao.business.dto.ApplyChangeCyclePriceDTO;
+import com.doumee.dao.business.dto.ApplyChangeOptDTO;
+import com.doumee.dao.business.dto.SaveUnionChangeDTO;
+import com.doumee.dao.business.dto.SmsCheckDTO;
 import com.doumee.dao.business.join.*;
 import com.doumee.dao.business.model.*;
-import com.doumee.dao.business.vo.ChangeDealTypeVO;
 import com.doumee.dao.business.vo.CountCyclePriceVO;
 import com.doumee.dao.system.model.SystemUser;
 import com.doumee.service.business.ApplyChangeService;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
-import java.util.*;
 import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -263,7 +260,7 @@
             pidanFile.setObjType(Constants.MultiFile.CA_PD_PDF.getKey());
             pidanFile.setType(Constants.TWO);
         }
-        multifileMapper.insertBatchSomeColumn(pidanFileList);
+        multifileMapper.insert(pidanFileList);
         update.setApplyId(model.getApplyId());
 
 
@@ -363,7 +360,7 @@
             pidanFile.setObjType(Constants.MultiFile.CA_PD_PDF.getKey());
             pidanFile.setType(Constants.TWO);
         }
-        multifileMapper.insertBatchSomeColumn(param.getPidanFileList());
+        multifileMapper.insert(param.getPidanFileList());
 
 //        param.getPidanFile().setIsdeleted(Constants.ZERO);
 //        param.getPidanFile().setObjId(update.getId());
@@ -616,11 +613,14 @@
                     .eq(ApplyDetail::getMemberId, detail.getMemberId())
                     .orderByDesc(ApplyDetail::getCreateDate)
                     .last("limit 1"));
-            if (oldModel == null || oldModel.getStartTime() == null || oldModel.getStartTime().getTime() > update.getApplyStartTime().getTime()) {
+//            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() + "銆戝噺淇濇棩鏈熸湭鍦ㄤ繚鍗曡褰曟棩鏈熶腑锛�");
+//            }
+            if (oldModel == null || oldModel.getEndTime() == null || oldModel.getEndTime().getTime() < update.getDelValidTime().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() + "銆戝噺淇濇棩鏈熸湭鍦ㄤ繚鍗曡褰曟棩鏈熶腑锛�");
             }
             BigDecimal sumFee = Objects.isNull(insuranceApply.getServerCost())?
                     solutions.getPrice():
@@ -640,6 +640,9 @@
                         sumFee
                         ,insuranceApply.getStartTime(),insuranceApply.getFinalEndTime(),oldModel.getStartTime(),delValidTime
                 ) ;
+            }else{
+                delValidTime  = oldModel.getStartTime();
+                updateFee = BigDecimal.ZERO;
             }
             if (oldModel.getStartTime().getTime() < System.currentTimeMillis()) {
                 //// 2024骞�5鏈�8鏃�17:37:23 淇敼 璁$畻浜х敓璐圭敤
@@ -727,7 +730,7 @@
             }
             //鏌ヨ浜哄憳淇℃伅鏄惁瀛樺湪鐩稿悓鐨勬柟妗堜笅鏄惁瀛樺湪 鍐茬獊鏁版嵁
             InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getBaseId(),
-                    member.getIdcardNo(),member.getName(),detail.getStartTime(),detail.getEndTime(),
+                    member.getId(),member.getIdcardNo(),member.getName(),detail.getStartTime(),detail.getEndTime(),
                     applyDetailJoinMapper);
 
             //鏌ヨ鍔犱繚浜哄憳鏄惁瀛樺湪 鍐茬獊鐨� 淇濆崟鏄庣粏鏁版嵁
@@ -802,7 +805,7 @@
         }
 
         if (memberInsuranceList != null && memberInsuranceList.size() > 0) {
-            memberInsuranceJoinMapper.insertBatchSomeColumn(memberInsuranceList);
+            memberInsuranceJoinMapper.insert(memberInsuranceList);
         }
 
         if (totalFee.compareTo(new BigDecimal(0)) != 0) {
@@ -985,6 +988,9 @@
         Constants.ApplyLogType applyLogType = Constants.ApplyLogType.CA_COMPANY_COMMIT;
         ApplyLog log = new ApplyLog(applyChange,applyLogType.getName(),"",applyChange.getId(),applyLogType.getKey(), null, null);
         applyLogMapper.insert(log);
+//        if(1==1){
+//            throw new BusinessException(ResponseStatus.DATA_EMPTY );
+//        }
         return applyChange.getId();
     }
 
@@ -1130,9 +1136,12 @@
         }
     }
 
+    private static Logger logger = LoggerFactory.getLogger(ApplyChangeServiceImpl.class);
 
     public BigDecimal dealApplyChangeData(ApplyChange applyChange,InsuranceApply insuranceApply
             ,CompanySolution companySolution,Solutions solutions,LoginUserInfo loginUserInfo,BigDecimal fee){
+        Long start = System.currentTimeMillis();
+        logger.error("澶勭悊鍔犲噺淇濅繚鍗曟暟鎹紑濮嬫椂闂�:=========================>"+start);
         if(Constants.equalsInteger(applyChange.getType(),Constants.ZERO)){
             if(Objects.nonNull(solutions.getDelOnlyReplace())&& solutions.getDelOnlyReplace().equals(Constants.ONE)){
                 if(applyChange.getDelDetailList().size() > applyChange.getAddDetailList().size()){
@@ -1184,6 +1193,14 @@
         List<ApplyChagneDetail> delDetailList = applyChange.getDelDetailList();
         //鍔犱繚鏁版嵁
         List<ApplyChagneDetail> addDetailList = applyChange.getAddDetailList();
+        //鎹㈠巶涓氬姟
+        List<ApplyChagneDetail> changeDetailList = applyChange.getChangeDetailList();
+        
+        if(CollectionUtils.isEmpty(delDetailList)
+        && CollectionUtils.isEmpty(addDetailList)
+                && CollectionUtils.isEmpty(changeDetailList)){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝鏈坊鍔犱汉鍛樻暟鎹棤娉曡繘琛屾彁浜�");
+        }
 
         if (CollectionUtils.isNotEmpty(addDetailList)) {
             if(Objects.isNull(solutions.getCanAdd()) || solutions.getCanAdd().equals(Constants.ZERO)){
@@ -1221,10 +1238,7 @@
             fee = fee.add(delDetailList.stream().map(ApplyChagneDetail::getFee).reduce(BigDecimal.ZERO,BigDecimal::add));
         }
 
-       
-
         //鎹㈠巶涓氬姟
-        List<ApplyChagneDetail> changeDetailList = applyChange.getChangeDetailList();
         if (CollectionUtils.isNotEmpty(changeDetailList)) {
             if(Objects.isNull(solutions.getCanChangeUnit()) || solutions.getCanChangeUnit().equals(Constants.ZERO)){
                 throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "璇ヤ繚闄╂柟妗堟棤娉曡繘琛屾崲鍘傛搷浣�");
@@ -1238,6 +1252,8 @@
 
             this.changeDetail(applyChange,changeDetailList,duSolutionList,loginUserInfo,solutions,worktypeIdList);
         }
+        Long end = System.currentTimeMillis();
+        logger.error("澶勭悊鍔犲噺淇濅繚鍗曟暟鎹粨鏉熸椂闂�:=========================>"+end +";鍗曟潯鑰楁椂锛�====銆�"+(end-start));
         return fee;
     }
 
@@ -1286,18 +1302,35 @@
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍑忎繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝凡鍑洪櫓鏃犳硶杩涜鍑忎繚");
             };
             //2024-10-29 15:17:54 鏌ヨ浜哄憳鏄惁宸插噺淇� 宸插噺淇濆悗鏃犳硶鍐嶆鍑忎繚
-            if(applyChangeDetailJoinMapper.selectJoinCount(new MPJLambdaWrapper<ApplyChagneDetail>()
+//            if(applyChangeDetailJoinMapper.selectJoinCount(new MPJLambdaWrapper<ApplyChagneDetail>()
+//                    .leftJoin(ApplyChange.class,ApplyChange::getId,ApplyChagneDetail::getApplyChangeId)
+//                    .eq(ApplyChagneDetail::getType,Constants.ONE)
+//                    .eq(ApplyChange::getApplyId,applyChange.getApplyId())
+//                            .eq(ApplyChagneDetail::getMemberId,applyChagneDetail.getMemberId())
+//                    .notIn(ApplyChange::getStatus,Constants.ApplyChangeStatus.CLOSE.getKey()
+//                            ,Constants.ApplyChangeStatus.PALTFORM_CHECK_PASS_NO.getKey()
+//                    )
+//            )>Constants.ZERO){
+//                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍑忎繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝凡鍑忎繚鏃犳硶鍐嶆杩涜鍑忎繚");
+//            };
+            //2025-1-16 09:11:14 鏍规嵁鏌ヨ褰撳墠浜哄憳鏈�鍚庝竴娆$殑鍔犲噺淇濊褰� 濡傛灉鏈�鍚庝竴鏉¤褰曟槸鍔犱繚杩涘叆 鍒欏彲浠ュ噺淇� 濡傛灉鏈�鍚庝竴鏉¤褰曟槸鍑忎繚璁板綍 鍒欎笉鍙互鍑忎繚 濡傛灉涓虹┖ 杩欏彲浠ヨ繘琛屾搷浣�
+            ApplyChagneDetail lastApplyChagneDetail = applyChangeDetailJoinMapper.selectJoinOne(ApplyChagneDetail.class,
+                    new MPJLambdaWrapper<ApplyChagneDetail>()
                     .leftJoin(ApplyChange.class,ApplyChange::getId,ApplyChagneDetail::getApplyChangeId)
-                    .eq(ApplyChagneDetail::getType,Constants.ONE)
+                    .ne(ApplyChagneDetail::getType,Constants.TWO)
                     .eq(ApplyChange::getApplyId,applyChange.getApplyId())
-                            .eq(ApplyChagneDetail::getMemberId,applyChagneDetail.getMemberId())
+                    .eq(ApplyChagneDetail::getMemberId,applyChagneDetail.getMemberId())
                     .notIn(ApplyChange::getStatus,Constants.ApplyChangeStatus.CLOSE.getKey()
-                            ,Constants.ApplyChangeStatus.PALTFORM_CHECK_PASS_NO.getKey() 
+                            ,Constants.ApplyChangeStatus.PALTFORM_CHECK_PASS_NO.getKey()
                     )
-            )>Constants.ZERO){
-                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍑忎繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝凡鍑忎繚鏃犳硶鍐嶆杩涜鍑忎繚");
-            };
-
+                    .orderByDesc(ApplyChagneDetail::getId)
+                    .last(" limit 1 ")
+            );
+            if(Objects.nonNull(lastApplyChagneDetail)){
+                if(Constants.equalsInteger(lastApplyChagneDetail.getType(),Constants.ONE)){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍑忎繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝凡鍑忎繚鏃犳硶鍐嶆杩涜鍑忎繚");
+                }
+            }
             //鏌ヨ鍑忎繚浜哄憳鏄惁瀛樺湪 鍐茬獊鐨� 淇濆崟鏄庣粏鏁版嵁
             if(applyDetailJoinMapper.selectCount(new QueryWrapper<ApplyDetail>()
                     .lambda()
@@ -1325,6 +1358,7 @@
             }
             //鏌ヨ鍛樺伐鏄湪涓诲崟涓� 鏄惁瀛樺湪鐢熸晥涓殑鏁版嵁
             List<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectList(new QueryWrapper<ApplyDetail>().lambda()
+                            .eq(ApplyDetail::getIsdeleted,Constants.ZERO)
                     .eq(ApplyDetail::getApplyId, applyChange.getApplyId())
                     .eq(ApplyDetail::getMemberId, applyChagneDetail.getMemberId())
 //                    .le(ApplyDetail::getStartTime,DateUtil.getMontageDate(applyChange.getDelValidTime(),1))
@@ -1340,7 +1374,6 @@
             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());
             applyChagneDetail.setIsdeleted(Constants.ZERO);
@@ -1378,11 +1411,10 @@
                 applyChagneDetail.setReduceMoney(solutions.getPrice().multiply(new BigDecimal(-1)));
                 applyChagneDetail.setFee(BigDecimal.ZERO);
             }
+            applyChagneDetail.setId(null);
             applyChagneDetailJoinMapper.insert(applyChagneDetail);
         }
     }
-
-
 
     /**
      * 鍔犱繚鏁版嵁澶勭悊
@@ -1398,6 +1430,207 @@
         if(applyChange.getApplyStartTime().getTime()>insuranceApply.getEndTime().getTime()){
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍔犱繚鐢熸晥鏈熶笉鑳藉ぇ浜庝繚鍗曠粨鏉熸棩鏈�");
         }
+        //鏌ヨ鏈鍔犱繚鎵�鏈変汉鍛樹俊鎭�
+        List<Member> memberList = memberMapper.selectList(new QueryWrapper<Member>().lambda()
+                .eq(Member::getIsdeleted,Constants.ZERO)
+                .in(Member::getIdcardNo,addDetailList.stream().map(i->i.getIdcardNo()).collect(Collectors.toList()))
+        );
+        ApplyDetail applyDetail = applyDetailJoinMapper.selectOne(new QueryWrapper<ApplyDetail>().lambda()
+                .eq(ApplyDetail::getApplyId,applyChange.getApplyId())
+                .isNotNull(ApplyDetail::getPrice)
+                .last("limit 1 ")
+        );
+        if(Objects.isNull(applyDetail)){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "淇濆崟涓嬫棤鏄庣粏鏁版嵁");
+        }
+        List<Member> updMemberList = new ArrayList<>();
+        //鏌ヨ鏈鍔犱繚鎵�鏈変汉鍛樼殑鍘嗗彶淇濆崟璁板綍
+        List<ApplyDetail> applyDetailAllList = applyDetailJoinMapper.selectJoinList(ApplyDetail.class,
+                new MPJLambdaWrapper<ApplyDetail>()
+                        .selectAll(ApplyDetail.class)
+                        .selectAs(InsuranceApply::getCode,ApplyDetail::getApplyCode)
+                        .selectAs(InsuranceApply::getStatus,ApplyDetail::getApplyStatus)
+                        .selectAs(Company::getName,ApplyDetail::getCompanyName)
+                        .selectAs(Solutions::getBaseId,ApplyDetail::getSolutionBaseId)
+                        .leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyDetail::getApplyId)
+                        .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
+                        .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
+                        .in(CollectionUtils.isNotEmpty(memberList),ApplyDetail::getMemberId,memberList.stream().map(i->i.getId()).collect(Collectors.toList()))
+                        .apply(CollectionUtils.isEmpty(memberList),"1 = 2 ")
+                        .eq(ApplyDetail::getIsdeleted,Constants.ZERO));
+
+        List<ApplyChagneDetail> applyChangeDetailAllList = applyChagneDetailJoinMapper.selectJoinList(ApplyChagneDetail.class,
+                new MPJLambdaWrapper<ApplyChagneDetail>()
+                        .selectAll(ApplyChagneDetail.class)
+                        .leftJoin(ApplyChange.class, ApplyChange::getId, ApplyChagneDetail::getApplyChangeId)
+                        .leftJoin(Member.class,Member::getId,ApplyChagneDetail::getMemberId)
+                        .eq(ApplyChange::getApplyId,applyChange.getApplyId())
+                        .in(CollectionUtils.isNotEmpty(memberList),Member::getIdcardNo,memberList.stream().map(i->i.getIdcardNo()).collect(Collectors.toList()))
+                        .apply(CollectionUtils.isEmpty(memberList),"1 = 2 ")
+                        .in(ApplyChange::getStatus, Constants.ZERO, Constants.ONE));
+
+        List<ApplyChagneDetail> applyChagneDetailList = new ArrayList<>();
+        for (int i = 0; i < addDetailList.size(); i++) {
+            ApplyChagneDetail applyChagneDetail = addDetailList.get(i);
+            if (
+                    Constants.equalsInteger(solutions.getHasDispatchUnit(),Constants.ZERO) && Objects.isNull(applyChagneDetail.getDuId())
+                            || Objects.isNull(applyChagneDetail.getWorktypeId())
+                            || StringUtils.isBlank(applyChagneDetail.getIdcardNo())
+            ) {
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍔犱繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝繀濉」缂哄け");
+            }
+
+            //鏍规嵁鍛樺伐韬唤璇佽繘琛屽垽鏂勾榫�
+            long age = Constants.getAgeByIdCard(applyChagneDetail.getIdcardNo());
+            if(Objects.isNull(age)
+                    || age > solutions.getMaxAge()
+                    || age < solutions.getMinAge()){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+applyChagneDetail.getMemberName()+"銆戝憳宸ュ勾榫勮秴鍑烘柟妗堥厤缃� 鏂规閰嶇疆銆�"+solutions.getMinAge()+" - "+solutions.getMaxAge()+"銆戝瓨鍦ㄥ紓甯告暟鎹紒");
+            }
+
+            //鏌ヨ褰撳墠澶勭悊鐨勪汉鍛樹俊鎭�
+            List<Member> optMembers = memberList.stream().filter(j->j.getIdcardNo().equals(applyChagneDetail.getIdcardNo())).collect(Collectors.toList());
+            Member member = new Member();
+            if(CollectionUtils.isEmpty(optMembers)){
+                member = new Member();
+                member.setCreateDate(new Date());
+                member.setCreator(loginUserInfo.getId());
+                member.setIsdeleted(Constants.ZERO);
+                member.setName(applyChagneDetail.getMemberName());
+                member.setCompanyId(insuranceApply.getCompanyId());
+                member.setSex(Constants.getSexByIdCard(applyChagneDetail.getIdcardNo()));
+                if(!IdcardUtil.isValidCard(applyChagneDetail.getIdcardNo())){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍔犱繚鍛樺伐淇℃伅韬唤璇佷俊鎭敊璇痆"+member.getName()+"]");
+                }
+                member.setIdcardNo(applyChagneDetail.getIdcardNo());
+                member.setApplyId(insuranceApply.getId());
+                member.setDuId(applyChagneDetail.getDuId());
+                member.setWorktypeId(applyChagneDetail.getWorktypeId());
+                memberMapper.insert(member);
+                applyChagneDetail.setMemberId(member.getId());
+            }else{
+                member = optMembers.get(Constants.ZERO);
+                member.setApplyId(insuranceApply.getId());
+                member.setDuId(applyChagneDetail.getDuId());
+                member.setWorktypeId(applyChagneDetail.getWorktypeId());
+                member.setStartTime(applyChagneDetail.getStartTime());
+                member.setEndTime(applyChagneDetail.getEndTime());
+//                memberMapper.updateById(member);
+                updMemberList.add(member);
+                applyChagneDetail.setMemberId(member.getId());
+                if(CollectionUtils.isNotEmpty(applyChangeDetailAllList)&&applyChangeDetailAllList.stream().filter(
+                        j->Constants.equalsInteger(j.getMemberId(),applyChagneDetail.getMemberId())
+                ).collect(Collectors.toList()).size()>Constants.ZERO){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍔犱繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝瓨鍦ㄧ敵璇蜂腑鐨勫姞鍑忎繚/鎹㈠巶鍗曟嵁");
+                }
+
+            }
+            List<ApplyDetail> memberApplyDetailList = new ArrayList<>();
+            if(CollectionUtils.isNotEmpty(applyDetailAllList)){
+                memberApplyDetailList = applyDetailAllList.stream().filter(j->j.getIdcardNo().equals(applyChagneDetail.getIdcardNo())).collect(Collectors.toList());
+
+                if(memberApplyDetailList.stream().filter(j->j.getIdcardNo().equals(applyChagneDetail.getIdcardNo())&&Constants.equalsInteger(j.getApplyId(),applyChange.getApplyId())
+                        && j.getStartTime().getTime() <= DateUtil.getMontageDate(applyChange.getApplyStartTime(),1).getTime()
+                        && j.getEndTime().getTime() >= DateUtil.getMontageDate(insuranceApply.getEndTime(),2).getTime()
+                ).collect(Collectors.toList()).size()>Constants.ZERO){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "褰撳墠淇濆崟涓嬶紝鍔犱繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝瓨鍦ㄦ棩鏈熷啿绐佺殑鏁版嵁");
+                };
+                
+                if(memberApplyDetailList.stream().filter(j->j.getIdcardNo().equals(applyChagneDetail.getIdcardNo())
+                        &&Constants.equalsInteger(j.getApplyId(),applyChange.getApplyId())
+                        && j.getStartTime().getTime() <= System.currentTimeMillis()
+                        && j.getEndTime().getTime() >= System.currentTimeMillis()
+                ).collect(Collectors.toList()).size()>Constants.ZERO){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍔犱繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝瓨鍦ㄤ繚闅滀腑鐨勪繚鍗曚俊鎭紝鏃犳硶杩涜鍔犱繚");
+                };
+
+            } 
+
+            applyChagneDetail.setPrice(applyDetail.getPrice());
+            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);
+
+
+            List<ApplyDetail> checkStaticMemberSolutionList = memberApplyDetailList.stream()
+                            .filter(j->Constants.equalsInteger(j.getSolutionBaseId(),solutions.getBaseId())
+                            && !( j.getApplyStatus() == Constants.InsuranceApplyStatus.CLOSE.getKey() || j.getApplyStatus() == Constants.InsuranceApplyStatus.WTB_CLOSED.getKey() )
+                            && (
+                                ( applyChange.getApplyStartTime().getTime()<= j.getStartTime().getTime() && j.getStartTime().getTime() <  insuranceApply.getEndTime().getTime() )
+                                    ||
+                                ( applyChange.getApplyStartTime().getTime()< j.getEndTime().getTime() && j.getEndTime().getTime() <  insuranceApply.getEndTime().getTime() )
+                                    ||
+                                ( applyChange.getApplyStartTime().getTime()> j.getStartTime().getTime() &&   insuranceApply.getEndTime().getTime() < j.getEndTime().getTime() )
+                                            )
+                            ).collect(Collectors.toList());
+
+            if(checkStaticMemberSolutionList.size() >Constants.ZERO){
+                String companyName = checkStaticMemberSolutionList.get(Constants.ZERO).getCompanyName();
+                String idCode = checkStaticMemberSolutionList.get(Constants.ZERO).getIdcardNo();
+                if(StringUtils.isNotBlank(companyName)){
+                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ュ憳宸ャ��"+applyChagneDetail.getMemberName()+" "+idCode+"銆戝凡鍦ㄣ��"+companyName+"銆戝瓨鍦ㄤ繚闄�,璇疯仈绯诲鏈嶇‘璁�");
+                }else{
+                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ュ憳宸ャ��"+applyChagneDetail.getMemberName()+" "+idCode+"銆戝湪璇ヤ繚闄╂柟妗堜笅宸插瓨鍦ㄦ姇淇濊褰曪紝鏃犳硶杩涜璇ユ搷浣�");
+                }
+            };
+
+            //楠岃瘉娲鹃仯鍗曚綅淇℃伅 涓庡伐绉嶄俊鎭� 鏄惁瀛樺湪
+            if(Constants.equalsInteger(solutions.getHasDispatchUnit(),Constants.ZERO)){
+                if (duSolutionList.stream().filter(d -> d.getDispatchUnitId().equals(applyChagneDetail.getDuId())).collect(Collectors.toList()).size() <= Constants.ZERO) {
+                    throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(), "銆�" + applyChagneDetail.getMemberName() + "銆戝憳宸ユ淳閬e崟浣嶆湭鏌ヨ鍒帮紒");
+                }
+            }
+            if (worktypeIdList.stream().filter(d ->  Constants.equalsInteger(d,applyChagneDetail.getWorktypeId()))
+                    .collect(Collectors.toList()).size() <= Constants.ZERO) {
+                throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(), "銆�" + applyChagneDetail.getMemberName() + "銆戝憳宸ュ伐绉嶄俊鎭湭鏌ヨ鍒帮紒");
+            }
+            applyChagneDetail.setMemberId(member.getId());
+            //濡傛灉鏄噺淇濅笟鍔′负浠呮浛鎹� 涓� 鏂规鐨勬墸璐瑰懆鏈熷拰鎬诲懆鏈熺浉绛� 鍒欏鐞嗗噺淇濊垂鐢�
+            if(Constants.equalsInteger(solutions.getDelOnlyReplace(),Constants.ONE)
+                    && Constants.equalsInteger(solutions.getTimeUnit(),solutions.getInsureCycleUnit()) && delSize> i){
+                applyChagneDetail.setFee(BigDecimal.ZERO);
+            }else{
+                applyChagneDetail.setFee(detailFee);
+            }
+            applyChagneDetail.setId(null);
+            applyChagneDetailList.add(applyChagneDetail);
+        }
+        if(CollectionUtils.isNotEmpty(applyChagneDetailList)){
+            applyChagneDetailJoinMapper.insert(applyChagneDetailList);
+        }
+        if(CollectionUtils.isNotEmpty(updMemberList)){
+            Thread t1=new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        memberMapper.insertOrUpdate(updMemberList);
+                    }catch (Exception e){
+                        e.printStackTrace();
+                    }
+                }
+            });
+            t1.start(); 
+        }
+    }
+
+    /**
+     * 鍔犱繚鏁版嵁澶勭悊
+     * @param applyChange 鍔犲噺淇濅繚鍗曟暟鎹�
+     * @param addDetailList  鍔犱繚浜哄憳
+     * @param duSolutionList  娲鹃仯鍗曚綅鏂规鏁版嵁
+     * @param loginUserInfo 鎿嶄綔浜�
+     */
+    public void addChangeDetailOld(ApplyChange applyChange ,List<ApplyChagneDetail> addDetailList,
+                                List<DuSolution> duSolutionList,
+                                InsuranceApply insuranceApply,Solutions solutions,LoginUserInfo loginUserInfo,BigDecimal detailFee,Integer delSize,
+                                List<Integer> worktypeIdList){
+        if(applyChange.getApplyStartTime().getTime()>insuranceApply.getEndTime().getTime()){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍔犱繚鐢熸晥鏈熶笉鑳藉ぇ浜庝繚鍗曠粨鏉熸棩鏈�");
+        }
         for (int i = 0; i < addDetailList.size(); i++) {
             ApplyChagneDetail applyChagneDetail = addDetailList.get(i);
             if (
@@ -1407,10 +1640,6 @@
             ) {
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍔犱繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝繀濉」缂哄け");
             }
-            //鏌ヨ浜哄憳淇℃伅鏄惁瀛樺湪鐩稿悓鐨勬柟妗堜笅鏄惁瀛樺湪 鍐茬獊鏁版嵁
-            InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getBaseId(),
-                    applyChagneDetail.getIdcardNo(),applyChagneDetail.getMemberName(),applyChange.getApplyStartTime(),insuranceApply.getEndTime(),
-                    applyDetailJoinMapper);
 
             //鏌ヨ鍔犱繚浜哄憳鏄惁瀛樺湪 鍐茬獊鐨� 淇濆崟鏄庣粏鏁版嵁
             if(applyDetailJoinMapper.selectCount(new QueryWrapper<ApplyDetail>()
@@ -1418,7 +1647,7 @@
                     .eq(ApplyDetail::getApplyId,applyChange.getApplyId())
                     .eq(ApplyDetail::getIdcardNo,applyChagneDetail.getIdcardNo())
                     .le(ApplyDetail::getStartTime,DateUtil.getMontageDate(applyChange.getApplyStartTime(),1))
-                            .ge(ApplyDetail::getEndTime,DateUtil.getMontageDate(insuranceApply.getEndTime(),2))
+                    .ge(ApplyDetail::getEndTime,DateUtil.getMontageDate(insuranceApply.getEndTime(),2))
             )>Constants.ZERO){
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "褰撳墠淇濆崟涓嬶紝鍔犱繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝瓨鍦ㄦ棩鏈熷啿绐佺殑鏁版嵁");
             }
@@ -1426,6 +1655,7 @@
             ApplyDetail applyDetail = applyDetailJoinMapper.selectOne(new QueryWrapper<ApplyDetail>()
                             .lambda()
                             .eq(ApplyDetail::getApplyId,applyChange.getApplyId()).last("limit 1"));
+
             if(Objects.isNull(applyDetail)){
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "淇濆崟涓湭瀛樺湪鏄庣粏璁板綍");
             }
@@ -1461,17 +1691,14 @@
                     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);
                 }
+                applyChagneDetail.setMemberId(member.getId());
             }else{
                 member = memberMapper.selectById(applyChagneDetail.getMemberId());
                 if(Objects.isNull(member)){
@@ -1484,6 +1711,11 @@
                 member.setEndTime(applyChagneDetail.getEndTime());
                 memberMapper.updateById(member);
             }
+
+            //鏌ヨ浜哄憳淇℃伅鏄惁瀛樺湪鐩稿悓鐨勬柟妗堜笅鏄惁瀛樺湪 鍐茬獊鏁版嵁
+            InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getBaseId(),
+                    applyChagneDetail.getMemberId(),applyChagneDetail.getIdcardNo(),applyChagneDetail.getMemberName(),applyChange.getApplyStartTime(),insuranceApply.getEndTime(),
+                    applyDetailJoinMapper);
 
             //鏍规嵁鍛樺伐韬唤璇佽繘琛屽垽鏂勾榫�
             long age = Constants.getAgeByIdCard(member.getIdcardNo());
@@ -1516,6 +1748,7 @@
                     throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍔犱繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝瓨鍦ㄤ繚闅滀腑鐨勪繚鍗曚俊鎭紝鏃犳硶杩涜鍔犱繚");
                 }
             }
+
             //楠岃瘉娲鹃仯鍗曚綅淇℃伅 涓庡伐绉嶄俊鎭� 鏄惁瀛樺湪
             if(Constants.equalsInteger(solutions.getHasDispatchUnit(),Constants.ZERO)){
                 if (duSolutionList.stream().filter(d -> d.getDispatchUnitId().equals(applyChagneDetail.getDuId())).collect(Collectors.toList()).size() <= Constants.ZERO) {
@@ -1585,6 +1818,7 @@
             }
             //鏌ヨ鍛樺伐鏄湪涓诲崟涓� 鏄惁瀛樺湪鐢熸晥涓殑鏁版嵁
             List<ApplyDetail>  applyDetailList = applyDetailJoinMapper.selectList(new QueryWrapper<ApplyDetail>().lambda()
+                    .eq(ApplyDetail::getIsdeleted,Constants.ZERO)
                     .eq(ApplyDetail::getApplyId, applyChange.getApplyId())
                     .eq(ApplyDetail::getMemberId, applyChagneDetail.getMemberId())
                     .le(ApplyDetail::getStartTime,DateUtil.getMontageDate(applyChange.getApplyStartTime(),1))
@@ -1621,7 +1855,7 @@
             applyChagneDetail.setType(Constants.TWO);
             applyChagneDetail.setStartTime(applyDetail.getStartTime());
             applyChagneDetail.setEndTime(applyDetail.getEndTime());
-
+            applyChagneDetail.setId(null);
             applyChagneDetailJoinMapper.insert(applyChagneDetail);
 
             member.setApplyId(applyChange.getApplyId());
@@ -2274,18 +2508,18 @@
             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈡柟妗堜俊鎭�");
         }
         String fileUrl = null;
-//        if(Constants.equalsObject(model.getType(), Constants.ONE)){
-//              fileUrl = ExcelExporter.build(ApplyChange.class).exportChangeUnitExcelToPdf(model,"鎹㈠巶鐢宠琛�","鎶曚繚浼佷笟");
-//        }else{
-//            fileUrl = ExcelExporter.build(ApplyChange.class).exportJiajianBaoExcelToPdf(model,"鍔犲噺淇濈敵璇疯〃","鎶曚繚浼佷笟");
-//        }
+        if(Constants.equalsObject(model.getType(), Constants.ONE)){
+              fileUrl = ExcelExporter.build(ApplyChange.class).exportChangeUnitExcelToPdf(model,"鎹㈠巶鐢宠琛�","鎶曚繚浼佷笟");
+        }else{
+            fileUrl = ExcelExporter.build(ApplyChange.class).exportJiajianBaoExcelToPdf(model,"鍔犲噺淇濈敵璇疯〃","鎶曚繚浼佷笟");
+        }
         String notifyUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SIGN_DONE_NOTIFY_URL).getCode();
-//        notifyUrl = notifyUrl.replace("${type}","0").replace("${id}",model.getId().toString());
-//        String applyNo = signService.applySignLocalFile(company.getName(),company.getName(),fileUrl,company.getCode(),company.getEmail(),"鎶曚繚浼佷笟绛剧珷",company.getSignId(),notifyUrl);
+        notifyUrl = notifyUrl.replace("${type}","0").replace("${id}",model.getId().toString());
+        String applyNo = signService.applySignLocalFileByParam(company.getName(),company.getName(),fileUrl,company.getCode(),company.getEmail(),"鎶曚繚浼佷笟绛剧珷",company.getSignId(),notifyUrl,new Float(0.7));
         //涓存椂浣跨敤
-        fileUrl =  
-                "https://yybred.oss-cn-hangzhou.aliyuncs.com/apply/20241120/1c80f0d7-ab35-4355-b9fe-944464643115.pdf";
-        String applyNo = signService.applySign(companyName,fileUrl,companyName,creditCode,email,"浜哄憳鍚嶅崟绛剧珷",null,notifyUrl);
+//        fileUrl =
+//                "https://yybred.oss-cn-hangzhou.aliyuncs.com/apply/20241120/1c80f0d7-ab35-4355-b9fe-944464643115.pdf";
+//        String applyNo = signService.applySign(companyName,fileUrl,companyName,creditCode,email,"浜哄憳鍚嶅崟绛剧珷",null,notifyUrl);
         if(StringUtils.isBlank(applyNo) ){
             throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝鑾峰彇鍦ㄧ嚎绛剧珷鍦板潃澶辫触锛岃绋嶅悗閲嶈瘯锛�");
         }
@@ -2532,19 +2766,19 @@
             if(!Constants.equalsInteger(Constants.ZERO,model.getStatus())){
                 throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"瀵逛笉璧凤紝璇ョ敵璇风姸鎬佸凡娴佽浆锛屽綋鍓嶄笉鏀寔绛剧珷鎿嶄綔锛�");
             }
-//            if(Constants.equalsObject(model.getType(), Constants.ONE)){
-//                fileUrl = ExcelExporter.build(ApplyChange.class).exportChangeUnitExcelToPdf(model,"鎹㈠巶鐢宠琛�","琚繚闄╀汉");
-//            }else{
-//                fileUrl = ExcelExporter.build(ApplyChange.class).exportJiajianBaoExcelToPdf(model,"鍔犲噺淇濈敵璇疯〃","琚繚闄╀汉");
-//            }
+            if(Constants.equalsObject(model.getType(), Constants.ONE)){
+                fileUrl = ExcelExporter.build(ApplyChange.class).exportChangeUnitExcelToPdf(model,"鎹㈠巶鐢宠琛�","琚繚闄╀汉");
+            }else{
+                fileUrl = ExcelExporter.build(ApplyChange.class).exportJiajianBaoExcelToPdf(model,"鍔犲噺淇濈敵璇疯〃","琚繚闄╀汉");
+            }
             String notifyUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SIGN_DONE_NOTIFY_URL).getCode();
             notifyUrl = notifyUrl.replace("${type}","0").replace("${id}",model.getId().toString());
 
             //涓存椂浣跨敤
-            fileUrl =  "https://yybred.oss-cn-hangzhou.aliyuncs.com/apply/20241120/1c80f0d7-ab35-4355-b9fe-944464643115.pdf";
-            String applyNo = signService.applySign(company.getName(),fileUrl,company.getName(),company.getCode(),company.getEmail(),"浜哄憳鍚嶅崟绛剧珷",company.getSignId(),notifyUrl);
+//            fileUrl =  "https://yybred.oss-cn-hangzhou.aliyuncs.com/apply/20241230/a0d128f2-ba6c-4ad4-b86b-b2610a513d41.pdf";
+//            String applyNo = signService.applySignDoByParam(company.getName(),fileUrl,company.getName(),company.getCode(),company.getEmail(),"浜哄憳鍚嶅崟绛剧珷",company.getSignId(),notifyUrl,new Float(0.7));
 
-//            String applyNo = signService.applySignLocalFile(company.getName(),company.getName(),fileUrl,company.getCode(),company.getEmail(),"浜哄憳鍚嶅崟绛剧珷",company.getSignId(),notifyUrl);
+            String applyNo = signService.applySignLocalFileByParam(company.getName(),company.getName(),fileUrl,company.getCode(),company.getEmail(),"浜哄憳鍚嶅崟绛剧珷",company.getSignId(),notifyUrl,new Float(0.7));
             if(StringUtils.isBlank(applyNo) ){
                 throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝鑾峰彇鍦ㄧ嚎绛剧珷鍦板潃澶辫触锛岃绋嶅悗閲嶈瘯锛�");
             }
@@ -2650,26 +2884,26 @@
                 throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌淇濆崟鏁版嵁");
             }
             SaveUnionChangeDTO saveUnionChangeDTO = new SaveUnionChangeDTO();
-            saveUnionChangeDTO.setApplyDate(update.getApplyStartTime());
+            saveUnionChangeDTO.setApplyDate(model.getValidTime());
             List<Integer> applyIds = new ArrayList<>();
             applyIds.add(model.getId());
             saveUnionChangeDTO.setApplyIds(applyIds);
             saveUnionChangeDTO.setApplyChange(model);
             saveUnionChangeDTO.setUnionApplyId(insuranceApply.getUnionApplyId());
             saveUnionChangeDTO.setBusinessType(model.getType());
-            if(Constants.equalsInteger(model.getType(),Constants.ONE)){
-                saveUnionChangeDTO.setApplyDate(model.getApplyStartTime());
-            }
             if(Constants.equalsInteger(user.getType(),Constants.TWO)){
                 saveUnionChangeDTO.setShopId(user.getCompanyId());
             }else{
-                CompanySolution companySolution = companySolutionMapper.selectOne(new QueryWrapper<CompanySolution>().lambda().eq(CompanySolution::getSolutionId,solutions.getId()).eq(CompanySolution::getCompanyId,insuranceApply.getCompanyId()).last(" limit 1 "));
+                CompanySolution companySolution = companySolutionMapper.selectOne(new QueryWrapper<CompanySolution>()
+                        .lambda().eq(CompanySolution::getSolutionBaseId,solutions.getBaseId())
+                        .eq(CompanySolution::getCompanyId,insuranceApply.getCompanyId()).last(" limit 1 "));
                 if(Objects.isNull(companySolution)){
                     throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌浼佷笟鏂规淇℃伅");
                 }
                 saveUnionChangeDTO.setShopId(companySolution.getShopId());
 
             }
+
             unionChangeService.merge(saveUnionChangeDTO);
         }
         return  1;

--
Gitblit v1.9.3