|
@@ -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);
|
|
|
+ }
|
|
|
+}
|