From bb64d5e37ba396998f75793476e381782ca6cefa Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期四, 20 六月 2024 18:46:50 +0800
Subject: [PATCH] git ch

---
 server/service/src/main/java/com/doumee/service/business/impl/ApplyChangeServiceImpl.java |  110 +++++++++++++++++++++++++++++-------------------------
 1 files changed, 59 insertions(+), 51 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 72d7e5d..edc9ea4 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
@@ -681,7 +681,7 @@
                 throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "鏈煡璇㈠埌鍛樺伐鏁版嵁");
             }
             //鏌ヨ浜哄憳淇℃伅鏄惁瀛樺湪鐩稿悓鐨勬柟妗堜笅鏄惁瀛樺湪 鍐茬獊鏁版嵁
-            InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getId(),
+            InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getBaseId(),
                     member.getIdcardNo(),member.getName(),detail.getStartTime(),detail.getEndTime(),
                     applyDetailJoinMapper);
 
@@ -690,6 +690,13 @@
                     .lambda()
                     .eq(ApplyDetail::getApplyId,update.getApplyId())
                     .eq(ApplyDetail::getIdcardNo,detail.getIdcardNo())
+//                    .apply(" ( " +
+//                            " '"+DateUtil.getLongDateTime(DateUtil.getMontageDate(update.getApplyStartTime(),1))+"'  <= t.start_time AND t.start_time < '"+DateUtil.getLongDateTime(DateUtil.getMontageDate(detail.getEndTime(),2))+"' " +
+//                            " or " +
+//                            "  ( '"+DateUtil.getLongDateTime(DateUtil.getMontageDate(update.getApplyStartTime(),1))+"' < t.end_time AND t.end_time < '"+DateUtil.getLongDateTime(DateUtil.getMontageDate(detail.getEndTime(),2))+"' )  " +
+//                            " or " +
+//                            " ( '"+DateUtil.getLongDateTime(DateUtil.getMontageDate(update.getApplyStartTime(),1))+"' > t.start_time AND '"+DateUtil.getLongDateTime(DateUtil.getMontageDate(detail.getEndTime(),2))+"' < t.end_time )" +
+//                            " ) " )
                     .le(ApplyDetail::getStartTime,DateUtil.getMontageDate(update.getApplyStartTime(),1))
                     .ge(ApplyDetail::getEndTime,DateUtil.getMontageDate(detail.getEndTime(),2))
             )>Constants.ZERO){
@@ -717,7 +724,7 @@
             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())){
+                    && Constants.equalsInteger(solutions.getTimeUnit(),solutions.getInsureCycleUnit()) && i < reduceList.size()){
                 add.setReduceId(reduceList.get(i).getId());
             }
             if(new Date().compareTo(DateUtil.getMontageDate(detail.getStartTime(), 2))>=0){
@@ -1038,14 +1045,16 @@
         }
         if (!(Constants.equalsInteger(insuranceApply.getStatus(), Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey())
                 ||Constants.equalsInteger(insuranceApply.getStatus(), Constants.InsuranceApplyStatus.WTB_DONE.getKey())
-            )
-        ) {
+            )) {
             throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(), "淇濆崟鐘舵�侀敊璇�");
         }
-        if (DateUtil.compareDate(insuranceApply.getEndTime(),new Date()) >= Constants.ZERO
-        ) {
+        if (DateUtil.compareDate(insuranceApply.getEndTime(),new Date()) >= Constants.ZERO ) {
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "淇濆崟宸茶繃淇濓紝鏃犳硶杩涜璇ユ搷浣�");
         }
+//        if (DateUtil.compareDate(applyChange.getValidTime(),insuranceApply.getStartTime()) >= Constants.ZERO) {
+//            //濡傛灉淇濆崟灏氭湭鐢熸晥锛岃缃湡鏈涚敓鏁堟棩鏈熶负淇濆崟鐢熸晥寮�濮嬫椂闂�
+//            applyChange.setValidTime(insuranceApply.getStartTime());
+//        }
         Solutions solutions = solutionsMapper.selectById(insuranceApply.getSolutionId());
         if(Objects.isNull(solutions)){
             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌淇濋櫓鏂规");
@@ -1086,30 +1095,10 @@
         applyChange.setIsdeleted(Constants.ZERO);
         //鏍规嵁鐢宠鏃ユ湡 澶勭悊鍔犲噺淇濈殑 瀹為檯鐢熸晥鏃ユ湡
         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()
-                );
-            }
+            initJJBValidTime(applyChange,insuranceApply,solutions);
         }else{
             applyChange.setApplyStartTime(applyChange.getValidTime());
         }
-
         applyChange.setStatus(Constants.ZERO);
         applyChangeMapper.insert(applyChange);
 
@@ -1147,7 +1136,7 @@
 //                || Objects.isNull(applyChange.getValidTime())
                 || Objects.isNull(applyChange.getType())
                 || !(applyChange.getType().equals(Constants.ZERO) || applyChange.getType().equals(Constants.ONE))
-        ) {
+        ){
             throw new BusinessException(ResponseStatus.BAD_REQUEST);
         }
         LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
@@ -1177,6 +1166,9 @@
         ) {
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "淇濆崟宸茶繃淇濓紝鏃犳硶杩涜璇ユ搷浣�");
         }
+//        if (DateUtil.compareDate(applyChange.getValidTime(),insuranceApply.getStartTime()) > Constants.ZERO) {
+//            applyChange.setValidTime(insuranceApply.getStartTime());
+//        }
         Solutions solutions = solutionsMapper.selectById(insuranceApply.getSolutionId());
         if(Objects.isNull(solutions)){
             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌淇濋櫓鏂规");
@@ -1211,27 +1203,8 @@
         };
 
         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()
-                );
-            }
-
+            //澶勭悊鏈熸湜鐢熸晥鏃ユ湡
+            initJJBValidTime(applyChange,insuranceApply,solutions);
         }else{
             applyChange.setApplyStartTime(applyChange.getValidTime());
         }
@@ -1259,6 +1232,34 @@
         noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,applyChange.getId()));
 
         return applyChange.getId();
+    }
+
+    private void initJJBValidTime(ApplyChange applyChange, InsuranceApply insuranceApply, Solutions solutions) {
+        if( applyChange.getValidTime().getTime()>=insuranceApply.getStartTime().getTime()
+                && Objects.nonNull(solutions.getAddValidDays())){
+            //濡傛灉淇濆崟宸茬敓鏁堬紝鎸夌収t+n鐨勮鍒�
+            applyChange.setApplyStartTime(
+                    DateUtil.afterDateByType(applyChange.getValidTime(),0,solutions.getAddValidDays())
+            );
+        }else{
+            //濡傛灉淇濆崟鏈敓鎴栬�呮病鏈夐厤缃敓鏁堝ぉ鏁帮紝璁剧疆鏈熸湜鐢熸晥鏃ユ湡涓轰繚鍗曠敓鏁堝紑濮嬫椂闂�
+            applyChange.setApplyStartTime(applyChange.getValidTime().getTime()>=insuranceApply.getStartTime().getTime()?applyChange.getValidTime():insuranceApply.getStartTime());
+        }
+        if(applyChange.getValidTime().getTime()>=insuranceApply.getStartTime().getTime()
+                &&Objects.nonNull(solutions.getDelValidDays())){
+            applyChange.setDelValidTime(
+                    DateUtil.afterDateByType(applyChange.getValidTime(),0,solutions.getDelValidDays())
+            );
+        }else{
+            applyChange.setDelValidTime(applyChange.getValidTime().getTime()>=insuranceApply.getStartTime().getTime()?applyChange.getValidTime():insuranceApply.getStartTime());
+        }
+        //浠呮敮鎸佹浛鎹�  淇濊瘉鍔犲噺淇濇棩鏈熶负鍚屼竴澶�
+        if(Constants.equalsInteger(solutions.getDelOnlyReplace(),Constants.ONE)){
+            applyChange.setApplyStartTime(
+                    applyChange.getDelValidTime()
+            );
+        }
+
     }
 
 
@@ -1496,7 +1497,7 @@
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍔犱繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝繀濉」缂哄け");
             }
             //鏌ヨ浜哄憳淇℃伅鏄惁瀛樺湪鐩稿悓鐨勬柟妗堜笅鏄惁瀛樺湪 鍐茬獊鏁版嵁
-            InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getId(),
+            InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getBaseId(),
                     applyChagneDetail.getMemberIdcardNo(),applyChagneDetail.getMemberName(),insuranceApply.getStartTime(),insuranceApply.getEndTime(),
                     applyDetailJoinMapper);
 
@@ -1505,9 +1506,15 @@
                     .lambda()
                     .eq(ApplyDetail::getApplyId,applyChange.getApplyId())
                     .eq(ApplyDetail::getIdcardNo,applyChagneDetail.getIdcardNo())
+//                    .apply(" ( " +
+//                            " '"+DateUtil.getLongDateTime(DateUtil.getMontageDate(applyChange.getApplyStartTime(),1))+"'  <= t.start_time AND t.start_time < '"+DateUtil.getLongDateTime(DateUtil.getMontageDate(insuranceApply.getEndTime(),2))+"' " +
+//                            " or " +
+//                            "  ( '"+DateUtil.getLongDateTime(DateUtil.getMontageDate(applyChange.getApplyStartTime(),1))+"' < t.end_time AND t.end_time < '"+DateUtil.getLongDateTime(DateUtil.getMontageDate(insuranceApply.getEndTime(),2))+"' )  " +
+//                            " or " +
+//                            " ( '"+DateUtil.getLongDateTime(DateUtil.getMontageDate(applyChange.getApplyStartTime(),1))+"' > t.start_time AND '"+DateUtil.getLongDateTime(DateUtil.getMontageDate(insuranceApply.getEndTime(),2))+"' < t.end_time )" +
+//                            " ) " )
                     .le(ApplyDetail::getStartTime,DateUtil.getMontageDate(applyChange.getApplyStartTime(),1))
                             .ge(ApplyDetail::getEndTime,DateUtil.getMontageDate(insuranceApply.getEndTime(),2))
-                    //.ge(ApplyDetail::getEndTime,DateUtil.getMontageDate(applyChange.getApplyStartTime(),3))
             )>Constants.ZERO){
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "褰撳墠淇濆崟涓嬶紝鍔犱繚浜哄憳銆�" + applyChagneDetail.getMemberName() + "銆戝瓨鍦ㄦ棩鏈熷啿绐佺殑鏁版嵁");
             }
@@ -2124,6 +2131,7 @@
                 .selectAs(Solutions::getName,ApplyChange::getSolutionsName)
                 .selectAs(Solutions::getType,ApplyChange::getSolutionType)
                 .selectAs(Solutions::getId,ApplyChange::getSolutionsId)
+                .selectAs(Solutions::getDelOnlyReplace,ApplyChange::getDelOnlyReplace)
                 .select("( select count(1) from apply_chagne_detail ad where t.id = ad.APPLY_CHANGE_ID and ad.TYPE = 0  )",ApplyChange::getAddNum)
                 .select("( select count(1) from apply_chagne_detail ad where t.id = ad.APPLY_CHANGE_ID and ad.TYPE = 1  )",ApplyChange::getDelNum)
                 .select("( select count(1) from apply_chagne_detail ad where t.id = ad.APPLY_CHANGE_ID and ad.TYPE = 2  )",ApplyChange::getChangeNum)

--
Gitblit v1.9.3