|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|