Bläddra i källkod

华为hag接口 bug fix

xushengqiang 5 år sedan
förälder
incheckning
fe852618b8

+ 28 - 2
src/main/java/cn/efunbox/audio/controller/hag/HagOrderController.java

@@ -1,28 +1,54 @@
 package cn.efunbox.audio.controller.hag;
 
+import cn.efunbox.audio.service.hag.HagContentService;
 import cn.efunbox.audio.service.hag.HagOrderService;
+import cn.efunbox.audio.utils.BaseConstant;
 import cn.efunbox.audio.vo.hag.HagSkillReq;
 import cn.efunbox.audio.vo.hag.HagSkillResp;
+import com.alibaba.fastjson.JSON;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Objects;
+
 /**
  * HaOrderController
  * Created by xusq on 2019/12/25.
  */
-@RequestMapping("/api/hag/v1/order")
+@Slf4j
+@RequestMapping("/api/hag/v1/auth")
 @RestController
 public class HagOrderController {
 
+
+
     @Autowired
     private HagOrderService hagOrderService;
+    @Autowired
+    private HagContentService hagContentService;
 
     @PostMapping
     public HagSkillResp sync(@RequestBody HagSkillReq skillReq) {
-        return hagOrderService.save(skillReq);
+
+        log.info("HAG sync order param : {}", JSON.toJSONString(skillReq));
+        HagSkillResp hagSkillResp = new HagSkillResp();
+        HagSkillReq.HagHeader header = skillReq.getHeader();
+        if (Objects.isNull(header)) {
+            return hagSkillResp;
+        }
+
+        if (Objects.equals(BaseConstant.HAG_SYNC_ORDER_TYPE,header.getType())) {
+            hagSkillResp = hagOrderService.save(skillReq);
+        } else {
+            hagSkillResp = hagContentService.getResUrl(skillReq);
+        }
+
+
+        return hagSkillResp;
     }
 
 }

+ 5 - 17
src/main/java/cn/efunbox/audio/impl/hag/HagProductServiceImpl.java

@@ -1,6 +1,5 @@
 package cn.efunbox.audio.impl.hag;
 
-import cn.efunbox.audio.entity.hag.HagContent;
 import cn.efunbox.audio.entity.hag.HagProduct;
 import cn.efunbox.audio.repository.hag.HagContentRepository;
 import cn.efunbox.audio.repository.hag.HagProductRepository;
@@ -11,7 +10,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
 
 /**
  * HagProductServiceImpl
@@ -72,26 +74,12 @@ public class HagProductServiceImpl implements HagProductService {
 
         hagProducts.forEach(product -> albumIds.add(product.getAlbumId()));
 
-        List<HagContent> contentList = hagContentRepository.findByAlbumIdIn(albumIds);
-
-        Map<String,List<String>> albumContentMap = new HashMap<>();
-        contentList.forEach(content -> {
-
-            List<String> list = albumContentMap.get(content.getAlbumId());
-            if (CollectionUtils.isEmpty(list)) {
-                list = new ArrayList<>();
-            }
-            list.add(content.getId());
-            albumContentMap.remove(content.getAlbumId());
-            albumContentMap.put(content.getAlbumId(),list);
-
-        });
 
         List<ProductVO> productVOList = new ArrayList<>();
 
         if (!CollectionUtils.isEmpty(hagProducts)) {
             hagProducts.forEach(product ->
-                productVOList.add(ProductConverter.productToProductVO(product,albumContentMap.get(product.getAlbumId())))
+                productVOList.add(ProductConverter.productToProductVO(product))
             );
         }
         hagProductResp.setPagination(pagination);

+ 2 - 0
src/main/java/cn/efunbox/audio/utils/BaseConstant.java

@@ -4,4 +4,6 @@ package cn.efunbox.audio.utils;
  * 常量类
  */
 public class BaseConstant {
+
+    public static final String HAG_SYNC_ORDER_TYPE = "Charge.SyncOrderRightRequest";
 }

+ 5 - 5
src/main/java/cn/efunbox/audio/vo/hag/ProductConverter.java

@@ -16,7 +16,7 @@ public class ProductConverter {
 
     private ProductConverter(){}
 
-    public static ProductVO productToProductVO(HagProduct product,List<String> contentIds){
+    public static ProductVO productToProductVO(HagProduct product){
 
         if (Objects.isNull(product)) {
             return null;
@@ -62,10 +62,10 @@ public class ProductConverter {
         productVO.setUpdateTime(DateUtil.dateFormatStr(product.getGmtModified()));
 
         List<ProductVO.ResourceRight> resourceRights = new ArrayList<>();
-       ProductVO.ResourceRight resourceRight = new ProductVO.ResourceRight();
-            resourceRight.setResourceType(product.getResourceType());
-            resourceRight.setResourceId(product.getAlbumId());
-            resourceRights.add(resourceRight);
+        ProductVO.ResourceRight resourceRight = new ProductVO.ResourceRight();
+        resourceRight.setResourceType(product.getResourceType());
+        resourceRight.setResourceId(product.getAlbumId());
+        resourceRights.add(resourceRight);
        
         productVO.setResourceRights(resourceRights);