Преглед изворни кода

Merge branch 'master' of http://gogs.efunbox.cn:3000/Rankin/rankin

xuchaolang пре 6 година
родитељ
комит
80337f7aee

+ 14 - 1
rankin-product-service/src/main/java/cn/rankin/productservice/service/TagService.java

@@ -193,6 +193,20 @@ public class TagService {
     @Transactional
     public void sortTag(String groupId, List<String> tagIdList) {
         List<Tag> tagList = tagRepository.findByGroupId(groupId);
+        sortTag(tagIdList, tagList);
+        tagRepository.update(tagList);
+    }
+
+
+
+    @Transactional
+    public void sortTagByTypeCode(String typeCode, List<String> tagIdList) {
+        List<Tag> tagList = tagRepository.findByTypeCode(typeCode);
+        sortTag(tagIdList, tagList);
+        tagRepository.update(tagList);
+    }
+
+    private void sortTag(List<String> tagIdList, List<Tag> tagList) {
         for (Tag tag : tagList) {
             String tagId = tag.getId();
             if (!tagIdList.contains(tagId)) {
@@ -202,6 +216,5 @@ public class TagService {
             Integer index = tagIdList.indexOf(tagId);
             tag.setSort(index);
         }
-        tagRepository.update(tagList);
     }
 }

+ 2 - 2
rankin-product-service/src/main/java/cn/rankin/productservice/service/TagTypeService.java

@@ -64,14 +64,14 @@ public class TagTypeService {
 
     @Transactional
     public TagType update(TagTypeDTO tagTypeDTO) {
-        String groupId = tagTypeDTO.getId();
+        String typeCode = tagTypeDTO.getCode();
         TagType tagType = convert(tagTypeDTO);
         // 更新标签组
         TagType result = tagTypeRepository.update(tagType);
         // 给组内的标签排序
         List<String> tagIdList = tagTypeDTO.getTagList();
         if (!CollectionUtils.isEmpty(tagIdList)) {
-            tagService.sortTag(groupId, tagIdList);
+            tagService.sortTagByTypeCode(typeCode, tagIdList);
         }
         return result;
     }

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

@@ -5,10 +5,7 @@ import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.resourceservice.dto.ResourceDetail;
 import cn.rankin.resourceservice.dto.ResourceRemote;
 import org.springframework.cloud.netflix.feign.FeignClient;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 import java.util.Map;
@@ -32,9 +29,9 @@ public interface RemoteResourceProxy {
     APIResult<List<ResourceDetail>> getBatch(@RequestParam("ids") List<String> ids);
 
     @RequestMapping(value = "/rcenter/v1/resources/mgt", method = RequestMethod.POST)
-    APIResult<ResourceDetail> saveResources(@RequestParam Map<String, Object> map);
+    APIResult<ResourceDetail> saveResources(@RequestBody ResourceRemote resourceRemote);
 
     @RequestMapping(value = "/rcenter/v1/resources/mgt", method = RequestMethod.PUT)
-    APIResult<ResourceDetail> updateResources(@RequestParam Map<String, Object> map);
+    APIResult<ResourceDetail> updateResources(@RequestBody ResourceRemote resourceRemote);
 
 }

+ 85 - 23
rankin-resource-service/src/main/java/cn/rankin/resourceservice/service/ResourceService.java

@@ -11,6 +11,7 @@ import cn.rankin.common.utils.exception.UnsupportedOperationException;
 import cn.rankin.resourceservice.dto.ResourceDetail;
 import cn.rankin.resourceservice.dto.ResourceRemote;
 import cn.rankin.data.api.resource.entity.Resource;
+import cn.rankin.resourceservice.dto.ResourceVideo;
 import cn.rankin.resourceservice.proxy.RemoteResourceProxy;
 import cn.rankin.resourceservice.repository.ResourceRepository;
 import lombok.extern.slf4j.Slf4j;
@@ -19,10 +20,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 
 @Slf4j
@@ -243,9 +241,9 @@ public class ResourceService {
      */
     public APIResult<Resource> saveRemoteResource(Resource resource) {
 
-        List<Map<String, Object>> videos = new ArrayList<>();
+/*        List<Map<String, Object>> videos = new ArrayList<>();
         Map<String, Object> video = new HashMap<>();
-        video.put("bucket","");
+        video.put("bucket","efunbox");
         video.put("path",resource.getPath());
         video.put("format",resource.getFormat());
         video.put("quality",resource.getQuality());
@@ -253,6 +251,7 @@ public class ResourceService {
 
         videos.add(video);
 
+
         APIResult<ResourceDetail> apiResult = resourceProxy.saveResources(new HashMap<String, Object>(){
             {
                 this.put("no", resource.getCode());
@@ -262,15 +261,40 @@ public class ResourceService {
             }
         });
 
+
+
+
+
+        */
+
+        Set<ResourceVideo> videos = new HashSet<>();
+        ResourceVideo video = new ResourceVideo();
+        video.setBucket("efunbox");
+        video.setPath(resource.getPath());
+        video.setQuality(resource.getQuality());
+        video.setFormat(resource.getFormat());
+        video.setSize(resource.getSize());
+        videos.add(video);
+
+
+        ResourceRemote resourceRemote = new ResourceRemote();
+        resourceRemote.setNo(resource.getCode());
+        resourceRemote.setTitle(resource.getName());
+        resourceRemote.setType(resource.getType());
+        resourceRemote.setVideos(videos);
+
+
+
+
+        APIResult<ResourceDetail> apiResult = resourceProxy.saveResources(resourceRemote);
+        log.info("saveResources: "+apiResult);
+        log.info("Remote Server return: code={}, message={}", apiResult.getCode(), apiResult.getMessage());
         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;
+            return errorResourceAPIResult(apiResult);
         }
 
-        Resource resourceVO = apiResult.getData().toNativeResource();
-        return APIResult.ok(resourceVO);
+//        Resource resourceVO = apiResult.getData().toNativeResource();
+        return APIResult.ok();
     }
 
     /**
@@ -281,17 +305,18 @@ public class ResourceService {
     public APIResult<Resource> updateRemoteResource(Resource resource) {
 
         APIResult<ResourceRemote> result = resourceProxy.findById(resource.getId());
+        log.info("Remote Server info: code={}, message={},data={}", result.getCode(), result.getMessage(),result.getData());
         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());
+            errResult.setMessage(result.getMessage());
             return errResult;
         }
 
 
-        List<Map<String, Object>> videos = new ArrayList<>();
+/*        List<Map<String, Object>> videos = new ArrayList<>();
         Map<String, Object> video = new HashMap<>();
-        video.put("bucket","");
+        video.put("bucket","efunbox");
         video.put("path",resource.getPath());
         video.put("format",resource.getFormat());
         video.put("quality",resource.getQuality());
@@ -307,17 +332,54 @@ public class ResourceService {
                 this.put("type", "1");
                 this.put("videos", videos);
             }
-        });
+        });*/
+
+        Set<ResourceVideo> videos = result.getData().getVideos();
+        if(videos != null && videos.size() > 0){
+            Iterator<ResourceVideo> iterator = videos.iterator();
+            while(iterator.hasNext()){
+                ResourceVideo video = iterator.next();
+                video.setBucket("efunbox");
+                video.setPath(resource.getPath());
+                video.setQuality(resource.getQuality());
+                video.setFormat(resource.getFormat());
+                video.setSize(resource.getSize());
+                log.info("Remote Server info: video={}, message={},data={}", video);
+            }
+        }
+
+
+/*        Set<ResourceVideo> videos = new HashSet<>();
+        ResourceVideo video = new ResourceVideo();
+        video.setBucket("efunbox");
+        video.setPath(resource.getPath());
+        video.setQuality(resource.getQuality());
+        video.setFormat(resource.getFormat());
+        video.setSize(resource.getSize());
+        videos.add(video);
 
+
+        ResourceRemote resourceRemote = new ResourceRemote();
+        resourceRemote.setNo(resource.getCode());
+        resourceRemote.setTitle(resource.getName());
+        resourceRemote.setType(resource.getType());
+        resourceRemote.setVideos(videos);
+
+        APIResult<ResourceDetail> apiResult = resourceProxy.updateResources(resourceRemote);
+        log.info("updateResources: "+apiResult);
         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;
-        }
+            return errorResourceAPIResult(apiResult);
+        }*/
+
+//        Resource resourceVO = apiResult.getData().toNativeResource();
+        return APIResult.ok();
+    }
 
-        Resource resourceVO = apiResult.getData().toNativeResource();
-        return APIResult.ok(resourceVO);
+    private APIResult<Resource> errorResourceAPIResult(APIResult<ResourceDetail> apiResult) {
+        log.error("Remote Server Error: code={}, message={}", apiResult.getCode(), apiResult.getMessage());
+        APIResult errResult = APIResult.error(APICode.REMOTE_SERVER_ERROR);
+        errResult.setMessage(apiResult.getMessage());
+        return errResult;
     }
 
 }