Bladeren bron

酷乐秀曲目来源改为内容平台

zouxuan 1 jaar geleden
bovenliggende
commit
767d5497ce

+ 80 - 12
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/SubjectController.java

@@ -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("内容平台服务异常");
+		}
     }
 }

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/SubjectDao.java

@@ -78,4 +78,6 @@ public interface SubjectDao extends BaseDAO<Long, Subject> {
     int findCount(Map<String, Object> params);
 
     List<SubjectWrapper.Subject> findPage(Map<String, Object> params);
+
+    List<Subject> notInSubjectIds(Long subjectId);
 }

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/SubjectService.java

@@ -68,4 +68,6 @@ public interface SubjectService extends BaseService<Long, Subject> {
 	Boolean enable(Subject subject);
 
 	PageInfo<SubjectWrapper.Subject> selectPage(SubjectWrapper.SubjectQuery query);
+
+	List<SubjectWrapper.Subject> list(SubjectWrapper.SubjectQuery query1);
 }

+ 24 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/SubjectServiceImpl.java

@@ -1,8 +1,10 @@
 package com.yonge.cooleshow.biz.dal.service.impl;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
 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.response.paging.QueryInfo;
 import com.yonge.cooleshow.biz.dal.dao.SubjectDao;
 import com.yonge.cooleshow.biz.dal.dao.TeacherDao;
 import com.yonge.cooleshow.biz.dal.entity.Instrument;
@@ -366,6 +368,28 @@ public class SubjectServiceImpl extends BaseServiceImpl<Long, Subject> implement
         return pageInfo;
     }
 
+    @Override
+    public List<SubjectWrapper.Subject> list(SubjectWrapper.SubjectQuery query) {
+        query.setPage(1);
+        query.setRows(9999);
+        Map<String, Object> params = new HashMap<>();
+        MapUtil.populateMap(params, query);
+        List<SubjectWrapper.Subject> records = subjectDao.findPage(params);
+        String instrumentIds = query.getInstrumentIds();
+        List<Long> instrumentIdList = new ArrayList<>();
+        if (StringUtils.isNotEmpty(instrumentIds)) {
+            List<Long> collect = Arrays.stream(instrumentIds.split(",")).map(Long::valueOf).distinct().collect(Collectors.toList());
+            instrumentIdList.addAll(collect);
+        }
+        if (!instrumentIdList.isEmpty()) {
+            records.forEach(record -> {
+                List<InstrumentWrapper.Instrument> instruments = record.getInstruments();
+                instruments.removeIf(next -> !instrumentIdList.contains(next.getId()));
+            });
+        }
+        return records;
+    }
+
     /***
      * 查询声部树
      * @param: sub

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/SubjectWrapper.java

@@ -39,6 +39,9 @@ public class SubjectWrapper {
         @ApiModelProperty("声部ID")
         private Integer subjectId;
 
+        @ApiModelProperty("父级声部ID")
+        private Integer parentSubjectId;
+
         @ApiModelProperty("多个声部ID")
         private String subjectIds;
 

+ 16 - 2
cooleshow-user/user-biz/src/main/resources/config/mybatis/SubjectMapper.xml

@@ -241,7 +241,12 @@
         FROM subject t
         LEFT JOIN instrument i on t.id_ = i.subject_id_
         <where>
-            t.parent_subject_id_ != 0
+            <if test="parentSubjectId != null">
+                AND t.parent_subject_id_ == #{parentSubjectId}
+            </if>
+            <if test="parentSubjectId == null">
+                AND t.parent_subject_id_ != 0
+            </if>
             <if test="delFlag != null">
                 AND t.del_flag_ = #{delFlag}
             </if>
@@ -290,7 +295,12 @@
         FROM subject t
         LEFT JOIN instrument i on t.id_ = i.subject_id_
         <where>
-            t.parent_subject_id_ != 0
+            <if test="parentSubjectId != null">
+                AND t.parent_subject_id_ == #{parentSubjectId}
+            </if>
+            <if test="parentSubjectId == null">
+                AND t.parent_subject_id_ != 0
+            </if>
             <if test="delFlag != null">
                 AND t.del_flag_ = #{delFlag}
             </if>
@@ -316,6 +326,10 @@
                 having count(i.id_) = 0
             </if>
         </if>
+        <include refid="global.limit"/>
+    </select>
+    <select id="notInSubjectIds" resultMap="Subject">
+        SELECT * FROM subject WHERE del_flag_ = 0 and id_ != #{subjectId}
     </select>
 
     <update id="updateCbsSubjectIdNull">