|
@@ -1,13 +1,16 @@
|
|
|
package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
|
|
|
import com.dayaedu.cbs.openfeign.client.MusicFeignClientService;
|
|
|
+import com.dayaedu.cbs.openfeign.wrapper.music.CbsSubjectWrapper;
|
|
|
import com.dayaedu.cbs.openfeign.wrapper.musicInstrument.CbsMusicalInstrumentWrapper;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.SubjectDao;
|
|
|
+import com.yonge.cooleshow.biz.dal.dao.TeacherDao;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.Instrument;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.Subject;
|
|
|
import com.yonge.cooleshow.biz.dal.queryInfo.SubjectQueryInfo;
|
|
|
import com.yonge.cooleshow.biz.dal.service.InstrumentService;
|
|
|
import com.yonge.cooleshow.biz.dal.service.SubjectService;
|
|
|
+import com.yonge.cooleshow.biz.dal.wrapper.InstrumentWrapper;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.SubjectWrapper;
|
|
|
import com.yonge.cooleshow.common.enums.CacheNameEnum;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
@@ -15,6 +18,7 @@ import com.yonge.toolset.base.page.PageInfo;
|
|
|
import com.yonge.toolset.base.util.StringUtil;
|
|
|
import com.yonge.toolset.mybatis.dal.BaseDAO;
|
|
|
import com.yonge.toolset.mybatis.service.impl.BaseServiceImpl;
|
|
|
+import com.yonge.toolset.utils.collection.MapUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
@@ -26,6 +30,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -40,6 +45,8 @@ public class SubjectServiceImpl extends BaseServiceImpl<Long, Subject> implement
|
|
|
private MusicFeignClientService musicFeignClientService;
|
|
|
@Resource
|
|
|
private InstrumentService instrumentService;
|
|
|
+ @Resource
|
|
|
+ private TeacherDao teacherDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, Subject> getDAO() {
|
|
@@ -296,6 +303,64 @@ public class SubjectServiceImpl extends BaseServiceImpl<Long, Subject> implement
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public PageInfo<SubjectWrapper.Subject> selectPage(SubjectWrapper.SubjectQuery query) {
|
|
|
+ PageInfo<SubjectWrapper.Subject> pageInfo = new PageInfo<>(query.getPage(), query.getRows());
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ MapUtil.populateMap(params, query);
|
|
|
+
|
|
|
+ List<SubjectWrapper.Subject> dataList = null;
|
|
|
+ int count = subjectDao.findCount(params);
|
|
|
+ if (count > 0) {
|
|
|
+ pageInfo.setTotal(count);
|
|
|
+ params.put("offset", pageInfo.getOffset());
|
|
|
+ dataList = subjectDao.findPage(params);
|
|
|
+ // 转map
|
|
|
+ Map<Long, SubjectWrapper.Subject> subjectMap = dataList.stream().collect(Collectors.toMap(SubjectWrapper.Subject::getCbsSubjectId, Function.identity(),(o1, o2)->o1));
|
|
|
+ // cbs声部ID集合
|
|
|
+ List<Long> cbsSubjectIds = dataList.stream().map(SubjectWrapper.Subject::getCbsSubjectId).collect(Collectors.toList());
|
|
|
+ dataList = new ArrayList<>();
|
|
|
+ CbsSubjectWrapper.SubjectQuery subjectQuery = new CbsSubjectWrapper.SubjectQuery();
|
|
|
+ subjectQuery.setIds(cbsSubjectIds);
|
|
|
+ subjectQuery.setName(query.getKeyword());
|
|
|
+ subjectQuery.setPage(query.getPage());
|
|
|
+ subjectQuery.setRows(query.getRows());
|
|
|
+ try {
|
|
|
+ com.microsvc.toolkit.common.response.paging.PageInfo<CbsSubjectWrapper.Subject> subjectPageInfo = musicFeignClientService.subjectPage(subjectQuery).feignData();
|
|
|
+ List<CbsSubjectWrapper.Subject> rows = subjectPageInfo.getRows();
|
|
|
+ if (org.apache.commons.collections.CollectionUtils.isNotEmpty(rows)) {
|
|
|
+ for (CbsSubjectWrapper.Subject row : rows) {
|
|
|
+ SubjectWrapper.Subject subject = subjectMap.get(row.getId());
|
|
|
+ if (subject == null) {
|
|
|
+ log.warn("未查询到声部信息,id:{}", row.getId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ subject.setCbsSubjectName(row.getName());
|
|
|
+ subject.setName(row.getName());
|
|
|
+ subject.setCode(row.getCode());
|
|
|
+ dataList.add(subject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("调用音乐服务查询曲目详情失败", e);
|
|
|
+ }
|
|
|
+ // 设置声部下的乐器信息
|
|
|
+ List<Integer> subjectIds = dataList.stream().map(SubjectWrapper.Subject::getId).distinct().collect(Collectors.toList());
|
|
|
+ Map<Integer, List<InstrumentWrapper.Instrument>> groupBySubjectId = instrumentService.getGroupBySubjectId(subjectIds, query.getEnableFlag());
|
|
|
+ dataList.forEach(e -> {
|
|
|
+ List<InstrumentWrapper.Instrument> instruments = groupBySubjectId.get(e.getId());
|
|
|
+ if (org.apache.commons.collections.CollectionUtils.isNotEmpty(instruments)) {
|
|
|
+ e.setInstruments(instruments);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (count == 0) {
|
|
|
+ dataList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ pageInfo.setRows(dataList);
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+
|
|
|
/***
|
|
|
* 查询声部树
|
|
|
* @param: sub
|