提交 a8d6c7e6 编写于 作者: F fengyw

架构功能升级

上级 e2e0b204
......@@ -88,4 +88,6 @@ public interface UserStudyDao {
List<UserStudy> listByUserIdAndCourseIdsForSumProgress(Long userId, List<Long> courseIdList);
List<UserStudy> listByUserIdAndCourseId(Long userId, Long courseId);
int deleteByPeriodId(Long periodId);
}
......@@ -124,4 +124,11 @@ public class UserStudyDaoImpl extends AbstractBaseJdbc implements UserStudyDao {
example.createCriteria().andUserIdEqualTo(userId).andCourseIdEqualTo(courseId);
return this.mapper.selectByExample(example);
}
@Override
public int deleteByPeriodId(Long periodId) {
UserStudyExample example = new UserStudyExample();
example.createCriteria().andPeriodIdEqualTo(periodId);
return this.mapper.deleteByExample(example);
}
}
......@@ -10,6 +10,7 @@ import com.roncoo.education.common.service.BaseBiz;
import com.roncoo.education.course.dao.CourseChapterDao;
import com.roncoo.education.course.dao.CourseChapterPeriodDao;
import com.roncoo.education.course.dao.ResourceDao;
import com.roncoo.education.course.dao.UserStudyDao;
import com.roncoo.education.course.dao.impl.mapper.entity.CourseChapter;
import com.roncoo.education.course.dao.impl.mapper.entity.CourseChapterExample;
import com.roncoo.education.course.dao.impl.mapper.entity.CourseChapterExample.Criteria;
......@@ -24,6 +25,7 @@ import com.roncoo.education.course.service.admin.resp.AdminCourseChapterViewResp
import com.roncoo.education.course.service.admin.resp.AdminResourceViewResp;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.validation.constraints.NotNull;
import java.util.List;
......@@ -45,6 +47,8 @@ public class AdminCourseChapterBiz extends BaseBiz {
private final CourseChapterPeriodDao courseChapterPeriodDao;
@NotNull
private final ResourceDao resourceDao;
@NotNull
private final UserStudyDao userStudyDao;
/**
* 章节信息分页
......@@ -125,6 +129,7 @@ public class AdminCourseChapterBiz extends BaseBiz {
* @param id ID主键
* @return 删除结果
*/
@Transactional(rollbackFor = Exception.class)
public Result<String> delete(Long id) {
List<CourseChapterPeriod> periodList = courseChapterPeriodDao.listByChapterId(id);
if(CollUtil.isNotEmpty(periodList) && periodList.size() > 0){
......@@ -134,6 +139,8 @@ public class AdminCourseChapterBiz extends BaseBiz {
return Result.success("操作成功");
}
if (courseChapterPeriodDao.deleteById(id) > 0) {
// 删除课时,也需要删除对应的学习记录,否则统计进度出现数据异常
userStudyDao.deleteByPeriodId(id);
return Result.success("操作成功");
}
return Result.error("操作失败");
......
......@@ -52,16 +52,16 @@ public class AuthUserCourseBiz extends BaseBiz {
Page<AuthUserCourseResp> respPage = PageUtil.transform(userCoursePage, AuthUserCourseResp.class);
if (CollUtil.isNotEmpty(respPage.getList())) {
List<Long> courseIdList = respPage.getList().stream().map(AuthUserCourseResp::getCourseId).collect(Collectors.toList());
// 用户学习记录
// 用户学习记录,获取每个课程里面最新学习的课时
Map<Long, UserStudy> userStudyMap = new HashMap<>();
List<UserStudy> userStudyList = userStudyDao.listByUserIdAndCourseIdsForMax(ThreadContext.userId(), courseIdList);
if (CollUtil.isNotEmpty(userStudyList)) {
userStudyMap = userStudyList.stream().collect(Collectors.toMap(item -> item.getCourseId(), item -> item));
}
// 课时信息
// 课时名称
Map<Long, String> periodNameMap = new HashMap<>();
// 课时数
// 每个课程的课时数
Map<Long, Long> periodSumMap = new HashMap<>();
List<CourseChapterPeriod> courseChapterPeriodList = courseChapterPeriodDao.listByCourseIds(courseIdList);
if (CollUtil.isNotEmpty(courseChapterPeriodList)) {
......@@ -69,6 +69,7 @@ public class AuthUserCourseBiz extends BaseBiz {
periodSumMap = courseChapterPeriodList.stream().collect(Collectors.groupingBy(item -> item.getCourseId(), Collectors.counting()));
}
// 每个课程的学习进度汇总
Map<Long, BigDecimal> userStudySumMap = new HashMap<>();
List<UserStudy> userStudySumList = userStudyDao.listByUserIdAndCourseIdsForSumProgress(ThreadContext.userId(), courseIdList);
if (CollUtil.isNotEmpty(userStudySumList)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册