Selaa lähdekoodia

自定义sql补充查询条件不查已删除数据
课程和blockly课程数据权限在后台查询给状态

liyanbo 4 kuukautta sitten
vanhempi
sitoutus
9f24c3c56a

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

@@ -39,4 +39,7 @@ public class WebBlocklyTypeVO extends PageParam {
     @Schema(description = "用户id")
     private Long userId;
 
+    @Schema(description = "数据权限-只读")
+    private Boolean dataReadonly;
+
 }

+ 4 - 4
byzs-web/src/main/java/cn/iocoder/byzs/module/web/controller/admin/course/WebCourseController.java

@@ -41,7 +41,7 @@ public class WebCourseController {
 
 
     @GetMapping("/getCourseByTypeId")
-    @Operation(summary = "根据类型获得课程列表")
+    @Operation(summary = "根据大纲类型获得课程列表")
     @Parameter(name = "typeId", description = "编号", required = true, example = "1024")
     public CommonResult<List<WebCourseVO>> getCourseByTypeId(@RequestParam("typeId") Long typeId) {
 //        List<CoursePageReqVO> courseList = courseService.getCourseList(new CoursePageReqVO().setCourseType(typeId));
@@ -51,7 +51,7 @@ public class WebCourseController {
     }
 
     @GetMapping("/getTypeGrade")
-    @Operation(summary = "获得课程-年级")
+    @Operation(summary = "获得大纲-根据年级")
     public CommonResult<List<CourseTypeRespVO>> getTypeGrade() {
         CourseTypeListReqVO listReqVO = new CourseTypeListReqVO().setCtTypeNode("0");
         List<CourseTypeDO> list = courseTypeService.getCourseTypeList(listReqVO);
@@ -60,7 +60,7 @@ public class WebCourseController {
     }
 
     @GetMapping("/getTypeScByGradeId")
-    @Operation(summary = "获得实操课程-年级大纲")
+    @Operation(summary = "获得实操课大纲-根据年级")
     public CommonResult<List<CourseTypeRespVO>> getTypeScByGradeId(@RequestParam("id") Integer id) {
         CourseTypeListReqVO listReqVO = new CourseTypeListReqVO().setCtParentId(id).setCtTypeNode("2");
         List<CourseTypeDO> list = courseTypeService.getCourseTypeList(listReqVO);
@@ -69,7 +69,7 @@ public class WebCourseController {
     }
 
     @GetMapping("/getTypeTsByGradeId")
-    @Operation(summary = "获得通识课程-年级大纲")
+    @Operation(summary = "获得通识课大纲-根据年级")
     public CommonResult<List<CourseTypeRespVO>> getTypeTsByGradeId(@RequestParam("id") Integer id) {
         CourseTypeListReqVO listReqVO = new CourseTypeListReqVO().setCtParentId(id).setCtTypeNode("1");
         List<CourseTypeDO> list = courseTypeService.getCourseTypeList(listReqVO);

+ 3 - 0
byzs-web/src/main/java/cn/iocoder/byzs/module/web/controller/admin/course/vo/WebCourseVO.java

@@ -61,4 +61,7 @@ public class WebCourseVO extends PageParam {
 
     private List<CourseConfigRespVO> courseConfigList;
 
+    @Schema(description = "数据权限-只读")
+    private Boolean dataReadonly;
+
 }

+ 15 - 5
byzs-web/src/main/java/cn/iocoder/byzs/module/web/service/blockly/WebBlocklyServiceImpl.java

@@ -12,14 +12,12 @@ import cn.iocoder.byzs.module.web.controller.admin.blockly.vo.WebBlocklyVO;
 import cn.iocoder.byzs.module.web.controller.admin.blocklyprogress.vo.WebBlocklyProgressDO;
 import cn.iocoder.byzs.module.web.dal.mysql.blockly.WebBlocklyMapper;
 import cn.iocoder.byzs.module.web.service.blocklyprogress.WebBlocklyProgressServiceImpl;
+import cn.iocoder.byzs.module.web.service.role.WebAuthRoleServiceImpl;
 import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -39,6 +37,9 @@ public class WebBlocklyServiceImpl {
     private WebBlocklyMapper webBlocklyMapper;
     @Resource
     private WebBlocklyProgressServiceImpl webBlocklyProgressService;
+    @Resource
+    private WebAuthRoleServiceImpl webAuthRoleService;
+
 
 
     /**
@@ -62,7 +63,6 @@ public class WebBlocklyServiceImpl {
         Map<Long, WebBlocklyProgressDO> progressMap = progressList.stream().collect(Collectors.toMap(WebBlocklyProgressDO::getBrpCourseId, a -> a));
 
 
-
         //重新组装
         List<WebBlocklyVO> blocklyVoList = new ArrayList<>();
         for (BlocklyPageReqVO blockly : blocklyList) {
@@ -107,7 +107,17 @@ public class WebBlocklyServiceImpl {
         List<WebBlocklyProgressDO> progressList = webBlocklyProgressService.getBlocklyProgressByThemeId(themeId);
         Map<Long, WebBlocklyProgressDO> progressMap = progressList.stream().collect(Collectors.toMap(WebBlocklyProgressDO::getBrpCtId, a -> a));
 
+        //获得blockly数据权限
+        Set<Long> blocklyAuthRoleVO = webAuthRoleService.getBlocklyAuthRoleVO();
+
         blocklyTypeVoList.forEach(blocklyType -> {
+
+            //判断是否有数据权限
+            if (blocklyAuthRoleVO.isEmpty()) {
+                blocklyType.setDataReadonly(false);
+            }else blocklyType.setDataReadonly(!blocklyAuthRoleVO.contains(blocklyType.getId()));
+
+
             if (progressMap.containsKey(blocklyType.getId())) {
                 WebBlocklyProgressDO progress = progressMap.get(blocklyType.getId());
                 Double brpProgress = progress.getBrpProgress();

+ 20 - 5
byzs-web/src/main/java/cn/iocoder/byzs/module/web/service/course/WebCourseServiceImpl.java

@@ -9,14 +9,12 @@ import cn.iocoder.byzs.module.bjdx.service.course.CourseService;
 import cn.iocoder.byzs.module.bjdx.service.courseconfig.CourseConfigService;
 import cn.iocoder.byzs.module.web.controller.admin.course.vo.WebCourseVO;
 import cn.iocoder.byzs.module.web.dal.mysql.course.WebCourseMapper;
+import cn.iocoder.byzs.module.web.service.role.WebAuthRoleServiceImpl;
 import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -34,6 +32,8 @@ public class WebCourseServiceImpl{
     private CourseConfigService courseConfigService;
     @Resource
     private WebCourseMapper webCourseMapper;
+    @Resource
+    private WebAuthRoleServiceImpl webAuthRoleService;
 
 
     public List<WebCourseVO> getCourseVoByTypeId(Long typeId) {
@@ -49,16 +49,31 @@ public class WebCourseServiceImpl{
         Map<Long, List<CourseConfigRespVO>> configMap = courseConfigQuestionList.stream()
                 .collect(Collectors.groupingBy(CourseConfigRespVO::getCcCourseId));
 
+        //获得blockly数据权限
+        Set<Long> courseAuthRoleVO = webAuthRoleService.getCourseAuthRoleVO();
+
         //重新组装
         List<WebCourseVO> courseVoList = new ArrayList<>();
         for (CoursePageReqVO course : courseList) {
+
+            WebCourseVO webCourseVo = BeanUtils.toBean(course, WebCourseVO.class);
+
+
+            //根据课程id获得课程配置-试题列表
             List<CourseConfigRespVO> courseConfigQuestion = configMap.get(course.getId());
             List<CourseConfigRespVO> list = new ArrayList<>();
             if (CollUtil.isNotEmpty(courseConfigQuestion)) {
                 // 根据 ccTime 升序排序(提示时间)
                 list = courseConfigQuestion.stream().sorted(Comparator.comparing(CourseConfigRespVO::getCcTime)).toList();
             }
-            courseVoList.add(BeanUtils.toBean(course, WebCourseVO.class).setCourseConfigList(list));
+            webCourseVo.setCourseConfigList(list);
+
+            //判断是否有数据权限
+            if (courseAuthRoleVO.isEmpty()) {
+                webCourseVo.setDataReadonly(false);
+            }else webCourseVo.setDataReadonly(!courseAuthRoleVO.contains(webCourseVo.getId()));
+
+            courseVoList.add(webCourseVo);
         }
 
         return courseVoList;

+ 87 - 0
byzs-web/src/main/java/cn/iocoder/byzs/module/web/service/role/WebAuthRoleServiceImpl.java

@@ -0,0 +1,87 @@
+package cn.iocoder.byzs.module.web.service.role;
+
+import cn.iocoder.byzs.framework.common.enums.CommonStatusEnum;
+import cn.iocoder.byzs.framework.security.config.SecurityProperties;
+import cn.iocoder.byzs.framework.web.core.util.WebFrameworkUtils;
+import cn.iocoder.byzs.module.system.dal.dataobject.permission.RoleDO;
+import cn.iocoder.byzs.module.system.service.permission.PermissionService;
+import cn.iocoder.byzs.module.system.service.permission.RoleService;
+import jakarta.annotation.Resource;
+import org.springframework.stereotype.Service;
+import org.springframework.validation.annotation.Validated;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * 角色权限 Service 实现类
+ *
+ * @author lyb
+ */
+@Service
+@Validated
+public class WebAuthRoleServiceImpl {
+
+    @Resource
+    private SecurityProperties securityProperties;
+    @Resource
+    private PermissionService permissionService;
+    @Resource
+    private RoleService roleService;
+
+    /**
+     * 获得用户角色列表
+     * @return
+     */
+    private List<RoleDO> getUserRoleList() {
+        // 获得角色列表
+        Set<Long> roleIds = permissionService.getUserRoleIdListByUserId(WebFrameworkUtils.getLoginUserId());
+        List<RoleDO> roles = roleService.getRoleList(roleIds);
+        roles.removeIf(role -> !CommonStatusEnum.ENABLE.getStatus().equals(role.getStatus())); // 移除禁用的角色
+
+        return roles;
+    }
+
+    /**
+     * 取课程数据权限
+     * @return
+     */
+    public Set<Long> getCourseAuthRoleVO() {
+
+        // 获得角色列表
+        List<RoleDO> roles = getUserRoleList();
+
+        // 将所有角色的dataScopeCourseIds拼接成一个Set集合
+        Set<Long> allDataScopeCourseIds = new HashSet<>();
+        for (RoleDO role : roles) {
+            // 填充课程数据权限
+            Set<Long> dataScopeCourseIds = role.getDataScopeCourseIds();
+            if (dataScopeCourseIds != null && !dataScopeCourseIds.isEmpty()) {
+                allDataScopeCourseIds.addAll(dataScopeCourseIds);
+            }
+        }
+        return allDataScopeCourseIds;
+    }
+
+    /**
+     * 取blockly数据权限
+     * @return
+     */
+    public Set<Long> getBlocklyAuthRoleVO() {
+
+        // 获得角色列表
+        List<RoleDO> roles = getUserRoleList();
+
+        // 将所有角色的dataScopeBlocklyIds拼接成一个Set集合
+        Set<Long> allDataScopeBlocklyIds = new HashSet<>();
+        for (RoleDO role : roles) {
+            //blocklu课程数据权限
+            Set<Long> dataScopeBlocklyIds = role.getDataScopeBlocklyIds();
+            if (dataScopeBlocklyIds != null && !dataScopeBlocklyIds.isEmpty()) {
+                allDataScopeBlocklyIds.addAll(dataScopeBlocklyIds);
+            }
+        }
+        return allDataScopeBlocklyIds;
+    }
+}

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

@@ -16,7 +16,7 @@
             blockly_course_type bct
                 LEFT JOIN blockly_course bc ON bct.id = bc.bc_type
         WHERE
-            bct.deleted = 0 AND bc.deleted = 0 AND bc.status = 0 AND
+            bct.deleted = 0 AND bc.deleted = 0 AND bc.bc_status = 0 AND
             bct.ct_parent_id = #{ctParentId}
         GROUP BY
             id, ctType, ctParentId, ctTypeImage, ctTypeSort;