|
@@ -5,9 +5,12 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.company.cache.ICompanyUserCacheService;
|
|
|
+import com.fs.company.domain.CompanyUser;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
import com.fs.course.domain.FsCourseFinishTemp;
|
|
|
import com.fs.course.domain.FsCourseWatchLog;
|
|
@@ -34,11 +37,15 @@ import com.fs.qw.vo.QwSopCourseFinishTempSetting;
|
|
|
import com.fs.qw.vo.QwSopTempSetting;
|
|
|
import com.fs.sop.domain.QwSopLogs;
|
|
|
import com.fs.sop.mapper.SopUserLogsMapper;
|
|
|
+import com.fs.store.domain.FsUser;
|
|
|
+import com.fs.store.service.IFsUserService;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.Duration;
|
|
|
import java.time.LocalDate;
|
|
@@ -83,6 +90,13 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
|
|
|
@Autowired
|
|
|
private ConfigUtil configUtil;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ICompanyUserCacheService companyUserCacheService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsUserService fsUserService;
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 查询短链课程看课记录
|
|
|
*
|
|
@@ -382,11 +396,39 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
|
|
|
|
|
|
@Override
|
|
|
public List<FsCourseOverVO> selectFsCourseWatchLogOverStatisticsListVO(FsCourseOverParam param) {
|
|
|
- return fsCourseWatchLogMapper.selectFsCourseWatchLogOverStatisticsListVO(param);
|
|
|
+ QueryWrapper<FsCourseWatchLog> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.select("MIN(create_time) as createTime","company_user_id as companyUserId");
|
|
|
+ if(param.getCompanyId() != null) {
|
|
|
+ queryWrapper.eq("company_id", param.getCompanyId());
|
|
|
+ }
|
|
|
+ if(param.getSTime() != null) {
|
|
|
+ queryWrapper.apply("DATE(create_time) >= DATE({0})", param.getSTime());
|
|
|
+ }
|
|
|
+ if (param.getETime() != null) {
|
|
|
+ queryWrapper.apply("DATE(create_time) <= DATE({0})", param.getETime());
|
|
|
+ }
|
|
|
+ queryWrapper.groupBy("company_user_id");
|
|
|
+ List<FsCourseWatchLog> fsCourseWatchLogs = fsCourseWatchLogMapper.selectList(queryWrapper);
|
|
|
+ List<FsCourseOverVO> fsCourseOverVOS = new ArrayList<>();
|
|
|
+ for (FsCourseWatchLog fsCourseWatchLog : fsCourseWatchLogs) {
|
|
|
+ FsCourseOverVO overVO = new FsCourseOverVO();
|
|
|
+ overVO.setCreateTime(fsCourseWatchLog.getCreateTime());
|
|
|
+ if(fsCourseWatchLog.getCompanyUserId() != null) {
|
|
|
+ CompanyUser companyUser = companyUserCacheService.selectCompanyUserById(fsCourseWatchLog.getCompanyUserId());
|
|
|
+ if (companyUser != null) {
|
|
|
+ overVO.setUserName(companyUser.getUserName());
|
|
|
+ overVO.setUserCreateTime(companyUser.getCreateTime());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fsCourseOverVOS.add(overVO);
|
|
|
+ }
|
|
|
+ return fsCourseOverVOS;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- public void addCourseWatchLogDay() {
|
|
|
+ @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
|
|
|
+ public void addCourseWatchLogDayNew() {
|
|
|
|
|
|
List<FsUserCourse> courses = fsUserCourseMapper.selectFsUserCourseAllCourse();
|
|
|
for (FsUserCourse course : courses) {
|
|
@@ -395,8 +437,21 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
|
|
|
for (FsUserCourseVideo fsUserCourseVideo : fsUserCourseVideos) {
|
|
|
try {
|
|
|
ArrayList<QwWatchLog> QwWatchLogs = new ArrayList<>();
|
|
|
- List<FsQwCourseWatchLogVO> watchLogs = fsCourseWatchLogMapper.selectFsCourseWatchLogByNoDayAndVoidId(fsUserCourseVideo.getVideoId());
|
|
|
+ List<FsQwCourseWatchLogVO> watchLogs = fsCourseWatchLogMapper.selectFsCourseBeforeMonthWatchLogByVideoId(fsUserCourseVideo.getVideoId());
|
|
|
+
|
|
|
for (FsQwCourseWatchLogVO fsCourseWatchLog : watchLogs) {
|
|
|
+
|
|
|
+ // 获取进线时间
|
|
|
+ FsUser fsUser = fsUserService.selectFsUserById(fsCourseWatchLog.getUserId());
|
|
|
+ if (fsUser!=null){
|
|
|
+ fsCourseWatchLog.setFirstTime(fsUser.getCreateTime());
|
|
|
+ }
|
|
|
+ // 查询首次观看时间
|
|
|
+ Date date = fsCourseWatchLogMapper.queryFirstWatchDateLogByVideoId(fsCourseWatchLog.getUserId());
|
|
|
+ if (date!=null){
|
|
|
+ fsCourseWatchLog.setFirstTime(date);
|
|
|
+ }
|
|
|
+
|
|
|
Date firstTime = fsCourseWatchLog.getFirstTime();
|
|
|
Long day=1L;
|
|
|
if (fsCourseWatchLog.getLineTime()==null){
|
|
@@ -410,18 +465,13 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
|
|
|
}else {
|
|
|
//是先导课
|
|
|
if (fsUserCourseVideo.getIsFirst()!=null&&fsUserCourseVideo.getIsFirst()==1){
|
|
|
- int count = qwWatchLogMapper.selectQwWatchLogIsFirst(fsCourseWatchLog.getQwExternalContactId());
|
|
|
+ // 如果存在第一次记录就跳过
|
|
|
+ int count = qwWatchLogMapper.selectQwWatchLogIsFirstByUserId(fsCourseWatchLog.getUserId());
|
|
|
if (count>0){
|
|
|
continue;
|
|
|
}
|
|
|
day=0L;
|
|
|
//不是先导课
|
|
|
- }else {
|
|
|
- day=1L;
|
|
|
- QwExternalContact qwExternalContact = new QwExternalContact();
|
|
|
- qwExternalContact.setId(fsCourseWatchLog.getQwExternalContactId());
|
|
|
- qwExternalContact.setFirstTime(fsCourseWatchLog.getCreateTime());
|
|
|
- qwExternalContactMapper.updateQwExternalContact(qwExternalContact);
|
|
|
}
|
|
|
}
|
|
|
QwWatchLog qwWatchLog = new QwWatchLog();
|
|
@@ -432,6 +482,10 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
|
|
|
qwWatchLog.setStatus(fsCourseWatchLog.getLogType()==3?0:fsCourseWatchLog.getLogType()==2?2:1);
|
|
|
qwWatchLog.setProject(project);
|
|
|
qwWatchLog.setCreateTime(fsCourseWatchLog.getCreateTime());
|
|
|
+ qwWatchLog.setCompanyId(fsCourseWatchLog.getCompanyId());
|
|
|
+ qwWatchLog.setCompanyUserId(fsCourseWatchLog.getCompanyUserId());
|
|
|
+ qwWatchLog.setFsUserId(fsCourseWatchLog.getUserId());
|
|
|
+
|
|
|
QwWatchLogs.add(qwWatchLog);
|
|
|
}
|
|
|
if (!QwWatchLogs.isEmpty()){
|
|
@@ -439,6 +493,7 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
log.error("看课记录add异常:{}",course.getCourseId(),e);
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -447,66 +502,73 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
- public void addCourseWatchLogDay2() {
|
|
|
+ public void addCourseWatchLogDay() {
|
|
|
|
|
|
List<FsUserCourse> courses = fsUserCourseMapper.selectFsUserCourseAllCourse();
|
|
|
for (FsUserCourse course : courses) {
|
|
|
Long project = course.getProject();
|
|
|
List<FsUserCourseVideo> fsUserCourseVideos = fsUserCourseVideoMapper.selectVideoByCourseId(course.getCourseId());
|
|
|
for (FsUserCourseVideo fsUserCourseVideo : fsUserCourseVideos) {
|
|
|
- ArrayList<QwWatchLog> QwWatchLogs = new ArrayList<>();
|
|
|
- List<FsQwCourseWatchLogVO> watchLogs = fsCourseWatchLogMapper.selectFsCourseWatchLogByNoDayAndVoidId2(fsUserCourseVideo.getVideoId());
|
|
|
- for (FsQwCourseWatchLogVO fsCourseWatchLog : watchLogs) {
|
|
|
- Date firstTime = fsCourseWatchLog.getFirstTime();
|
|
|
- Long day=1L;
|
|
|
- if (fsCourseWatchLog.getLineTime()==null){
|
|
|
- continue;
|
|
|
- }
|
|
|
- //不是第一次 看课程
|
|
|
- if (firstTime!=null){
|
|
|
- LocalDate firstLocalDate = firstTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
- LocalDate currentDate = LocalDate.now();
|
|
|
- day = ChronoUnit.DAYS.between(firstLocalDate, currentDate);
|
|
|
- day=day-1;
|
|
|
- }else {
|
|
|
- //是先导课
|
|
|
- if (fsUserCourseVideo.getIsFirst()!=null&&fsUserCourseVideo.getIsFirst()==1){
|
|
|
- int count = qwWatchLogMapper.selectQwWatchLogIsFirst(fsCourseWatchLog.getQwExternalContactId());
|
|
|
- if (count>0){
|
|
|
- continue;
|
|
|
- }
|
|
|
- day=0L;
|
|
|
- //不是先导课
|
|
|
+ try {
|
|
|
+ ArrayList<QwWatchLog> QwWatchLogs = new ArrayList<>();
|
|
|
+ List<FsQwCourseWatchLogVO> watchLogs = fsCourseWatchLogMapper.selectFsCourseWatchLogByNoDayAndVoidId(fsUserCourseVideo.getVideoId());
|
|
|
+ for (FsQwCourseWatchLogVO fsCourseWatchLog : watchLogs) {
|
|
|
+ Date firstTime = fsCourseWatchLog.getFirstTime();
|
|
|
+ Long day=1L;
|
|
|
+ if (fsCourseWatchLog.getLineTime()==null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //不是第一次 看课程
|
|
|
+ if (firstTime!=null){
|
|
|
+ LocalDate firstLocalDate = firstTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
+ day = ChronoUnit.DAYS.between(firstLocalDate, currentDate);
|
|
|
}else {
|
|
|
- day=1L;
|
|
|
- QwExternalContact qwExternalContact = new QwExternalContact();
|
|
|
- qwExternalContact.setId(fsCourseWatchLog.getQwExternalContactId());
|
|
|
- qwExternalContact.setFirstTime(fsCourseWatchLog.getCreateTime());
|
|
|
- qwExternalContactMapper.updateQwExternalContact(qwExternalContact);
|
|
|
+ //是先导课
|
|
|
+ if (fsUserCourseVideo.getIsFirst()!=null&&fsUserCourseVideo.getIsFirst()==1){
|
|
|
+ int count = qwWatchLogMapper.selectQwWatchLogIsFirst(fsCourseWatchLog.getQwExternalContactId());
|
|
|
+ if (count>0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ day=0L;
|
|
|
+ //不是先导课
|
|
|
+ }else {
|
|
|
+ day=1L;
|
|
|
+ QwExternalContact qwExternalContact = new QwExternalContact();
|
|
|
+ qwExternalContact.setId(fsCourseWatchLog.getQwExternalContactId());
|
|
|
+ qwExternalContact.setFirstTime(fsCourseWatchLog.getCreateTime());
|
|
|
+ qwExternalContactMapper.updateQwExternalContact(qwExternalContact);
|
|
|
+ }
|
|
|
}
|
|
|
+ QwWatchLog qwWatchLog = new QwWatchLog();
|
|
|
+ qwWatchLog.setExtId(fsCourseWatchLog.getQwExternalContactId());
|
|
|
+ qwWatchLog.setLineTime(fsCourseWatchLog.getLineTime());
|
|
|
+ qwWatchLog.setQwUserId(Long.parseLong(fsCourseWatchLog.getQwUserId()));
|
|
|
+ qwWatchLog.setDay(day);
|
|
|
+ qwWatchLog.setStatus(fsCourseWatchLog.getLogType()==3?0:fsCourseWatchLog.getLogType()==2?2:1);
|
|
|
+ qwWatchLog.setProject(project);
|
|
|
+ qwWatchLog.setCreateTime(fsCourseWatchLog.getCreateTime());
|
|
|
+ qwWatchLog.setCompanyId(fsCourseWatchLog.getCompanyId());
|
|
|
+ qwWatchLog.setCompanyUserId(fsCourseWatchLog.getCompanyUserId());
|
|
|
+ qwWatchLog.setFsUserId(fsCourseWatchLog.getUserId());
|
|
|
+ QwWatchLogs.add(qwWatchLog);
|
|
|
}
|
|
|
- QwWatchLog qwWatchLog = new QwWatchLog();
|
|
|
- qwWatchLog.setExtId(fsCourseWatchLog.getQwExternalContactId());
|
|
|
- qwWatchLog.setLineTime(fsCourseWatchLog.getLineTime());
|
|
|
- qwWatchLog.setQwUserId(Long.parseLong(fsCourseWatchLog.getQwUserId()));
|
|
|
- qwWatchLog.setDay(day);
|
|
|
- qwWatchLog.setStatus(fsCourseWatchLog.getLogType()==3?0:fsCourseWatchLog.getLogType()==2?2:1);
|
|
|
- qwWatchLog.setProject(project);
|
|
|
- qwWatchLog.setCreateTime(fsCourseWatchLog.getCreateTime());
|
|
|
- QwWatchLogs.add(qwWatchLog);
|
|
|
- }
|
|
|
- if (!QwWatchLogs.isEmpty()){
|
|
|
- qwWatchLogMapper.insertQwWatchLogBatch(QwWatchLogs);
|
|
|
+ if (!QwWatchLogs.isEmpty()){
|
|
|
+ qwWatchLogMapper.insertQwWatchLogBatch(QwWatchLogs);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("看课记录add异常:{}",course.getCourseId(),e);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public Long getVideoDuration(Long videoId){
|
|
|
//将视频时长也存到redis
|
|
|
String videoRedisKey = "h5user:video:duration:" + videoId;
|