Procházet zdrojové kódy

新增获取分类下的专辑列表接口

songshuai před 5 roky
rodič
revize
da1be1fd6d

+ 1 - 0
src/main/java/cn/efunbox/audio/AudioApplication.java

@@ -2,6 +2,7 @@ package cn.efunbox.audio;
 
 import cn.efunbox.audio.config.Config;
 import cn.efunbox.audio.repository.base.ProjectSimpleJpaRepository;
+import cn.efunbox.audio.utils.ResApiCode;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.Import;

+ 6 - 2
src/main/java/cn/efunbox/audio/controller/res/ResAlbumController.java

@@ -1,9 +1,13 @@
 package cn.efunbox.audio.controller.res;
 
+import cn.efunbox.audio.entity.res.ResAlbum;
+import cn.efunbox.audio.page.ResOnePage;
 import cn.efunbox.audio.service.res.ResAlbumService;
+import cn.efunbox.audio.utils.ResApiResult;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestHeader;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 @RestController
@@ -14,7 +18,7 @@ public class ResAlbumController {
     ResAlbumService resAlbumService;
 
     @RequestMapping(value = "/getTypeContentList")
-    public void getResCategoryList(@RequestHeader(value = "USERID",required = false) String USERID,String typeId,String pageNum,String pageSize){
-        resAlbumService.getResAlbumList(typeId,1,2);
+    public ResApiResult<ResOnePage<ResAlbum>> getResCategoryList(@RequestHeader(value = "USERID",required = false) String USERID, @RequestParam(name="typeId") String typeId, @RequestParam(name="pageNum") int pageNum, @RequestParam(name="pageSize") int pageSize){
+        return resAlbumService.getResAlbumList(typeId,pageNum,pageSize);
     }
 }

+ 36 - 3
src/main/java/cn/efunbox/audio/impl/res/ResAlbumServiceImpl.java

@@ -1,6 +1,8 @@
 package cn.efunbox.audio.impl.res;
 
+import cn.efunbox.audio.entity.BaseOrderEnum;
 import cn.efunbox.audio.entity.res.ResAlbum;
+import cn.efunbox.audio.helper.SortHelper;
 import cn.efunbox.audio.page.ResOnePage;
 import cn.efunbox.audio.repository.res.ResAlbumRepository;
 import cn.efunbox.audio.service.res.ResAlbumService;
@@ -10,6 +12,9 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.LinkedHashMap;
+import java.util.List;
+
 @Service
 public class ResAlbumServiceImpl implements ResAlbumService {
 
@@ -17,12 +22,40 @@ public class ResAlbumServiceImpl implements ResAlbumService {
     ResAlbumRepository resAlbumRepository;
 
     @Override
-    public ResApiResult getResAlbumList(String typeId, Integer pageNo, Integer pageSize) {
+    public ResApiResult<ResOnePage<ResAlbum>> getResAlbumList(String typeId, Integer pageNum, Integer pageSize) {
         if(StringUtils.isBlank(typeId)){
-            return ResApiResult.error(ResApiCode.PARAMETER_NULL,"");
+            return ResApiResult.error(ResApiCode.PARAMETER_NULL,ResApiCode.PARAMETER_NULL.getMessage()+"typeId");//错误提示语格式=》请求参数为空:typeId
+        }
+
+        //查询条件
+        ResAlbum resAlbum = new ResAlbum();
+        resAlbum.setTypeId(typeId);
+
+        Long count = resAlbumRepository.count(resAlbum);
+
+
+        ResOnePage onePage = new ResOnePage(count);
+        if(pageNum > 0){
+            onePage.setPageNum(pageNum);
+        }
+        if(pageSize > 0){
+            onePage.setPageSize(pageSize);
         }
 
+        //数据查询
+        List<ResAlbum> resAlbumList = resAlbumRepository.find(
+                resAlbum,
+                onePage.getStart(),
+                onePage.getPageSize(),
+                SortHelper.sortMap2Sort(
+                        new LinkedHashMap<String, BaseOrderEnum>() {{
+                            put("sort", BaseOrderEnum.ASC);
+                        }}
+                )
+        );
+        onePage.setContentList(resAlbumList);
 
-        return null;
+        //响应
+        return ResApiResult.ok(onePage);
     }
 }

+ 11 - 1
src/main/java/cn/efunbox/audio/page/ResOnePage.java

@@ -14,7 +14,7 @@ public class ResOnePage<E> implements ResPageable<List<E>> ,Serializable {
 
 	private static final long serialVersionUID = 1L;
 	// 默认分页数据条数
-	public final static int DEFAULT_PAGE_SIZE = 10;
+	public final static int DEFAULT_PAGE_SIZE = 20;
 
 	// 当前页
 	private int pageNum = 1;
@@ -28,6 +28,8 @@ public class ResOnePage<E> implements ResPageable<List<E>> ,Serializable {
 	// 数据内容
 	private List<E> list;
 
+	// 数据内容
+	private List<E> contentList;
 	/**
 	 * 构造方法
 	 */
@@ -216,6 +218,14 @@ public class ResOnePage<E> implements ResPageable<List<E>> ,Serializable {
 		this.list = list;
 	}
 
+	public List<E> getContentList() {
+		return null == contentList ? Collections.emptyList() : contentList;
+	}
+
+	public void setContentList(List<E> contentList) {
+		this.contentList = contentList;
+	}
+
 	/**
 	 * 功能: <br/>
 	 * 

+ 1 - 1
src/main/java/cn/efunbox/audio/service/res/ResAlbumService.java

@@ -6,5 +6,5 @@ import cn.efunbox.audio.utils.ResApiResult;
 
 public interface ResAlbumService {
 
-    ResApiResult getResAlbumList(String typeId, Integer pageNo, Integer pageSize);
+    ResApiResult<ResOnePage<ResAlbum>> getResAlbumList(String typeId, Integer pageNo, Integer pageSize);
 }

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

@@ -0,0 +1,9 @@
+package cn.efunbox.audio.utils;
+
+/**
+ * 常量类
+ */
+public class BaseConstant {
+
+
+}

+ 3 - 3
src/main/java/cn/efunbox/audio/utils/ResApiCode.java

@@ -8,9 +8,9 @@ public class ResApiCode extends AbstractApiCode {
     public static final int _C_UNKNOWN_ERROR = -1;
     public static final ResApiCode UNKNOWN_ERROR = new ResApiCode("系统异常", -1);
     public static final int _C_PARAMETER_NULL = -102;
-    public static final ResApiCode PARAMETER_NULL = new ResApiCode("请求参数为空", -102);
+    public static final ResApiCode PARAMETER_NULL = new ResApiCode("请求参数为空", -102);
     public static final int _C_PARAMETER_ERROR = -103;
-    public static final ResApiCode PARAMETER_ERROR = new ResApiCode("请求参数非法", -103);
+    public static final ResApiCode PARAMETER_ERROR = new ResApiCode("请求参数非法", -103);
     public static final int _C_NOT_SUPPORT = -104;
     public static final ResApiCode NOT_SUPPORT = new ResApiCode("内容来源不存在", -104);
     public static final int _C_SIGNATURE_ERROR = -105;
@@ -18,7 +18,7 @@ public class ResApiCode extends AbstractApiCode {
     public static final int _C_USER_DEFINED_ERROR = -201;
     public static final ResApiCode USER_DEFINED_ERROR = new ResApiCode("自定义错误类型", -201);
     public static final int _C_EXTERNAL_ERROR = -301;
-    public static final ResApiCode EXTERNAL_ERROR = new ResApiCode("外部平台访问失败", -301);
+    public static final ResApiCode EXTERNAL_ERROR = new ResApiCode("外部平台访问失败", -301);
     public static final int _C_NOT_FOUND = 24000;
     public static final ResApiCode NOT_FOUND = new ResApiCode("服务端侧不存在符合条件的数据", 24000);