|
@@ -1,36 +1,30 @@
|
|
|
package com.fs.course.service.impl;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.*;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.fs.ad.enums.AdUploadType;
|
|
|
-import com.fs.ad.service.IAdHtmlClickLogService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.fs.common.BeanCopyUtils;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.domain.ResponseResult;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.common.utils.date.DateUtil;
|
|
|
+import com.fs.company.domain.CompanyUser;
|
|
|
+import com.fs.company.mapper.CompanyUserMapper;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
import com.fs.course.domain.*;
|
|
|
import com.fs.course.dto.CoursePackageDTO;
|
|
|
import com.fs.course.mapper.*;
|
|
|
import com.fs.course.param.*;
|
|
|
-import com.fs.course.param.newfs.UserCourseVideoPageParam;
|
|
|
+import com.fs.course.param.newfs.*;
|
|
|
+import com.fs.course.service.IFsUserCourseVideoService;
|
|
|
+import com.fs.course.service.IFsVideoResourceService;
|
|
|
import com.fs.course.vo.FsUserCourseVideoListUVO;
|
|
|
import com.fs.course.vo.FsUserCourseVideoQVO;
|
|
|
import com.fs.course.vo.FsUserCourseVideoVO;
|
|
|
-import com.fs.course.vo.newfs.FsUserCourseVideoDetailsVO;
|
|
|
-import com.fs.course.vo.newfs.FsUserCourseVideoPageListVO;
|
|
|
-import com.fs.course.vo.newfs.FsUserVideoListVO;
|
|
|
-import com.fs.course.vo.newfs.FsUserVideoQuestionVO;
|
|
|
+import com.fs.course.vo.newfs.*;
|
|
|
import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.domain.FsUserIntegralLogs;
|
|
|
import com.fs.his.mapper.FsUserIntegralLogsMapper;
|
|
@@ -38,6 +32,7 @@ import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.his.param.WxSendRedPacketParam;
|
|
|
import com.fs.his.service.IFsStorePaymentService;
|
|
|
import com.fs.his.service.IFsUserService;
|
|
|
+import com.fs.his.vo.OptionsVO;
|
|
|
import com.fs.qw.domain.QwExternalContact;
|
|
|
import com.fs.qw.domain.QwUser;
|
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
@@ -49,21 +44,30 @@ import com.fs.sop.mapper.QwSopLogsMapper;
|
|
|
import com.fs.sop.mapper.SopUserLogsInfoMapper;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.fs.course.service.IFsUserCourseVideoService;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.atomic.AtomicLong;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* 课堂视频Service业务层处理
|
|
|
*
|
|
|
* @author fs
|
|
|
* @date 2024-05-17
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
{
|
|
@@ -91,8 +95,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
private FsCourseSopLogsMapper courseSopLogsMapper;
|
|
|
@Autowired
|
|
|
private QwApiService qwApiService;
|
|
|
- @Autowired
|
|
|
- private IAdHtmlClickLogService adHtmlClickLogService;
|
|
|
+ // @Autowired
|
|
|
+// private IAdHtmlClickLogService adHtmlClickLogService;
|
|
|
@Autowired
|
|
|
private QwUserMapper qwUserMapper;
|
|
|
@Autowired
|
|
@@ -116,6 +120,29 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
private FsCourseLinkMapper courseLinkMapper;
|
|
|
@Autowired
|
|
|
RedisCache redisCache;
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService sysConfigService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyUserMapper companyUserMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsVideoResourceService fsVideoResourceService;
|
|
|
+ @Autowired
|
|
|
+ private FsVideoResourceMapper fsVideoResourceMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserCourseMapper fsUserCourseMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserCoursePeriodMapper fsUserCoursePeriodMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserCoursePeriodDaysMapper fsUserCoursePeriodDaysMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserCompanyUserMapper fsUserCompanyUserMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询课堂视频
|
|
|
*
|
|
@@ -280,12 +307,14 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
if (param.getLinkType()!=null && param.getLinkType()==1){
|
|
|
return R.ok();
|
|
|
}
|
|
|
+
|
|
|
if (param.getIsRoom()!=null&¶m.getIsRoom()==1&¶m.getQwExternalId()==null){
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
// 从Redis中获取观看时长
|
|
|
String redisKey = "h5user:watch:duration:" + param.getQwUserId()+ ":" + param.getQwExternalId() + ":" + param.getVideoId();
|
|
|
+ log.info("看课redis-key:{}", redisKey);
|
|
|
try {
|
|
|
String durationStr = redisCache.getCacheObject(redisKey);
|
|
|
Long duration = durationStr != null ? Long.parseLong(durationStr) : 0L;
|
|
@@ -323,9 +352,6 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
if (fsUser==null){
|
|
|
return R.error(504,"未授权");
|
|
|
}
|
|
|
- if (fsUser.getStatus()==0){
|
|
|
- return R.error("无权限!");
|
|
|
- }
|
|
|
|
|
|
String msg = "<div style=\"color: red;margin-bottom: 15px;font-weight: bold;\">本课程为会员独享<br>请长按二维码</div>\n" +
|
|
|
"\t\t\t\t\t<div style=\"color: #999;font-size: 14px;font-weight: bold;\">添加伴学助手免费领取会员权限</div>";
|
|
@@ -347,24 +373,22 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
}
|
|
|
|
|
|
- //群聊逻辑
|
|
|
private R handleRoom(FsUserCourseVideoAddKfUParam param,FsUser user) {
|
|
|
- if (user.getQwExtId()!=null){
|
|
|
- param.setQwExternalId(user.getQwExtId());
|
|
|
- //查询是否有添加客服
|
|
|
- QwExternalContact externalContact = qwExternalContactMapper.selectQwExternalContactById(param.getQwExternalId());
|
|
|
- if (externalContact==null){
|
|
|
- return R.error("客户不存在!");
|
|
|
- }
|
|
|
- if (!externalContact.getQwUserId().equals(Long.parseLong(param.getQwUserId()))){
|
|
|
- logger.error("zyp \n【无权观看参数】:{}",param);
|
|
|
- return R.error("无权限观看,添加群主非本群主");
|
|
|
- }
|
|
|
- FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByExt(param.getQwExternalId(), param.getVideoId(),param.getQwUserId());
|
|
|
- if (log==null){
|
|
|
- createWatchLog(param);
|
|
|
- }
|
|
|
- return R.ok().put("qwExternalId",user.getQwExtId());
|
|
|
+ if (user.getQwExtId()==null){
|
|
|
+ return R.error("未注册");
|
|
|
+ }
|
|
|
+ param.setQwExternalId(user.getQwExtId());
|
|
|
+ //查询是否有添加客服
|
|
|
+ QwExternalContact externalContact = qwExternalContactMapper.selectQwExternalContactById(param.getQwExternalId());
|
|
|
+ if (externalContact==null){
|
|
|
+ return R.error("客户不存在!");
|
|
|
+ }
|
|
|
+ if (!externalContact.getQwUserId().equals(param.getUserId())){
|
|
|
+ return R.error("无权限观看,添加群主非本群主");
|
|
|
+ }
|
|
|
+ FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByExt(param.getQwExternalId(), param.getVideoId(),param.getQwUserId());
|
|
|
+ if (log==null){
|
|
|
+ createWatchLog(param);
|
|
|
}
|
|
|
return R.ok();
|
|
|
}
|
|
@@ -457,6 +481,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
if (list!=null&& !list.isEmpty()){
|
|
|
sopUserLogsInfoMapper.updateSopUserLogsInfoFsUserIdById(list,param.getUserId());
|
|
|
}
|
|
|
+
|
|
|
//绑定上之后 更新观看记录
|
|
|
//看课记录中userId为0绑定userId
|
|
|
if (log.getUserId()==null||log.getUserId().equals(0L) || !log.getUserId().equals(param.getUserId())){
|
|
@@ -516,8 +541,10 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
public R getInternetTraffic(FsUserCourseVideoFinishUParam param) {
|
|
|
try {
|
|
|
FsCourseTrafficLog trafficLog = new FsCourseTrafficLog();
|
|
|
- trafficLog.setQwExternalContactId(param.getQwExternalId() != null ? param.getQwExternalId() : 0L);
|
|
|
+ trafficLog.setQwExternalContactId(param.getQwExternalId());
|
|
|
+ trafficLog.setUserId(param.getUserId());
|
|
|
trafficLog.setCreateTime(new Date());
|
|
|
+// trafficLog.setTime(new Date());
|
|
|
BeanUtils.copyProperties(param, trafficLog);
|
|
|
|
|
|
FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
@@ -535,6 +562,12 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
if (StringUtils.isNotEmpty(trafficLog.getUuId())) {
|
|
|
// 直接插入或更新
|
|
|
// logger.error("zyp \n【插入或更新流量】:{}",trafficLog);
|
|
|
+// if(ObjectUtils.isNotNull(trafficLog.getCourseId())) {
|
|
|
+// FsUserCourse course = fsUserCourseCacheService.selectFsUserCourseByCourseId(trafficLog.getCourseId());
|
|
|
+// if(ObjectUtils.isNotNull(course)){
|
|
|
+// trafficLog.setProject(course.getProject());
|
|
|
+// }
|
|
|
+// }
|
|
|
fsCourseTrafficLogMapper.insertOrUpdateTrafficLog(trafficLog);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -548,63 +581,63 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
@Override
|
|
|
public R getIntegralByH5Video(FsUserCourseVideoFinishUParam param) {
|
|
|
- //临时短链不做处理
|
|
|
- if (param.getLinkType()!=null&¶m.getLinkType()==1){
|
|
|
- return R.ok();
|
|
|
- }
|
|
|
- FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideo(param.getUserId(),param.getVideoId(),param.getQwUserId(), param.getQwExternalId());
|
|
|
- if (log==null){
|
|
|
- return R.error("无记录");
|
|
|
- }
|
|
|
- if (log.getLogType()==2){
|
|
|
- return R.error("已存在完课记录");
|
|
|
- }
|
|
|
- if (log.getLogType()==1){
|
|
|
- FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
|
- if (video==null){
|
|
|
- return R.error("课程视频不存在!");
|
|
|
- }
|
|
|
- FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
|
|
|
- if (user!=null){
|
|
|
- //判断该视频可增加积分的此时 (每十分钟增加积分)
|
|
|
- Long count = video.getDuration()/600;
|
|
|
- Long getIntegralCount = fsUserIntegralLogsMapper.selectH5VideoIntegralCount(param.getUserId(), param.getVideoId());
|
|
|
- if (getIntegralCount.equals(count)){
|
|
|
- return R.error("该课堂或积分已达限制!");
|
|
|
- }
|
|
|
- String json = configService.selectConfigByKey("course.config");
|
|
|
- CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
- //增加积分
|
|
|
- FsUser userMap=new FsUser();
|
|
|
- userMap.setUserId(user.getUserId());
|
|
|
- userMap.setIntegral(user.getIntegral()+config.getVideoIntegral());
|
|
|
- fsUserMapper.updateFsUser(userMap);
|
|
|
- FsUserIntegralLogs integralLogs = new FsUserIntegralLogs();
|
|
|
- integralLogs.setIntegral(config.getVideoIntegral().longValue());
|
|
|
- integralLogs.setUserId(user.getUserId());
|
|
|
- integralLogs.setBalance(userMap.getIntegral());
|
|
|
- integralLogs.setLogType(16);
|
|
|
- integralLogs.setBusinessId(log.getLogId().toString());
|
|
|
- integralLogs.setCreateTime(new Date());
|
|
|
- fsUserIntegralLogsMapper.insertFsUserIntegralLogs(integralLogs);
|
|
|
-
|
|
|
- FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
- redPacketLog.setCourseId(log.getCourseId());
|
|
|
- redPacketLog.setOutBatchNo(integralLogs.getId().toString());
|
|
|
- redPacketLog.setCompanyId(log.getCompanyId());
|
|
|
- redPacketLog.setUserId(log.getUserId());
|
|
|
- redPacketLog.setVideoId(log.getVideoId());
|
|
|
- redPacketLog.setStatus(1);
|
|
|
- redPacketLog.setQwUserId(log.getQwUserId() != null ? log.getQwUserId() : null );
|
|
|
- redPacketLog.setCompanyUserId(log.getCompanyUserId());
|
|
|
- redPacketLog.setCreateTime(new Date());
|
|
|
- redPacketLog.setAmount(BigDecimal.valueOf(config.getVideoIntegral()).divide(BigDecimal.valueOf(1000)));
|
|
|
- redPacketLog.setRemark("点播看课获得积分转");
|
|
|
- redPacketLog.setWatchLogId(log.getLogId() !=null ? log.getLogId() : null);
|
|
|
- redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
- return R.ok();
|
|
|
- }
|
|
|
- }
|
|
|
+// //临时短链不做处理
|
|
|
+// if (param.getLinkType()!=null&¶m.getLinkType()==1){
|
|
|
+// return R.ok();
|
|
|
+// }
|
|
|
+// FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideo(param.getUserId(),param.getVideoId(),param.getQwUserId(), param.getQwExternalId());
|
|
|
+// if (log==null){
|
|
|
+// return R.error("无记录");
|
|
|
+// }
|
|
|
+// if (log.getLogType()==2){
|
|
|
+// return R.error("已存在完课记录");
|
|
|
+// }
|
|
|
+// if (log.getLogType()==1){
|
|
|
+// FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
|
+// if (video==null){
|
|
|
+// return R.error("课程视频不存在!");
|
|
|
+// }
|
|
|
+// FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
|
|
|
+// if (user!=null){
|
|
|
+// //判断该视频可增加积分的此时 (每十分钟增加积分)
|
|
|
+// Long count = video.getDuration()/600;
|
|
|
+// Long getIntegralCount = fsUserIntegralLogsMapper.selectH5VideoIntegralCount(param.getUserId(), param.getVideoId());
|
|
|
+// if (getIntegralCount.equals(count)){
|
|
|
+// return R.error("该课堂或积分已达限制!");
|
|
|
+// }
|
|
|
+// String json = configService.selectConfigByKey("course.config");
|
|
|
+// CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
+// //增加积分
|
|
|
+// FsUser userMap=new FsUser();
|
|
|
+// userMap.setUserId(user.getUserId());
|
|
|
+// userMap.setIntegral(user.getIntegral()+config.getVideoIntegral());
|
|
|
+// fsUserMapper.updateFsUser(userMap);
|
|
|
+// FsUserIntegralLogs integralLogs = new FsUserIntegralLogs();
|
|
|
+// integralLogs.setIntegral(config.getVideoIntegral().longValue());
|
|
|
+// integralLogs.setUserId(user.getUserId());
|
|
|
+// integralLogs.setBalance(userMap.getIntegral());
|
|
|
+// integralLogs.setLogType(16);
|
|
|
+// integralLogs.setBusinessId(log.getLogId().toString());
|
|
|
+// integralLogs.setCreateTime(new Date());
|
|
|
+// fsUserIntegralLogsMapper.insertFsUserIntegralLogs(integralLogs);
|
|
|
+//
|
|
|
+// FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
+// redPacketLog.setCourseId(log.getCourseId());
|
|
|
+// redPacketLog.setOutBatchNo(integralLogs.getId().toString());
|
|
|
+// redPacketLog.setCompanyId(log.getCompanyId());
|
|
|
+// redPacketLog.setUserId(log.getUserId());
|
|
|
+// redPacketLog.setVideoId(log.getVideoId());
|
|
|
+// redPacketLog.setStatus(1);
|
|
|
+// redPacketLog.setQwUserId(log.getQwUserId() != null ? log.getQwUserId() : null );
|
|
|
+// redPacketLog.setCompanyUserId(log.getCompanyUserId());
|
|
|
+// redPacketLog.setCreateTime(new Date());
|
|
|
+// redPacketLog.setAmount(BigDecimal.valueOf(config.getVideoIntegral()).divide(BigDecimal.valueOf(1000)));
|
|
|
+// redPacketLog.setRemark("点播看课获得积分转");
|
|
|
+// redPacketLog.setWatchLogId(log.getLogId() !=null ? log.getLogId() : null);
|
|
|
+// redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
+// return R.ok();
|
|
|
+// }
|
|
|
+// }
|
|
|
return R.error();
|
|
|
}
|
|
|
|
|
@@ -649,7 +682,42 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
return sendRedPacketReward(param, user, log, video, config);
|
|
|
// 积分奖励
|
|
|
case 2:
|
|
|
- return sendIntegralReward(param,user, log, config);
|
|
|
+ return sendIntegralReward(user, log, config);
|
|
|
+ default:
|
|
|
+ return R.error("参数错误!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R sendRewardByFsUser(FsCourseSendRewardUParam param) {
|
|
|
+ FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
|
|
|
+ if (user == null){
|
|
|
+ return R.error("未识别到用户信息");
|
|
|
+ }
|
|
|
+ FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByFsUser(param.getUserId(), param.getVideoId(), param.getCompanyUserId());
|
|
|
+ if (log == null) {
|
|
|
+ return R.error("无记录");
|
|
|
+ }
|
|
|
+ if (log.getRewardType() != null) {
|
|
|
+ return R.error("奖励已发放");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 获取视频信息
|
|
|
+ FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
|
+
|
|
|
+ // 获取配置信息
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
+ CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
+
|
|
|
+ // 根据奖励类型发放不同奖励
|
|
|
+ switch (config.getRewardType()) {
|
|
|
+ // 红包奖励
|
|
|
+ case 1:
|
|
|
+ return sendRedPacketReward(param, user, log, video, config);
|
|
|
+ // 积分奖励
|
|
|
+ case 2:
|
|
|
+ return sendIntegralReward(user, log, config);
|
|
|
default:
|
|
|
return R.error("参数错误!");
|
|
|
}
|
|
@@ -666,14 +734,28 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
* @return 处理结果
|
|
|
*/
|
|
|
private R sendRedPacketReward(FsCourseSendRewardUParam param, FsUser user, FsCourseWatchLog log, FsUserCourseVideo video, CourseConfig config) {
|
|
|
+ // 判断是否属于领取红包时间(会员看课发放红包)
|
|
|
+ FsUserCoursePeriodDays periodDays = new FsUserCoursePeriodDays();
|
|
|
+ periodDays.setVideoId(param.getVideoId());
|
|
|
+ periodDays.setPeriodId(param.getPeriodId());
|
|
|
+ //正常情况是只能查询到一条,之前可能存在重复的脏数据,暂使用查询list的方式
|
|
|
+ List<FsUserCoursePeriodDays> fsUserCoursePeriodDays = fsUserCoursePeriodDaysMapper.selectFsUserCoursePeriodDaysList(periodDays);
|
|
|
+ if(fsUserCoursePeriodDays != null && !fsUserCoursePeriodDays.isEmpty()){
|
|
|
+ periodDays = fsUserCoursePeriodDays.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(periodDays != null && periodDays.getLastJoinTime() !=null && LocalDateTime.now().isAfter(periodDays.getLastJoinTime())) {
|
|
|
+ return R.error(403,"已超过领取红包时间");
|
|
|
+ }
|
|
|
+
|
|
|
// 确定红包金额
|
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
|
- FsUserCourseVideoRedPackage redPackage = fsUserCourseVideoRedPackageMapper.selectRedPacketByCompanyId(param.getVideoId(), param.getCompanyId());
|
|
|
+ FsUserCourseVideoRedPackage redPackage = fsUserCourseVideoRedPackageMapper.selectRedPacketByCompanyId(param.getVideoId(), param.getCompanyId(), param.getPeriodId());
|
|
|
|
|
|
if (redPackage != null) {
|
|
|
amount = redPackage.getRedPacketMoney();
|
|
|
} else if (video != null) {
|
|
|
- amount = new BigDecimal(video.getRedPacketMoney());
|
|
|
+ amount = video.getRedPacketMoney();
|
|
|
}
|
|
|
|
|
|
// 准备发送红包参数
|
|
@@ -681,7 +763,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
packetParam.setOpenId(user.getMpOpenId());
|
|
|
// 来源是小程序切换openId
|
|
|
if (param.getSource() == 2) {
|
|
|
- packetParam.setOpenId(user.getCourseMaOpenId());
|
|
|
+ packetParam.setOpenId(user.getMaOpenId());
|
|
|
}
|
|
|
packetParam.setAmount(amount);
|
|
|
packetParam.setSource(param.getSource());
|
|
@@ -702,6 +784,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
}
|
|
|
// 添加红包记录
|
|
|
redPacketLog.setCourseId(param.getCourseId());
|
|
|
+// redPacketLog.setOutBatchNo(sendRedPacket.get("orderCode").toString());
|
|
|
redPacketLog.setCompanyId(param.getCompanyId());
|
|
|
redPacketLog.setUserId(param.getUserId());
|
|
|
redPacketLog.setVideoId(param.getVideoId());
|
|
@@ -711,12 +794,14 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
redPacketLog.setCreateTime(new Date());
|
|
|
redPacketLog.setAmount(amount);
|
|
|
redPacketLog.setWatchLogId(log.getLogId() != null ? log.getLogId() : null);
|
|
|
+ redPacketLog.setPeriodId(param.getPeriodId());
|
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
|
|
|
-
|
|
|
+ // 更新观看记录的奖励类型
|
|
|
+// if (param.getLinkType() == null || param.getLinkType() == 0) {
|
|
|
log.setRewardType(config.getRewardType());
|
|
|
courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
-
|
|
|
+// }
|
|
|
return sendRedPacket;
|
|
|
} else {
|
|
|
return R.error("奖励发送失败,请联系客服");
|
|
@@ -731,12 +816,14 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
* @param config 配置信息
|
|
|
* @return 处理结果
|
|
|
*/
|
|
|
- private R sendIntegralReward(FsCourseSendRewardUParam param,FsUser user, FsCourseWatchLog log, CourseConfig config) {
|
|
|
+ private R sendIntegralReward(FsUser user, FsCourseWatchLog log, CourseConfig config) {
|
|
|
// 更新用户积分
|
|
|
- FsUser userMap=new FsUser();
|
|
|
+ FsUser userMap = new FsUser();
|
|
|
userMap.setUserId(user.getUserId());
|
|
|
- userMap.setIntegral(user.getIntegral()+config.getAnswerIntegral());
|
|
|
+ userMap.setIntegral(user.getIntegral() + config.getAnswerIntegral());
|
|
|
fsUserMapper.updateFsUser(userMap);
|
|
|
+
|
|
|
+ // 记录积分日志
|
|
|
FsUserIntegralLogs integralLogs = new FsUserIntegralLogs();
|
|
|
integralLogs.setIntegral(config.getAnswerIntegral().longValue());
|
|
|
integralLogs.setUserId(user.getUserId());
|
|
@@ -746,136 +833,14 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
integralLogs.setCreateTime(new Date());
|
|
|
fsUserIntegralLogsMapper.insertFsUserIntegralLogs(integralLogs);
|
|
|
|
|
|
+ //更新看课记录的奖励类型
|
|
|
log.setRewardType(config.getRewardType());
|
|
|
courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
- //转换红包
|
|
|
- FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
- redPacketLog.setCourseId(param.getCourseId());
|
|
|
- redPacketLog.setOutBatchNo(integralLogs.getId().toString());
|
|
|
- redPacketLog.setCompanyId(param.getCompanyId());
|
|
|
- redPacketLog.setUserId(param.getUserId());
|
|
|
- redPacketLog.setVideoId(param.getVideoId());
|
|
|
- redPacketLog.setStatus(1);
|
|
|
- redPacketLog.setQwUserId(param.getQwUserId() != null ? param.getQwUserId() : null );
|
|
|
- redPacketLog.setCompanyUserId(param.getCompanyUserId());
|
|
|
- redPacketLog.setCreateTime(new Date());
|
|
|
- redPacketLog.setAmount(BigDecimal.valueOf(config.getAnswerIntegral()).divide(BigDecimal.valueOf(1000)));
|
|
|
- redPacketLog.setRemark("点播答题领取积分转");
|
|
|
- redPacketLog.setWatchLogId(log.getLogId() !=null ? log.getLogId() : null);
|
|
|
- redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
+ logger.info("发放奖励====================》看课记录,{}",log);
|
|
|
|
|
|
return R.ok("奖励发放成功");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional
|
|
|
- public R sendRewardNew(FsCourseSendRewardUParam param) {
|
|
|
- FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
|
|
|
- if (StringUtils.isEmpty(user.getMpOpenId())){
|
|
|
- return R.error("未识别到领取信息");
|
|
|
- }
|
|
|
- FsCourseWatchLog log = new FsCourseWatchLog();
|
|
|
-
|
|
|
- //判断链接类型
|
|
|
- if (param.getLinkType()!=null&¶m.getLinkType()==1){
|
|
|
- FsCourseRedPacketLog packetLog = redPacketLogMapper.selectFsCourseRedPacketLogByTemporary(param.getVideoId(),param.getUserId());
|
|
|
- if (packetLog!=null){
|
|
|
- return R.error("奖励已发放");
|
|
|
- }
|
|
|
- }else {
|
|
|
- log = courseWatchLogMapper.getWatchCourseVideo(param.getUserId(),param.getVideoId(),param.getQwUserId(),param.getQwExternalId());
|
|
|
- if (log==null){
|
|
|
- return R.error("无记录");
|
|
|
- }
|
|
|
- if (log.getRewardType()!=null){
|
|
|
- return R.error("奖励已发放");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
|
- //发放奖励
|
|
|
- switch (param.getRewardType()){
|
|
|
- //红包奖励
|
|
|
- case 1:
|
|
|
- BigDecimal amount = BigDecimal.ZERO;
|
|
|
- FsUserCourseVideoRedPackage redPackage = fsUserCourseVideoRedPackageMapper.selectRedPacketByCompanyId(param.getVideoId(), param.getCompanyId());
|
|
|
- WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
|
|
|
-
|
|
|
- if (redPackage!=null){
|
|
|
- amount = redPackage.getRedPacketMoney();
|
|
|
- }else if (video!=null){
|
|
|
- amount = new BigDecimal(video.getRedPacketMoney());
|
|
|
- }
|
|
|
- packetParam.setOpenId(user.getMpOpenId());
|
|
|
- packetParam.setAmount(amount);
|
|
|
- R sendRedPacket = paymentService.sendRedPacketV3(packetParam);
|
|
|
- if (sendRedPacket.get("code").equals(200)){
|
|
|
- TransferBillsResult transferBillsResult = (TransferBillsResult)sendRedPacket.get("data");
|
|
|
- //添加红包记录
|
|
|
- FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
- redPacketLog.setCourseId(param.getCourseId());
|
|
|
- redPacketLog.setOutBatchNo(transferBillsResult.getOutBillNo());
|
|
|
- redPacketLog.setCompanyId(param.getCompanyId());
|
|
|
- redPacketLog.setUserId(param.getUserId());
|
|
|
- redPacketLog.setVideoId(param.getVideoId());
|
|
|
- redPacketLog.setStatus(0);
|
|
|
- redPacketLog.setQwUserId(param.getQwUserId() != null ? param.getQwUserId() : null );
|
|
|
- redPacketLog.setCompanyUserId(param.getCompanyUserId());
|
|
|
- redPacketLog.setCreateTime(new Date());
|
|
|
- redPacketLog.setAmount(amount);
|
|
|
- redPacketLog.setWatchLogId(log.getLogId() !=null ? log.getLogId() : null);
|
|
|
- redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
- if (param.getLinkType()==null || param.getLinkType()==0){
|
|
|
- log.setRewardType(param.getRewardType());
|
|
|
- courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
- }
|
|
|
- return R.ok("奖励发放成功").put("package",transferBillsResult.getPackageInfo());
|
|
|
- }else {
|
|
|
- return R.error("奖励发送失败,请联系客服");
|
|
|
- }
|
|
|
- //积分奖励
|
|
|
- case 2:
|
|
|
- String json = configService.selectConfigByKey("course.config");
|
|
|
- CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
- //增加积分
|
|
|
- FsUser userMap=new FsUser();
|
|
|
- userMap.setUserId(user.getUserId());
|
|
|
- userMap.setIntegral(user.getIntegral()+config.getAnswerIntegral());
|
|
|
- fsUserMapper.updateFsUser(userMap);
|
|
|
- FsUserIntegralLogs integralLogs = new FsUserIntegralLogs();
|
|
|
- integralLogs.setIntegral(config.getAnswerIntegral().longValue());
|
|
|
- integralLogs.setUserId(user.getUserId());
|
|
|
- integralLogs.setBalance(userMap.getIntegral());
|
|
|
- integralLogs.setLogType(17);
|
|
|
- integralLogs.setBusinessId(StringUtils.isNotEmpty(log.getLogId().toString()) ? log.getLogId().toString() : null);
|
|
|
- integralLogs.setCreateTime(new Date());
|
|
|
- fsUserIntegralLogsMapper.insertFsUserIntegralLogs(integralLogs);
|
|
|
- if (param.getLinkType()==null || param.getLinkType()==0 ){
|
|
|
- log.setRewardType(param.getRewardType());
|
|
|
- courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
- //转换红包
|
|
|
- FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
- redPacketLog.setCourseId(param.getCourseId());
|
|
|
- redPacketLog.setOutBatchNo(integralLogs.getId().toString());
|
|
|
- redPacketLog.setCompanyId(param.getCompanyId());
|
|
|
- redPacketLog.setUserId(param.getUserId());
|
|
|
- redPacketLog.setVideoId(param.getVideoId());
|
|
|
- redPacketLog.setStatus(1);
|
|
|
- redPacketLog.setQwUserId(param.getQwUserId() != null ? param.getQwUserId() : null );
|
|
|
- redPacketLog.setCompanyUserId(param.getCompanyUserId());
|
|
|
- redPacketLog.setCreateTime(new Date());
|
|
|
- redPacketLog.setAmount(BigDecimal.valueOf(config.getAnswerIntegral()).divide(BigDecimal.valueOf(1000)));
|
|
|
- redPacketLog.setRemark("点播答题领取积分转");
|
|
|
- redPacketLog.setWatchLogId(log.getLogId() !=null ? log.getLogId() : null);
|
|
|
- redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
- }
|
|
|
- return R.ok("奖励发放成功");
|
|
|
- default:
|
|
|
- return R.error("参数错误!");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public List<FsUserCourseVideoPageListVO> pageListCourseVideo(UserCourseVideoPageParam param) {
|
|
|
return fsUserCourseVideoMapper.selectFsUserCourseVideoPageList(param);
|
|
@@ -908,7 +873,17 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
SopUserLogsInfoMapper sopUserLogsInfoMapper;
|
|
|
|
|
|
@Override
|
|
|
- public R registerCourse(FsUserCourseRegisterParam param,FsUser fsUser) {
|
|
|
+ public R registerCourse(FsUserCourseRegisterParam param) {
|
|
|
+
|
|
|
+
|
|
|
+ FsUser fsUser = fsUserMapper.selectFsUserById(param.getUserId());
|
|
|
+ if (fsUser==null){
|
|
|
+ return R.error("未登录成功");
|
|
|
+ }
|
|
|
+ logger.info(""+fsUser);
|
|
|
+ if (fsUser.getIsAddQw()==1){
|
|
|
+ return R.error("已经注册");
|
|
|
+ }
|
|
|
QwExternalContact qwExternalContact = qwExternalContactMapper.selectQwExternalContactById(param.getQwExternalId());
|
|
|
if (qwExternalContact==null){
|
|
|
return R.error("注册信息错误");
|
|
@@ -940,27 +915,249 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void updateVideoUrl() {
|
|
|
- List<FsUserCourseVideo> videos = fsUserCourseVideoMapper.selectVideoupdateUrl();
|
|
|
- for (FsUserCourseVideo video : videos) {
|
|
|
- FsUserCourseVideo video1 = new FsUserCourseVideo();
|
|
|
- video1.setVideoId(video.getVideoId());
|
|
|
- String url = updateUrlPrefix(video.getLineTwo());
|
|
|
- video1.setLineTwo(url);
|
|
|
- fsUserCourseVideoMapper.updateFsUserCourseVideo(video1);
|
|
|
+ @Transactional
|
|
|
+ public ResponseResult<Boolean> isAddCompanyUser(FsUserCourseAddCompanyUserParam param) {
|
|
|
+ logger.info("=======================进入个微-判断是否添加客服===========================,入参:{}",param);
|
|
|
+ //查询用户
|
|
|
+ FsUser fsUser = fsUserMapper.selectFsUserById(param.getUserId());
|
|
|
+ if (fsUser == null){
|
|
|
+ return ResponseResult.fail(404,"当前用户信息不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断该销售是否存在
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectCompanyUserById(param.getCompanyUserId());
|
|
|
+ if (companyUser == null){
|
|
|
+ return ResponseResult.fail(405,"当前销售不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断:1、如果没有绑定销售,就提示;
|
|
|
+ //2、如果只绑定了当前销售,需要添加看课记录(正常流程);
|
|
|
+ //3、以上都不是,则标识重粉,需要加入关系表,并打上重粉标签
|
|
|
+ if(fsUser.getCompanyUserId() == null) {
|
|
|
+ return ResponseResult.fail(503, "暂时未绑定销售,请联系管理员");
|
|
|
+ }
|
|
|
+ if(companyUser.getUserId().equals(fsUser.getCompanyUserId())){
|
|
|
+ //查询看课记录
|
|
|
+ FsCourseWatchLog log = new FsCourseWatchLog();
|
|
|
+ log.setUserId(param.getUserId());
|
|
|
+ log.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ log.setVideoId(param.getVideoId());
|
|
|
+ List<FsCourseWatchLog> fsCourseWatchLogs = courseWatchLogMapper.selectFsCourseWatchLogList(log);
|
|
|
+
|
|
|
+ // 获取课程所属项目id
|
|
|
+ FsUserCourse fsUserCourse = fsUserCourseMapper.selectFsUserCourseByCourseId(param.getCourseId());
|
|
|
+ Long courseProject = null;
|
|
|
+ if(fsUserCourse != null){
|
|
|
+ courseProject = fsUserCourse.getProject();
|
|
|
+ }
|
|
|
+ //如果存在,则更新
|
|
|
+ if (fsCourseWatchLogs != null && !fsCourseWatchLogs.isEmpty()){
|
|
|
+ FsCourseWatchLog updateLog = new FsCourseWatchLog();
|
|
|
+ updateLog.setPeriodId(param.getPeriodId());
|
|
|
+ updateLog.setProject(courseProject);
|
|
|
+ updateLog.setUpdateTime(new Date());
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(updateLog);
|
|
|
+ } else {
|
|
|
+ //如果是会员,则需要添加看课记录
|
|
|
+ FsCourseWatchLog fsCourseWatchLog = new FsCourseWatchLog();
|
|
|
+ BeanUtils.copyProperties(param, fsCourseWatchLog);
|
|
|
+ fsCourseWatchLog.setSendType(1);
|
|
|
+ fsCourseWatchLog.setDuration(0L);
|
|
|
+ fsCourseWatchLog.setCreateTime(new Date());
|
|
|
+ fsCourseWatchLog.setLogType(1);
|
|
|
+ fsCourseWatchLog.setProject(courseProject);
|
|
|
+ courseWatchLogMapper.insertFsCourseWatchLog(fsCourseWatchLog);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ FsUserCompanyUser fsUserCompanyUser = new FsUserCompanyUser();
|
|
|
+ fsUserCompanyUser.setIsRepeatFans(1);
|
|
|
+ fsUserCompanyUser.setUserId(param.getUserId());
|
|
|
+ fsUserCompanyUser.setCompanyId(param.getCompanyId());
|
|
|
+ fsUserCompanyUser.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ QueryWrapper<FsUserCompanyUser> queryWrapper = new QueryWrapper<FsUserCompanyUser>().eq("user_id", param.getUserId()).eq("company_user_id", param.getCompanyUserId());
|
|
|
+ Integer i = fsUserCompanyUserMapper.selectCount(queryWrapper);
|
|
|
+ if(i == 0) {
|
|
|
+ fsUserCompanyUserMapper.insertFsUserCompanyUser(fsUserCompanyUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 打上重粉标签
|
|
|
+ FsUserCourseBeMemberParam fsUserCourseBeMemberParam = new FsUserCourseBeMemberParam();
|
|
|
+ fsUserCourseBeMemberParam.setUserId(param.getUserId());
|
|
|
+ fsUserCourseBeMemberParam.setCompanyId(param.getCompanyId());
|
|
|
+ fsUserCourseBeMemberParam.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ fsUserService.setRepeatFansTag(fsUserCourseBeMemberParam);
|
|
|
+ }
|
|
|
+ return ResponseResult.ok(Boolean.TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseResult<FsUserCourseVideoLinkDetailsVO> getLinkCourseVideoDetails(FsUserCourseVideoLinkParam param) {
|
|
|
+// FsUserCoursePeriodDays periodDays = new FsUserCoursePeriodDays();
|
|
|
+// periodDays.setVideoId(param.getVideoId());
|
|
|
+// periodDays.setPeriodId(param.getPeriodId());
|
|
|
+// //正常情况是只能查询到一条,之前可能存在重复的脏数据,暂使用查询list的方式
|
|
|
+// List<FsUserCoursePeriodDays> fsUserCoursePeriodDays = fsUserCoursePeriodDaysMapper.selectFsUserCoursePeriodDaysList(periodDays);
|
|
|
+// if(fsUserCoursePeriodDays != null && !fsUserCoursePeriodDays.isEmpty()){
|
|
|
+// periodDays = fsUserCoursePeriodDays.get(0);
|
|
|
+// }
|
|
|
+// if(periodDays.getStatus() != 1){
|
|
|
+// return ResponseResult.fail(403, "当前课程未开始或已结束,暂不能看课");
|
|
|
+// }
|
|
|
+
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
+ CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
+
|
|
|
+ // 1、获取视频详情、问题详情
|
|
|
+ ResponseResult<FsUserCourseVideoDetailsVO> videoDetails = this.getVideoDetails(param.getVideoId());
|
|
|
+ FsUserCourseVideoDetailsVO courseVideoDetails = videoDetails.getData() != null ? videoDetails.getData() : null;
|
|
|
+
|
|
|
+ Long duration = 0L;
|
|
|
+ long tipsTime = 0L;
|
|
|
+ int isFinish = 0;
|
|
|
+ FsUserCourseVideoLinkDetailsVO vo = new FsUserCourseVideoLinkDetailsVO();
|
|
|
+ vo.setCourseVideoDetails(courseVideoDetails);
|
|
|
+ vo.setCourseConfig(config);
|
|
|
+ vo.setIsFinish(isFinish);
|
|
|
+ vo.setPlayDuration(duration);
|
|
|
+
|
|
|
+ //2、判断链接类型
|
|
|
+ if (param.getLinkType() != null && param.getLinkType() == 1) {
|
|
|
+ ResponseResult.ok(vo);
|
|
|
+ }
|
|
|
+ // 从Redis中获取用户目前的观看时长
|
|
|
+ String redisKey = "h5wxuser:watch:duration:" + param.getFsUserId() + ":" + param.getVideoId() + ":" + param.getCompanyUserId();
|
|
|
+ String durationCurrent = redisCache.getCacheObject(redisKey);
|
|
|
+
|
|
|
+ //3、获取看课记录
|
|
|
+ FsCourseWatchLog watchLog = courseWatchLogMapper.getWatchLogByFsUser(param.getVideoId(), param.getFsUserId(), param.getCompanyUserId());
|
|
|
+ if (durationCurrent != null) {
|
|
|
+ duration = Long.parseLong(durationCurrent);
|
|
|
+ } else {
|
|
|
+ duration = Objects.isNull(watchLog) ? 0 : watchLog.getDuration();
|
|
|
+ }
|
|
|
+//
|
|
|
+// if (course.getDuration()!=null){
|
|
|
+// tipsTime = course.getDuration()/2;
|
|
|
+// }
|
|
|
+ //判断是否完课
|
|
|
+ if (watchLog!=null && watchLog.getLogType() == 2) {
|
|
|
+ isFinish = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ //将视频时长也存到redis
|
|
|
+ String videoRedisKey = "h5wxuser:video:duration:" + param.getVideoId();
|
|
|
+ Long videoDuration = redisCache.getCacheObject(videoRedisKey);
|
|
|
+ if (videoDuration == null) {
|
|
|
+ redisCache.setCacheObject(videoRedisKey, courseVideoDetails != null ? courseVideoDetails.getDuration() != null ? courseVideoDetails.getDuration() : 0 : 0);
|
|
|
}
|
|
|
+ vo.setIsFinish(isFinish);
|
|
|
+ vo.setPlayDuration(duration);
|
|
|
+ //判断营期的课程状态是否是进行中
|
|
|
+ if(param.getId() != null){
|
|
|
+ FsUserCoursePeriodDays days = fsUserCoursePeriodDaysMapper.selectById(param.getId());
|
|
|
+ vo.setStartDateTime(days.getStartDateTime());
|
|
|
+ vo.setEndDateTime(days.getEndDateTime());
|
|
|
+ vo.setRang(DateUtil.isWithinRangeSafe(LocalDateTime.now(), days.getStartDateTime(), days.getEndDateTime()) && days.getStatus() == 1);
|
|
|
+ }
|
|
|
+ return ResponseResult.ok(vo);
|
|
|
}
|
|
|
|
|
|
- public static String updateUrlPrefix(String url) {
|
|
|
- final String oldPrefix = "https://myhktcpv.ylrztop.com";
|
|
|
- final String newPrefix = "https://myhkobs.ylrztop.com";
|
|
|
+ @Override
|
|
|
+ public R addWatchLogByLink(FsUserCourseAddCompanyUserParam param) {
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- // 判断是否以 oldPrefix 开头,如果是,则进行替换
|
|
|
- if (url.startsWith(oldPrefix)) {
|
|
|
- // 去掉 oldPrefix 前缀,然后拼上 newPrefix
|
|
|
- return newPrefix + url.substring(oldPrefix.length());
|
|
|
+ @Override
|
|
|
+ public R updateWatchDurationWx(FsUserCourseVideoUParam param) {
|
|
|
+ //临时短链不做记录
|
|
|
+ if (param.getLinkType() != null && param.getLinkType() == 1){
|
|
|
+ return R.ok();
|
|
|
}
|
|
|
- // 如果不是以 oldPrefix 开头,则原样返回
|
|
|
- return url;
|
|
|
+
|
|
|
+ // 从Redis中获取观看时长
|
|
|
+ String redisKey = "h5wxuser:watch:duration:" + param.getUserId() + ":" + param.getVideoId() + ":" + param.getCompanyUserId();
|
|
|
+ log.info("看课redis缓存key:{}", redisKey);
|
|
|
+ try {
|
|
|
+ String durationStr = redisCache.getCacheObject(redisKey);
|
|
|
+ log.info("看课记录:{}", durationStr);
|
|
|
+ long duration = durationStr != null ? Long.parseLong(durationStr) : 0L;
|
|
|
+
|
|
|
+ // 更新Redis中的观看时长
|
|
|
+ if (param.getDuration() != null && param.getDuration() > duration) {
|
|
|
+ //24小时过期
|
|
|
+ redisCache.setCacheObject(redisKey, param.getDuration().toString(),2,TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新缓存中的心跳时间
|
|
|
+ updateHeartbeatWx(param);
|
|
|
+ return R.ok();
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("更新看课时长失败:{}", redisKey, e.getMessage());
|
|
|
+ return R.error("更新看课时长失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updates(CourseVideoUpdates vo) {
|
|
|
+ fsUserCourseVideoMapper.updates(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void batchSaveVideo(BatchVideoSvae vo) {
|
|
|
+ List<FsVideoResource> videoResourceList = fsVideoResourceMapper.selectBatchIds(vo.getIds());
|
|
|
+ FsUserCourseVideo param = new FsUserCourseVideo();
|
|
|
+ param.setCourseId(vo.getCourseId());
|
|
|
+ List<FsUserCourseVideo> videoList = selectFsUserCourseVideoList(param);
|
|
|
+ AtomicLong i = new AtomicLong(videoList.size() + 1);
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
+ CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
+
|
|
|
+ List<FsUserCourseVideo> collect = videoResourceList.stream().map(e -> {
|
|
|
+ FsUserCourseVideo entity = new FsUserCourseVideo();
|
|
|
+ entity.setTitle(e.getFileName());
|
|
|
+ entity.setVideoUrl(e.getVideoUrl());
|
|
|
+ entity.setThumbnail(e.getThumbnail());
|
|
|
+ entity.setDuration(e.getDuration().longValue());
|
|
|
+ entity.setCourseId(vo.getCourseId());
|
|
|
+ entity.setStatus(3L);
|
|
|
+ entity.setCourseSort(i.getAndIncrement());
|
|
|
+ entity.setFileName(e.getFileName());
|
|
|
+ entity.setQuestionBankId(e.getProjectIds());
|
|
|
+ entity.setLineOne(e.getLine1());
|
|
|
+ entity.setLineTwo(e.getLine2());
|
|
|
+ entity.setLineThree(e.getLine3());
|
|
|
+ entity.setRedPacketMoney(config.getRedPackageMoney());
|
|
|
+ entity.setFileSize(e.getFileSize());
|
|
|
+ entity.setFileKey(e.getFileKey());
|
|
|
+ entity.setIsTranscode(0);
|
|
|
+ return entity;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ fsUserCourseVideoMapper.insertBatchFsUserCourseVideo(collect);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void batchUpdateRed(List<BatchRedUpdate> list) {
|
|
|
+ list.forEach(e -> {
|
|
|
+ fsUserCourseVideoMapper.updateRedPacketMoney(e.getVideoId(), e.getRedPacketMoney());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取选项列表
|
|
|
+ * @param params 参数
|
|
|
+ * @return list
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<OptionsVO> selectVideoListByMap(Map<String, Object> params) {
|
|
|
+ return fsUserCourseVideoMapper.selectVideoListByMap(params);
|
|
|
+ }
|
|
|
+
|
|
|
+ //会员-更新心跳时间
|
|
|
+ public void updateHeartbeatWx(FsUserCourseVideoUParam param) {
|
|
|
+ String redisKey = "h5wxuser:watch:heartbeat:" + param.getUserId() + ":" + param.getVideoId() + ":" + param.getCompanyUserId();
|
|
|
+ redisCache.setCacheObject(redisKey, LocalDateTime.now().toString());
|
|
|
+ // 设置 Redis 记录的过期时间(例如 5 分钟)
|
|
|
+ redisCache.expire(redisKey, 300, TimeUnit.SECONDS);
|
|
|
}
|
|
|
}
|