| 
														
															@@ -402,9 +402,14 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         List<VipCardRecord> vipCardRecordList = this.lambdaQuery() 
														 | 
														
														 | 
														
															         List<VipCardRecord> vipCardRecordList = this.lambdaQuery() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 .eq(VipCardRecord::getClientType, addVipCardRecord.getClientType()) 
														 | 
														
														 | 
														
															                 .eq(VipCardRecord::getClientType, addVipCardRecord.getClientType()) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 .eq(VipCardRecord::getUserId, addVipCardRecord.getUserId()) 
														 | 
														
														 | 
														
															                 .eq(VipCardRecord::getUserId, addVipCardRecord.getUserId()) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                .ge(VipCardRecord::getEndTime, new Date()) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+//                .ge(VipCardRecord::getEndTime, new Date()) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 .eq(VipCardRecord::getEfficientFlag, true) 
														 | 
														
														 | 
														
															                 .eq(VipCardRecord::getEfficientFlag, true) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                .list(); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                .list() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                .stream() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                .filter(n -> n.getEndTime() == null || n.getEndTime().after(new Date())) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                .sorted(Comparator.comparing(VipCardRecord::getStartTime)) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                .collect(Collectors.toList()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															         EVipType addVipType = addVipCardRecord.getVipType(); 
														 | 
														
														 | 
														
															         EVipType addVipType = addVipCardRecord.getVipType(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         List<VipCardRecord> perpetualRecords = vipCardRecordList.stream() 
														 | 
														
														 | 
														
															         List<VipCardRecord> perpetualRecords = vipCardRecordList.stream() 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -414,7 +419,8 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             throw new BizException("已经是永久会员"); 
														 | 
														
														 | 
														
															             throw new BizException("已经是永久会员"); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         } 
														 | 
														
														 | 
														
															         } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        Date startTime = new Date(); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        Date now = new Date(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        Date startTime = now; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         // 没有会员信息 
														 | 
														
														 | 
														
															         // 没有会员信息 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         if (vipCardRecordList.isEmpty()) { 
														 | 
														
														 | 
														
															         if (vipCardRecordList.isEmpty()) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             PeriodEnum period = addVipCardRecord.getType(); 
														 | 
														
														 | 
														
															             PeriodEnum period = addVipCardRecord.getType(); 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -431,39 +437,39 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             return; 
														 | 
														
														 | 
														
															             return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         } 
														 | 
														
														 | 
														
															         } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        // 存在会员信息 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        // 找到插入数据的位置 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         int index = 0; 
														 | 
														
														 | 
														
															         int index = 0; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        for (int i = 0; i < vipCardRecordList.size(); i++) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            VipCardRecord vipCardRecord = vipCardRecordList.get(i); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            if (vipCardRecord.getVipType().equals(addVipType)) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                index = i; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                startTime = vipCardRecord.getEndTime(); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        if (addVipType.equals(EVipType.VIP)) { // vip 放到最后 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            index = vipCardRecordList.size(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            startTime = vipCardRecordList.stream().map(VipCardRecord::getEndTime).max(Date::compareTo).get(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        if (addVipType.equals(EVipType.SVIP)) { //放到VIP的前面 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            index = (int) vipCardRecordList.stream().filter(n -> EVipType.SVIP.equals(n.getVipType())).count(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            if (index > 0) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                startTime = vipCardRecordList.stream().filter(n -> EVipType.SVIP.equals(n.getVipType())).map(VipCardRecord::getEndTime).max(Date::compareTo).get(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             } 
														 | 
														
														 | 
														
															             } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         } 
														 | 
														
														 | 
														
															         } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         Date endDate = plusDate(startTime, addVipCardRecord.getType(), Long.valueOf(addVipCardRecord.getTimes())); 
														 | 
														
														 | 
														
															         Date endDate = plusDate(startTime, addVipCardRecord.getType(), Long.valueOf(addVipCardRecord.getTimes())); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        VipCardRecord newRecord = JSON.parseObject(JSON.toJSONString(addVipCardRecord), VipCardRecord.class); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        newRecord.setSourceType(SourceTypeEnum.BACKEND_GIVE); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        newRecord.setStatus(EVipRecordStatus.ADD); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        newRecord.setStartTime(startTime); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        newRecord.setEndTime(endDate); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        newRecord.setDisplayFlag(true); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        newRecord.setEfficientFlag(true); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        save(newRecord); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         // 平移时间 
														 | 
														
														 | 
														
															         // 平移时间 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         long plusMills = endDate == null ? 0L : (endDate.getTime() - startTime.getTime()); 
														 | 
														
														 | 
														
															         long plusMills = endDate == null ? 0L : (endDate.getTime() - startTime.getTime()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         for (int i = 0; i < vipCardRecordList.size(); i++) { 
														 | 
														
														 | 
														
															         for (int i = 0; i < vipCardRecordList.size(); i++) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            if (index == i) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                VipCardRecord addRecord = JSON.parseObject(JSON.toJSONString(addVipCardRecord), VipCardRecord.class); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                addRecord.setSourceType(SourceTypeEnum.BACKEND_GIVE); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                addRecord.setStatus(EVipRecordStatus.ADD); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                addRecord.setStartTime(startTime); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                addRecord.setEndTime(endDate); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                addRecord.setDisplayFlag(true); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                addRecord.setEfficientFlag(true); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                save(addRecord); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            } 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            if (i > index) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                VipCardRecord vipCardRecord = vipCardRecordList.get(i); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            VipCardRecord vipCardRecord = vipCardRecordList.get(i); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            if (i >= index) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 Long refId = null; 
														 | 
														
														 | 
														
															                 Long refId = null; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 if (plusMills > 0L) { 
														 | 
														
														 | 
														
															                 if (plusMills > 0L) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     VipCardRecord addRecord = JSON.parseObject(JSON.toJSONString(vipCardRecord), VipCardRecord.class); 
														 | 
														
														 | 
														
															                     VipCardRecord addRecord = JSON.parseObject(JSON.toJSONString(vipCardRecord), VipCardRecord.class); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     addRecord.setStatus(EVipRecordStatus.UPDATE); 
														 | 
														
														 | 
														
															                     addRecord.setStatus(EVipRecordStatus.UPDATE); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    addRecord.setStartTime(new Date(vipCardRecord.getStartTime().getTime() - plusMills)); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    addRecord.setEndTime(new Date(vipCardRecord.getEndTime().getTime() - plusMills)); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    addRecord.setStartTime(new Date(Math.max(vipCardRecord.getStartTime().getTime(), now.getTime()) + plusMills)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    addRecord.setEndTime(new Date(vipCardRecord.getEndTime().getTime() + plusMills)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     addRecord.setDisplayFlag(false); 
														 | 
														
														 | 
														
															                     addRecord.setDisplayFlag(false); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     addRecord.setEfficientFlag(true); 
														 | 
														
														 | 
														
															                     addRecord.setEfficientFlag(true); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     save(addRecord); 
														 | 
														
														 | 
														
															                     save(addRecord); 
														 |