|
@@ -9,29 +9,29 @@ import com.microsvc.toolkit.common.webportal.exception.BizException;
|
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.MemberPriceSettingsDao;
|
|
|
import com.yonge.cooleshow.biz.dal.dto.search.VipRecordSearch;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.ActivityReward;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.MemberPriceSettings;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.Student;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.*;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.*;
|
|
|
import com.yonge.cooleshow.biz.dal.service.*;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.*;
|
|
|
+import com.yonge.cooleshow.biz.dal.wrapper.DiscountCardRecordWrapper;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.VipCardRecordWrapper;
|
|
|
import com.yonge.toolset.base.page.PageInfo;
|
|
|
import com.yonge.toolset.mybatis.support.PageUtil;
|
|
|
import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.yonge.toolset.utils.date.DateUtil;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.VipCardRecord;
|
|
|
import com.yonge.cooleshow.biz.dal.dto.search.VipCardRecordSearch;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.VipCardRecordDao;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
@@ -425,13 +425,39 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
Integer vipDays = addVipCardRecord.getVipDays();
|
|
|
// 存在转换,先扣除,再添加
|
|
|
if (vipDays != null && vipDays > 0) {
|
|
|
- VipCardRecordWrapper.AddVipCardRecord dedectRecord = JSON.parseObject(JSON.toJSONString(addVipCardRecord), VipCardRecordWrapper.AddVipCardRecord.class);
|
|
|
- dedectRecord.setStatus(EVipRecordStatus.DEDUCTION);
|
|
|
- dedectRecord.setVipType(EVipType.VIP);
|
|
|
- dedectRecord.setType(PeriodEnum.DAY);
|
|
|
- dedectRecord.setTimes(vipDays);
|
|
|
- dedectRecord.setReason("后台转换扣减");
|
|
|
- deductVip(dedectRecord);
|
|
|
+
|
|
|
+ // 转换的 ,找到转换的记录,设置为失效,修改时间,添加一条转换后的记录 订单与添加转换订单一致
|
|
|
+ List<VipCardRecord> vipCardRecords = getVipCardRecords(addVipCardRecord.getUserId(), clientType, Lists.newArrayList(EVipType.VIP));
|
|
|
+ int vipDaysNum = vipDays;
|
|
|
+ if (CollectionUtils.isNotEmpty(vipCardRecords)) {
|
|
|
+ // 根据结束时间正序
|
|
|
+ vipCardRecords.sort(Comparator.comparing(VipCardRecord::getEndTime));
|
|
|
+ List<VipCardRecord> vipCardRecordList = new ArrayList<>();
|
|
|
+ for (VipCardRecord vipCardRecord : vipCardRecords) {
|
|
|
+ int i = DateUtil.daysBetweenUp(vipCardRecord.getStartTime(), vipCardRecord.getEndTime());
|
|
|
+ VipCardRecord record = new VipCardRecord();
|
|
|
+ record.setId(vipCardRecord.getId());
|
|
|
+ if (vipDaysNum == 0) {
|
|
|
+ record.setStartTime(addTime(vipCardRecord.getStartTime(), PeriodEnum.DAY, -vipDaysNum,0));
|
|
|
+ record.setEndTime(addTime(vipCardRecord.getEndTime(), PeriodEnum.DAY, -vipDaysNum,1));
|
|
|
+ } else if (i > vipDaysNum) {
|
|
|
+ record.setEndTime(addTime(vipCardRecord.getEndTime(), PeriodEnum.DAY, -vipDaysNum,1));
|
|
|
+ record.setEfficientFlag(true);
|
|
|
+ record.setDisplayFlag(true);
|
|
|
+ record.setReason("后台转换扣减");
|
|
|
+ record.setUpdateTime(new Date());
|
|
|
+ } else {
|
|
|
+ record.setEfficientFlag(false);
|
|
|
+ record.setDeductionStatus(EDeductionStatus.EXPIRED);
|
|
|
+ record.setUpdateTime(new Date());
|
|
|
+ record.setReason("后台转换扣减");
|
|
|
+ vipDaysNum = vipDaysNum - i;
|
|
|
+ }
|
|
|
+ vipCardRecordList.add(record);
|
|
|
+ }
|
|
|
+ this.updateBatchById(vipCardRecordList);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
VipCardRecordWrapper.AddVipCardRecord addRecord = JSON.parseObject(JSON.toJSONString(addVipCardRecord), VipCardRecordWrapper.AddVipCardRecord.class);
|
|
|
addRecord.setStatus(EVipRecordStatus.ADD);
|
|
@@ -451,7 +477,8 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
}
|
|
|
|
|
|
if (Boolean.TRUE.equals(addVipCardRecord.getSendMsg())) {
|
|
|
- sendAddVipMsg(addVipCardRecord);
|
|
|
+ sendAddVipMsg(addVipCardRecord.getUserId(),addVipCardRecord.getClientType(),addVipCardRecord.getStatus(),
|
|
|
+ addVipCardRecord.getVipType(),addVipCardRecord.getType(),addVipCardRecord.getTimes(),addVipCardRecord.getReason());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -480,38 +507,17 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
// 会员添加
|
|
|
@Override
|
|
|
public VipCardRecord addVip(VipCardRecordWrapper.AddVipCardRecord addVipCardRecord) {
|
|
|
- List<VipCardRecord> vipCardRecordList = this.lambdaQuery()
|
|
|
- .eq(VipCardRecord::getClientType, addVipCardRecord.getClientType())
|
|
|
- .eq(VipCardRecord::getUserId, addVipCardRecord.getUserId())
|
|
|
- .ge(VipCardRecord::getEndTime, new Date())
|
|
|
- .eq(VipCardRecord::getEfficientFlag, true)
|
|
|
- .list()
|
|
|
- .stream()
|
|
|
-// .filter(n -> n.getEndTime() == null || n.getEndTime().after(new Date()))
|
|
|
- .sorted(Comparator.comparing(VipCardRecord::getStartTime))
|
|
|
- .collect(Collectors.toList());
|
|
|
+ List<VipCardRecord> vipCardRecordList = getVipCardRecords(addVipCardRecord.getUserId(),addVipCardRecord.getClientType(), Lists.newArrayList(EVipType.VIP,EVipType.SVIP));
|
|
|
|
|
|
|
|
|
EVipType addVipType = addVipCardRecord.getVipType();
|
|
|
-// List<VipCardRecord> perpetualRecords = vipCardRecordList.stream()
|
|
|
-// .filter(n -> n.getVipType().equals(addVipType) && PeriodEnum.PERPETUAL.equals(n.getType()))
|
|
|
-// .collect(Collectors.toList());
|
|
|
-// if (!perpetualRecords.isEmpty()) {
|
|
|
-// throw new BizException("已经是永久会员");
|
|
|
-// }
|
|
|
|
|
|
Date now = new Date();
|
|
|
- long startTimeMills = now.getTime();
|
|
|
+ Date startDate = now;
|
|
|
// 没有会员信息
|
|
|
if (vipCardRecordList.isEmpty()) {
|
|
|
PeriodEnum period = addVipCardRecord.getType();
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(now);
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 23);
|
|
|
- calendar.set(Calendar.MINUTE, 59);
|
|
|
- calendar.set(Calendar.SECOND, 59);
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
- Date endDate = plusDate(calendar.getTime(), period, Long.valueOf(addVipCardRecord.getTimes()));
|
|
|
+
|
|
|
|
|
|
VipCardRecord addRecord = JSON.parseObject(JSON.toJSONString(addVipCardRecord), VipCardRecord.class);
|
|
|
addRecord.setSourceType(addVipCardRecord.getSourceType() !=null?addVipCardRecord.getSourceType():SourceTypeEnum.BACKEND_GIVE);
|
|
@@ -519,74 +525,86 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
addRecord.setDisplayFlag(true);
|
|
|
addRecord.setEfficientFlag(true);
|
|
|
addRecord.setStartTime(now);
|
|
|
- addRecord.setEndTime(endDate);
|
|
|
+ addRecord.setVersion(2);
|
|
|
+ addRecord.setEndTime(addTime(addRecord.getStartTime(), period, addRecord.getTimes(),1));
|
|
|
+ formatVipRecordTime(addRecord);
|
|
|
+
|
|
|
+ addRecord.setEstimatedEndTime(addRecord.getEndTime());
|
|
|
+ addRecord.setEstimatedStartTime(addRecord.getStartTime());
|
|
|
return addRecord;
|
|
|
}
|
|
|
|
|
|
- // 找到插入数据的位置
|
|
|
- int index = 0;
|
|
|
if (addVipType.equals(EVipType.VIP)) { // vip 放到最后
|
|
|
- index = vipCardRecordList.size();
|
|
|
- startTimeMills = vipCardRecordList.stream().map(VipCardRecord::getEndTime).max(Date::compareTo).get().getTime() + 1000L;
|
|
|
- }
|
|
|
- if (addVipType.equals(EVipType.SVIP)) { //放到VIP的前面
|
|
|
- index = (int) vipCardRecordList.stream().filter(n -> EVipType.SVIP.equals(n.getVipType()) && !PeriodEnum.PERPETUAL.equals(n.getType())).count();
|
|
|
- if (index > 0) {
|
|
|
- startTimeMills = vipCardRecordList.stream().filter(n -> EVipType.SVIP.equals(n.getVipType()) && !PeriodEnum.PERPETUAL.equals(n.getType()))
|
|
|
- .map(VipCardRecord::getEndTime).max(Date::compareTo).get().getTime() + 1000;
|
|
|
+ startDate = vipCardRecordList.stream().map(VipCardRecord::getEndTime).max(Date::compareTo).get();
|
|
|
+ } else if (addVipType.equals(EVipType.SVIP)) { //放到VIP的前面
|
|
|
+ Optional<VipCardRecord> max = vipCardRecordList.stream().filter(o -> o.getVipType().equals(EVipType.SVIP)).max(Comparator.comparing(VipCardRecord::getEndTime));
|
|
|
+ if (max.isPresent()) {
|
|
|
+ startDate = max.get().getEndTime();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
VipCardRecord newRecord = JSON.parseObject(JSON.toJSONString(addVipCardRecord), VipCardRecord.class);
|
|
|
newRecord.setSourceType(addVipCardRecord.getSourceType() !=null?addVipCardRecord.getSourceType():SourceTypeEnum.BACKEND_GIVE);
|
|
|
newRecord.setStatus(EVipRecordStatus.ADD);
|
|
|
- newRecord.setStartTime(new Date(startTimeMills));
|
|
|
- if (index == 0) { // 当天剩余时间属于赠送
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(new Date(startTimeMills));
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 23);
|
|
|
- calendar.set(Calendar.MINUTE, 59);
|
|
|
- calendar.set(Calendar.SECOND, 59);
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
- Date endDate = plusDate(calendar.getTime(), addVipCardRecord.getType(), Long.valueOf(addVipCardRecord.getTimes()));
|
|
|
- newRecord.setEndTime(new Date(endDate.getTime()));
|
|
|
- } else {
|
|
|
- Date endDate = plusDate(new Date(startTimeMills - 1000), addVipCardRecord.getType(), Long.valueOf(addVipCardRecord.getTimes()));
|
|
|
- newRecord.setEndTime(endDate);
|
|
|
- }
|
|
|
+ newRecord.setStartTime(startDate);
|
|
|
+ newRecord.setEndTime(addTime(newRecord.getStartTime(), addVipCardRecord.getType(), addVipCardRecord.getTimes(),1));
|
|
|
|
|
|
newRecord.setDisplayFlag(true);
|
|
|
newRecord.setEfficientFlag(true);
|
|
|
|
|
|
- // 平移时间
|
|
|
-// long plusMills = newRecord.getEndTime().getTime() - startTimeMills;
|
|
|
- long beforeEndTime = newRecord.getEndTime().getTime();
|
|
|
- for (int i = 0; i < vipCardRecordList.size(); i++) {
|
|
|
- VipCardRecord vipCardRecord = vipCardRecordList.get(i);
|
|
|
- if (i >= index) {
|
|
|
- VipCardRecord addRecord = JSON.parseObject(JSON.toJSONString(vipCardRecord), VipCardRecord.class);
|
|
|
- addRecord.setStatus(EVipRecordStatus.UPDATE);
|
|
|
-
|
|
|
- addRecord.setStartTime(new Date(beforeEndTime + 1000));
|
|
|
-
|
|
|
-// int days = (int) Math.ceil(plusMills * 1.0D / (24 * 60 * 60 * 1000));
|
|
|
- Date endTime = plusDate(vipCardRecord.getEndTime(), addVipCardRecord.getType(), addVipCardRecord.getTimes());
|
|
|
- addRecord.setEndTime(endTime);
|
|
|
- addRecord.setDisplayFlag(false);
|
|
|
- addRecord.setEfficientFlag(true);
|
|
|
- save(addRecord);
|
|
|
- Long refId = addRecord.getId();
|
|
|
+ // 如果是SVIP,平移VIP
|
|
|
+ List<VipCardRecord> vipList = vipCardRecordList.stream().filter(o -> o.getVipType() == EVipType.VIP).collect(Collectors.toList());
|
|
|
+ if (addVipType.equals(EVipType.SVIP) && CollectionUtils.isNotEmpty(vipList)) {
|
|
|
+ // 更新开始时间/结束时间
|
|
|
+ List<VipCardRecord> updateList = new ArrayList<>();
|
|
|
+ for (VipCardRecord vipCardRecord : vipList) {
|
|
|
+ formatVipRecordTime(vipCardRecord);
|
|
|
+
|
|
|
+ // 如果开始时间小于当前时间, 切分过去的时间为一段记录,并且不显示,剩余的时间为一段记录,标记为显示并且生效中
|
|
|
+ if (vipCardRecord.getStartTime().before(now)) {
|
|
|
+ VipCardRecord record = JSON.parseObject(JSON.toJSONString(vipCardRecord), VipCardRecord.class);
|
|
|
+ record.setStartTime(vipCardRecord.getStartTime());
|
|
|
+ record.setEndTime(addTime(new Date(),PeriodEnum.DAY,-1,1));
|
|
|
+ record.setEfficientFlag(true);
|
|
|
+ record.setDeductionStatus(EDeductionStatus.EXPIRED);
|
|
|
+ record.setDisplayFlag(false);
|
|
|
+ record.setVersion(2);
|
|
|
+ save(record);
|
|
|
+ vipCardRecord.setStartTime(addTime(new Date(),PeriodEnum.DAY,0,0));
|
|
|
+ }
|
|
|
|
|
|
- VipCardRecord updateRecord = JSON.parseObject(JSON.toJSONString(vipCardRecord), VipCardRecord.class);
|
|
|
- updateRecord.setEfficientFlag(false);
|
|
|
- updateRecord.setRefId(refId);
|
|
|
- updateById(updateRecord);
|
|
|
- beforeEndTime = endTime.getTime();
|
|
|
+ VipCardRecord record = new VipCardRecord();
|
|
|
+ record.setStartTime(addTime(vipCardRecord.getStartTime(), addVipCardRecord.getType(), addVipCardRecord.getTimes(),0));
|
|
|
+ record.setEndTime(addTime(vipCardRecord.getEndTime(), addVipCardRecord.getType(), addVipCardRecord.getTimes(),1));
|
|
|
+
|
|
|
+ record.setId(vipCardRecord.getId());
|
|
|
+ updateList.add(record);
|
|
|
}
|
|
|
+ updateBatchById(updateList);
|
|
|
}
|
|
|
+ newRecord.setDeductionStatus(EDeductionStatus.EFFECTIVE);
|
|
|
+ newRecord.setVersion(2);
|
|
|
+ formatVipRecordTime(newRecord);
|
|
|
+ newRecord.setEstimatedEndTime(newRecord.getEndTime());
|
|
|
+ newRecord.setEstimatedStartTime(newRecord.getStartTime());
|
|
|
return newRecord;
|
|
|
}
|
|
|
|
|
|
+ @NotNull
|
|
|
+ private List<VipCardRecord> getVipCardRecords(Long userId,ClientEnum client, List<EVipType> vipTypes) {
|
|
|
+ List<VipCardRecord> vipCardRecordList = this.lambdaQuery()
|
|
|
+ .eq(VipCardRecord::getClientType, client)
|
|
|
+ .eq(VipCardRecord::getUserId, userId)
|
|
|
+ .in(CollectionUtils.isNotEmpty(vipTypes),VipCardRecord::getVipType, vipTypes)
|
|
|
+ .ge(VipCardRecord::getEndTime, new Date())
|
|
|
+ .eq(VipCardRecord::getEfficientFlag, true)
|
|
|
+ .list()
|
|
|
+ .stream()
|
|
|
+ .sorted(Comparator.comparing(VipCardRecord::getStartTime))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return vipCardRecordList;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<VipCardRecordWrapper.UserVipInfo> queryUserVipInfo(List<Long> userIdList, String clientType) {
|
|
|
List<VipCardRecordWrapper.UserVipInfo> userVipInfos = baseMapper.queryUserVipInfo(userIdList, clientType);
|
|
@@ -603,19 +621,147 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 扣减会员
|
|
|
+ *
|
|
|
+ * @param result
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void deduction(VipCardRecordWrapper.DeductionVipCardRecord result) {
|
|
|
+
|
|
|
+ // 查找被扣除的记录
|
|
|
+ VipCardRecord record = this.getById(result.getRecordId());
|
|
|
+ if (record == null) {
|
|
|
+ throw new BizException("记录不存在");
|
|
|
+ }
|
|
|
+ if (record.getDeductionTime() != null) {
|
|
|
+ throw new BizException("记录已扣除");
|
|
|
+ }
|
|
|
+ Date endTime = record.getEndTime();
|
|
|
+ if (endTime.before(new Date())) {
|
|
|
+ throw new BizException("记录已过期");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取 剩余时长
|
|
|
+ int days =0;
|
|
|
+ if (record.getStartTime().before(new Date())) {
|
|
|
+ days = DateUtil.daysBetweenUp(new Date(), endTime);
|
|
|
+ } else {
|
|
|
+ days = DateUtil.daysBetweenUp(record.getStartTime(), endTime);
|
|
|
+ }
|
|
|
+ VipCardRecord vipCardRecord = new VipCardRecord();
|
|
|
+ vipCardRecord.setId(record.getId());
|
|
|
+ vipCardRecord.setDeductionTime(new Date());
|
|
|
+ vipCardRecord.setDeductionReason(result.getReason());
|
|
|
+ vipCardRecord.setEndTime(addTime(record.getEndTime(), PeriodEnum.DAY, -days,1));
|
|
|
+ vipCardRecord.setDeductionBy(result.getCreateBy());
|
|
|
+ vipCardRecord.setDeductionStatus(EDeductionStatus.DEDUCT);
|
|
|
+ if (record.getStartTime().after(record.getEndTime())) {
|
|
|
+ vipCardRecord.setEfficientFlag(false);
|
|
|
+ }
|
|
|
+ this.updateById(vipCardRecord);
|
|
|
+
|
|
|
+ // 对比剩余天数
|
|
|
+
|
|
|
+ // 获取其他有效的记录
|
|
|
+ List<VipCardRecord> list = this.lambdaQuery()
|
|
|
+ .eq(VipCardRecord::getUserId, record.getUserId())
|
|
|
+ .gt(VipCardRecord::getEndTime, endTime)
|
|
|
+ .eq(VipCardRecord::getEfficientFlag, 1)
|
|
|
+ .list();
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ List<VipCardRecord> updateList = new ArrayList<>();
|
|
|
+ for (VipCardRecord vipCardRecord1 : list) {
|
|
|
+ VipCardRecord cardRecord = new VipCardRecord();
|
|
|
+ cardRecord.setId(vipCardRecord1.getId());
|
|
|
+ cardRecord.setStartTime(addTime(vipCardRecord1.getStartTime(), PeriodEnum.DAY, -days,0));
|
|
|
+ cardRecord.setEndTime(addTime(vipCardRecord1.getEndTime(), PeriodEnum.DAY, -days,1));
|
|
|
+ updateList.add(cardRecord);
|
|
|
+ }
|
|
|
+ this.updateBatchById(updateList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (Boolean.TRUE.equals(result.getSendMsg())) {
|
|
|
+ sendAddVipMsg(record.getUserId(),record.getClientType(),EVipRecordStatus.DEDUCTION,
|
|
|
+ record.getVipType(),record.getType(),record.getTimes(),result.getReason());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 获取会员信息
|
|
|
+ *
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public VipCardRecordWrapper.Info info(VipCardRecordWrapper.InfoQuery infoQuery) {
|
|
|
+ VipCardRecordWrapper.Info info = new VipCardRecordWrapper.Info();
|
|
|
+
|
|
|
+ // 所有的会员重新生成
|
|
|
+ List<VipCardRecord> vipCardRecordList = getVipCardRecords(infoQuery.getUserId(),infoQuery.getClient(), Lists.newArrayList(EVipType.VIP,EVipType.SVIP));
|
|
|
+ if (CollectionUtils.isEmpty(vipCardRecordList)) {
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+ // 过滤出会员
|
|
|
+ List<VipCardRecord> vipList = vipCardRecordList.stream().filter(o -> o.getVipType() == EVipType.VIP).collect(Collectors.toList());
|
|
|
+ // 计算天数
|
|
|
+ int vipDays = 0;
|
|
|
+ if (CollectionUtils.isNotEmpty(vipList)) {
|
|
|
+ vipDays = vipList.stream().mapToInt(o -> DateUtil.daysBetweenUp(o.getStartTime(), o.getEndTime())).sum();
|
|
|
+ }
|
|
|
+ info.setSurplusVipDay(vipDays);
|
|
|
+ // 过滤出SVIP
|
|
|
+ List<VipCardRecord> svipList = vipCardRecordList.stream().filter(o -> o.getVipType() == EVipType.SVIP && o.getType() !=PeriodEnum.PERPETUAL).collect(Collectors.toList());
|
|
|
+ // 计算天数
|
|
|
+ int svipDays = 0;
|
|
|
+ if (CollectionUtils.isNotEmpty(svipList)) {
|
|
|
+ svipDays = svipList.stream().mapToInt(o -> DateUtil.daysBetweenUp(o.getStartTime(), o.getEndTime())).sum();
|
|
|
+ }
|
|
|
+ info.setSurplusSvipDay(svipDays);
|
|
|
+ // 过滤出永久SVIP
|
|
|
+ List<VipCardRecord> svipPerpetualList = vipCardRecordList.stream().filter(o -> o.getVipType() == EVipType.SVIP && o.getType() ==PeriodEnum.PERPETUAL).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(svipPerpetualList)) {
|
|
|
+ info.setPerpetualFlag(true);
|
|
|
+ }
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<VipCardRecordWrapper.VipCardRecord> selectAdminPage(IPage<VipCardRecordWrapper.VipCardRecord> page, VipCardRecordWrapper.VipQuery query) {
|
|
|
+ IPage<VipCardRecordWrapper.VipCardRecord> vipCardRecordIPage = baseMapper.selectAdminPage(page, query);
|
|
|
+ List<VipCardRecordWrapper.VipCardRecord> records = vipCardRecordIPage.getRecords();
|
|
|
+ if (CollectionUtils.isEmpty(records)) {
|
|
|
+ return vipCardRecordIPage;
|
|
|
+ }
|
|
|
+ // 创建人ID集合
|
|
|
+ List<Long> createByList = records.stream()
|
|
|
+ .map(VipCardRecordWrapper.VipCardRecord::getOperatorId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
+ Map<Long, com.yonge.cooleshow.biz.dal.entity.SysUser> userMap = sysUserService.getMapByIds(createByList);
|
|
|
+ records.forEach(vipCardRecord -> {
|
|
|
+
|
|
|
+ if (vipCardRecord.getStartTime().before(new Date())) {
|
|
|
+ vipCardRecord.setSurplusDay(DateUtil.daysBetweenUp(new Date(), vipCardRecord.getEndTime()));
|
|
|
+ } else {
|
|
|
+ vipCardRecord.setSurplusDay(DateUtil.daysBetweenUp(vipCardRecord.getStartTime(), vipCardRecord.getEndTime()));
|
|
|
+ }
|
|
|
+
|
|
|
+ com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = userMap.get(vipCardRecord.getOperatorId());
|
|
|
+ if (sysUser != null) {
|
|
|
+ vipCardRecord.setOperatorName(sysUser.getRealName());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return vipCardRecordIPage;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// 会员扣减
|
|
|
private VipCardRecord deductVip(VipCardRecordWrapper.AddVipCardRecord addVipCardRecord) {
|
|
|
|
|
|
// 所有的会员重新生成
|
|
|
- List<VipCardRecord> vipCardRecordList = this.lambdaQuery()
|
|
|
- .eq(VipCardRecord::getClientType, addVipCardRecord.getClientType())
|
|
|
- .eq(VipCardRecord::getUserId, addVipCardRecord.getUserId())
|
|
|
- .ge(VipCardRecord::getEndTime, new Date())
|
|
|
- .eq(VipCardRecord::getEfficientFlag, true)
|
|
|
- .list()
|
|
|
- .stream()
|
|
|
- .sorted(Comparator.comparing(VipCardRecord::getStartTime))
|
|
|
- .collect(Collectors.toList());
|
|
|
+ List<VipCardRecord> vipCardRecordList = getVipCardRecords(addVipCardRecord.getUserId(),addVipCardRecord.getClientType(), Lists.newArrayList(EVipType.VIP,EVipType.SVIP));
|
|
|
|
|
|
// 当前类型的VIP
|
|
|
PeriodEnum period = addVipCardRecord.getType();
|
|
@@ -878,19 +1024,16 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
}
|
|
|
|
|
|
// 添加、扣除会员发送推送
|
|
|
- private void sendAddVipMsg(VipCardRecordWrapper.AddVipCardRecord addVipCardRecord) {
|
|
|
- SysUser sysUser = sysUserService.getByUserId(addVipCardRecord.getUserId());
|
|
|
+ private void sendAddVipMsg(Long userId,ClientEnum client,EVipRecordStatus status,EVipType vipType,PeriodEnum period,Integer times,String reason) {
|
|
|
+ SysUser sysUser = sysUserService.getByUserId(userId);
|
|
|
if (sysUser == null) {
|
|
|
return;
|
|
|
}
|
|
|
MessageTypeEnum messageTypeEnum;
|
|
|
- EVipRecordStatus status = addVipCardRecord.getStatus();
|
|
|
- EVipType vipType = addVipCardRecord.getVipType();
|
|
|
if (EVipRecordStatus.ADD.equals(status)) {
|
|
|
if (EVipType.VIP.equals(vipType)) {
|
|
|
messageTypeEnum = MessageTypeEnum.PLATFORM_ADD_VIP;
|
|
|
}else {
|
|
|
- PeriodEnum period = addVipCardRecord.getType();
|
|
|
if (PeriodEnum.PERPETUAL.equals(period)) {
|
|
|
messageTypeEnum = MessageTypeEnum.PLATFORM_ADD_PER_SVIP;
|
|
|
} else {
|
|
@@ -901,7 +1044,6 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
if (EVipType.VIP.equals(vipType)) {
|
|
|
messageTypeEnum = MessageTypeEnum.PLATFORM_ADD_DUDECT_VIP;
|
|
|
}else {
|
|
|
- PeriodEnum period = addVipCardRecord.getType();
|
|
|
if (PeriodEnum.PERPETUAL.equals(period)) {
|
|
|
messageTypeEnum = MessageTypeEnum.PLATFORM_ADD_DUDECT_PER_SVIP;
|
|
|
} else {
|
|
@@ -913,17 +1055,49 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
}
|
|
|
|
|
|
Map<Long, String> receivers = new HashMap<>();
|
|
|
- receivers.put(addVipCardRecord.getUserId(), sysUser.getPhone());
|
|
|
+ receivers.put(userId, sysUser.getPhone());
|
|
|
|
|
|
try {
|
|
|
sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, messageTypeEnum,
|
|
|
- receivers, null, 0, null, addVipCardRecord.getClientType().getCode(), String.valueOf(addVipCardRecord.getTimes()), addVipCardRecord.getType().getMsg(),
|
|
|
- addVipCardRecord.getReason());
|
|
|
+ receivers, null, 0, null, client.getCode(), String.valueOf(times), period.getMsg(),
|
|
|
+ reason);
|
|
|
} catch (Exception e) {
|
|
|
log.error("会员添加消息发送失败 : {}", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ private Date addTime(Date time, PeriodEnum period, Integer times, int type) {
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.setTime(time);
|
|
|
+
|
|
|
+ if (PeriodEnum.DAY.equals(period)) {
|
|
|
+ cal.add(Calendar.DAY_OF_MONTH, times);
|
|
|
+ } else if (PeriodEnum.MONTH.equals(period)) {
|
|
|
+ cal.add(Calendar.MONTH, times);
|
|
|
+ } else if (PeriodEnum.YEAR.equals(period)) {
|
|
|
+ cal.add(Calendar.YEAR, times);
|
|
|
+ } else if (PeriodEnum.QUARTERLY.equals(period)) {
|
|
|
+ cal.add(Calendar.MONTH, times * 3);
|
|
|
+ } else if (PeriodEnum.YEAR_HALF.equals(period)) {
|
|
|
+ cal.add(Calendar.MONTH, times * 6);
|
|
|
+ } else if (PeriodEnum.PERPETUAL.equals(period)) {
|
|
|
+ cal.add(Calendar.YEAR, 100);
|
|
|
+ }
|
|
|
+ if (type ==0) {
|
|
|
+ cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ cal.set(Calendar.MINUTE, 0);
|
|
|
+ cal.set(Calendar.SECOND, 0);
|
|
|
+ } else {
|
|
|
+ cal.set(Calendar.HOUR_OF_DAY, 23);
|
|
|
+ cal.set(Calendar.MINUTE, 59);
|
|
|
+ cal.set(Calendar.SECOND, 59);
|
|
|
+ cal.set(Calendar.MILLISECOND, 0);
|
|
|
+ }
|
|
|
+ cal.set(Calendar.MILLISECOND, 0);
|
|
|
+ return cal.getTime();
|
|
|
+ }
|
|
|
private Date formatEnd(Date date) {
|
|
|
Calendar c1 = Calendar.getInstance();
|
|
|
c1.setTime(date);
|
|
@@ -942,4 +1116,30 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
|
|
|
c1.set(Calendar.MILLISECOND, 0);
|
|
|
return c1.getTime();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public VipCardRecord formatVipRecordTime(VipCardRecord vipCardRecord) {
|
|
|
+ // 如果开始时间是23:59:59,开始时间改为第二天的00:00:00
|
|
|
+ LocalDateTime startTime = vipCardRecord.getStartTime().toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ if (startTime.toLocalTime().equals(LocalTime.of(23, 59, 59))) {
|
|
|
+ startTime = startTime.plusDays(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ startTime = startTime.withHour(0).withMinute(0).withSecond(0).withNano(0);
|
|
|
+ // 如果结束时间是00:00:00,开始时间改为前一天的23:59:59
|
|
|
+ LocalDateTime endTime = vipCardRecord.getEndTime().toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ if (endTime.toLocalTime().equals(LocalTime.of(0, 0, 0))) {
|
|
|
+ endTime = endTime.plusDays(-1);
|
|
|
+ }
|
|
|
+ endTime = endTime.withHour(23).withMinute(59).withSecond(59).withNano(0);
|
|
|
+ vipCardRecord.setStartTime(Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant()));
|
|
|
+ vipCardRecord.setEndTime(Date.from(endTime.atZone(ZoneId.systemDefault()).toInstant()));
|
|
|
+ if (vipCardRecord.getStartTime().after(vipCardRecord.getEndTime())) {
|
|
|
+ vipCardRecord.setEndTime(vipCardRecord.getStartTime());
|
|
|
+ }
|
|
|
+ return vipCardRecord;
|
|
|
+ }
|
|
|
}
|