|
@@ -1,13 +1,15 @@
|
|
|
package com.yonge.cooleshow.admin.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
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.microsvc.toolkit.common.webportal.exception.BizException;
|
|
|
-import com.yonge.cooleshow.biz.dal.dto.PageUtil;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.Subject;
|
|
|
import com.yonge.cooleshow.biz.dal.queryInfo.SubjectQueryInfo;
|
|
|
import com.yonge.cooleshow.biz.dal.service.SubjectService;
|
|
|
import com.yonge.cooleshow.biz.dal.service.SysUserService;
|
|
|
+import com.yonge.cooleshow.biz.dal.wrapper.InstrumentWrapper;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.SubjectWrapper;
|
|
|
import com.yonge.cooleshow.common.controller.BaseController;
|
|
|
import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
@@ -16,10 +18,15 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
@RequestMapping("${app-config.url.admin:}/subject")
|
|
|
@Api(tags = "声部服务")
|
|
|
@RestController
|
|
@@ -79,16 +86,77 @@ public class SubjectController extends BaseController {
|
|
|
*/
|
|
|
@ApiOperation(value = "内容平台对应的声部数据")
|
|
|
@PostMapping("/cbsSubject/page")
|
|
|
- public HttpResponseResult<PageInfo<CbsSubjectWrapper.Subject>> subjectPage(){
|
|
|
- CbsSubjectWrapper.SubjectQuery subjectQuery = new CbsSubjectWrapper.SubjectQuery();
|
|
|
- subjectQuery.setPage(1);
|
|
|
- subjectQuery.setRows(-1);
|
|
|
-
|
|
|
- try {
|
|
|
- return succeed(PageUtil.pageInfo(musicFeignClientService.subjectPage(subjectQuery).feignData()));
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("内容平台对应的声部数据查询失败", e);
|
|
|
- throw BizException.from("内容平台服务异常");
|
|
|
- }
|
|
|
+ public HttpResponseResult<List<SubjectWrapper.CbsSubject>> subjectPage(@RequestBody SubjectWrapper.CbsSubjectQuery query){
|
|
|
+ // 移除已被使用的声部ID
|
|
|
+ if (Boolean.TRUE.equals(query.getRemoveUsed())) {
|
|
|
+ List<Subject> list = subjectService.getDao().notInSubjectIds(query.getSubjectId());
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ List<Long> cbsSubjectIds = list.stream().map(Subject::getCbsSubjectId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(cbsSubjectIds)) {
|
|
|
+ query.setRemoveIds(cbsSubjectIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ query.setPage(1);
|
|
|
+ query.setRows(-1);
|
|
|
+ List<CbsSubjectWrapper.Subject> subjectPageInfo = musicFeignClientService.subjectPage(query).feignData().getRows();
|
|
|
+ if (CollectionUtils.isEmpty(subjectPageInfo)) {
|
|
|
+ return succeed(new ArrayList<>());
|
|
|
+ }
|
|
|
+ List<Integer> subjectIds = subjectPageInfo.stream().map(CbsSubjectWrapper.Subject::getId).map(Long::intValue).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 查询乐器信息
|
|
|
+ CbsMusicalInstrumentWrapper.MusicalInstrumentQuery musicalInstrumentQuery = new CbsMusicalInstrumentWrapper.MusicalInstrumentQuery();
|
|
|
+ musicalInstrumentQuery.setSubjectIds(subjectIds);
|
|
|
+ musicalInstrumentQuery.setPage(1);
|
|
|
+ musicalInstrumentQuery.setRows(9999);
|
|
|
+ List<CbsMusicalInstrumentWrapper.MusicalInstrumentQueryDto> rows = musicFeignClientService
|
|
|
+ .musicalInstrumentPage(musicalInstrumentQuery).feignData().getRows();
|
|
|
+ Map<Long, List<CbsMusicalInstrumentWrapper.MusicalInstrumentQueryDto>> subjectIdMap = rows.stream()
|
|
|
+ .collect(Collectors.groupingBy(o -> o.getSubjectId().longValue(), LinkedHashMap::new, Collectors.toList()));
|
|
|
+
|
|
|
+ // 查询本地已经添加过的曲目数据
|
|
|
+ SubjectWrapper.SubjectQuery query1 = new SubjectWrapper.SubjectQuery();
|
|
|
+ query1.setHasInstrument(true);
|
|
|
+ List<SubjectWrapper.Subject> list = subjectService.list(query1);
|
|
|
+ // 转map
|
|
|
+ Map<Long, SubjectWrapper.Subject> subjectMap = list.stream().collect(Collectors.groupingBy(e -> e.getCbsSubjectId(), Collectors.collectingAndThen(Collectors.toList(), v -> v.get(0))));
|
|
|
+
|
|
|
+ List<SubjectWrapper.CbsSubject> cbsSubjects = new ArrayList<>();
|
|
|
+ for (CbsSubjectWrapper.Subject subject : subjectPageInfo) {
|
|
|
+ SubjectWrapper.CbsSubject cbsSubject = new SubjectWrapper.CbsSubject();
|
|
|
+ BeanUtils.copyProperties(subject, cbsSubject);
|
|
|
+
|
|
|
+ List<CbsMusicalInstrumentWrapper.MusicalInstrumentQueryDto> musicalInstrumentQueryDtos = subjectIdMap.get(cbsSubject.getId());
|
|
|
+ if (CollectionUtils.isEmpty(musicalInstrumentQueryDtos)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ cbsSubject.setInstruments(JSON.parseArray(JSON.toJSONString(musicalInstrumentQueryDtos), SubjectWrapper.Instrument.class));
|
|
|
+
|
|
|
+ cbsSubjects.add(cbsSubject);
|
|
|
+ // 本地已经添加过的曲目数据
|
|
|
+ SubjectWrapper.Subject subject1 = subjectMap.get(subject.getId());
|
|
|
+ if (subject1 == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<InstrumentWrapper.Instrument> instruments = subject1.getInstruments();
|
|
|
+ if (CollectionUtils.isEmpty(instruments)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // instruments 转map
|
|
|
+ Map<Long, InstrumentWrapper.Instrument> instrumentMap = instruments.stream().collect(Collectors.toMap(InstrumentWrapper.Instrument::getId, o -> o));
|
|
|
+ for (SubjectWrapper.Instrument instrument : cbsSubject.getInstruments()) {
|
|
|
+ instrument.setAdded(instrumentMap.containsKey(instrument.getId().longValue()));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return succeed(cbsSubjects);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("内容平台对应的声部数据查询失败", e);
|
|
|
+ throw BizException.from("内容平台服务异常");
|
|
|
+ }
|
|
|
}
|
|
|
}
|