Jelajahi Sumber

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

zouxuan 1 tahun lalu
induk
melakukan
0511811ac4

+ 1 - 9
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/SubjectController.java

@@ -2,9 +2,7 @@ package com.yonge.cooleshow.admin.controller;
 
 import com.dayaedu.cbs.openfeign.client.MusicFeignClientService;
 import com.dayaedu.cbs.openfeign.wrapper.music.CbsSubjectWrapper;
-import com.microsvc.toolkit.common.response.template.R;
 import com.microsvc.toolkit.common.webportal.exception.BizException;
-import com.microsvc.toolkit.config.jwt.utils.JwtUserInfo;
 import com.yonge.cooleshow.biz.dal.dto.PageUtil;
 import com.yonge.cooleshow.biz.dal.entity.Subject;
 import com.yonge.cooleshow.biz.dal.queryInfo.SubjectQueryInfo;
@@ -21,13 +19,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import springfox.documentation.annotations.ApiIgnore;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 import java.util.Map;

+ 25 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/InstrumentDao.java

@@ -0,0 +1,25 @@
+package com.yonge.cooleshow.biz.dal.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.yonge.cooleshow.biz.dal.entity.Instrument;
+import com.yonge.cooleshow.biz.dal.wrapper.InstrumentWrapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 乐器设置
+ * 2024-04-22 16:55:18
+ */
+public interface InstrumentDao extends BaseMapper<Instrument> {
+
+	/**
+	 * 分页查询
+	 * @param page IPage<InstrumentWrapper.Instrument>
+	 * @param param InstrumentWrapper.InstrumentQuery
+	 * @return List<InstrumentWrapper.Instrument>
+	 */
+	List<InstrumentWrapper.Instrument> selectPage(@Param("page") IPage<InstrumentWrapper.Instrument> page, @Param("param") InstrumentWrapper.InstrumentQuery param);
+
+}

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

@@ -0,0 +1,195 @@
+package com.yonge.cooleshow.biz.dal.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.dayaedu.cbs.openfeign.client.MusicFeignClientService;
+import com.dayaedu.cbs.openfeign.wrapper.musicInstrument.CbsMusicalInstrumentWrapper;
+import com.microsvc.toolkit.common.webportal.exception.BizException;
+import com.yonge.cooleshow.biz.dal.dao.InstrumentDao;
+import com.yonge.cooleshow.biz.dal.entity.Instrument;
+import com.yonge.cooleshow.biz.dal.service.InstrumentService;
+import com.yonge.cooleshow.biz.dal.wrapper.InstrumentWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * 乐器设置
+ * 2024-04-22 16:55:18
+ */
+@Slf4j
+@Service
+public class InstrumentServiceImpl extends ServiceImpl<InstrumentDao, Instrument> implements InstrumentService {
+
+    @Autowired
+    private MusicFeignClientService musicFeignClientService;
+
+    /**
+     * 查询详情
+     *
+     * @param id 详情ID
+     * @return Instrument
+     */
+    @Override
+    public Instrument detail(Long id) {
+
+        return baseMapper.selectById(id);
+    }
+
+    /**
+     * 分页查询
+     *
+     * @param page  IPage<Instrument>
+     * @param query InstrumentWrapper.InstrumentQuery
+     * @return IPage<Instrument>
+     */
+    @Override
+    public IPage<InstrumentWrapper.Instrument> selectPage(IPage<InstrumentWrapper.Instrument> page, InstrumentWrapper.InstrumentQuery query) {
+
+        IPage<InstrumentWrapper.Instrument> instrumentIPage = page.setRecords(baseMapper.selectPage(page, query));
+        List<InstrumentWrapper.Instrument> records = instrumentIPage.getRecords();
+        if (CollectionUtils.isEmpty(records)) {
+            return instrumentIPage;
+        }
+        List<InstrumentWrapper.Instrument> instruments = getInstruments(records.stream().map(InstrumentWrapper.Instrument::getId).distinct().collect(Collectors.toList()));
+        return instrumentIPage.setRecords(instruments);
+    }
+
+    /**
+     * 添加
+     *
+     * @param instrument InstrumentWrapper.Instrument
+     * @return Boolean
+     */
+    @Override
+    public Boolean add(InstrumentWrapper.Instrument instrument) {
+
+        return this.save(JSON.parseObject(instrument.jsonString(), Instrument.class));
+    }
+
+    /**
+     * 更新
+     *
+     * @param instrument InstrumentWrapper.Instrument
+     * @return Boolean
+     */
+    @Override
+    public Boolean update(InstrumentWrapper.Instrument instrument) {
+
+        return this.updateById(JSON.parseObject(instrument.jsonString(), Instrument.class));
+    }
+
+    @Override
+    public List<Instrument> queryBySubjectId(Long subject) {
+        if (subject == null) {
+            return new ArrayList<>();
+        }
+        return this.lambdaQuery()
+            .eq(Instrument::getSubjectId, subject)
+            .list();
+    }
+
+    @Override
+    public Map<Long, InstrumentWrapper.Instrument> getMapByIds(List<Long> instrumentIdList) {
+        if (CollectionUtils.isEmpty(instrumentIdList)) {
+            return new HashMap<>();
+        }
+        instrumentIdList = instrumentIdList.stream().distinct().collect(Collectors.toList());
+        List<InstrumentWrapper.Instrument> instrumentList = getInstruments(instrumentIdList);
+        return instrumentList.stream().collect(Collectors.toMap(InstrumentWrapper.Instrument::getId, Function.identity()));
+    }
+
+    private List<InstrumentWrapper.Instrument> getInstruments(List<Long> instrumentIdList) {
+        instrumentIdList = instrumentIdList.stream().filter(Objects::nonNull).collect(Collectors.toList());
+        Map<Long, Instrument> idImstrumentMap = this.lambdaQuery().in(Instrument::getId, instrumentIdList).list()
+            .stream().collect(Collectors.toMap(Instrument::getId, Function.identity()));
+        // 去内容平台查询乐器名称
+        CbsMusicalInstrumentWrapper.MusicalInstrumentQuery build = CbsMusicalInstrumentWrapper.MusicalInstrumentQuery.builder()
+            .rows(-1)
+            .ids(instrumentIdList.stream().map(Long::intValue).distinct().collect(Collectors.toList()))
+            .build();
+        List<CbsMusicalInstrumentWrapper.MusicalInstrumentQueryDto> rows;
+        try {
+            rows = musicFeignClientService
+                .musicalInstrumentPage(build).feignData().getRows();
+        } catch (Exception e) {
+            throw new BizException("内容平台服务异常");
+        }
+        Map<Integer, CbsMusicalInstrumentWrapper.MusicalInstrumentQueryDto> idMap = rows.stream().collect(Collectors.toMap(CbsMusicalInstrumentWrapper.MusicalInstrumentQueryDto::getId,
+            Function.identity()));
+
+        List<InstrumentWrapper.Instrument> instrumentList = new ArrayList<>();
+        instrumentIdList.forEach(next -> {
+            CbsMusicalInstrumentWrapper.MusicalInstrumentQueryDto dto = idMap.get(next.intValue());
+            if (dto == null) {
+                return;
+            }
+            InstrumentWrapper.Instrument instrument = JSON.parseObject(JSON.toJSONString(dto), InstrumentWrapper.Instrument.class);
+            if (dto.getDefaultScore() != null) {
+                instrument.setDefaultScore(dto.getDefaultScore().name());
+            }
+            instrument.setId(next);
+
+            Instrument instrument1 = idImstrumentMap.getOrDefault(next, new Instrument());
+            instrument.setOrientation(instrument1.getOrientation());
+            instrument.setEnableFlag(instrument1.getEnableFlag());
+            instrument.setOperator(instrument1.getOperator());
+            instrument.setSubjectId(instrument1.getSubjectId());
+            instrumentList.add(instrument);
+        });
+        return instrumentList;
+    }
+
+    @Override
+    public Map<Integer, List<InstrumentWrapper.Instrument>> getGroupBySubjectId(List<Integer> subjectIds, Boolean enableFlag) {
+        if (CollectionUtils.isEmpty(subjectIds)) {
+            return new HashMap<>();
+        }
+        List<Instrument> list = this.lambdaQuery()
+            .in(Instrument::getSubjectId, subjectIds)
+            .eq(enableFlag != null, Instrument::getEnableFlag, enableFlag)
+            .list();
+        if (CollectionUtils.isEmpty(list)) {
+            return new HashMap<>();
+        }
+        // group
+        Map<Integer, List<Long>> idResult = list.stream()
+            .collect(Collectors.groupingBy(o->o.getSubjectId().intValue(), LinkedHashMap::new,Collectors.mapping(Instrument::getId, Collectors.toList())));
+
+        // id 集合
+        List<Long> instrumentIds = list.stream().map(Instrument::getId).collect(Collectors.toList());
+        Map<Long, InstrumentWrapper.Instrument> instrumentMap = getMapByIds(instrumentIds);
+        Map<Integer, List<InstrumentWrapper.Instrument>> result = new HashMap<>();
+        idResult.forEach((k,v)->{
+            List<InstrumentWrapper.Instrument> instruments = v.stream().map(instrumentMap::get).collect(Collectors.toList());
+            result.put(k, instruments);
+        });
+        return result;
+
+    }
+
+    @Override
+    public List<InstrumentWrapper.Instrument> getList(InstrumentWrapper.InstrumentQuery query) {
+
+        IPage<InstrumentWrapper.Instrument> instrumentIPage = this.selectPage(new Page<>(1, -1), query);
+        return instrumentIPage.getRecords();
+    }
+
+    @Override
+    public List<Long> getInstrumentIdsBySubjectId(Long subjectId) {
+        List<Instrument> list = this.lambdaQuery()
+            .eq(Instrument::getSubjectId, subjectId)
+            .list();
+        if (CollectionUtils.isEmpty(list)) {
+            return new ArrayList<>();
+        }
+        return list.stream().map(Instrument::getId).collect(Collectors.toList());
+    }
+}

+ 39 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/InstrumentMapper.xml

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE  mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.yonge.cooleshow.biz.dal.dao.InstrumentDao">
+
+
+
+    <!-- 表字段 -->
+    <sql id="baseColumns">
+         t.id_ AS id
+        , t.subject_id_ AS subjectId
+        , t.orientation_ AS orientation
+        , t.del_flag_ AS delFlag
+        , t.enable_flag_ AS enableFlag
+        , t.create_time_ AS createTime
+        , t.update_time_ AS updateTime
+        , t.operator_ AS operator
+        </sql>
+
+    <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.wrapper.InstrumentWrapper$Instrument">
+		SELECT
+        	<include refid="baseColumns" />
+		FROM instrument t
+        <where>
+            <if test="param.subjectId != null">
+                AND t.subject_id_ = #{param.subjectId}
+            </if>
+            <if test="param.subjectIds != null and param.subjectIds.size() != 0">
+                AND t.subject_id_ in
+                <foreach collection="param.subjectIds" item="item" separator="," open="(" close=")">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="param.enableFlag != null">
+                AND t.enable_flag_ = #{param.enableFlag}
+            </if>
+        </where>
+	</select>
+
+</mapper>