From e3615abf0e9b87f574ddce53f94529d40762cecc Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期五, 07 六月 2024 17:34:43 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/1.0.1' into 1.0.1

---
 server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java |  172 +++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 113 insertions(+), 59 deletions(-)

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 3a437bb..d0cfb09 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
@@ -1,6 +1,8 @@
 package com.doumee.service.business.impl;
 
+import cn.hutool.core.util.IdcardUtil;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.api.R;
 import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.core.annotation.excel.ExcelExporter;
 import com.doumee.core.constants.ResponseStatus;
@@ -93,11 +95,15 @@
     @Autowired
     private MemberMapper memberMapper;
     @Autowired
+    private MemberJoinMapper memberJoinMapper;
+    @Autowired
     private DuSolutionMapper duSolutionMapper;
     @Autowired
     private DuSolutionJoinMapper duSolutionJoinMapper;
     @Autowired
     private DuWorktypeMapper duWorktypeMapper;
+    @Autowired
+    private DuWorkTypeJoinMapper duWorkTypeJoinMapper;
 
     @Autowired
     private NoticesMapper noticesMapper;
@@ -235,11 +241,17 @@
         update.setCode(insuranceApply.getCode());
         update.setEndTime(actEndTime);
         update.setStartTime(insuranceApply.getStartTime());
+        CountCyclePriceDTO countCyclePriceDTO = new CountCyclePriceDTO();
+        countCyclePriceDTO.setSolutionsId(model.getSolutionId());
+        countCyclePriceDTO.setStartDate(insuranceApply.getStartTime());
+        update.setFinalEndTime(this.getCountCyclePriceVO(countCyclePriceDTO).getEndDate());
         insuranceApplyMapper.updateById(update);
 
         //淇敼鏄庣粏琛岀殑寮�濮嬬粨鏉熸棩鏈�
-        applyDetailMapper.update(null,new UpdateWrapper<ApplyDetail>().lambda().set(ApplyDetail::getStartTime,insuranceApply.getStartTime())
-                .set(ApplyDetail::getEndTime,actEndTime).eq(ApplyDetail::getApplyId,model.getId()));
+        applyDetailMapper.update(null,new UpdateWrapper<ApplyDetail>().lambda()
+                .set(ApplyDetail::getStartTime,insuranceApply.getStartTime())
+                .set(ApplyDetail::getEndTime,actEndTime)
+                .eq(ApplyDetail::getApplyId,model.getId()));
 
         multifileMapper.update(null,new UpdateWrapper<Multifile>().lambda()
                 .eq(Multifile::getIsdeleted,Constants.ZERO)
@@ -258,6 +270,10 @@
         insuranceApply.getBaoxiandanFile().setType(Constants.TWO);
         multifileMapper.insert(insuranceApply.getBaoxiandanFile());
         update.setBaoxiandanFile(insuranceApply.getBaoxiandanFile());
+
+        noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,Constants.NoticeObjectType.INSURANCE_APPLY.getKey())
+                .ne(Notices::getType,Constants.NoticeType.SIX.getStatus())
+                .eq(Notices::getObjId,insuranceApply.getId()));
 
         Constants.ApplyLogType applyLogType = Constants.ApplyLogType.UPLOAD_INSURANCE;
         String info = "";
@@ -309,6 +325,7 @@
             memberInsuranceJoinMapper.insertBatchSomeColumn(memberInsuranceList);
         }
 
+        this.updateApplyCurrentFee(insuranceApply.getId(),null);
         return  1;
     }
 
@@ -1285,6 +1302,7 @@
                     return;
                 }
                 uploadChangeSignedFileDo(applyChange,fileUrl,path+fileUrl);
+                return;
             }
 
             //濮旀墭淇� 鍔犲噺淇濅紒涓氱缃�
@@ -1309,6 +1327,7 @@
                     return;
                 }
                 uploadChangeMemberListSignedFileDo(applyChangeMemberList,fileUrl,path+fileUrl);
+                return;
             }
 
 
@@ -1323,6 +1342,7 @@
                     return;
                 }
                 uploadUnionApplySignedFileDo(unionApply,fileUrl,path+fileUrl);
+                return;
             }
 
 
@@ -1342,6 +1362,7 @@
                     return;
                 }
                 uploadUnionChangeSignedFileDo(unionChange,fileUrl,path+fileUrl);
+                return;
             }
 
 
@@ -1592,18 +1613,18 @@
         insuranceApply.setCheckUserId(loginUserInfo.getId());
         insuranceApply.setStatus(insuranceApplyStatus.getKey());
         insuranceApply.setUnionApplyTbdStatus(Constants.ZERO);
-
         CountCyclePriceDTO countCyclePriceDTO = new CountCyclePriceDTO();
         countCyclePriceDTO.setSolutionsId(insuranceApply.getSolutionId());
         countCyclePriceDTO.setStartDate(insuranceApply.getStartTime());
         CountCyclePriceVO  countCyclePriceVO = this.getCountCyclePriceVO(countCyclePriceDTO);
         insuranceApply.setApplyEndTime(countCyclePriceVO.getEndDate());
         insuranceApply.setEndTime(countCyclePriceVO.getEndDate());
+        insuranceApply.setFinalEndTime(countCyclePriceVO.getEndDate());
         insuranceApplyMapper.insert(insuranceApply);
 
 
         //澶勭悊涓嬬骇鏁版嵁
-        this.dealApplyDetailData(insuranceApply,solutions,applyDetailList,loginUserInfo,countCyclePriceVO);
+        this.dealApplyDetailData(insuranceApply,solutions,applyDetailList,loginUserInfo,countCyclePriceVO,true);
         InsuranceApply updBean = new InsuranceApply();
         updBean.setId(insuranceApply.getId());
         updBean.setFee(applyDetailList.stream().map(ApplyDetail::getFee).reduce(BigDecimal.ZERO,BigDecimal::add));
@@ -1639,7 +1660,6 @@
                 noticesMapper.insert(shopNotices);
             }
         }
-
         return insuranceApply.getId();
     }
 
@@ -1705,7 +1725,7 @@
         }
 
         //澶勭悊涓嬬骇鏁版嵁
-        this.dealApplyDetailData(insuranceApply,solutions,applyDetailList,loginUserInfo,countCyclePriceVO);
+        this.dealApplyDetailData(insuranceApply,solutions,applyDetailList,loginUserInfo,countCyclePriceVO,false);
         insuranceApply.setFee(applyDetailList.stream().map(ApplyDetail::getFee).reduce(BigDecimal.ZERO,BigDecimal::add));
         insuranceApplyMapper.updateById(insuranceApply);
         //瀛樺偍鏃ュ織鏁版嵁
@@ -1731,7 +1751,8 @@
 
 
 
-    public void dealApplyDetailData(InsuranceApply insuranceApply,Solutions solutions,List<ApplyDetail> applyDetailList,LoginUserInfo loginUserInfo,CountCyclePriceVO  countCyclePriceVO){
+    public void dealApplyDetailData(InsuranceApply insuranceApply,Solutions solutions,List<ApplyDetail> applyDetailList,
+                                    LoginUserInfo loginUserInfo,CountCyclePriceVO  countCyclePriceVO,Boolean checkNewData){
         //鏌ヨ淇濋櫓鏂规涓嬬殑鎵�鏈夋淳閬e崟浣�
         List<DuSolution>  duSolutionList = duSolutionJoinMapper.selectJoinList(DuSolution.class,new MPJLambdaWrapper<DuSolution>()
                 .selectAll(DuSolution.class)
@@ -1740,22 +1761,66 @@
                 .eq(DispatchUnit::getIsdeleted,Constants.ZERO)
                 .eq(DispatchUnit::getUnitStatus,Constants.ONE)
                 .eq(DuSolution::getIsdeleted,Constants.ZERO)
+                .eq(checkNewData,DispatchUnit::getDataType,Constants.TWO)
                 .eq(DuSolution::getStatus,Constants.ONE)
-                .eq(DuSolution::getSolutionId,insuranceApply.getSolutionId()));
+                .eq(DuSolution::getSolutionId,insuranceApply.getSolutionId())
+                .apply(" t1.BASE_ID in ( select du.id from dispatch_unit du where du.STATUS = 0 and du.ISDELETED = 0 ) ")
+        );
         if(!CollectionUtils.isNotEmpty(duSolutionList)){
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鏁版嵁寮傚父锛氫繚闄╂柟妗堜笅鏈煡璇㈠埌娲鹃仯鍗曚綅");
         }
         //鏌ヨ鎵�鏈夋淳閬e崟浣嶄笅鐨勫伐绉�
         List<Integer> duSolutionIdList = duSolutionList.stream().map(i->i.getId()).collect(Collectors.toList());
-        List<DuWorktype> duWorktypeList = duWorktypeMapper.selectList(new QueryWrapper<DuWorktype>().lambda()
+        List<DuWorktype> duWorktypeList = duWorkTypeJoinMapper.selectJoinList(DuWorktype.class,new MPJLambdaWrapper<DuWorktype>()
+                .selectAll(DuWorktype.class)
+                .innerJoin(Worktype.class,Worktype::getId,DuWorktype::getWorkTypeId)
                 .eq(DuWorktype::getIsdeleted,Constants.ZERO)
                 .eq(DuWorktype::getStatus,Constants.ONE)
+                .eq(checkNewData,Worktype::getDataType,Constants.TWO)
                 .in(DuWorktype::getDuSolutionId,duSolutionIdList));
         if(!CollectionUtils.isNotEmpty(duWorktypeList)){
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鏁版嵁寮傚父锛氫繚闄╂柟妗堜笅鏈煡璇㈠埌宸ョ淇℃伅");
         }
 
         if(CollectionUtils.isNotEmpty(applyDetailList)){
+            List<Member> memberList = memberMapper.selectList(new QueryWrapper<Member>().lambda()
+                    .eq(Member::getCompanyId,insuranceApply.getCompanyId())
+                    .eq(Member::getIsdeleted,Constants.ZERO));
+
+            List<Member> addMemberList = new ArrayList<>();
+            for (int i = 0; i < applyDetailList.size(); i++) {
+                ApplyDetail applyDetail = applyDetailList.get(i);
+                Member member = null;
+                if(CollectionUtils.isNotEmpty(memberList)){
+                    Optional<Member>  optional = memberList.stream().filter(m->m.getIdcardNo().equals(applyDetail.getIdcardNo())).findFirst();
+                    if(optional.isPresent()){
+                        member = optional.get();
+                    }
+                }
+                if(Objects.isNull(member)){
+                    member = new Member();
+                    member.setCreateDate(new Date());
+                    member.setCreator(loginUserInfo.getId());
+                    member.setIsdeleted(Constants.ZERO);
+                    member.setName(applyDetail.getMemberName());
+                    member.setCompanyId(insuranceApply.getCompanyId());
+                    member.setSex(Constants.getSexByIdCard(applyDetail.getIdcardNo()));
+                    if(!IdcardUtil.isValidCard(applyDetail.getIdcardNo())){
+                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鎶曚繚鍛樺伐淇℃伅韬唤璇佷俊鎭敊璇痆"+member.getName()+"]");
+                    }
+                    member.setIdcardNo(applyDetail.getIdcardNo());
+                    member.setApplyId(insuranceApply.getId());
+                    member.setStartTime(applyDetail.getStartTime());
+                    member.setEndTime(applyDetail.getEndTime());
+                    member.setDuId(applyDetail.getDuId());
+                    member.setWorktypeId(applyDetail.getWorktypeId());
+                    addMemberList.add(member);
+                }
+            }
+            if(CollectionUtils.isNotEmpty(addMemberList)){
+                memberJoinMapper.insertBatchSomeColumn(addMemberList);
+            }
+            memberList.addAll(addMemberList);
             for (int i = 0; i < applyDetailList.size(); i++) {
                 ApplyDetail applyDetail = applyDetailList.get(i);
                 if(Objects.isNull(applyDetail)
@@ -1773,31 +1838,16 @@
                 applyDetail.setEndTime(insuranceApply.getApplyEndTime());
                 applyDetail.setSortnum(i);
                 applyDetail.setApplyId(insuranceApply.getId());
-                Member member = new Member();
+                Member member = null;
                 if(Objects.isNull(applyDetail.getMemberId())){
+                    if(CollectionUtils.isNotEmpty(memberList)){
+                        Optional<Member>  optional = memberList.stream().filter(m->m.getIdcardNo().equals(applyDetail.getIdcardNo())).findFirst();
+                        if(optional.isPresent()){
+                            member = optional.get();
+                        }
+                    }
                     //鏌ヨ鏄惁瀛樺湪璇ョ敤鎴�
-                    member = memberMapper.selectOne(new QueryWrapper<Member>().lambda()
-                            .eq(Member::getCompanyId,insuranceApply.getCompanyId())
-                            .eq(Member::getIsdeleted,Constants.ZERO)
-                            .eq(Member::getIdcardNo,applyDetail.getIdcardNo())
-                            .last(" limit 1")
-                    );
-                    if(Objects.isNull(member)){
-                        member = new Member();
-                        member.setCreateDate(new Date());
-                        member.setCreator(loginUserInfo.getId());
-                        member.setIsdeleted(Constants.ZERO);
-                        member.setName(applyDetail.getMemberName());
-                        member.setCompanyId(insuranceApply.getCompanyId());
-                        member.setSex(Constants.getSexByIdCard(applyDetail.getIdcardNo()));
-                        member.setIdcardNo(applyDetail.getIdcardNo());
-                        member.setApplyId(insuranceApply.getId());
-                        member.setStartTime(applyDetail.getStartTime());
-                        member.setEndTime(applyDetail.getEndTime());
-                        member.setDuId(applyDetail.getDuId());
-                        member.setWorktypeId(applyDetail.getWorktypeId());
-                        memberMapper.insert(member);
-                    }else{
+                    if(!Objects.isNull(member)){
                         member.setApplyId(insuranceApply.getId());
                         member.setDuId(applyDetail.getDuId());
                         member.setWorktypeId(applyDetail.getWorktypeId());
@@ -2512,38 +2562,38 @@
      */
     @Override
     @Transactional(rollbackFor = {Exception.class,BusinessException.class})
-    public void updateApplyCurrentFee(Integer id){
+    public void updateApplyCurrentFee(Integer id,Integer unionId){
         List<InsuranceApply> insuranceApplyList = insuranceApplyJoinMapper.selectJoinList(InsuranceApply.class,new MPJLambdaWrapper<InsuranceApply>()
                 .selectAll(InsuranceApply.class)
                 .eq(InsuranceApply::getIsdeleted,Constants.ZERO)
-                .in(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey(),Constants.InsuranceApplyStatus.WTB_TOUBAOING.getKey())
+                .in(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey(),Constants.InsuranceApplyStatus.WTB_DONE.getKey())
                 .eq(!Objects.isNull(id),InsuranceApply::getId,id)
+                .eq(!Objects.isNull(unionId),InsuranceApply::getUnionApplyId,unionId)
                 .le(InsuranceApply::getStartTime,DateUtil.getDate(new Date(),"yyyy-MM-dd") + " 00:00:00")
                 .ge(InsuranceApply::getEndTime,DateUtil.getDate(new Date(),"yyyy-MM-dd") + " 23:59:59")
         );
-
         if(CollectionUtils.isNotEmpty(insuranceApplyList)){
             for (InsuranceApply insuranceApply:insuranceApplyList) {
-//                Solutions solutions = solutionsMapper.selectById(insuranceApply.getSolutionId());
-//                if(Objects.isNull(solutions)){
-//                    continue;
-//                }
+                Solutions solutions = solutionsMapper.selectById(insuranceApply.getSolutionId());
+                if(Objects.isNull(solutions)){
+                    continue;
+                }
                 BigDecimal sumAmount = BigDecimal.ZERO;
                 List<ApplyDetail> applyDetailList = applyDetailMapper
                         .selectList(new QueryWrapper<ApplyDetail>().lambda()
                                 .eq(ApplyDetail::getApplyId,insuranceApply.getId()));
                 if(CollectionUtils.isNotEmpty(applyDetailList)){
                     for (ApplyDetail applyDetail: applyDetailList) {
-                        //2024-1-30 10:04:24 淇敼 鏍规嵁瀹為檯澶╂暟杩涜璁$畻 褰撳墠璐圭敤  鎬婚噾棰�/鎬诲ぉ鏁�*瀹為檯澶╂暟
-//                        Integer maxDays = DateUtil.calculateBetween(applyDetail.getStartTime(),applyDetail.getEndTime(),0);
-                        BigDecimal fee = applyDetail.getFee();
+                        BigDecimal fee =  Objects.isNull(insuranceApply.getServerCost())?
+                                solutions.getPrice():
+                                solutions.getPrice().add(insuranceApply.getServerCost());
+                        //鍦ㄥ紑濮嬬粨鏉熸棩鏈熶箣闂�
                         if(applyDetail.getStartTime().compareTo(new Date()) <= 0 && applyDetail.getEndTime().compareTo(new Date()) >= 0 ){
-                            Integer days =  DateUtil.calculateBetween(applyDetail.getStartTime(),new Date(),0);
-                            applyDetail.setCurrentFee(new BigDecimal(days).multiply(applyDetail.getPrice()));
-                            //applyDetail.setCurrentFee(fee.divide(BigDecimal.valueOf(maxDays),2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(days)));
+                            applyDetail.setCurrentFee(Constants.produceFee(solutions,fee,insuranceApply.getStartTime(),insuranceApply.getFinalEndTime(),applyDetail.getStartTime()));
                             applyDetailMapper.updateById(applyDetail);
-                        }else if(applyDetail.getStartTime().compareTo(new Date()) <= 0&&applyDetail.getEndTime().compareTo(new Date()) <= 0){
-                            applyDetail.setCurrentFee(fee);
+                        }else  if(applyDetail.getStartTime().compareTo(new Date()) <= 0&&applyDetail.getEndTime().compareTo(new Date()) <= 0){
+                            //鍦ㄧ粨鏉熸棩鏈熶箣鍚�
+                            applyDetail.setCurrentFee(applyDetail.getFee());
                             applyDetailMapper.updateById(applyDetail);
                         }
                         sumAmount = sumAmount.add(applyDetail.getCurrentFee());
@@ -2553,6 +2603,9 @@
                 insuranceApplyMapper.updateById(insuranceApply);
             }
         }
+//        if(1==1){
+//            throw new BusinessException(ResponseStatus.NOT_ALLOWED);
+//        }
     }
 
 
@@ -2606,13 +2659,13 @@
     public  String getSignTBQRSLink(SmsCheckDTO smsCheckDTO) {
         if(Objects.isNull(smsCheckDTO)
             || Objects.isNull(smsCheckDTO.getBusinessId())
-                || StringUtils.isBlank(smsCheckDTO.getCode())
+//                || StringUtils.isBlank(smsCheckDTO.getCode())
         ){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST);
         }
-        if(!debugModel){
-            smsEmailService.validateCode(smsCheckDTO.getCode());
-        }
+//        if(!debugModel){
+//            smsEmailService.validateCode(smsCheckDTO.getCode());
+//        }
         MPJLambdaWrapper wrapper=  new MPJLambdaWrapper<InsuranceApply>()
                 .selectAll(InsuranceApply.class)
                 .selectAs(Solutions::getSignKeyword,InsuranceApply::getSignKeyword)
@@ -2688,6 +2741,7 @@
                 .leftJoin(DispatchUnit.class,DispatchUnit::getId,ApplyDetail::getDuId)
                 .isNull(ApplyDetail::getFromId)
                 .eq(ApplyDetail::getApplyId,model.getId())
+                .orderByAsc(ApplyDetail::getId)
         );
         model.setApplyDetailList(applyDetailList);
         return model;
@@ -2702,14 +2756,14 @@
     public String getMemberListOnlineSignLink(SmsCheckDTO smsCheckDTO) {
         if(Objects.isNull(smsCheckDTO)
                 || Objects.isNull(smsCheckDTO.getBusinessId())
-                || StringUtils.isBlank(smsCheckDTO.getCode())
+//                || StringUtils.isBlank(smsCheckDTO.getCode())
         ){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST);
         }
         //楠岃瘉 楠岃瘉鐮�
-        if(!debugModel){
-            smsEmailService.validateCode(smsCheckDTO.getCode());
-        }
+//        if(!debugModel){
+//            smsEmailService.validateCode(smsCheckDTO.getCode());
+//        }
         InsuranceApply model = this.queryApplyDetail(smsCheckDTO.getBusinessId());
         if(Objects.isNull(model)){
             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇繚鍗曚俊鎭�");
@@ -2765,14 +2819,14 @@
     public  String getSignWTBTBDLink(SmsCheckDTO smsCheckDTO) {
         if(Objects.isNull(smsCheckDTO)
                 || Objects.isNull(smsCheckDTO.getBusinessId())
-                || StringUtils.isBlank(smsCheckDTO.getCode())
+//                || StringUtils.isBlank(smsCheckDTO.getCode())
         ){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST);
         }
         //楠岃瘉 楠岃瘉鐮�
-        if(!debugModel){
-            smsEmailService.validateCode(smsCheckDTO.getCode());
-        }
+//        if(!debugModel){
+//            smsEmailService.validateCode(smsCheckDTO.getCode());
+//        }
         MPJLambdaWrapper wrapper=  new MPJLambdaWrapper<InsuranceApply>()
                 .selectAll(InsuranceApply.class)
                 .selectAs(Solutions::getSignKeyword,InsuranceApply::getSignKeyword)

--
Gitblit v1.9.3