-- 新版提交
This commit is contained in:
@@ -1,28 +1,18 @@
|
||||
package com.peanut.modules.book.controller;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.peanut.common.utils.ReadProvinceUtil;
|
||||
import com.peanut.modules.book.entity.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.book.vo.BookIndexVo;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
||||
/**
|
||||
* 图书表
|
||||
*
|
||||
@@ -55,7 +45,8 @@ public class BookController {
|
||||
private CityService cityService;
|
||||
@Autowired
|
||||
private CountyService countyService;
|
||||
|
||||
@Autowired
|
||||
private UserEbookBuyService userEbookBuyService;
|
||||
final ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10);
|
||||
|
||||
/**
|
||||
@@ -69,6 +60,17 @@ public class BookController {
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@@ -89,12 +91,15 @@ public class BookController {
|
||||
public R appinfo(@PathVariable("id") Integer id,
|
||||
@PathVariable("userId") Integer userId) {
|
||||
|
||||
|
||||
System.out.println("++++++id"+id);
|
||||
System.out.println("++++++userId"+userId);
|
||||
// 判断用户是否够买书籍
|
||||
|
||||
|
||||
BookEntity book = bookService.getById(id);
|
||||
book.setIsBuy(1);
|
||||
|
||||
book.setIsBuy(0);
|
||||
Boolean canListen = book.getCanListen();
|
||||
// Integer isVip = book.getIsVip(); // 0-免费 1-会免 2-付费
|
||||
|
||||
boolean b = myUserService.bookAuthenticate(id, userId);
|
||||
@@ -103,31 +108,10 @@ public class BookController {
|
||||
book.setIsBuy(0);
|
||||
}
|
||||
|
||||
// // 书籍为 会免
|
||||
// if (isVip == 1) {
|
||||
// //查询用户身份
|
||||
// MyUserEntity user = myUserService.getById(userId);
|
||||
// String vip = user.getVip();
|
||||
// if (!"1".equals(vip)) {
|
||||
//
|
||||
// //TODO 判断 非会员 是否购买会免书籍
|
||||
//
|
||||
// // 无权限
|
||||
// book.setIsBuy(0);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// if (isVip == 2) {
|
||||
// // 鉴权 查询权限表中 用户是否开通
|
||||
// boolean b = myUserService.bookAuthenticate(id, userId);
|
||||
//
|
||||
// if (!b) {
|
||||
// // 无权限
|
||||
// book.setIsBuy(0);
|
||||
// }
|
||||
// }
|
||||
// if (canListen==false) {
|
||||
// // 无权限
|
||||
// return R.error("该图书暂未开通听书功能");
|
||||
// }
|
||||
|
||||
|
||||
String authorName = "";
|
||||
@@ -193,7 +177,7 @@ public class BookController {
|
||||
book.setPublisherName(publisherName);
|
||||
book.setFlag(flag);
|
||||
|
||||
return R.ok().put("book", book);
|
||||
return R.ok().put("book", book).put("canListen",canListen);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,7 +215,7 @@ public class BookController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 章节拆分
|
||||
* 常规章节拆分
|
||||
*/
|
||||
@RequestMapping("/getChapter")
|
||||
public R getChapter(@RequestParam("id") Integer id) {
|
||||
@@ -240,51 +224,124 @@ public class BookController {
|
||||
singleThreadExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
bookService.getWordChapter(id);
|
||||
// bookService.getWordChapter(id);
|
||||
// bookService.getChapter(id);
|
||||
// bookService.getWord(id);
|
||||
bookService.getWordSection(id);
|
||||
}
|
||||
});
|
||||
|
||||
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
|
||||
bookEntity.setChapterStatus("2");
|
||||
bookService.updateById(bookEntity);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 章节拆分 2.0
|
||||
*/
|
||||
@RequestMapping("/getWord")
|
||||
public R getWord(@RequestParam("id") Integer id) {
|
||||
|
||||
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
|
||||
singleThreadExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//2.0
|
||||
bookService.getWord(id);
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
|
||||
bookEntity.setChapterStatus("2");
|
||||
bookService.updateById(bookEntity);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 章节拆分 3.0小节
|
||||
*/
|
||||
@RequestMapping("/WordSection")
|
||||
public R getWordSection(@RequestParam("id") Integer id) {
|
||||
|
||||
// List<BookChapterEntity> kid = bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>().eq("book_id", id));
|
||||
// if (kid != null) {
|
||||
// for (BookChapterEntity bookChapterEntity : kid) {
|
||||
// // 调用删除方法进行删除
|
||||
// Integer id1 = bookChapterEntity.getId();
|
||||
// System.out.println("===========id1=="+id1);
|
||||
//// bookChapterService.removeById(id1);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
|
||||
singleThreadExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
|
||||
|
||||
//3.0 大小章拆分
|
||||
bookService.getWordSection(id);
|
||||
// bookService.getChapter(id);
|
||||
}
|
||||
});
|
||||
|
||||
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
|
||||
bookEntity.setChapterStatus("1");
|
||||
bookEntity.setChapterStatus("2");
|
||||
bookService.updateById(bookEntity);
|
||||
return R.ok();
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* app 获取电子书目录
|
||||
*/
|
||||
@RequestMapping("/getBookCatalogue")
|
||||
public R getBookCatalogue(@RequestParam("bookid") Integer id) {
|
||||
public R getBookCatalogue(@RequestParam("bookid") Integer id,
|
||||
@RequestParam("userid") Integer userid) {
|
||||
|
||||
//优化查询速度 目录放入redis中
|
||||
String s = redisTemplate.opsForValue().get("bookCatalogue" + String.valueOf(id));
|
||||
List<Map<String, Object>> listData = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(s)) {
|
||||
List<Object> redisData = JSONArray.parseArray(s);
|
||||
for (Object object : redisData) {
|
||||
Map<String, Object> ret = (Map<String, Object>) object;//取出list里面的值转为map
|
||||
listData.add(ret);
|
||||
}
|
||||
return R.ok().put("bookCatalogue", listData);
|
||||
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
|
||||
if (bookEntity.getImages()==null) {
|
||||
return R.error("电子书目录为空");
|
||||
}
|
||||
String images = bookEntity.getImages() ;
|
||||
|
||||
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
Integer freeChapterCount = bookEntity.getFreeChapterCount();
|
||||
UserEbookBuyEntity userEbookBuyEntity1 = userEbookBuyService.getBaseMapper().selectOne(new QueryWrapper<UserEbookBuyEntity>().eq("book_id", id).eq("user_id", userid));
|
||||
|
||||
List<BookChapterEntity> bookChapterEntities = bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>().eq("book_id", id));
|
||||
for (BookChapterEntity bookEntity : bookChapterEntities) {
|
||||
List<HashMap<Object, Object>> chapterList = new ArrayList<>();
|
||||
for (BookChapterEntity bookEntitys : bookChapterEntities) {
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
String chapter = bookEntity.getChapter();
|
||||
// map.put(bookEntity.getId(),chapter);
|
||||
map.put("chapterId", bookEntity.getId());
|
||||
map.put("chapterName", chapter);
|
||||
list.add(map);
|
||||
}
|
||||
redisTemplate.opsForValue().set("bookCatalogue" + String.valueOf(id), JSON.toJSONString(list));
|
||||
map.put("bookid",id);
|
||||
map.put("number", bookEntitys.getNumber());
|
||||
map.put("chapterId", bookEntitys.getId());
|
||||
map.put("chapterName", bookEntitys.getChapter());
|
||||
//freeChapterCount
|
||||
|
||||
return R.ok().put("bookCatalogue", list);
|
||||
map.put("images",images);
|
||||
chapterList.add(map);
|
||||
}
|
||||
//true免费 ,false付费
|
||||
if (userEbookBuyEntity1!=null) {
|
||||
return R.ok().put("BookCatalogue", chapterList).put("buy",true);
|
||||
}
|
||||
return R.ok().put("BookCatalogue", chapterList).put("buy",false).put("freeChapterCount",freeChapterCount);
|
||||
}
|
||||
|
||||
|
||||
@@ -517,4 +574,7 @@ public class BookController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user