Browse Source

1、blockly课程星星按照最大值5颗星(优化逻辑)

liyanbo 4 months ago
parent
commit
5e00cf414f

+ 1 - 1
byzs-blockly/src/main/java/cn/iocoder/byzs/module/blockly/controller/admin/blocklyType/vo/BlocklyTypeListReqVO.java

@@ -14,7 +14,7 @@ public class BlocklyTypeListReqVO {
     private String ctTypeImage;
 
     @Schema(description = "课程类型父级id")
-    private Integer ctParentId;
+    private Long ctParentId;
 
     @Schema(description = "课程节点")
     private String ctTypeNode;

+ 1 - 1
byzs-web/src/main/java/cn/iocoder/byzs/module/web/controller/admin/blockly/WebBlocklyController.java

@@ -54,7 +54,7 @@ public class WebBlocklyController {
 
     @GetMapping("/getTypeByThemeId")
     @Operation(summary = "获得blockly课程类型-根据主题id")
-    public CommonResult<List<WebBlocklyTypeVO>> getTypeByThemeId(@RequestParam("id") Integer themeId) {
+    public CommonResult<List<WebBlocklyTypeVO>> getTypeByThemeId(@RequestParam("id") Long themeId) {
         List<WebBlocklyTypeVO> list = webBlocklyService.getTypeByThemeId(themeId);
         return success(list);
     }

+ 4 - 1
byzs-web/src/main/java/cn/iocoder/byzs/module/web/controller/admin/blockly/vo/WebBlocklyTypeVO.java

@@ -25,11 +25,14 @@ public class WebBlocklyTypeVO extends PageParam {
     private String ctTypeImage;
 
     @Schema(description = "课程类型父级id")
-    private Integer ctParentId;
+    private Long ctParentId;
 
     @Schema(description = "课程排序")
     private Integer ctTypeSort;
 
+    @Schema(description = "课程小节数量")
+    private Integer sectionCount;
+
     @Schema(description = "完成进度")
     private Integer progress;
 

+ 2 - 0
byzs-web/src/main/java/cn/iocoder/byzs/module/web/dal/mysql/blocklyprogress/WebBlocklyProgressMapper.java

@@ -18,4 +18,6 @@ public interface WebBlocklyProgressMapper extends BaseMapperX<WebBlocklyProgress
     List<WebBlocklyProgressDTO> selectProgres(WebBlocklyProgressDO blocklyProgressDO);
 
     List<WebBlocklyProgressDO> getBlocklyProgressByTypeId(WebBlocklyProgressDO blocklyProgressDO);
+
+    List<WebBlocklyProgressDO> getBlocklyProgressByThemeId(WebBlocklyProgressDO blocklyProgressDO);
 }

+ 23 - 8
byzs-web/src/main/java/cn/iocoder/byzs/module/web/service/blockly/WebBlocklyServiceImpl.java

@@ -3,12 +3,10 @@ package cn.iocoder.byzs.module.web.service.blockly;
 import cn.hutool.core.collection.CollUtil;
 import cn.iocoder.byzs.framework.common.enums.CommonStatusEnum;
 import cn.iocoder.byzs.framework.common.util.object.BeanUtils;
-import cn.iocoder.byzs.framework.web.core.util.WebFrameworkUtils;
 import cn.iocoder.byzs.module.blockly.controller.admin.blockly.vo.BlocklyPageReqVO;
 import cn.iocoder.byzs.module.blockly.controller.admin.blocklyConfig.vo.BlocklyConfigRespVO;
 import cn.iocoder.byzs.module.blockly.service.blockly.BlocklyService;
 import cn.iocoder.byzs.module.blockly.service.blocklyConfig.BlocklyConfigService;
-import cn.iocoder.byzs.module.blockly.service.blocklyType.BlocklyTypeService;
 import cn.iocoder.byzs.module.web.controller.admin.blockly.vo.WebBlocklyTypeVO;
 import cn.iocoder.byzs.module.web.controller.admin.blockly.vo.WebBlocklyVO;
 import cn.iocoder.byzs.module.web.controller.admin.blocklyprogress.vo.WebBlocklyProgressDO;
@@ -33,8 +31,6 @@ import java.util.stream.Collectors;
 @Validated
 public class WebBlocklyServiceImpl {
 
-    @Resource
-    private BlocklyTypeService blocklyTypeService;
     @Resource
     private BlocklyService blocklyService;
     @Resource
@@ -63,7 +59,7 @@ public class WebBlocklyServiceImpl {
 
         //课程小节进度
         List<WebBlocklyProgressDO> progressList = webBlocklyProgressService.getBlocklyProgressByTypeId(typeId);
-        Map<Long, WebBlocklyProgressDO> progressMap = progressList.stream().collect(Collectors.toMap(WebBlocklyProgressDO::getBrpUserId, a -> a));
+        Map<Long, WebBlocklyProgressDO> progressMap = progressList.stream().collect(Collectors.toMap(WebBlocklyProgressDO::getBrpCourseId, a -> a));
 
 
 
@@ -101,8 +97,27 @@ public class WebBlocklyServiceImpl {
      * @param themeId
      * @return
      */
-    public List<WebBlocklyTypeVO> getTypeByThemeId(Integer themeId) {
-        WebBlocklyTypeVO blocklyTypeVO = new WebBlocklyTypeVO().setCtParentId(themeId).setUserId(WebFrameworkUtils.getLoginUserId());
-        return webBlocklyMapper.getTypeByThemeId(blocklyTypeVO);
+    public List<WebBlocklyTypeVO> getTypeByThemeId(Long themeId) {
+
+        //查询课程类型列表
+        List<WebBlocklyTypeVO> list = webBlocklyMapper.getTypeByThemeId(new WebBlocklyTypeVO().setCtParentId(themeId));
+        List<WebBlocklyTypeVO> blocklyTypeVoList = BeanUtils.toBean(list, WebBlocklyTypeVO.class);
+
+        //课程小节进度
+        List<WebBlocklyProgressDO> progressList = webBlocklyProgressService.getBlocklyProgressByThemeId(themeId);
+        Map<Long, WebBlocklyProgressDO> progressMap = progressList.stream().collect(Collectors.toMap(WebBlocklyProgressDO::getBrpCtId, a -> a));
+
+        blocklyTypeVoList.forEach(blocklyType -> {
+            if (progressMap.containsKey(blocklyType.getId())) {
+                WebBlocklyProgressDO progress = progressMap.get(blocklyType.getId());
+                Double brpProgress = progress.getBrpProgress();
+                long progressL = Math.round(brpProgress / blocklyType.getSectionCount() * 5);
+                blocklyType.setProgress((int) progressL);
+            }else{
+                blocklyType.setProgress(0);
+            }
+        });
+
+        return blocklyTypeVoList;
     }
 }

+ 12 - 0
byzs-web/src/main/java/cn/iocoder/byzs/module/web/service/blocklyprogress/WebBlocklyProgressServiceImpl.java

@@ -106,4 +106,16 @@ public class WebBlocklyProgressServiceImpl {
         List<WebBlocklyProgressDO> blocklyProgressList = progressMapper.getBlocklyProgressByTypeId(webBlocklyProgressDO);
         return blocklyProgressList;
     }
+
+    /**
+     * 根据主题id查询进度
+     *
+     * @param themeId 主题id
+     * @return 进度列表
+     */
+    public List<WebBlocklyProgressDO> getBlocklyProgressByThemeId(Long themeId) {
+        WebBlocklyProgressDO webBlocklyProgressDO = new WebBlocklyProgressDO().setBrpZtId(themeId).setBrpUserId(WebFrameworkUtils.getLoginUserId());
+        List<WebBlocklyProgressDO> blocklyProgressList = progressMapper.getBlocklyProgressByThemeId(webBlocklyProgressDO);
+        return blocklyProgressList;
+    }
 }

+ 5 - 8
byzs-web/src/main/resources/mapper/blockly/WebBlocklyMapper.xml

@@ -11,16 +11,13 @@
             bct.ct_parent_id as ctParentId,
             bct.ct_type_image as ctTypeImage,
             bct.ct_type_sort as ctTypeSort,
-            ROUND(COALESCE((SUM(brp.brp_progress) * 1.0 / NULLIF(COUNT(bct.ct_type) * 100, 0)), 0), 0) AS progress
+            COUNT(bct.id) + SUM(CASE WHEN bc.bc_label = 2 THEN 2 ELSE 0 END) AS sectionCount
         FROM
             blockly_course_type bct
-                LEFT JOIN blockly_report_progress brp
-                          ON bct.id = brp.brp_ct_id
-                              AND bct.ct_parent_id = brp.brp_zt_id
-                              AND brp.brp_user_id = #{userId}
-                              AND brp.brp_course_config_id IS NULL
+                LEFT JOIN blockly_course bc ON bct.id = bc.bc_type
         WHERE
-            bct.ct_parent_id = #{ctParentId}
-        GROUP BY id, ctType, ctParentId, ctTypeImage, ctTypeSort;
+            bct.ct_parent_id = 1
+        GROUP BY
+            id, ctType, ctParentId, ctTypeImage, ctTypeSort;
     </select>
 </mapper>

+ 18 - 4
byzs-web/src/main/resources/mapper/blocklyprogress/BlocklyProgressMapper.xml

@@ -29,12 +29,26 @@
             resultType="cn.iocoder.byzs.module.web.controller.admin.blocklyprogress.vo.WebBlocklyProgressDO">
 
         SELECT
-            brp_course_id AS brpUserId,
-            COALESCE(ROUND(brp_progress / 100), 0) AS brpProgress
+            brp_course_id AS brpCourseId,
+            COALESCE(brp_progress / 100, 0) AS brpProgress
         FROM blockly_report_progress
         WHERE
             brp_ct_id = #{brpCtId}
-            AND brp_user_id = #{brpUserId}
-            AND brp_course_config_id IS NULL
+          AND brp_user_id = #{brpUserId}
+          AND brp_course_config_id IS NULL
+    </select>
+
+    <select id="getBlocklyProgressByThemeId"
+            parameterType="cn.iocoder.byzs.module.web.controller.admin.blocklyprogress.vo.WebBlocklyProgressDO"
+            resultType="cn.iocoder.byzs.module.web.controller.admin.blocklyprogress.vo.WebBlocklyProgressDO">
+        SELECT
+            brp_ct_id AS brpCtId,
+            COALESCE(SUM(brp_progress) / 100, 0) AS brpProgress
+        FROM blockly_report_progress
+        WHERE
+            brp_zt_id = #{brpZtId}
+          AND brp_user_id = #{brpUserId}
+          AND brp_course_config_id IS NULL
+        GROUP BY brp_ct_id
     </select>
 </mapper>