rename the file

This commit is contained in:
Cauchy
2023-10-11 16:51:29 +08:00
parent d80d598529
commit a356cceb62
20 changed files with 566 additions and 683 deletions

View File

@@ -2,7 +2,6 @@ package com.peanut.modules.book.controller;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -16,7 +15,6 @@ import com.peanut.modules.book.service.*;
import com.peanut.modules.oss.service.OssService;
import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.bind.annotation.PathVariable;
@@ -31,8 +29,6 @@ import org.springframework.web.multipart.MultipartFile;
/**
*
*
* @author yl
* @email yl328572838@163.com
* @date 2022-08-16 14:32:06
@@ -53,27 +49,24 @@ public class BookChapterContentController {
@Autowired
private UserEbookBuyService userEbookBuyService;
@Autowired
private ShopProudictBookService shopProudictBookService;
private ShopProductBookService shopProductBookService;
/**
* 列表
*/
@RequestMapping("/list")
// @RequiresPermissions("book:bookchaptercontent:list")
public R list(@RequestParam Map<String, Object> params){
public R list(@RequestParam Map<String, Object> params) {
PageUtils page = bookChapterContentService.queryPage(params);
return R.ok().put("page", page);
}
/**
* 信息
*/
@RequestMapping("/info/{id}")
// @RequiresPermissions("book:bookchaptercontent:info")
public R info(@PathVariable("id") Integer id){
BookChapterContentEntity bookChapterContent = bookChapterContentService.getById(id);
public R info(@PathVariable("id") Integer id) {
BookChapterContentEntity bookChapterContent = bookChapterContentService.getById(id);
return R.ok().put("bookChapterContent", bookChapterContent);
}
@@ -82,9 +75,8 @@ public class BookChapterContentController {
* 保存
*/
@RequestMapping("/save")
// @RequiresPermissions("book:bookchaptercontent:save")
public R save(@RequestBody BookChapterContentEntity bookChapterContent){
bookChapterContentService.save(bookChapterContent);
public R save(@RequestBody BookChapterContentEntity bookChapterContent) {
bookChapterContentService.save(bookChapterContent);
return R.ok();
}
@@ -93,9 +85,8 @@ public class BookChapterContentController {
* 修改
*/
@RequestMapping("/update")
// @RequiresPermissions("book:bookchaptercontent:update")
public R update(@RequestBody BookChapterContentEntity bookChapterContent){
bookChapterContentService.updateById(bookChapterContent);
public R update(@RequestBody BookChapterContentEntity bookChapterContent) {
bookChapterContentService.updateById(bookChapterContent);
return R.ok();
}
@@ -104,9 +95,8 @@ public class BookChapterContentController {
* 删除
*/
@RequestMapping("/delete")
// @RequiresPermissions("book:bookchaptercontent:delete")
public R delete(@RequestBody Integer[] ids){
bookChapterContentService.removeByIds(Arrays.asList(ids));
public R delete(@RequestBody Integer[] ids) {
bookChapterContentService.removeByIds(Arrays.asList(ids));
return R.ok();
}
@@ -116,17 +106,10 @@ public class BookChapterContentController {
* 章节拆分转换单句
*/
@RequestMapping("/getBookVoices")
// @RequiresPermissions("book:bookchaptercontent:delete")
public R getBookVoices(@RequestParam("id") Integer id){
public R getBookVoices(@RequestParam("id") Integer id) {
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
singleThreadExecutor.execute(new Runnable() {
@Override
public void run() {
bookChapterContentService.getWordChapterParagraph(id);
}
});
singleThreadExecutor.execute(() -> bookChapterContentService.getWordChapterParagraph(id));
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
bookEntity.setContentStatus("2");
@@ -134,6 +117,7 @@ public class BookChapterContentController {
return R.ok();
}
/**
* 章节单句 转成音频
*/
@@ -146,21 +130,16 @@ public class BookChapterContentController {
return R.error("语音文件未生成");
}
FileInputStream fileInputStream = new FileInputStream(file);
MultipartFile multipartFile =new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream));
MultipartFile multipartFile = new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream));
String path = ossService.uploadFileAvatar(multipartFile);
fileInputStream.close();
file.delete();
if (StringUtils.isEmpty(path)){
if (StringUtils.isEmpty(path)) {
return R.error("语音上传失败");
}
return R.ok().put("voices",path);
return R.ok().put("voices", path);
}
/**
@@ -180,7 +159,7 @@ public class BookChapterContentController {
List<BookChapterContentEntity> book_id = bookChapterContentService.getBaseMapper().selectList(new QueryWrapper<BookChapterContentEntity>()
.eq("book_id", id));
for (BookChapterContentEntity bookContent:book_id) {
for (BookChapterContentEntity bookContent : book_id) {
String content = bookContent.getContent();
//生成相应的语音文件
String voices = BaiduVoicesUtils.run(content);
@@ -193,9 +172,9 @@ public class BookChapterContentController {
//把 voices 音频文件读入到内存中并将其转换成MultipartFile格式文件 multipartFile 用于OSS上传
// application/x-www-form-urlencoded form表单数据被编码为key/value格式发送到服务器
// text/plain 纯文本格式
// text/plain 纯文本格式
// MultipartFile multipartFile =new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream));
MultipartFile multipartFile =new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream));
MultipartFile multipartFile = new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream));
//上传 multipartFile 文件到阿里云OSS上
String path = ossService.uploadFileAvatar(multipartFile);
@@ -206,7 +185,7 @@ public class BookChapterContentController {
file.delete();
bookChapterContentService.updateById(bookContent);
if (StringUtils.isEmpty(path)){
if (StringUtils.isEmpty(path)) {
bookEntity.setVoicesStatus("3");
}
}
@@ -235,7 +214,7 @@ public class BookChapterContentController {
List<BookChapterEntity> book_id = bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>().eq("book_id", id));
for (BookChapterEntity bookChapter:book_id) {
for (BookChapterEntity bookChapter : book_id) {
String content = bookChapter.getContent();
//生成相应的语音文件
String voices = BaiduVoicesUtils.run(content);
@@ -245,7 +224,7 @@ public class BookChapterContentController {
bookEntity.setVoicesStatus("3");
}
FileInputStream fileInputStream = new FileInputStream(file);
MultipartFile multipartFile =new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream));
MultipartFile multipartFile = new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream));
//上传 multipartFile 文件到阿里云OSS上
String path = ossService.uploadFileAvatar(multipartFile);
@@ -256,7 +235,7 @@ public class BookChapterContentController {
file.delete();
bookChapterService.updateById(bookChapter);
if (StringUtils.isEmpty(path)){
if (StringUtils.isEmpty(path)) {
bookEntity.setVoicesStatus("3");
}
}
@@ -271,14 +250,15 @@ public class BookChapterContentController {
/**
* 鉴权获取章节
*
* @param bookid
* @param userId
* @return
*/
@RequestMapping("/getBooksCatal")
public R getBooksCatal(@RequestParam("id") Integer id,
@RequestParam("bookid") Integer bookid,
@RequestParam("userId") Integer userId) {
@RequestParam("bookid") Integer bookid,
@RequestParam("userId") Integer userId) {
// TODO 验证 当前请求的书 是否存在免费章节数
BookEntity bookEntity = bookService.getBaseMapper().selectById(bookid);
Integer freeChapterCount = bookEntity.getFreeChapterCount();
@@ -294,7 +274,7 @@ public class BookChapterContentController {
String vip = user.getVip();
if (!"1".equals(vip)) {
return R.error("当前为VIP");
return R.error("当前为VIP");
}
}
@@ -308,14 +288,14 @@ public class BookChapterContentController {
return R.error(500, "请购买书籍!");
}
}
if(isVip == 3){
boolean b = myUserService.bookAuthenticate(bookid,userId);
if (!b){
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;
int chapterIndex = 0;
for (BookChapterEntity chapter : book) {
if (chapterIndex >= freeChapterCount) {
break; // 取出前freeChapterCount条记录后退出循环
@@ -330,19 +310,18 @@ public class BookChapterContentController {
chapterIndex++;
}
return R.ok("当前为试听章节:"+chapterList).put("bookCatalogue", chapterList).put("image", bookEntity.getImages()).put("chapterIndex",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());
map.put("name", chapter.getChapter());
map.put("url", chapter.getVoices());
chapterList.add(map);
}
return R.ok().put("bookCatalogue", chapterList).put("image", bookEntity.getImages());
@@ -351,128 +330,114 @@ public class BookChapterContentController {
/**
* 获取章节音频地址
*
* @return
*/
@RequestMapping("/getBooksCatalogue")
public R getBooksCatalogue(@RequestParam Integer chapterId,
@RequestParam Integer bookId,
@RequestParam Integer userId){
@RequestParam Integer userId) {
//鉴权阶段
BookEntity book_info = bookService.getById(bookId);
BookChapterEntity chapter_info = bookChapterService.getById(chapterId);
UserEbookBuyEntity userEbookBuyEntity = userEbookBuyService.getBaseMapper().selectOne(new LambdaQueryWrapper<UserEbookBuyEntity>().
eq(UserEbookBuyEntity::getUserId,userId).eq(UserEbookBuyEntity::getBookId,bookId));
if(chapter_info.getNumber()>book_info.getFreeChapterCount()&&userEbookBuyEntity==null){
Integer productByBookId = shopProudictBookService.getProductByBookId(bookId);
return R.ok().put("jq",false).put("product",productByBookId);
eq(UserEbookBuyEntity::getUserId, userId).eq(UserEbookBuyEntity::getBookId, bookId));
if (chapter_info.getNumber() > book_info.getFreeChapterCount() && userEbookBuyEntity == null) {
Integer productByBookId = shopProductBookService.getProductByBookId(bookId);
return R.ok().put("jq", false).put("product", productByBookId);
}
return R.ok().put("chapter",chapter_info);
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();
/**
* 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);
BookChapterEntity bookChapterEntity = bookChapterService.getBaseMapper().selectById(id);
Integer number = bookChapterEntity.getNumber();
Integer number = bookChapterEntity.getNumber();
//TODO 0-免费 1-会免(改为电子书听书) 2-付费 // 阅读章节数 大于 免费章节数
Integer isVip = bookEntity.getIsVip();
Boolean canListen = bookEntity.getCanListen();
//TODO 0-免费 1-会免(改为电子书听书) 2-付费 // 阅读章节数 大于 免费章节数
Integer isVip = bookEntity.getIsVip();
Boolean canListen = bookEntity.getCanListen();
//todo 暂未开通听书功能
//todo 暂未开通听书功能
// if (canListen==false) {
// return R.error1("暂未开通听书功能");
// }
if ((number > freeChapterCount) || freeChapterCount == 0) {
// 书籍为 会免
if ((number > freeChapterCount) || freeChapterCount == 0) {
// 书籍为 会免
if (isVip == 1) {
//查询用户身份
MyUserEntity user = myUserService.getById(userId);
String vip = user.getVip();
if (!"1".equals(vip)) {
if (isVip == 1) {
//查询用户身份
MyUserEntity user = myUserService.getById(userId);
String vip = user.getVip();
if (!"1".equals(vip)) {
return R.error("当前为VIP");
return R.error("当前为VIP");
}
}
if(canListen == true){
boolean b = myUserService.bookAuthenticate(bookid,userId);
if (!b) {
if (canListen == true) {
boolean b = myUserService.bookAuthenticate(bookid, userId);
if (!b) {
return R.error("未购买书籍!");
return R.error("未购买书籍!");
}
}
}
}
if (isVip == 2) {
if (isVip == 2) {
// 鉴权 查询权限表中 用户是否开通
boolean b = myUserService.bookAuthenticate(bookid, userId);
if (!b) {
return R.error(500, "请购买书籍!").put("code",500);
return R.error(500, "请购买书籍!").put("code", 500);
}
}
ArrayList<Object> chapterList = new ArrayList<>();
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());
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());
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){
@RequestParam("userId") Integer userId) {
// TODO 验证 当前请求的书 是否存在免费章节数
BookEntity bookEntity = bookService.getBaseMapper().selectById(bookid);
@@ -481,57 +446,56 @@ public R getBooksCatalogue1(@RequestParam("chapterid") Integer id,
BookChapterEntity bookChapterEntity = bookChapterService.getBaseMapper().selectById(chapterid);
Integer number = bookChapterEntity.getNumber();
// 阅读章节数 大于 免费章节数
if ((number > freeChapterCount) || freeChapterCount ==0){
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,"当前书籍为会员书籍,请开通会员或购买!");
return R.error(500, "当前书籍为会员书籍,请开通会员或购买!");
}
}
if (isVip == 2) {
boolean b = myUserService.bookAuthenticate(bookid, userId);
if (!b) {
return R.error(500,"请购买此书籍!");
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));
.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>","");
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 (stringBuffer.indexOf("title") != -1) {
stringBuffer.insert(stringBuffer.indexOf("title"), "width=\"100%\"");
}
if (bookChapterContentEntity.getNumber() == 1){
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);
bookChapterContentEntity.setPicAndWord(content.replaceAll(" ", "") + stringBuffer);
list.add(bookChapterContentEntity);
}
return R.ok().put("bookCatalogue",list);
return R.ok().put("bookCatalogue", list);
}
//生成电子书 目录
@RequestMapping("/getWordChapterParagraph")
public R getWordChapterParagraph(@RequestParam Map<String, Object> params){
public R getWordChapterParagraph(@RequestParam Map<String, Object> params) {
bookChapterContentService.getWordChapterParagraph(14);
return R.ok();
}