|
|
@@ -5,6 +5,7 @@ import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.DictUtils;
|
|
|
import com.fs.common.utils.SecurityUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.live.domain.Live;
|
|
|
import com.fs.live.domain.LiveConsoleOpLog;
|
|
|
import com.fs.live.domain.LiveConsoleOpLogUser;
|
|
|
import com.fs.live.domain.LiveCoupon;
|
|
|
@@ -15,6 +16,7 @@ import com.fs.live.domain.LiveRedConf;
|
|
|
import com.fs.live.mapper.LiveConsoleOpLogMapper;
|
|
|
import com.fs.live.mapper.LiveConsoleOpLogUserMapper;
|
|
|
import com.fs.live.mapper.LiveCouponMapper;
|
|
|
+import com.fs.live.mapper.LiveMapper;
|
|
|
import com.fs.live.service.ILiveConsoleOpLogService;
|
|
|
import com.fs.live.service.ILiveCouponIssueService;
|
|
|
import com.fs.live.service.ILiveLotteryConfService;
|
|
|
@@ -24,6 +26,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Collections;
|
|
|
@@ -46,6 +50,8 @@ public class LiveConsoleOpLogServiceImpl implements ILiveConsoleOpLogService {
|
|
|
private static final String AUTO_OPERATOR_NAME = "运营自动化";
|
|
|
/** 中控台 WebSocket 无登录上下文时的默认操作人 */
|
|
|
private static final String CONSOLE_OPERATOR_NAME = "中控台";
|
|
|
+ /** 超过领取截止时间或直播结束后的宽限期(毫秒) */
|
|
|
+ private static final long EXPIRE_GRACE_MILLIS = 60_000L;
|
|
|
|
|
|
@Autowired
|
|
|
private LiveConsoleOpLogMapper liveConsoleOpLogMapper;
|
|
|
@@ -65,6 +71,9 @@ public class LiveConsoleOpLogServiceImpl implements ILiveConsoleOpLogService {
|
|
|
@Autowired
|
|
|
private LiveCouponMapper liveCouponMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private LiveMapper liveMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public List<LiveConsoleOpLog> selectLiveConsoleOpLogList(LiveConsoleOpLog liveConsoleOpLog) {
|
|
|
return liveConsoleOpLogMapper.selectLiveConsoleOpLogList(liveConsoleOpLog);
|
|
|
@@ -243,18 +252,47 @@ public class LiveConsoleOpLogServiceImpl implements ILiveConsoleOpLogService {
|
|
|
}
|
|
|
|
|
|
Date now = DateUtils.getNowDate();
|
|
|
+ Live live = liveMapper.selectLiveByLiveId(liveId);
|
|
|
Map<Long, Long> couponTypeMap = resolveCouponTypeMap(opLogs);
|
|
|
List<LiveConsoleOpLogRecordVo> result = new ArrayList<>(opLogs.size());
|
|
|
for (LiveConsoleOpLog opLog : opLogs) {
|
|
|
+ if (isInternalSettleOpLog(opLog)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
boolean claimed = opLog.getId() != null && claimedOpLogIds.contains(opLog.getId());
|
|
|
- int status = resolveOpLogStatus(opLog, claimed, now);
|
|
|
+ int status = resolveOpLogStatus(opLog, claimed, now, live);
|
|
|
LiveConsoleOpLogRecordVo recordVo = LiveConsoleOpLogRecordVo.from(opLog, status);
|
|
|
fillCouponType(recordVo, opLog, couponTypeMap);
|
|
|
result.add(recordVo);
|
|
|
}
|
|
|
+ result.sort(this::compareOpLogRecordByTime);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /** 按创建时间倒序(最新在前) */
|
|
|
+ private int compareOpLogRecordByTime(LiveConsoleOpLogRecordVo a, LiveConsoleOpLogRecordVo b) {
|
|
|
+ Date timeA = a.getCreateTime();
|
|
|
+ Date timeB = b.getCreateTime();
|
|
|
+ if (timeA == null && timeB == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ if (timeA == null) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ if (timeB == null) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ return timeB.compareTo(timeA);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isInternalSettleOpLog(LiveConsoleOpLog opLog) {
|
|
|
+ if (opLog == null || opLog.getOpType() == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ int opType = opLog.getOpType();
|
|
|
+ return opType == LiveConsoleOpLog.OP_RED_SETTLE || opType == LiveConsoleOpLog.OP_LOTTERY_SETTLE;
|
|
|
+ }
|
|
|
+
|
|
|
private Map<Long, Long> resolveCouponTypeMap(List<LiveConsoleOpLog> opLogs) {
|
|
|
List<Long> couponIds = opLogs.stream()
|
|
|
.filter(log -> log.getOpType() != null && log.getBizId() != null
|
|
|
@@ -292,23 +330,53 @@ public class LiveConsoleOpLogServiceImpl implements ILiveConsoleOpLogService {
|
|
|
|
|
|
/**
|
|
|
* 状态优先级:已领取 > 已结束 > 待领取
|
|
|
+ * <p>已领取:用户已成功领取/参与;已结束:活动已截止或用户未领到(如红包抢完),不再展示待领取</p>
|
|
|
*/
|
|
|
- private int resolveOpLogStatus(LiveConsoleOpLog opLog, boolean claimed, Date now) {
|
|
|
+ private int resolveOpLogStatus(LiveConsoleOpLog opLog, boolean claimed, Date now, Live live) {
|
|
|
if (claimed) {
|
|
|
return LiveConsoleOpLogRecordVo.STATUS_CLAIMED;
|
|
|
}
|
|
|
- if (isOpLogEnded(opLog, now)) {
|
|
|
+ if (isLiveBroadcastEndedOverGrace(live, now) || isOpLogItemEnded(opLog, now)) {
|
|
|
return LiveConsoleOpLogRecordVo.STATUS_ENDED;
|
|
|
}
|
|
|
return LiveConsoleOpLogRecordVo.STATUS_PENDING;
|
|
|
}
|
|
|
|
|
|
- private boolean isOpLogEnded(LiveConsoleOpLog opLog, Date now) {
|
|
|
- Date expireTime = resolveExpireTime(opLog);
|
|
|
- if (expireTime != null && !now.before(expireTime)) {
|
|
|
+ private boolean isLiveBroadcastEndedOverGrace(Live live, Date now) {
|
|
|
+ Date liveEnd = resolveLiveEndTime(live);
|
|
|
+ if (liveEnd == null || now == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return now.getTime() >= liveEnd.getTime() + EXPIRE_GRACE_MILLIS;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date resolveLiveEndTime(Live live) {
|
|
|
+ if (live == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (live.getFinishTime() != null) {
|
|
|
+ return Date.from(live.getFinishTime().atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ }
|
|
|
+ if (live.getStartTime() != null && live.getDuration() != null && live.getDuration() > 0) {
|
|
|
+ LocalDateTime endTime = live.getStartTime().plusSeconds(live.getDuration());
|
|
|
+ return Date.from(endTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ }
|
|
|
+ if (live.getStartTime() != null && live.getVideoDuration() != null && live.getVideoDuration() > 0) {
|
|
|
+ LocalDateTime endTime = live.getStartTime().plusSeconds(live.getVideoDuration());
|
|
|
+ return Date.from(endTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isOpLogItemEnded(LiveConsoleOpLog opLog, Date now) {
|
|
|
+ if (isBizEnded(opLog)) {
|
|
|
return true;
|
|
|
}
|
|
|
- return isBizEnded(opLog);
|
|
|
+ Date expireTime = resolveExpireTime(opLog);
|
|
|
+ if (expireTime != null && now != null) {
|
|
|
+ return now.getTime() >= expireTime.getTime() + EXPIRE_GRACE_MILLIS;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
private Date resolveExpireTime(LiveConsoleOpLog opLog) {
|