first commit
This commit is contained in:
@@ -0,0 +1,520 @@
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* 图书表
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-08-04 15:36:59
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("book/book")
|
||||
public class BookController {
|
||||
@Autowired
|
||||
private BookService bookService;
|
||||
@Autowired
|
||||
private BookChapterService bookChapterService;
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
@Autowired
|
||||
private AuthorService authorService;
|
||||
@Autowired
|
||||
private PublisherService publisherService;
|
||||
@Autowired
|
||||
private BookShelfService bookShelfService;
|
||||
@Autowired
|
||||
private BookReadRateService bookReadRateService;
|
||||
@Autowired
|
||||
private MyUserService myUserService;
|
||||
@Autowired
|
||||
private ProvinceService provinceService;
|
||||
@Autowired
|
||||
private CityService cityService;
|
||||
@Autowired
|
||||
private CountyService countyService;
|
||||
|
||||
final ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10);
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping("/list")
|
||||
// @RequiresPermissions("book:book:list")
|
||||
public R list(@RequestParam Map<String, Object> params) {
|
||||
PageUtils page = bookService.queryPage(params);
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
// @RequiresPermissions("book:book:info")
|
||||
public R info(@PathVariable("id") Integer id) {
|
||||
BookEntity book = bookService.getById(id);
|
||||
|
||||
return R.ok().put("book", book);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/appinfo/{id}/{userId}")
|
||||
// @RequiresPermissions("book:book:info")
|
||||
public R appinfo(@PathVariable("id") Integer id,
|
||||
@PathVariable("userId") Integer userId) {
|
||||
|
||||
// 判断用户是否够买书籍
|
||||
|
||||
|
||||
BookEntity book = bookService.getById(id);
|
||||
book.setIsBuy(1);
|
||||
|
||||
// Integer isVip = book.getIsVip(); // 0-免费 1-会免 2-付费
|
||||
|
||||
boolean b = myUserService.bookAuthenticate(id, userId);
|
||||
if (!b) {
|
||||
// 无权限
|
||||
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);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
String authorName = "";
|
||||
String publisherName = "";
|
||||
String authorId = book.getAuthorId();
|
||||
|
||||
String[] authorIds = authorId.split(",");
|
||||
List<String> authorList = Arrays.asList(authorIds);
|
||||
List<AuthorEntity> authorEntities = authorService.getBaseMapper().selectList(new QueryWrapper<AuthorEntity>().in("id", authorList));
|
||||
|
||||
for (AuthorEntity authorEntity : authorEntities) {
|
||||
authorName += "," + authorEntity.getAuthorName();
|
||||
}
|
||||
|
||||
authorName = authorName.startsWith(",") ? authorName.substring(1) : authorName;
|
||||
|
||||
|
||||
String publisherId = book.getPublisherId();
|
||||
String[] publisherIds = publisherId.split(",");
|
||||
List<String> publisherList = Arrays.asList(publisherIds);
|
||||
List<PublisherEntity> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<PublisherEntity>().in("id", publisherList));
|
||||
|
||||
for (PublisherEntity publisherEntity : publisherEntities) {
|
||||
publisherName += "," + publisherEntity.getPublisherName();
|
||||
}
|
||||
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;
|
||||
|
||||
//查询书籍阅读进度
|
||||
|
||||
BookReadRateEntity bookReadRateEntity = bookReadRateService.getBaseMapper().selectOne(new QueryWrapper<BookReadRateEntity>()
|
||||
.eq("book_id", id)
|
||||
.eq("user_id", userId)
|
||||
);
|
||||
if (bookReadRateEntity != null) {
|
||||
|
||||
Integer chapterId = bookReadRateEntity.getChapterId();
|
||||
String chapterName = bookReadRateEntity.getChapterName();
|
||||
book.setChapterName(chapterName);
|
||||
book.setChapterId(chapterId);
|
||||
// 查询 书籍 章节 number
|
||||
BookChapterEntity bookChapterEntity = bookChapterService.getById(chapterId);
|
||||
if (bookChapterEntity != null) {
|
||||
Integer number = bookChapterEntity.getNumber();
|
||||
book.setChapterNum(number);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//查询书籍是否加入书架
|
||||
Integer integer = bookShelfService.getBaseMapper().selectCount(new QueryWrapper<BookShelfEntity>()
|
||||
.eq("book_id", id)
|
||||
.eq("user_id", userId));
|
||||
|
||||
boolean flag = false;
|
||||
|
||||
if (integer > 0) {
|
||||
flag = true;
|
||||
}
|
||||
|
||||
book.setAuthorName(authorName);
|
||||
book.setPublisherName(publisherName);
|
||||
book.setFlag(flag);
|
||||
|
||||
return R.ok().put("book", book);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
@RequiresPermissions("book:book:save")
|
||||
public R save(@RequestBody BookEntity book) {
|
||||
bookService.save(book);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
@RequiresPermissions("book:book:update")
|
||||
public R update(@RequestBody BookEntity book) {
|
||||
bookService.updateById(book);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
@RequiresPermissions("book:book:delete")
|
||||
public R delete(@RequestBody Integer[] ids) {
|
||||
bookService.removeByIds(Arrays.asList(ids));
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 章节拆分
|
||||
*/
|
||||
@RequestMapping("/getChapter")
|
||||
public R getChapter(@RequestParam("id") Integer id) {
|
||||
|
||||
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
|
||||
singleThreadExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
bookService.getWordChapter(id);
|
||||
// bookService.getChapter(id);
|
||||
}
|
||||
});
|
||||
|
||||
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
|
||||
bookEntity.setChapterStatus("1");
|
||||
bookService.updateById(bookEntity);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* app 获取电子书目录
|
||||
*/
|
||||
@RequestMapping("/getBookCatalogue")
|
||||
public R getBookCatalogue(@RequestParam("bookid") Integer id) {
|
||||
|
||||
//优化查询速度 目录放入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);
|
||||
}
|
||||
|
||||
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
|
||||
List<BookChapterEntity> bookChapterEntities = bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>().eq("book_id", id));
|
||||
for (BookChapterEntity bookEntity : 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));
|
||||
|
||||
return R.ok().put("bookCatalogue", list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 对外图标列表
|
||||
*/
|
||||
@RequestMapping("/listForWebsite")
|
||||
// @RequiresPermissions("book:book:list")
|
||||
public R listForWebsite(@RequestParam Map<String, Object> params) {
|
||||
PageUtils page = bookService.queryPage(params);
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* app首页数据
|
||||
*/
|
||||
@RequestMapping("/bookIndex")
|
||||
// @RequiresPermissions("book:book:list")
|
||||
public R bookIndex() {
|
||||
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
|
||||
List list = new ArrayList<>();
|
||||
List topList = new ArrayList<>();
|
||||
List saleList = new ArrayList<>();
|
||||
|
||||
|
||||
// 新书
|
||||
List<BookEntity> newBookList = bookService.getBaseMapper().selectList(new QueryWrapper<BookEntity>().eq("state", 1).last("limit 6").orderByDesc("create_time"));
|
||||
for (BookEntity book : newBookList) {
|
||||
String authorName = "";
|
||||
String publisherName = "";
|
||||
BookIndexVo bookIndexVo = new BookIndexVo();
|
||||
String authorId = book.getAuthorId();
|
||||
|
||||
String[] authorIds = authorId.split(",");
|
||||
List<String> authorList = Arrays.asList(authorIds);
|
||||
List<AuthorEntity> authorEntities = authorService.getBaseMapper().selectList(new QueryWrapper<AuthorEntity>().in("id", authorList));
|
||||
|
||||
for (AuthorEntity authorEntity : authorEntities) {
|
||||
authorName += "," + authorEntity.getAuthorName();
|
||||
}
|
||||
|
||||
authorName = authorName.startsWith(",") ? authorName.substring(1) : authorName;
|
||||
|
||||
|
||||
String publisherId = book.getPublisherId();
|
||||
String[] publisherIds = publisherId.split(",");
|
||||
List<String> publisherList = Arrays.asList(publisherIds);
|
||||
List<PublisherEntity> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<PublisherEntity>().in("id", publisherList));
|
||||
|
||||
for (PublisherEntity publisherEntity : publisherEntities) {
|
||||
publisherName += "," + publisherEntity.getPublisherName();
|
||||
}
|
||||
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;
|
||||
|
||||
bookIndexVo.setBookName(book.getName());
|
||||
bookIndexVo.setAuthorName(authorName);
|
||||
bookIndexVo.setBookid(book.getId());
|
||||
bookIndexVo.setImage(book.getImages());
|
||||
bookIndexVo.setIntroduce(book.getDescription());
|
||||
bookIndexVo.setPublisherName(publisherName);
|
||||
bookIndexVo.setIsVip(book.getIsVip());
|
||||
list.add(bookIndexVo);
|
||||
}
|
||||
|
||||
// 推荐
|
||||
|
||||
List<BookEntity> topBookList = bookService.getBaseMapper().selectList(new QueryWrapper<BookEntity>().eq("state", 1).eq("istop", 1).last("limit 6").orderByDesc("sort"));
|
||||
|
||||
for (BookEntity book : topBookList) {
|
||||
String authorName = "";
|
||||
String publisherName = "";
|
||||
|
||||
BookIndexVo bookIndexVo = new BookIndexVo();
|
||||
String authorId = book.getAuthorId();
|
||||
|
||||
String[] authorIds = authorId.split(",");
|
||||
List<String> authorList = Arrays.asList(authorIds);
|
||||
List<AuthorEntity> authorEntities = authorService.getBaseMapper().selectList(new QueryWrapper<AuthorEntity>().in("id", authorList));
|
||||
|
||||
for (AuthorEntity authorEntity : authorEntities) {
|
||||
authorName += "," + authorEntity.getAuthorName();
|
||||
}
|
||||
|
||||
authorName = authorName.startsWith(",") ? authorName.substring(1) : authorName;
|
||||
|
||||
String publisherId = book.getPublisherId();
|
||||
String[] publisherIds = publisherId.split(",");
|
||||
List<String> publisherList = Arrays.asList(publisherIds);
|
||||
List<PublisherEntity> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<PublisherEntity>().in("id", publisherList));
|
||||
|
||||
for (PublisherEntity publisherEntity : publisherEntities) {
|
||||
publisherName += "," + publisherEntity.getPublisherName();
|
||||
}
|
||||
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;
|
||||
|
||||
bookIndexVo.setBookName(book.getName());
|
||||
bookIndexVo.setAuthorName(authorName);
|
||||
bookIndexVo.setBookid(book.getId());
|
||||
bookIndexVo.setImage(book.getImages());
|
||||
bookIndexVo.setIntroduce(book.getDescription());
|
||||
bookIndexVo.setPublisherName(publisherName);
|
||||
bookIndexVo.setIsVip(book.getIsVip());
|
||||
topList.add(bookIndexVo);
|
||||
}
|
||||
|
||||
//秒杀
|
||||
List<BookEntity> saleBookList = bookService.getBaseMapper().selectList(new QueryWrapper<BookEntity>().eq("state", 1).eq("is_sale", 1).last("limit 6").orderByDesc("create_time"));
|
||||
|
||||
for (BookEntity book : saleBookList) {
|
||||
String authorName = "";
|
||||
String publisherName = "";
|
||||
|
||||
BookIndexVo bookIndexVo = new BookIndexVo();
|
||||
String authorId = book.getAuthorId();
|
||||
|
||||
String[] authorIds = authorId.split(",");
|
||||
List<String> authorList = Arrays.asList(authorIds);
|
||||
List<AuthorEntity> authorEntities = authorService.getBaseMapper().selectList(new QueryWrapper<AuthorEntity>().in("id", authorList));
|
||||
|
||||
for (AuthorEntity authorEntity : authorEntities) {
|
||||
authorName += "," + authorEntity.getAuthorName();
|
||||
}
|
||||
|
||||
authorName = authorName.startsWith(",") ? authorName.substring(1) : authorName;
|
||||
|
||||
String publisherId = book.getPublisherId();
|
||||
String[] publisherIds = publisherId.split(",");
|
||||
List<String> publisherList = Arrays.asList(publisherIds);
|
||||
List<PublisherEntity> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<PublisherEntity>().in("id", publisherList));
|
||||
|
||||
for (PublisherEntity publisherEntity : publisherEntities) {
|
||||
publisherName += "," + publisherEntity.getPublisherName();
|
||||
}
|
||||
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;
|
||||
|
||||
bookIndexVo.setBookName(book.getName());
|
||||
bookIndexVo.setAuthorName(authorName);
|
||||
bookIndexVo.setBookid(book.getId());
|
||||
bookIndexVo.setImage(book.getImages());
|
||||
bookIndexVo.setIntroduce(book.getDescription());
|
||||
bookIndexVo.setPublisherName(publisherName);
|
||||
bookIndexVo.setIsVip(book.getIsVip());
|
||||
bookIndexVo.setPrice(book.getPrice());
|
||||
bookIndexVo.setSalePrice(book.getSalePrice());
|
||||
saleList.add(bookIndexVo);
|
||||
}
|
||||
|
||||
|
||||
map.put("newBookList", list);
|
||||
map.put("topBookList", topList);
|
||||
map.put("saleList", saleList);
|
||||
|
||||
return R.ok().put("bookIndex", map);
|
||||
}
|
||||
|
||||
|
||||
//精选
|
||||
@RequestMapping("/getBestBook")
|
||||
public R getBestBook(@RequestParam Map<String, Object> params) {
|
||||
PageUtils page = bookService.getBestBook(params);
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
//新书
|
||||
@RequestMapping("/getNewBook")
|
||||
public R getNewBook(@RequestParam Map<String, Object> params) {
|
||||
PageUtils page = bookService.getNewBook(params);
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
//特价
|
||||
@RequestMapping("/getSaleBook")
|
||||
public R getSaleBook(@RequestParam Map<String, Object> params) {
|
||||
PageUtils page = bookService.getSaleBook(params);
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
//生成电子书 目录
|
||||
@RequestMapping("/getWordChapter")
|
||||
public R getWordChapter(@RequestParam Map<String, Object> params) {
|
||||
bookService.getWordChapter(14);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@RequestMapping("/file")
|
||||
public String getFile() {
|
||||
String filePath = "C:\\Users\\Administrator\\IdeaProjects\\peanut_book\\2020年8月中华人民共和国县以上行政区划代码.json";
|
||||
List<ProvinceEntity> provinceList = ReadProvinceUtil.getFile(filePath);
|
||||
// System.out.println(provinceList);
|
||||
if (provinceList != null && provinceList.size() > 0) {
|
||||
for (ProvinceEntity province : provinceList) {
|
||||
// ProvinceEntity provinceEntity = new ProvinceEntity();
|
||||
// provinceEntity.setProvName(province.getProvName());
|
||||
// provinceEntity.setCreateDate(province.getCreateDate());
|
||||
// provinceEntity.setRegionCode(province.getRegionCode());
|
||||
provinceService.save(province);
|
||||
List<CityEntity> cityList = province.getCityList();
|
||||
if (cityList != null && cityList.size() > 0) {
|
||||
for (CityEntity city : cityList) {
|
||||
// CityEntity cityEntity = new CityEntity();
|
||||
// cityEntity.setCreateDate(city.getCreateDate());
|
||||
// cityEntity.setCityName(city.getCityName());
|
||||
// cityEntity.setRegionCode(city.getRegionCode());
|
||||
// city.setProvId(province.getProvId());
|
||||
city.setProvId(province.getProvId());
|
||||
cityService.save(city);
|
||||
List<CountyEntity> countyList = city.getCountyList();
|
||||
if (countyList != null && countyList.size() > 0) {
|
||||
for (CountyEntity county : countyList) {
|
||||
// CountyEntity countyEntity = new CountyEntity();
|
||||
county.setCityId(city.getCityId());
|
||||
// countyEntity.setCountyName(county.getCountyName());
|
||||
// countyEntity.setCreateDate(county.getCreateDate());
|
||||
// countyEntity.setRegionCode(county.getRegionCode());
|
||||
countyService.save(county);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user