Explorar o código

课程学习进度计算bug

yangfeng hai 1 ano
pai
achega
b5812503aa

+ 9 - 10
web/src/main/java/com/ynfy/buss/course/usercoursecatalog/service/impl/UserCourseCatalogServiceImpl.java

@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
 import java.util.List;
 import java.util.Objects;
@@ -47,8 +48,7 @@ public class UserCourseCatalogServiceImpl extends ServiceImpl<UserCourseCatalogM
     @Override
     @Transactional(rollbackFor = Exception.class)
     public synchronized void calcStudyTime(CatalogTimeVO catalogTimeVO, String userId) {
-        if (Objects.isNull(catalogTimeVO.getCourseCatalog()) || StringUtils.isBlank(catalogTimeVO.getCourseCatalog().getId())
-                || Objects.isNull(catalogTimeVO.getStartLearnTime()) || Objects.isNull(catalogTimeVO.getEndLearnTime())) {
+        if (Objects.isNull(catalogTimeVO.getCourseCatalog()) || StringUtils.isBlank(catalogTimeVO.getCourseCatalog().getId()) || Objects.isNull(catalogTimeVO.getStartLearnTime()) || Objects.isNull(catalogTimeVO.getEndLearnTime())) {
             return;
         }
         if (DateUtil.compare(catalogTimeVO.getEndLearnTime(), catalogTimeVO.getStartLearnTime()) > 0) {
@@ -61,12 +61,10 @@ public class UserCourseCatalogServiceImpl extends ServiceImpl<UserCourseCatalogM
             userCourseCatalog.setUserId(userId);
             userCourseCatalog.setCourseCatalogId(courseCatalog.getId());
             long between = DateUtil.between(catalogTimeVO.getStartLearnTime(), catalogTimeVO.getEndLearnTime(), DateUnit.SECOND);
-            userCourseCatalog.setTotalLearnTime(Integer.parseInt(String.valueOf(((!Objects.isNull(userCourseCatalog.getTotalLearnTime())
-                    ? userCourseCatalog.getTotalLearnTime() : 0) + between))));
+            userCourseCatalog.setTotalLearnTime(Integer.parseInt(String.valueOf(((!Objects.isNull(userCourseCatalog.getTotalLearnTime()) ? userCourseCatalog.getTotalLearnTime() : 0) + between))));
 
             //如果有必须时长的话则以其分母,如果没有的话取总时长
-            Long number = !Objects.isNull(courseCatalog.getMustLearnTime()) ? courseCatalog.getMustLearnTime() :
-                    !Objects.isNull(courseCatalog.getVideoHour()) ? courseCatalog.getVideoHour() : 0L;
+            Long number = !Objects.isNull(courseCatalog.getMustLearnTime()) ? courseCatalog.getMustLearnTime() : !Objects.isNull(courseCatalog.getVideoHour()) ? courseCatalog.getVideoHour() : 0L;
             if (number.intValue() > 0) {
                 //计算学习进度
                 userCourseCatalog.setLearnProcess(NumberUtil.div(userCourseCatalog.getTotalLearnTime(), number).doubleValue());
@@ -82,8 +80,10 @@ public class UserCourseCatalogServiceImpl extends ServiceImpl<UserCourseCatalogM
     @Override
     public UserCourseCatalog findUserCatalog(String userId, String courseCatalogId) {
         LambdaQueryWrapper<UserCourseCatalog> query = new LambdaQueryWrapper<UserCourseCatalog>()
-                .eq(UserCourseCatalog::getUserId, userId).eq(UserCourseCatalog::getCourseCatalogId, courseCatalogId);
-        return getOne(query);
+                .eq(UserCourseCatalog::getUserId, userId).eq(UserCourseCatalog::getCourseCatalogId, courseCatalogId)
+                .orderByDesc(UserCourseCatalog::getCreateTime);
+        List<UserCourseCatalog> userCourseCatalogs = list(query);
+        return !CollectionUtils.isEmpty(userCourseCatalogs) ? userCourseCatalogs.get(0) : null;
     }
 
 
@@ -96,8 +96,7 @@ public class UserCourseCatalogServiceImpl extends ServiceImpl<UserCourseCatalogM
     public List<UserCourseCatalog> getCourseStudyProcess(String courseId, String userId) {
         List<CourseCatalog> catalogList = courseCatalogService.listCourseCatalog(courseId);
         List<String> courseCatalogIdList = catalogList.stream().map(CourseCatalog::getId).collect(Collectors.toList());
-        LambdaQueryWrapper<UserCourseCatalog> query = new LambdaQueryWrapper<UserCourseCatalog>()
-                .in(UserCourseCatalog::getCourseCatalogId, courseCatalogIdList).eq(UserCourseCatalog::getUserId, userId);
+        LambdaQueryWrapper<UserCourseCatalog> query = new LambdaQueryWrapper<UserCourseCatalog>().in(UserCourseCatalog::getCourseCatalogId, courseCatalogIdList).eq(UserCourseCatalog::getUserId, userId);
         return list(query);
     }