|
@@ -4,24 +4,28 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.dayaedu.cbs.openfeign.client.CoursewareFeignService;
|
|
|
import com.dayaedu.cbs.openfeign.wrapper.courseware.CbsLessonCoursewareWrapper;
|
|
|
+import com.microsvc.toolkit.common.response.template.R;
|
|
|
import com.ym.mec.biz.dal.dao.SubjectDao;
|
|
|
-import com.ym.mec.biz.dal.mapper.LessonCoursewareMapper;
|
|
|
+import com.ym.mec.biz.dal.dao.TeacherDao;
|
|
|
+import com.ym.mec.biz.dal.dto.SimpleUserDto;
|
|
|
import com.ym.mec.biz.dal.entity.LessonCourseware;
|
|
|
+import com.ym.mec.biz.dal.entity.LessonCoursewareUserMapper;
|
|
|
+import com.ym.mec.biz.dal.mapper.LessonCoursewareMapper;
|
|
|
import com.ym.mec.biz.dal.wrapper.LessonCoursewareWrapper;
|
|
|
import com.ym.mec.biz.service.LessonCoursewareService;
|
|
|
-import com.ym.mec.biz.service.SubjectService;
|
|
|
+import com.ym.mec.biz.service.LessonCoursewareUserMapperService;
|
|
|
+import com.ym.mec.biz.service.SysUserService;
|
|
|
+import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -34,14 +38,35 @@ public class LessonCoursewareServiceImpl extends ServiceImpl<LessonCoursewareMap
|
|
|
public LessonCoursewareMapper getDao() {
|
|
|
return this.baseMapper;
|
|
|
}
|
|
|
-
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private CoursewareFeignService coursewareFeignService;
|
|
|
@Resource
|
|
|
+ private LessonCoursewareUserMapperService lessonCoursewareUserMapperService;
|
|
|
+ @Resource
|
|
|
+ private SysUserService sysUserService;
|
|
|
+ @Resource
|
|
|
private SubjectDao subjectDao;
|
|
|
+ @Resource
|
|
|
+ private TeacherDao teacherDao;
|
|
|
|
|
|
@Override
|
|
|
public IPage<LessonCoursewareWrapper.LessonCoursewareDto> selectPage(IPage<LessonCoursewareWrapper.LessonCoursewareDto> page, LessonCoursewareWrapper.LessonCoursewareQuery query) {
|
|
|
+ if(StringUtils.isNotEmpty(query.getSearch())){
|
|
|
+ List<LessonCoursewareWrapper.LessonCoursewareDto> dtos = baseMapper.selectList(query);
|
|
|
+ if(CollectionUtils.isNotEmpty(dtos)){
|
|
|
+ List<Long> lessonCoursewareIds = dtos.stream().map(LessonCoursewareWrapper.LessonCoursewareDto::getLessonCoursewareId).collect(Collectors.toList());
|
|
|
+ CbsLessonCoursewareWrapper.LambdaQuery lambdaQuery = new CbsLessonCoursewareWrapper.LambdaQuery();
|
|
|
+ lambdaQuery.setIds(lessonCoursewareIds);
|
|
|
+ lambdaQuery.setKeyword(query.getSearch());
|
|
|
+ List<CbsLessonCoursewareWrapper.Entity> entityList = coursewareFeignService.lessonCoursewareLambdaQuery(lambdaQuery).feignData();
|
|
|
+ if(CollectionUtils.isNotEmpty(entityList)){
|
|
|
+ List<Long> collect = entityList.stream().map(e -> e.getId()).collect(Collectors.toList());
|
|
|
+ query.setLessonCoursewareIds(collect);
|
|
|
+ }else {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
List<LessonCoursewareWrapper.LessonCoursewareDto> dtos = baseMapper.selectPage(page, query);
|
|
|
if(CollectionUtils.isNotEmpty(dtos)){
|
|
|
List<Long> lessonCoursewareIds = dtos.stream().map(LessonCoursewareWrapper.LessonCoursewareDto::getLessonCoursewareId).collect(Collectors.toList());
|
|
@@ -51,27 +76,111 @@ public class LessonCoursewareServiceImpl extends ServiceImpl<LessonCoursewareMap
|
|
|
if(CollectionUtils.isNotEmpty(entityList)){
|
|
|
Map<Long, CbsLessonCoursewareWrapper.Entity> entityMap = entityList.stream().collect(Collectors.groupingBy(CbsLessonCoursewareWrapper.Entity::getId,
|
|
|
Collectors.collectingAndThen(Collectors.toList(), e -> e.get(0))));
|
|
|
+ List<Integer> collect = dtos.stream().map(e -> e.getSubjectId()).collect(Collectors.toList());
|
|
|
+ String subjectIds = collect.stream().map(e -> String.valueOf(e)).collect(Collectors.joining(","));
|
|
|
+ List<Map<Integer, String>> subjectNames = subjectDao.queryNameByIds(subjectIds);
|
|
|
+ Map<Integer, String> subjectNameMap = MapUtil.convertMybatisMap(subjectNames);
|
|
|
+
|
|
|
+ List<Integer> userIds = dtos.stream().map(e -> e.getCreateBy()).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
+ userIds.addAll(dtos.stream().map(e -> e.getUpdateBy()).filter(Objects::nonNull).distinct().collect(Collectors.toList()));
|
|
|
+ userIds.removeAll(Collections.singleton(null));
|
|
|
+ Map<Integer, String> userNameMap = new HashMap<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(userIds)){
|
|
|
+ userNameMap = MapUtil.convertMybatisMap(teacherDao.queryNameByIdList(userIds));
|
|
|
+ }
|
|
|
for (LessonCoursewareWrapper.LessonCoursewareDto e : dtos) {
|
|
|
CbsLessonCoursewareWrapper.Entity entity = entityMap.get(e.getLessonCoursewareId());
|
|
|
if (Objects.isNull(entity)) {
|
|
|
continue;
|
|
|
}
|
|
|
+ e.setCreateName(userNameMap.get(e.getCreateBy()));
|
|
|
+ e.setUpdateName(userNameMap.get(e.getUpdateBy()));
|
|
|
+ e.setSubjectName(subjectNameMap.get(e.getSubjectId()));
|
|
|
e.setName(entity.getName());
|
|
|
e.setCover(entity.getCoverImg());
|
|
|
e.setCourseNum(entity.getCourseNum());
|
|
|
}
|
|
|
}
|
|
|
- List<Integer> collect = dtos.stream().map(e -> e.getSubjectId()).collect(Collectors.toList());
|
|
|
- if(CollectionUtils.isNotEmpty(collect)){
|
|
|
- String subjectIds = collect.stream().map(e -> String.valueOf(e)).collect(Collectors.joining(","));
|
|
|
- List<Map<Integer, String>> subjectNames = subjectDao.queryNameByIds(subjectIds);
|
|
|
- Map<Integer, String> subjectNameMap = MapUtil.convertMybatisMap(subjectNames);
|
|
|
- for (LessonCoursewareWrapper.LessonCoursewareDto e : dtos) {
|
|
|
- e.setSubjectName(subjectNameMap.get(e.getSubjectId()));
|
|
|
+ }
|
|
|
+ return page.setRecords(dtos);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void updateRangeType(LessonCoursewareWrapper.UpdateRange updateRange) {
|
|
|
+ LessonCourseware lessonCourseware = this.getById(updateRange.getLessonCoursewareId());
|
|
|
+ if (Objects.isNull(lessonCourseware)) {
|
|
|
+ throw new RuntimeException("课件不存在");
|
|
|
+ }
|
|
|
+ lessonCourseware.setStudentRangeType(updateRange.getStudentRangeType());
|
|
|
+ lessonCourseware.setTeacherRangeType(updateRange.getTeacherRangeType());
|
|
|
+ lessonCourseware.setUpdateBy(sysUserService.getUserId());
|
|
|
+ this.updateById(lessonCourseware);
|
|
|
+ lessonCoursewareUserMapperService.lambdaUpdate()
|
|
|
+ .eq(LessonCoursewareUserMapper::getLessonCoursewareId, updateRange.getLessonCoursewareId()).remove();
|
|
|
+ if(StringUtils.equals(updateRange.getStudentRangeType(), "RANGE") && CollectionUtils.isNotEmpty(updateRange.getStudentIds())){
|
|
|
+ List<LessonCoursewareUserMapper> list = updateRange.getStudentIds().stream().map(e -> {
|
|
|
+ LessonCoursewareUserMapper mapper = new LessonCoursewareUserMapper();
|
|
|
+ mapper.setLessonCoursewareId(updateRange.getLessonCoursewareId());
|
|
|
+ mapper.setUserId(e);
|
|
|
+ mapper.setUserType("STUDENT");
|
|
|
+ return mapper;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ lessonCoursewareUserMapperService.saveBatch(list);
|
|
|
+ }
|
|
|
+ if(StringUtils.equals(updateRange.getTeacherRangeType(), "RANGE") && CollectionUtils.isNotEmpty(updateRange.getTeacherIds())){
|
|
|
+ List<LessonCoursewareUserMapper> list = updateRange.getTeacherIds().stream().map(e -> {
|
|
|
+ LessonCoursewareUserMapper mapper = new LessonCoursewareUserMapper();
|
|
|
+ mapper.setLessonCoursewareId(updateRange.getLessonCoursewareId());
|
|
|
+ mapper.setUserId(e);
|
|
|
+ mapper.setUserType("TEACHER");
|
|
|
+ return mapper;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ lessonCoursewareUserMapperService.saveBatch(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public LessonCoursewareWrapper.UpdateRangeDetail getRangeType(Integer lessonCoursewareId) {
|
|
|
+ LessonCourseware lessonCourseware = this.getById(lessonCoursewareId);
|
|
|
+ if (Objects.isNull(lessonCourseware)) {
|
|
|
+ throw new RuntimeException("课件不存在");
|
|
|
+ }
|
|
|
+ R<CbsLessonCoursewareWrapper.LessonCourseware> lessonCoursewareR = coursewareFeignService.lessonCoursewareDetail(lessonCourseware.getLessonCourseId());
|
|
|
+ if (!lessonCoursewareR.getCode().equals(200)) {
|
|
|
+ throw new BizException("获取课件详情失败 {}", lessonCoursewareR.getMessage());
|
|
|
+ }
|
|
|
+ LessonCoursewareWrapper.UpdateRangeDetail detail = new LessonCoursewareWrapper.UpdateRangeDetail();
|
|
|
+ detail.setName(lessonCoursewareR.getData().getName());
|
|
|
+ detail.setLessonCoursewareId(lessonCoursewareId);
|
|
|
+ detail.setStudentRangeType(lessonCourseware.getStudentRangeType());
|
|
|
+ detail.setTeacherRangeType(lessonCourseware.getTeacherRangeType());
|
|
|
+ if(lessonCourseware.getStudentRangeType().equals("RANGE")){
|
|
|
+ List<LessonCoursewareUserMapper> studentList = lessonCoursewareUserMapperService.lambdaQuery()
|
|
|
+ .eq(LessonCoursewareUserMapper::getLessonCoursewareId, lessonCoursewareId)
|
|
|
+ .eq(LessonCoursewareUserMapper::getUserType, "STUDENT").list();
|
|
|
+ if(CollectionUtils.isNotEmpty(studentList)){
|
|
|
+ List<Integer> studentIds = studentList.stream().map(LessonCoursewareUserMapper::getUserId).collect(Collectors.toList());
|
|
|
+ List<SimpleUserDto> userDtoList = teacherDao.getUsersSimpleInfo(studentIds);
|
|
|
+ if (CollectionUtils.isNotEmpty(userDtoList)) {
|
|
|
+ for (SimpleUserDto userDto : userDtoList) {
|
|
|
+ userDto.setUserName(userDto.getNickName());
|
|
|
+ }
|
|
|
}
|
|
|
+ detail.setStudentList(userDtoList);
|
|
|
}
|
|
|
}
|
|
|
- return page.setRecords(dtos);
|
|
|
+ if(lessonCourseware.getTeacherRangeType().equals("RANGE")){
|
|
|
+ List<LessonCoursewareUserMapper> teacherList = lessonCoursewareUserMapperService.lambdaQuery()
|
|
|
+ .eq(LessonCoursewareUserMapper::getLessonCoursewareId, lessonCoursewareId)
|
|
|
+ .eq(LessonCoursewareUserMapper::getUserType, "TEACHER").list();
|
|
|
+ if(CollectionUtils.isNotEmpty(teacherList)){
|
|
|
+ List<Integer> teacherIds = teacherList.stream().map(LessonCoursewareUserMapper::getUserId).collect(Collectors.toList());
|
|
|
+ List<SimpleUserDto> userDtoList = teacherDao.getUsersSimpleInfo(teacherIds);
|
|
|
+ detail.setTeacherList(userDtoList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return detail;
|
|
|
}
|
|
|
|
|
|
}
|