|
@@ -2,66 +2,66 @@ package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.beust.jcommander.internal.Lists;
|
|
|
+import com.dayaedu.cbs.common.enums.EClientType;
|
|
|
+import com.dayaedu.cbs.common.enums.music.EAudioType;
|
|
|
+import com.dayaedu.cbs.common.enums.music.EMusicAvailableType;
|
|
|
+import com.dayaedu.cbs.common.enums.music.EMusicPlayMode;
|
|
|
+import com.dayaedu.cbs.common.enums.music.EMusicSourceType;
|
|
|
+import com.dayaedu.cbs.common.enums.school.EMusicSheetType;
|
|
|
+import com.dayaedu.cbs.domain.wrapper.MusicSheetWrapper;
|
|
|
import com.dayaedu.cbs.openfeign.client.MusicFeignClientService;
|
|
|
import com.dayaedu.cbs.openfeign.wrapper.music.CbsMusicSheetApplicationExtendClientWrapper;
|
|
|
import com.dayaedu.cbs.openfeign.wrapper.music.CbsMusicSheetWrapper;
|
|
|
import com.microsvc.toolkit.common.response.template.R;
|
|
|
-import com.ym.mec.biz.dal.dao.*;
|
|
|
-import com.ym.mec.biz.dal.dto.MusicScoreDto;
|
|
|
-import com.ym.mec.biz.dal.dto.SysMusicScoreMetronomeTranscod;
|
|
|
-import com.ym.mec.biz.dal.dto.SysMusicScoreTranscod;
|
|
|
-import com.ym.mec.biz.dal.entity.*;
|
|
|
+import com.ym.mec.biz.dal.dao.SysMusicScoreAccompanimentDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SysMusicScoreCategoriesDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SysMusicScoreDao;
|
|
|
+import com.ym.mec.biz.dal.dto.ReasonDto;
|
|
|
+import com.ym.mec.biz.dal.entity.Subject;
|
|
|
+import com.ym.mec.biz.dal.entity.SysMusicScore;
|
|
|
+import com.ym.mec.biz.dal.entity.SysMusicScoreAccompaniment;
|
|
|
+import com.ym.mec.biz.dal.entity.SysMusicScoreCategories;
|
|
|
+import com.ym.mec.biz.dal.enums.YesOrNoEnum;
|
|
|
import com.ym.mec.biz.dal.page.SysExamSongQueryInfo;
|
|
|
import com.ym.mec.biz.service.*;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
-import com.ym.mec.common.entity.UploadReturnBean;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
-import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
-import com.ym.mec.util.file.FileUtil;
|
|
|
-import com.ym.mec.util.shell.ScriptUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.net.HttpURLConnection;
|
|
|
-import java.net.URL;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.LinkedBlockingQueue;
|
|
|
+import java.util.concurrent.ThreadPoolExecutor;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-import static com.ym.mec.biz.dal.enums.ClientTypeEnum.SMART_PRACTICE;
|
|
|
-
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class SysMusicScoreServiceImpl extends BaseServiceImpl<Integer, SysMusicScore> implements SysMusicScoreService {
|
|
|
|
|
|
@Resource
|
|
|
private SysMusicScoreDao sysMusicScoreDao;
|
|
|
@Resource
|
|
|
- private SysMusicScoreAccompanimentDao sysMusicScoreAccompanimentDao;
|
|
|
- @Resource
|
|
|
- private SysUserService sysUserService;
|
|
|
- @Resource
|
|
|
private SysMusicScoreCategoriesDao sysMusicScoreCategoriesDao;
|
|
|
@Resource
|
|
|
- private SubjectDao subjectDao;
|
|
|
- @Resource
|
|
|
private SysMusicScoreCategoriesService sysMusicScoreCategoriesService;
|
|
|
@Resource
|
|
|
- private SysMusicScoreChangeLogDao sysMusicScoreChangeLogDao;
|
|
|
- @Resource
|
|
|
- private IdGeneratorService idGeneratorService;
|
|
|
+ private OrganizationService organizationService;
|
|
|
@Resource
|
|
|
- private UploadFileService uploadFileService;
|
|
|
+ private SubjectService subjectService;
|
|
|
@Resource
|
|
|
- private OrganizationService organizationService;
|
|
|
+ private SysMusicScoreAccompanimentDao sysMusicScoreAccompanimentDao;
|
|
|
@Resource
|
|
|
private MusicFeignClientService musicFeignClientService;
|
|
|
|
|
@@ -78,101 +78,6 @@ public class SysMusicScoreServiceImpl extends BaseServiceImpl<Integer, SysMusicS
|
|
|
return sysMusicScoreDao;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void updateMusicScore(MusicScoreDto musicScoreDto) {
|
|
|
- SysMusicScore sysMusicScore = musicScoreDto.getSysMusicScore();
|
|
|
- sysMusicScoreDao.update(sysMusicScore);
|
|
|
- List<Integer> delExamSongAccompanimentIds = musicScoreDto.getDelExamSongAccompanimentIds();
|
|
|
- if (delExamSongAccompanimentIds != null && delExamSongAccompanimentIds.size() > 0) {
|
|
|
- sysMusicScoreAccompanimentDao.batchDel(delExamSongAccompanimentIds);
|
|
|
- }
|
|
|
- List<SysMusicScoreAccompaniment> sysMusicScoreAccompaniments = musicScoreDto.getSysMusicScoreAccompaniments();
|
|
|
- if (sysMusicScoreAccompaniments != null && sysMusicScoreAccompaniments.size() > 0) {
|
|
|
- List<Integer> subjectIdList = sysMusicScoreAccompaniments.stream().map(e -> e.getSubjectId()).collect(Collectors.toList());
|
|
|
- subjectIdList.removeAll(Collections.singleton(null));
|
|
|
-
|
|
|
- if (subjectIdList.size() > 0) {
|
|
|
- List<Integer> idList = sysMusicScoreAccompaniments.stream().map(e -> e.getId()).collect(Collectors.toList());
|
|
|
- List<Integer> subjectIds = sysMusicScoreAccompanimentDao.findSubjectByMusicScoreId(sysMusicScore.getId(), idList);
|
|
|
- int subjectSize = subjectIds.size() + subjectIdList.size();
|
|
|
- subjectIdList.addAll(subjectIds);
|
|
|
- int size = new HashSet<>(subjectIdList).size();
|
|
|
- if (size < subjectSize && !musicScoreDto.getMultitrack()) {
|
|
|
- throw new BizException("操作失败:请勿提交重复的伴奏声部");
|
|
|
- }
|
|
|
- }
|
|
|
- //获取需要修改的伴奏
|
|
|
- List<SysMusicScoreAccompaniment> updateCollect = sysMusicScoreAccompaniments.stream().filter(e -> e.getId() != null).collect(Collectors.toList());
|
|
|
- if (updateCollect.size() > 0) {
|
|
|
- sysMusicScoreAccompanimentDao.batchUpdate(updateCollect, sysMusicScore.getIsOpenMetronome());
|
|
|
- }
|
|
|
- //获取需要新增的伴奏
|
|
|
- List<SysMusicScoreAccompaniment> addCollect = sysMusicScoreAccompaniments.stream().filter(e -> e.getId() == null).collect(Collectors.toList());
|
|
|
- if (addCollect.size() > 0) {
|
|
|
- sysMusicScoreAccompanimentDao.batchInsert(addCollect, sysMusicScore.getId(), sysMusicScore.getIsOpenMetronome());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void add(MusicScoreDto musicScoreDto) {
|
|
|
- SysMusicScore sysMusicScore = musicScoreDto.getSysMusicScore();
|
|
|
- sysMusicScore.setCreateUserId(sysUserService.getUserId());
|
|
|
- sysMusicScoreDao.insert(sysMusicScore);
|
|
|
- List<SysMusicScoreAccompaniment> sysMusicScoreAccompaniments = musicScoreDto.getSysMusicScoreAccompaniments();
|
|
|
- if (sysMusicScoreAccompaniments != null && sysMusicScoreAccompaniments.size() > 0) {
|
|
|
- sysMusicScoreAccompaniments.forEach(e -> {
|
|
|
- e.setIsOpenMetronome(sysMusicScore.getIsOpenMetronome());
|
|
|
- });
|
|
|
- sysMusicScoreAccompanimentDao.batchInsert(sysMusicScoreAccompaniments, sysMusicScore.getId(), sysMusicScore.getIsOpenMetronome());
|
|
|
- }
|
|
|
- Integer categoriesId = sysMusicScore.getMusicScoreCategoriesId();
|
|
|
- if (categoriesId != null && sysMusicScore.getClientType() == SMART_PRACTICE) {
|
|
|
- while (true) {
|
|
|
- SysMusicScoreCategories categories = sysMusicScoreCategoriesDao.get(categoriesId);
|
|
|
- if (categories.getParentId() == 0) {
|
|
|
- categories.setMusicScoreNum(categories.getMusicScoreNum() + 1);
|
|
|
- sysMusicScoreCategoriesDao.update(categories);
|
|
|
- return;
|
|
|
- }
|
|
|
- categoriesId = categories.getParentId();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void del(Integer id) {
|
|
|
- SysMusicScore sysMusicScore = sysMusicScoreDao.get(id);
|
|
|
- if (sysMusicScore == null) {
|
|
|
- throw new BizException("曲目不存在");
|
|
|
- }
|
|
|
- Integer userId = sysUserService.getUserId();
|
|
|
- if (!Objects.equals(sysMusicScore.getCreateUserId(), userId)) {
|
|
|
- throw new BizException("无权限删除");
|
|
|
- }
|
|
|
- sysMusicScoreDao.delete(id);
|
|
|
- sysMusicScoreAccompanimentDao.deleteBySongId(id);
|
|
|
- Integer categoriesId = sysMusicScore.getMusicScoreCategoriesId();
|
|
|
- if (categoriesId != null && sysMusicScore.getClientType() == SMART_PRACTICE) {
|
|
|
- while (true) {
|
|
|
- SysMusicScoreCategories categories = sysMusicScoreCategoriesDao.get(categoriesId);
|
|
|
- if (categories.getParentId() == 0) {
|
|
|
- Integer musicScoreNum = categories.getMusicScoreNum() - 1;
|
|
|
- if (musicScoreNum < 0) {
|
|
|
- musicScoreNum = 0;
|
|
|
- }
|
|
|
- categories.setMusicScoreNum(musicScoreNum);
|
|
|
- sysMusicScoreCategoriesDao.update(categories);
|
|
|
- return;
|
|
|
- }
|
|
|
- categoriesId = categories.getParentId();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private String getParentTreeName(Integer categoriesId) {
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
while (true) {
|
|
@@ -191,9 +96,9 @@ public class SysMusicScoreServiceImpl extends BaseServiceImpl<Integer, SysMusicS
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<CbsMusicSheetWrapper.MusicSheetApplication> queryCbsMusicSheetApplication(List<Long> cbsMusicSheetIds){
|
|
|
+ public List<CbsMusicSheetWrapper.MusicSheetApplication> queryCbsMusicSheetApplication(List<String> cbsMusicSheetIds){
|
|
|
CbsMusicSheetWrapper.MusicSheetApplicationQuery query = new CbsMusicSheetWrapper.MusicSheetApplicationQuery();
|
|
|
- query.setMusicSheetIds(cbsMusicSheetIds);
|
|
|
+ query.setMusicSheetIds(cbsMusicSheetIds.stream().map(Long::parseLong).collect(Collectors.toList()));
|
|
|
query.setDetailFlag(true);
|
|
|
query.setDelFlag(true);
|
|
|
query.setPage(1);
|
|
@@ -213,60 +118,36 @@ public class SysMusicScoreServiceImpl extends BaseServiceImpl<Integer, SysMusicS
|
|
|
|
|
|
private void dealMusicScoreData(List<SysMusicScore> records){
|
|
|
if (CollectionUtils.isNotEmpty(records)) {
|
|
|
- List<Long> cbsMusicSheetIds = records.stream().map(e -> e.getCbsMusicSheetId()).collect(Collectors.toList());
|
|
|
+ List<String> cbsMusicSheetIds = records.stream().map(SysMusicScore::getCbsMusicSheetId).collect(Collectors.toList());
|
|
|
List<CbsMusicSheetWrapper.MusicSheetApplication> applications = this.queryCbsMusicSheetApplication(cbsMusicSheetIds);
|
|
|
if(CollectionUtils.isNotEmpty(applications)){
|
|
|
+ Set<Integer> categoriesIds = records.stream().map(SysMusicScore::getMusicScoreCategoriesId).collect(Collectors.toSet());
|
|
|
+ //获取分部列表
|
|
|
+ Map<Integer, String> organMap = MapUtil.convertMybatisMap(sysMusicScoreCategoriesDao.queryOrganByIds(categoriesIds));
|
|
|
+ Map<Integer, String> map = new HashMap<>(categoriesIds.size());
|
|
|
+ for (Integer categoriesId : categoriesIds) {
|
|
|
+ if(null != categoriesId){
|
|
|
+ map.put(categoriesId, getParentTreeName(categoriesId));
|
|
|
+ }
|
|
|
+ }
|
|
|
Map<Long, CbsMusicSheetWrapper.MusicSheetApplication> musicSheetApplicationMap = applications
|
|
|
.stream().collect(Collectors.toMap(CbsMusicSheetWrapper.MusicSheetApplication::getId, Function.identity()));
|
|
|
- List<Subject> subjects = subjectDao.queryCbsList(null);
|
|
|
- Map<Long, Subject> subjectMap = subjects.stream().collect(Collectors.toMap(Subject::getCbsSubjectId, Function.identity()));
|
|
|
for (SysMusicScore record : records) {
|
|
|
- CbsMusicSheetWrapper.MusicSheetApplication musicSheetApplication = musicSheetApplicationMap.get(record.getCbsMusicSheetId());
|
|
|
+ record.setCategoriesName(map.get(record.getMusicScoreCategoriesId()));
|
|
|
+ record.setOrganName(organMap.get(record.getMusicScoreCategoriesId()));
|
|
|
+ CbsMusicSheetWrapper.MusicSheetApplication musicSheetApplication = musicSheetApplicationMap.get(Long.parseLong(record.getCbsMusicSheetId()));
|
|
|
if(musicSheetApplication != null){
|
|
|
- this.initMusicSheetVo(record,musicSheetApplication,subjectMap);
|
|
|
+ this.initMusicSheetVo(record,musicSheetApplication);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- Set<Integer> categoriesIds = records.stream().map(e -> e.getMusicScoreCategoriesId()).collect(Collectors.toSet());
|
|
|
- //获取分部列表
|
|
|
- Map<Integer, String> organMap = MapUtil.convertMybatisMap(sysMusicScoreCategoriesDao.queryOrganByIds(categoriesIds));
|
|
|
- //获取声部列表
|
|
|
- /*Set<Integer> subjectIds = rows.stream().map(e -> e.getSubjectId()).collect(Collectors.toSet());
|
|
|
- subjectIds.removeAll(Collections.singleton(null));
|
|
|
- Map<Long, String> subjectMap = new HashMap();
|
|
|
- if (subjectIds.size() > 0) {
|
|
|
- String ids = StringUtils.join(subjectIds, ",");
|
|
|
- subjectMap = MapUtil.convertMybatisMap(subjectDao.findBySubjecIds(ids));
|
|
|
- }*/
|
|
|
- Map<Integer, String> map = new HashMap<>(categoriesIds.size());
|
|
|
- for (Integer categoriesId : categoriesIds) {
|
|
|
- if(null != categoriesId){
|
|
|
- map.put(categoriesId, getParentTreeName(categoriesId));
|
|
|
- }
|
|
|
- }
|
|
|
- for (SysMusicScore row : records) {
|
|
|
- row.setCategoriesName(map.get(row.getMusicScoreCategoriesId()));
|
|
|
- row.setOrganName(organMap.get(row.getMusicScoreCategoriesId()));
|
|
|
-// row.setSubjectName(subjectMap.get(row.getSubjectId()));
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void initMusicSheetVo(SysMusicScore record,CbsMusicSheetWrapper.MusicSheetApplication musicSheetApplication,Map<Long, Subject> subjectMap){
|
|
|
- if(StringUtils.isNotEmpty(musicSheetApplication.getSubjectIds())){
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- for (String s : musicSheetApplication.getSubjectIds().split(",")) {
|
|
|
- Subject subject = subjectMap.get(Long.parseLong(s));
|
|
|
- if(subject != null){
|
|
|
- if (sb.length() > 0) {
|
|
|
- sb.append(",");
|
|
|
- }
|
|
|
- sb.append(subject.getName());
|
|
|
- }
|
|
|
- }
|
|
|
- record.setSubjectName(sb.toString());
|
|
|
- }
|
|
|
- record.setCbsMusicSheetId(musicSheetApplication.getId());
|
|
|
+ public void initMusicSheetVo(SysMusicScore record,CbsMusicSheetWrapper.MusicSheetApplication musicSheetApplication){
|
|
|
+ record.setSubjectName(musicSheetApplication.getSubjectNames());
|
|
|
+ record.setRankIds(StringUtils.equals("FREE",musicSheetApplication.getPaymentType()) ? "" : "1");
|
|
|
+ record.setCbsMusicSheetId(musicSheetApplication.getId().toString());
|
|
|
record.setPlayMode(SysMusicScore.PlayMode.valueOf(musicSheetApplication.getPlayMode().getCode()));
|
|
|
record.setExtConfigJson(musicSheetApplication.getExtConfigJson());
|
|
|
record.setExtStyleConfigJson(musicSheetApplication.getExtStyleConfigJson());
|
|
@@ -362,77 +243,6 @@ public class SysMusicScoreServiceImpl extends BaseServiceImpl<Integer, SysMusicS
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void transcod(Integer sysMusicScoreId) {
|
|
|
- SysMusicScoreTranscod obj = sysMusicScoreDao.getTranscod(sysMusicScoreId);
|
|
|
- if (obj == null) {
|
|
|
- throw new BizException("曲目信息不存在");
|
|
|
- }
|
|
|
- List<SysMusicScoreMetronomeTranscod> metronomeTranscod = sysMusicScoreDao.getMetronomeTranscod(sysMusicScoreId);
|
|
|
- obj.setAccompanimentList(metronomeTranscod);
|
|
|
- //
|
|
|
- String old = JSONObject.toJSONString(obj);
|
|
|
- boolean flag = false;
|
|
|
- String url = doTranscod(obj.getUrl());
|
|
|
- if (StringUtils.isNotEmpty(url)) {
|
|
|
- obj.setUrl(url);
|
|
|
- flag = true;
|
|
|
- }
|
|
|
- String metronomeUrl = doTranscod(obj.getMetronomeUrl());
|
|
|
- if (StringUtils.isNotEmpty(metronomeUrl)) {
|
|
|
- obj.setMetronomeUrl(metronomeUrl);
|
|
|
- flag = true;
|
|
|
- }
|
|
|
- if (flag) {
|
|
|
- //更新obj
|
|
|
- SysMusicScore sysMusicScore = new SysMusicScore();
|
|
|
- sysMusicScore.setId(obj.getId());
|
|
|
- sysMusicScore.setUrl(obj.getUrl());
|
|
|
- sysMusicScore.setMetronomeUrl(obj.getMetronomeUrl());
|
|
|
- sysMusicScoreDao.update(sysMusicScore);
|
|
|
- }
|
|
|
-
|
|
|
- for (SysMusicScoreMetronomeTranscod o : metronomeTranscod) {
|
|
|
- Boolean subFlag = false;
|
|
|
- String mp3Url = doTranscod(o.getMp3Url());
|
|
|
- if (StringUtils.isNotEmpty(mp3Url)) {
|
|
|
- o.setMp3Url(mp3Url);
|
|
|
- flag = true;
|
|
|
- subFlag = true;
|
|
|
- }
|
|
|
- String metronomeMp3Url = doTranscod(o.getMetronomeMp3Url());
|
|
|
- if (StringUtils.isNotEmpty(metronomeMp3Url)) {
|
|
|
- o.setMetronomeMp3Url(metronomeMp3Url);
|
|
|
- flag = true;
|
|
|
- subFlag = true;
|
|
|
- }
|
|
|
- if (subFlag) {
|
|
|
- SysMusicScoreAccompaniment accompaniment = new SysMusicScoreAccompaniment();
|
|
|
- accompaniment.setExamSongId(o.getId());
|
|
|
- accompaniment.setMp3Url(o.getMp3Url());
|
|
|
- accompaniment.setMetronomeMp3Url(o.getMetronomeMp3Url());
|
|
|
- sysMusicScoreDao.updateAccompanimentBySongId(accompaniment);
|
|
|
- }
|
|
|
- }
|
|
|
- if (!flag) {
|
|
|
- return;
|
|
|
- }
|
|
|
- obj.setAccompanimentList(metronomeTranscod);
|
|
|
- String now = JSONObject.toJSONString(obj);
|
|
|
-
|
|
|
- //记录日志
|
|
|
- SysMusicScoreChangeLog log = new SysMusicScoreChangeLog();
|
|
|
- log.setSysMusicScoreId(obj.getId());
|
|
|
- log.setChangeBefore(old);
|
|
|
- log.setChangeAfter(now);
|
|
|
- sysMusicScoreChangeLogDao.insert(log);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int updateExtStyleConfigJson(Integer id, String extStyleConfigJson) {
|
|
|
- return sysMusicScoreDao.updateExtStyleConfigJson(id, extStyleConfigJson);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
public Map<Long, SysMusicScore> getMapByIds(List<Long> musicSheetIds) {
|
|
|
if (CollectionUtils.isEmpty(musicSheetIds)) {
|
|
|
return new HashMap<>();
|
|
@@ -446,108 +256,195 @@ public class SysMusicScoreServiceImpl extends BaseServiceImpl<Integer, SysMusicS
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void enable(Integer sysMusicScoreId, Integer showFlag) {
|
|
|
- SysMusicScore sysMusicScore = this.get(sysMusicScoreId);
|
|
|
- if(sysMusicScore == null){
|
|
|
+ public Boolean stateList(ReasonDto reasonDto) {
|
|
|
+ List<Integer> musicSheets = Arrays.stream(reasonDto.getMusicSheetIds().split(",")).map(Integer::parseInt).collect(Collectors.toList());
|
|
|
+ List<SysMusicScore> musicSheetList = sysMusicScoreDao.findByIds(musicSheets.stream().map(String::valueOf).collect(Collectors.joining(",")));
|
|
|
+
|
|
|
+ List<CbsMusicSheetWrapper.MusicSheetApplication> rows =
|
|
|
+ this.queryCbsMusicSheetApplication(musicSheetList.stream().map(e -> e.getCbsMusicSheetId()).collect(Collectors.toList()));
|
|
|
+ String applicationExtendIds = rows.stream().map(e -> e.getApplicationExtendId().toString()).collect(Collectors.joining(","));
|
|
|
+ CbsMusicSheetApplicationExtendClientWrapper.MusicSheetApplicationExtendStatus extendStatus = new CbsMusicSheetApplicationExtendClientWrapper.MusicSheetApplicationExtendStatus();
|
|
|
+ extendStatus.setIds(applicationExtendIds);
|
|
|
+ extendStatus.setStatus(reasonDto.getState()== YesOrNoEnum.YES);
|
|
|
+ R<JSONObject> jsonObjectR = musicFeignClientService.musicSheetApplicationExtendStatus(extendStatus);
|
|
|
+ if (jsonObjectR.getCode() != 200) {
|
|
|
+ throw new BizException("修改曲目状态失败,{}", jsonObjectR.getMessage());
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean state(Integer id) {
|
|
|
+ SysMusicScore musicScore = sysMusicScoreDao.get(id);
|
|
|
+ if (musicScore == null) {
|
|
|
throw new BizException("曲目信息不存在");
|
|
|
}
|
|
|
- CbsMusicSheetWrapper.MusicSheetApplicationQuery query = new CbsMusicSheetWrapper.MusicSheetApplicationQuery();
|
|
|
- query.setApplicationId(applicationId);
|
|
|
- query.setMusicSheetIds(Collections.singletonList(sysMusicScore.getCbsMusicSheetId()));
|
|
|
- query.setDelFlag(true);
|
|
|
- query.setPage(1);
|
|
|
- query.setRows(1);
|
|
|
- R<com.microsvc.toolkit.common.response.paging.PageInfo<CbsMusicSheetWrapper.MusicSheetApplication>> pageInfoR = musicFeignClientService.musicSheetPageByApplication(query);
|
|
|
- if (pageInfoR.getCode() != 200) {
|
|
|
- throw new BizException("获取曲目信息异常,{}", pageInfoR.getMessage());
|
|
|
+ List<CbsMusicSheetWrapper.MusicSheetApplication> rows =
|
|
|
+ this.queryCbsMusicSheetApplication(Collections.singletonList(musicScore.getCbsMusicSheetId()));
|
|
|
+ String applicationExtendIds = rows.stream().map(e -> e.getApplicationExtendId().toString()).collect(Collectors.joining(","));
|
|
|
+ CbsMusicSheetApplicationExtendClientWrapper.MusicSheetApplicationExtendStatus extendStatus = new CbsMusicSheetApplicationExtendClientWrapper.MusicSheetApplicationExtendStatus();
|
|
|
+ extendStatus.setIds(applicationExtendIds);
|
|
|
+ extendStatus.setStatus(musicScore.getShowFlag() != 1);
|
|
|
+ R<JSONObject> jsonObjectR = musicFeignClientService.musicSheetApplicationExtendStatus(extendStatus);
|
|
|
+ if (jsonObjectR.getCode() != 200) {
|
|
|
+ throw new BizException("修改曲目状态失败,{}", jsonObjectR.getMessage());
|
|
|
}
|
|
|
- List<CbsMusicSheetWrapper.MusicSheetApplication> rows = pageInfoR.feignData().getRows();
|
|
|
- if (CollectionUtils.isEmpty(rows)) {
|
|
|
- throw new BizException("获取曲目信息失败");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateCbs(MusicSheetWrapper.MusicSheetApplicationExtendWrapper addMusicSheetApplicationExtend) {
|
|
|
+ CbsMusicSheetApplicationExtendClientWrapper.AddMusicSheetApplicationExtend extend =
|
|
|
+ JSONObject.parseObject(JSONObject.toJSONString(addMusicSheetApplicationExtend), CbsMusicSheetApplicationExtendClientWrapper.AddMusicSheetApplicationExtend.class);
|
|
|
+ extend.setApplicationId(applicationId);
|
|
|
+ R<JSONObject> jsonObjectR = musicFeignClientService.musicSheetApplicationExtendUpdate(extend);
|
|
|
+ if (jsonObjectR.getCode() != 200) {
|
|
|
+ throw new BizException("修改失败,{}",jsonObjectR.getMessage());
|
|
|
}
|
|
|
- CbsMusicSheetWrapper.MusicSheetApplication musicSheetApplication = rows.get(0);
|
|
|
- CbsMusicSheetApplicationExtendClientWrapper.MusicSheetApplicationExtendStatus extendStatus = new CbsMusicSheetApplicationExtendClientWrapper.MusicSheetApplicationExtendStatus();
|
|
|
- extendStatus.setIds(musicSheetApplication.getApplicationExtendId().toString());
|
|
|
- extendStatus.setStatus(showFlag == 1);
|
|
|
- musicFeignClientService.musicSheetApplicationExtendStatus(extendStatus);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 进行转码
|
|
|
- *
|
|
|
- * @param fileUrl
|
|
|
- * @return
|
|
|
- */
|
|
|
- private String doTranscod(String fileUrl) {
|
|
|
- String transcodUrl = "";
|
|
|
- if (StringUtils.isEmpty(fileUrl)) {
|
|
|
- return transcodUrl;
|
|
|
+ @Override
|
|
|
+ public void sync() {
|
|
|
+ ThreadPoolExecutor executorService = new ThreadPoolExecutor(50, 50,
|
|
|
+ 0L, TimeUnit.MILLISECONDS,
|
|
|
+ new LinkedBlockingQueue<>());
|
|
|
+ List<SysMusicScore> records = sysMusicScoreDao.selectSyncPage();
|
|
|
+ if (CollectionUtils.isEmpty(records)) {
|
|
|
+ return;
|
|
|
}
|
|
|
- //文件扩展名
|
|
|
- String expand = FileUtil.getFileExpandByPath(fileUrl);
|
|
|
- //将远程文件写入本地临时文件路径
|
|
|
- String tempFileName = getTempFileName(expand);
|
|
|
- File tempFile = new File(tempFileName);
|
|
|
- //转码后文件路径
|
|
|
- String tempTranscodFileName = getTempFileName(expand);
|
|
|
- try {
|
|
|
- URL url = new URL(fileUrl);
|
|
|
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
|
- //设置超时间为3秒
|
|
|
- conn.setConnectTimeout(3 * 1000);
|
|
|
- //防止屏蔽程序抓取而返回403错误
|
|
|
- conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
|
|
-
|
|
|
- FileUtil.inputStreamToFile(conn.getInputStream(), tempFile);
|
|
|
-
|
|
|
- String script = "ffmpeg -i " + tempFileName + " -vn -c:a libmp3lame -b:a 320k -ac 2 " + tempTranscodFileName;
|
|
|
- int i = ScriptUtil.callScript(script);
|
|
|
- if (i == 0) {
|
|
|
- //转码成功
|
|
|
- FileInputStream inputStream = new FileInputStream(tempTranscodFileName);
|
|
|
- UploadReturnBean uploadReturnBean = uploadFileService.uploadFile(inputStream, expand);
|
|
|
- transcodUrl = uploadReturnBean.getUrl();
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- //删除服务器中的文件
|
|
|
- if (tempFile.exists()) {
|
|
|
- tempFile.delete();
|
|
|
+ for (SysMusicScore record : records) {
|
|
|
+ executorService.submit(() ->
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ syncMusicSheet(record);
|
|
|
+ }catch (Exception e) {
|
|
|
+ log.error("曲目同步异常,曲目ID:{}", record.getId(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ while (!executorService.getQueue().isEmpty()) {
|
|
|
+ try {
|
|
|
+ log.info("线程池中正在执行的任务数量:{},等待数量:{}", executorService.getActiveCount(),executorService.getQueue().size());
|
|
|
+ Thread.sleep(1000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error("线程等待异常", e);
|
|
|
}
|
|
|
- File tempTranscodFile = new File(tempTranscodFileName);
|
|
|
- if (tempTranscodFile.exists()) {
|
|
|
- tempTranscodFile.delete();
|
|
|
+ }
|
|
|
+ log.info("-------------------- 曲目数据同步成功! -------------------------------");
|
|
|
+ executorService.shutdown();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void syncMusicSheet(SysMusicScore record) {
|
|
|
+ List<SysMusicScoreAccompaniment> list = sysMusicScoreAccompanimentDao.findByMusicScoreId(record.getId());
|
|
|
+
|
|
|
+ CbsMusicSheetWrapper.AddMusicSheet addMusicSheet = this.musicToAddMusicSheet(record,list);
|
|
|
+
|
|
|
+ R<CbsMusicSheetWrapper.MusicSheet> musicSheetR = musicFeignClientService.musicCbsSync(addMusicSheet);
|
|
|
+ try {
|
|
|
+ CbsMusicSheetWrapper.MusicSheet musicSheet = musicSheetR.feignData();
|
|
|
+ if (musicSheet == null) {
|
|
|
+ log.error("曲目同步失败,曲目ID:{}", record.getId());
|
|
|
}
|
|
|
+ } catch (Exception e){
|
|
|
+ log.error("曲目同步失败,曲目ID:{}", record.getId(),e);
|
|
|
}
|
|
|
- return transcodUrl;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 通过网络文件路径获取临时文件路径
|
|
|
- *
|
|
|
- * @param fileUrl
|
|
|
- * @return
|
|
|
- */
|
|
|
- String tempPath = "/usr/temp";
|
|
|
-
|
|
|
- private String getTempFileName(String expand) {
|
|
|
- //没有目录则创建
|
|
|
- File file = new File(tempPath);
|
|
|
- if (!file.exists()) {
|
|
|
- file.mkdirs();
|
|
|
+ //测试环境合奏分类
|
|
|
+ private static String categoryIds = "42,43,44,45,46,91,92,93,94,95,7,11,15,180";
|
|
|
+ private static String prodCategoryIds = "42,43,44,45,46,91,92,93,94,95,185,186,7,11,15,180";
|
|
|
+
|
|
|
+ private CbsMusicSheetWrapper.AddMusicSheet musicToAddMusicSheet(SysMusicScore from, List<SysMusicScoreAccompaniment> accList) {
|
|
|
+ CbsMusicSheetWrapper.AddMusicSheet addMusicSheet = new CbsMusicSheetWrapper.AddMusicSheet();
|
|
|
+ addMusicSheet.setId(Long.parseLong(from.getCbsMusicSheetId()));
|
|
|
+ addMusicSheet.setName(from.getName());
|
|
|
+ if (StringUtils.isNotBlank(from.getSubjectIds())) {
|
|
|
+ List<Integer> subjectIds = Arrays.stream(from.getSubjectIds().split(","))
|
|
|
+ .map(Integer::parseInt).distinct().collect(Collectors.toList());
|
|
|
+ List<Subject> list = subjectService.findBySubjectByIdList(subjectIds);
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ addMusicSheet.setSubjectIds(list.stream().map(o->o.getCbsSubjectId().toString()).collect(Collectors.joining(",")));
|
|
|
+ }
|
|
|
}
|
|
|
- //.mp3
|
|
|
- String fileName = tempPath + File.separator + idGeneratorService.generatorId("tempFile");
|
|
|
- if (StringUtils.isNotEmpty(expand)) {
|
|
|
- fileName += "." + expand;
|
|
|
+ addMusicSheet.setSendAppFlag(false);
|
|
|
+ addMusicSheet.setAppAuditFlag(false);
|
|
|
+ addMusicSheet.setRemark(from.getMuseScoreMemo());
|
|
|
+ addMusicSheet.setIsUseSystemBeat(true);
|
|
|
+ if(categoryIds.contains(from.getCategoriesId().toString())){
|
|
|
+ addMusicSheet.setMusicSheetType(EMusicSheetType.CONCERT);
|
|
|
+ }else {
|
|
|
+ addMusicSheet.setMusicSheetType(EMusicSheetType.SINGLE);
|
|
|
+ }
|
|
|
+ addMusicSheet.setIsEvaluated(from.isEnableEvaluation());
|
|
|
+ addMusicSheet.setIsConvertibleScore(true);
|
|
|
+ addMusicSheet.setPlaySpeed(from.getSpeed());
|
|
|
+ addMusicSheet.setPlayMode(from.getPlayMode() == SysMusicScore.PlayMode.MP3 ? EMusicPlayMode.MP3 : EMusicPlayMode.MIDI);
|
|
|
+ addMusicSheet.setMidiFileUrl(from.getMidiUrl());
|
|
|
+ addMusicSheet.setExtConfigJson(from.getExtConfigJson());
|
|
|
+ addMusicSheet.setCreateTime(from.getCreateTime());
|
|
|
+ addMusicSheet.setAudioType(EAudioType.HOMEMODE);
|
|
|
+ addMusicSheet.setAvailableType(EMusicAvailableType.ORG);
|
|
|
+ addMusicSheet.setSourceType(EMusicSourceType.PLATFORM);
|
|
|
+ addMusicSheet.setStatus(true);
|
|
|
+
|
|
|
+ String tracks = "";
|
|
|
+ // 伴奏,原音 扩展信息
|
|
|
+ if (addMusicSheet.getPlayMode() == EMusicPlayMode.MP3) {
|
|
|
+ CbsMusicSheetWrapper.MusicSheetAccompaniment musicSheetAccompaniment = new CbsMusicSheetWrapper.MusicSheetAccompaniment();
|
|
|
+ if (StringUtils.isNotBlank(musicSheetAccompaniment.getAudioFileUrl())) {
|
|
|
+ addMusicSheet.setMusicSheetAccompanimentList(Lists.newArrayList(musicSheetAccompaniment));
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(accList)) {
|
|
|
+ List<CbsMusicSheetWrapper.MusicSheetSound> musicSheetSounds = new ArrayList<>();
|
|
|
+ int i = 0;
|
|
|
+ for (SysMusicScoreAccompaniment sheetAccompaniment : accList) {
|
|
|
+ CbsMusicSheetWrapper.MusicSheetSound musicSheetSound = new CbsMusicSheetWrapper.MusicSheetSound();
|
|
|
+ if (StringUtils.isNotBlank(sheetAccompaniment.getMetronomeMp3Url())){
|
|
|
+ musicSheetSound.setAudioFileUrl(sheetAccompaniment.getMetronomeMp3Url());
|
|
|
+ } else {
|
|
|
+ musicSheetSound.setAudioFileUrl(sheetAccompaniment.getMp3Url());
|
|
|
+ }
|
|
|
+ musicSheetSound.setTrack(sheetAccompaniment.getTrack());
|
|
|
+ musicSheetSound.setSortNumber(i++);
|
|
|
+ if (StringUtils.isNotBlank(musicSheetSound.getAudioFileUrl())) {
|
|
|
+ //xml
|
|
|
+ addMusicSheet.setXmlFileUrl(sheetAccompaniment.getXmlUrl());
|
|
|
+ //是否显示指法
|
|
|
+ addMusicSheet.setIsShowFingering(sheetAccompaniment.getIsShowFingering());
|
|
|
+ //是否播放节拍器
|
|
|
+ addMusicSheet.setIsPlayBeat(sheetAccompaniment.getIsOpenMetronome());
|
|
|
+ musicSheetSounds.add(musicSheetSound);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tracks = musicSheetSounds.stream().map(CbsMusicSheetWrapper.MusicSheetSound::getTrack).collect(Collectors.joining(","));
|
|
|
+ addMusicSheet.setMusicSheetSoundList(musicSheetSounds);
|
|
|
+ }
|
|
|
}
|
|
|
- return fileName;
|
|
|
+ addMusicSheet.setMultiTracksSelection(tracks);
|
|
|
+
|
|
|
+ CbsMusicSheetWrapper.MusicSheetExtend musicSheetExtend = new CbsMusicSheetWrapper.MusicSheetExtend();
|
|
|
+ musicSheetExtend.setApplicationId(applicationId);
|
|
|
+ musicSheetExtend.setClientType(EClientType.BACKEND.name());
|
|
|
+ addMusicSheet.setMusicSheetExtend(musicSheetExtend);
|
|
|
+
|
|
|
+ // 应用扩展信息
|
|
|
+ CbsMusicSheetApplicationExtendClientWrapper.AddMusicSheetApplicationExtend addMusicSheetApplicationExtend = new CbsMusicSheetApplicationExtendClientWrapper.AddMusicSheetApplicationExtend();
|
|
|
+ addMusicSheetApplicationExtend.setApplicationId(applicationId);
|
|
|
+ addMusicSheetApplicationExtend.setStatus(addMusicSheet.getStatus());
|
|
|
+ addMusicSheetApplicationExtend.setSortNo(from.getOrder());
|
|
|
+ addMusicSheetApplicationExtend.setPaymentType(StringUtils.isNotEmpty(from.getRankIds()) ? "PAY" : "FREE");
|
|
|
+ addMusicSheetApplicationExtend.setAvailableType(EMusicAvailableType.ORG);
|
|
|
+ addMusicSheetApplicationExtend.setMusicSheetCategoryId(from.getCategoriesId().longValue());
|
|
|
+ addMusicSheet.setAddMusicSheetApplicationExtend(Lists.newArrayList(addMusicSheetApplicationExtend));
|
|
|
+ addMusicSheet.setIsConvertibleScore(true);
|
|
|
+ return addMusicSheet;
|
|
|
}
|
|
|
|
|
|
private void getAllCategoryIdList(List<Integer> categoryIdList, List<SysMusicScoreCategories> sysMusicScoreCategoriesList) {
|
|
|
|
|
|
- if (sysMusicScoreCategoriesList != null && sysMusicScoreCategoriesList.size() > 0) {
|
|
|
+ if (CollectionUtils.isNotEmpty(sysMusicScoreCategoriesList)) {
|
|
|
for (SysMusicScoreCategories sysMusicScoreCategories : sysMusicScoreCategoriesList) {
|
|
|
categoryIdList.add(sysMusicScoreCategories.getId());
|
|
|
getAllCategoryIdList(categoryIdList, sysMusicScoreCategories.getSysMusicScoreCategoriesList());
|