|
@@ -9,11 +9,13 @@ import cn.rankin.common.utils.enums.BaseOrderEnum;
|
|
import cn.rankin.common.utils.exception.DuplicateValueException;
|
|
import cn.rankin.common.utils.exception.DuplicateValueException;
|
|
import cn.rankin.common.utils.exception.NotFoundException;
|
|
import cn.rankin.common.utils.exception.NotFoundException;
|
|
import cn.rankin.common.utils.exception.UnsupportedOperationException;
|
|
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.data.api.resource.entity.Resource;
|
|
import cn.rankin.resourceservice.dto.ResourceDetail;
|
|
import cn.rankin.resourceservice.dto.ResourceDetail;
|
|
import cn.rankin.resourceservice.dto.ResourceRemote;
|
|
import cn.rankin.resourceservice.dto.ResourceRemote;
|
|
import cn.rankin.resourceservice.dto.ResourceVideo;
|
|
import cn.rankin.resourceservice.dto.ResourceVideo;
|
|
import cn.rankin.resourceservice.proxy.RemoteResourceProxy;
|
|
import cn.rankin.resourceservice.proxy.RemoteResourceProxy;
|
|
|
|
+import cn.rankin.resourceservice.repository.AudioImgRepository;
|
|
import cn.rankin.resourceservice.repository.ResourceRepository;
|
|
import cn.rankin.resourceservice.repository.ResourceRepository;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -30,6 +32,9 @@ import java.util.*;
|
|
public class ResourceService {
|
|
public class ResourceService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ private AudioImgRepository audioImgRepository;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
private ResourceRepository resourceRepository;
|
|
private ResourceRepository resourceRepository;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -38,6 +43,9 @@ public class ResourceService {
|
|
@Value("${resource.img.domain}")
|
|
@Value("${resource.img.domain}")
|
|
private String imgDomain;
|
|
private String imgDomain;
|
|
|
|
|
|
|
|
+ @Value("${resource.audio.domain}")
|
|
|
|
+ private String audioDomain;
|
|
|
|
+
|
|
@Value("${resource.video.domain}")
|
|
@Value("${resource.video.domain}")
|
|
private String videoDomain;
|
|
private String videoDomain;
|
|
|
|
|
|
@@ -46,6 +54,10 @@ public class ResourceService {
|
|
return count > 0L;
|
|
return count > 0L;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public Resource get(String id) {
|
|
|
|
+ return resourceRepository.find(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
public Resource save(Resource resource) {
|
|
public Resource save(Resource resource) {
|
|
return resourceRepository.save(resource);
|
|
return resourceRepository.save(resource);
|
|
}
|
|
}
|
|
@@ -78,6 +90,19 @@ public class ResourceService {
|
|
resourceMap.put(resource.getId(), resource);
|
|
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) {
|
|
if (nativeResourceList.size() == ids.size() && nativeResourceList.size() > 0) {
|
|
return APIResult.ok(resourceMap);
|
|
return APIResult.ok(resourceMap);
|
|
@@ -159,6 +184,8 @@ public class ResourceService {
|
|
String path = resource.getPath();
|
|
String path = resource.getPath();
|
|
if (ResourceType.VIDEO == resource.getType()) {
|
|
if (ResourceType.VIDEO == resource.getType()) {
|
|
resource.setUrl(concatUrl(videoDomain, path));
|
|
resource.setUrl(concatUrl(videoDomain, path));
|
|
|
|
+ }else if (ResourceType.AUDIO == resource.getType()) {
|
|
|
|
+ resource.setUrl(concatUrl(audioDomain, path));
|
|
}else if (ResourceType.IMG == resource.getType()) {
|
|
}else if (ResourceType.IMG == resource.getType()) {
|
|
resource.setUrl(concatUrl(imgDomain, path).replace(" ", ""));
|
|
resource.setUrl(concatUrl(imgDomain, path).replace(" ", ""));
|
|
}
|
|
}
|
|
@@ -183,14 +210,14 @@ public class ResourceService {
|
|
* @throws DuplicateValueException
|
|
* @throws DuplicateValueException
|
|
* @throws NotFoundException
|
|
* @throws NotFoundException
|
|
*/
|
|
*/
|
|
- public void update(Resource resource) throws DuplicateValueException, NotFoundException, UnsupportedOperationException {
|
|
|
|
|
|
+ public Resource update(Resource resource) throws DuplicateValueException, NotFoundException, UnsupportedOperationException {
|
|
if (null == resource){
|
|
if (null == resource){
|
|
log.error("Resource is null");
|
|
log.error("Resource is null");
|
|
- return;
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
- if (ResourceType.IMG == resource.getType()){
|
|
|
|
- updateImg(resource);
|
|
|
|
|
|
+ if (ResourceType.IMG == resource.getType() || ResourceType.AUDIO == resource.getType() ){
|
|
|
|
+ return updateResource(resource);
|
|
}
|
|
}
|
|
else{
|
|
else{
|
|
log.error("Not-Supported-Resource-Type, id={}, type={}", resource.getId(), resource.getType());
|
|
log.error("Not-Supported-Resource-Type, id={}, type={}", resource.getId(), resource.getType());
|
|
@@ -237,38 +264,50 @@ public class ResourceService {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * saveRemoteResource
|
|
|
|
- * type 0 video , 1 audio
|
|
|
|
|
|
+ * update Img,audio
|
|
* @param resource
|
|
* @param resource
|
|
- * @return
|
|
|
|
|
|
+ * @throws DuplicateValueException
|
|
|
|
+ * @throws NotFoundException
|
|
*/
|
|
*/
|
|
- public APIResult<Resource> saveRemoteResource(Resource resource) {
|
|
|
|
|
|
+ public Resource updateResource(Resource resource) throws DuplicateValueException, NotFoundException {
|
|
|
|
|
|
-/* 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());
|
|
|
|
|
|
+ if (ResourceType.IMG != resource.getType() && ResourceType.AUDIO!= resource.getType()){
|
|
|
|
+ log.error("Not-Img/audio -Resource");
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
|
|
- videos.add(video);
|
|
|
|
|
|
+ //find target resource
|
|
|
|
+ Resource targetResouce = resourceRepository.find(resource.getId());
|
|
|
|
|
|
|
|
+ if(null == targetResouce){
|
|
|
|
+ log.error("Cannot Find Resource, id={}", resource.getId());
|
|
|
|
+ throw new NotFoundException("Resource-Not-Found");
|
|
|
|
+ }
|
|
|
|
|
|
- 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);
|
|
|
|
|
|
+ //only support code,title,path
|
|
|
|
+ //first, make sure code is not duplicated
|
|
|
|
+ List<Resource> foundedResource = resourceRepository.findByCode(resource.getCode());
|
|
|
|
+ foundedResource.forEach( (each) -> {
|
|
|
|
+ if ( !resource.getId().equals(each.getId()) ){
|
|
|
|
+ log.error("Code-Already-Exist, code={}", resource.getCode());
|
|
|
|
+ throw new DuplicateValueException("Code-Already-Exist");
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ //set and save
|
|
|
|
+ targetResouce.setCode(resource.getCode());
|
|
|
|
+ targetResouce.setName(resource.getName());
|
|
|
|
+ targetResouce.setPath(resource.getPath());
|
|
|
|
+ return resourceRepository.save(targetResouce);
|
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- */
|
|
|
|
|
|
+ /**
|
|
|
|
+ * saveRemoteResource
|
|
|
|
+ * type 0 video , 1 audio
|
|
|
|
+ * @param resource
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public APIResult<Resource> saveRemoteResource(Resource resource) {
|
|
|
|
|
|
Set<ResourceVideo> videos = new HashSet<>();
|
|
Set<ResourceVideo> videos = new HashSet<>();
|
|
ResourceVideo video = new ResourceVideo();
|
|
ResourceVideo video = new ResourceVideo();
|
|
@@ -287,8 +326,6 @@ public class ResourceService {
|
|
resourceRemote.setVideos(videos);
|
|
resourceRemote.setVideos(videos);
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
APIResult<ResourceDetail> apiResult = resourceProxy.saveResources(resourceRemote);
|
|
APIResult<ResourceDetail> apiResult = resourceProxy.saveResources(resourceRemote);
|
|
if (!apiResult.getSuccess()) {
|
|
if (!apiResult.getSuccess()) {
|
|
return errorResourceAPIResult(apiResult);
|
|
return errorResourceAPIResult(apiResult);
|
|
@@ -344,5 +381,35 @@ public class ResourceService {
|
|
return errResult;
|
|
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;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|