-- 新版提交

This commit is contained in:
yc13649764453
2023-09-09 13:51:35 +08:00
parent 763e24b4e0
commit 0b193caa03
92 changed files with 3451 additions and 1120 deletions

View File

@@ -10,12 +10,8 @@ import java.util.concurrent.Executors;
import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.common.utils.BaiduVoicesUtils;
import com.peanut.modules.book.entity.BookChapterEntity;
import com.peanut.modules.book.entity.BookEntity;
import com.peanut.modules.book.entity.MyUserEntity;
import com.peanut.modules.book.service.BookChapterService;
import com.peanut.modules.book.service.BookService;
import com.peanut.modules.book.service.MyUserService;
import com.peanut.modules.book.entity.*;
import com.peanut.modules.book.service.*;
import com.peanut.modules.oss.service.OssService;
import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;
@@ -28,8 +24,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.peanut.modules.book.entity.BookChapterContentEntity;
import com.peanut.modules.book.service.BookChapterContentService;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
import org.springframework.web.multipart.MultipartFile;
@@ -55,6 +49,8 @@ public class BookChapterContentController {
private BookChapterService bookChapterService;
@Autowired
private MyUserService myUserService;
@Autowired
private UserEbookBuyService userEbookBuyService;
/**
* 列表
@@ -124,14 +120,13 @@ public class BookChapterContentController {
singleThreadExecutor.execute(new Runnable() {
@Override
public void run() {
// bookChapterContentService.getBookVoices(id);
bookChapterContentService.getWordChapterParagraph(14);
bookChapterContentService.getWordChapterParagraph(id);
}
});
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
bookEntity.setContentStatus("1");
bookEntity.setContentStatus("2");
bookService.updateById(bookEntity);
return R.ok();
@@ -141,9 +136,8 @@ public class BookChapterContentController {
*/
@RequestMapping("/signVoices")
public R signVoices(@RequestParam("content") String content) throws Exception {
//调用百度语音合成 API
String voices = BaiduVoicesUtils.run(content);
File file = new File(voices);
if (!file.exists()) {
return R.error("语音文件未生成");
@@ -173,7 +167,7 @@ public class BookChapterContentController {
public R allVoices(@RequestParam("id") Integer id) throws Exception {
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
//创建单线程
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
singleThreadExecutor.execute(new Runnable() {
@SneakyThrows
@@ -185,7 +179,7 @@ public class BookChapterContentController {
for (BookChapterContentEntity bookContent:book_id) {
String content = bookContent.getContent();
//生成相应的语音文件
String voices = BaiduVoicesUtils.run(content);
File file = new File(voices);
@@ -194,9 +188,12 @@ public class BookChapterContentController {
}
FileInputStream fileInputStream = new FileInputStream(file);
//把 voices 音频文件读入到内存中并将其转换成MultipartFile格式文件 multipartFile 用于OSS上传
// application/x-www-form-urlencoded form表单数据被编码为key/value格式发送到服务器
// 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 文件到阿里云OSS上
String path = ossService.uploadFileAvatar(multipartFile);
bookContent.setVoices(path);
@@ -218,6 +215,232 @@ public class BookChapterContentController {
bookService.updateById(bookEntity);
return R.ok();
}
//章节2.0转音频
@RequestMapping("/AllVOices")
public R allVoicess2(@RequestParam("id") Integer id) throws Exception {
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
//创建单线程
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
singleThreadExecutor.execute(new Runnable() {
@SneakyThrows
@Override
public void run() {
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
List<BookChapterEntity> book_id = bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>().eq("book_id", id));
for (BookChapterEntity bookChapter:book_id) {
String content = bookChapter.getContent();
//生成相应的语音文件
String voices = BaiduVoicesUtils.run(content);
File file = new File(voices);
if (!file.exists()) {
bookEntity.setVoicesStatus("3");
}
FileInputStream fileInputStream = new FileInputStream(file);
MultipartFile multipartFile =new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream));
//上传 multipartFile 文件到阿里云OSS上
String path = ossService.uploadFileAvatar(multipartFile);
bookChapter.setVoices(path);
fileInputStream.close();
file.delete();
bookChapterService.updateById(bookChapter);
if (StringUtils.isEmpty(path)){
bookEntity.setVoicesStatus("3");
}
}
bookEntity.setVoicesStatus("2");
bookService.updateById(bookEntity);
}
});
bookEntity.setVoicesStatus("1");
bookService.updateById(bookEntity);
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());
}
/**
* app 获取电子书章节内容 2.0 (在用鉴权)
*/
@RequestMapping("/appBooksChapterContent")
public R getBooksCatalogue(@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 获取电子书章节内容
*/
@@ -227,20 +450,14 @@ public class BookChapterContentController {
@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 ((number > freeChapterCount) || freeChapterCount ==0){
if (isVip == 1) {
//查询用户身份
MyUserEntity user = myUserService.getById(userId);
String vip = user.getVip();
if (!"1".equals(vip)) {
@@ -248,13 +465,10 @@ public class BookChapterContentController {
}
}
if (isVip == 2) {
// 鉴权 查询权限表中 用户是否开通
boolean b = myUserService.bookAuthenticate(bookid, userId);
if (!b) {
return R.error(500,"开通会员或购买此书籍!");
return R.error(500,"请购买此书籍!");
}
}
}
@@ -262,8 +476,6 @@ public class BookChapterContentController {
ArrayList<Object> list = new ArrayList<>();
List<BookChapterContentEntity> bookChapterContentEntities = bookChapterContentService.getBaseMapper().selectList(new QueryWrapper<BookChapterContentEntity>()
.eq("book_id",bookid)
.eq("book_chatper_id",chapterid));
@@ -273,7 +485,6 @@ public class BookChapterContentController {
String substring = "";
if (bookChapterContentEntity.getOtherContent() != null){
// substring = bookChapterContentEntity.getOtherContent().substring(3, bookChapterContentEntity.getOtherContent().length() - 3);
substring = bookChapterContentEntity.getOtherContent().replace("<p>","").replace("</p>","");
}
StringBuffer stringBuffer = new StringBuffer(substring);
@@ -286,8 +497,6 @@ public class BookChapterContentController {
String chapter = chapterEntity.getChapter();
content = bookChapterContentEntity.getContent().replace(chapter, "");
}
// System.out.println(content.length());
// System.out.println(content.replaceAll("[\\\\s\\\\u00A0]",""));
bookChapterContentEntity.setPicAndWord(content.replaceAll(" ","") + stringBuffer);
list.add(bookChapterContentEntity);
}

View File

@@ -1,9 +1,10 @@
package com.peanut.modules.book.controller;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.text.Collator;
import java.util.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
@@ -36,7 +37,6 @@ public class BookChapterController {
* 列表
*/
@RequestMapping("/list")
// @RequiresPermissions("book:bookchapter:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = bookChapterService.queryPage(params);
@@ -44,11 +44,19 @@ public class BookChapterController {
}
@RequestMapping("/booklist")
public R booklist(@RequestParam Map<String, Object> params){
PageUtils page = bookChapterService.queryPage1(params);
return R.ok().put("page", page);
}
/**
* 信息
*/
@RequestMapping("/info/{id}")
// @RequiresPermissions("book:bookchapter:info")
public R info(@PathVariable("id") Integer id){
BookChapterEntity bookChapter = bookChapterService.getById(id);
@@ -59,36 +67,176 @@ public class BookChapterController {
* 保存
*/
@RequestMapping("/save")
// @RequiresPermissions("book:bookchapter:save")
public R save(@RequestBody BookChapterEntity bookChapter){
bookChapterService.save(bookChapter);
public R save(@RequestBody BookChapterEntity bookChapter) {
BookChapterEntity bookChapterEntity = new BookChapterEntity();
Integer number = bookChapter.getNumber();
Integer bookId = bookChapter.getBookId();
List<BookChapterEntity> bookChapterEntities = this.bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
.eq("book_id", bookId)
.ge("number", number));
for(BookChapterEntity entity: bookChapterEntities){
entity.setNumber(entity.getNumber() + 1);
this.bookChapterService.updateById(entity);
}
bookChapterService.save(bookChapter);
// if (number != null && bookId != null) {
// BookChapterEntity chapter = bookChapterService.getBaseMapper().selectOne(new QueryWrapper<BookChapterEntity>()
// .eq("number", number)
// .eq("book_id", bookId));
// if (chapter != null) {
// return R.error("该章节已存在,请修改或重新上传");
// } else {
// bookChapterEntity.setBookId(bookChapter.getBookId());
// bookChapterEntity.setNumber(bookChapter.getNumber());
// bookChapterEntity.setContent(bookChapter.getContent());
// bookChapterEntity.setChapter(bookChapter.getChapter());
// bookChapterEntity.setVoices(bookChapter.getVoices());
// bookChapterService.save(bookChapterEntity);
// }
//
// }
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/contentupdate")
public R contentupdate(@RequestBody BookChapterEntity bookChapter) {
Integer id = bookChapter.getId();
String content = bookChapter.getContent();
//
// bookChapterService.updateById(bookChapter); // 更新对象的属性
//
// return R.ok();
BookChapterEntity byId = bookChapterService.getById(id);
String content1 = byId.getContent();
if (content.equals(content1)) {
} else {
// 如果content字段和原来数据库的content内容不同则voices字段为空
bookChapter.setVoices(""); // 设置voices字段为空
}
bookChapterService.updateById(bookChapter); // 更新对象的属性
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
// @RequiresPermissions("book:bookchapter:update")
public R update(@RequestBody BookChapterEntity bookChapter){
bookChapterService.updateById(bookChapter);
public R update(@RequestBody BookChapterEntity bookChapter) {
bookChapterService.updateById(bookChapter); // 更新对象的属性
return R.ok();
}
public static List<BookChapterEntity> sort(List<BookChapterEntity> list){
//根据指定比较器产生的顺序对指定列表进行排序。
Collections.sort(list, new Comparator<BookChapterEntity>() {
@Override
public int compare(BookChapterEntity o1, BookChapterEntity o2) {
//获取所需语言环境的 Collator根据所需切换其他语言环境
//Collator collator = Collator.getInstance(Locale.ENGLISH);
//return collator.compare(o1.getAddress(), o2.getAddress());
Collator collator = Collator.getInstance(Locale.CANADA);
return collator.compare(o1.getNumber(), o2.getNumber());
}
});
return list;
}
/**
* 优化删除,暂时报错未修改
*/
//TODO 优化删除,暂时报错未修改
@RequestMapping("/deletess")
public R deletess(@RequestBody Integer[] ids){
for(Integer id : ids){
BookChapterEntity chapter = bookChapterService.getBaseMapper().selectOne(new QueryWrapper<BookChapterEntity>()
.eq("id", id)
);
List<BookChapterEntity> bookChapterEntities = this.bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
.eq("book_id", chapter.getBookId())
.gt("number", chapter.getNumber()));
this.bookChapterService.removeById(id);
for(BookChapterEntity entity: bookChapterEntities){
entity.setNumber(entity.getNumber() - 1);
}
List<BookChapterEntity> bookChapterEntities2 = sort(bookChapterEntities);
List<BookChapterEntity> tempEntity = this.bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
.eq("book_id", chapter.getBookId()).orderByAsc("number")
);
int index = tempEntity.size() - bookChapterEntities.size();
for(BookChapterEntity entity: bookChapterEntities2){
index ++;
entity.setNumber(index);
this.bookChapterService.updateById(entity);
}
}
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
// @RequiresPermissions("book:bookchapter:delete")
public R delete(@RequestBody Integer[] ids){
bookChapterService.removeByIds(Arrays.asList(ids));
public R delete(@RequestBody Integer[] ids) {
for(Integer id : ids){
BookChapterEntity chapter = bookChapterService.getBaseMapper().selectOne(new QueryWrapper<BookChapterEntity>()
.eq("id", id)
);
List<BookChapterEntity> bookChapterEntities = this.bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
.eq("book_id", chapter.getBookId())
.gt("number", chapter.getNumber()));
this.bookChapterService.removeById(id);
for(BookChapterEntity entity: bookChapterEntities){
entity.setNumber(entity.getNumber() - 1);
this.bookChapterService.updateById(entity);
}
List<BookChapterEntity> tempEntity = this.bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
.eq("book_id", chapter.getBookId()).orderByAsc("number")
);
int index = 0;
for(BookChapterEntity entity: tempEntity){
index ++;
entity.setNumber(index);
this.bookChapterService.updateById(entity);
}
}
return R.ok();
}
}
}

View File

@@ -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 {
}
}

View File

@@ -57,10 +57,10 @@ public class BookReadRateController {
/**
* 保存
*/
@RequestMapping("book/bookreadrate/save")
// @RequiresPermissions("book:bookreadrate:save")
public R save(@RequestBody BookReadRateEntity bookReadRate){
@RequestMapping("/save")
// @RequiresPermissions("book:bookreadrate:save") @RequestBody
public R save(@RequestBody BookReadRateEntity bookReadRate){
Integer bookId = bookReadRate.getBookId();
Integer userId = bookReadRate.getUserId();
BookReadRateEntity bookReadRateEntity = bookReadRateService.getBaseMapper().selectOne(new QueryWrapper<BookReadRateEntity>().eq("book_id", bookId)
@@ -68,10 +68,10 @@ public class BookReadRateController {
if (bookReadRateEntity != null) {
return R.ok().put("bookReadId",bookReadRateEntity.getId());
}else {
bookReadRateService.save(bookReadRate);
}
bookReadRateService.save(bookReadRate);
return R.ok();
}
@@ -83,6 +83,7 @@ public class BookReadRateController {
public R update(@RequestBody BookReadRateEntity bookReadRate){
bookReadRateService.updateById(bookReadRate);
return R.ok();
}

View File

@@ -70,9 +70,10 @@ public class BookShelfController {
// 加入前判断数据库是否加入过 这本书
Integer integer = bookShelfService.getBaseMapper().selectCount(new QueryWrapper<BookShelfEntity>()
.eq("book_id", bookShelf.getBookId())
.eq("user_id", bookShelf.getUserId()));
System.out.println("bookShelf"+bookShelf);
if (integer > 0){
return R.error(500,"当前书籍已加入书架");
}
@@ -119,4 +120,16 @@ public class BookShelfController {
return R.ok().put("userBookshelf",userBookshelf);
}
/**
* 获取用户听书书架 getUserBookChapterRead
*/
@RequestMapping("/getUserBookChapterRead")
public R getUserBookChapterRead(@RequestParam Integer userId){
List<BookShelfVo> bookShelfVos = bookShelfService.getUserBookChapterRead(userId);
return R.ok().put("bookShelfVos",bookShelfVos);
}
}

View File

@@ -1,29 +1,20 @@
package com.peanut.modules.book.controller;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.peanut.common.utils.MD5Util;
import com.peanut.common.utils.MD5Utils;
import com.peanut.modules.book.entity.*;
import com.peanut.modules.book.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import lombok.var;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
@@ -32,7 +23,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
@@ -61,15 +51,34 @@ public class BuyOrderController {
private CouponHistoryService couponHistoryService;
@Autowired
private OrderCartService orderCartService;
@Autowired
private MyUserService myUserService;
@Autowired
private TransactionDetailsService transactionDetailsService;
@Autowired
private AuthorService authorService;
@Autowired
private UserEbookBuyService userEbookBuyService;
@Autowired
private BookService bookService;
@Autowired
private BookShelfService bookShelfService;
@Autowired
private UserRecordService userRecordService;
@Autowired
private UserFollowUpService userFollowUpService;
@Autowired
private PayWechatOrderService payWechatOrderService;
@Autowired
private PayZfbOrderService payZfbOrderService;
// @Autowired
// private
/**
* 列表
*/
@RequestMapping("/list")
// @RequiresPermissions("book:buyorder:list")
public R list(@RequestParam Map<String, Object> params){
public R list(@RequestParam Map<String, Object> params) throws Exception {
if("all".equals(params.get("orderStatus"))){
params.remove("orderStatus");
@@ -79,6 +88,29 @@ public class BuyOrderController {
}
/**
*
* @param params
* @return 听书未购买页面展示
* (销量最多的书,最先放最前面展示。最新上线的书,预售的书,放最前面展示
* @throws Exception
*/
@RequestMapping("/lists")
// @RequiresPermissions("book:buyorder:list")
public R lists(@RequestParam Map<String, Object> params) throws Exception {
if("all".equals(params.get("orderStatus"))){
params.remove("orderStatus");
}
PageUtils page = buyOrderService.queryPages(params);
return R.ok().put("page", page);
}
/**
* 信息
*/
@@ -90,6 +122,7 @@ public class BuyOrderController {
return R.ok().put("buyOrder", buyOrder);
}
/**
* 保存
*/
@@ -127,7 +160,6 @@ public class BuyOrderController {
product.setProductStock(product.getProductStock() - buyOrderDetail.getQuantity());
product.setSumSales(product.getSumSales() + buyOrderDetail.getQuantity());
shopProductService.updateById(product);
BeanUtils.copyProperties(buyOrderDetail,buyOrderDetailEntity);
buyOrderDetailEntity.setProductName(product.getProductName());
buyOrderDetailEntity.setProductPrice(product.getPrice());
@@ -136,6 +168,10 @@ public class BuyOrderController {
System.out.println(buyOrder.getAddressId());
buyOrderDetailEntity.setOrderStatus("0");
list.add(buyOrderDetailEntity);
}
Integer couponId = buyOrder.getCouponId();
@@ -149,28 +185,25 @@ public class BuyOrderController {
}
if (buyOrder.getShippingMoney() != null) {
System.out.println("bigDecimal1============>"+bigDecimal1);
System.out.println("ShippingMoney============>"+buyOrder.getShippingMoney());
bigDecimal1 = bigDecimal1.add(buyOrder.getShippingMoney());
}
// 减去优惠券金额
realMoney = buyOrder.getRealMoney();
System.out.println("realMoney============>"+realMoney);
System.out.println("bigDecimal1============>"+bigDecimal1);
if (bigDecimal1.compareTo(realMoney) == 0) {
String timeId = IdWorker.getTimeId();
//特定格式的时间ID
String timeId = IdWorker.getTimeId().substring(0,32);
buyOrder.setOrderSn(timeId);
if("4".equals(buyOrder.getPaymentMethod())){
buyOrder.setOrderStatus("1");
}
//todo 增加结束时间
buyOrder.setPaymentDate(new Date());
buyOrderService.save(buyOrder);
System.out.println("orderId====================>"+buyOrder.getOrderId());
for (BuyOrderDetailEntity buyOrderDetailEntity : list) {
buyOrderDetailEntity.setOrderId(buyOrder.getOrderId());
buyOrderDetailEntity.setUserId(buyOrder.getUserId());
@@ -182,7 +215,6 @@ public class BuyOrderController {
// 更改购物车 状态
List<OrderCartEntity> list1 = orderCartService.getBaseMapper().selectList(new QueryWrapper<OrderCartEntity>()
.eq("user_id", buyOrder.getUserId()).eq("product_id", buyOrderDetailEntity.getProductId()));
if (list1.size() > 0){
List<Integer> collect = list1.stream().map(orderCartEntity -> {
Integer cartId = orderCartEntity.getCartId();
@@ -205,8 +237,26 @@ public class BuyOrderController {
one.setOrderSn(buyOrder.getOrderSn());
couponHistoryService.updateById(one);
}
if("4".equals(buyOrder.getPaymentMethod())){
MyUserEntity user = this.myUserService.getById(buyOrder.getUserId());
if(user.getPeanutCoin().compareTo(realMoney) >= 0){
user.setPeanutCoin(user.getPeanutCoin().subtract(realMoney));
this.myUserService.updateById(user);
// 添加消费信息
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
transactionDetailsEntity.setRemark("购买健康超市用品!订单编号为《 "+ buyOrder.getOrderSn() + "");
transactionDetailsEntity.setUserId(user.getId());
transactionDetailsEntity.setUserName(user.getNickname());
transactionDetailsEntity.setChangeAmount(realMoney.negate());
transactionDetailsEntity.setUserBalance(user.getPeanutCoin());
transactionDetailsEntity.setTel(user.getTel());
transactionDetailsEntity.setOrderType("购买健康超市用品!");
transactionDetailsService.save(transactionDetailsEntity);
}else{
return R.error("余额不足!");
}
}
}
}catch (Exception e){
e.printStackTrace();
@@ -214,13 +264,261 @@ public class BuyOrderController {
l.unlock();
}
return R.ok().put("orderSn",buyOrder.getOrderSn()).put("money",realMoney);
}
/**
* 修改
* 修改购买书籍(赠送电子书,加鉴权)
* @param buyOrder 订单表
* @return
*/
@RequestMapping("/buysave")
@Transactional
public R buysave(@RequestBody BuyOrderEntity buyOrder) {
BigDecimal realMoney = new BigDecimal(0);
Lock l = new ReentrantLock();
l.lock();
try {
List<BuyOrderDetailEntity> products = buyOrder.getProducts();
BigDecimal bigDecimal1 = new BigDecimal(0);
ArrayList<BuyOrderDetailEntity> list = new ArrayList<>();
// 遍历商品 查询价格
for (BuyOrderDetailEntity buyOrderDetail : products) {
BuyOrderDetailEntity buyOrderDetailEntity = new BuyOrderDetailEntity();
Integer productId = buyOrderDetail.getProductId();
ShopProductEntity product = shopProductService.getById(productId);
BigDecimal price = product.getPrice();
Integer quantity = buyOrderDetail.getQuantity();
//价格*数量 = 单价*购买数量赋值给bigDecimal1
BigDecimal bigDecimal = new BigDecimal(price.doubleValue() * quantity);
bigDecimal1 = bigDecimal1.add(bigDecimal);
if (product.getProductStock() - buyOrderDetail.getQuantity() < 0) {
return R.error(500, "库存不足");
}
// 改写 商品库存
product.setProductStock(product.getProductStock() - buyOrderDetail.getQuantity());
product.setSumSales(product.getSumSales() + buyOrderDetail.getQuantity());
shopProductService.updateById(product);
//buyOrderDetail 对象中的属性值复制到 buyOrderDetailEntity 对象中的属性值中
BeanUtils.copyProperties(buyOrderDetail, buyOrderDetailEntity);
buyOrderDetailEntity.setProductName(product.getProductName());
buyOrderDetailEntity.setProductPrice(product.getPrice());
buyOrderDetailEntity.setAddressId(buyOrder.getAddressId());
buyOrderDetailEntity.setProductUrl(product.getProductImages());
buyOrderDetailEntity.setOrderStatus("0");
list.add(buyOrderDetailEntity);
}
//优惠券Id couponId
Integer couponId = buyOrder.getCouponId();
if (couponId != null) {
CouponHistoryEntity byId = couponHistoryService.getById(couponId);
CouponEntity coupon = couponService.getById(byId.getCouponId());
BigDecimal amount = coupon.getCouponAmount();
bigDecimal1 = bigDecimal1.subtract(amount);
}
if (buyOrder.getShippingMoney() != null) {
bigDecimal1 = bigDecimal1.add(buyOrder.getShippingMoney());
}
// 减去优惠券金额
realMoney = buyOrder.getRealMoney();
if (bigDecimal1.compareTo(realMoney) == 0) {
//特定格式的时间ID
String timeId = IdWorker.getTimeId().substring(0, 32);
buyOrder.setOrderSn(timeId);
if ("4".equals(buyOrder.getPaymentMethod())) {
buyOrder.setOrderStatus("1");
}
//todo 增加结束时间
buyOrder.setPaymentDate(new Date());
buyOrderService.save(buyOrder);
for (BuyOrderDetailEntity buyetailEntity : list) {
buyetailEntity.setOrderId(buyOrder.getOrderId());
buyetailEntity.setUserId(buyOrder.getUserId());
// 判断结算状态 下单 位置 0- 商品页直接下单 1- 购物车结算
String buyType = buyOrder.getBuyType();
if (buyType.equals("1")) {
// 更改购物车 状态
List<OrderCartEntity> list1 = orderCartService.getBaseMapper().selectList(new QueryWrapper<OrderCartEntity>()
.eq("user_id", buyOrder.getUserId()).eq("product_id", buyetailEntity.getProductId()));
//将购物车列表转换为流,并从中提取每个购物车的 cartId。removeByIds() 方法从数据库中删除这些购物车记录。
if (list1.size() > 0) {
List<Integer> collect = list1.stream().map(orderCartEntity -> {
Integer cartId = orderCartEntity.getCartId();
return cartId;
}).collect(Collectors.toList());
orderCartService.removeByIds(collect);
}
}
}
buyOrderDetailService.saveBatch(list);
if (couponId != null) {
//更改优惠券状态
CouponHistoryEntity one = couponHistoryService.getById(couponId);
one.setUseStatus(1);
one.setUseTime(new Date());
one.setOrderId(Long.valueOf(buyOrder.getOrderId()));
one.setOrderSn(buyOrder.getOrderSn());
couponHistoryService.updateById(one);
}
// 购买书籍直接赠送电子书听书
TransactionDetailsEntity transaction = new TransactionDetailsEntity();
//避免重复购买
TransactionDetailsEntity entity = transactionDetailsService.getBaseMapper().selectOne(new QueryWrapper<TransactionDetailsEntity>().eq("user_id", transaction.getUserId())
.eq("relation_id", transaction.getRelationId()));
if (entity != null) {
return R.error("余额不足,请充值!!!!!!!!!!!!!!!!");
}
List<BuyOrderDetailEntity> produ = buyOrder.getProducts();
// 遍历商品 查询价格
for (BuyOrderDetailEntity buyOrdr : produ) {
Integer pId = buyOrdr.getProductId();
ShopProductEntity product1 = shopProductService.getById(pId);
// 如果是虚拟币购买 减少用户的虚拟币数量
if ("4".equals(buyOrder.getPaymentMethod())) {
MyUserEntity user = this.myUserService.getById(buyOrder.getUserId());
if (user.getPeanutCoin().compareTo(realMoney) >= 0) {
user.setPeanutCoin(user.getPeanutCoin().subtract(realMoney));
this.myUserService.updateById(user);
// 添加消费信息
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
transactionDetailsEntity.setRemark("购买健康超市用品!订单编号为《 " + buyOrder.getOrderSn() + "");
transactionDetailsEntity.setUserId(user.getId());
transactionDetailsEntity.setUserName(user.getNickname());
transactionDetailsEntity.setChangeAmount(realMoney.negate());
transactionDetailsEntity.setUserBalance(user.getPeanutCoin());
transactionDetailsEntity.setTel(user.getTel());
transactionDetailsEntity.setOrderType("赠送本书听书图书");
transactionDetailsService.save(transactionDetailsEntity);
} else {
return R.error("余额不足!");
}
}
}
// }
for (BuyOrderDetailEntity buyOrderDetail : products) {
Integer productId = buyOrderDetail.getProductId();
ShopProductEntity product = shopProductService.getById(productId);
// 如果不等于空 则进行往下走
String authorName = "";
String bookId = product.getBookId();
if(null != bookId && !"".equals(bookId)){
List<String> bkids = new ArrayList<String>();
if(bookId.indexOf(",") == -1){
bkids.add(bookId);
}else {
for(String idObj : bookId.split(",")){
bkids.add(idObj);
}
}
for(String b_id : bkids){
if (b_id != null) {
List<BookEntity> book = bookService.getBaseMapper().selectList(new QueryWrapper<BookEntity>().eq("id", b_id));
for (BookEntity bo : book) {
Integer id = bo.getId();
String name = bo.getName();
String images = bo.getImages();
String authorId = bo.getAuthorId();
if (book != null) {
UserEbookBuyEntity userEbookBuyEntity = new UserEbookBuyEntity();
userEbookBuyEntity.setUserId(Integer.valueOf(buyOrder.getUserId()));
userEbookBuyEntity.setBookId(Integer.valueOf(id));
String[] authorIds = authorId.split(",");
List<String> authorList = Arrays.asList(authorIds);
List<AuthorEntity> authorEntities = authorService.getBaseMapper().selectList(new QueryWrapper<AuthorEntity>().in("id", authorList));
//购买书籍表 userId bookName 商品订单详情表 userId productName
List<UserEbookBuyEntity> userId = userEbookBuyService.getBaseMapper().selectList(new QueryWrapper<UserEbookBuyEntity>()
.eq("user_Id", buyOrder.getUserId())
.eq("book_id", id));
for (AuthorEntity authorEntity : authorEntities) {
authorName += "," + authorEntity.getAuthorName();
}
//查询dengyu则往下执行赠送电子书详情
if (userId != null && !userId.isEmpty()) {
// 如果userId不等于空则不赠送图书不执行任何方法
// return R.ok("此书已存在于您的书架");
} else {
authorName = authorName.startsWith(",") ? authorName.substring(1) : authorName;
userEbookBuyEntity.setAuthor(authorName);
userEbookBuyEntity.setImage(images);
userEbookBuyEntity.setPayStatus("赠送成功");
//这里后期需要修改字段内容
userEbookBuyEntity.setPayType("point");
userEbookBuyEntity.setPayTime(new Date());
userEbookBuyEntity.setBookName(name);
userEbookBuyService.save(userEbookBuyEntity);
//判断是否加入书架如果没有就加入听书书架
Integer integer = bookShelfService.getBaseMapper().selectCount(new QueryWrapper<BookShelfEntity>()
.eq("book_id", id)
.eq("user_id", userId));
//如果integer<0代表数据库没有这条数据则添加有就不执行下面操作
if (integer < 0) {
//保存到书架表中
BookShelfEntity bookShelfEntity = new BookShelfEntity();
bookShelfEntity.setBookId(id);
bookShelfEntity.setBookName(name);
bookShelfEntity.setUserId(buyOrder.getUserId());
bookShelfEntity.setCreateTime(new Date());
bookShelfService.save(bookShelfEntity);
}
// }
// else {
// return R.error().put("赠送失败",buyOrder.getOrderSn());
// }
}
}
}
}
}
}
}
}
}catch (Exception e){
e.printStackTrace();
}finally {
l.unlock();
}
return R.ok().put("orderSn",buyOrder.getOrderSn()).put("money",realMoney);
}
/**
* 修改
*/
@RequestMapping("/update")
// @RequiresPermissions("book:buyorder:update")
public R update(@RequestBody BuyOrderEntity buyOrder){
@@ -312,21 +610,35 @@ public class BuyOrderController {
return R.ok();
}
@RequestMapping("/randomOrderCode")
@Transactional
public R randomOrderCode(@RequestBody BuyOrderEntity buyOrder){
// String re= String.valueOf(buyOrderService.randomOrderCode(buyOrder));
// buyOrderService.save(re);
return R.ok();
}
/**
* 充值专用订单生成接口
*/
@RequestMapping("/rechargeSave")
@Transactional
// @RequiresPermissions("book:buyorder:save")
public R rechargeSave(@RequestBody BuyOrderEntity buyOrder){
String timeId = IdWorker.getTimeId();
buyOrder.setOrderSn(timeId);
buyOrderService.save(buyOrder);
return R.ok().put("orderSn",timeId);
}
String timeId = IdWorker.getTimeId().substring(0,32);
buyOrder.setOrderSn(timeId);
buyOrderService.save(buyOrder);
return R.ok().put("orderSn",timeId);
}
@@ -334,16 +646,24 @@ public class BuyOrderController {
* 信息
*/
@RequestMapping("/appGetOrderInfo/{type}")
// @RequiresPermissions("book:buyorder:info")
// @RequiresPermissions("book:buyorder:info") 就是这个
public R appGetOrderInfo(@PathVariable String type , @RequestParam("orderId") Integer orderId){
BuyOrderEntity buyOrder = buyOrderService.getById(orderId);
List<BuyOrderDetailEntity> orderDetail = null;
if("1".equals(type)){
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>()
.eq("order_id", orderId));
}else{
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>()
.eq("order_id", orderId).groupBy("shipping_sn"));
}
for (BuyOrderDetailEntity buyOrderDetailEntity : orderDetail) {
@@ -351,10 +671,40 @@ public class BuyOrderController {
buyOrderDetailEntity.setImage(prod.getProductImages());
}
buyOrder.setProducts(orderDetail);
return R.ok().put("buyOrder", buyOrder);
List<BuyOrderDetailEntity> resultOrder = new ArrayList<BuyOrderDetailEntity>();
Set<String> sn_no = new HashSet<String>();
for(BuyOrderDetailEntity buyOrderDetailEntity : orderDetail){
resultOrder.add(buyOrderDetailEntity);
sn_no.add(buyOrderDetailEntity.getShippingSn());
}
UserRecordEntity userRecordEntity = userRecordService.getBaseMapper().selectOne(new QueryWrapper<UserRecordEntity>()
.eq("orderSn", buyOrder.getOrderSn())
.eq("userid", buyOrder.getUserId())
.eq("orderdid",buyOrder.getOrderId())
.last("LIMIT 1"));
Integer id =null;
if (userRecordEntity != null) {
id = userRecordEntity.getId();
}
buyOrder.setProducts(resultOrder);
Date createDate = buyOrder.getCreateTime();
return R.ok().put("buyOrder", buyOrder).put("CreateTime",createDate).put("userRecordid",id);
}
/**
@@ -390,15 +740,7 @@ public class BuyOrderController {
}
/**
* 后台取消订单接口
*/
@RequestMapping("/cancelFMS")
public R cancelFMS(@RequestParam Map<String,Object> params){
buyOrderService.cancelFMS(params.get("orderSn").toString(), params.get("shipperCode").toString(),
params.get("expNo").toString());
return R.ok();
}
/**
@@ -408,13 +750,15 @@ public class BuyOrderController {
public R queryFMS(@RequestParam Map< String,String> params){
List<BuyOrderDetailEntity> detailList = this.buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>().eq("order_id", params.get("orderId")));
List<JSONObject> jsonList = new ArrayList<>();
JSONObject jsonObj =null;
for (BuyOrderDetailEntity detail : detailList) {
JSONObject jsonObj = buyOrderService.queryFMS(detail.getShipperCode(), detail.getShippingSn());
jsonObj = buyOrderService.queryFMS(detail.getShipperCode(), detail.getShippingSn());
if(Objects.isNull(jsonObj)){
return R.ok("暂未查到物流信息!");
}
jsonObj.put("ShipperName",detail.getShipperName());
jsonList.add(jsonObj);
}
return R.ok().put("rntStr",jsonList);
}
@@ -456,9 +800,37 @@ public class BuyOrderController {
@RequestMapping("/blendSendFMS/{shipperCode}")
public R blendSendFMS(@PathVariable("shipperCode") String shipperCode,@RequestParam("shipperName") String shipperName,@RequestBody Integer[] orderDetailIds){
buyOrderService.blendSendFMS(orderDetailIds,shipperCode,shipperName);
return R.ok();
}
/**
* 后台取消订单接口
*/
@RequestMapping("/cancelFMS")
public R cancelFMS(@RequestParam Map<String,Object> params){
buyOrderService.cancelFMS(params.get("orderSn").toString(), params.get("shipperCode").toString(),
params.get("expNo").toString());
// return R.ok()
return R.ok().put("paramsTEXT",params);
}
/**
* 去重查询可打印面单
*
* @param params
* @return
*/
@RequestMapping("/querySheetPage")
public R querySheetPage(@RequestParam Map<String, Object> params){
PageUtils page = buyOrderDetailService.querySheet(params);
return R.ok().put("page", page);
}
}

View File

@@ -32,6 +32,10 @@ public class BuyOrderDetailController {
@Autowired
private BuyOrderDetailService buyOrderDetailService;
/**
* 列表
*/
@@ -43,7 +47,17 @@ public class BuyOrderDetailController {
return R.ok().put("page", page);
}
/**
* 查询已购买书籍
* @param params
* @return
*/
@RequestMapping("/querybuy")
public R querybuy(@RequestParam Map<String, Object> params){
PageUtils page = buyOrderDetailService.querybuy(params);
return R.ok().put("page", page);
}
/**
* 去重查询可打印面单
*
@@ -62,7 +76,6 @@ public class BuyOrderDetailController {
* 信息
*/
@RequestMapping("/info/{allOrderId}")
// @RequiresPermissions("book:buyorderdetail:info")
public R info(@PathVariable("allOrderId") Long allOrderId){
BuyOrderDetailEntity buyOrderDetail = buyOrderDetailService.getById(allOrderId);

View File

@@ -75,6 +75,11 @@ public class CouponController {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE,Integer.valueOf(coupon.getValidity()).intValue());
coupon.setExpirationDate(cal.getTime());
}else{
Calendar cal = Calendar.getInstance();
cal.setTime(coupon.getTakeEffectDate());
cal.add(Calendar.DATE,Integer.valueOf(coupon.getValidity()).intValue());
coupon.setExpirationDate(cal.getTime());
}
couponService.save(coupon);
@@ -90,10 +95,14 @@ public class CouponController {
if(0 == coupon.getTakeEffectType()){
coupon.setTakeEffectDate(new Date());
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE,Integer.valueOf(coupon.getValidity()).intValue());
coupon.setExpirationDate(cal.getTime());
}else{
Calendar cal = Calendar.getInstance();
cal.setTime(coupon.getTakeEffectDate());
cal.add(Calendar.DATE,Integer.valueOf(coupon.getValidity()).intValue());
coupon.setExpirationDate(cal.getTime());
}
couponService.updateById(coupon);

View File

@@ -11,25 +11,23 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.common.utils.MD5Utils;
import com.peanut.modules.book.entity.CouponHistoryEntity;
import com.peanut.modules.book.entity.PayPaymentOrderEntity;
import com.peanut.modules.book.entity.TransactionDetailsEntity;
import com.peanut.modules.book.service.CouponHistoryService;
import com.peanut.modules.book.service.PayPaymentOrderService;
import com.peanut.modules.book.service.TransactionDetailsService;
import com.peanut.modules.book.entity.*;
import com.peanut.modules.book.service.*;
import com.peanut.modules.sys.service.SysUserTokenService;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.models.auth.In;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.peanut.modules.book.entity.MyUserEntity;
import com.peanut.modules.book.service.MyUserService;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
@@ -48,12 +46,18 @@ public class MyUserController {
@Autowired
private MyUserService userService;
@Autowired
private BuyOrderService buyOrderService;
@Autowired
private StringRedisTemplate redisTemplate;
@Autowired
private SysUserTokenService sysUserTokenService;
@Autowired
private CouponHistoryService couponHistoryService;
@Autowired
private BookBuyConfigService bookBuyConfigService;
@Autowired
private BookService bookService;
@Autowired
private TransactionDetailsService transactionDetailsService;
/**
@@ -107,8 +111,10 @@ public class MyUserController {
String password = user.getPassword();
String saltMD5 = MD5Utils.getSaltMD5(password);
user.setPassword(saltMD5);
userService.updateById(user);
}else{
userService.update(user);
}
userService.updateById(user);
return R.ok();
}
@@ -321,7 +327,9 @@ public class MyUserController {
String cellPhone = jsonObject.getJSONObject("obj").getString("cellPhone");
String customerIcons = jsonObject.getJSONObject("obj").getString("customerIcons");
String nameCN = jsonObject.getJSONObject("obj").getString("nameCN");
System.out.println(yljkOid);
// String password = jsonObject.getJSONObject("obj").getString("pass");
System.out.println("=====================yljkOid=============================="+yljkOid);
//查询 当前 花生账号 和 当前绑定的 一路健康账号是否有绑定 关系
@@ -398,7 +406,7 @@ public class MyUserController {
myUserEntity.setAvatar(customerIcons);
userService.save(myUserEntity);
R r = sysUserTokenService.createToken(myUserEntity.getId());
return R.ok().put("userInfo",myUserEntity).put("token",r);
return R.ok().put("userInfo",myUserEntity).put("token",r);
}
//判断当前手机号用户是否绑定过一路健康账号
if (userEntity.getYljkOid() != null){
@@ -411,7 +419,9 @@ public class MyUserController {
userEntity.setAvatar(customerIcons);
userService.updateById(userEntity);
R r = sysUserTokenService.createToken(userEntity.getId());
// todo 为什么验证成功以后不能实现页面跳转登录 R返回更新生成的token和电话
return R.ok().put("userInfo",userEntity).put("token",r);
}
@RequestMapping("/test")
@@ -426,10 +436,19 @@ public class MyUserController {
*/
@RequestMapping("/buyEbook")
public R buyEbook(@RequestParam Map<String, Object> params){
String msg = "";
String bookId = (String) params.get("bookId");
String userId = (String) params.get("userId");
String couponId = (String) params.get("couponId");
String msg = userService.buyEbook(userId, bookId,couponId);
BookEntity book = this.bookService.getById(bookId);
MyUserEntity user = this.userService.getById(userId);
if(1 == book.getIsVip()){
if(!"1".equals(user.getVip())){
msg ="当前书籍为VIP书籍请开通VIP后购买";
return R.ok().put("msg", msg).put("status","error");
}
}
msg = userService.buyEbook(userId, bookId,couponId);
if (msg.equals("当前书籍以购买,请勿重复购买!")) {
return R.ok().put("msg",msg).put("status","error");
@@ -452,12 +471,12 @@ public class MyUserController {
MyUserEntity byId = userService.getById(id);
int i = 0;
if (pointType.equals("0")) {
i = byId.getPeanutCoin() + Integer.valueOf(pointAmount);
byId.setPeanutCoin(i);
i = byId.getPeanutCoin().intValue() + Integer.valueOf(pointAmount);
byId.setPeanutCoin(new BigDecimal(i));
}else {
i = byId.getPeanutCoin() - Integer.valueOf(pointAmount);
i = byId.getPeanutCoin().intValue() - Integer.valueOf(pointAmount);
if (i >= 0) {
byId.setPeanutCoin(i);
byId.setPeanutCoin(new BigDecimal(i));
}else {
return R.error("余额不足!扣除失败!");
}
@@ -466,11 +485,15 @@ public class MyUserController {
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
transactionDetailsEntity.setUserId(Integer.valueOf(id));
transactionDetailsEntity.setChangeAmount(new BigDecimal(Integer.valueOf(pointAmount)));
transactionDetailsEntity.setOrderType("后台充值操作");
transactionDetailsEntity.setOrderType("后台充扣操作");
transactionDetailsEntity.setTel(byId.getTel());
transactionDetailsEntity.setUserName(byId.getNickname());
transactionDetailsEntity.setNote(params.get("note"));
if (pointType.equals("0")) {
transactionDetailsEntity.setChangeAmount(new BigDecimal(Integer.valueOf(pointAmount)));
transactionDetailsEntity.setRemark("充值");
}else {
transactionDetailsEntity.setChangeAmount(new BigDecimal(Integer.valueOf(pointAmount)).negate());
transactionDetailsEntity.setRemark("扣费");
}
BigDecimal balance = new BigDecimal(i);
@@ -479,7 +502,7 @@ public class MyUserController {
// 插入 花生币 充值记录
// PayPaymentOrderEntity payPaymentOrderEntity = new PayPaymentOrderEntity();
// IosPayOrderEntity payPaymentOrderEntity = new IosPayOrderEntity();
// payPaymentOrderEntity.setUserId(Integer.valueOf(id));
// payPaymentOrderEntity.setRealAmount(new BigDecimal(byId.getPeanutCoin()));
// payPaymentOrderEntity.setRechargeAmount(new BigDecimal(i));
@@ -487,9 +510,72 @@ public class MyUserController {
// payPaymentOrderEntity.setRechargeStatus("success");
// payPaymentOrderEntity.setSuccessTime(new Date());
// payPaymentOrderService.save(payPaymentOrderEntity);
userService.updateById(byId);
return R.ok();
}
/**
* 使用虚拟币开通vip
* @return
*/
@RequestMapping("/openVipByVirtualCoin")
public R openVipByVirtualCoin(@RequestParam Map<String,Object> params){
Integer configId = Integer.valueOf(params.get("configId").toString());
String orderSn = params.get("orderSn").toString();
Integer userId = Integer.valueOf(params.get("userId").toString());
// 根据userId查找用户信息
MyUserEntity user = this.userService.getById(userId);
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(configId);
String month = bookBuyConfigEntity.getMonth();
BigDecimal amount = new BigDecimal(bookBuyConfigEntity.getRealMoney());
if(user.getPeanutCoin().compareTo(amount) >= 0){
user.setPeanutCoin(user.getPeanutCoin().subtract(amount));
this.userService.updateById(user);
// 添加消费信息
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
transactionDetailsEntity.setRemark("购买"+bookBuyConfigEntity.getType()+",金额"+bookBuyConfigEntity.getMoney());
transactionDetailsEntity.setUserId(user.getId());
transactionDetailsEntity.setUserName(user.getNickname());
transactionDetailsEntity.setChangeAmount(amount.negate());
transactionDetailsEntity.setUserBalance(user.getPeanutCoin());
transactionDetailsEntity.setTel(user.getTel());
transactionDetailsEntity.setOrderType("购买会员!");
transactionDetailsService.save(transactionDetailsEntity);
userService.openMember(userId,Integer.valueOf(month));
// 插入 开通记录
buyOrderService.updateOrderStatus(userId,orderSn,"2");
}else{
return R.error(500,"余额不足,请检查后操作!");
}
return R.ok();
}
/**
* @Description: app微信登陆
* @Author: z.hw
*/
@RequestMapping("/appUserAuthorLogin")
// @ApiOperation(value = "getUserInfoByAppCode", notes = "不分页", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
// @ApiResponses(value = {
// @ApiResponse(code = 404, message = "Not Found"),
// @ApiResponse(code = 400, message = "No Name Provided"),
// })
public R getUserInfoByApp(@Validated @RequestBody UserAppAuthorEntity userAppAuthorEntity) {
return userService.getUserInfoByApp(userAppAuthorEntity);
}
}

View File

@@ -74,7 +74,6 @@ public class OrderCartController {
// @RequiresPermissions("book:ordercart:update")
public R update(@RequestBody OrderCartEntity orderCart){
orderCartService.updateById(orderCart);
return R.ok();
}
@@ -96,7 +95,6 @@ public class OrderCartController {
// @RequiresPermissions("book:ordercart:delete")
public R getCartList(@RequestParam("userId") Integer userId){
List<ShopCartVo> cartList = orderCartService.getCartList(userId);
return R.ok().put("cartList",cartList);
}

View File

@@ -101,6 +101,7 @@ public class PublisherController {
@RequestMapping("/save")
@RequiresPermissions("book:publisher:save")
public R save(@RequestBody PublisherEntity publisher){
publisher.setDelFlag(0);
publisherService.save(publisher);
return R.ok();

View File

@@ -116,7 +116,6 @@ public class ShopCategoryController {
@RequestMapping("/getOneLevel")
public R getOneLevel(){
List<ShopCategoryEntity> list = shopCategoryService.getOneLevel();
return R.ok().put("list",list);
}
@@ -127,7 +126,6 @@ public class ShopCategoryController {
@RequestMapping("/getTwoLevel")
public R getTwoLevel(@RequestParam("catId") Integer catId){
List<ShopCategoryEntity> list = shopCategoryService.getTwoLevel(catId);
return R.ok().put("list",list);
}

View File

@@ -1,22 +1,20 @@
package com.peanut.modules.book.controller;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.modules.book.entity.BookEntity;
import com.peanut.modules.book.entity.BuyOrderDetailEntity;
import com.peanut.modules.book.service.BookService;
import com.peanut.modules.book.service.BuyOrderDetailService;
import com.peanut.modules.book.service.ShopCategoryService;
import com.peanut.modules.book.vo.ShopProductVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.peanut.modules.book.entity.ShopProductEntity;
import com.peanut.modules.book.service.ShopProductService;
import com.peanut.common.utils.PageUtils;
@@ -38,7 +36,10 @@ public class ShopProductController {
private ShopProductService shopProductService;
@Autowired
private ShopCategoryService shopCategoryService;
@Autowired
private BuyOrderDetailService buyOrderDetailService;
@Autowired
private BookService bookService;
/**
* 列表
*/
@@ -46,45 +47,209 @@ public class ShopProductController {
// @RequiresPermissions("book:shopproduct:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = shopProductService.queryPage(params);
return R.ok().put("page", page);
}
/**
* 列表
*/
@RequestMapping("/selectList")
public R selectList(@RequestParam Map<String, Object> params){
PageUtils page = shopProductService.selectListqueryPage(params);
return R.ok().put("page", page);
}
//新书
@RequestMapping("/getNewBook")
public R getNewBook(@RequestParam Map<String, Object> params) {
PageUtils page = shopProductService.getNewBook(params);
return R.ok().put("page", page);
}
/**
* 未购买书列表
* @param userId 用户id
* @return
*/
//todo 9.7未调试
@RequestMapping("/booklist")
public R booklistss(@RequestParam("userId") Integer userId
) {
//查询已购买的书籍
List<BuyOrderDetailEntity> buyOrderDetailEntities = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>()
.eq("user_id", userId));
//hashset不重复 且无序
Set<String> purchasedProductIds = new HashSet<>();
ArrayList<Object> list = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
for (BuyOrderDetailEntity buyOrderDetailEntity : buyOrderDetailEntities) {
map.put("ProductId", String.valueOf(buyOrderDetailEntity.getProductId()));
list.add(map);
//去重取出以后买书籍的id
purchasedProductIds.add(String.valueOf(buyOrderDetailEntity.getProductId()));
}
//查询商品表并过滤已购买商品id,根据时间倒叙展示
List<ShopProductEntity> allProductEntities = shopProductService.getBaseMapper().selectList(new QueryWrapper<ShopProductEntity>()
.notIn("product_id", purchasedProductIds)
.orderByDesc("create_time")
// .notLike("book_ids",",")
.isNotNull("book_ids")
);
List lists = new ArrayList<>();
for (ShopProductEntity product : allProductEntities) {
Map<String, Object> productMap = new HashMap<>();
productMap.put("product",product);
lists.add(productMap);
}
return R.ok().put("pages", lists); // 返回未购买的书籍分页
}
@RequestMapping("/bookinfo/{productId}")
public R bookinfo(@PathVariable("productId") Integer productId){
ShopProductEntity shopProductEntity = shopProductService.getBaseMapper().selectOne(new QueryWrapper<ShopProductEntity>().eq("book_ids", productId));
Integer poid = shopProductEntity.getProductPid();
List<Integer> poids = shopCategoryService.findPoid(poid);
shopProductEntity.setPoids(poids);
ArrayList<String> list = new ArrayList<>();
String bookId = shopProductEntity.getBookId();
list.add(bookId);
shopProductEntity.setBookids(list);
String bookId1 = shopProductEntity.getBookId();
ArrayList<Map<String, String>> imagesUrl = new ArrayList<Map<String,String>>();
for(String s : bookId1.split(",")){
if(null != s && !"".equals(s)){
BookEntity book = this.bookService.getById(s);
Map<String, String> urlMap = new HashMap<String, String>();
// urlMap.put("",s,book.getImages());
urlMap.put("id",s);
urlMap.put("images",book.getImages());
urlMap.put("name",book.getName());
imagesUrl.add(urlMap)
;
}
}
shopProductEntity.setBookidsimages(imagesUrl);
return R.ok().put("shopProduct", shopProductEntity);
}
/**
* 信息
* @param productId
* @return
*/
@RequestMapping("/info/{productId}")
// @RequiresPermissions("book:shopproduct:info")
public R info(@PathVariable("productId") Integer productId){
ShopProductEntity shopProduct = shopProductService.getById(productId);
Integer poid = shopProduct.getProductPid();
ShopProductEntity shopProductEntity = shopProductService.getBaseMapper().selectOne(new QueryWrapper<ShopProductEntity>().eq("product_id", productId));
Integer poid = shopProductEntity.getProductPid();
String bookids = shopProductEntity.getBookId();
List<Integer> poids = shopCategoryService.findPoid(poid);
shopProduct.setPoids(poids);
return R.ok().put("shopProduct", shopProduct);
shopProductEntity.setPoids(poids);
ArrayList<String> list = new ArrayList<>();
String bookId = shopProductEntity.getBookId();
list.add(bookId);
shopProductEntity.setBookids(list);
String bookId1 = shopProductEntity.getBookId();
ArrayList<Map<String, String>> imagesUrl = new ArrayList<Map<String,String>>();
ArrayList<Map<String, String>> imagesUrls = new ArrayList<Map<String,String>>();
Boolean canListen=null;
for(String s : bookId1.split(",")){
if(null != s && !"".equals(s)){
BookEntity book = this.bookService.getById(s);
String canListen1 =String.valueOf(book.getCanListen()) ;
Map<String, String> urlMap = new HashMap<String, String>();
urlMap.put("id",s);
//如果图书删除了,商品页面会报错
urlMap.put("images",book.getImages());
urlMap.put("name",book.getName());
urlMap.put("canListen",canListen1);
imagesUrl.add(urlMap)
;
}
}
shopProductEntity.setBookidsimages(imagesUrl);
return R.ok().put("shopProduct", shopProductEntity);
}
/**
* 保存
*/
@RequestMapping("/save")
// @RequiresPermissions("book:shopproduct:save")
public R save(@RequestBody ShopProductEntity shopProduct){
shopProduct.setCreateTime(new Date());
//用list集合接收数组转String类型字符串
String bkids = "";
for(String s : shopProduct.getBookids()){
bkids += s+",";
}
if (bkids!=null &&!bkids.isEmpty()){
String substring = bkids.substring(0, bkids.length() - 1);
shopProduct.setBookId(substring);
}
shopProduct.setBookId("");
shopProduct.setCreateTime(new Date());
shopProductService.save(shopProduct);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
// @RequiresPermissions("book:shopproduct:update")
@RequestMapping("/update")
public R update(@RequestBody ShopProductEntity shopProduct){
shopProductService.updateById(shopProduct);
String bkids = "";
for(String s : shopProduct.getBookids()){
bkids += s+",";
}
if (bkids!=null &&!bkids.isEmpty()){
String substring = bkids.substring(0, bkids.length() - 1);
shopProduct.setBookId(substring);
}else {
shopProduct.setBookId("");
}
shopProductService.updateById(shopProduct);
return R.ok();
}
@@ -115,8 +280,10 @@ public class ShopProductController {
*/
@RequestMapping("/appGetCategoryList")
public R appGetCategoryList(@RequestParam("catId") Integer catId){
if(catId == 0){
catId = null;
}
List<ShopProductEntity> list = shopProductService.appGetCategoryList(catId);
return R.ok().put("list", list);
}

View File

@@ -1,53 +1,135 @@
package com.peanut.modules.book.controller;
import java.util.Arrays;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.peanut.modules.book.entity.UserEbookBuyEntity;
import com.peanut.modules.book.service.UserEbookBuyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
import com.peanut.modules.book.entity.BookEntity;
import com.peanut.modules.book.entity.UserEbookBuyEntity;
import com.peanut.modules.book.service.BookService;
import com.peanut.modules.book.service.UserEbookBuyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
* 用户购买书籍表
*
* @author yl
* @email yl328572838@163.com
* @date 2022-10-18 16:28:20
*
*/
@RestController
@RequestMapping("book/userebookbuy")
public class UserEbookBuyController {
@Autowired
private UserEbookBuyService userEbookBuyService;
@Autowired
private BookService bookService;
/**
* 列表
*/
@RequestMapping("/list")
// @RequiresPermissions("book:userebookbuy:list")
public R list(@RequestParam Map<String, Object> params){
String userId = (String) params.get("userId");
PageUtils page = userEbookBuyService.queryPage(params);
return R.ok().put("page", page);
}
/**
* 列表
*/
@RequestMapping("/appbooklist")
public R appbooklist(@RequestParam("userId") Integer userId) {
String user = String.valueOf(userId);
ArrayList<Object> maplist = new ArrayList<>();
ArrayList<Integer> list = new ArrayList<>();
List<UserEbookBuyEntity> user_id = userEbookBuyService.getBaseMapper().selectList(new QueryWrapper<UserEbookBuyEntity>().eq("user_id", user));
if (user_id==null){
return R.error("您打卡列表暂未添加内容");
}
for (UserEbookBuyEntity userEbookBuyEntity : user_id) {
Integer bookId = userEbookBuyEntity.getBookId();
list.add(bookId);
}
int index =0;
for (Object S : list) {
List<BookEntity> books = bookService.getBaseMapper().selectList(new QueryWrapper<BookEntity>()
.eq("clock_in", 1)
.eq("id", S));
for (BookEntity book : books) {
Map<String,Object> map = new HashMap<>();
Integer id = book.getId();
map.put("book",book);
index++;
maplist.add(map);
}
}
if (maplist==null&&maplist.size() > 0){
return R.error("您暂未参与打卡");
}
return R.ok().put("resultlist",maplist).put("total",index);
}
@RequestMapping("/buylist")
public R buylist(@RequestParam Map<String, Object> params){
String userId = (String) params.get("id");
List list = new ArrayList<>();
List<UserEbookBuyEntity> user_id = userEbookBuyService.getBaseMapper().selectList(new QueryWrapper<UserEbookBuyEntity>().eq("user_id", userId));
for (UserEbookBuyEntity userEbookBuyEntity : user_id) {
Map<String, Object> map = new HashMap<>();
Integer bookId = userEbookBuyEntity.getBookId();
Integer userId1 = userEbookBuyEntity.getUserId();
String bookName = userEbookBuyEntity.getBookName();
Integer buyId = userEbookBuyEntity.getBuyId();
String image = userEbookBuyEntity.getImage();
String author = userEbookBuyEntity.getAuthor();
List<BookEntity> id = bookService.getBaseMapper().selectList(new QueryWrapper<BookEntity>().eq("id", bookId));
for (BookEntity bookEntity : id) {
String name = bookEntity.getName();
Boolean canListen = bookEntity.getCanListen();
map.put("canListen", canListen);
map.put("bookId",bookId);
map.put("userId",userId1);
map.put("bookName",bookName);
map.put("buyId",buyId);
map.put("image",image);
map.put("author",author);
list.add(map);
}
}
Collections.reverse(list);
return R.ok().put("page", list);
}
/**
* 信息
*/
@RequestMapping("/info/{buyId}")
// @RequiresPermissions("book:userebookbuy:info")
public R info(@PathVariable("buyId") Integer buyId){
UserEbookBuyEntity userEbookBuy = userEbookBuyService.getById(buyId);
@@ -58,8 +140,8 @@ public class UserEbookBuyController {
* 保存
*/
@RequestMapping("/save")
// @RequiresPermissions("book:userebookbuy:save")
public R save(@RequestBody UserEbookBuyEntity userEbookBuy){
userEbookBuyService.save(userEbookBuy);
return R.ok();
@@ -69,7 +151,6 @@ public class UserEbookBuyController {
* 修改
*/
@RequestMapping("/update")
// @RequiresPermissions("book:userebookbuy:update")
public R update(@RequestBody UserEbookBuyEntity userEbookBuy){
userEbookBuyService.updateById(userEbookBuy);
@@ -80,7 +161,6 @@ public class UserEbookBuyController {
* 删除
*/
@RequestMapping("/delete")
// @RequiresPermissions("book:userebookbuy:delete")
public R delete(@RequestBody Integer[] buyIds){
userEbookBuyService.removeByIds(Arrays.asList(buyIds));