Explorar el Código

华为hag接口

xushengqiang hace 5 años
padre
commit
3f0126e362

+ 32 - 6
src/main/java/cn/efunbox/audio/impl/hag/HagContentServiceImpl.java

@@ -5,6 +5,7 @@ import cn.efunbox.audio.entity.hag.HagContent;
 import cn.efunbox.audio.repository.hag.HagAlbumRepository;
 import cn.efunbox.audio.repository.hag.HagContentRepository;
 import cn.efunbox.audio.service.hag.HagContentService;
+import cn.efunbox.audio.utils.DateUtil;
 import cn.efunbox.audio.vo.hag.*;
 import com.alibaba.fastjson.JSON;
 import lombok.extern.slf4j.Slf4j;
@@ -31,26 +32,51 @@ public class HagContentServiceImpl implements HagContentService {
     @Override
     public HagBaseResp list(HagContentReq hagContentReq) {
 
-        List<HagAlbum> hagAlbums = hagAlbumRepository.findAll();
+        Pagination paginationReq = hagContentReq.getPagination();
+        Integer limit = paginationReq.getLimit();
+        if (Objects.isNull(limit)) {
+            limit = 10;
+        }
+        if (limit > 1000) {
+            limit = 1000;
+        }
+        Integer start = paginationReq.getStart();
+        if (Objects.isNull(start)) {
+            start = 0;
+        }
+
+        HagContentResp hagContentResp = new HagContentResp();
+
+        String updateTime = hagContentReq.getTimestamp();
+        Date date = DateUtil.strToDate(updateTime);
+        if (Objects.isNull(date)) {
+            hagContentResp.setErrorCode("400");
+            hagContentResp.setErrorMessage("timestamp数据异常");
+            return hagContentResp;
+        }
+
+        List<HagAlbum> hagAlbums = hagAlbumRepository.findByGmtModifiedAfter(date);
 
         List<ContentVO> contentVOList = new ArrayList<>();
         if (!CollectionUtils.isEmpty(hagAlbums)) {
             hagAlbums.forEach(album -> contentVOList.add(AlbumConverter.albumToContentVO(album)));
         }
 
-        List<HagContent> hagContents = hagContentRepository.findAll();
+        List<HagContent> hagContents = hagContentRepository.findByGmtModifiedAfter(date);
         if (!CollectionUtils.isEmpty(hagContents)) {
             hagContents.forEach(content -> contentVOList.add(ContentConverter.contentToContentVO(content)));
         }
 
+        List<ContentVO> contentVOResp = contentVOList.subList(start, start + limit);
+
         Pagination pagination = new Pagination();
-        pagination.setNext("1");
+        pagination.setNext(start + limit + "");
         pagination.setTotal(Long.valueOf(contentVOList.size()));
 
-        HagContentResp hagContentResp = new HagContentResp();
-        hagContentResp.setSource("test");
+
+        hagContentResp.setSource(DateUtil.getDateStr() +"-同步数据");
         hagContentResp.setPagination(pagination);
-        hagContentResp.setContentItems(contentVOList);
+        hagContentResp.setContentItems(contentVOResp);
         return hagContentResp;
     }
 

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

@@ -41,14 +41,18 @@ public class HagProductServiceImpl implements HagProductService {
         if (Objects.isNull(start)) {
             start = 0;
         }
-
+        HagProductResp hagProductResp = new HagProductResp();
         String updateTime = productReq.getUpdateTime();
+        Date date = DateUtil.strToDate(updateTime);
+        if (Objects.isNull(date)) {
+            hagProductResp.setErrorCode("400");
+            hagProductResp.setErrorMessage("timestamp数据异常");
+            return hagProductResp;
+        }
 
 
+        long count = hagProductRepository.countByGmtModifiedAfter(date);
 
-        long count = hagProductRepository.countByGmtModifiedAfter(DateUtil.strToDate(updateTime));
-
-        HagProductResp hagProductResp = new HagProductResp();
         Pagination pagination = new Pagination();
         pagination.setTotal(count);
 
@@ -60,7 +64,7 @@ public class HagProductServiceImpl implements HagProductService {
 
         pagination.setNext(start + limit + "");
 
-        List<HagProduct> hagProducts = hagProductRepository.findByGmtModifiedAfterPage(DateUtil.strToDate(updateTime),start,limit);
+        List<HagProduct> hagProducts = hagProductRepository.findByGmtModifiedAfterPage(date,start,limit);
 
 
 

+ 4 - 0
src/main/java/cn/efunbox/audio/repository/hag/HagAlbumRepository.java

@@ -3,9 +3,13 @@ package cn.efunbox.audio.repository.hag;
 import cn.efunbox.audio.entity.hag.HagAlbum;
 import cn.efunbox.audio.repository.base.BasicRepository;
 
+import java.util.Date;
+import java.util.List;
+
 /**
  * HagAlbumRepository
  * Created by xusq on 2019/12/25.
  */
 public interface HagAlbumRepository extends BasicRepository<HagAlbum> {
+    List<HagAlbum> findByGmtModifiedAfter(Date date);
 }

+ 3 - 0
src/main/java/cn/efunbox/audio/repository/hag/HagContentRepository.java

@@ -3,6 +3,7 @@ package cn.efunbox.audio.repository.hag;
 import cn.efunbox.audio.entity.hag.HagContent;
 import cn.efunbox.audio.repository.base.BasicRepository;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -11,4 +12,6 @@ import java.util.List;
  */
 public interface HagContentRepository extends BasicRepository<HagContent> {
     List<HagContent> findByAlbumIdIn(List<String> albumIds);
+
+    List<HagContent> findByGmtModifiedAfter(Date date);
 }

+ 1 - 1
src/main/java/cn/efunbox/audio/vo/hag/HagProductResp.java

@@ -10,7 +10,7 @@ import java.util.List;
  * Created by xusq on 2019/12/25.
  */
 @Data
-public class HagProductResp implements Serializable {
+public class HagProductResp extends HagBaseResp implements Serializable {
     private Pagination pagination;
     private List<ProductVO> contentItems;
 }