Browse Source

add support video create/update

guozhaoshun 6 years ago
parent
commit
947203e499

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

@@ -88,7 +88,13 @@ public class ResourceController {
 
     @RequestMapping(value="/{id}", method = RequestMethod.PUT)
     public APIResult<Resource> update(@PathVariable("id") String id, @RequestBody Resource resource) {
-        resourceService.update(resource);
+        if(resource.getType().intValue() == ResourceType.VIDEO){
+            //视频类型   存远程资源库
+            return  resourceService.updateRemoteResource(resource);
+        }else{
+            resourceService.update(resource);
+        }
+
         return APIResult.ok();
     }
 }

+ 6 - 0
rankin-resource-service/src/main/java/cn/rankin/resourceservice/proxy/RemoteResourceProxy.java

@@ -22,6 +22,9 @@ public interface RemoteResourceProxy {
     @RequestMapping(value = "rcenter/v1/resources/no/{code}", method = RequestMethod.GET)
     APIResult<ResourceRemote> findByCode(@PathVariable("code") String code);
 
+    @RequestMapping(value = "rcenter/v1/resources/{id}", method = RequestMethod.GET)
+    APIResult<ResourceRemote> findById(@PathVariable("id") String id);
+
 //    @RequestMapping(value = "rcenter/v1/resources", method = RequestMethod.GET)
 //    APIResult<List<ResourceRemote>> getBatch(@RequestParam("ids") List<String> ids);
 
@@ -31,4 +34,7 @@ public interface RemoteResourceProxy {
     @RequestMapping(value = "/rcenter/v1/resources/mgt", method = RequestMethod.POST)
     APIResult<ResourceDetail> saveResources(@RequestParam Map<String, Object> map);
 
+    @RequestMapping(value = "/rcenter/v1/resources/mgt", method = RequestMethod.PUT)
+    APIResult<ResourceDetail> updateResources(@RequestParam Map<String, Object> map);
+
 }

+ 51 - 3
rankin-resource-service/src/main/java/cn/rankin/resourceservice/service/ResourceService.java

@@ -236,7 +236,8 @@ public class ResourceService {
     }
 
     /**
-     * upload  ViDEO
+     * saveRemoteResource
+     * type 0 video , 1 audio
      * @param resource
      * @return
      */
@@ -268,8 +269,55 @@ public class ResourceService {
             return errResult;
         }
 
-        Resource result = apiResult.getData().toNativeResource();
-        return APIResult.ok(result);
+        Resource resourceVO = apiResult.getData().toNativeResource();
+        return APIResult.ok(resourceVO);
+    }
+
+    /**
+     * update  RemoteResource
+     * @param resource
+     * @return
+     */
+    public APIResult<Resource> updateRemoteResource(Resource resource) {
+
+        APIResult<ResourceRemote> result = resourceProxy.findById(resource.getId());
+        if (!result.getSuccess()) {
+            log.error("Remote Server Error: code={}, message={}", result.getCode(), result.getMessage());
+            APIResult errResult = APIResult.error(APICode.REMOTE_SERVER_ERROR);
+            result.setMessage(result.getMessage());
+            return errResult;
+        }
+
+
+        List<Map<String, Object>> videos = new ArrayList<>();
+        Map<String, Object> video = new HashMap<>();
+        video.put("bucket","");
+        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.updateResources(new HashMap<String, Object>(){
+            {
+                this.put("id", resource.getId());
+                this.put("no", resource.getCode());
+                this.put("title", resource.getName());
+                this.put("type", "1");
+                this.put("videos", videos);
+            }
+        });
+
+        if (!apiResult.getSuccess()) {
+            log.error("Remote Server Error: code={}, message={}", apiResult.getCode(), apiResult.getMessage());
+            APIResult errResult = APIResult.error(APICode.REMOTE_SERVER_ERROR);
+            apiResult.setMessage(apiResult.getMessage());
+            return errResult;
+        }
+
+        Resource resourceVO = apiResult.getData().toNativeResource();
+        return APIResult.ok(resourceVO);
     }
 
 }