소스 검색

courseware support audioImg resource

guozhaoshun 6 년 전
부모
커밋
81538f7bf4

+ 33 - 1
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/product/proxy/WareServiceProxy.java

@@ -142,12 +142,14 @@ public class WareServiceProxy {
         if (courseWare == null || courseWare.getResourceList() == null) {
             return courseWareVo;
         }
-
+        //资源ID集合,可能包含基础资源和有声读物(可以看做特殊资源)
         List<String> resourceIdList = courseWare.getResourceList();
+        List<String> audioImgIdList = new ArrayList<>();
         if (CollectionUtils.isEmpty(resourceIdList)) {
             return courseWareVo;
         }
 
+        //查询基础资源
         Map<String, ResourceVo> resourceVoMap = getResourceMap(resourceIdList);
 
         List<ResourceVo> resourceVoList = new ArrayList<>();
@@ -155,10 +157,40 @@ public class WareServiceProxy {
             ResourceVo resourceVo = resourceVoMap.get(resourceId);
             if (resourceVo != null) {
                 resourceVoList.add(resourceVo);
+            }else{
+                //根据id没有找到基础资源,放入有声读物id集合,尝试查找有声读物
+                audioImgIdList.add(resourceId);
             }
         }
+
+        if (CollectionUtils.isEmpty(audioImgIdList)) {
+            //查询有声读物
+            Map<String, ResourceVo> audioImgMap = getAudioImgMap(audioImgIdList);
+            for (String resourceId : audioImgIdList) {
+                ResourceVo resourceVo = audioImgMap.get(resourceId);
+                if (resourceVo != null) {
+                    resourceVoList.add(resourceVo);
+                }
+            }
+        }
+
         courseWareVo.setResourceList(resourceVoList);
 
         return courseWareVo;
     }
+
+    public Map<String, ResourceVo> getAudioImgMap(List<String> idList) {
+        Map<String, ResourceVo> resourceVoMap = new HashMap<>();
+        if (CollectionUtils.isEmpty(idList)) {
+            return resourceVoMap;
+        }
+
+        Map<String, ResourceVo> data = resourceService.getAudioImgBatch(idList);
+        if (data == null) {
+            log.warn("get AudioImg map empty");
+            return resourceVoMap;
+        }
+
+        return data;
+    }
 }

+ 3 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/resource/ResourceService.java

@@ -37,5 +37,8 @@ public interface ResourceService {
 
     @RequestMapping(value = "/resource/audioImg", method = RequestMethod.PUT)
     AudioImg updateAudioImg(@RequestBody AudioImgDTO dto);
+
+    @RequestMapping(value = "/resource/audioImg/batch", method = RequestMethod.GET)
+    Map<String, ResourceVo> getAudioImgBatch(@RequestParam("ids") List<String> ids);
 }
 

+ 51 - 22
rankin-resource-service/src/main/java/cn/rankin/resourceservice/controller/ResourceController.java

@@ -20,6 +20,7 @@ import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -90,28 +91,7 @@ public class ResourceController {
 
                     //有声读物   转  资源
                     audioImgList.forEach(ai -> {
-                        String audioId = ai.getAudioId();
-                        Resource audio = resourceService.get(audioId);
-                        resourceService.initResourceUrl(audio);
-                        String imgId = ai.getImgId();
-                        Resource img = resourceService.get(imgId);
-                        resourceService.initResourceUrl(img);
-
-                        Resource resource = new Resource();
-                        //有声读物info
-                        resource.setType(ai.getType());
-                        resource.setId(ai.getId());
-                        resource.setCode(ai.getCode());
-                        resource.setName(ai.getName());
-                        resource.setStatus(ai.getStatus());
-                        resource.setGmtCreated(ai.getGmtCreated());
-                        resource.setGmtModified(ai.getGmtModified());
-
-                        //图片info
-                        resource.setImg(img);
-                        //音频info
-                        resource.setAudio(audio);
-
+                        Resource resource = audioImgToResource(ai);
                         resourceList.add(resource);
                     });
                     page.setList(resourceList);
@@ -129,6 +109,8 @@ public class ResourceController {
         }
     }
 
+
+
     @RequestMapping(method = RequestMethod.POST)
     public APIResult<Resource> create(@RequestBody Resource resource) {
 
@@ -233,6 +215,53 @@ public class ResourceController {
         }
     }
 
+    @RequestMapping(value = "/audioImg/batch", method = RequestMethod.GET)
+    public Map<String, Resource> getAudioImgBatch(@RequestParam("ids") List<String> ids) {
+        Map<String, Resource> audioImgMap= new HashMap<>();
+        List<AudioImg> audioImgs = audioImgService.findMixByIds(ids);
+        if(CollectionUtils.isEmpty(audioImgs)){
+            return audioImgMap;
+        }
+
+        audioImgs.forEach(ai -> {
+            Resource resource = audioImgToResource(ai);
+            audioImgMap.put(ai.getId(),resource);
+
+        });
+
+        return audioImgMap;
+    }
+
+    /**
+     * 有声读物 转  资源
+     * @param ai
+     * @return
+     */
+    private Resource audioImgToResource(AudioImg ai) {
+        String audioId = ai.getAudioId();
+        Resource audio = resourceService.get(audioId);
+        resourceService.initResourceUrl(audio);
+        String imgId = ai.getImgId();
+        Resource img = resourceService.get(imgId);
+        resourceService.initResourceUrl(img);
+
+        Resource resource = new Resource();
+        //有声读物info
+        resource.setType(ai.getType());
+        resource.setId(ai.getId());
+        resource.setCode(ai.getCode());
+        resource.setName(ai.getName());
+        resource.setStatus(ai.getStatus());
+        resource.setGmtCreated(ai.getGmtCreated());
+        resource.setGmtModified(ai.getGmtModified());
+
+        //图片info
+        resource.setImg(img);
+        //音频info
+        resource.setAudio(audio);
+        return resource;
+    }
+
     private Resource toAudioResource(AudioImgDTO dto) {
         Resource audio = new Resource();
         audio.setCode(dto.getCode()+"_"+ResourceType.AUDIO+DateUtil.getTimeStamp());

+ 9 - 0
rankin-resource-service/src/main/java/cn/rankin/resourceservice/service/AudioImgService.java

@@ -1,10 +1,13 @@
 package cn.rankin.resourceservice.service;
 
+import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.common.utils.exception.DuplicateValueException;
 import cn.rankin.common.utils.exception.NotFoundException;
 import cn.rankin.common.utils.exception.UnsupportedOperationException;
 import cn.rankin.data.api.resource.entity.AudioImg;
+import cn.rankin.data.api.resource.entity.Resource;
+import cn.rankin.resourceservice.dto.ResourceDetail;
 import cn.rankin.resourceservice.repository.AudioImgRepository;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -64,5 +67,11 @@ public class AudioImgService {
         return result;
     }
 
+    public List<AudioImg>  findMixByIds(List<String> ids) {
+
+        // 取本地
+        List<AudioImg> audioImgs = audioImgRepository.findByIds(ids);
+        return audioImgs;
+    }
 }