ソースを参照

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

zouxuan 1 年間 前
コミット
ba6119c567

+ 52 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/MusicalInstrumentController.java

@@ -0,0 +1,52 @@
+package com.yonge.cooleshow.admin.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.microsvc.toolkit.common.response.template.R;
+import com.yonge.cooleshow.biz.dal.service.InstrumentService;
+import com.yonge.cooleshow.biz.dal.service.SysUserService;
+import com.yonge.cooleshow.biz.dal.wrapper.InstrumentWrapper;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+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 javax.annotation.Resource;
+import java.util.List;
+
+@Slf4j
+@Validated
+@RestController
+@RequestMapping("/musicalInstrument")
+@Api(tags = "曲目乐器")
+public class MusicalInstrumentController {
+
+    @Resource
+    private InstrumentService instrumentService;
+    @Resource
+    private SysUserService sysUserService;
+
+
+    @ApiOperation(value = "修改乐器")
+    @PreAuthorize("@pcs.hasPermissions('musicalInstrument/update', {'BACKEND'})")
+    @PostMapping("/update")
+    public R<JSONObject> update(@RequestBody @Validated InstrumentWrapper.Update update) {
+        update.setOperator(sysUserService.getUserId());
+        instrumentService.modify(update);
+        return R.defaultR();
+
+    }
+
+    @ApiOperation(value = "乐器列表")
+    @PreAuthorize("@pcs.hasPermissions('musicalInstrument/list', {'BACKEND'})")
+    @PostMapping("/list")
+    public R<List<InstrumentWrapper.Instrument>> list(@RequestBody InstrumentWrapper.InstrumentQuery query) {
+        List<InstrumentWrapper.Instrument> instruments = instrumentService.getList(query);
+        return R.from(instruments);
+	}
+
+}

+ 2 - 43
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/SubjectController.java

@@ -16,15 +16,10 @@ 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.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
 @RequestMapping("${app-config.url.admin:}/subject")
 @Api(tags = "声部服务")
 @RestController
@@ -50,46 +45,10 @@ public class SubjectController extends BaseController {
 	@ApiOperation(value = "分页查询声部列表")
 	@GetMapping("/queryPage")
 	@PreAuthorize("@pcs.hasPermissions('subject/queryPage')")
-	public HttpResponseResult<PageInfo<Subject>> queryPage(SubjectQueryInfo queryInfo) {
-		PageInfo<Subject> pageInfo = subjectService.queryPage(queryInfo);
-
-        List<Subject> records = pageInfo.getRows();
-        if(records.isEmpty()){
-			return succeed(pageInfo);
-		}
-
-		Map<Long, Subject> map = subjectService.findBySubjectByIdList(records.stream().map(Subject::getParentSubjectId).collect(Collectors.toList())).stream()
-				.collect(Collectors.toMap(Subject::getId, t -> t));
-
-		records.forEach(row -> {
-			if(row.getParentSubjectId() != null && row.getParentSubjectId() > 0) {
-				row.setParentSubjectName(map.get(row.getParentSubjectId()).getName());
-			}
-		});
-
-        setCbsSubjectName(records);
-		return succeed(pageInfo);
+	public HttpResponseResult<PageInfo<SubjectWrapper.Subject>> queryPage(@RequestBody SubjectWrapper.SubjectQuery query) {
+		return succeed(subjectService.selectPage(query));
 	}
 
-
-    private void setCbsSubjectName(List<Subject> records) {
-        // cbs声部ID集合
-        List<Long> cbsSubjectIds = records.stream().map(Subject::getCbsSubjectId).collect(Collectors.toList());
-        CbsSubjectWrapper.SubjectQuery subjectQuery = new CbsSubjectWrapper.SubjectQuery();
-        subjectQuery.setIds(cbsSubjectIds);
-        subjectQuery.setPage(1);
-        subjectQuery.setRows(-1);
-        try {
-            List<CbsSubjectWrapper.Subject> rows = musicFeignClientService.subjectPage(subjectQuery).feignData().getRows();
-            if (CollectionUtils.isNotEmpty(rows)) {
-                Map<Long, String> cbsSubjectMap = rows.stream().collect(Collectors.toMap(CbsSubjectWrapper.Subject::getId, CbsSubjectWrapper.Subject::getName));
-                records.stream().forEach(e -> e.setCbsSubjectName(cbsSubjectMap.get(e.getCbsSubjectId())));
-            }
-        } catch (Exception e) {
-            log.error("调用音乐服务查询曲目详情失败", e);
-        }
-    }
-
 	@ApiOperation(value = "分页查询声部树状列表")
 	@GetMapping("/queryPageTree")
 	@PreAuthorize("@pcs.hasPermissions('subject/queryPageTree')")

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

@@ -2,10 +2,12 @@ package com.yonge.cooleshow.biz.dal.dao;
 
 import com.dayaedu.cbs.openfeign.wrapper.music.CbsSubjectApiWrapper;
 import com.yonge.cooleshow.biz.dal.entity.Subject;
+import com.yonge.cooleshow.biz.dal.wrapper.SubjectWrapper;
 import com.yonge.toolset.mybatis.dal.BaseDAO;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Map;
 
 public interface SubjectDao extends BaseDAO<Long, Subject> {
     /***
@@ -72,4 +74,8 @@ public interface SubjectDao extends BaseDAO<Long, Subject> {
     void updateCbsSubjectIdNull(@Param("subjectId") Long subjectId);
 
     List<Subject> getByCbsSubjectIds(String subjectIds);
+
+    int findCount(Map<String, Object> params);
+
+    List<SubjectWrapper.Subject> findPage(@Param("params") Map<String, Object> params);
 }

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

@@ -52,4 +52,6 @@ public interface InstrumentService extends IService<Instrument>  {
     List<InstrumentWrapper.Instrument> getList(InstrumentWrapper.InstrumentQuery query);
 
     List<Long> getInstrumentIdsBySubjectId(Long subjectId);
+
+    void modify(InstrumentWrapper.Update update);
 }

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

@@ -9,6 +9,7 @@ import com.yonge.cooleshow.biz.dal.entity.Employee;
 import com.yonge.cooleshow.biz.dal.entity.Subject;
 import com.yonge.cooleshow.biz.dal.queryInfo.SubjectQueryInfo;
 import com.yonge.cooleshow.biz.dal.wrapper.SubjectWrapper;
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.toolset.base.page.PageInfo;
 import com.yonge.toolset.mybatis.service.BaseService;
 
@@ -65,4 +66,6 @@ public interface SubjectService extends BaseService<Long, Subject> {
     void add(SubjectWrapper.AddSubject add);
 
 	Boolean enable(Subject subject);
+
+	PageInfo<SubjectWrapper.Subject> selectPage(SubjectWrapper.SubjectQuery query);
 }

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

@@ -9,13 +9,17 @@ import com.dayaedu.cbs.openfeign.wrapper.musicInstrument.CbsMusicalInstrumentWra
 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.entity.Subject;
 import com.yonge.cooleshow.biz.dal.service.InstrumentService;
+import com.yonge.cooleshow.biz.dal.service.SubjectService;
 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.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
+import javax.annotation.Resource;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -28,8 +32,10 @@ import java.util.stream.Collectors;
 @Service
 public class InstrumentServiceImpl extends ServiceImpl<InstrumentDao, Instrument> implements InstrumentService {
 
-    @Autowired
+    @Resource
     private MusicFeignClientService musicFeignClientService;
+    @Resource
+    private SubjectService subjectService;
 
     /**
      * 查询详情
@@ -192,4 +198,23 @@ public class InstrumentServiceImpl extends ServiceImpl<InstrumentDao, Instrument
         }
         return list.stream().map(Instrument::getId).collect(Collectors.toList());
     }
+
+    @Override
+    @Transactional
+    public void modify(InstrumentWrapper.Update update) {
+        Instrument instrument = JSON.parseObject(JSON.toJSONString(update), Instrument.class);
+
+        this.updateById(instrument);
+
+        if (update.getEnableFlag() != null && update.getEnableFlag()) {
+            // 启用声部
+            Instrument entity = this.getById(update.getId());
+            if (entity == null) {
+                return;
+            }
+            Subject subject = subjectService.get(entity.getSubjectId());
+            subject.setEnableFlag(true);
+            subjectService.getDao().update(subject);
+        }
+    }
 }

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

@@ -1,13 +1,16 @@
 package com.yonge.cooleshow.biz.dal.service.impl;
 
 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.yonge.cooleshow.biz.dal.dao.SubjectDao;
+import com.yonge.cooleshow.biz.dal.dao.TeacherDao;
 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.InstrumentWrapper;
 import com.yonge.cooleshow.biz.dal.wrapper.SubjectWrapper;
 import com.yonge.cooleshow.common.enums.CacheNameEnum;
 import com.yonge.toolset.base.exception.BizException;
@@ -15,6 +18,7 @@ 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 com.yonge.toolset.utils.collection.MapUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.redisson.api.RedissonClient;
 import org.slf4j.Logger;
@@ -26,6 +30,7 @@ import org.springframework.util.CollectionUtils;
 import javax.annotation.Resource;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 @Service
@@ -40,6 +45,8 @@ public class SubjectServiceImpl extends BaseServiceImpl<Long, Subject> implement
     private MusicFeignClientService musicFeignClientService;
     @Resource
     private InstrumentService instrumentService;
+    @Resource
+    private TeacherDao teacherDao;
 
     @Override
     public BaseDAO<Long, Subject> getDAO() {
@@ -296,6 +303,64 @@ public class SubjectServiceImpl extends BaseServiceImpl<Long, Subject> implement
         return true;
     }
 
+    @Override
+    public PageInfo<SubjectWrapper.Subject> selectPage(SubjectWrapper.SubjectQuery query) {
+        PageInfo<SubjectWrapper.Subject> pageInfo = new PageInfo<>(query.getPage(), query.getRows());
+        Map<String, Object> params = new HashMap<>();
+        MapUtil.populateMap(params, query);
+
+        List<SubjectWrapper.Subject> dataList = null;
+        int count = subjectDao.findCount(params);
+        if (count > 0) {
+            pageInfo.setTotal(count);
+            params.put("offset", pageInfo.getOffset());
+            dataList = subjectDao.findPage(params);
+            // 转map
+            Map<Long, SubjectWrapper.Subject> subjectMap = dataList.stream().collect(Collectors.toMap(SubjectWrapper.Subject::getCbsSubjectId, Function.identity(),(o1, o2)->o1));
+            // cbs声部ID集合
+            List<Long> cbsSubjectIds = dataList.stream().map(SubjectWrapper.Subject::getCbsSubjectId).collect(Collectors.toList());
+            dataList = new ArrayList<>();
+            CbsSubjectWrapper.SubjectQuery subjectQuery = new CbsSubjectWrapper.SubjectQuery();
+            subjectQuery.setIds(cbsSubjectIds);
+            subjectQuery.setName(query.getKeyword());
+            subjectQuery.setPage(query.getPage());
+            subjectQuery.setRows(query.getRows());
+            try {
+                com.microsvc.toolkit.common.response.paging.PageInfo<CbsSubjectWrapper.Subject> subjectPageInfo = musicFeignClientService.subjectPage(subjectQuery).feignData();
+                List<CbsSubjectWrapper.Subject> rows = subjectPageInfo.getRows();
+                if (org.apache.commons.collections.CollectionUtils.isNotEmpty(rows)) {
+                    for (CbsSubjectWrapper.Subject row : rows) {
+                        SubjectWrapper.Subject subject = subjectMap.get(row.getId());
+                        if (subject == null) {
+                            log.warn("未查询到声部信息,id:{}", row.getId());
+                            continue;
+                        }
+                        subject.setCbsSubjectName(row.getName());
+                        subject.setName(row.getName());
+                        subject.setCode(row.getCode());
+                        dataList.add(subject);
+                    }
+                }
+            } catch (Exception e) {
+                log.error("调用音乐服务查询曲目详情失败", e);
+            }
+            // 设置声部下的乐器信息
+            List<Integer> subjectIds = dataList.stream().map(SubjectWrapper.Subject::getId).distinct().collect(Collectors.toList());
+            Map<Integer, List<InstrumentWrapper.Instrument>> groupBySubjectId = instrumentService.getGroupBySubjectId(subjectIds, query.getEnableFlag());
+            dataList.forEach(e -> {
+                List<InstrumentWrapper.Instrument> instruments = groupBySubjectId.get(e.getId());
+                if (org.apache.commons.collections.CollectionUtils.isNotEmpty(instruments)) {
+                    e.setInstruments(instruments);
+                }
+            });
+        }
+        if (count == 0) {
+            dataList = new ArrayList<>();
+        }
+        pageInfo.setRows(dataList);
+        return pageInfo;
+    }
+
     /***
      * 查询声部树
      * @param: sub

+ 81 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/SubjectMapper.xml

@@ -235,6 +235,87 @@
     <select id="getByCbsSubjectIds" resultMap="Subject">
         select * from subject where find_in_set(cbs_subject_id_,#{subjectIds})
     </select>
+    <select id="findCount" resultType="java.lang.Integer">
+        select count(DISTINCT t.id_) from
+        (SELECT t.id_
+        FROM subject t
+        LEFT JOIN instrument i on t.id_ = i.subject_id_
+        <where>
+            <if test="param.delFlag != null">
+                AND t.del_flag_ = #{param.delFlag}
+            </if>
+            <if test="param.subjectId != null">
+                AND t.id_ = #{param.subjectId}
+            </if>
+            <if test="param.subjectIds != null">
+                AND find_in_set(t.id_,#{param.subjectIds})
+            </if>
+            <if test="param.instrumentIds != null">
+                AND find_in_set(i.id_, #{param.instrumentIds})
+            </if>
+            <if test="param.enableFlag != null">
+                AND t.enable_flag_ = #{param.enableFlag} and i.enable_flag_ = #{param.enableFlag}
+            </if>
+        </where>
+        group by t.id_
+        <if test="param.hasInstrument != null">
+            <if test="param.hasInstrument == true">
+                having count(i.id_) > 0
+            </if>
+            <if test="param.hasInstrument == false">
+                having count(i.id_) = 0
+            </if>
+        </if>) t
+    </select>
+    <sql id="baseColumns">
+        t.id_ as id
+        , t.name_ as name
+        , t.code_ as code
+        , t.parent_subject_id_ as parentId
+        , t.img_ as img
+        , t.del_flag_ as delFlag
+        , t.update_time_ as updateTime
+        , t.create_time_ as createTime
+        , t.enable_flag_ as enableFlag
+        ,t.orientation_ as orientation
+        ,t.enable_flag_ as enableFlag
+        ,t.logo_ as logo
+        ,t.media_ as media
+        ,t.operator_ as operator
+        ,t.cbs_subject_id_ as cbsSubjectId
+    </sql>
+    <select id="findPage" resultType="com.yonge.cooleshow.biz.dal.wrapper.SubjectWrapper$Subject">
+        SELECT
+        <include refid="baseColumns" />
+        FROM subject t
+        LEFT JOIN instrument i on t.id_ = i.subject_id_
+        <where>
+            <if test="param.delFlag != null">
+                AND t.del_flag_ = #{param.delFlag}
+            </if>
+            <if test="param.subjectId != null">
+                AND t.id_ = #{param.subjectId}
+            </if>
+            <if test="param.subjectIds != null">
+                AND find_in_set(t.id_,#{param.subjectIds})
+            </if>
+            <if test="param.instrumentIds != null">
+                AND find_in_set(i.id_, #{param.instrumentIds})
+            </if>
+            <if test="param.enableFlag != null">
+                AND t.enable_flag_ = #{param.enableFlag} and i.enable_flag_ = #{param.enableFlag}
+            </if>
+        </where>
+        group by t.id_
+        <if test="param.hasInstrument != null">
+            <if test="param.hasInstrument == true">
+                having count(i.id_) > 0
+            </if>
+            <if test="param.hasInstrument == false">
+                having count(i.id_) = 0
+            </if>
+        </if>
+    </select>
 
     <update id="updateCbsSubjectIdNull">
         update subject set cbs_subject_id_ = null where id_ = #{subjectId}