VIP改版
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
package com.peanut.modules.book.controller;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -27,7 +24,6 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
||||
/**
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
@@ -391,85 +387,7 @@ public class BookChapterContentController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 鉴权获取章节
|
||||
*
|
||||
* @param bookid
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/getBooksCatal")
|
||||
public R getBooksCatal(@RequestParam("id") Integer id,
|
||||
@RequestParam("bookid") Integer bookid,
|
||||
@RequestParam("userId") Integer userId) {
|
||||
// TODO 验证 当前请求的书 是否存在免费章节数
|
||||
BookEntity bookEntity = bookService.getBaseMapper().selectById(bookid);
|
||||
Integer freeChapterCount = bookEntity.getFreeChapterCount();
|
||||
|
||||
//TODO 0-免费 1-会免(改为电子书听书) 2-付费 // 阅读章节数 大于 免费章节数
|
||||
Integer isVip = bookEntity.getIsVip();
|
||||
if ((bookid > freeChapterCount) || freeChapterCount == 0) {
|
||||
// 书籍为 会免
|
||||
|
||||
if (isVip == 1) {
|
||||
//查询用户身份
|
||||
MyUserEntity user = myUserService.getById(userId);
|
||||
String vip = user.getVip();
|
||||
if (!"1".equals(vip)) {
|
||||
|
||||
return R.error("当前为VIP");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (isVip == 2) {
|
||||
// 鉴权 查询权限表中 用户是否开通
|
||||
boolean b = myUserService.bookAuthenticate(bookid, userId);
|
||||
|
||||
if (!b) {
|
||||
return R.error(500, "请购买书籍!");
|
||||
}
|
||||
}
|
||||
if (isVip == 3) {
|
||||
boolean b = myUserService.bookAuthenticate(bookid, userId);
|
||||
if (!b) {
|
||||
|
||||
List<BookChapterEntity> book = bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
|
||||
.eq("book_id", bookid));
|
||||
ArrayList<Object> chapterList = new ArrayList<>();
|
||||
int chapterIndex = 0;
|
||||
for (BookChapterEntity chapter : book) {
|
||||
if (chapterIndex >= freeChapterCount) {
|
||||
break; // 取出前freeChapterCount条记录后,退出循环
|
||||
}
|
||||
//获取条数记录,取出对应name,url
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", chapter.getChapter());
|
||||
map.put("url", chapter.getVoices());
|
||||
|
||||
chapterList.add(map);
|
||||
|
||||
chapterIndex++;
|
||||
|
||||
}
|
||||
return R.ok("当前为试听章节:" + chapterList).put("bookCatalogue", chapterList).put("image", bookEntity.getImages()).put("chapterIndex", chapterIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<BookChapterEntity> book = bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
|
||||
.eq("book_id", bookid));
|
||||
ArrayList<Object> chapterList = new ArrayList<>();
|
||||
for (BookChapterEntity chapter : book) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", chapter.getChapter());
|
||||
map.put("url", chapter.getVoices());
|
||||
chapterList.add(map);
|
||||
}
|
||||
return R.ok().put("bookCatalogue", chapterList).put("image", bookEntity.getImages());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取章节音频地址
|
||||
@@ -495,147 +413,6 @@ public class BookChapterContentController {
|
||||
return R.ok().put("chapter", chapter_info);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* app 获取电子书章节内容 2.0 (在用鉴权)
|
||||
*/
|
||||
@RequestMapping("/appBooksChapterContent1")
|
||||
public R getBooksCatalogue1(@RequestParam("chapterid") Integer id,
|
||||
@RequestParam("bookid") Integer bookid,
|
||||
@RequestParam("userId") Integer userId) {
|
||||
// TODO 验证 当前请求的书 是否存在免费章节数
|
||||
BookEntity bookEntity = bookService.getBaseMapper().selectById(bookid);
|
||||
Integer freeChapterCount = bookEntity.getFreeChapterCount();
|
||||
|
||||
BookChapterEntity bookChapterEntity = bookChapterService.getBaseMapper().selectById(id);
|
||||
|
||||
Integer number = bookChapterEntity.getNumber();
|
||||
|
||||
//TODO 0-免费 1-会免(改为电子书听书) 2-付费 // 阅读章节数 大于 免费章节数
|
||||
Integer isVip = bookEntity.getIsVip();
|
||||
Boolean canListen = bookEntity.getCanListen();
|
||||
|
||||
//todo 暂未开通听书功能
|
||||
// if (canListen==false) {
|
||||
// return R.error1("暂未开通听书功能");
|
||||
// }
|
||||
|
||||
if ((number > freeChapterCount) || freeChapterCount == 0) {
|
||||
// 书籍为 会免
|
||||
|
||||
if (isVip == 1) {
|
||||
//查询用户身份
|
||||
MyUserEntity user = myUserService.getById(userId);
|
||||
String vip = user.getVip();
|
||||
if (!"1".equals(vip)) {
|
||||
|
||||
return R.error("当前为VIP");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (canListen == true) {
|
||||
boolean b = myUserService.bookAuthenticate(bookid, userId);
|
||||
if (!b) {
|
||||
|
||||
return R.error("未购买书籍!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (isVip == 2) {
|
||||
// 鉴权 查询权限表中 用户是否开通
|
||||
boolean b = myUserService.bookAuthenticate(bookid, userId);
|
||||
|
||||
if (!b) {
|
||||
return R.error(500, "请购买书籍!").put("code", 500);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ArrayList<Object> chapterList = new ArrayList<>();
|
||||
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", bookChapterEntity.getChapter());
|
||||
map.put("url", bookChapterEntity.getVoices());
|
||||
map.put("bookid", bookChapterEntity.getBookId());
|
||||
map.put("chapterid", bookChapterEntity.getId());
|
||||
//todo sort先注释调
|
||||
// map.put("sort",bookChapterEntity.getSort());
|
||||
chapterList.add(map);
|
||||
|
||||
return R.ok().put("bookCatalogue", chapterList).put("image", bookEntity.getImages());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* app 获取电子书章节内容
|
||||
*/
|
||||
@RequestMapping("/appGetBookChapterContent")
|
||||
public R getBookCatalogue(@RequestParam("chapterid") Integer chapterid,
|
||||
@RequestParam("bookid") Integer bookid,
|
||||
@RequestParam("userId") Integer userId) {
|
||||
|
||||
// TODO 验证 当前请求的书 是否存在免费章节数
|
||||
BookEntity bookEntity = bookService.getBaseMapper().selectById(bookid);
|
||||
Integer freeChapterCount = bookEntity.getFreeChapterCount();
|
||||
Integer isVip = bookEntity.getIsVip(); // 0-免费 1-会免 2-付费
|
||||
BookChapterEntity bookChapterEntity = bookChapterService.getBaseMapper().selectById(chapterid);
|
||||
Integer number = bookChapterEntity.getNumber();
|
||||
// 阅读章节数 大于 免费章节数
|
||||
if ((number > freeChapterCount) || freeChapterCount == 0) {
|
||||
if (isVip == 1) {
|
||||
MyUserEntity user = myUserService.getById(userId);
|
||||
String vip = user.getVip();
|
||||
if (!"1".equals(vip)) {
|
||||
return R.error(500, "当前书籍为会员书籍,请开通会员或购买!");
|
||||
}
|
||||
|
||||
}
|
||||
if (isVip == 2) {
|
||||
boolean b = myUserService.bookAuthenticate(bookid, userId);
|
||||
if (!b) {
|
||||
return R.error(500, "请购买此书籍!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
List<BookChapterContentEntity> bookChapterContentEntities = bookChapterContentService.getBaseMapper().selectList(new QueryWrapper<BookChapterContentEntity>()
|
||||
.eq("book_id", bookid)
|
||||
.eq("book_chatper_id", chapterid));
|
||||
for (BookChapterContentEntity bookChapterContentEntity : bookChapterContentEntities) {
|
||||
|
||||
String content = bookChapterContentEntity.getContent();
|
||||
|
||||
String substring = "";
|
||||
if (bookChapterContentEntity.getOtherContent() != null) {
|
||||
substring = bookChapterContentEntity.getOtherContent().replace("<p>", "").replace("</p>", "");
|
||||
}
|
||||
StringBuffer stringBuffer = new StringBuffer(substring);
|
||||
if (stringBuffer.indexOf("title") != -1) {
|
||||
stringBuffer.insert(stringBuffer.indexOf("title"), "width=\"100%\"");
|
||||
}
|
||||
if (bookChapterContentEntity.getNumber() == 1) {
|
||||
Integer bookChatperId = bookChapterContentEntity.getBookChatperId();
|
||||
BookChapterEntity chapterEntity = bookChapterService.getById(bookChatperId);
|
||||
String chapter = chapterEntity.getChapter();
|
||||
content = bookChapterContentEntity.getContent().replace(chapter, "");
|
||||
}
|
||||
bookChapterContentEntity.setPicAndWord(content.replaceAll(" ", "") + stringBuffer);
|
||||
list.add(bookChapterContentEntity);
|
||||
}
|
||||
|
||||
return R.ok().put("bookCatalogue", list);
|
||||
}
|
||||
|
||||
//生成电子书 目录
|
||||
@RequestMapping("/getWordChapterParagraph")
|
||||
public R getWordChapterParagraph(@RequestParam Map<String, Object> params) {
|
||||
|
||||
Reference in New Issue
Block a user