|
@@ -11,16 +11,21 @@ import com.fs.live.domain.LiveConsoleOpLogUser;
|
|
|
import com.fs.live.domain.LiveCoupon;
|
|
import com.fs.live.domain.LiveCoupon;
|
|
|
import com.fs.live.domain.LiveCouponIssue;
|
|
import com.fs.live.domain.LiveCouponIssue;
|
|
|
import com.fs.live.domain.LiveCouponIssueRelation;
|
|
import com.fs.live.domain.LiveCouponIssueRelation;
|
|
|
|
|
+import com.fs.live.domain.LiveCouponIssueUser;
|
|
|
|
|
+import com.fs.live.domain.LiveCouponUser;
|
|
|
import com.fs.live.domain.LiveLotteryConf;
|
|
import com.fs.live.domain.LiveLotteryConf;
|
|
|
import com.fs.live.domain.LiveRedConf;
|
|
import com.fs.live.domain.LiveRedConf;
|
|
|
import com.fs.live.mapper.LiveConsoleOpLogMapper;
|
|
import com.fs.live.mapper.LiveConsoleOpLogMapper;
|
|
|
import com.fs.live.mapper.LiveConsoleOpLogUserMapper;
|
|
import com.fs.live.mapper.LiveConsoleOpLogUserMapper;
|
|
|
|
|
+import com.fs.live.mapper.LiveCouponIssueUserMapper;
|
|
|
import com.fs.live.mapper.LiveCouponMapper;
|
|
import com.fs.live.mapper.LiveCouponMapper;
|
|
|
import com.fs.live.mapper.LiveMapper;
|
|
import com.fs.live.mapper.LiveMapper;
|
|
|
import com.fs.live.service.ILiveConsoleOpLogService;
|
|
import com.fs.live.service.ILiveConsoleOpLogService;
|
|
|
import com.fs.live.service.ILiveCouponIssueService;
|
|
import com.fs.live.service.ILiveCouponIssueService;
|
|
|
|
|
+import com.fs.live.service.ILiveCouponUserService;
|
|
|
import com.fs.live.service.ILiveLotteryConfService;
|
|
import com.fs.live.service.ILiveLotteryConfService;
|
|
|
import com.fs.live.service.ILiveRedConfService;
|
|
import com.fs.live.service.ILiveRedConfService;
|
|
|
|
|
+import com.fs.live.utils.LiveCompletionConfigUtils;
|
|
|
import com.fs.live.vo.LiveConsoleOpLogRecordVo;
|
|
import com.fs.live.vo.LiveConsoleOpLogRecordVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -28,6 +33,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
import java.util.Calendar;
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
@@ -71,6 +77,15 @@ public class LiveConsoleOpLogServiceImpl implements ILiveConsoleOpLogService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private LiveCouponMapper liveCouponMapper;
|
|
private LiveCouponMapper liveCouponMapper;
|
|
|
|
|
|
|
|
|
|
+ /** 完课优惠券 live_coupon_user.type 前缀 */
|
|
|
|
|
+ private static final String COMPLETION_COUPON_USER_TYPE_PREFIX = "4-";
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private LiveCouponIssueUserMapper liveCouponIssueUserMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ILiveCouponUserService liveCouponUserService;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private LiveMapper liveMapper;
|
|
private LiveMapper liveMapper;
|
|
|
|
|
|
|
@@ -250,16 +265,23 @@ public class LiveConsoleOpLogServiceImpl implements ILiveConsoleOpLogService {
|
|
|
.filter(Objects::nonNull)
|
|
.filter(Objects::nonNull)
|
|
|
.collect(Collectors.toSet());
|
|
.collect(Collectors.toSet());
|
|
|
}
|
|
}
|
|
|
|
|
+ Set<Long> claimedCouponIssueIds = loadUserClaimedCouponIssueIds(userId);
|
|
|
|
|
+ Set<Long> claimedCompletionCouponIds = loadUserClaimedCompletionCouponIds(liveId, userId);
|
|
|
|
|
|
|
|
Date now = DateUtils.getNowDate();
|
|
Date now = DateUtils.getNowDate();
|
|
|
Live live = liveMapper.selectLiveByLiveId(liveId);
|
|
Live live = liveMapper.selectLiveByLiveId(liveId);
|
|
|
|
|
+ boolean completionCouponMode = live != null && LiveCompletionConfigUtils.isCompletionCouponMode(live.getConfigJson());
|
|
|
Map<Long, Long> couponTypeMap = resolveCouponTypeMap(opLogs);
|
|
Map<Long, Long> couponTypeMap = resolveCouponTypeMap(opLogs);
|
|
|
List<LiveConsoleOpLogRecordVo> result = new ArrayList<>(opLogs.size());
|
|
List<LiveConsoleOpLogRecordVo> result = new ArrayList<>(opLogs.size());
|
|
|
for (LiveConsoleOpLog opLog : opLogs) {
|
|
for (LiveConsoleOpLog opLog : opLogs) {
|
|
|
if (isInternalSettleOpLog(opLog)) {
|
|
if (isInternalSettleOpLog(opLog)) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- boolean claimed = opLog.getId() != null && claimedOpLogIds.contains(opLog.getId());
|
|
|
|
|
|
|
+ if (completionCouponMode && opLog.getOpType() != null
|
|
|
|
|
+ && opLog.getOpType() == LiveConsoleOpLog.OP_COMPLETION_POINTS) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ boolean claimed = isUserClaimedOpLog(opLog, claimedOpLogIds, claimedCouponIssueIds, claimedCompletionCouponIds);
|
|
|
int status = resolveOpLogStatus(opLog, claimed, now, live);
|
|
int status = resolveOpLogStatus(opLog, claimed, now, live);
|
|
|
LiveConsoleOpLogRecordVo recordVo = LiveConsoleOpLogRecordVo.from(opLog, status);
|
|
LiveConsoleOpLogRecordVo recordVo = LiveConsoleOpLogRecordVo.from(opLog, status);
|
|
|
fillCouponType(recordVo, opLog, couponTypeMap);
|
|
fillCouponType(recordVo, opLog, couponTypeMap);
|
|
@@ -328,6 +350,86 @@ public class LiveConsoleOpLogServiceImpl implements ILiveConsoleOpLogService {
|
|
|
recordVo.setCouponType(couponTypeMap.get(opLog.getBizId()));
|
|
recordVo.setCouponType(couponTypeMap.get(opLog.getBizId()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private Set<Long> loadUserClaimedCouponIssueIds(Long userId) {
|
|
|
|
|
+ if (userId == null) {
|
|
|
|
|
+ return Collections.emptySet();
|
|
|
|
|
+ }
|
|
|
|
|
+ LiveCouponIssueUser query = new LiveCouponIssueUser();
|
|
|
|
|
+ query.setUserId(userId);
|
|
|
|
|
+ query.setIsDel(0);
|
|
|
|
|
+ List<LiveCouponIssueUser> issueUsers = liveCouponIssueUserMapper.selectLiveCouponIssueUserList(query);
|
|
|
|
|
+ if (issueUsers == null || issueUsers.isEmpty()) {
|
|
|
|
|
+ return Collections.emptySet();
|
|
|
|
|
+ }
|
|
|
|
|
+ return issueUsers.stream()
|
|
|
|
|
+ .map(LiveCouponIssueUser::getIssueId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Set<Long> loadUserClaimedCompletionCouponIds(Long liveId, Long userId) {
|
|
|
|
|
+ if (liveId == null || userId == null) {
|
|
|
|
|
+ return Collections.emptySet();
|
|
|
|
|
+ }
|
|
|
|
|
+ LiveCouponUser query = new LiveCouponUser();
|
|
|
|
|
+ query.setUserId(userId.intValue());
|
|
|
|
|
+ query.setType(COMPLETION_COUPON_USER_TYPE_PREFIX + liveId);
|
|
|
|
|
+ List<LiveCouponUser> couponUsers = liveCouponUserService.selectLiveCouponUserList(query);
|
|
|
|
|
+ if (couponUsers == null || couponUsers.isEmpty()) {
|
|
|
|
|
+ return Collections.emptySet();
|
|
|
|
|
+ }
|
|
|
|
|
+ return couponUsers.stream()
|
|
|
|
|
+ .map(LiveCouponUser::getCouponId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 判断用户是否已领取/参与该条留存。
|
|
|
|
|
+ * 普通优惠券 additionally 以 live_coupon_issue_user 为准,避免领券时未绑定 opLog 被误判为已结束。
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean isUserClaimedOpLog(LiveConsoleOpLog opLog, Set<Long> claimedOpLogIds,
|
|
|
|
|
+ Set<Long> claimedCouponIssueIds, Set<Long> claimedCompletionCouponIds) {
|
|
|
|
|
+ if (opLog == null) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (opLog.getId() != null && claimedOpLogIds.contains(opLog.getId())) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (opLog.getOpType() == null || opLog.getBizId() == null) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ int opType = opLog.getOpType();
|
|
|
|
|
+ if (opType == LiveConsoleOpLog.OP_COUPON_SHOW || opType == LiveConsoleOpLog.OP_VERIFY_COUPON_SHOW) {
|
|
|
|
|
+ return claimedCouponIssueIds.contains(opLog.getBizId());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (opType == LiveConsoleOpLog.OP_COMPLETION_COUPON) {
|
|
|
|
|
+ return claimedCompletionCouponIds.contains(opLog.getBizId());
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Long resolveLatestCouponShowOpLogId(Long liveId, Long couponIssueId) {
|
|
|
|
|
+ if (liveId == null || couponIssueId == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ LiveConsoleOpLog query = new LiveConsoleOpLog();
|
|
|
|
|
+ query.setLiveId(liveId);
|
|
|
|
|
+ query.setBizId(couponIssueId);
|
|
|
|
|
+ List<LiveConsoleOpLog> logs = liveConsoleOpLogMapper.selectLiveConsoleOpLogList(query);
|
|
|
|
|
+ if (logs == null || logs.isEmpty()) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return logs.stream()
|
|
|
|
|
+ .filter(log -> log.getOpType() != null
|
|
|
|
|
+ && (log.getOpType() == LiveConsoleOpLog.OP_COUPON_SHOW
|
|
|
|
|
+ || log.getOpType() == LiveConsoleOpLog.OP_VERIFY_COUPON_SHOW))
|
|
|
|
|
+ .max(Comparator.comparing(LiveConsoleOpLog::getCreateTime, Comparator.nullsLast(Date::compareTo)))
|
|
|
|
|
+ .map(LiveConsoleOpLog::getId)
|
|
|
|
|
+ .orElse(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 状态优先级:已领取 > 已结束 > 待领取
|
|
* 状态优先级:已领取 > 已结束 > 待领取
|
|
|
* <p>已领取:用户已成功领取/参与;已结束:活动已截止或用户未领到(如红包抢完),不再展示待领取</p>
|
|
* <p>已领取:用户已成功领取/参与;已结束:活动已截止或用户未领到(如红包抢完),不再展示待领取</p>
|