|
@@ -4,23 +4,22 @@ import cn.hutool.core.util.NumberUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.dayaedu.cbs.common.enums.EClientType;
|
|
|
+import com.dayaedu.cbs.common.enums.school.ECourseType;
|
|
|
+import com.dayaedu.cbs.openfeign.client.CoursewareFeignService;
|
|
|
+import com.dayaedu.cbs.openfeign.wrapper.courseware.CbsCourseTypeWrapper;
|
|
|
+import com.dayaedu.cbs.openfeign.wrapper.courseware.CbsLessonCoursewareWrapper;
|
|
|
+import com.microsvc.toolkit.common.response.paging.PageInfo;
|
|
|
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.MusicFavorite;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.MusicSheet;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.MusicTag;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.Subject;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.SysUser;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.TenantAlbumCategory;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.TenantAlbumCategoryDetail;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.TenantAlbumMusic;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.*;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.SubjectTypeEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.TenantAlbumMusicMapper;
|
|
|
import com.yonge.cooleshow.biz.dal.service.*;
|
|
|
+import com.yonge.cooleshow.biz.dal.wrapper.LessonCoursewareWrapper;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.TenantAlbumMusicWrapper;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
-import jodd.util.StringUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -74,6 +73,9 @@ public class TenantAlbumMusicServiceImpl extends ServiceImpl<TenantAlbumMusicMap
|
|
|
@Autowired
|
|
|
private TenantAlbumCategoryDetailService tenantAlbumCategoryDetailService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CoursewareFeignService coursewareFeignService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询详情
|
|
|
* @param id 详情ID
|
|
@@ -94,66 +96,119 @@ public class TenantAlbumMusicServiceImpl extends ServiceImpl<TenantAlbumMusicMap
|
|
|
@Override
|
|
|
public IPage<TenantAlbumMusicWrapper.StudentTenantAlbumMusic> selectPage(IPage<TenantAlbumMusicWrapper.StudentTenantAlbumMusic> page,
|
|
|
TenantAlbumMusicWrapper.StudentTenantAlbumMusicQuery query) {
|
|
|
+ List<TenantAlbumMusicWrapper.StudentTenantAlbumMusic> musicSheets = new ArrayList<>();
|
|
|
+ if (query.getSubjectType() != SubjectTypeEnum.COURSEWARE) {
|
|
|
|
|
|
+ musicSheets = tenantAlbumMusicMapper.selectPage(page, query);
|
|
|
+ if (CollectionUtils.isEmpty(musicSheets)) {
|
|
|
+ return page.setRecords(musicSheets);
|
|
|
+ }
|
|
|
|
|
|
- List<TenantAlbumMusicWrapper.StudentTenantAlbumMusic> musicSheets = tenantAlbumMusicMapper.selectPage(page, query);
|
|
|
- if (CollectionUtils.isEmpty(musicSheets)) {
|
|
|
- return page.setRecords(musicSheets);
|
|
|
- }
|
|
|
-
|
|
|
- // 设置声部
|
|
|
- List<String> subjectIds = musicSheets.stream()
|
|
|
- .map(TenantAlbumMusicWrapper.StudentTenantAlbumMusic::getMusicSubject)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .flatMap(x -> Arrays.stream(x.split(",")))
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
- Map<Integer, Subject> subjectMap = subjectService.getMapByIds(subjectIds);
|
|
|
-
|
|
|
- // 设置上传人
|
|
|
- List<Long> userIds = musicSheets.stream()
|
|
|
- .map(TenantAlbumMusicWrapper.StudentTenantAlbumMusic::getUserId)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
- Map<Long, SysUser> userMap = sysUserService.getMapByIds(userIds);
|
|
|
-
|
|
|
- // 设置是否收藏
|
|
|
- List<Long> musicSheetIds = musicSheets.stream()
|
|
|
- .map(TenantAlbumMusicWrapper.StudentTenantAlbumMusic::getId)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
- List<Long> favoriteIds = new ArrayList<>();
|
|
|
- if (query.getUserId() != null && query.getClientType() != null) {
|
|
|
- List<MusicFavorite> favoriteList = musicFavoriteService.lambdaQuery()
|
|
|
- .in(MusicFavorite::getMusicSheetId, musicSheetIds)
|
|
|
- .eq(MusicFavorite::getUserId, query.getUserId())
|
|
|
- .eq(MusicFavorite::getClientType, query.getClientType().equals(ClientEnum.TENANT_STUDENT) ? ClientEnum.STUDENT : query.getClientType())
|
|
|
- .list();
|
|
|
- favoriteIds = favoriteList.stream().map(MusicFavorite::getMusicSheetId).distinct().collect(Collectors.toList());
|
|
|
+ // 设置声部
|
|
|
+ List<String> subjectIds = musicSheets.stream()
|
|
|
+ .map(TenantAlbumMusicWrapper.StudentTenantAlbumMusic::getMusicSubject)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .flatMap(x -> Arrays.stream(x.split(",")))
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Map<Integer, Subject> subjectMap = subjectService.getMapByIds(subjectIds);
|
|
|
+
|
|
|
+ // 设置上传人
|
|
|
+ List<Long> userIds = musicSheets.stream()
|
|
|
+ .map(TenantAlbumMusicWrapper.StudentTenantAlbumMusic::getUserId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Map<Long, SysUser> userMap = sysUserService.getMapByIds(userIds);
|
|
|
+
|
|
|
+ // 设置是否收藏
|
|
|
+ List<Long> musicSheetIds = musicSheets.stream()
|
|
|
+ .map(TenantAlbumMusicWrapper.StudentTenantAlbumMusic::getId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<Long> favoriteIds = new ArrayList<>();
|
|
|
+ if (query.getUserId() != null && query.getClientType() != null) {
|
|
|
+ List<MusicFavorite> favoriteList = musicFavoriteService.lambdaQuery()
|
|
|
+ .in(MusicFavorite::getMusicSheetId, musicSheetIds)
|
|
|
+ .eq(MusicFavorite::getUserId, query.getUserId())
|
|
|
+ .eq(MusicFavorite::getClientType, query.getClientType().equals(ClientEnum.TENANT_STUDENT) ? ClientEnum.STUDENT : query.getClientType())
|
|
|
+ .list();
|
|
|
+ favoriteIds = favoriteList.stream().map(MusicFavorite::getMusicSheetId).distinct().collect(Collectors.toList());
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- for (TenantAlbumMusicWrapper.StudentTenantAlbumMusic m : musicSheets) {
|
|
|
- if (StringUtils.isNotBlank(m.getMusicSubject())) {
|
|
|
- String subjectNames = Arrays.stream(m.getMusicSubject().split(","))
|
|
|
- .distinct()
|
|
|
- .map(Integer::parseInt)
|
|
|
- .map(subjectMap::get)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .map(Subject::getName)
|
|
|
- .collect(Collectors.joining(","));
|
|
|
- m.setMusicSubjectName(subjectNames);
|
|
|
+ for (TenantAlbumMusicWrapper.StudentTenantAlbumMusic m : musicSheets) {
|
|
|
+ if (StringUtils.isNotBlank(m.getMusicSubject())) {
|
|
|
+ String subjectNames = Arrays.stream(m.getMusicSubject().split(","))
|
|
|
+ .distinct()
|
|
|
+ .map(Integer::parseInt)
|
|
|
+ .map(subjectMap::get)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(Subject::getName)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ m.setMusicSubjectName(subjectNames);
|
|
|
+ }
|
|
|
+ SysUser sysUser = userMap.get(m.getUserId());
|
|
|
+ if (sysUser != null) {
|
|
|
+ m.setUserName(sysUser.getUsername());
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(favoriteIds)) {
|
|
|
+ m.setFavorite(favoriteIds.contains(m.getId()));
|
|
|
+ }
|
|
|
}
|
|
|
- SysUser sysUser = userMap.get(m.getUserId());
|
|
|
- if (sysUser != null) {
|
|
|
- m.setUserName(sysUser.getUsername());
|
|
|
+ } else {
|
|
|
+ // 查询专辑课件
|
|
|
+ List<TenantAlbumMusic> list = tenantAlbumMusicService.lambdaQuery()
|
|
|
+ .eq(TenantAlbumMusic::getTenantAlbumId, query.getAlbumId())
|
|
|
+ .eq(TenantAlbumMusic::getSubjectType, SubjectTypeEnum.COURSEWARE)
|
|
|
+ .eq(TenantAlbumMusic::getDelFlag, false)
|
|
|
+ .orderByAsc(TenantAlbumMusic::getSortNumber)
|
|
|
+ .list();
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return page.setRecords(musicSheets);
|
|
|
}
|
|
|
- if (CollectionUtils.isNotEmpty(favoriteIds)) {
|
|
|
- m.setFavorite(favoriteIds.contains(m.getId()));
|
|
|
+ List<Long> coursewareIds = list.stream().map(TenantAlbumMusic::getMusicSheetId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<ECourseType> courseTypeList = courseTypeBySubject(query.getSubjectId());
|
|
|
+
|
|
|
+ PageInfo<CbsLessonCoursewareWrapper.LessonCourseware> lessonCoursewarePageInfo = coursewareFeignService.lessonCoursewarePage(CbsLessonCoursewareWrapper.LessonCoursewareQuery.builder()
|
|
|
+ .page(query.getPage()).rows(query.getRows()).lessonCoursewareIds(coursewareIds).courseTypes(courseTypeList).keyword(query.getKeyword()).enableFlag(true)
|
|
|
+ .courseTypeCode(StringUtils.isNotBlank(query.getCourseTypeCode())?ECourseType.valueOf(query.getCourseTypeCode()):null).build()
|
|
|
+ ).feignData();
|
|
|
+ List<CbsLessonCoursewareWrapper.LessonCourseware> rows = lessonCoursewarePageInfo.getRows();
|
|
|
+ if (CollectionUtils.isEmpty(rows)) {
|
|
|
+ return page.setRecords(musicSheets);
|
|
|
+ }
|
|
|
+ // 转map
|
|
|
+ Map<Long, CbsLessonCoursewareWrapper.LessonCourseware> coursewareMap = rows.stream().collect(Collectors.toMap(CbsLessonCoursewareWrapper.LessonCourseware::getId, o -> o,(o1,o2)->o1));
|
|
|
+
|
|
|
+ for (Long coursewareId : coursewareIds) {
|
|
|
+ CbsLessonCoursewareWrapper.LessonCourseware row = coursewareMap.get(coursewareId);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ TenantAlbumMusicWrapper.StudentTenantAlbumMusic studentTenantAlbumMusic = new TenantAlbumMusicWrapper.StudentTenantAlbumMusic();
|
|
|
+ studentTenantAlbumMusic.setId(row.getId());
|
|
|
+ studentTenantAlbumMusic.setTenantAlbumId(query.getAlbumId());
|
|
|
+ studentTenantAlbumMusic.setMusicSheetName(row.getName());
|
|
|
+ studentTenantAlbumMusic.setTitleImg(row.getCoverImg());
|
|
|
+ studentTenantAlbumMusic.setMusicSubject(row.getCourseTypeCode());
|
|
|
+ studentTenantAlbumMusic.setMusicSubjectName(ECourseType.valueOf(row.getCourseTypeCode()).getName());
|
|
|
+ musicSheets.add(studentTenantAlbumMusic);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ page.setRecords(musicSheets);
|
|
|
+ page.setTotal(lessonCoursewarePageInfo.getTotal());
|
|
|
+ return page;
|
|
|
+ }catch (Exception e) {
|
|
|
+ log.error("查询课件失败", e);
|
|
|
+ throw new BizException("内容平台查询课件异常");
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
return page.setRecords(musicSheets);
|
|
|
}
|
|
@@ -196,18 +251,29 @@ public class TenantAlbumMusicServiceImpl extends ServiceImpl<TenantAlbumMusicMap
|
|
|
}
|
|
|
|
|
|
// 专辑曲目关联数据
|
|
|
-// List<TenantAlbumMusic> list = this.lambdaQuery()
|
|
|
-// .in(TenantAlbumMusic::getTenantAlbumId, albumIds)
|
|
|
-// .eq(query.getTenantAlbumId() != null, TenantAlbumMusic::getTenantAlbumId, query.getTenantAlbumId())
|
|
|
-// .eq(query.getSubjectType() != null, TenantAlbumMusic::getSubjectType, query.getSubjectType())
|
|
|
-// .eq(TenantAlbumMusic::getDelFlag, false)
|
|
|
-// .list();
|
|
|
List<TenantAlbumMusic> list = tenantAlbumMusicMapper.getList(query,albumIds);
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
- List<Long> musicSheetIds = list.stream().map(o -> o.getMusicSheetId()).distinct().collect(Collectors.toList());
|
|
|
+ List<Long> coursewareIds = list.stream().filter(o -> o.getSubjectType() == SubjectTypeEnum.COURSEWARE)
|
|
|
+ .map(TenantAlbumMusic::getMusicSheetId).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(coursewareIds) ) {
|
|
|
+ CbsLessonCoursewareWrapper.LambdaQuery lambdaQuery = CbsLessonCoursewareWrapper.LambdaQuery.builder().ids(coursewareIds)
|
|
|
+ .delFlag(false).enableFlag(true).build();
|
|
|
+ List<CbsLessonCoursewareWrapper.Entity> entities = coursewareFeignService.lessonCoursewareLambdaQuery(lambdaQuery).feignData();
|
|
|
+
|
|
|
+ List<ECourseType> courseTypeList = courseTypeBySubject(query.getSubjectId());
|
|
|
+ List<String> courseTypes = entities.stream()
|
|
|
+ .map(CbsLessonCoursewareWrapper.Entity::getCourseTypeCode)
|
|
|
+ .filter(courseTypeCode -> courseTypeList.contains(ECourseType.valueOf(courseTypeCode)))
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
+ data.setCourseTypeList(courseTypes);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> musicSheetIds = list.stream().filter(o -> o.getSubjectType() != SubjectTypeEnum.COURSEWARE)
|
|
|
+ .map(TenantAlbumMusic::getMusicSheetId).distinct().collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(musicSheetIds)) {
|
|
|
return data;
|
|
|
}
|
|
@@ -273,19 +339,55 @@ public class TenantAlbumMusicServiceImpl extends ServiceImpl<TenantAlbumMusicMap
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private List<ECourseType> courseTypeBySubject(Long subjectId) {
|
|
|
+ List<ECourseType> courseTypeList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 有声部, 根据声部查询对应的课件类型
|
|
|
+ List<CbsCourseTypeWrapper.CourseType> courseTypes = coursewareFeignService.courseTypeList().feignData();
|
|
|
+ if (subjectId != null) {
|
|
|
+ Subject subject = subjectService.get(subjectId);
|
|
|
+ for (CbsCourseTypeWrapper.CourseType courseType : courseTypes) {
|
|
|
+ if (StringUtils.isNotBlank(courseType.getSubjectIds()) ) {
|
|
|
+ if (subject !=null && subject.getCbsSubjectId() !=null) {
|
|
|
+ boolean contains = Arrays.asList(courseType.getSubjectIds().split(",")).contains(subject.getCbsSubjectId().toString());
|
|
|
+ if (contains) {
|
|
|
+ courseTypeList.add(ECourseType.valueOf(courseType.getTypeCode()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ courseTypeList.add(ECourseType.valueOf(courseType.getTypeCode()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return courseTypes.stream().map(CbsCourseTypeWrapper.CourseType::getTypeCode).distinct()
|
|
|
+ .map(ECourseType::valueOf).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return courseTypeList;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
- public List<Long> getMusicIdsByIds(List<Long> tenantAlbumIds) {
|
|
|
+ public List<Long> getTenantAlbumMusicIdsByIds(List<Long> tenantAlbumIds, List<SubjectTypeEnum> subjectTypes) {
|
|
|
|
|
|
if (CollectionUtils.isEmpty(tenantAlbumIds)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
- List<TenantAlbumMusic> list = this.lambdaQuery().in(TenantAlbumMusic::getTenantAlbumId, tenantAlbumIds).list();
|
|
|
+ List<TenantAlbumMusic> list = this.lambdaQuery()
|
|
|
+ .in(TenantAlbumMusic::getTenantAlbumId, tenantAlbumIds)
|
|
|
+ .in(CollectionUtils.isNotEmpty(subjectTypes),TenantAlbumMusic::getSubjectType,subjectTypes)
|
|
|
+ .list();
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
return list.stream().map(TenantAlbumMusic::getMusicSheetId).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<Long> getMusicIdsByIds(List<Long> tenantAlbumIds) {
|
|
|
+
|
|
|
+ return getTenantAlbumMusicIdsByIds(tenantAlbumIds,Arrays.asList(SubjectTypeEnum.MUSIC, SubjectTypeEnum.ENSEMBLE,SubjectTypeEnum.SUBJECT));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取机构专辑曲目ID集合
|
|
@@ -296,4 +398,37 @@ public class TenantAlbumMusicServiceImpl extends ServiceImpl<TenantAlbumMusicMap
|
|
|
public List<Long> getMusicIdsByTenantIds(Long tenantId) {
|
|
|
return baseMapper.selectMusicIdsByTenantIds(tenantId);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public LessonCoursewareWrapper.LessonCourseware getLessonCoursewareDetail(LessonCoursewareWrapper.LessonCourseQuery query) {
|
|
|
+ CbsLessonCoursewareWrapper.LessonCourseware lessonCourseware = coursewareFeignService.lessonCoursewareDetail(query.getLessonCoursewareId()).feignData();
|
|
|
+ if (lessonCourseware == null) {
|
|
|
+ throw new BizException("课件不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ LessonCoursewareWrapper.LessonCourseware lessonCoursewareDto = JSON.parseObject(JSON.toJSONString(lessonCourseware), LessonCoursewareWrapper.LessonCourseware.class);
|
|
|
+ lessonCoursewareDto.setPlay(false);
|
|
|
+
|
|
|
+ if (query.getClient() == ClientEnum.STUDENT) {
|
|
|
+ // 判断学生有咩有购买
|
|
|
+ if (query.getAlbumId() != null) {
|
|
|
+ UserTenantAlbumRecord albumRecord = userTenantAlbumRecordService.getNewestByTenantAlbumId(query.getAlbumId(), query.getUserId(), query.getClient());
|
|
|
+ if (albumRecord != null && albumRecord.getEndTime().after(new Date())) {
|
|
|
+ lessonCoursewareDto.setPlay(true);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ List<Long> useAlbumIdsByUserId = userTenantAlbumRecordService.getUseAlbumIdsByUserId(query.getUserId(), query.getClient());
|
|
|
+ if (CollectionUtils.isNotEmpty(useAlbumIdsByUserId)) {
|
|
|
+ List<Long> list = tenantAlbumMusicService.getTenantAlbumMusicIdsByIds(useAlbumIdsByUserId, Arrays.asList(SubjectTypeEnum.COURSEWARE));
|
|
|
+ if (list.contains(query.getLessonCoursewareId())) {
|
|
|
+ lessonCoursewareDto.setPlay(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ lessonCoursewareDto.setPlay(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ return lessonCoursewareDto;
|
|
|
+ }
|
|
|
}
|