|
@@ -1,34 +1,45 @@
|
|
|
package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
|
|
|
-import java.util.*;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.redisson.api.RedissonClient;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
-
|
|
|
+import com.dayaedu.cbs.openfeign.client.MusicFeignClientService;
|
|
|
+import com.dayaedu.cbs.openfeign.wrapper.musicInstrument.CbsMusicalInstrumentWrapper;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.SubjectDao;
|
|
|
+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.SubjectWrapper;
|
|
|
import com.yonge.cooleshow.common.enums.CacheNameEnum;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
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 org.apache.commons.lang3.StringUtils;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class SubjectServiceImpl extends BaseServiceImpl<Long, Subject> implements SubjectService {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(MusicSheetServiceImpl.class);
|
|
|
|
|
|
- @Autowired
|
|
|
- private SubjectDao subjectDao;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private RedissonClient redissonClient;
|
|
|
+ @Resource
|
|
|
+ private SubjectDao subjectDao;
|
|
|
+ @Resource
|
|
|
+ private MusicFeignClientService musicFeignClientService;
|
|
|
+ @Resource
|
|
|
+ private InstrumentService instrumentService;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, Subject> getDAO() {
|
|
@@ -119,7 +130,7 @@ public class SubjectServiceImpl extends BaseServiceImpl<Long, Subject> implement
|
|
|
List<Subject> subjects;
|
|
|
|
|
|
if(StringUtil.isEmpty(type)){
|
|
|
- List<Subject> allList = subjectDao.findAll(new HashMap<>());
|
|
|
+ List<Subject> allList = subjectDao.getAll();
|
|
|
|
|
|
parents = allList.stream()
|
|
|
.filter(o -> (null == o.getParentSubjectId() || o.getParentSubjectId().equals(0L)))
|
|
@@ -203,6 +214,88 @@ public class SubjectServiceImpl extends BaseServiceImpl<Long, Subject> implement
|
|
|
return all.stream().collect(Collectors.toMap(o -> o.getId().intValue(), o -> o));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void add(SubjectWrapper.AddSubject add) {
|
|
|
+ List<SubjectWrapper.AddSubjectInstrument> subjects = add.getSubjects();
|
|
|
+ if (CollectionUtils.isEmpty(subjects)) {
|
|
|
+ throw new BizException("声部不能为空");
|
|
|
+ }
|
|
|
+ // 声部ID集合
|
|
|
+ String cbsSubjectIds = subjects.stream().map(e->e.getCbsSubjectId().toString()).collect(Collectors.joining(","));
|
|
|
+ // 查询声部是否存在
|
|
|
+ List<Subject> subjectList = subjectDao.getByCbsSubjectIds(cbsSubjectIds);
|
|
|
+ // 已存在的cbsId集合
|
|
|
+ Map<Long,Long> cbsSubjectMap = subjectList.stream()
|
|
|
+ .collect(Collectors.toMap(Subject::getCbsSubjectId, Subject::getId,(o1, o2)->o1));
|
|
|
+
|
|
|
+ // 乐器ID集合
|
|
|
+ List<Long> instrumentIds = subjects.stream().filter(o -> org.apache.commons.collections.CollectionUtils.isNotEmpty(o.getInstrumentIds()))
|
|
|
+ .flatMap(o -> o.getInstrumentIds().stream()).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<Long, CbsMusicalInstrumentWrapper.MusicalInstrumentQueryDto> instrumentQueryDtoMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 查询乐器信息
|
|
|
+ CbsMusicalInstrumentWrapper.MusicalInstrumentQuery musicalInstrumentQuery = new CbsMusicalInstrumentWrapper.MusicalInstrumentQuery();
|
|
|
+ musicalInstrumentQuery.setIds(instrumentIds.stream().map(Long::intValue).collect(Collectors.toList()));
|
|
|
+ musicalInstrumentQuery.setPage(1);
|
|
|
+ musicalInstrumentQuery.setRows(9999);
|
|
|
+ try {
|
|
|
+ List<CbsMusicalInstrumentWrapper.MusicalInstrumentQueryDto> rows = musicFeignClientService
|
|
|
+ .musicalInstrumentPage(musicalInstrumentQuery).feignData().getRows();
|
|
|
+ instrumentQueryDtoMap = rows.stream().collect(Collectors.toMap(o->o.getId().longValue(),o->o,(o1,o2)->o1));
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("调用音乐服务查询乐器失败", e);
|
|
|
+ throw new com.microsvc.toolkit.common.webportal.exception.BizException("内容平台服务异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Instrument> saveInstrumentList = new ArrayList<>();
|
|
|
+ // 保存声部
|
|
|
+ for (SubjectWrapper.AddSubjectInstrument addSubject : subjects) {
|
|
|
+ Long subjectId;
|
|
|
+ if (!cbsSubjectMap.containsKey(addSubject.getCbsSubjectId())) {
|
|
|
+ Subject subject = new Subject();
|
|
|
+ subject.setCbsSubjectId(addSubject.getCbsSubjectId());
|
|
|
+ subject.setEnableFlag(false);
|
|
|
+ this.insert(subject);
|
|
|
+ subjectId= subject.getId();
|
|
|
+ } else {
|
|
|
+ subjectId = cbsSubjectMap.get(addSubject.getCbsSubjectId());
|
|
|
+ }
|
|
|
+ if (org.apache.commons.collections.CollectionUtils.isNotEmpty(addSubject.getInstrumentIds())) {
|
|
|
+ for (Long instrumentId : addSubject.getInstrumentIds()) {
|
|
|
+ Instrument instrument = new Instrument();
|
|
|
+ instrument.setId(instrumentId);
|
|
|
+ instrument.setSubjectId(subjectId);
|
|
|
+ instrument.setEnableFlag(false);
|
|
|
+ instrument.setOperator(add.getOperator());
|
|
|
+ CbsMusicalInstrumentWrapper.MusicalInstrumentQueryDto musicalInstrumentQueryDto = instrumentQueryDtoMap.get(instrumentId);
|
|
|
+ if (musicalInstrumentQueryDto != null) {
|
|
|
+ instrument.setOrientation(musicalInstrumentQueryDto.getOrientation());
|
|
|
+ } else {
|
|
|
+ instrument.setOrientation(false);
|
|
|
+ }
|
|
|
+ saveInstrumentList.add(instrument);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ instrumentService.saveOrUpdateBatch(saveInstrumentList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean enable(Subject subject) {
|
|
|
+ // 停用声部,同时停用声部下的乐器
|
|
|
+ subjectDao.update(subject);
|
|
|
+ if (Boolean.FALSE.equals(subject.getEnableFlag())) {
|
|
|
+ instrumentService.lambdaUpdate()
|
|
|
+ .eq(Instrument::getSubjectId, subject.getId())
|
|
|
+ .eq(Instrument::getEnableFlag, true)
|
|
|
+ .set(Instrument::getEnableFlag, false)
|
|
|
+ .update();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/***
|
|
|
* 查询声部树
|
|
|
* @param: sub
|