|
|
@@ -2122,7 +2122,6 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- @RepeatSubmit(interval = 5000)
|
|
|
public ResponseResult<FsUser> isAddCompanyUser(FsUserCourseAddCompanyUserParam param) {
|
|
|
logger.info("\n 【进入个微-判断是否添加客服】,入参:{}", param);
|
|
|
|
|
|
@@ -2142,36 +2141,45 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService {
|
|
|
}
|
|
|
//公开课
|
|
|
if (param.getIsOpenCourse() != null && param.getIsOpenCourse() == 1) {
|
|
|
- FsCourseWatchLog watchCourseVideo = courseWatchLogMapper.getCourseWatchLogByUser(param.getUserId(), param.getVideoId(), null);
|
|
|
- //添加判断:该用户是否已经存在此课程的看课记录,并且看课记录的销售id不是传入的销售id
|
|
|
- if (watchCourseVideo != null) {
|
|
|
- FsCourseWatchLog updateLog = new FsCourseWatchLog();
|
|
|
- updateLog.setUpdateTime(new Date());
|
|
|
- if (param.getTypeFlag() != null) {
|
|
|
- updateLog.setWatchType(param.getTypeFlag());
|
|
|
+ String watchLogLockKey = "course:watch:log:" + param.getUserId() + ":" + param.getVideoId() + ":0:1";
|
|
|
+ RLock watchLogLock = redissonClient.getLock(watchLogLockKey);
|
|
|
+ watchLogLock.lock(10, TimeUnit.SECONDS);
|
|
|
+ try {
|
|
|
+ FsCourseWatchLog watchCourseVideo = courseWatchLogMapper.getCourseWatchLogByUser(param.getUserId(), param.getVideoId(), null);
|
|
|
+ //添加判断:该用户是否已经存在此课程的看课记录,并且看课记录的销售id不是传入的销售id
|
|
|
+ if (watchCourseVideo != null) {
|
|
|
+ FsCourseWatchLog updateLog = new FsCourseWatchLog();
|
|
|
+ updateLog.setUpdateTime(new Date());
|
|
|
+ if (param.getTypeFlag() != null) {
|
|
|
+ updateLog.setWatchType(param.getTypeFlag());
|
|
|
+ }
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(updateLog);
|
|
|
+ } else {
|
|
|
+ FsCourseWatchLog fsCourseWatchLog = new FsCourseWatchLog();
|
|
|
+ BeanUtils.copyProperties(param, fsCourseWatchLog);
|
|
|
+ fsCourseWatchLog.setCompanyId(companyUser.getCompanyId());
|
|
|
+ fsCourseWatchLog.setSendType(1);
|
|
|
+ fsCourseWatchLog.setDuration(0L);
|
|
|
+ fsCourseWatchLog.setCreateTime(new Date());
|
|
|
+ fsCourseWatchLog.setLogType(1);
|
|
|
+ if (param.getTypeFlag() != null) {
|
|
|
+ fsCourseWatchLog.setWatchType(param.getTypeFlag());
|
|
|
+ }
|
|
|
+ courseWatchLogMapper.insertFsCourseWatchLog(fsCourseWatchLog);
|
|
|
+
|
|
|
+ String redisKey = "h5wxuser:watch:heartbeat:" + param.getUserId() + ":" + param.getVideoId() + ":" + 0;
|
|
|
+ redisCache.setCacheObject(redisKey, LocalDateTime.now().toString());
|
|
|
+ redisCache.expire(redisKey, 300, TimeUnit.SECONDS);
|
|
|
+ //记录活跃用户
|
|
|
+ fsAppActiveUserDailyService.recordActiveUserToRedis(param.getUserId(), companyUser.getCompanyId(), param.getCompanyUserId());
|
|
|
}
|
|
|
- courseWatchLogMapper.updateFsCourseWatchLog(updateLog);
|
|
|
- } else {
|
|
|
- FsCourseWatchLog fsCourseWatchLog = new FsCourseWatchLog();
|
|
|
- BeanUtils.copyProperties(param, fsCourseWatchLog);
|
|
|
- fsCourseWatchLog.setCompanyId(companyUser.getCompanyId());
|
|
|
- fsCourseWatchLog.setSendType(1);
|
|
|
- fsCourseWatchLog.setDuration(0L);
|
|
|
- fsCourseWatchLog.setCreateTime(new Date());
|
|
|
- fsCourseWatchLog.setLogType(1);
|
|
|
- if (param.getTypeFlag() != null) {
|
|
|
- fsCourseWatchLog.setWatchType(param.getTypeFlag());
|
|
|
+ } finally {
|
|
|
+ if (watchLogLock.isHeldByCurrentThread()) {
|
|
|
+ watchLogLock.unlock();
|
|
|
}
|
|
|
- courseWatchLogMapper.insertFsCourseWatchLog(fsCourseWatchLog);
|
|
|
-
|
|
|
- String redisKey = "h5wxuser:watch:heartbeat:" + param.getUserId() + ":" + param.getVideoId() + ":" + 0;
|
|
|
- redisCache.setCacheObject(redisKey, LocalDateTime.now().toString());
|
|
|
- redisCache.expire(redisKey, 300, TimeUnit.SECONDS);
|
|
|
- //记录活跃用户
|
|
|
- fsAppActiveUserDailyService.recordActiveUserToRedis(param.getUserId(), companyUser.getCompanyId(), param.getCompanyUserId());
|
|
|
+ }
|
|
|
+ return ResponseResult.ok(fsUser);
|
|
|
}
|
|
|
- return ResponseResult.ok(fsUser);
|
|
|
- }
|
|
|
|
|
|
if (!isUserCoursePeriodValid(param)) {
|
|
|
return ResponseResult.fail(504, "请观看最新的课程项目");
|
|
|
@@ -2265,56 +2273,65 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService {
|
|
|
return ResponseResult.fail(504, "已被拉黑,请联系管理员#" + userCompanyUser.getUserId());
|
|
|
}
|
|
|
|
|
|
- //查询看课记录
|
|
|
- FsCourseWatchLog watchCourseVideo = courseWatchLogMapper.selectWatchLogByUserIdAndVideoIdAndPeriodId(param.getUserId(), param.getVideoId(), param.getPeriodId());
|
|
|
-
|
|
|
- // 项目看课数限制
|
|
|
- Integer logCount = fsUserCourseMapper.selectTodayCourseWatchLogCountByUserIdAndProjectId(param.getUserId(), courseProject);
|
|
|
+ String watchLogLockKey = "course:watch:log:" + param.getUserId() + ":" + param.getVideoId() + ":" + param.getPeriodId() + ":1";
|
|
|
+ RLock watchLogLock = redissonClient.getLock(watchLogLockKey);
|
|
|
+ watchLogLock.lock(10, TimeUnit.SECONDS);
|
|
|
+ try {
|
|
|
+ //查询看课记录
|
|
|
+ FsCourseWatchLog watchCourseVideo = courseWatchLogMapper.selectWatchLogByUserIdAndVideoIdAndPeriodId(param.getUserId(), param.getVideoId(), param.getPeriodId());
|
|
|
|
|
|
- // 院长大讲堂#11 要求可以看两节
|
|
|
- int maxWatchCount = courseProject == 11 ? 2 : 1;
|
|
|
- if (Objects.isNull(watchCourseVideo) && logCount >= maxWatchCount) {
|
|
|
- return ResponseResult.fail(504, "今日学习打卡成功!坚持的你真棒,明天见。");
|
|
|
- }
|
|
|
+ // 项目看课数限制
|
|
|
+ Integer logCount = fsUserCourseMapper.selectTodayCourseWatchLogCountByUserIdAndProjectId(param.getUserId(), courseProject);
|
|
|
|
|
|
- //添加判断:该用户是否已经存在此课程的看课记录,并且看课记录的销售id不是传入的销售id
|
|
|
- if (watchCourseVideo != null) {
|
|
|
- if (!watchCourseVideo.getCompanyUserId().equals(param.getCompanyUserId())) {
|
|
|
- //提示
|
|
|
- log.error("数据库存在销售信息:{},分享得销售信息:{}", watchCourseVideo.getCompanyUserId(), param.getCompanyUserId());
|
|
|
- return ResponseResult.fail(504, "已看过其他销售分享的此课程,不能重复观看");
|
|
|
+ // 院长大讲堂#11 要求可以看两节
|
|
|
+ int maxWatchCount = courseProject == 11 ? 2 : 1;
|
|
|
+ if (Objects.isNull(watchCourseVideo) && logCount >= maxWatchCount) {
|
|
|
+ return ResponseResult.fail(504, "今日学习打卡成功!坚持的你真棒,明天见。");
|
|
|
}
|
|
|
|
|
|
- FsCourseWatchLog updateLog = new FsCourseWatchLog();
|
|
|
- updateLog.setLogId(watchCourseVideo.getLogId());
|
|
|
- updateLog.setCompanyId(companyUser.getCompanyId());
|
|
|
- updateLog.setPeriodId(param.getPeriodId());
|
|
|
- updateLog.setProject(courseProject);
|
|
|
- updateLog.setUpdateTime(new Date());
|
|
|
- if (param.getTypeFlag() != null) {
|
|
|
- updateLog.setWatchType(param.getTypeFlag());
|
|
|
- }
|
|
|
- courseWatchLogMapper.updateFsCourseWatchLog(updateLog);
|
|
|
- } else {
|
|
|
- FsCourseWatchLog fsCourseWatchLog = new FsCourseWatchLog();
|
|
|
- BeanUtils.copyProperties(param, fsCourseWatchLog);
|
|
|
- fsCourseWatchLog.setCompanyId(companyUser.getCompanyId());
|
|
|
- fsCourseWatchLog.setSendType(1);
|
|
|
- fsCourseWatchLog.setDuration(0L);
|
|
|
- fsCourseWatchLog.setCreateTime(new Date());
|
|
|
- fsCourseWatchLog.setLogType(1);
|
|
|
- fsCourseWatchLog.setProject(courseProject);
|
|
|
- if (param.getTypeFlag() != null) {
|
|
|
- fsCourseWatchLog.setWatchType(param.getTypeFlag());
|
|
|
- }
|
|
|
- courseWatchLogMapper.insertFsCourseWatchLog(fsCourseWatchLog);
|
|
|
+ //添加判断:该用户是否已经存在此课程的看课记录,并且看课记录的销售id不是传入的销售id
|
|
|
+ if (watchCourseVideo != null) {
|
|
|
+ if (!watchCourseVideo.getCompanyUserId().equals(param.getCompanyUserId())) {
|
|
|
+ //提示
|
|
|
+ log.error("数据库存在销售信息:{},分享得销售信息:{}", watchCourseVideo.getCompanyUserId(), param.getCompanyUserId());
|
|
|
+ return ResponseResult.fail(504, "已看过其他销售分享的此课程,不能重复观看");
|
|
|
+ }
|
|
|
|
|
|
- String redisKey = "h5wxuser:watch:heartbeat:" + param.getUserId() + ":" + param.getVideoId() + ":" + param.getCompanyUserId();
|
|
|
- redisCache.setCacheObject(redisKey, LocalDateTime.now().toString());
|
|
|
- redisCache.expire(redisKey, 300, TimeUnit.SECONDS);
|
|
|
+ FsCourseWatchLog updateLog = new FsCourseWatchLog();
|
|
|
+ updateLog.setLogId(watchCourseVideo.getLogId());
|
|
|
+ updateLog.setCompanyId(companyUser.getCompanyId());
|
|
|
+ updateLog.setPeriodId(param.getPeriodId());
|
|
|
+ updateLog.setProject(courseProject);
|
|
|
+ updateLog.setUpdateTime(new Date());
|
|
|
+ if (param.getTypeFlag() != null) {
|
|
|
+ updateLog.setWatchType(param.getTypeFlag());
|
|
|
+ }
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(updateLog);
|
|
|
+ } else {
|
|
|
+ FsCourseWatchLog fsCourseWatchLog = new FsCourseWatchLog();
|
|
|
+ BeanUtils.copyProperties(param, fsCourseWatchLog);
|
|
|
+ fsCourseWatchLog.setCompanyId(companyUser.getCompanyId());
|
|
|
+ fsCourseWatchLog.setSendType(1);
|
|
|
+ fsCourseWatchLog.setDuration(0L);
|
|
|
+ fsCourseWatchLog.setCreateTime(new Date());
|
|
|
+ fsCourseWatchLog.setLogType(1);
|
|
|
+ fsCourseWatchLog.setProject(courseProject);
|
|
|
+ if (param.getTypeFlag() != null) {
|
|
|
+ fsCourseWatchLog.setWatchType(param.getTypeFlag());
|
|
|
+ }
|
|
|
+ courseWatchLogMapper.insertFsCourseWatchLog(fsCourseWatchLog);
|
|
|
|
|
|
- //记录活跃用户
|
|
|
- fsAppActiveUserDailyService.recordActiveUserToRedis(param.getUserId(), companyUser.getCompanyId(), param.getCompanyUserId());
|
|
|
+ String redisKey = "h5wxuser:watch:heartbeat:" + param.getUserId() + ":" + param.getVideoId() + ":" + param.getCompanyUserId();
|
|
|
+ redisCache.setCacheObject(redisKey, LocalDateTime.now().toString());
|
|
|
+ redisCache.expire(redisKey, 300, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ //记录活跃用户
|
|
|
+ fsAppActiveUserDailyService.recordActiveUserToRedis(param.getUserId(), companyUser.getCompanyId(), param.getCompanyUserId());
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ if (watchLogLock.isHeldByCurrentThread()) {
|
|
|
+ watchLogLock.unlock();
|
|
|
+ }
|
|
|
}
|
|
|
//导入im好友
|
|
|
openIMService.checkAndImportFriendByDianBoNew(param.getCompanyUserId(), param.getUserId().toString(), true);
|