|
@@ -10,20 +10,22 @@ 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.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.FsUserCourseAddCompanyUserParam;
|
|
|
+import com.fs.course.param.newfs.FsUserCourseVideoLinkParam;
|
|
|
+import com.fs.course.param.newfs.FsUserCourseVideoUParam;
|
|
|
import com.fs.course.param.newfs.UserCourseVideoPageParam;
|
|
|
import com.fs.course.service.IFsUserCourseVideoService;
|
|
|
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.param.WxSendRedPacketParam;
|
|
|
import com.fs.sop.mapper.SopUserLogsInfoMapper;
|
|
|
import com.fs.store.domain.FsUser;
|
|
@@ -121,6 +123,9 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
@Autowired
|
|
|
private ISysConfigService sysConfigService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CompanyUserMapper companyUserMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询课堂视频
|
|
|
*
|
|
@@ -838,7 +843,143 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ResponseResult<Boolean> isAddCompanyUser(FsUserCourseVideoAddKfUParam param) {
|
|
|
+ @Transactional
|
|
|
+ public ResponseResult<Boolean> isAddCompanyUser(FsUserCourseAddCompanyUserParam param) {
|
|
|
+ logger.info("=======================进入个微-判断是否添加客服===========================,入参:{}",param);
|
|
|
+ //查询用户
|
|
|
+ FsUser fsUser = fsUserMapper.selectFsUserById(param.getUserId());
|
|
|
+ if (fsUser == null){
|
|
|
+ return ResponseResult.fail(401,"未授权");
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断该销售是否存在
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectCompanyUserById(param.getCompanyUserId());
|
|
|
+ if (companyUser == null){
|
|
|
+ return ResponseResult.fail(500,"销售不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断该用户是否绑定了该销售
|
|
|
+ List<FsUser> fsUserCompany = fsUserMapper.getFsUserByCompanyUserAndId(param.getCompanyUserId(), param.getUserId());
|
|
|
+ if(fsUserCompany != null && !fsUserCompany.isEmpty()){
|
|
|
+ //查询看课记录
|
|
|
+ FsCourseWatchLog log = new FsCourseWatchLog();
|
|
|
+ log.setUserId(param.getUserId());
|
|
|
+ log.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ log.setVideoId(param.getVideoId());
|
|
|
+ List<FsCourseWatchLog> fsCourseWatchLogs = courseWatchLogMapper.selectFsCourseWatchLogList(log);
|
|
|
+ //如果存在,则更新
|
|
|
+ if (fsCourseWatchLogs != null && !fsCourseWatchLogs.isEmpty()){
|
|
|
+ FsCourseWatchLog updateLog = new FsCourseWatchLog();
|
|
|
+ updateLog.setUpdateTime(new Date());
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(updateLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果是会员,则需要添加看课记录
|
|
|
+ FsCourseWatchLog fsCourseWatchLog = new FsCourseWatchLog();
|
|
|
+ BeanUtils.copyProperties(param, fsCourseWatchLog);
|
|
|
+ fsCourseWatchLog.setSendType(1);
|
|
|
+ fsCourseWatchLog.setDuration(0L);
|
|
|
+ fsCourseWatchLog.setCreateTime(new Date());
|
|
|
+ fsCourseWatchLog.setLogType(1);
|
|
|
+ courseWatchLogMapper.insertFsCourseWatchLog(fsCourseWatchLog);
|
|
|
+ } else {
|
|
|
+ return ResponseResult.ok(Boolean.FALSE);
|
|
|
+ }
|
|
|
+ return ResponseResult.ok(Boolean.TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseResult<FsUserCourseVideoLinkDetailsVO> getLinkCourseVideoDetails(FsUserCourseVideoLinkParam param) {
|
|
|
+ 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();
|
|
|
+ String durationCurrent = redisCache.getCacheObject(redisKey);
|
|
|
+
|
|
|
+ //3、获取看课记录
|
|
|
+ FsCourseWatchLog watchLog = courseWatchLogMapper.getWatchLogByFsUser(param.getVideoId(), param.getFsUserId());
|
|
|
+ if (durationCurrent != null) {
|
|
|
+ duration = Long.parseLong(durationCurrent);
|
|
|
+ } else {
|
|
|
+ duration = 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() : 0);
|
|
|
+ }
|
|
|
+ vo.setIsFinish(isFinish);
|
|
|
+ vo.setPlayDuration(duration);
|
|
|
+ return ResponseResult.ok(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R addWatchLogByLink(FsUserCourseAddCompanyUserParam param) {
|
|
|
+
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R updateWatchDurationWx(FsUserCourseVideoUParam param) {
|
|
|
+ //临时短链不做记录
|
|
|
+ if (param.getLinkType() != null && param.getLinkType() == 1){
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从Redis中获取观看时长
|
|
|
+ String redisKey = "h5wxuser:watch:duration:" + param.getUserId() + ":" + param.getVideoId();
|
|
|
+ try {
|
|
|
+ String durationStr = redisCache.getCacheObject(redisKey);
|
|
|
+ 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("更新看课时长失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //会员-更新心跳时间
|
|
|
+ public void updateHeartbeatWx(FsUserCourseVideoUParam param) {
|
|
|
+ String redisKey = "h5wxuser:watch:heartbeat:" + param.getUserId() + ":" + param.getVideoId();
|
|
|
+ redisCache.setCacheObject(redisKey, LocalDateTime.now().toString());
|
|
|
+ // 设置 Redis 记录的过期时间(例如 5 分钟)
|
|
|
+ redisCache.expire(redisKey, 300, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
}
|