|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.beust.jcommander.internal.Lists;
|
|
|
import com.microsvc.toolkit.common.webportal.exception.BizException;
|
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.MemberPriceSettingsDao;
|
|
@@ -248,9 +249,12 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<VipCardRecord> getEfficientVipRecord(Long userId, ClientEnum clientEnum) {
|
|
|
+ public List<VipCardRecord> getEfficientVipRecord(List<Long> userId, ClientEnum clientEnum) {
|
|
|
+ if (CollectionUtils.isEmpty(userId)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
return this.lambdaQuery()
|
|
|
- .eq(VipCardRecord::getUserId, userId)
|
|
|
+ .in(VipCardRecord::getUserId, userId)
|
|
|
.eq(VipCardRecord::getEfficientFlag, true)
|
|
|
.eq(VipCardRecord::getClientType, clientEnum.name())
|
|
|
.and(wrapper -> wrapper
|
|
@@ -272,7 +276,7 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
public VipCardRecordWrapper.UserVip UserVipInfo(Long userId, ClientEnum clientEnum) {
|
|
|
// 获取生效中的会员记录
|
|
|
VipCardRecordWrapper.UserVip userVip = new VipCardRecordWrapper.UserVip();
|
|
|
- List<VipCardRecord> vipCardRecords = this.getEfficientVipRecord(userId,clientEnum);
|
|
|
+ List<VipCardRecord> vipCardRecords = this.getEfficientVipRecord(Lists.newArrayList(userId),clientEnum);
|
|
|
if (CollectionUtils.isEmpty(vipCardRecords)) {
|
|
|
userVip.setVipType(EVipType.NOT_VIP);
|
|
|
// 判断有没有过期的会员类型
|
|
@@ -371,14 +375,41 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<Long, EVipType> getVipTypeMapByUserIds(List<Long> studentIds, ClientEnum client) {
|
|
|
+
|
|
|
+ List<VipCardRecord> vipCardRecords = this.getEfficientVipRecord(studentIds,client);
|
|
|
+
|
|
|
+ // 根据用户ID分组
|
|
|
+ Map<Long, List<VipCardRecord>> vipCardRecordMap = vipCardRecords.stream().collect(Collectors.groupingBy(VipCardRecord::getUserId));
|
|
|
+ Map<Long, EVipType> vipTypeMap = new HashMap<>();
|
|
|
+ vipCardRecordMap.forEach((k, v) -> {
|
|
|
+ List<VipCardRecord> svipList = v.stream().filter(o -> o.getVipType() == EVipType.SVIP).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(svipList)) {
|
|
|
+ vipTypeMap.put(k, EVipType.SVIP);
|
|
|
+ } else {
|
|
|
+ List<VipCardRecord> vipList = v.stream().filter(o -> o.getVipType() == EVipType.VIP).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(vipList)) {
|
|
|
+ vipTypeMap.put(k, EVipType.VIP);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return vipTypeMap;
|
|
|
+ }
|
|
|
+
|
|
|
// 会员添加
|
|
|
private void addVip(VipCardRecordWrapper.AddVipCardRecord addVipCardRecord) {
|
|
|
List<VipCardRecord> vipCardRecordList = this.lambdaQuery()
|
|
|
.eq(VipCardRecord::getClientType, addVipCardRecord.getClientType())
|
|
|
.eq(VipCardRecord::getUserId, addVipCardRecord.getUserId())
|
|
|
- .ge(VipCardRecord::getEndTime, new Date())
|
|
|
+// .ge(VipCardRecord::getEndTime, new Date())
|
|
|
.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();
|
|
|
List<VipCardRecord> perpetualRecords = vipCardRecordList.stream()
|
|
@@ -388,7 +419,8 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
throw new BizException("已经是永久会员");
|
|
|
}
|
|
|
|
|
|
- Date startTime = new Date();
|
|
|
+ Date now = new Date();
|
|
|
+ Date startTime = now;
|
|
|
// 没有会员信息
|
|
|
if (vipCardRecordList.isEmpty()) {
|
|
|
PeriodEnum period = addVipCardRecord.getType();
|
|
@@ -405,39 +437,39 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 存在会员信息
|
|
|
+ // 找到插入数据的位置
|
|
|
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()));
|
|
|
+ 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());
|
|
|
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;
|
|
|
if (plusMills > 0L) {
|
|
|
VipCardRecord addRecord = JSON.parseObject(JSON.toJSONString(vipCardRecord), VipCardRecord.class);
|
|
|
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.setEfficientFlag(true);
|
|
|
save(addRecord);
|