Browse Source

新增课件搜索逻辑

zouxuan 4 months ago
parent
commit
2b277baa0c

+ 25 - 6
mec-application/src/main/java/com/ym/mec/student/controller/LessonCoursewareController.java

@@ -24,7 +24,6 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.collections.CollectionUtils;
 import org.jetbrains.annotations.NotNull;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -48,13 +47,13 @@ public class LessonCoursewareController extends BaseController {
 	@Resource
 	private CbsMusicScoreCategoriesService cbsMusicScoreCategoriesService;
 
-    @Autowired
+    @Resource
     private CloudTeacherOrderDao cloudTeacherOrderDao;
 
-    @Autowired
+    @Resource
     private MemberRankCourseTypeMapperService memberRankCourseTypeMapperService;
 
-    @Autowired
+    @Resource
     private MemberRankCategoryMapperService memberRankCategoryMapperService;
 
 	@ApiOperation(value = "分页查询已添加的课件")
@@ -136,6 +135,27 @@ public class LessonCoursewareController extends BaseController {
         query.setSearch(search);
 		List<CbsLessonCoursewareWrapper.CourseScheduleCoursewareDetail> courseScheduleCoursewareDetails = coursewareFeignService.coursewareDetail(query).feignData();
 		if (CollectionUtils.isNotEmpty(courseScheduleCoursewareDetails)) {
+            SysUser sysUser = sysUserService.getUser();
+            // 机构可用曲目分类
+            String teachingMaterialIds = organizationService.getTeachingMaterialIds(sysUser.getOrganId().toString(),sysUser.getTenantId());
+            List<Integer> categoryIdList = cbsMusicScoreCategoriesService.getAllCategoryIdList(teachingMaterialIds);
+            // 学生会员可用曲目分类
+            List<Integer> activationVipIds = cloudTeacherOrderDao.getActivationVipIds(sysUser.getId());
+            // 获取会员的曲目分类
+            List<Integer> categoryIds = new ArrayList<>();
+            if (CollectionUtils.isNotEmpty(activationVipIds)) {
+                List<MemberRankCategoryMapper> categoryMapperList = memberRankCategoryMapperService.getByMemberRankId(activationVipIds);
+                if (CollectionUtils.isEmpty(categoryMapperList)) {
+                    categoryMapperList = new ArrayList<>();
+                }
+                categoryIds = categoryMapperList.stream().map(MemberRankCategoryMapper::getCategoryId)
+                        .distinct().collect(Collectors.toList());
+            }
+            LessonCoursewareWrapper.LessonCoursewareDetailQuery query1 = new LessonCoursewareWrapper.LessonCoursewareDetailQuery();
+            query1.setUserType(ClientEnum.STUDENT);
+            query1.setTenantCategoriesIdList(categoryIdList);
+            query1.setStudentCategoriesIdList(categoryIds);
+            courseScheduleCoursewareDetails.forEach(e->lessonCoursewareService.setTreeResourceId(e.getKnowledgePointList(),query1));
 			String jsonString = JSONObject.toJSONString(courseScheduleCoursewareDetails);
 			List<LessonCoursewareWrapper.CourseScheduleCoursewareDetail> courseScheduleCoursewareDetailList =
                     JSONObject.parseArray(jsonString, LessonCoursewareWrapper.CourseScheduleCoursewareDetail.class);
@@ -153,8 +173,7 @@ public class LessonCoursewareController extends BaseController {
 		List<Integer> categoryIdList = cbsMusicScoreCategoriesService.getAllCategoryIdList(teachingMaterialIds);
 
         // 学生会员可用曲目分类
-        Integer userId = sysUserService.getUserId();
-        List<Integer> activationVipIds = cloudTeacherOrderDao.getActivationVipIds(userId);
+        List<Integer> activationVipIds = cloudTeacherOrderDao.getActivationVipIds(sysUser.getId());
 
         // 获取会员的曲目分类
 

+ 9 - 1
mec-application/src/main/java/com/ym/mec/teacher/controller/LessonCoursewareController.java

@@ -81,8 +81,16 @@ public class LessonCoursewareController extends BaseController {
 		query.setSearch(search);
 		List<CbsLessonCoursewareWrapper.CourseScheduleCoursewareDetail> courseScheduleCoursewareDetails = coursewareFeignService.coursewareDetail(query).feignData();
 		if (CollectionUtils.isNotEmpty(courseScheduleCoursewareDetails)) {
+			SysUser sysUser = sysUserService.getUser();
+			String teachingMaterialIds = organizationService.getTeachingMaterialIds(sysUser.getOrganId().toString(),sysUser.getTenantId());
+			List<Integer> categoryIdList = cbsMusicScoreCategoriesService.getAllCategoryIdList(teachingMaterialIds);
+			LessonCoursewareWrapper.LessonCoursewareDetailQuery query1 = new LessonCoursewareWrapper.LessonCoursewareDetailQuery();
+			query1.setUserType(ClientEnum.TEACHER);
+			query1.setTenantCategoriesIdList(categoryIdList);
 			String jsonString = JSONObject.toJSONString(courseScheduleCoursewareDetails);
-			List<LessonCoursewareWrapper.CourseScheduleCoursewareDetail> courseScheduleCoursewareDetailList = JSONObject.parseArray(jsonString, LessonCoursewareWrapper.CourseScheduleCoursewareDetail.class);
+			courseScheduleCoursewareDetails.forEach(e->lessonCoursewareService.setTreeResourceId(e.getKnowledgePointList(),query1));
+			List<LessonCoursewareWrapper.CourseScheduleCoursewareDetail> courseScheduleCoursewareDetailList =
+					JSONObject.parseArray(jsonString, LessonCoursewareWrapper.CourseScheduleCoursewareDetail.class);
 			return succeed(courseScheduleCoursewareDetailList);
 		}
 		return succeed(new ArrayList<>());

+ 3 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/LessonCoursewareService.java

@@ -29,5 +29,8 @@ public interface LessonCoursewareService extends IService<LessonCourseware> {
     LessonCourseware getByLessonCoursewareId(Long lessonCoursewareId);
 
     List<LessonCourseware> getByLessonCoursewareIds(List<Integer> categoryIds);
+
+    //递归处理CbsLessonCoursewareDetailWrapper.KnowledgePointSmall
+    void setTreeResourceId(List<CbsLessonCoursewareDetailWrapper.KnowledgePointSmall> knowledgePointList, LessonCoursewareWrapper.LessonCoursewareDetailQuery query);
 }
 

+ 26 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/LessonCoursewareServiceImpl.java

@@ -349,7 +349,8 @@ public class LessonCoursewareServiceImpl extends ServiceImpl<LessonCoursewareMap
     }
 
     //递归处理CbsLessonCoursewareDetailWrapper.KnowledgePointSmall
-    private void setTreeResourceId(List<CbsLessonCoursewareDetailWrapper.KnowledgePointSmall> knowledgePointList,LessonCoursewareWrapper.LessonCoursewareDetailQuery query){
+    @Override
+    public void setTreeResourceId(List<CbsLessonCoursewareDetailWrapper.KnowledgePointSmall> knowledgePointList,LessonCoursewareWrapper.LessonCoursewareDetailQuery query){
         if(CollectionUtils.isNotEmpty(knowledgePointList)){
             knowledgePointList.forEach(knowledgePointSmall -> {
                 this.setResourceId(knowledgePointSmall,query);
@@ -365,9 +366,19 @@ public class LessonCoursewareServiceImpl extends ServiceImpl<LessonCoursewareMap
     private void setResourceId(CbsLessonCoursewareDetailWrapper.KnowledgePointSmall knowledgePointSmall,LessonCoursewareWrapper.LessonCoursewareDetailQuery query){
         List<CbsLessonCoursewareDetailWrapper.MaterialSmall> materialList = knowledgePointSmall.getMaterialList();
         if(CollectionUtils.isNotEmpty(materialList)){
+            //获取所有曲目的ID
+            List<Long> musicScoreIds = materialList.stream().filter(materialSmall -> materialSmall.getType() == EMaterialType.SONG)
+                    .map(materialSmall -> Long.parseLong(materialSmall.getContent())).collect(Collectors.toList());
+            Map<Long, SysMusicScore> musicScoreMap = new HashMap<>();
+            if(CollectionUtils.isNotEmpty(musicScoreIds)){
+                List<SysMusicScore> musicScores = sysMusicScoreService.getDao().findByCbsId(musicScoreIds,false);
+                if(CollectionUtils.isNotEmpty(musicScores)){
+                    musicScoreMap = musicScores.stream().collect(Collectors.toMap(e->e.getId().longValue(), o -> o));
+                }
+            }
             for (CbsLessonCoursewareDetailWrapper.MaterialSmall materialSmall : materialList) {
                 if(materialSmall.getType() == EMaterialType.SONG){
-                    SysMusicScore musicScore = sysMusicScoreService.getDao().getCbsId(Long.parseLong(materialSmall.getContent()));
+                    SysMusicScore musicScore = musicScoreMap.get(Long.parseLong(materialSmall.getContent()));
                     //没有启用的曲目不显示
                     if(musicScore != null && musicScore.getShowFlag() == 1 && musicScore.getClientShowFlag() == 1) {
                         materialSmall.setContent(musicScore.getId().toString());
@@ -378,11 +389,23 @@ public class LessonCoursewareServiceImpl extends ServiceImpl<LessonCoursewareMap
                 //
                 List<CbsMaterialRefWrapper.AddMaterialRef> materialRefs = materialSmall.getMaterialRefs();
                 if (CollectionUtils.isNotEmpty(materialRefs)){
+                    //获取所有曲目的ID
+                    List<Long> musicScoreIds1 = materialRefs.stream().filter(materialRef -> materialRef.getRelateMaterialInfo() != null
+                            && StringUtils.equals(materialRef.getRelateMaterialInfo().getType(),"SONG")
+                            && CollectionUtils.isNotEmpty(materialRef.getRelateMaterialInfo().getApplicationIdList()))
+                            .map(materialRef -> materialRef.getRelateMaterialInfo().getId()).collect(Collectors.toList());
+                    Map<Long, SysMusicScore> musicScoreMap1 = new HashMap<>();
+                    if(CollectionUtils.isNotEmpty(musicScoreIds1)){
+                        List<SysMusicScore> musicScores = sysMusicScoreService.getDao().findByCbsId(musicScoreIds1,false);
+                        if(CollectionUtils.isNotEmpty(musicScores)){
+                            musicScoreMap1 = musicScores.stream().collect(Collectors.toMap(e->e.getId().longValue(), o -> o));
+                        }
+                    }
                     for (CbsMaterialRefWrapper.AddMaterialRef materialRef : materialRefs) {
                         CbsMaterialRefWrapper.RelateMaterialInfo relateMaterialInfo = materialRef.getRelateMaterialInfo();
                         if(relateMaterialInfo != null && StringUtils.equals(relateMaterialInfo.getType(),"SONG")
                                 && CollectionUtils.isNotEmpty(relateMaterialInfo.getApplicationIdList())){
-                            SysMusicScore musicScore = sysMusicScoreService.getDao().getCbsId(relateMaterialInfo.getId());
+                            SysMusicScore musicScore = musicScoreMap1.get(relateMaterialInfo.getId());
                             if(musicScore != null && musicScore.getShowFlag() == 1 && musicScore.getClientShowFlag() == 1
                                     && query.getTenantCategoriesIdList().contains(musicScore.getCbsMusicCategoriesId())) {
                                 materialRef.setResourceIdStr(musicScore.getId().toString());