Переглянути джерело

courseware support audioImg resource

guozhaoshun 6 роки тому
батько
коміт
0eea46bf57

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

@@ -142,14 +142,12 @@ 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<>();
@@ -157,21 +155,8 @@ 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);
@@ -179,18 +164,4 @@ public class WareServiceProxy {
         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;
-    }
 }

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

@@ -91,7 +91,7 @@ public class ResourceController {
 
                     //有声读物   转  资源
                     audioImgList.forEach(ai -> {
-                        Resource resource = audioImgToResource(ai);
+                        Resource resource = resourceService.audioImgToResource(ai);
                         resourceList.add(resource);
                     });
                     page.setList(resourceList);
@@ -224,7 +224,7 @@ public class ResourceController {
         }
 
         audioImgs.forEach(ai -> {
-            Resource resource = audioImgToResource(ai);
+            Resource resource = resourceService.audioImgToResource(ai);
             audioImgMap.put(ai.getId(),resource);
 
         });
@@ -237,7 +237,7 @@ public class ResourceController {
      * @param ai
      * @return
      */
-    private Resource audioImgToResource(AudioImg ai) {
+    /*private Resource audioImgToResource(AudioImg ai) {
         String audioId = ai.getAudioId();
         Resource audio = resourceService.get(audioId);
         resourceService.initResourceUrl(audio);
@@ -260,7 +260,7 @@ public class ResourceController {
         //音频info
         resource.setAudio(audio);
         return resource;
-    }
+    }*/
 
     private Resource toAudioResource(AudioImgDTO dto) {
         Resource audio = new Resource();

+ 48 - 28
rankin-resource-service/src/main/java/cn/rankin/resourceservice/service/ResourceService.java

@@ -9,11 +9,13 @@ import cn.rankin.common.utils.enums.BaseOrderEnum;
 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.dto.ResourceRemote;
 import cn.rankin.resourceservice.dto.ResourceVideo;
 import cn.rankin.resourceservice.proxy.RemoteResourceProxy;
+import cn.rankin.resourceservice.repository.AudioImgRepository;
 import cn.rankin.resourceservice.repository.ResourceRepository;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -30,6 +32,9 @@ import java.util.*;
 public class ResourceService {
 
     @Autowired
+    private AudioImgRepository audioImgRepository;
+
+    @Autowired
     private ResourceRepository resourceRepository;
 
     @Autowired
@@ -85,6 +90,19 @@ public class ResourceService {
             resourceMap.put(resource.getId(), resource);
         });
 
+        // 本地基础资源取够了不取了
+        if (nativeResourceList.size() == ids.size() && nativeResourceList.size() > 0) {
+            return APIResult.ok(resourceMap);
+        }
+
+        // 取本地,有声读物资源
+        List<AudioImg> audioImgList = audioImgRepository.findByIds(ids);
+        audioImgList.forEach(ai -> {
+            Resource resource = audioImgToResource(ai);
+            resourceMap.put(resource.getId(), resource);
+        });
+
+
         // 本地取够了不取了
         if (nativeResourceList.size() == ids.size() && nativeResourceList.size() > 0) {
             return APIResult.ok(resourceMap);
@@ -253,32 +271,6 @@ public class ResourceService {
      */
     public APIResult<Resource> saveRemoteResource(Resource resource) {
 
-/*        List<Map<String, Object>> videos = new ArrayList<>();
-        Map<String, Object> video = new HashMap<>();
-        video.put("bucket","efunbox");
-        video.put("path",resource.getPath());
-        video.put("format",resource.getFormat());
-        video.put("quality",resource.getQuality());
-        video.put("size",resource.getSize());
-
-        videos.add(video);
-
-
-        APIResult<ResourceDetail> apiResult = resourceProxy.saveResources(new HashMap<String, Object>(){
-            {
-                this.put("no", resource.getCode());
-                this.put("title", resource.getName());
-                this.put("type", resource.getType());
-                this.put("videos", videos);
-            }
-        });
-
-
-
-
-
-        */
-
         Set<ResourceVideo> videos = new HashSet<>();
         ResourceVideo video = new ResourceVideo();
         video.setBucket("efunbox");
@@ -296,8 +288,6 @@ public class ResourceService {
         resourceRemote.setVideos(videos);
 
 
-
-
         APIResult<ResourceDetail> apiResult = resourceProxy.saveResources(resourceRemote);
         if (!apiResult.getSuccess()) {
             return errorResourceAPIResult(apiResult);
@@ -353,5 +343,35 @@ public class ResourceService {
         return errResult;
     }
 
+    /**
+     * 有声读物 转  资源
+     * @param ai
+     * @return
+     */
+    public Resource audioImgToResource(AudioImg ai) {
+        String audioId = ai.getAudioId();
+        Resource audio = resourceRepository.find(audioId);
+        initResourceUrl(audio);
+        String imgId = ai.getImgId();
+        Resource img = resourceRepository.find(imgId);
+        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;
+    }
+
 }