|
|
@@ -16,21 +16,17 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollStreamUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
|
|
|
-import vip.xiaonuo.common.enums.CommonSortOrderEnum;
|
|
|
import vip.xiaonuo.common.exception.CommonException;
|
|
|
import vip.xiaonuo.common.page.CommonPageRequest;
|
|
|
-import vip.xiaonuo.disk.domain.CourseInfo;
|
|
|
-import vip.xiaonuo.disk.domain.CourseNotebooks;
|
|
|
import vip.xiaonuo.disk.domain.CourseNotes;
|
|
|
+import vip.xiaonuo.disk.domain.CourseNotesVo;
|
|
|
import vip.xiaonuo.disk.mapper.CourseInfoMapper;
|
|
|
-import vip.xiaonuo.disk.mapper.CourseNotebooksMapper;
|
|
|
import vip.xiaonuo.disk.mapper.CourseNotesMapper;
|
|
|
import vip.xiaonuo.disk.param.CourseNotesAddParam;
|
|
|
import vip.xiaonuo.disk.param.CourseNotesEditParam;
|
|
|
@@ -39,6 +35,12 @@ import vip.xiaonuo.disk.param.CourseNotesPageParam;
|
|
|
import vip.xiaonuo.disk.service.CourseNotesService;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -57,51 +59,53 @@ public class CourseNotesServiceImpl extends ServiceImpl<CourseNotesMapper, Cours
|
|
|
@Resource
|
|
|
private CourseNotesMapper courseNotesMapper;
|
|
|
|
|
|
- @Resource
|
|
|
- private CourseNotebooksMapper courseNotebooksMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Page<CourseNotes> page(CourseNotesPageParam courseNotesPageParam) {
|
|
|
- QueryWrapper<CourseNotes> queryWrapper = new QueryWrapper<>();
|
|
|
- if(ObjectUtil.isAllNotEmpty(courseNotesPageParam.getSortField(), courseNotesPageParam.getSortOrder())) {
|
|
|
- CommonSortOrderEnum.validate(courseNotesPageParam.getSortOrder());
|
|
|
- queryWrapper.orderBy(true, courseNotesPageParam.getSortOrder().equals(CommonSortOrderEnum.ASC.getValue()),
|
|
|
- StrUtil.toUnderlineCase(courseNotesPageParam.getSortField()));
|
|
|
- } else {
|
|
|
- queryWrapper.lambda().orderByAsc(CourseNotes::getNoteId);
|
|
|
- }
|
|
|
- return this.page(CommonPageRequest.defaultPage(), queryWrapper);
|
|
|
+ public Page<CourseNotesVo> page(CourseNotesPageParam courseNotesPageParam) {
|
|
|
+ Page<CourseNotesVo> page= courseNotesMapper.page(CommonPageRequest.defaultPage(),courseNotesPageParam);
|
|
|
+ page.getRecords().stream().forEach(item -> {
|
|
|
+ LocalDateTime currentTime = LocalDateTime.now();
|
|
|
+ LocalDate today = currentTime.toLocalDate();
|
|
|
+ LocalDateTime passTime = item.getUpdateTime().toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDateTime();
|
|
|
+ LocalDate pastDate = passTime.toLocalDate();
|
|
|
+
|
|
|
+ if (passTime.toLocalDate().isEqual(today)) {
|
|
|
+ Duration duration=Duration.between(passTime, currentTime);
|
|
|
+ if (duration.toMinutes() < 60) {
|
|
|
+ item.setHourString(duration.toMinutes() + "分钟前");
|
|
|
+ }else{
|
|
|
+ item.setHourString(duration.toHours() + "小时前");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ // 判断是否是昨天或两天前
|
|
|
+ if (pastDate.isEqual(today.minus(1, ChronoUnit.DAYS))) {
|
|
|
+ item.setHourString("昨天");
|
|
|
+ } else if (pastDate.isEqual(today.minus(2, ChronoUnit.DAYS))) {
|
|
|
+ item.setHourString("两天前");
|
|
|
+ } else if (pastDate.isEqual(today.minus(3, ChronoUnit.DAYS))) {
|
|
|
+ item.setHourString("三天前");
|
|
|
+ } else {
|
|
|
+ item.setHourString("更早");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return page;
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void add(CourseNotesAddParam courseNotesAddParam) {
|
|
|
CourseNotes courseNotes = BeanUtil.toBean(courseNotesAddParam, CourseNotes.class);
|
|
|
- // 校验当前课程是否有笔记本
|
|
|
- // 1.根据章节查询课程
|
|
|
- CourseInfo courseInfo = courseInfoMapper.selectById(courseNotesAddParam.getChapterId());
|
|
|
- if(ObjectUtil.isEmpty(courseInfo)) {
|
|
|
- throw new CommonException("课程不存在,id值为:{}", courseNotesAddParam.getChapterId());
|
|
|
- }
|
|
|
- // 2.判断当前课程是否有笔记本
|
|
|
- QueryWrapper<CourseNotebooks> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.lambda().eq(CourseNotebooks::getCourseId, courseInfo.getCourseId());
|
|
|
- queryWrapper.lambda().eq(CourseNotebooks::getUserId, StpLoginUserUtil.getLoginUser().getId());
|
|
|
- CourseNotebooks courseNotebooks = courseNotebooksMapper.selectOne(queryWrapper);
|
|
|
- // 如果没有笔记本,则创建笔记本
|
|
|
- if (courseNotebooks == null) {
|
|
|
- CourseNotebooks newCourseNotebooks = new CourseNotebooks();
|
|
|
- courseNotebooks.setUserId(StpLoginUserUtil.getLoginUser().getId()); // 用户id
|
|
|
- String notebookId = IdUtil.fastSimpleUUID();
|
|
|
- courseNotebooks.setNotebookId(notebookId); // 主键id
|
|
|
- courseNotebooks.setCourseId(courseInfo.getCourseId()); // 课程id
|
|
|
- courseNotebooksMapper.insert(newCourseNotebooks);
|
|
|
- courseNotebooks.setNotebookId(notebookId);
|
|
|
- }
|
|
|
// 3.保存笔记信息
|
|
|
courseNotes.setUserId(StpLoginUserUtil.getLoginUser().getId()); // 用户id
|
|
|
- courseNotes.setNotebookId(courseNotebooks.getNotebookId()); // 笔记本id
|
|
|
+ courseNotes.setCreateTime(new Date());
|
|
|
+ courseNotes.setCreateUser(StpLoginUserUtil.getLoginUser().getId());
|
|
|
+ courseNotes.setUpdateTime(new Date());
|
|
|
+ courseNotes.setUpdateUser(StpLoginUserUtil.getLoginUser().getId());
|
|
|
+ courseNotes.setNoteId(IdUtil.getSnowflakeNextIdStr());
|
|
|
this.save(courseNotes);
|
|
|
}
|
|
|
|
|
|
@@ -110,6 +114,8 @@ public class CourseNotesServiceImpl extends ServiceImpl<CourseNotesMapper, Cours
|
|
|
public void edit(CourseNotesEditParam courseNotesEditParam) {
|
|
|
CourseNotes courseNotes = this.queryEntity(courseNotesEditParam.getNoteId());
|
|
|
BeanUtil.copyProperties(courseNotesEditParam, courseNotes);
|
|
|
+ courseNotes.setUpdateTime(new Date());
|
|
|
+ courseNotes.setUpdateUser(StpLoginUserUtil.getLoginUser().getId());
|
|
|
this.updateById(courseNotes);
|
|
|
}
|
|
|
|