|
|
@@ -8,16 +8,29 @@ import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.live.domain.LiveConsoleOpLog;
|
|
|
import com.fs.live.domain.LiveConsoleOpLogUser;
|
|
|
import com.fs.live.domain.LiveCoupon;
|
|
|
+import com.fs.live.domain.LiveCouponIssue;
|
|
|
+import com.fs.live.domain.LiveLotteryConf;
|
|
|
+import com.fs.live.domain.LiveRedConf;
|
|
|
import com.fs.live.mapper.LiveConsoleOpLogMapper;
|
|
|
import com.fs.live.mapper.LiveConsoleOpLogUserMapper;
|
|
|
import com.fs.live.service.ILiveConsoleOpLogService;
|
|
|
+import com.fs.live.service.ILiveCouponIssueService;
|
|
|
+import com.fs.live.service.ILiveLotteryConfService;
|
|
|
+import com.fs.live.service.ILiveRedConfService;
|
|
|
+import com.fs.live.vo.LiveConsoleOpLogRecordVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 直播中控台操作留存 Service 实现
|
|
|
@@ -34,6 +47,15 @@ public class LiveConsoleOpLogServiceImpl implements ILiveConsoleOpLogService {
|
|
|
@Autowired
|
|
|
private LiveConsoleOpLogUserMapper liveConsoleOpLogUserMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ILiveRedConfService liveRedConfService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILiveLotteryConfService liveLotteryConfService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILiveCouponIssueService liveCouponIssueService;
|
|
|
+
|
|
|
@Override
|
|
|
public List<LiveConsoleOpLog> selectLiveConsoleOpLogList(LiveConsoleOpLog liveConsoleOpLog) {
|
|
|
return liveConsoleOpLogMapper.selectLiveConsoleOpLogList(liveConsoleOpLog);
|
|
|
@@ -115,6 +137,137 @@ public class LiveConsoleOpLogServiceImpl implements ILiveConsoleOpLogService {
|
|
|
Collections.singletonList(new LiveConsoleOpLogUser(opLogId, userId, liveId, couponUserId)));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<LiveConsoleOpLogRecordVo> listUserOpLogRecords(Long liveId, Long userId) {
|
|
|
+ if (liveId == null || userId == null) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ LiveConsoleOpLog query = new LiveConsoleOpLog();
|
|
|
+ query.setLiveId(liveId);
|
|
|
+ List<LiveConsoleOpLog> opLogs = liveConsoleOpLogMapper.selectLiveConsoleOpLogList(query);
|
|
|
+ if (opLogs == null || opLogs.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Long> claimedOpLogIds = new HashSet<>();
|
|
|
+ List<LiveConsoleOpLogUser> relations = liveConsoleOpLogUserMapper.selectByLiveIdAndUserId(liveId, userId);
|
|
|
+ if (relations != null) {
|
|
|
+ claimedOpLogIds = relations.stream()
|
|
|
+ .map(LiveConsoleOpLogUser::getOpLogId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ }
|
|
|
+
|
|
|
+ Date now = DateUtils.getNowDate();
|
|
|
+ List<LiveConsoleOpLogRecordVo> result = new ArrayList<>(opLogs.size());
|
|
|
+ for (LiveConsoleOpLog opLog : opLogs) {
|
|
|
+ boolean claimed = opLog.getId() != null && claimedOpLogIds.contains(opLog.getId());
|
|
|
+ int status = resolveOpLogStatus(opLog, claimed, now);
|
|
|
+ result.add(LiveConsoleOpLogRecordVo.from(opLog, status));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 状态优先级:已领取 > 已结束 > 待领取
|
|
|
+ */
|
|
|
+ private int resolveOpLogStatus(LiveConsoleOpLog opLog, boolean claimed, Date now) {
|
|
|
+ if (claimed) {
|
|
|
+ return LiveConsoleOpLogRecordVo.STATUS_CLAIMED;
|
|
|
+ }
|
|
|
+ if (isOpLogEnded(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)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return isBizEnded(opLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date resolveExpireTime(LiveConsoleOpLog opLog) {
|
|
|
+ if (opLog == null || opLog.getCreateTime() == null || opLog.getOpType() == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Integer opType = opLog.getOpType();
|
|
|
+ Long bizId = opLog.getBizId();
|
|
|
+ if (bizId == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long durationMinutes = null;
|
|
|
+ Date limitTime = null;
|
|
|
+
|
|
|
+ switch (opType) {
|
|
|
+ case LiveConsoleOpLog.OP_COUPON_SHOW:
|
|
|
+ case LiveConsoleOpLog.OP_VERIFY_COUPON_SHOW:
|
|
|
+ LiveCouponIssue issue = liveCouponIssueService.selectLiveCouponIssueById(bizId);
|
|
|
+ if (issue != null) {
|
|
|
+ limitTime = issue.getLimitTime();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case LiveConsoleOpLog.OP_RED_SETTLE:
|
|
|
+ case LiveConsoleOpLog.OP_RED_SEND:
|
|
|
+ LiveRedConf redConf = liveRedConfService.selectLiveRedConfByRedId(bizId);
|
|
|
+ if (redConf != null) {
|
|
|
+ durationMinutes = redConf.getDuration();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case LiveConsoleOpLog.OP_LOTTERY_SETTLE:
|
|
|
+ case LiveConsoleOpLog.OP_LOTTERY_SEND:
|
|
|
+ LiveLotteryConf lotteryConf = liveLotteryConfService.selectLiveLotteryConfByLotteryId(bizId);
|
|
|
+ if (lotteryConf != null) {
|
|
|
+ durationMinutes = lotteryConf.getDuration();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (limitTime != null) {
|
|
|
+ return limitTime;
|
|
|
+ }
|
|
|
+ if (durationMinutes != null && durationMinutes > 0) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(opLog.getCreateTime());
|
|
|
+ calendar.add(Calendar.MINUTE, durationMinutes.intValue());
|
|
|
+ return calendar.getTime();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isBizEnded(LiveConsoleOpLog opLog) {
|
|
|
+ if (opLog == null || opLog.getOpType() == null || opLog.getBizId() == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Integer opType = opLog.getOpType();
|
|
|
+ Long bizId = opLog.getBizId();
|
|
|
+
|
|
|
+ switch (opType) {
|
|
|
+ case LiveConsoleOpLog.OP_COUPON_SHOW:
|
|
|
+ case LiveConsoleOpLog.OP_VERIFY_COUPON_SHOW:
|
|
|
+ LiveCouponIssue issue = liveCouponIssueService.selectLiveCouponIssueById(bizId);
|
|
|
+ return issue == null
|
|
|
+ || issue.getStatus() == null
|
|
|
+ || issue.getStatus() != 1
|
|
|
+ || (issue.getRemainCount() != null && issue.getRemainCount() <= 0);
|
|
|
+ case LiveConsoleOpLog.OP_RED_SETTLE:
|
|
|
+ case LiveConsoleOpLog.OP_RED_SEND:
|
|
|
+ LiveRedConf redConf = liveRedConfService.selectLiveRedConfByRedId(bizId);
|
|
|
+ return redConf != null && redConf.getRedStatus() != null && redConf.getRedStatus() == 2L;
|
|
|
+ case LiveConsoleOpLog.OP_LOTTERY_SETTLE:
|
|
|
+ case LiveConsoleOpLog.OP_LOTTERY_SEND:
|
|
|
+ LiveLotteryConf lotteryConf = liveLotteryConfService.selectLiveLotteryConfByLotteryId(bizId);
|
|
|
+ return lotteryConf != null && "2".equals(lotteryConf.getLotteryStatus());
|
|
|
+ default:
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 判断是否为核销券 / 核销代金券类型
|
|
|
*/
|