|  | @@ -1,5 +1,6 @@
 | 
	
		
			
				|  |  |  package com.ym.mec.biz.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.dayaedu.cbs.openfeign.wrapper.music.CbsSubjectWrapper;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.StudentRegistrationDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.SubjectDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.SubjectGoodsMapperDao;
 | 
	
	
		
			
				|  | @@ -281,4 +282,68 @@ public class SubjectServiceImpl extends BaseServiceImpl<Integer, Subject> implem
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return records;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @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);
 | 
	
		
			
				|  |  | +            if(query.getParentSubjectId() == null || query.getParentSubjectId() > 0){
 | 
	
		
			
				|  |  | +                // 转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.setPage(1);
 | 
	
		
			
				|  |  | +                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());
 | 
	
		
			
				|  |  | +                Map<Long, Subject> map = this.findBySubjectByIdList(dataList.stream().map(SubjectWrapper.Subject::getParentSubjectId).collect(Collectors.toList())).stream()
 | 
	
		
			
				|  |  | +                        .collect(Collectors.toMap(Subject::getId, t -> t));
 | 
	
		
			
				|  |  | +                dataList.forEach(e -> {
 | 
	
		
			
				|  |  | +                    if(e.getParentSubjectId() != null && e.getParentSubjectId() > 0) {
 | 
	
		
			
				|  |  | +                        e.setParentSubjectName(map.get(e.getParentSubjectId()).getName());
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    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;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |