|
|
@ -12,7 +12,6 @@ import com.teaching.backend.mapper.records.LearningRecordsMapper; |
|
|
|
import com.teaching.backend.model.entity.records.LearningRecords; |
|
|
|
import com.teaching.backend.model.entity.records.LearningRecords; |
|
|
|
import com.teaching.backend.model.vo.records.LearningRecordsVo; |
|
|
|
import com.teaching.backend.model.vo.records.LearningRecordsVo; |
|
|
|
import com.teaching.backend.service.impl.CourseResourcesServiceImpl; |
|
|
|
import com.teaching.backend.service.impl.CourseResourcesServiceImpl; |
|
|
|
import com.teaching.backend.service.impl.chapter.ChapterServiceImpl; |
|
|
|
|
|
|
|
import com.teaching.backend.service.impl.courses.CoursesServiceImpl; |
|
|
|
import com.teaching.backend.service.impl.courses.CoursesServiceImpl; |
|
|
|
import com.teaching.backend.service.records.LearningRecordsService; |
|
|
|
import com.teaching.backend.service.records.LearningRecordsService; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
@ -36,8 +35,8 @@ public class LearningRecordsServiceImpl extends ServiceImpl<LearningRecordsMappe |
|
|
|
private LearningRecordsMapper learningRecordsMapper; |
|
|
|
private LearningRecordsMapper learningRecordsMapper; |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private CourseResourcesServiceImpl courseResourcesService; |
|
|
|
private CourseResourcesServiceImpl courseResourcesService; |
|
|
|
@Autowired |
|
|
|
// @Autowired
|
|
|
|
private ChapterServiceImpl chapterService; |
|
|
|
// private ChapterServiceImpl chapterService;
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public IPage<LearningRecords> selectPageList(Page<LearningRecords> page, LearningRecords model) { |
|
|
|
public IPage<LearningRecords> selectPageList(Page<LearningRecords> page, LearningRecords model) { |
|
|
@ -53,76 +52,64 @@ public class LearningRecordsServiceImpl extends ServiceImpl<LearningRecordsMappe |
|
|
|
for (LearningRecords learningRecords : list) { |
|
|
|
for (LearningRecords learningRecords : list) { |
|
|
|
learningRecords.setStatus("0"); |
|
|
|
learningRecords.setStatus("0"); |
|
|
|
} |
|
|
|
} |
|
|
|
this.updateBatchById(list); |
|
|
|
updateBatchById(list); |
|
|
|
// System.out.println(this.updateBatchById(list));
|
|
|
|
// System.out.println(this.updateBatchById(list));
|
|
|
|
// this.remove(lambdaQueryWrapper);
|
|
|
|
// this.remove(lambdaQueryWrapper);
|
|
|
|
return "删除成功"; |
|
|
|
return "删除成功"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<LearningRecordsVo> getAll(String userId){ |
|
|
|
public List<LearningRecordsVo> getAll(List<LearningRecords> list){ |
|
|
|
//格式化时间
|
|
|
|
List<LearningRecordsVo> records = new ArrayList<>(); |
|
|
|
//格式化时间
|
|
|
|
//格式化时间
|
|
|
|
String strDateFormat = "yyyy-MM-dd HH:mm:ss"; |
|
|
|
String strDateFormat = "yyyy-MM-dd HH:mm:ss"; |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); |
|
|
|
|
|
|
|
|
|
|
|
List<LearningRecordsVo> list = new ArrayList<>(); |
|
|
|
|
|
|
|
//将学习记录实体转成学习记录Vo实体
|
|
|
|
|
|
|
|
LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper1 = new LambdaQueryWrapper<>(); |
|
|
|
|
|
|
|
lambdaQueryWrapper1 |
|
|
|
|
|
|
|
.orderByDesc(LearningRecords::getAccessTime) |
|
|
|
|
|
|
|
.eq(LearningRecords::getUserId, userId) |
|
|
|
|
|
|
|
.eq(LearningRecords::getStatus, "1"); |
|
|
|
|
|
|
|
// System.out.println("查询数据库结果为:"+this.list(lambdaQueryWrapper1));
|
|
|
|
|
|
|
|
//如果为空-------------------?????
|
|
|
|
//如果为空-------------------?????
|
|
|
|
for (LearningRecords learningRecords : this.list(lambdaQueryWrapper1)) { |
|
|
|
list.forEach(learningRecords -> { |
|
|
|
//查找该用户的学习记录
|
|
|
|
|
|
|
|
// if (learningRecords.getUserId().equals(userId) && learningRecords.getStatus().equals("1")){
|
|
|
|
|
|
|
|
LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------??
|
|
|
|
LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------??
|
|
|
|
BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(缺少人数,和资源名称,时间需要转格式)
|
|
|
|
BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(时间需要转格式)
|
|
|
|
//添加时间
|
|
|
|
Date date = Date.from(learningRecords.getTime().atZone(ZoneId.systemDefault()).toInstant()); |
|
|
|
//LocalDateTime转Date
|
|
|
|
|
|
|
|
Date date = Date.from(learningRecords.getAccessTime().atZone(ZoneId.systemDefault()).toInstant()); |
|
|
|
|
|
|
|
learningRecordsVo.setTime(sdf.format(date)); |
|
|
|
learningRecordsVo.setTime(sdf.format(date)); |
|
|
|
LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
// //统计记录表里有多少人查看过这门资源
|
|
|
|
lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId()); |
|
|
|
// LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
// System.out.println(learningRecords.getResourceId());
|
|
|
|
// lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId());
|
|
|
|
// System.out.println("1");
|
|
|
|
// long count = this.count(lambdaQueryWrapper);
|
|
|
|
|
|
|
|
learningRecordsVo.setNumber(learningRecords.getNumber()); |
|
|
|
String name; |
|
|
|
|
|
|
|
//添加课程名称
|
|
|
|
|
|
|
|
switch (learningRecords.getType()) { |
|
|
|
|
|
|
|
case "4": //如果是资源学习
|
|
|
|
|
|
|
|
learningRecordsVo.setCoursesName(courseResourcesService.getById(learningRecords.getCoursesId()).getName());//设置名称 --------------------------------------------待完善
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "3": //如果是知识点学习记录
|
|
|
|
|
|
|
|
// learningRecordsVo.setCoursesName(knowledgePointService.getById(learningRecords.getCoursesId()).get());
|
|
|
|
|
|
|
|
// if (knowledgePointService.getById(learningRecords.getCoursesId()) != null){
|
|
|
|
|
|
|
|
// name=knowledgePointService.getById(learningRecords.getCoursesId()).getName();
|
|
|
|
|
|
|
|
// }else {
|
|
|
|
|
|
|
|
// name = "查无次记录";
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// learningRecordsVo.setCoursesName(knowledgePointService.getById(learningRecords.getCoursesId()).getName());
|
|
|
|
|
|
|
|
//如果对应的资源不存在
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "2": //如果是章节学习记录
|
|
|
|
|
|
|
|
learningRecordsVo.setCoursesName(chapterService.getById(learningRecords.getCoursesId()).getName()); |
|
|
|
|
|
|
|
//如果对应的资源不存在
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "1": //如果是课程学习记录
|
|
|
|
|
|
|
|
learningRecordsVo.setCoursesName(coursesService.getById(learningRecords.getCoursesId()).getName()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//添加观看人数
|
|
|
|
|
|
|
|
//统计记录表里有多少人查看过这门资源
|
|
|
|
|
|
|
|
long count = this.count(lambdaQueryWrapper); |
|
|
|
|
|
|
|
learningRecordsVo.setNumber(count); |
|
|
|
|
|
|
|
//把整合后该用户的学习记录添加到List里
|
|
|
|
//把整合后该用户的学习记录添加到List里
|
|
|
|
list.add(learningRecordsVo); |
|
|
|
records.add(learningRecordsVo); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
// for (LearningRecords learningRecords : list) {
|
|
|
|
|
|
|
|
// //查找该用户的学习记录
|
|
|
|
|
|
|
|
// LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------??
|
|
|
|
|
|
|
|
// BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(缺少人数,和资源名称,时间需要转格式)
|
|
|
|
|
|
|
|
// //添加时间
|
|
|
|
|
|
|
|
// //LocalDateTime转Date
|
|
|
|
|
|
|
|
// Date date = Date.from(learningRecords.getTime().atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
|
|
|
|
// learningRecordsVo.setTime(sdf.format(date));
|
|
|
|
|
|
|
|
// LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
|
|
|
// lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId());
|
|
|
|
|
|
|
|
// String name;
|
|
|
|
|
|
|
|
// //添加课程名称
|
|
|
|
|
|
|
|
// switch (learningRecords.getType()) {
|
|
|
|
|
|
|
|
// case "4": //如果是资源学习
|
|
|
|
|
|
|
|
// if (courseResourcesService.getById(learningRecords.getCoursesId()) != null){
|
|
|
|
|
|
|
|
// learningRecordsVo.setCoursesName(courseResourcesService.getById(learningRecords.getCoursesId()).getName());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
} |
|
|
|
// break;
|
|
|
|
// System.out.println("查询后结果:"+list);
|
|
|
|
// case "1": //如果是课程学习记录
|
|
|
|
return list; |
|
|
|
// if (coursesService.getById(learningRecords.getCoursesId()) != null){
|
|
|
|
|
|
|
|
// learningRecordsVo.setCoursesName(coursesService.getById(learningRecords.getCoursesId()).getName());
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// //添加观看人数
|
|
|
|
|
|
|
|
// //统计记录表里有多少人查看过这门资源
|
|
|
|
|
|
|
|
// long count = this.count(lambdaQueryWrapper);
|
|
|
|
|
|
|
|
// learningRecordsVo.setNumber(count);
|
|
|
|
|
|
|
|
// //把整合后该用户的学习记录添加到List里
|
|
|
|
|
|
|
|
// records.add(learningRecordsVo);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
return records; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -148,14 +135,26 @@ public class LearningRecordsServiceImpl extends ServiceImpl<LearningRecordsMappe |
|
|
|
.eq(LearningRecords::getCoursesId, coursesId) |
|
|
|
.eq(LearningRecords::getCoursesId, coursesId) |
|
|
|
.eq(LearningRecords::getType, learningRecords.getType()); |
|
|
|
.eq(LearningRecords::getType, learningRecords.getType()); |
|
|
|
long count = this.count(lambdaQueryWrapper); |
|
|
|
long count = this.count(lambdaQueryWrapper); |
|
|
|
System.out.println("数据库:"+count); |
|
|
|
//System.out.println("数据库:"+count);
|
|
|
|
learningRecords.setStatus("1");//将该记录的状态设置为1
|
|
|
|
learningRecords.setStatus("1");//将该记录的状态设置为1
|
|
|
|
//更新观看时间
|
|
|
|
//更新观看时间
|
|
|
|
learningRecords.setAccessTime(LocalDateTime.now()); |
|
|
|
learningRecords.setTime(LocalDateTime.now()); |
|
|
|
//设置默认封面
|
|
|
|
//设置默认封面
|
|
|
|
if (learningRecords.getContent() == null || learningRecords.getContent().equals("")){ |
|
|
|
if (learningRecords.getContent() == null || learningRecords.getContent().equals("")){ |
|
|
|
learningRecords.setContent("img/v2-c57eb7863ec4233f503176ca3f90f8d5_1440w.png"); |
|
|
|
learningRecords.setContent("img/v2-c57eb7863ec4233f503176ca3f90f8d5_1440w.png"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<LearningRecords> list = query().eq("courses_id", coursesId).eq("type", learningRecords.getType()).list(); |
|
|
|
|
|
|
|
int number; |
|
|
|
|
|
|
|
if (list != null){ |
|
|
|
|
|
|
|
number = list.get(0).getNumber() + 1; |
|
|
|
|
|
|
|
learningRecords.setNumber(number); |
|
|
|
|
|
|
|
list.forEach(learningRecords1 -> { |
|
|
|
|
|
|
|
learningRecords1.setNumber(number); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
number = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
updateBatchById(list); |
|
|
|
if (count == 0){//如果没有就新增并记录学习方式是打开还是下载
|
|
|
|
if (count == 0){//如果没有就新增并记录学习方式是打开还是下载
|
|
|
|
//根据传上来的type设置
|
|
|
|
//根据传上来的type设置
|
|
|
|
// learningRecords.setType(learningRecords.getType());
|
|
|
|
// learningRecords.setType(learningRecords.getType());
|
|
|
|