|
@@ -0,0 +1,112 @@
|
|
|
|
+package cn.efunbox.audio.impl.res;
|
|
|
|
+
|
|
|
|
+import cn.efunbox.audio.entity.res.ResAlbum;
|
|
|
|
+import cn.efunbox.audio.entity.res.ResWare;
|
|
|
|
+import cn.efunbox.audio.repository.res.ResAlbumRepository;
|
|
|
|
+import cn.efunbox.audio.repository.res.ResWareRepository;
|
|
|
|
+import cn.efunbox.audio.service.res.ChapterUpdateListService;
|
|
|
|
+import cn.efunbox.audio.utils.ResApiCode;
|
|
|
|
+import cn.efunbox.audio.utils.ResApiResult;
|
|
|
|
+import cn.efunbox.audio.vo.res.ChapterUpdateVO;
|
|
|
|
+import cn.efunbox.audio.vo.res.ChapterVO;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.text.DateFormat;
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * ChapterUpdateListServiceImpl
|
|
|
|
+ * Created by wangys on
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class ChapterUpdateListServiceImpl implements ChapterUpdateListService {
|
|
|
|
+ @Autowired
|
|
|
|
+ private ResWareRepository resWareRepository;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ResAlbumRepository resAlbumRepository;
|
|
|
|
+ @Override
|
|
|
|
+ public ResApiResult getChapterUpdateList(String beginTime, String order, Integer pageNum, Integer pageSize) throws ParseException {
|
|
|
|
+ if (StringUtils.isNotBlank(order)) {
|
|
|
|
+ if (StringUtils.equals(order, "asc") || StringUtils.equals(order, "desc")) {
|
|
|
|
+ } else {
|
|
|
|
+ return ResApiResult.error(ResApiCode.NOT_FOUND);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ int startNum = 0;
|
|
|
|
+ int startSize = 20;
|
|
|
|
+ if (pageNum != null || pageSize != null) {
|
|
|
|
+ if (pageNum < 0 || pageSize < 0) {
|
|
|
|
+ return ResApiResult.error(ResApiCode.NOT_FOUND);
|
|
|
|
+ }
|
|
|
|
+ startNum = (pageNum - 1) * pageSize;
|
|
|
|
+ startSize = pageNum * pageSize;
|
|
|
|
+ }
|
|
|
|
+ DateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss");
|
|
|
|
+ Date parse = null;
|
|
|
|
+ if (StringUtils.isNotBlank(beginTime)) {
|
|
|
|
+ parse = dateFormat.parse(beginTime);
|
|
|
|
+ } else {
|
|
|
|
+ long time = 24 * 60 * 60 * 1000;
|
|
|
|
+ time = System.currentTimeMillis() - time;
|
|
|
|
+ parse = new Date(time);
|
|
|
|
+ }
|
|
|
|
+ DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
|
|
|
+ String format = dateFormat2.format(parse);
|
|
|
|
+ List<ResWare> resCategoryLimit3 = resWareRepository.getResCategoryLimit3(format);
|
|
|
|
+ if (Objects.isNull(resCategoryLimit3))
|
|
|
|
+ return ResApiResult.error(ResApiCode.NOT_FOUND);
|
|
|
|
+ int size = resCategoryLimit3.size();
|
|
|
|
+ List<ResWare> resCategoryLimit = null;
|
|
|
|
+ if (StringUtils.equals(order, "desc")) {
|
|
|
|
+ resCategoryLimit = resWareRepository.getResCategoryLimit(format, startNum, startSize);
|
|
|
|
+ }else {
|
|
|
|
+ resCategoryLimit = resWareRepository.getResCategoryLimit2(format, startNum, startSize);
|
|
|
|
+ }
|
|
|
|
+ ChapterUpdateVO chapterUpdateVO = new ChapterUpdateVO();
|
|
|
|
+ List<ChapterVO> list = new ArrayList<>();
|
|
|
|
+ resCategoryLimit.forEach(resWare -> {
|
|
|
|
+ ChapterVO chapterVO = getChapterVO(resWare);
|
|
|
|
+ list.add(chapterVO);
|
|
|
|
+ });
|
|
|
|
+ if (Objects.isNull(pageNum)){
|
|
|
|
+ chapterUpdateVO.setPageNum(1);
|
|
|
|
+ }else {
|
|
|
|
+ chapterUpdateVO.setPageNum(pageNum);
|
|
|
|
+ }
|
|
|
|
+ chapterUpdateVO.setPageSize(resCategoryLimit.size());
|
|
|
|
+ chapterUpdateVO.setPageTotal(size);
|
|
|
|
+ chapterUpdateVO.setChapterList(list);
|
|
|
|
+ return ResApiResult.ok(chapterUpdateVO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private ChapterVO getChapterVO(ResWare resWare) {
|
|
|
|
+ ChapterVO chapterVO = new ChapterVO();
|
|
|
|
+ chapterVO.setChapterId(resWare.getChapterId());
|
|
|
|
+ chapterVO.setChapterName(resWare.getChapterName());
|
|
|
|
+ chapterVO.setChapterRanking(resWare.getChapterRanking());
|
|
|
|
+ chapterVO.setChapterDuration(resWare.getChapterDuration());
|
|
|
|
+ chapterVO.setChapterPicUrl(resWare.getChapterPicUrl());
|
|
|
|
+ chapterVO.setChapterRecommend(resWare.getChapterRecommend());
|
|
|
|
+ chapterVO.setPayMode(resWare.getPayMode());
|
|
|
|
+ chapterVO.setUpdateType(resWare.getRenewal());
|
|
|
|
+ chapterVO.setStatus(resWare.getIsDel());
|
|
|
|
+ Date gmtModified = resWare.getGmtModified();
|
|
|
|
+ DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ String format1 = format.format(gmtModified);
|
|
|
|
+ chapterVO.setUpdatetime(format1);
|
|
|
|
+ chapterVO.setMediaType(resWare.getMediaType());
|
|
|
|
+ chapterVO.setDownLoadFlag(resWare.getDownLoadFlag());
|
|
|
|
+ ResAlbum resAlbum = resAlbumRepository.find(resWare.getContentId());
|
|
|
|
+ chapterVO.setContentId(resWare.getContentId());
|
|
|
|
+ chapterVO.setContentName(resAlbum.getContentName());
|
|
|
|
+ chapterVO.setContentPicUrl(resAlbum.getContentPicUrl());
|
|
|
|
+ return chapterVO;
|
|
|
|
+ }
|
|
|
|
+}
|