songshuai vor 5 Jahren
Ursprung
Commit
5f032fbd9c

+ 1 - 1
src/main/java/cn/efunbox/audio/config/Config.java

@@ -51,7 +51,7 @@ public class Config extends WebMvcConfigurerAdapter{
         registry.addInterceptor(adminInterceptor())
                 .addPathPatterns("/**", "/device/update", "/device/delete")
                 .excludePathPatterns("/device/**","/audio/info/{audioId}", "/error", "/admin/login", "/audio/search","/file/**","/audio/searchList","/statistics","/album","/album/{albumId}")
-                .excludePathPatterns("/getTypeList","/getTypeContentList","/getContentDetail");
+                .excludePathPatterns("/getTypeList","/getTypeContentList","/getContentDetail","/getContentChapterList","/getChapterDetail");
 
         registry.addInterceptor(ignoreOptionsInterceptor())
                 .addPathPatterns("/**");

+ 48 - 0
src/main/java/cn/efunbox/audio/controller/res/ResWareController.java

@@ -0,0 +1,48 @@
+package cn.efunbox.audio.controller.res;
+
+import cn.efunbox.audio.entity.res.ResWare;
+import cn.efunbox.audio.page.ResOnePage;
+import cn.efunbox.audio.service.res.ResWareService;
+import cn.efunbox.audio.utils.ResApiCode;
+import cn.efunbox.audio.utils.ResApiResult;
+import lombok.extern.slf4j.Slf4j;
+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
+@RequestMapping
+@Slf4j
+public class ResWareController {
+
+    @Autowired
+    ResWareService resWareService;
+
+    @RequestMapping(value = "/getContentChapterList")
+    public ResApiResult<ResOnePage<ResWare>> getResWareListByContentId(@RequestHeader(value = "USERID",required = false) String USERID,
+                                                                       @RequestParam(name="contentId",required = false) String contentId,
+                                                                       @RequestParam(name="order",required = false) String order,
+                                                                       @RequestParam(name="pageNum",required = false) Integer pageNum,
+                                                                       @RequestParam(name="pageSize",required = false) Integer pageSize){
+        try {
+            return resWareService.getResWareListByContentId(contentId,order,pageNum,pageSize);
+        } catch (Exception e) {
+            log.error("getContentChapterList接口异常:{}",e.getMessage());
+            return ResApiResult.error(ResApiCode.UNKNOWN_ERROR);
+        }
+    }
+
+    @RequestMapping(value = "/getChapterDetail")
+    public ResApiResult<ResWare> getResWareById(@RequestHeader(value = "USERID",required = false) String USERID,
+                                                @RequestParam(name="chapterId",required = false) String chapterId) {
+        try {
+            return resWareService.getResWareById(chapterId);
+        } catch (Exception e) {
+            log.error("getChapterDetail接口异常:{}", e.getMessage());
+            return ResApiResult.error(ResApiCode.UNKNOWN_ERROR);
+        }
+    }
+}

+ 7 - 4
src/main/java/cn/efunbox/audio/entity/res/ResWare.java

@@ -5,10 +5,7 @@ import lombok.ToString;
 import org.hibernate.annotations.DynamicInsert;
 import org.hibernate.annotations.DynamicUpdate;
 
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
+import javax.persistence.*;
 import java.util.Date;
 
 @ToString
@@ -52,6 +49,12 @@ public class ResWare {
     @Column(name = "content_id")
     private String contentId;
 
+    @Transient
+    private String contentName;
+
+    @Transient
+    private String contentPicUrl;
+
     @Column(name = "price")
     private String price;
 

+ 111 - 0
src/main/java/cn/efunbox/audio/impl/res/ResWareServiceImpl.java

@@ -0,0 +1,111 @@
+package cn.efunbox.audio.impl.res;
+
+import cn.efunbox.audio.entity.BaseOrderEnum;
+import cn.efunbox.audio.entity.res.ResAlbum;
+import cn.efunbox.audio.entity.res.ResWare;
+import cn.efunbox.audio.helper.SortHelper;
+import cn.efunbox.audio.page.ResOnePage;
+import cn.efunbox.audio.repository.res.ResAlbumRepository;
+import cn.efunbox.audio.repository.res.ResWareRepository;
+import cn.efunbox.audio.service.res.ResWareService;
+import cn.efunbox.audio.utils.ResApiCode;
+import cn.efunbox.audio.utils.ResApiResult;
+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 ResWareServiceImpl implements ResWareService {
+
+    @Autowired
+    ResWareRepository resWareRepository;
+    @Autowired
+    ResAlbumRepository resAlbumRepository;
+
+    /**
+     * 根据专辑获取节目列表
+     * @param contentId 专辑编号
+     * @param pageNum   页码
+     * @param pageSize  页大小
+     * @return
+     */
+    @Override
+    public ResApiResult<ResOnePage<ResWare>> getResWareListByContentId(String contentId,String order, Integer pageNum, Integer pageSize) {
+        if(StringUtils.isBlank(contentId)){
+            return ResApiResult.error(ResApiCode.PARAMETER_NULL,ResApiCode.PARAMETER_NULL.getMessage()+"contentId");//错误提示语格式=》请求参数为空:contentId
+        }
+
+        ResWare resWare = new ResWare();
+        resWare.setContentId(contentId);
+
+
+        //总记录数
+        Long count = resWareRepository.count(resWare);
+        if(count == 0){
+            return ResApiResult.error(ResApiCode.NOT_FOUND);
+        }
+
+        ResOnePage onePage = new ResOnePage(count);
+        if(pageNum != null){
+            onePage.setPageNum(pageNum);
+        }
+        if(pageSize != null){
+            onePage.setPageSize(pageSize);
+        }
+
+        //查询
+        List<ResWare> wareList = resWareRepository.find(resWare,
+             onePage.getStart(),
+             onePage.getPageSize(),
+              SortHelper.sortMap2Sort(
+                    new LinkedHashMap<String, BaseOrderEnum>() {{
+                        if(StringUtils.isBlank(order) || "asc".equals(order)){
+                            put("sort", BaseOrderEnum.ASC);
+                        }else{
+                            put("sort",BaseOrderEnum.DESC);
+                        }
+                    }}
+              )
+        );
+
+        if(wareList == null || wareList.size() == 0){
+            return ResApiResult.error(ResApiCode.NOT_FOUND);
+        }
+        onePage.setChapterList(wareList);
+
+
+        //响应
+        return ResApiResult.ok(onePage);
+    }
+
+    /**
+     * 获取节目详情信息
+     * @param chapterId
+     * @return
+     */
+    @Override
+    public ResApiResult<ResWare> getResWareById(String chapterId) {
+        if(StringUtils.isBlank(chapterId)){
+            return ResApiResult.error(ResApiCode.PARAMETER_NULL,ResApiCode.PARAMETER_NULL.getMessage()+"contentId");//错误提示语格式=》请求参数为空:chapterId
+        }
+
+        //课件查询
+        ResWare resWare = resWareRepository.find(chapterId);
+        if(resWare == null){
+            return ResApiResult.error(ResApiCode.NOT_FOUND);
+        }
+
+        //课程
+        ResAlbum resAlbum = resAlbumRepository.find(resWare.getContentId());
+        if(resAlbum != null){
+            resWare.setContentName(resAlbum.getContentName());
+            resWare.setContentPicUrl(resAlbum.getContentPicUrl());
+        }
+
+        //响应
+        return ResApiResult.ok(resWare);
+    }
+}

+ 12 - 0
src/main/java/cn/efunbox/audio/page/ResOnePage.java

@@ -30,6 +30,10 @@ public class ResOnePage<E> implements ResPageable<List<E>> ,Serializable {
 
 	// 数据内容
 	private List<E> contentList;
+
+	//数据内容
+	private List<E> chapterList;
+
 	/**
 	 * 构造方法
 	 */
@@ -226,6 +230,14 @@ public class ResOnePage<E> implements ResPageable<List<E>> ,Serializable {
 		this.contentList = contentList;
 	}
 
+	public List<E> getChapterList() {
+		return null == chapterList ? Collections.emptyList() : chapterList;
+	}
+
+	public void setChapterList(List<E> chapterList) {
+		this.chapterList = chapterList;
+	}
+
 	/**
 	 * 功能: <br/>
 	 * 

+ 12 - 0
src/main/java/cn/efunbox/audio/service/res/ResWareService.java

@@ -0,0 +1,12 @@
+package cn.efunbox.audio.service.res;
+
+import cn.efunbox.audio.entity.res.ResWare;
+import cn.efunbox.audio.page.ResOnePage;
+import cn.efunbox.audio.utils.ResApiResult;
+
+public interface ResWareService {
+
+    public ResApiResult<ResOnePage<ResWare>> getResWareListByContentId(String contentId, String order, Integer pageNum, Integer pageSize);
+
+    public ResApiResult<ResWare> getResWareById(String chapterId);
+}