|
@@ -6,15 +6,19 @@ import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.microsoft.schemas.office.visio.x2012.main.SectionType;
|
|
|
+import com.zhongzheng.common.core.page.TableDataInfo;
|
|
|
import com.zhongzheng.common.core.redis.RedisCache;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
import com.zhongzheng.modules.bank.domain.Exam;
|
|
|
-import com.zhongzheng.modules.course.bo.CourseQueryBo;
|
|
|
+import com.zhongzheng.modules.course.bo.*;
|
|
|
import com.zhongzheng.modules.course.domain.CoursePhotoLog;
|
|
|
+import com.zhongzheng.modules.course.domain.CourseSection;
|
|
|
import com.zhongzheng.modules.course.service.ICourseChapterSectionService;
|
|
|
import com.zhongzheng.modules.course.service.ICoursePhotoLogService;
|
|
|
import com.zhongzheng.modules.course.service.ICourseSectionService;
|
|
@@ -132,6 +136,8 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
|
|
|
private IUserBankRecordService iUserBankRecordService;
|
|
|
@Autowired
|
|
|
private IUserExamGoodsService iUserExamGoodsService;
|
|
|
+ @Autowired
|
|
|
+ private IPolyvLiveService ployvLiveService;
|
|
|
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
@@ -295,9 +301,10 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Integer insertByAddBo(UserStudyRecordAddBo bo) {
|
|
|
- if(Validator.isEmpty(bo.getOrderGoodsId())){
|
|
|
- throw new CustomException("订单商品ID缺失");
|
|
|
- }
|
|
|
+// if(Validator.isEmpty(bo.getOrderGoodsId())){
|
|
|
+// throw new CustomException("订单商品ID缺失");
|
|
|
+// }
|
|
|
+
|
|
|
String key = "STUDY_Record_"+bo.getUserId();
|
|
|
Long value = redisCache.getCacheObject(key);
|
|
|
if(value!=null&&(Validator.isEmpty(bo.getStatus())||bo.getStatus()!=1)){
|
|
@@ -330,7 +337,16 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
|
|
|
}else{
|
|
|
add.setFirstStartTime(add.getStartTime());
|
|
|
}
|
|
|
+ add.setBuyCourse(bo.getBuyCourse());
|
|
|
+ //获取节类型
|
|
|
+ CourseSection section = iCourseSectionService.getById(bo.getSectionId());
|
|
|
+ add.setSectionType(section.getSectionType());
|
|
|
+ add.setFirstEntry(ObjectUtils.isNull(bo.getFirstEntry())?0:bo.getFirstEntry());
|
|
|
this.save(add);
|
|
|
+ if (ObjectUtils.isNull(bo.getOrderGoodsId())){
|
|
|
+ //没有购买商品,通过分享观看
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
/* if(courseSectionVo.getSectionType()==1||courseSectionVo.getSectionType()==2||courseSectionVo.getSectionType()==3){
|
|
|
UserStudyRecordQueryBo queryBo = BeanUtil.toBean(bo, UserStudyRecordQueryBo.class);
|
|
|
*//* queryBo.setUserId(bo.getUserId());
|
|
@@ -622,7 +638,119 @@ public class UserStudyRecordServiceImpl extends ServiceImpl<UserStudyRecordMappe
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<CourseStatementVo> getCourseStatement(CourseStatementBo bo) {
|
|
|
+ com.baomidou.mybatisplus.extension.plugins.pagination.Page<UserStudyRecord> page =
|
|
|
+ page(new com.baomidou.mybatisplus.extension.plugins.pagination.Page<UserStudyRecord>(bo.getPageNum(), bo.getPageSize()),
|
|
|
+ new LambdaQueryWrapper<UserStudyRecord>()
|
|
|
+ .eq(UserStudyRecord::getGoodsId, bo.getGoodsId())
|
|
|
+ .groupBy(UserStudyRecord::getSectionId));
|
|
|
+ if (CollectionUtils.isEmpty(page.getRecords())){
|
|
|
+ return new TableDataInfo<>();
|
|
|
+ }
|
|
|
+ List<CourseStatementVo> statementVos = page.getRecords().stream().map(item -> {
|
|
|
+ CourseStatementVo vo = new CourseStatementVo();
|
|
|
+ //课程节信息
|
|
|
+ CourseSection section = iCourseSectionService.getById(item.getSectionId());
|
|
|
+ if (ObjectUtils.isNotNull(section)) {
|
|
|
+ vo.setSectionName(section.getName());
|
|
|
+ vo.setLiveStartTime(section.getLiveStartTime());
|
|
|
+ vo.setLiveEndTime(section.getLiveEndTime());
|
|
|
+ vo.setLiveUrl(section.getLiveUrl());
|
|
|
+ }
|
|
|
+ //统计观看人数
|
|
|
+ List<UserStudyRecord> recordList = list(new LambdaQueryWrapper<UserStudyRecord>()
|
|
|
+ .eq(UserStudyRecord::getGoodsId, item.getGoodsId())
|
|
|
+ .eq(UserStudyRecord::getSectionId, item.getSectionId()));
|
|
|
+ if (CollectionUtils.isNotEmpty(recordList)) {
|
|
|
+ Map<Long, List<UserStudyRecord>> map = recordList.stream().collect(Collectors.groupingBy(UserStudyRecord::getUserId));
|
|
|
+ vo.setWatchNumber(map.keySet().size());
|
|
|
+ Integer unBuyCourse = 0;
|
|
|
+ Integer buyCourse = 0;
|
|
|
+ for (UserStudyRecord record : recordList) {
|
|
|
+ if (record.getBuyCourse() == 0) {
|
|
|
+ //没有购买课程
|
|
|
+ unBuyCourse++;
|
|
|
+ } else {
|
|
|
+ buyCourse++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vo.setBuyCourseNumber(buyCourse);
|
|
|
+ vo.setUnBuyCourseNumber(unBuyCourse);
|
|
|
+ Map<String, List<UserStudyRecord>> collect = recordList.stream().filter(x -> ObjectUtils.isNotNull(x.getFromPlat())).collect(Collectors.groupingBy(UserStudyRecord::getFromPlat));
|
|
|
+ if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
+ collect.forEach((k, v) -> {
|
|
|
+ if (k.equals("1")) {
|
|
|
+ //小程序
|
|
|
+ vo.setAppWatchNumber(collect.get(k).size());
|
|
|
+ } else {
|
|
|
+ //PC
|
|
|
+ vo.setAdminWatchNumber(collect.get(k).size());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ //查询保利威直播状态
|
|
|
+ Set<String> setUrl = statementVos.stream().map(CourseStatementVo::getLiveUrl).collect(Collectors.toSet());
|
|
|
+ List<LiveChannelBasicInfoResponse> result = setUrl.stream().map(url -> {
|
|
|
+ PolyvLiveQueryBo queryBo = new PolyvLiveQueryBo();
|
|
|
+ queryBo.setChannelId(url);
|
|
|
+ LiveChannelBasicInfoResponse response = new LiveChannelBasicInfoResponse();
|
|
|
+ try {
|
|
|
+ response = ployvLiveService.GetChannelBasicInfo(queryBo);
|
|
|
+ } catch (Exception e) {
|
|
|
+// throw new CustomException("获取保利威直播状态失败");
|
|
|
+ response.setChannelId(url);
|
|
|
+ response.setWatchStatus("waiting");
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ statementVos.forEach(item -> {
|
|
|
+ for (LiveChannelBasicInfoResponse response : result) {
|
|
|
+ if (net.polyv.common.v1.util.StringUtils.isNotBlank(item.getLiveUrl()) && item.getLiveUrl().equals(response.getChannelId())){
|
|
|
+ item.setWatchStatus(response.getWatchStatus());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ TableDataInfo<CourseStatementVo> info = new TableDataInfo<CourseStatementVo>();
|
|
|
+ info.setRows(statementVos);
|
|
|
+ info.setTotal(page.getTotal());
|
|
|
+ return info;
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<CourseSectionDetailVo> getCourseDetailStatistics(CourseSectionDetailBo bo) {
|
|
|
+ List<CourseSectionDetailVo> detailVos = baseMapper.getUserByRecord(bo);
|
|
|
+ if (CollectionUtils.isEmpty(detailVos)){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ //直播时长
|
|
|
+ CourseSection section = iCourseSectionService.getById(bo.getSectionId());
|
|
|
+ Long liveStartTime = 0L;
|
|
|
+ if (ObjectUtils.isNotNull(section)){
|
|
|
+ liveStartTime = section.getLiveEndTime() - section.getLiveStartTime();
|
|
|
+ }
|
|
|
+ //获取学员观看统计次数
|
|
|
+ for (CourseSectionDetailVo item : detailVos) {
|
|
|
+ List<UserStudyRecord> list = list(new LambdaQueryWrapper<UserStudyRecord>()
|
|
|
+ .eq(UserStudyRecord::getUserId, item.getUserId())
|
|
|
+ .eq(UserStudyRecord::getGoodsId, bo.getGoodsId())
|
|
|
+ .eq(UserStudyRecord::getCourseId, bo.getCourseId())
|
|
|
+ .eq(UserStudyRecord::getSectionId, bo.getSectionId()));
|
|
|
+ item.setLiveDuration(liveStartTime);
|
|
|
+ if (list.stream().anyMatch(x -> x.getBuyCourse() == 1)){
|
|
|
+ //已开课
|
|
|
+ item.setPurchaseStatus(1);
|
|
|
+ }
|
|
|
+ Long sum = list.stream().filter(x -> ObjectUtils.isNotNull(x.getStudyDuration())).mapToLong(UserStudyRecord::getStudyDuration).sum();
|
|
|
+ item.setWatchLiveDuration(sum);
|
|
|
+ Integer size = list.stream().filter(x -> ObjectUtils.isNotNull(x.getFirstEntry()) && x.getFirstEntry() == 1).collect(Collectors.toList()).size();
|
|
|
+ item.setWatchNumber(size);
|
|
|
+ }
|
|
|
+ return detailVos;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|