|
|
@@ -4,15 +4,20 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.exception.base.BaseException;
|
|
|
+import com.fs.common.utils.DictUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.live.domain.*;
|
|
|
+import com.fs.live.mapper.LiveCompletionPointsRecordMapper;
|
|
|
import com.fs.live.mapper.LiveQuestionBankMapper;
|
|
|
+import com.fs.live.param.LiveCompletionAnswerRecordParam;
|
|
|
import com.fs.live.param.LiveCompletionCouponAnswerItem;
|
|
|
import com.fs.live.param.LiveCompletionCouponAnswerParam;
|
|
|
import com.fs.live.param.LiveCompletionCouponClaimParam;
|
|
|
import com.fs.live.service.*;
|
|
|
import com.fs.live.utils.LiveCompletionConfigUtils;
|
|
|
+import com.fs.live.vo.LiveCompletionAnswerClaimRecordsVo;
|
|
|
import com.fs.live.vo.LiveCompletionAnswerDetailVO;
|
|
|
+import com.fs.live.vo.LiveCompletionAnswerRecordListVO;
|
|
|
import com.fs.live.vo.LiveCompletionCouponAnswerResult;
|
|
|
import com.fs.live.vo.LiveCompletionCouponClaimItemVO;
|
|
|
import com.fs.live.vo.LiveCompletionCouponClaimResult;
|
|
|
@@ -22,6 +27,7 @@ import com.fs.live.vo.LiveCompletionCouponNotifyResult;
|
|
|
import com.fs.live.vo.LiveCompletionCouponStatusVO;
|
|
|
import com.fs.live.vo.LiveCompletionQuestionVO;
|
|
|
import com.fs.live.vo.LiveRewardCouponItem;
|
|
|
+import com.fs.live.vo.LiveUserClaimRecordVo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -81,6 +87,9 @@ public class LiveCompletionCouponServiceImpl implements ILiveCompletionCouponSer
|
|
|
@Autowired
|
|
|
private ILiveCompletionAnswerRecordService liveCompletionAnswerRecordService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private LiveCompletionPointsRecordMapper liveCompletionPointsRecordMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public LiveCompletionCouponConfigVO parseCompletionCouponConfig(Live live) {
|
|
|
LiveCompletionCouponConfigVO vo = new LiveCompletionCouponConfigVO();
|
|
|
@@ -1045,4 +1054,119 @@ public class LiveCompletionCouponServiceImpl implements ILiveCompletionCouponSer
|
|
|
return details;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 完播答题后奖励领取记录:红包/积分、核销券、优惠券三类整合。
|
|
|
+ * <p>无答题全对记录时三类均为空;券类仅取完课优惠券留存(opType=8),并按券模板区分核销券/普通优惠券。</p>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public LiveCompletionAnswerClaimRecordsVo getAnswerClaimRecords(Long liveId, Long userId) {
|
|
|
+ LiveCompletionAnswerClaimRecordsVo result = new LiveCompletionAnswerClaimRecordsVo();
|
|
|
+ result.setAnswered(false);
|
|
|
+ result.setAnswerRecordId(null);
|
|
|
+ result.setRedPointsList(new ArrayList<>());
|
|
|
+ result.setVerifyCouponList(new ArrayList<>());
|
|
|
+ result.setCouponList(new ArrayList<>());
|
|
|
+ if (liveId == null || userId == null) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ LiveCompletionAnswerRecordParam answerParam = new LiveCompletionAnswerRecordParam();
|
|
|
+ answerParam.setLiveId(liveId);
|
|
|
+ answerParam.setUserId(userId);
|
|
|
+ answerParam.setIsRight(1);
|
|
|
+ List<LiveCompletionAnswerRecordListVO> answerList =
|
|
|
+ liveCompletionAnswerRecordService.selectLiveCompletionAnswerRecordList(answerParam);
|
|
|
+ if (answerList == null || answerList.isEmpty()) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ result.setAnswered(true);
|
|
|
+ result.setAnswerRecordId(answerList.get(0).getId());
|
|
|
+
|
|
|
+ // 1) 红包/积分:本场已领取完课积分
|
|
|
+ List<LiveCompletionPointsRecord> pointsRecords =
|
|
|
+ liveCompletionPointsRecordMapper.selectReceivedByLiveAndUser(liveId, userId);
|
|
|
+ if (pointsRecords != null) {
|
|
|
+ for (LiveCompletionPointsRecord pointsRecord : pointsRecords) {
|
|
|
+ result.getRedPointsList().add(buildPointsClaimRow(pointsRecord));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2) 核销券 / 优惠券:完课优惠券留存(opType=8)已领取明细
|
|
|
+ List<LiveUserClaimRecordVo> claimRecords = liveConsoleOpLogService.listUserClaimRecords(liveId, userId);
|
|
|
+ if (claimRecords == null || claimRecords.isEmpty()) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ Map<Long, LiveCoupon> couponCache = new HashMap<>();
|
|
|
+ for (LiveUserClaimRecordVo claim : claimRecords) {
|
|
|
+ if (claim == null || claim.getOpType() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (claim.getOpType() != LiveConsoleOpLog.OP_COMPLETION_COUPON) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (isVerifyCouponClaim(claim, couponCache)) {
|
|
|
+ result.getVerifyCouponList().add(claim);
|
|
|
+ } else {
|
|
|
+ result.getCouponList().add(claim);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private LiveUserClaimRecordVo buildPointsClaimRow(LiveCompletionPointsRecord pointsRecord) {
|
|
|
+ LiveUserClaimRecordVo vo = new LiveUserClaimRecordVo();
|
|
|
+ vo.setOpLogId(null);
|
|
|
+ vo.setOpType(LiveConsoleOpLog.OP_COMPLETION_POINTS);
|
|
|
+ vo.setOpTypeName(LiveUserClaimRecordVo.resolveOpTypeName(LiveConsoleOpLog.OP_COMPLETION_POINTS));
|
|
|
+ vo.setBizId(pointsRecord.getId());
|
|
|
+ Integer points = pointsRecord.getPointsAwarded();
|
|
|
+ vo.setBizName(points == null ? "完课积分" : ("完课积分+" + points));
|
|
|
+ vo.setCreateTime(pointsRecord.getReceiveTime() != null
|
|
|
+ ? pointsRecord.getReceiveTime() : pointsRecord.getCreateTime());
|
|
|
+ vo.setCouponCount(1);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isVerifyCouponClaim(LiveUserClaimRecordVo claim, Map<Long, LiveCoupon> couponCache) {
|
|
|
+ Long couponId = resolveCouponIdFromClaim(claim);
|
|
|
+ if (couponId == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ LiveCoupon coupon = couponCache.get(couponId);
|
|
|
+ if (coupon == null) {
|
|
|
+ coupon = liveCouponService.selectLiveCouponById(couponId);
|
|
|
+ if (coupon != null) {
|
|
|
+ couponCache.put(couponId, coupon);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return isVerifyCouponType(coupon);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long resolveCouponIdFromClaim(LiveUserClaimRecordVo claim) {
|
|
|
+ if (claim == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (claim.getCouponUserId() != null) {
|
|
|
+ LiveCouponUser couponUser = liveCouponUserService.selectLiveCouponUserById(claim.getCouponUserId());
|
|
|
+ if (couponUser != null && couponUser.getCouponId() != null) {
|
|
|
+ return couponUser.getCouponId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 完课优惠券留存 bizId 即为 couponId
|
|
|
+ return claim.getBizId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 核销券/无门槛券:type=3,或字典标签含核销/代金券 */
|
|
|
+ private boolean isVerifyCouponType(LiveCoupon coupon) {
|
|
|
+ if (coupon == null || coupon.getType() == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (coupon.getType() == 3L) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ String typeLabel = DictUtils.getDictLabel("store_coupon_type", String.valueOf(coupon.getType()));
|
|
|
+ return StringUtils.isNotEmpty(typeLabel)
|
|
|
+ && (typeLabel.contains("核销") || typeLabel.contains("代金券"));
|
|
|
+ }
|
|
|
}
|