|
@@ -4,17 +4,25 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alipay.service.schema.util.StringUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.microsvc.toolkit.common.response.paging.QueryInfo;
|
|
|
+import com.ym.mec.auth.api.entity.SysUser;
|
|
|
+import com.ym.mec.biz.dal.entity.Student;
|
|
|
+import com.ym.mec.biz.dal.entity.Subject;
|
|
|
+import com.ym.mec.biz.dal.entity.Teacher;
|
|
|
import com.ym.mec.biz.dal.entity.UserMusicStar;
|
|
|
+import com.ym.mec.biz.dal.enums.ClientEnum;
|
|
|
import com.ym.mec.biz.dal.mapper.UserMusicMapper;
|
|
|
import com.ym.mec.biz.dal.mapper.UserMusicStarMapper;
|
|
|
import com.ym.mec.biz.dal.wrapper.UserMusicStarWrapper;
|
|
|
-import com.ym.mec.biz.service.UserMusicStarService;
|
|
|
+import com.ym.mec.biz.service.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -31,6 +39,16 @@ public class UserMusicStarServiceImpl extends ServiceImpl<UserMusicStarMapper, U
|
|
|
@Autowired
|
|
|
private UserMusicMapper userMusicMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StudentService studentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SubjectService subjectService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserService sysUserService;
|
|
|
+ @Autowired
|
|
|
+ private TeacherService teacherService;
|
|
|
/**
|
|
|
* 查询详情
|
|
|
* @param id 详情ID
|
|
@@ -49,9 +67,78 @@ public class UserMusicStarServiceImpl extends ServiceImpl<UserMusicStarMapper, U
|
|
|
* @return IPage<UserMusicStar>
|
|
|
*/
|
|
|
@Override
|
|
|
- public IPage<UserMusicStar> selectPage(IPage<UserMusicStar> page, UserMusicStarWrapper.UserMusicStarQuery query) {
|
|
|
+ public IPage<UserMusicStarWrapper.UserMusicStar> selectPage(IPage<UserMusicStar> page, UserMusicStarWrapper.UserMusicStarQuery query) {
|
|
|
+
|
|
|
+ IPage<UserMusicStar> userMusicStarIPage = page.setRecords(baseMapper.selectPage(page, query));
|
|
|
+ IPage<UserMusicStarWrapper.UserMusicStar> convert = userMusicStarIPage.convert(o -> JSON.parseObject(JSON.toJSONString(o), UserMusicStarWrapper.UserMusicStar.class));
|
|
|
+
|
|
|
+
|
|
|
+ List<UserMusicStarWrapper.UserMusicStar> records = convert.getRecords();
|
|
|
+
|
|
|
+ List<UserMusicStarWrapper.UserMusicStar> userMusicStars = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isEmpty(records)){
|
|
|
+ return convert;
|
|
|
+ }
|
|
|
+
|
|
|
+ userMusicStars = JSON.parseArray(JSON.toJSONString(records), UserMusicStarWrapper.UserMusicStar.class);
|
|
|
+
|
|
|
+ // 学生ID集合
|
|
|
+ List<Integer> studentIds = records.stream().map(UserMusicStarWrapper.UserMusicStar::getUserId).map(Long::intValue).collect(Collectors.toList());
|
|
|
|
|
|
- return page.setRecords(baseMapper.selectPage(page, query));
|
|
|
+ Map<Long, SysUser> userMap = sysUserService.getMapByIds(studentIds);
|
|
|
+ studentIds = records.stream().filter(o ->o.getClientType() == ClientEnum.STUDENT)
|
|
|
+ .map(UserMusicStarWrapper.UserMusicStar::getUserId).map(Long::intValue).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<Integer, Student> studentMap = studentService.getMapByIds(studentIds);
|
|
|
+
|
|
|
+
|
|
|
+ studentIds = records.stream().filter(o ->o.getClientType() == ClientEnum.TEACHER)
|
|
|
+ .map(UserMusicStarWrapper.UserMusicStar::getUserId).map(Long::intValue).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<Integer, Teacher> teacherMap = teacherService.getMapByIds(studentIds);
|
|
|
+ for (UserMusicStarWrapper.UserMusicStar userMusicStar : userMusicStars) {
|
|
|
+ if (userMusicStar.getClientType() == ClientEnum.STUDENT) {
|
|
|
+ Student student = studentMap.get(userMusicStar.getUserId().intValue());
|
|
|
+ if (student != null) {
|
|
|
+ userMusicStar.setSubjectId(student.getSubjectId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Teacher teacher = teacherMap.get(userMusicStar.getUserId().intValue());
|
|
|
+ if (teacher != null) {
|
|
|
+ userMusicStar.setSubjectId(teacher.getSubjectId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ SysUser sysUser = userMap.get(userMusicStar.getUserId());
|
|
|
+ if (sysUser != null) {
|
|
|
+ userMusicStar.setUserName(sysUser.getUsername());
|
|
|
+ userMusicStar.setUserAvatar(sysUser.getAvatar());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 声部ID集合
|
|
|
+ List<Integer> subjectIds = studentMap.values().stream().map(Student::getSubjectId).filter(StringUtils::isNotBlank).map(Integer::parseInt).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<Integer, Subject> subjectMap =
|
|
|
+ subjectService.getMapByIds(subjectIds);
|
|
|
+
|
|
|
+ for (UserMusicStarWrapper.UserMusicStar userMusicStar : userMusicStars) {
|
|
|
+
|
|
|
+
|
|
|
+ if (!StringUtil.isEmpty(userMusicStar.getSubjectId())) {
|
|
|
+ String[] split = userMusicStar.getSubjectId().split(",");
|
|
|
+ List<String> subjectNameList = new ArrayList<>();
|
|
|
+ for (String s : split) {
|
|
|
+ Subject subject = subjectMap.get(Integer.parseInt(s));
|
|
|
+ if (subject != null) {
|
|
|
+ subjectNameList.add(subject.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userMusicStar.setSubjectName(String.join(",", subjectNameList));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return convert.setRecords(userMusicStars);
|
|
|
}
|
|
|
|
|
|
/**
|