From d80d598529ddb03b0cbea5276357170b55965e38 Mon Sep 17 00:00:00 2001 From: Cauchy Date: Wed, 11 Oct 2023 14:22:45 +0800 Subject: [PATCH 1/2] clock in and comment finished waitting for test --- .../controller/BookClockForumController.java | 90 +++++++++ .../BookClockinCommentController.java | 5 +- .../controller/BookClockinController.java | 22 +-- .../BookClockinPunchController.java | 181 +++++++----------- .../book/controller/BookTaskController.java | 1 - .../controller/UserBookClockController.java | 99 ++++++++++ .../book/dao/BookClockEntryChatDao.java | 4 +- .../modules/book/dao/BookClockinDao.java | 5 +- ...Entity.java => BookClockInChatEntity.java} | 4 +- ...ckinEntity.java => BookClockInEntity.java} | 3 +- .../book/entity/UserBookClockEntity.java | 2 +- .../service/BookClockEntryChatService.java | 4 +- .../book/service/BookClockinPunchService.java | 1 - .../book/service/BookClockinService.java | 4 +- .../service/impl/BookClockEntryChatImpl.java | 4 +- .../impl/BookClockinCommentServiceImpl.java | 1 - .../service/impl/BookClockinServiceImpl.java | 16 +- .../mq/Consumer/OrderCancelConsumer.java | 1 + .../resources/mapper/book/BookClockinDao.xml | 2 +- src/main/resources/weChatConfig.properties | 26 +-- 20 files changed, 311 insertions(+), 164 deletions(-) create mode 100644 src/main/java/com/peanut/modules/book/controller/BookClockForumController.java create mode 100644 src/main/java/com/peanut/modules/book/controller/UserBookClockController.java rename src/main/java/com/peanut/modules/book/entity/{BookClockEntryChatEntity.java => BookClockInChatEntity.java} (86%) rename src/main/java/com/peanut/modules/book/entity/{BookClockinEntity.java => BookClockInEntity.java} (95%) diff --git a/src/main/java/com/peanut/modules/book/controller/BookClockForumController.java b/src/main/java/com/peanut/modules/book/controller/BookClockForumController.java new file mode 100644 index 00000000..c8bea1c7 --- /dev/null +++ b/src/main/java/com/peanut/modules/book/controller/BookClockForumController.java @@ -0,0 +1,90 @@ +package com.peanut.modules.book.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.peanut.common.utils.R; +import com.peanut.modules.book.entity.BookClockInChatEntity; +import com.peanut.modules.book.entity.BookClockInEntity; +import com.peanut.modules.book.service.BookClockEntryChatService; +import com.peanut.modules.book.service.BookClockinService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Description: 打卡论坛 Controller + * @Author: Cauchy + * @CreateTime: 2023/10/11 + */ +@RestController("/book/clockForum") +public class BookClockForumController { + + @Autowired + private BookClockEntryChatService bookClockEntryChatService; + + @Autowired + private BookClockinService bookClockinService; + + /** + * 获取论坛内容 + * + * @param bookId + * @param day + * @return + */ + @RequestMapping(path = "/getPostingInfo", method = RequestMethod.GET) + public R getPostingInfo(@RequestParam("bookId") Integer bookId, + @RequestParam("day") Integer day) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("book_id", bookId); + queryWrapper.eq("day", day); + BookClockInEntity entity = bookClockinService.getOne(queryWrapper); + Map result = new HashMap<>(); + result.put("result", entity); + return R.ok(result); + } + + /** + * 获取评论列表 + * + * @param entryId + * @return + */ + @RequestMapping(path = "/getChatList", method = RequestMethod.GET) + public R getChatList(@RequestParam("entryId") Integer entryId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("entry_id", entryId); + queryWrapper.orderByAsc("f_id", "create_time"); + List resultList = bookClockEntryChatService.list(queryWrapper); + Map result = new HashMap<>(); + result.put("chatList", resultList); + return R.ok(result); + } + + /** + * 添加评论 + * + * @param chat + * @return + */ + @RequestMapping(path = "/addChat", method = RequestMethod.POST) + public R addChat(@RequestBody BookClockInChatEntity chat) { + bookClockEntryChatService.save(chat); + return R.ok(); + } + + /** + * 删除评论 + * + * @param id + * @return + */ + @RequestMapping(path = "/deleteChat", method = RequestMethod.GET) + public R deleteChat(@RequestParam("id") Integer id) { + bookClockEntryChatService.removeById(id); + return R.ok(); + } + +} diff --git a/src/main/java/com/peanut/modules/book/controller/BookClockinCommentController.java b/src/main/java/com/peanut/modules/book/controller/BookClockinCommentController.java index 252f8ca0..7cd8cf4c 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookClockinCommentController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookClockinCommentController.java @@ -4,12 +4,11 @@ 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.BookClockinCommentEntity; -import com.peanut.modules.book.entity.BookClockinEntity; +import com.peanut.modules.book.entity.BookClockInEntity; import com.peanut.modules.book.entity.BookClockinPunchEntity; import com.peanut.modules.book.service.BookClockinCommentService; import com.peanut.modules.book.service.BookClockinPunchService; import com.peanut.modules.book.service.BookClockinService; -import com.peanut.modules.book.service.BookTaskService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Arrays; @@ -97,7 +96,7 @@ public class BookClockinCommentController { Integer bookid = clockinComment.getBookId(); Integer userId = clockinComment.getUserId(); Integer pid = clockinComment.getPid(); - BookClockinEntity bookClockinEntity = bookClockinService.getBaseMapper().selectOne(new QueryWrapper() + BookClockInEntity bookClockinEntity = bookClockinService.getBaseMapper().selectOne(new QueryWrapper() .eq("id",pid) ); clockinComment.setDelFlag(0); diff --git a/src/main/java/com/peanut/modules/book/controller/BookClockinController.java b/src/main/java/com/peanut/modules/book/controller/BookClockinController.java index dc6c326c..d30abd72 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookClockinController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookClockinController.java @@ -44,10 +44,10 @@ public class BookClockinController { public R applist(@RequestParam("bookid") String bookid, @RequestParam("taskid") String taskid) { - List bookClockinEntityList = bookClockinService.getBaseMapper().selectList(new QueryWrapper() + List bookClockinEntityList = bookClockinService.getBaseMapper().selectList(new QueryWrapper() .eq("book_id", bookid).eq("task_id", taskid)); List list = new ArrayList<>(); - for (BookClockinEntity bookClockinEntity : bookClockinEntityList) { + for (BookClockInEntity bookClockinEntity : bookClockinEntityList) { Map map = new HashMap<>(); String name = ""; String avatar=""; @@ -101,7 +101,7 @@ public class BookClockinController { */ @RequestMapping("/info/{id}") public R info(@PathVariable("id") Integer id) { - BookClockinEntity bookClockinEntity = bookClockinService.getById(id); + BookClockInEntity bookClockinEntity = bookClockinService.getById(id); return R.ok().put("bookBuyConfig", bookClockinEntity); } @@ -109,7 +109,7 @@ public class BookClockinController { * 保存 */ @RequestMapping("/save") - public R save(@RequestBody BookClockinEntity bookClockinEntity) { + public R save(@RequestBody BookClockInEntity bookClockinEntity) { Integer bookId = bookClockinEntity.getBookId(); Integer userId = bookClockinEntity.getUserId(); @@ -124,7 +124,7 @@ public class BookClockinController { if (bookClockinPunchEntity==null) { return R.error("当天打卡内容未发布"); } - BookClockinEntity bookClockin = bookClockinService.getBaseMapper().selectOne(new QueryWrapper() + BookClockInEntity bookClockin = bookClockinService.getBaseMapper().selectOne(new QueryWrapper() .eq("book_id", bookId) .eq("task_id", taskId) .eq("day_id", dayId) @@ -159,7 +159,7 @@ public class BookClockinController { * 修改 */ @RequestMapping("/update") - public R update(@RequestBody BookClockinEntity bookClockinEntity) { + public R update(@RequestBody BookClockInEntity bookClockinEntity) { bookClockinService.updateById(bookClockinEntity); return R.ok("提交成功"); } @@ -186,11 +186,11 @@ public class BookClockinController { List applist = new ArrayList<>(); Map productMap = new HashMap<>(); //根据bookid查找出签到表中签到的用户数据 - List bookid = bookClockinService.getBaseMapper().selectList(new QueryWrapper() + List bookid = bookClockinService.getBaseMapper().selectList(new QueryWrapper() .eq("book_id", bookId) .orderByDesc("create_time")); - for (BookClockinEntity book : bookid) { + for (BookClockInEntity book : bookid) { HashMap map = new HashMap<>(); Integer bookid1 = book.getBookId(); @@ -222,11 +222,11 @@ public class BookClockinController { @RequestParam("bookid") Integer bookId) { - List bookClockinEntityList = bookClockinService.getBaseMapper().selectList(new QueryWrapper() + List bookClockinEntityList = bookClockinService.getBaseMapper().selectList(new QueryWrapper() .eq("user_id",id) .eq("book_id",bookId).orderByDesc("create_time")); List list = new ArrayList<>(); - for (BookClockinEntity bookClockinEntity : bookClockinEntityList) { + for (BookClockInEntity bookClockinEntity : bookClockinEntityList) { Map productMap = new HashMap<>(); Integer userId = bookClockinEntity.getUserId(); Integer dayId = bookClockinEntity.getDayId(); @@ -286,7 +286,7 @@ public class BookClockinController { ) { List list = new ArrayList<>(); Map productMap = new HashMap<>(); - BookClockinEntity bookClockin = bookClockinService.getBaseMapper().selectOne(new QueryWrapper() + BookClockInEntity bookClockin = bookClockinService.getBaseMapper().selectOne(new QueryWrapper() .eq("user_id",id) .eq("task_id",taskid) .eq("book_id",bookId) diff --git a/src/main/java/com/peanut/modules/book/controller/BookClockinPunchController.java b/src/main/java/com/peanut/modules/book/controller/BookClockinPunchController.java index ef3a7871..adb671d1 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookClockinPunchController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookClockinPunchController.java @@ -1,4 +1,9 @@ package com.peanut.modules.book.controller; + +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -7,29 +12,28 @@ import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.R; import com.peanut.modules.book.dao.UserEbookBuyDao; import com.peanut.modules.book.entity.*; -import com.peanut.modules.book.service.BookClockinCommentService; -import com.peanut.modules.book.service.BookClockinPunchService; -import com.peanut.modules.book.service.BookService; -import com.peanut.modules.book.service.MyUserService; +import com.peanut.modules.book.service.*; +import io.swagger.models.auth.In; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; + import java.util.*; @RestController @RequestMapping("book/clockinPunch") public class BookClockinPunchController { -@Autowired -private BookClockinPunchService bookClockinPunchService; -@Autowired -private BookService bookService; -@Autowired -private MyUserService myUserService; -@Autowired -private BookClockinCommentService bookClockinCommentService; -@Autowired -private UserEbookBuyDao userEbookBuyDao; - - + @Autowired + private BookClockinPunchService bookClockinPunchService; + @Autowired + private BookService bookService; + @Autowired + private MyUserService myUserService; + @Autowired + private BookClockinCommentService bookClockinCommentService; + @Autowired + private UserEbookBuyDao userEbookBuyDao; + @Autowired + UserBookClockService userBookClockService; /** @@ -44,49 +48,6 @@ private UserEbookBuyDao userEbookBuyDao; - /** - * 计算打卡天数 - */ - @RequestMapping("/clockindays") - public R applists(@RequestParam("bookId") String bookid, - @RequestParam("userId") String userid) { - ArrayList list = new ArrayList<>(); - //查询用户id图书id 根据第一天打卡天数开始计算 - BookClockinPunchEntity bookClockinEntity = bookClockinPunchService.getBaseMapper().selectOne(new QueryWrapper() - .eq("book_id", bookid) - .eq("user_id", userid) - .eq("days",1) - ); - List bookClockinEntityList = bookClockinPunchService.getBaseMapper().selectList(new QueryWrapper() - .eq("book_id", bookid) - .eq("user_id", userid) - ); - for (BookClockinPunchEntity bookClock : bookClockinEntityList) { - Integer days = bookClock.getDays(); - list.add(days); - } - if (bookClockinEntity != null) { - Date createTime = bookClockinEntity.getCreateTime(); - long createTimeMillis = createTime.getTime(); - //获取第一次打卡天数createTimeMillis毫秒数,时间戳减并除以毫秒数(24 * 60 * 60 * 1000)计算打卡总天数+1 - int daysBetween = (int) (System.currentTimeMillis() - createTimeMillis) / (24 * 60 * 60 * 1000)+1; - return R.ok().put("daysBetween", daysBetween).put("dayslist", list); - - } else if (bookClockinEntity == null) { - Date createTime = new Date(); - long createTimeMillis = createTime.getTime(); - int daysBetween = (int) (System.currentTimeMillis() - createTimeMillis) / (24 * 60 * 60 * 1000)+1; - return R.ok().put("daysBetween", daysBetween).put("dayslist",list ); - - - - } - - - - return R.error("无信息记录"); - } - /** * 信息 */ @@ -113,25 +74,24 @@ private UserEbookBuyDao userEbookBuyDao; .eq("t_id", taskId) - ); - if (bookClock !=null) { + if (bookClock != null) { return R.error("您已经签到,请勿重复签到"); } - if(canListen == true){ - boolean b = myUserService.bookAuthen(bookid1,userId); - if (b){ + if (canListen == true) { + boolean b = myUserService.bookAuthen(bookid1, userId); + if (b) { bookClockinPunchEntity.setDelFlag(0); bookClockinPunchService.save(bookClockinPunchEntity); return R.ok("签到成功"); - }else { + } else { return R.error("您还未购买此书,购买后即可签到"); } - }else { + } else { return R.error("该书暂未开放打卡权限"); } @@ -141,37 +101,39 @@ private UserEbookBuyDao userEbookBuyDao; /** * 获取用户打卡已购图书 + * * @param userId * @return */ @RequestMapping("/myClockBooks") - public R myClockBooks(@RequestParam Integer userId,@RequestParam Integer limit,@RequestParam Integer page){ + public R myClockBooks(@RequestParam Integer userId, @RequestParam Integer limit, @RequestParam Integer page) { MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); wrapper.selectAll(BookEntity.class); - wrapper.leftJoin(BookEntity.class,BookEntity::getId,UserEbookBuyEntity::getBookId); - wrapper.eq(UserEbookBuyEntity::getUserId,userId); - wrapper.eq(BookEntity::getDelFlag,0); - wrapper.eq(BookEntity::getClockIn,1); + wrapper.leftJoin(BookEntity.class, BookEntity::getId, UserEbookBuyEntity::getBookId); + wrapper.eq(UserEbookBuyEntity::getUserId, userId); + wrapper.eq(BookEntity::getDelFlag, 0); + wrapper.eq(BookEntity::getClockIn, 1); Page userBookEntityPage = userEbookBuyDao.selectJoinPage(new Page(page, limit), BookEntity.class, wrapper); - return R.ok().put("page",userBookEntityPage); + return R.ok().put("page", userBookEntityPage); } /** * 获取打卡推荐图书 + * * @param userId * @param limit * @param page * @return */ @RequestMapping("/getBestClockBooks") - public R getBestClockBooks(@RequestParam Integer userId,@RequestParam Integer limit,@RequestParam Integer page){ - String not_ex_sql = "select 1 from user_ebook_buy where book.id = book_id and user_id = "+userId; + public R getBestClockBooks(@RequestParam Integer userId, @RequestParam Integer limit, @RequestParam Integer page) { + String not_ex_sql = "select 1 from user_ebook_buy where book.id = book_id and user_id = " + userId; LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(BookEntity::getDelFlag,0); - wrapper.eq(BookEntity::getClockIn,1); + wrapper.eq(BookEntity::getDelFlag, 0); + wrapper.eq(BookEntity::getClockIn, 1); wrapper.notExists(not_ex_sql); Page bookEntityPage = bookService.getBaseMapper().selectPage(new Page<>(page, limit), wrapper); - return R.ok().put("page",bookEntityPage); + return R.ok().put("page", bookEntityPage); } @@ -197,12 +159,13 @@ private UserEbookBuyDao userEbookBuyDao; /** - * 获取评论 + * 获取评论 + * * @param bookClockinPunchEntity * @return */ @RequestMapping("/punchcoments") - public R punchcoments(@RequestBody BookClockinPunchEntity bookClockinPunchEntity) { + public R punchcoments(@RequestBody BookClockinPunchEntity bookClockinPunchEntity) { //图书Id Integer bookId = bookClockinPunchEntity.getBookId(); //用户id @@ -212,48 +175,46 @@ private UserEbookBuyDao userEbookBuyDao; ArrayList list = new ArrayList<>(); List bookClockinCommentEntities = bookClockinCommentService.getBaseMapper().selectList(new QueryWrapper() - .eq("user_id", userId) - .eq("book_id", bookId) - .eq("task_id", days) + .eq("user_id", userId) + .eq("book_id", bookId) + .eq("task_id", days) //pid等于1时为一级评论 // .eq("pid",1) ); - for (BookClockinCommentEntity bookClockinCommentEntity : bookClockinCommentEntities) { - HashMap map = new HashMap<>(); - String name = ""; - String avatar=""; + for (BookClockinCommentEntity bookClockinCommentEntity : bookClockinCommentEntities) { + HashMap map = new HashMap<>(); + String name = ""; + String avatar = ""; - Integer userId1 = bookClockinCommentEntity.getUserId(); - Integer bookId1 = bookClockinCommentEntity.getBookId(); - String content = bookClockinCommentEntity.getContent(); - String images = bookClockinCommentEntity.getImages(); - Date createTime = bookClockinCommentEntity.getCreateTime(); + Integer userId1 = bookClockinCommentEntity.getUserId(); + Integer bookId1 = bookClockinCommentEntity.getBookId(); + String content = bookClockinCommentEntity.getContent(); + String images = bookClockinCommentEntity.getImages(); + Date createTime = bookClockinCommentEntity.getCreateTime(); + List id = myUserService.getBaseMapper().selectList(new QueryWrapper().eq("id", userId)); + for (MyUserEntity user : id) { + name = user.getNickname(); + avatar = user.getAvatar(); + } + map.put("userid", userId1); + map.put("name", name); + map.put("avatar", avatar); + map.put("bookid", bookId1); + map.put("content", content); + map.put("images", images); + map.put("createdate", createTime); + list.add(map); - List id = myUserService.getBaseMapper().selectList(new QueryWrapper().eq("id", userId)); - for (MyUserEntity user : id) { - name = user.getNickname(); - avatar = user.getAvatar(); - } - map.put("userid", userId1); - map.put("name", name); - map.put("avatar", avatar); - map.put("bookid", bookId1); - map.put("content", content); - map.put("images", images); - map.put("createdate", createTime); - list.add(map); - - } + } Collections.reverse(list); return R.ok().put("list", list); - } - - - } + +} + diff --git a/src/main/java/com/peanut/modules/book/controller/BookTaskController.java b/src/main/java/com/peanut/modules/book/controller/BookTaskController.java index 0349d0e6..4e4666c8 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookTaskController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookTaskController.java @@ -4,7 +4,6 @@ package com.peanut.modules.book.controller; 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.BookClockinEntity; import com.peanut.modules.book.entity.BookClockinPunchEntity; import com.peanut.modules.book.entity.BookTaskEntity; import com.peanut.modules.book.service.*; diff --git a/src/main/java/com/peanut/modules/book/controller/UserBookClockController.java b/src/main/java/com/peanut/modules/book/controller/UserBookClockController.java new file mode 100644 index 00000000..51a9eab0 --- /dev/null +++ b/src/main/java/com/peanut/modules/book/controller/UserBookClockController.java @@ -0,0 +1,99 @@ +package com.peanut.modules.book.controller; + +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.peanut.common.utils.R; +import com.peanut.modules.book.entity.UserBookClockEntity; +import com.peanut.modules.book.service.UserBookClockService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.*; + +/** + * @Description: 用户打卡 Controller + * @Author: Cauchy + * @CreateTime: 2023/10/11 + */ +@Slf4j +@RequestMapping("/book/userClockIn") +public class UserBookClockController { + @Autowired + UserBookClockService userBookClockService; + + /** + * 计算打卡天数 + * + * @param bookId + * @param userId + * @return + */ + @RequestMapping(path = "/clockInDays", method = RequestMethod.GET) + public R clockInDays(@RequestParam("bookId") Integer bookId, + @RequestParam("userId") Integer userId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("book_id", bookId); + queryWrapper.eq("user_id", userId); + UserBookClockEntity userBookClock = userBookClockService.getOne(queryWrapper); + if (userBookClock == null) { + return R.error("未获取到该用户的打卡信息"); + } + // 1. 获取打卡初始日期 + Date beginDate = userBookClock.getBeginDate(); + // 2. 获取打卡天数列表 + String clocksStr = userBookClock.getClocks(); + List clockInDayList = JSON.parseObject(clocksStr, new TypeReference>() { + }); + Map result = new HashMap<>(); + result.put("beginDate", beginDate); + result.put("clockInDayList", clockInDayList); + return R.ok(result); + } + + /** + * 用户打卡 + * + * @param bookId + * @param userId + * @return + */ + @RequestMapping(path = "/clockIn", method = RequestMethod.GET) + public R clockIn(@RequestParam("bookId") Integer bookId, @RequestParam("userId") Integer userId) { + // 查询是否有该用户打卡记录,如果没有,说明是第一天打卡 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("book_id", bookId); + queryWrapper.eq("user_id", userId); + UserBookClockEntity userBookClock = userBookClockService.getOne(queryWrapper); + // 第一天打卡 + if (userBookClock == null) { + UserBookClockEntity entity = new UserBookClockEntity(); + java.sql.Date beginDate = new java.sql.Date(new Date().getTime()); + List clockInDaysList = new ArrayList<>(); + clockInDaysList.add(1); + String clockInDaysListStr = JSON.toJSON(clockInDaysList).toString(); + entity.setBookId(bookId); + entity.setUserId(userId); + entity.setBeginDate(beginDate); + entity.setClocks(clockInDaysListStr); + userBookClockService.save(entity); + return R.ok("打卡成功"); + } + String clocksStr = userBookClock.getClocks(); + List clockInDaysList = JSON.parseObject(clocksStr, new TypeReference>() { + }); + Date beginDate = userBookClock.getBeginDate(); + Date today = new Date(); + long between = DateUtil.between(beginDate, today, DateUnit.DAY); + clockInDaysList.add((int) between); + String clockInDaysListStr = JSON.toJSON(clockInDaysList).toString(); + userBookClock.setClocks(clockInDaysListStr); + userBookClockService.updateById(userBookClock); + return R.ok("打卡成功"); + } +} diff --git a/src/main/java/com/peanut/modules/book/dao/BookClockEntryChatDao.java b/src/main/java/com/peanut/modules/book/dao/BookClockEntryChatDao.java index 43c572b9..c9a7d83f 100644 --- a/src/main/java/com/peanut/modules/book/dao/BookClockEntryChatDao.java +++ b/src/main/java/com/peanut/modules/book/dao/BookClockEntryChatDao.java @@ -1,9 +1,9 @@ package com.peanut.modules.book.dao; import com.github.yulichang.base.MPJBaseMapper; -import com.peanut.modules.book.entity.BookClockEntryChatEntity; +import com.peanut.modules.book.entity.BookClockInChatEntity; import org.apache.ibatis.annotations.Mapper; @Mapper -public interface BookClockEntryChatDao extends MPJBaseMapper { +public interface BookClockEntryChatDao extends MPJBaseMapper { } diff --git a/src/main/java/com/peanut/modules/book/dao/BookClockinDao.java b/src/main/java/com/peanut/modules/book/dao/BookClockinDao.java index 37b678a4..46e11221 100644 --- a/src/main/java/com/peanut/modules/book/dao/BookClockinDao.java +++ b/src/main/java/com/peanut/modules/book/dao/BookClockinDao.java @@ -1,12 +1,11 @@ package com.peanut.modules.book.dao; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.github.yulichang.base.MPJBaseMapper; -import com.peanut.modules.book.entity.BookClockinEntity; +import com.peanut.modules.book.entity.BookClockInEntity; import org.apache.ibatis.annotations.Mapper; @Mapper -public interface BookClockinDao extends MPJBaseMapper { +public interface BookClockinDao extends MPJBaseMapper { diff --git a/src/main/java/com/peanut/modules/book/entity/BookClockEntryChatEntity.java b/src/main/java/com/peanut/modules/book/entity/BookClockInChatEntity.java similarity index 86% rename from src/main/java/com/peanut/modules/book/entity/BookClockEntryChatEntity.java rename to src/main/java/com/peanut/modules/book/entity/BookClockInChatEntity.java index 2bf023a0..020ea5d8 100644 --- a/src/main/java/com/peanut/modules/book/entity/BookClockEntryChatEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/BookClockInChatEntity.java @@ -2,11 +2,13 @@ package com.peanut.modules.book.entity; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; import java.io.Serializable; import java.util.Date; -public class BookClockEntryChatEntity implements Serializable { +@Data +public class BookClockInChatEntity implements Serializable { private static final long serialVersionUID = 1L; @TableId diff --git a/src/main/java/com/peanut/modules/book/entity/BookClockinEntity.java b/src/main/java/com/peanut/modules/book/entity/BookClockInEntity.java similarity index 95% rename from src/main/java/com/peanut/modules/book/entity/BookClockinEntity.java rename to src/main/java/com/peanut/modules/book/entity/BookClockInEntity.java index 15de2c29..3d4e7c82 100644 --- a/src/main/java/com/peanut/modules/book/entity/BookClockinEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/BookClockInEntity.java @@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.annotation.*; import lombok.Data; import java.io.Serializable; -import java.util.ArrayList; import java.util.Date; /** @@ -16,7 +15,7 @@ import java.util.Date; */ @Data @TableName("book_clockin") -public class BookClockinEntity implements Serializable { +public class BookClockInEntity implements Serializable { diff --git a/src/main/java/com/peanut/modules/book/entity/UserBookClockEntity.java b/src/main/java/com/peanut/modules/book/entity/UserBookClockEntity.java index a3bf0c34..c5fae6fc 100644 --- a/src/main/java/com/peanut/modules/book/entity/UserBookClockEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/UserBookClockEntity.java @@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import java.io.Serializable; -import java.sql.Date; +import java.util.Date; @Data @TableName("user_book_clock") diff --git a/src/main/java/com/peanut/modules/book/service/BookClockEntryChatService.java b/src/main/java/com/peanut/modules/book/service/BookClockEntryChatService.java index c91fa49e..d6eb3352 100644 --- a/src/main/java/com/peanut/modules/book/service/BookClockEntryChatService.java +++ b/src/main/java/com/peanut/modules/book/service/BookClockEntryChatService.java @@ -1,7 +1,7 @@ package com.peanut.modules.book.service; import com.baomidou.mybatisplus.extension.service.IService; -import com.peanut.modules.book.entity.BookClockEntryChatEntity; +import com.peanut.modules.book.entity.BookClockInChatEntity; -public interface BookClockEntryChatService extends IService { +public interface BookClockEntryChatService extends IService { } diff --git a/src/main/java/com/peanut/modules/book/service/BookClockinPunchService.java b/src/main/java/com/peanut/modules/book/service/BookClockinPunchService.java index e0766f34..dbd140d5 100644 --- a/src/main/java/com/peanut/modules/book/service/BookClockinPunchService.java +++ b/src/main/java/com/peanut/modules/book/service/BookClockinPunchService.java @@ -3,7 +3,6 @@ package com.peanut.modules.book.service; import com.baomidou.mybatisplus.extension.service.IService; import com.peanut.common.utils.PageUtils; -import com.peanut.modules.book.entity.BookClockinEntity; import com.peanut.modules.book.entity.BookClockinPunchEntity; import java.util.Map; diff --git a/src/main/java/com/peanut/modules/book/service/BookClockinService.java b/src/main/java/com/peanut/modules/book/service/BookClockinService.java index fe9a9e18..051b092f 100644 --- a/src/main/java/com/peanut/modules/book/service/BookClockinService.java +++ b/src/main/java/com/peanut/modules/book/service/BookClockinService.java @@ -2,11 +2,11 @@ package com.peanut.modules.book.service; import com.baomidou.mybatisplus.extension.service.IService; import com.peanut.common.utils.PageUtils; -import com.peanut.modules.book.entity.BookClockinEntity; +import com.peanut.modules.book.entity.BookClockInEntity; import java.util.Map; -public interface BookClockinService extends IService { +public interface BookClockinService extends IService { PageUtils queryPage(Map params); diff --git a/src/main/java/com/peanut/modules/book/service/impl/BookClockEntryChatImpl.java b/src/main/java/com/peanut/modules/book/service/impl/BookClockEntryChatImpl.java index b9429070..85c51fc6 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/BookClockEntryChatImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/BookClockEntryChatImpl.java @@ -2,10 +2,10 @@ package com.peanut.modules.book.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.peanut.modules.book.dao.BookClockEntryChatDao; -import com.peanut.modules.book.entity.BookClockEntryChatEntity; +import com.peanut.modules.book.entity.BookClockInChatEntity; import com.peanut.modules.book.service.BookClockEntryChatService; import org.springframework.stereotype.Service; @Service("bookClockEntryChatService") -public class BookClockEntryChatImpl extends ServiceImpl implements BookClockEntryChatService { +public class BookClockEntryChatImpl extends ServiceImpl implements BookClockEntryChatService { } diff --git a/src/main/java/com/peanut/modules/book/service/impl/BookClockinCommentServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/BookClockinCommentServiceImpl.java index a8345696..14024d93 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/BookClockinCommentServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/BookClockinCommentServiceImpl.java @@ -7,7 +7,6 @@ import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.Query; import com.peanut.modules.book.dao.BookClockinCommentDao; import com.peanut.modules.book.entity.BookClockinCommentEntity; -import com.peanut.modules.book.entity.BookClockinEntity; import com.peanut.modules.book.service.BookClockinCommentService; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/peanut/modules/book/service/impl/BookClockinServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/BookClockinServiceImpl.java index 69535375..b28426d3 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/BookClockinServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/BookClockinServiceImpl.java @@ -6,23 +6,23 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.Query; import com.peanut.modules.book.dao.BookClockinDao; -import com.peanut.modules.book.entity.BookClockinEntity; +import com.peanut.modules.book.entity.BookClockInEntity; import com.peanut.modules.book.service.BookClockinService; import org.springframework.stereotype.Service; import java.util.Map; @Service -public class BookClockinServiceImpl extends ServiceImpl implements BookClockinService { +public class BookClockinServiceImpl extends ServiceImpl implements BookClockinService { @Override public PageUtils queryPage(Map params) { Object book =params.get("bookid"); Object taskid = params.get("taskid"); - IPage page = this.page( - new Query().getPage(params), - new QueryWrapper() + IPage page = this.page( + new Query().getPage(params), + new QueryWrapper() .eq("book_id",book) .eq("task_id",taskid) .orderByDesc("create_time") @@ -34,9 +34,9 @@ public class BookClockinServiceImpl extends ServiceImpl params) { - IPage page = this.page( - new Query().getPage(params), - new QueryWrapper() + IPage page = this.page( + new Query().getPage(params), + new QueryWrapper() ); return new PageUtils(page); diff --git a/src/main/java/com/peanut/modules/mq/Consumer/OrderCancelConsumer.java b/src/main/java/com/peanut/modules/mq/Consumer/OrderCancelConsumer.java index eee5205c..36c6869e 100644 --- a/src/main/java/com/peanut/modules/mq/Consumer/OrderCancelConsumer.java +++ b/src/main/java/com/peanut/modules/mq/Consumer/OrderCancelConsumer.java @@ -15,6 +15,7 @@ import org.springframework.stereotype.Component; */ @Component public class OrderCancelConsumer { + @Autowired BuyOrderService buyOrderService; diff --git a/src/main/resources/mapper/book/BookClockinDao.xml b/src/main/resources/mapper/book/BookClockinDao.xml index ac0ff659..3f4a0aa3 100644 --- a/src/main/resources/mapper/book/BookClockinDao.xml +++ b/src/main/resources/mapper/book/BookClockinDao.xml @@ -8,7 +8,7 @@ - + diff --git a/src/main/resources/weChatConfig.properties b/src/main/resources/weChatConfig.properties index f936951a..304f4f5f 100644 --- a/src/main/resources/weChatConfig.properties +++ b/src/main/resources/weChatConfig.properties @@ -1,27 +1,27 @@ # APP ID wxpay.appId:wx47134a8f15083734 -# ?? ID +# \u5546\u6237 ID wxpay.mchId:1612860909 -# ?? URL +# \u652F\u4ED8 URL wxpay.payUrl:https://api.mch.weixin.qq.com/v3/pay/transactions/app -# ???? +# \u901A\u77E5\u56DE\u8C03 URL wxpay.notifyUrl:https://testapi.nuttyreading.com/pay/payNotify -# ?? url +# \u9000\u6B3E URL wxpay.refundNotifyUrl:http://pjm6m9.natappfree.cc/pay/refundNotify # key pem -wxpay.keyPemPath:/usr/local/hs/peanut_book/target/classes/cent/apiclient_key.pem -#wxpay.keyPemPath:C:/Users/Cauchy/IdeaProjects/nuttyreading-java/src/main/resources/cent/apiclient_key.pem +#wxpay.keyPemPath:/usr/local/hs/peanut_book/target/classes/cent/apiclient_key.pem +wxpay.keyPemPath:C:/Users/Cauchy/IdeaProjects/nuttyreading-java/src/main/resources/cent/apiclient_key.pem #wxpay.keyPemPath:D:/hs/nuttyreading-java/src/main/resources/cent/apiclient_key.pem #wxpay.keyPemPath:/usr/local/hs/peanut_book/target/classes/cent/apiclient_key.pem -# ??? +# \u5546\u6237\u5E8F\u5217\u53F7 wxpay.serialNo:679AECB2F7AC4183033F713828892BA640E4EEE3 # API v3 key wxpay.apiV3Key:4aYFklzaULeGlr7oJPZ6rHWKcxjihZUF -# ???? -wxpay.wechatPayCertificateUrl:/usr/local/hs/peanut_book/target/classes/cent/wechatpay_7B5676E3CDF56680D0414A009CE501C844DBE2D6.pem -# wxpay.wechatPayCertificateUrl:C:/Users/Cauchy/IdeaProjects/nuttyreading-java/src/main/resources/cent/wechatpay_7B5676E3CDF56680D0414A009CE501C844DBE2D6.pem +# \u8BC1\u4E66 +#wxpay.wechatPayCertificateUrl:/usr/local/hs/peanut_book/target/classes/cent/wechatpay_7B5676E3CDF56680D0414A009CE501C844DBE2D6.pem +wxpay.wechatPayCertificateUrl:C:/Users/Cauchy/IdeaProjects/nuttyreading-java/src/main/resources/cent/wechatpay_7B5676E3CDF56680D0414A009CE501C844DBE2D6.pem # wxpay.wechatPayCertificateUrl:D:/hs/nuttyreading-java/src/main/resources/cent/wechatpay_7B5676E3CDF56680D0414A009CE501C844DBE2D6.pem -# ?? url -wxpay.privateKeyUrl:/usr/local/hs/peanut_book/target/classes/cent/apiclient_key.pem -#wxpay.privateKeyUrl:C:/Users/Cauchy/IdeaProjects/nuttyreading-java/src/main/resources/cent/apiclient_key.pem +# \u5BC6\u94A5 +#wxpay.privateKeyUrl:/usr/local/hs/peanut_book/target/classes/cent/apiclient_key.pem +wxpay.privateKeyUrl:C:/Users/Cauchy/IdeaProjects/nuttyreading-java/src/main/resources/cent/apiclient_key.pem #wxpay.privateKeyUrl:D:/hs/nuttyreading-java/src/main/resources/cent/apiclient_key.pem From a356cceb62e4aac645cb06832dc25b5d3bb291be Mon Sep 17 00:00:00 2001 From: Cauchy Date: Wed, 11 Oct 2023 16:51:29 +0800 Subject: [PATCH 2/2] rename the file --- .../BookChapterContentController.java | 220 +++++------ .../book/controller/BookController.java | 8 +- .../book/controller/BookTeachController.java | 88 ++--- .../book/controller/BuyOrderController.java | 8 +- .../controller/ShopProductBookController.java | 75 ++++ .../controller/ShopProductController.java | 354 +++++++++--------- .../ShopProudictBookController.java | 95 ----- ...ctBookDao.java => ShopProductBookDao.java} | 4 +- ...Entity.java => ShopProductBookEntity.java} | 41 +- .../book/service/ShopProductBookService.java | 24 ++ .../book/service/ShopProudictBookService.java | 24 -- ...l.java => ShopProductBookServiceImpl.java} | 68 ++-- .../service/impl/ShopProductServiceImpl.java | 7 - .../modules/book/vo/ProductBookQueryVO.java | 29 ++ .../modules/book/vo/ProudictBookqueryVO.java | 40 -- .../controller/WeChatPayController.java | 2 +- src/main/resources/application-dev.yml | 119 +++--- src/main/resources/application-prod.yml | 13 + src/main/resources/application.yml | 15 +- ...dictBookDao.xml => ShopProductBookDao.xml} | 15 +- 20 files changed, 566 insertions(+), 683 deletions(-) create mode 100644 src/main/java/com/peanut/modules/book/controller/ShopProductBookController.java delete mode 100644 src/main/java/com/peanut/modules/book/controller/ShopProudictBookController.java rename src/main/java/com/peanut/modules/book/dao/{ShopProudictBookDao.java => ShopProductBookDao.java} (60%) rename src/main/java/com/peanut/modules/book/entity/{ShopProudictBookEntity.java => ShopProductBookEntity.java} (53%) create mode 100644 src/main/java/com/peanut/modules/book/service/ShopProductBookService.java delete mode 100644 src/main/java/com/peanut/modules/book/service/ShopProudictBookService.java rename src/main/java/com/peanut/modules/book/service/impl/{ShopProudictBookServiceImpl.java => ShopProductBookServiceImpl.java} (53%) create mode 100644 src/main/java/com/peanut/modules/book/vo/ProductBookQueryVO.java delete mode 100644 src/main/java/com/peanut/modules/book/vo/ProudictBookqueryVO.java rename src/main/resources/mapper/book/{ShopProudictBookDao.xml => ShopProductBookDao.xml} (56%) diff --git a/src/main/java/com/peanut/modules/book/controller/BookChapterContentController.java b/src/main/java/com/peanut/modules/book/controller/BookChapterContentController.java index 55931e66..cd23619e 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookChapterContentController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookChapterContentController.java @@ -2,7 +2,6 @@ package com.peanut.modules.book.controller; import java.io.File; import java.io.FileInputStream; -import java.io.InputStream; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -16,7 +15,6 @@ import com.peanut.modules.book.service.*; import com.peanut.modules.oss.service.OssService; import lombok.SneakyThrows; import org.apache.commons.io.IOUtils; -import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.bind.annotation.PathVariable; @@ -31,8 +29,6 @@ import org.springframework.web.multipart.MultipartFile; /** - * - * * @author yl * @email yl328572838@163.com * @date 2022-08-16 14:32:06 @@ -53,27 +49,24 @@ public class BookChapterContentController { @Autowired private UserEbookBuyService userEbookBuyService; @Autowired - private ShopProudictBookService shopProudictBookService; + private ShopProductBookService shopProductBookService; /** * 列表 */ @RequestMapping("/list") -// @RequiresPermissions("book:bookchaptercontent:list") - public R list(@RequestParam Map params){ + public R list(@RequestParam Map params) { PageUtils page = bookChapterContentService.queryPage(params); return R.ok().put("page", page); } - /** * 信息 */ @RequestMapping("/info/{id}") -// @RequiresPermissions("book:bookchaptercontent:info") - public R info(@PathVariable("id") Integer id){ - BookChapterContentEntity bookChapterContent = bookChapterContentService.getById(id); + public R info(@PathVariable("id") Integer id) { + BookChapterContentEntity bookChapterContent = bookChapterContentService.getById(id); return R.ok().put("bookChapterContent", bookChapterContent); } @@ -82,9 +75,8 @@ public class BookChapterContentController { * 保存 */ @RequestMapping("/save") -// @RequiresPermissions("book:bookchaptercontent:save") - public R save(@RequestBody BookChapterContentEntity bookChapterContent){ - bookChapterContentService.save(bookChapterContent); + public R save(@RequestBody BookChapterContentEntity bookChapterContent) { + bookChapterContentService.save(bookChapterContent); return R.ok(); } @@ -93,9 +85,8 @@ public class BookChapterContentController { * 修改 */ @RequestMapping("/update") -// @RequiresPermissions("book:bookchaptercontent:update") - public R update(@RequestBody BookChapterContentEntity bookChapterContent){ - bookChapterContentService.updateById(bookChapterContent); + public R update(@RequestBody BookChapterContentEntity bookChapterContent) { + bookChapterContentService.updateById(bookChapterContent); return R.ok(); } @@ -104,9 +95,8 @@ public class BookChapterContentController { * 删除 */ @RequestMapping("/delete") -// @RequiresPermissions("book:bookchaptercontent:delete") - public R delete(@RequestBody Integer[] ids){ - bookChapterContentService.removeByIds(Arrays.asList(ids)); + public R delete(@RequestBody Integer[] ids) { + bookChapterContentService.removeByIds(Arrays.asList(ids)); return R.ok(); } @@ -116,17 +106,10 @@ public class BookChapterContentController { * 章节拆分转换单句 */ @RequestMapping("/getBookVoices") -// @RequiresPermissions("book:bookchaptercontent:delete") - public R getBookVoices(@RequestParam("id") Integer id){ + public R getBookVoices(@RequestParam("id") Integer id) { ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); - singleThreadExecutor.execute(new Runnable() { - @Override - public void run() { - bookChapterContentService.getWordChapterParagraph(id); - - } - }); + singleThreadExecutor.execute(() -> bookChapterContentService.getWordChapterParagraph(id)); BookEntity bookEntity = bookService.getBaseMapper().selectById(id); bookEntity.setContentStatus("2"); @@ -134,6 +117,7 @@ public class BookChapterContentController { return R.ok(); } + /** * 章节单句 转成音频 */ @@ -146,21 +130,16 @@ public class BookChapterContentController { return R.error("语音文件未生成"); } FileInputStream fileInputStream = new FileInputStream(file); - - - MultipartFile multipartFile =new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream)); - + MultipartFile multipartFile = new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream)); String path = ossService.uploadFileAvatar(multipartFile); - fileInputStream.close(); - file.delete(); - if (StringUtils.isEmpty(path)){ + if (StringUtils.isEmpty(path)) { return R.error("语音上传失败"); } - return R.ok().put("voices",path); + return R.ok().put("voices", path); } /** @@ -180,7 +159,7 @@ public class BookChapterContentController { List book_id = bookChapterContentService.getBaseMapper().selectList(new QueryWrapper() .eq("book_id", id)); - for (BookChapterContentEntity bookContent:book_id) { + for (BookChapterContentEntity bookContent : book_id) { String content = bookContent.getContent(); //生成相应的语音文件 String voices = BaiduVoicesUtils.run(content); @@ -193,9 +172,9 @@ public class BookChapterContentController { //把 voices 音频文件读入到内存中并将其转换成MultipartFile格式文件 multipartFile 用于OSS上传 // application/x-www-form-urlencoded form表单数据被编码为key/value格式发送到服务器 - // text/plain 纯文本格式 + // text/plain 纯文本格式 // MultipartFile multipartFile =new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream)); - MultipartFile multipartFile =new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream)); + MultipartFile multipartFile = new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream)); //上传 multipartFile 文件到阿里云OSS上 String path = ossService.uploadFileAvatar(multipartFile); @@ -206,7 +185,7 @@ public class BookChapterContentController { file.delete(); bookChapterContentService.updateById(bookContent); - if (StringUtils.isEmpty(path)){ + if (StringUtils.isEmpty(path)) { bookEntity.setVoicesStatus("3"); } } @@ -235,7 +214,7 @@ public class BookChapterContentController { List book_id = bookChapterService.getBaseMapper().selectList(new QueryWrapper().eq("book_id", id)); - for (BookChapterEntity bookChapter:book_id) { + for (BookChapterEntity bookChapter : book_id) { String content = bookChapter.getContent(); //生成相应的语音文件 String voices = BaiduVoicesUtils.run(content); @@ -245,7 +224,7 @@ public class BookChapterContentController { bookEntity.setVoicesStatus("3"); } FileInputStream fileInputStream = new FileInputStream(file); - MultipartFile multipartFile =new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream)); + MultipartFile multipartFile = new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(fileInputStream)); //上传 multipartFile 文件到阿里云OSS上 String path = ossService.uploadFileAvatar(multipartFile); @@ -256,7 +235,7 @@ public class BookChapterContentController { file.delete(); bookChapterService.updateById(bookChapter); - if (StringUtils.isEmpty(path)){ + if (StringUtils.isEmpty(path)) { bookEntity.setVoicesStatus("3"); } } @@ -271,14 +250,15 @@ public class BookChapterContentController { /** * 鉴权获取章节 + * * @param bookid * @param userId * @return */ @RequestMapping("/getBooksCatal") public R getBooksCatal(@RequestParam("id") Integer id, - @RequestParam("bookid") Integer bookid, - @RequestParam("userId") Integer userId) { + @RequestParam("bookid") Integer bookid, + @RequestParam("userId") Integer userId) { // TODO 验证 当前请求的书 是否存在免费章节数 BookEntity bookEntity = bookService.getBaseMapper().selectById(bookid); Integer freeChapterCount = bookEntity.getFreeChapterCount(); @@ -294,7 +274,7 @@ public class BookChapterContentController { String vip = user.getVip(); if (!"1".equals(vip)) { - return R.error("当前为VIP"); + return R.error("当前为VIP"); } } @@ -308,14 +288,14 @@ public class BookChapterContentController { return R.error(500, "请购买书籍!"); } } - if(isVip == 3){ - boolean b = myUserService.bookAuthenticate(bookid,userId); - if (!b){ + if (isVip == 3) { + boolean b = myUserService.bookAuthenticate(bookid, userId); + if (!b) { List book = bookChapterService.getBaseMapper().selectList(new QueryWrapper() .eq("book_id", bookid)); ArrayList chapterList = new ArrayList<>(); - int chapterIndex=0; + int chapterIndex = 0; for (BookChapterEntity chapter : book) { if (chapterIndex >= freeChapterCount) { break; // 取出前freeChapterCount条记录后,退出循环 @@ -330,19 +310,18 @@ public class BookChapterContentController { chapterIndex++; } - return R.ok("当前为试听章节:"+chapterList).put("bookCatalogue", chapterList).put("image", bookEntity.getImages()).put("chapterIndex",chapterIndex); + return R.ok("当前为试听章节:" + chapterList).put("bookCatalogue", chapterList).put("image", bookEntity.getImages()).put("chapterIndex", chapterIndex); } } - List book = bookChapterService.getBaseMapper().selectList(new QueryWrapper() .eq("book_id", bookid)); ArrayList chapterList = new ArrayList<>(); for (BookChapterEntity chapter : book) { Map map = new HashMap<>(); - map.put("name",chapter.getChapter()); - map.put("url",chapter.getVoices()); + map.put("name", chapter.getChapter()); + map.put("url", chapter.getVoices()); chapterList.add(map); } return R.ok().put("bookCatalogue", chapterList).put("image", bookEntity.getImages()); @@ -351,128 +330,114 @@ public class BookChapterContentController { /** * 获取章节音频地址 + * * @return */ @RequestMapping("/getBooksCatalogue") public R getBooksCatalogue(@RequestParam Integer chapterId, @RequestParam Integer bookId, - @RequestParam Integer userId){ + @RequestParam Integer userId) { //鉴权阶段 BookEntity book_info = bookService.getById(bookId); BookChapterEntity chapter_info = bookChapterService.getById(chapterId); UserEbookBuyEntity userEbookBuyEntity = userEbookBuyService.getBaseMapper().selectOne(new LambdaQueryWrapper(). - eq(UserEbookBuyEntity::getUserId,userId).eq(UserEbookBuyEntity::getBookId,bookId)); - if(chapter_info.getNumber()>book_info.getFreeChapterCount()&&userEbookBuyEntity==null){ - Integer productByBookId = shopProudictBookService.getProductByBookId(bookId); - return R.ok().put("jq",false).put("product",productByBookId); + eq(UserEbookBuyEntity::getUserId, userId).eq(UserEbookBuyEntity::getBookId, bookId)); + if (chapter_info.getNumber() > book_info.getFreeChapterCount() && userEbookBuyEntity == null) { + Integer productByBookId = shopProductBookService.getProductByBookId(bookId); + return R.ok().put("jq", false).put("product", productByBookId); } - - return R.ok().put("chapter",chapter_info); + return R.ok().put("chapter", chapter_info); } -/** - * app 获取电子书章节内容 2.0 (在用鉴权) - */ -@RequestMapping("/appBooksChapterContent1") -public R getBooksCatalogue1(@RequestParam("chapterid") Integer id, - @RequestParam("bookid") Integer bookid, - @RequestParam("userId") Integer userId) { - // TODO 验证 当前请求的书 是否存在免费章节数 - BookEntity bookEntity = bookService.getBaseMapper().selectById(bookid); - Integer freeChapterCount = bookEntity.getFreeChapterCount(); + /** + * app 获取电子书章节内容 2.0 (在用鉴权) + */ + @RequestMapping("/appBooksChapterContent1") + public R getBooksCatalogue1(@RequestParam("chapterid") Integer id, + @RequestParam("bookid") Integer bookid, + @RequestParam("userId") Integer userId) { + // TODO 验证 当前请求的书 是否存在免费章节数 + BookEntity bookEntity = bookService.getBaseMapper().selectById(bookid); + Integer freeChapterCount = bookEntity.getFreeChapterCount(); - BookChapterEntity bookChapterEntity = bookChapterService.getBaseMapper().selectById(id); + BookChapterEntity bookChapterEntity = bookChapterService.getBaseMapper().selectById(id); - Integer number = bookChapterEntity.getNumber(); + Integer number = bookChapterEntity.getNumber(); - //TODO 0-免费 1-会免(改为电子书听书) 2-付费 // 阅读章节数 大于 免费章节数 - Integer isVip = bookEntity.getIsVip(); - Boolean canListen = bookEntity.getCanListen(); + //TODO 0-免费 1-会免(改为电子书听书) 2-付费 // 阅读章节数 大于 免费章节数 + Integer isVip = bookEntity.getIsVip(); + Boolean canListen = bookEntity.getCanListen(); - //todo 暂未开通听书功能 + //todo 暂未开通听书功能 // if (canListen==false) { // return R.error1("暂未开通听书功能"); // } - if ((number > freeChapterCount) || freeChapterCount == 0) { - // 书籍为 会免 + if ((number > freeChapterCount) || freeChapterCount == 0) { + // 书籍为 会免 - if (isVip == 1) { - //查询用户身份 - MyUserEntity user = myUserService.getById(userId); - String vip = user.getVip(); - if (!"1".equals(vip)) { + if (isVip == 1) { + //查询用户身份 + MyUserEntity user = myUserService.getById(userId); + String vip = user.getVip(); + if (!"1".equals(vip)) { - return R.error("当前为VIP"); + return R.error("当前为VIP"); } } - if(canListen == true){ - boolean b = myUserService.bookAuthenticate(bookid,userId); - if (!b) { + if (canListen == true) { + boolean b = myUserService.bookAuthenticate(bookid, userId); + if (!b) { - return R.error("未购买书籍!"); + return R.error("未购买书籍!"); + } } - } - - - } - - if (isVip == 2) { + if (isVip == 2) { // 鉴权 查询权限表中 用户是否开通 boolean b = myUserService.bookAuthenticate(bookid, userId); if (!b) { - return R.error(500, "请购买书籍!").put("code",500); + return R.error(500, "请购买书籍!").put("code", 500); } } - - ArrayList chapterList = new ArrayList<>(); - + ArrayList chapterList = new ArrayList<>(); Map map = new HashMap<>(); - map.put("name",bookChapterEntity.getChapter()); - map.put("url",bookChapterEntity.getVoices()); - map.put("bookid",bookChapterEntity.getBookId()); - map.put("chapterid",bookChapterEntity.getId()); + map.put("name", bookChapterEntity.getChapter()); + map.put("url", bookChapterEntity.getVoices()); + map.put("bookid", bookChapterEntity.getBookId()); + map.put("chapterid", bookChapterEntity.getId()); //todo sort先注释调 // map.put("sort",bookChapterEntity.getSort()); chapterList.add(map); - return R.ok().put("bookCatalogue", chapterList).put("image", bookEntity.getImages()); + return R.ok().put("bookCatalogue", chapterList).put("image", bookEntity.getImages()); } - - - - - - - - /** * app 获取电子书章节内容 */ @RequestMapping("/appGetBookChapterContent") public R getBookCatalogue(@RequestParam("chapterid") Integer chapterid, @RequestParam("bookid") Integer bookid, - @RequestParam("userId") Integer userId){ + @RequestParam("userId") Integer userId) { // TODO 验证 当前请求的书 是否存在免费章节数 BookEntity bookEntity = bookService.getBaseMapper().selectById(bookid); @@ -481,57 +446,56 @@ public R getBooksCatalogue1(@RequestParam("chapterid") Integer id, BookChapterEntity bookChapterEntity = bookChapterService.getBaseMapper().selectById(chapterid); Integer number = bookChapterEntity.getNumber(); // 阅读章节数 大于 免费章节数 - if ((number > freeChapterCount) || freeChapterCount ==0){ + if ((number > freeChapterCount) || freeChapterCount == 0) { if (isVip == 1) { MyUserEntity user = myUserService.getById(userId); String vip = user.getVip(); if (!"1".equals(vip)) { - return R.error(500,"当前书籍为会员书籍,请开通会员或购买!"); + return R.error(500, "当前书籍为会员书籍,请开通会员或购买!"); } } if (isVip == 2) { boolean b = myUserService.bookAuthenticate(bookid, userId); if (!b) { - return R.error(500,"请购买此书籍!"); + return R.error(500, "请购买此书籍!"); } } } - ArrayList list = new ArrayList<>(); List bookChapterContentEntities = bookChapterContentService.getBaseMapper().selectList(new QueryWrapper() - .eq("book_id",bookid) - .eq("book_chatper_id",chapterid)); + .eq("book_id", bookid) + .eq("book_chatper_id", chapterid)); for (BookChapterContentEntity bookChapterContentEntity : bookChapterContentEntities) { String content = bookChapterContentEntity.getContent(); String substring = ""; - if (bookChapterContentEntity.getOtherContent() != null){ - substring = bookChapterContentEntity.getOtherContent().replace("

","").replace("

",""); + if (bookChapterContentEntity.getOtherContent() != null) { + substring = bookChapterContentEntity.getOtherContent().replace("

", "").replace("

", ""); } StringBuffer stringBuffer = new StringBuffer(substring); - if(stringBuffer.indexOf("title") != -1){ - stringBuffer.insert(stringBuffer.indexOf("title"),"width=\"100%\""); + if (stringBuffer.indexOf("title") != -1) { + stringBuffer.insert(stringBuffer.indexOf("title"), "width=\"100%\""); } - if (bookChapterContentEntity.getNumber() == 1){ + if (bookChapterContentEntity.getNumber() == 1) { Integer bookChatperId = bookChapterContentEntity.getBookChatperId(); BookChapterEntity chapterEntity = bookChapterService.getById(bookChatperId); String chapter = chapterEntity.getChapter(); content = bookChapterContentEntity.getContent().replace(chapter, ""); } - bookChapterContentEntity.setPicAndWord(content.replaceAll(" ","") + stringBuffer); + bookChapterContentEntity.setPicAndWord(content.replaceAll(" ", "") + stringBuffer); list.add(bookChapterContentEntity); } - return R.ok().put("bookCatalogue",list); + return R.ok().put("bookCatalogue", list); } //生成电子书 目录 @RequestMapping("/getWordChapterParagraph") - public R getWordChapterParagraph(@RequestParam Map params){ + public R getWordChapterParagraph(@RequestParam Map params) { bookChapterContentService.getWordChapterParagraph(14); return R.ok(); } diff --git a/src/main/java/com/peanut/modules/book/controller/BookController.java b/src/main/java/com/peanut/modules/book/controller/BookController.java index a708c582..7a57a9ed 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookController.java @@ -7,13 +7,11 @@ import java.util.stream.Collectors; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.peanut.common.utils.ReadProvinceUtil; import com.peanut.modules.book.dao.BookDao; import com.peanut.modules.book.entity.*; import com.peanut.modules.book.service.*; import com.peanut.modules.book.vo.BookIndexVo; -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.*; @@ -58,7 +56,7 @@ public class BookController { @Autowired private ShopProductService shopProductService; @Autowired - private ShopProudictBookService shopProudictBookService; + private ShopProductBookService shopProductBookService; @Autowired private ShopProductToLabelService shopProductToLabelService; final ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10); @@ -123,7 +121,7 @@ public class BookController { BookEntity book_info = bookService.getById(bookId); book_info.setAuthor(authorService.getById(book_info.getAuthorId())); book_info.setPublisher(publisherService.getById(book_info.getPublisherId())); - book_info.setProductId(shopProudictBookService.getProductByBookId(bookId)); + book_info.setProductId(shopProductBookService.getProductByBookId(bookId)); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(UserEbookBuyEntity::getUserId,userId); @@ -715,7 +713,7 @@ public class BookController { } Page bookEntityPage = bookService.getBaseMapper().selectPage(new Page<>(page, limit), wrapper1); for (BookEntity b : bookEntityPage.getRecords()){ - b.setProductId(shopProudictBookService.getProductByBookId(b.getId())); + b.setProductId(shopProductBookService.getProductByBookId(b.getId())); } return R.ok().put("page",bookEntityPage); diff --git a/src/main/java/com/peanut/modules/book/controller/BookTeachController.java b/src/main/java/com/peanut/modules/book/controller/BookTeachController.java index a2fbf3a8..65ed664a 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookTeachController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookTeachController.java @@ -7,16 +7,13 @@ import com.peanut.modules.book.entity.BookEntity; import com.peanut.modules.book.entity.BookTeachEntity; import com.peanut.modules.book.service.BookService; import com.peanut.modules.book.service.BookTeachService; -import com.peanut.modules.book.service.ShopProudictBookService; +import com.peanut.modules.book.service.ShopProductBookService; import org.springframework.beans.factory.annotation.Autowired; 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 java.util.ArrayList; -import java.util.List; - @RestController @RequestMapping("book/teach") public class BookTeachController { @@ -25,123 +22,82 @@ public class BookTeachController { @Autowired private BookService bookService; @Autowired - private ShopProudictBookService shopProudictBookService; + private ShopProductBookService shopProductBookService; /** * 获取讲书列表 + * * @return */ @RequestMapping("/getTeachBooks") - public R getTeachBooks(@RequestParam Integer limit,@RequestParam Integer page){ + public R getTeachBooks(@RequestParam Integer limit, @RequestParam Integer page) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(BookEntity::getDelFlag,0); - wrapper.eq(BookEntity::getTeachIn,1); + wrapper.eq(BookEntity::getDelFlag, 0); + wrapper.eq(BookEntity::getTeachIn, 1); Page bookEntityPage = bookService.getBaseMapper().selectPage(new Page(page, limit), wrapper); - return R.ok().put("page",bookEntityPage); + return R.ok().put("page", bookEntityPage); } /** * 获取讲书目录 + * * @return */ @RequestMapping("/getBookTeachItems") - public R getBookTeachItems(@RequestParam Integer bookId,@RequestParam Integer limit,@RequestParam Integer page){ + public R getBookTeachItems(@RequestParam Integer bookId, @RequestParam Integer limit, @RequestParam Integer page) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(BookTeachEntity::getBookId,bookId); - wrapper.eq(BookTeachEntity::getDelFlag,0); + wrapper.eq(BookTeachEntity::getBookId, bookId); + wrapper.eq(BookTeachEntity::getDelFlag, 0); wrapper.orderByAsc(BookTeachEntity::getChapter); Page bookTeachEntityPage = bookTeachService.getBaseMapper().selectPage(new Page(page, limit), wrapper); - return R.ok().put("page",bookTeachEntityPage); + return R.ok().put("page", bookTeachEntityPage); } /** * 获取讲书的详情 + * * @param teachId * @return */ @RequestMapping("/getTeachDetail") - public R getTeachDetail(@RequestParam Integer teachId){ + public R getTeachDetail(@RequestParam Integer teachId) { BookTeachEntity teach_info = bookTeachService.getById(teachId); - Integer productByBookId = shopProudictBookService.getProductByBookId(teach_info.getBookId()); - return R.ok().put("bookTeach",teach_info).put("product",productByBookId); + Integer productByBookId = shopProductBookService.getProductByBookId(teach_info.getBookId()); + return R.ok().put("bookTeach", teach_info).put("product", productByBookId); } - - - /** - * 添加讲书 - * @return - */ -// @RequestMapping("/addTeach") -// public R addTeach(@RequestParam Integer bookId, -// @RequestParam Integer chapter, -// @RequestParam String title, -// @RequestParam String voices, -// @RequestParam String content){ -// BookTeachEntity bookTeachEntity = new BookTeachEntity(); -// bookTeachEntity.setBookId(bookId); -// bookTeachEntity.setChapter(chapter); -// bookTeachEntity.setTitle(title); -// bookTeachEntity.setVoices(voices); -// bookTeachEntity.setContent(content); -// bookTeachService.save(bookTeachEntity); -// -// return R.ok(); -// } - /** * 添加讲书的章节 + * * @param bookTeach * @return */ @RequestMapping("/addTeach1") - public R addTeach1(@RequestBody BookTeachEntity bookTeach){ + public R addTeach1(@RequestBody BookTeachEntity bookTeach) { bookTeachService.save(bookTeach); return R.ok(); } /** * 删除讲书章节 + * * @return */ @RequestMapping("/delTeach") - public R delTeach(@RequestBody BookTeachEntity bookTeach){ + public R delTeach(@RequestBody BookTeachEntity bookTeach) { bookTeachService.removeById(bookTeach.getTeachId()); return R.ok(); } /** * 编辑讲书的章节 - * @return - */ -// @RequestMapping("/updateTeach") -// public R updateTeach(@RequestParam Integer teachId, -// @RequestParam Integer chapter, -// @RequestParam String title, -// @RequestParam String voices, -// @RequestParam String content){ -// -// BookTeachEntity bookTeachEntity = new BookTeachEntity(); -// bookTeachEntity.setTeachId(teachId); -// bookTeachEntity.setTitle(title); -// bookTeachEntity.setVoices(voices); -// bookTeachEntity.setContent(content); -// bookTeachService.updateById(bookTeachEntity); -// return R.ok(); -// -// } - - /** - * 编辑讲书的章节 + * * @return */ @RequestMapping("/updateTeach") - public R updateTeach(@RequestBody BookTeachEntity bookTeach){ + public R updateTeach(@RequestBody BookTeachEntity bookTeach) { bookTeachService.updateById(bookTeach); return R.ok(); } - - - } diff --git a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java index f0141438..12fe0620 100644 --- a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java +++ b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java @@ -63,7 +63,7 @@ public class BuyOrderController { private RabbitTemplate rabbitTemplate; @Autowired - private ShopProudictBookService shopProudictBookService; + private ShopProductBookService shopProductBookService; /** * 列表 @@ -523,9 +523,9 @@ public class BuyOrderController { private void addEbookToUser(List products, BuyOrderEntity buyOrder) { List productIds = products.stream().map(BuyOrderDetailEntity::getProductId).collect(Collectors.toList()); for (Integer productId : productIds) { - List collect = shopProudictBookService.getBaseMapper().selectList(new LambdaQueryWrapper() - .eq(ShopProudictBookEntity::getProudictId, productId) - .eq(ShopProudictBookEntity::getDelFlag, 0)).stream().map(ShopProudictBookEntity::getBookId).collect(Collectors.toList()); + List collect = shopProductBookService.getBaseMapper().selectList(new LambdaQueryWrapper() + .eq(ShopProductBookEntity::getProductId, productId) + .eq(ShopProductBookEntity::getDelFlag, 0)).stream().map(ShopProductBookEntity::getBookId).collect(Collectors.toList()); userEbookBuyService.addBookForUser(buyOrder.getUserId(), collect); } } diff --git a/src/main/java/com/peanut/modules/book/controller/ShopProductBookController.java b/src/main/java/com/peanut/modules/book/controller/ShopProductBookController.java new file mode 100644 index 00000000..0c4e1699 --- /dev/null +++ b/src/main/java/com/peanut/modules/book/controller/ShopProductBookController.java @@ -0,0 +1,75 @@ +package com.peanut.modules.book.controller; + +import com.peanut.common.utils.PageUtils; +import com.peanut.common.utils.R; +import com.peanut.modules.book.entity.ShopProductBookEntity; +import com.peanut.modules.book.service.ShopProductBookService; +import com.peanut.modules.book.vo.ProductBookQueryVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("book/shopProudictBook") +public class ShopProductBookController { + @Autowired + private ShopProductBookService shopProductBookService; + + /** + * 列表 + */ + @RequestMapping("/list") + public R list(@RequestParam Map params) { + PageUtils page = shopProductBookService.queryPage(params); + return R.ok().put("page", page); + + } + + /** + * 图书与商品信息 + */ + // 根据商品id查询图书信息,查询到图书信息,反向查找包含该图书id的所有商品返回 + @RequestMapping("/proudictBooklist") + public R productBookList(@RequestParam Integer productId) { + List cartList = shopProductBookService.getCartList(productId); + return R.ok().put("cartList", cartList); + + } + + /** + * 保存 + */ + @RequestMapping("/save") + public R save(@RequestBody ShopProductBookEntity shopProductBookEntity) { + for (Integer s : shopProductBookEntity.getBookIdList()) { + if (s != null) { + Integer productId = shopProductBookEntity.getProductId(); + shopProductBookEntity.setProductId(productId); + shopProductBookEntity.setBookId(s); + shopProductBookService.save(shopProductBookEntity); + } + } + return R.ok(); + } + + /** + * 修改 + */ + @RequestMapping("/update") + public R update(@RequestBody ShopProductBookEntity shopProductBookEntity) { + + shopProductBookService.updateById(shopProductBookEntity); + return R.ok(); + } + + /** + * 删除 + */ + @RequestMapping("/delete") + public R delete(@RequestParam Integer id) { + shopProductBookService.removeById(id); + return R.ok(); + } +} diff --git a/src/main/java/com/peanut/modules/book/controller/ShopProductController.java b/src/main/java/com/peanut/modules/book/controller/ShopProductController.java index 128c8317..ff7a3691 100644 --- a/src/main/java/com/peanut/modules/book/controller/ShopProductController.java +++ b/src/main/java/com/peanut/modules/book/controller/ShopProductController.java @@ -1,6 +1,8 @@ package com.peanut.modules.book.controller; + import java.util.*; import java.util.stream.Collectors; + import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.peanut.modules.book.entity.*; import com.peanut.modules.book.service.*; @@ -15,7 +17,6 @@ import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.R; - /** * 商品表 * @@ -35,27 +36,25 @@ public class ShopProductController { @Autowired private BookService bookService; @Autowired - private ShopProudictBookService shopProudictBookService; + private ShopProductBookService shopProductBookService; @Autowired private ShopProductToLabelService shopProductToLabelService; - @Autowired - private ShopProductLabelService shopProductLabelService; /** - * 精选商品 列表 + * 精选商品 列表 */ @RequestMapping("/listproductSales") -// @RequiresPermissions("book:shopproduct:list") - public R listproductSales(@RequestParam Map params){ + public R listProductSales(@RequestParam Map params) { PageUtils page = shopProductService.queryPageproductSales(params); return R.ok().put("page", page); } + /** * 折扣商品 */ @RequestMapping("/listactivityprice") - public R listactivityprice(@RequestParam Map params){ + public R listActivityPrice(@RequestParam Map params) { PageUtils page = shopProductService.queryPageactivityprice(params); return R.ok().put("page", page); @@ -65,18 +64,17 @@ public class ShopProductController { * 列表 */ @RequestMapping("/list") -// @RequiresPermissions("book:shopproduct:list") - public R list(@RequestParam Map params){ + public R list(@RequestParam Map params) { PageUtils page = shopProductService.appQueryPage(params); return R.ok().put("page", page); -} + } /** * 查询列表 */ @RequestMapping("/selectList") - public R selectList(@RequestParam Map params){ + public R selectList(@RequestParam Map params) { PageUtils page = shopProductService.selectListqueryPage(params); return R.ok().put("page", page); @@ -90,19 +88,15 @@ public class ShopProductController { } - - - - - /** - * 未购买书列表 - * @param userId 用户id + * 未购买书列表 + * + * @param userId 用户id * @return */ @RequestMapping("/booklist") - public R booklistss(@RequestParam("userId") Integer userId - ) { + public R bookList(@RequestParam("userId") Integer userId + ) { //查询已购买的书籍 List buyOrderDetailEntities = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper() .eq("user_id", userId)); @@ -118,17 +112,17 @@ public class ShopProductController { } //查询商品表并过滤已购买商品id,根据时间倒叙展示 List allProductEntities = shopProductService.getBaseMapper().selectList(new QueryWrapper() - .notIn("product_id", purchasedProductIds) - .orderByDesc("create_time") + .notIn("product_id", purchasedProductIds) + .orderByDesc("create_time") // .notLike("book_ids",",") - .isNotNull("book_ids") + .isNotNull("book_ids") ); List lists = new ArrayList<>(); for (ShopProductEntity product : allProductEntities) { Map productMap = new HashMap<>(); - productMap.put("product",product); + productMap.put("product", product); lists.add(productMap); } @@ -137,20 +131,17 @@ public class ShopProductController { } - - - @RequestMapping("/bookinfo/{productId}") - public R bookinfo(@PathVariable("productId") Integer productId){ - ArrayList> imagesUrl = new ArrayList>(); - List bookEntityList = shopProudictBookService.getBaseMapper().selectList(new QueryWrapper().eq("book_id", productId)); + public R bookInfo(@PathVariable("productId") Integer productId) { + ArrayList> imagesUrl = new ArrayList>(); + List bookEntityList = shopProductBookService.getBaseMapper().selectList(new QueryWrapper().eq("book_id", productId)); List list = new ArrayList<>(); ArrayList booklist = new ArrayList<>(); - ShopProductEntity shopProductEntity=null; - for (ShopProudictBookEntity shopProudictBookEntity : bookEntityList) { - Integer proudictId = shopProudictBookEntity.getProudictId(); + ShopProductEntity shopProductEntity = null; + for (ShopProductBookEntity shopProductBookEntity : bookEntityList) { + Integer proudictId = shopProductBookEntity.getProductId(); shopProductEntity = shopProductService.getBaseMapper().selectOne(new QueryWrapper().eq("product_id", proudictId)); - Integer bookId = shopProudictBookEntity.getBookId(); + Integer bookId = shopProductBookEntity.getBookId(); BookEntity byId = bookService.getById(bookId); booklist.add(String.valueOf(bookId)); list.add(byId); @@ -163,8 +154,6 @@ public class ShopProductController { } - - @RequestMapping("/bookinfolists/{productId}") public R bookinfolists(@PathVariable("productId") Integer productId) { //查询商品 @@ -176,31 +165,31 @@ public class ShopProductController { Integer productId1 = shopProductEntity.getProductId(); //分类信息 List poids = shopCategoryService.findPoid(poid); - List proudict = shopProudictBookService.getBaseMapper().selectList(new QueryWrapper() - .eq("proudict_id", productId1)); + List product = shopProductBookService.getBaseMapper().selectList(new QueryWrapper() + .eq("product_id", productId1)); List result = new ArrayList<>(); //获取商品id Set productIds = new HashSet<>(); productIds.add(productId); - for (ShopProudictBookEntity shopProudictBookEntity : proudict) { - Integer bookId = shopProudictBookEntity.getBookId(); + for (ShopProductBookEntity shopProductBookEntity : product) { + Integer bookId = shopProductBookEntity.getBookId(); BookEntity byId = bookService.getById(bookId); - List entityByBookId = shopProudictBookService.getBaseMapper().selectList(new QueryWrapper() + List entityByBookId = shopProductBookService.getBaseMapper().selectList(new QueryWrapper() .eq("book_id", bookId)); - for(ShopProudictBookEntity entity : entityByBookId){ - productIds.add(entity.getProudictId()); + for (ShopProductBookEntity entity : entityByBookId) { + productIds.add(entity.getProductId()); } } - for(Integer pId : productIds){ - ShopProductEntity proEntity =null; + for (Integer pId : productIds) { + ShopProductEntity proEntity = null; proEntity = shopProductService.getById(pId); - List pbookEntitys = shopProudictBookService.getBaseMapper().selectList(new QueryWrapper() - .eq("proudict_id", pId)); + List pbookEntitys = shopProductBookService.getBaseMapper().selectList(new QueryWrapper() + .eq("product_id", pId)); ArrayList booklist = new ArrayList<>(); List list = new ArrayList<>(); - for (ShopProudictBookEntity shopProudictBookEntity : pbookEntitys) { - booklist.add(String.valueOf(shopProudictBookEntity.getBookId())); - BookEntity byId = bookService.getById(shopProudictBookEntity.getBookId()); + for (ShopProductBookEntity shopProductBookEntity : pbookEntitys) { + booklist.add(String.valueOf(shopProductBookEntity.getBookId())); + BookEntity byId = bookService.getById(shopProductBookEntity.getBookId()); list.add(byId); } proEntity.setPoids(poids); @@ -214,6 +203,7 @@ public class ShopProductController { /** * 获取关联订单列表 + * * @param productId * @return */ @@ -221,45 +211,46 @@ public class ShopProductController { public R getGlProductList(@RequestParam int productId) { //获取此商品下的books - List ids = shopProudictBookService.getBookidsByProductId(productId); + List ids = shopProductBookService.getBookIdsByProductId(productId); - if(ids.size()==0){ + if (ids.size() == 0) { return R.ok(); } - List ss = shopProudictBookService.getBaseMapper().selectList(new QueryWrapper() - .eq("del_flag",0) - .in("book_id",ids) - .groupBy("proudict_id") - .having("count(proudict_id) >="+ids.size()) + List ss = shopProductBookService.getBaseMapper().selectList(new QueryWrapper() + .eq("del_flag", 0) + .in("book_id", ids) + .groupBy("product_id") + .having("count(product_id) >=" + ids.size()) ); List frag = new ArrayList<>(); //如果绑定的书为空,直接返回空值 - if(ids.size()==0){ + if (ids.size() == 0) { return R.ok(); } - for (ShopProudictBookEntity spbe : ss){ - ShopProductEntity ca_sp = shopProductService.getById(spbe.getProudictId()); + for (ShopProductBookEntity spbe : ss) { + ShopProductEntity ca_sp = shopProductService.getById(spbe.getProductId()); frag.add(ca_sp); } - return R.ok().put("result",frag); + return R.ok().put("result", frag); } /** * 信息 + * * @param productId * @return */ @RequestMapping("/info/{productId}") - public R info(@PathVariable("productId") Integer productId){ - ShopProductEntity shopProductEntity = shopProductService.getBaseMapper().selectOne(new QueryWrapper().eq("product_id", productId).eq("del_flag",0)); - if (shopProductEntity == null) { - return R.error("该商品已下架,看看其他商品吧"); - } - ArrayList> imagesUrl = new ArrayList>(); + public R info(@PathVariable("productId") Integer productId) { + ShopProductEntity shopProductEntity = shopProductService.getBaseMapper().selectOne(new QueryWrapper().eq("product_id", productId).eq("del_flag", 0)); + if (shopProductEntity == null) { + return R.error("该商品已下架,看看其他商品吧"); + } + ArrayList> imagesUrl = new ArrayList>(); Integer poid = shopProductEntity.getProductPid(); Integer productId1 = shopProductEntity.getProductId(); @@ -268,11 +259,11 @@ public class ShopProductController { List list = new ArrayList<>(); List bookIdlist = new ArrayList<>(); ArrayList booklist = new ArrayList<>(); - List proudict = shopProudictBookService.getBaseMapper().selectList(new QueryWrapper() - .eq("proudict_id", productId1)); - for (ShopProudictBookEntity shopProudictBookEntity : proudict) { - Integer id = shopProudictBookEntity.getId(); - Integer bookId = shopProudictBookEntity.getBookId(); + List product = shopProductBookService.getBaseMapper().selectList(new QueryWrapper() + .eq("product_id", productId1)); + for (ShopProductBookEntity shopProductBookEntity : product) { + Integer id = shopProductBookEntity.getId(); + Integer bookId = shopProductBookEntity.getBookId(); BookEntity byId = bookService.getById(bookId); bookIdlist.add(id); @@ -282,9 +273,9 @@ public class ShopProductController { //添加获取标签逻辑 List shopProductToLabelEntities = shopProductToLabelService.getBaseMapper().selectList(new QueryWrapper() - .eq("product_id",productId).eq("del_flag",0)); + .eq("product_id", productId).eq("del_flag", 0)); List labelList = new ArrayList(); - for (ShopProductToLabelEntity sp : shopProductToLabelEntities){ + for (ShopProductToLabelEntity sp : shopProductToLabelEntities) { labelList.add(sp.getSplId()); } @@ -292,32 +283,31 @@ public class ShopProductController { shopProductEntity.setBookidsimages(list); shopProductEntity.setBookids(booklist); shopProductEntity.setShoproudIds(bookIdlist); - return R.ok().put("shopProduct", shopProductEntity).put("labels",labelList); + return R.ok().put("shopProduct", shopProductEntity).put("labels", labelList); } - - /** - * 根据传入商品id反向查询图书id,然后查询图书id下包含的商品 + * 根据传入商品id反向查询图书id,然后查询图书id下包含的商品 + * * @param productId * @return */ @RequestMapping("/infobook/{productId}") public R infobook(@PathVariable("productId") Integer productId) { - List proudict = shopProudictBookService.getBaseMapper().selectList(new QueryWrapper() - .eq("proudict_id", productId)); + List proudict = shopProductBookService.getBaseMapper().selectList(new QueryWrapper() + .eq("product_id", productId)); List list = new ArrayList<>(); - for (ShopProudictBookEntity shopProudictBookEntity : proudict) { - Integer bookId = shopProudictBookEntity.getBookId(); + for (ShopProductBookEntity shopProductBookEntity : proudict) { + Integer bookId = shopProductBookEntity.getBookId(); - List bookIds = shopProudictBookService.getBaseMapper().selectList(new QueryWrapper() + List bookIds = shopProductBookService.getBaseMapper().selectList(new QueryWrapper() .eq("book_id", bookId)); - for (ShopProudictBookEntity shopProudict : bookIds) { - Integer proudictId = shopProudict.getProudictId(); + for (ShopProductBookEntity shopProduct : bookIds) { + Integer shopProductId = shopProduct.getProductId(); List shopProductEntities = shopProductService.getBaseMapper().selectList(new QueryWrapper() - .eq("proudict_id",proudictId)); + .eq("product_id", shopProductId)); list.add(shopProductEntities); } } @@ -334,147 +324,138 @@ public class ShopProductController { shopProduct.setCreateTime(new Date()); String bkids = ""; - for(String s : shopProduct.getBookids()){ - bkids += s+","; + 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(""); } - if (bkids!=null &&!bkids.isEmpty()){ - String substring = bkids.substring(0, bkids.length() - 1); - shopProduct.setBookId(substring); - }else { - shopProduct.setBookId(""); - } shopProductService.save(shopProduct); - ShopProudictBookEntity shopProudictBookEntity = new ShopProudictBookEntity(); + ShopProductBookEntity shopProductBookEntity = new ShopProductBookEntity(); for (String s : shopProduct.getBookids()) { String bookidlist = s; if (bookidlist != null) { Integer proudict = shopProduct.getProductId(); - shopProudictBookEntity.setProudictId(proudict); - shopProudictBookEntity.setBookId(Integer.valueOf(bookidlist)); - shopProudictBookService.save(shopProudictBookEntity); + shopProductBookEntity.setProductId(proudict); + shopProductBookEntity.setBookId(Integer.valueOf(bookidlist)); + shopProductBookService.save(shopProductBookEntity); } } return R.ok(); } + /** * 修改 */ - @RequestMapping("/update") + @RequestMapping("/update") public R update(@RequestBody ShopProductEntity shopProduct) { - //商品id - Integer productId = shopProduct.getProductId(); - 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); - } else { - shopProduct.setBookId(""); - } - //传过来的proudictid只有一个,但是bookid可能有多个,对应的一个proudictid一个bookid为一条数据,一对多存储 - List bookyList = shopProudictBookService.getBaseMapper().selectList(new QueryWrapper() - .eq("proudict_id", productId)); - Integer shop_book_ids [] = new Integer[bookyList.size()]; - for(int i=0; i 0){ - shopProudictBookService.getBaseMapper().deleteBatchIds(Arrays.asList(shop_book_ids)); - } - - ShopProudictBookEntity shopProudictBookEntity = new ShopProudictBookEntity(); - for (String s : shopProduct.getBookids()) { - String bookidlist = s; - if (bookidlist != null) { - Integer proudict = shopProduct.getProductId(); - shopProudictBookEntity.setProudictId(proudict); - shopProudictBookEntity.setBookId(Integer.valueOf(bookidlist)); - shopProudictBookService.save(shopProudictBookEntity); - } - } - - - //对于标签的增和删 - List shopProductToLabelEntities_now = shopProductToLabelService.getBaseMapper().selectList(new QueryWrapper() - .eq("product_id", productId)); - List m_spl_ids = shopProduct.getShoproudLabels(); - //删除 - for (ShopProductToLabelEntity sn:shopProductToLabelEntities_now){ - if(!m_spl_ids.contains(sn.getSplId())){ - shopProductToLabelService.removeById(sn.getPtlId()); - } - } - //添加 - for (String m:m_spl_ids){ - Integer spl_id = Integer.valueOf(m); - ShopProductToLabelEntity byId = shopProductToLabelService.getBaseMapper().selectOne(new QueryWrapper() - .eq("spl_id",spl_id).eq("product_id",productId)); - if(byId==null){ - ShopProductToLabelEntity shopProductToLabelEntity = new ShopProductToLabelEntity(); - shopProductToLabelEntity.setProductId(productId); - shopProductToLabelEntity.setSplId(spl_id); - shopProductToLabelService.save(shopProductToLabelEntity); - } - } - - shopProductService.updateById(shopProduct); - return R.ok(); + //商品id + Integer productId = shopProduct.getProductId(); + 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); + } else { + shopProduct.setBookId(""); + } + //传过来的proudictid只有一个,但是bookid可能有多个,对应的一个proudictid一个bookid为一条数据,一对多存储 + List bookyList = shopProductBookService.getBaseMapper().selectList(new QueryWrapper() + .eq("product_id", productId)); + Integer shop_book_ids[] = new Integer[bookyList.size()]; + for (int i = 0; i < bookyList.size(); i++) { + shop_book_ids[i] = bookyList.get(i).getId(); + } + if (null != shop_book_ids && shop_book_ids.length > 0) { + shopProductBookService.getBaseMapper().deleteBatchIds(Arrays.asList(shop_book_ids)); + } + + ShopProductBookEntity shopProductBookEntity = new ShopProductBookEntity(); + for (String s : shopProduct.getBookids()) { + String bookidlist = s; + if (bookidlist != null) { + Integer proudict = shopProduct.getProductId(); + shopProductBookEntity.setProductId(proudict); + shopProductBookEntity.setBookId(Integer.valueOf(bookidlist)); + shopProductBookService.save(shopProductBookEntity); + } + } + + + //对于标签的增和删 + List shopProductToLabelEntities_now = shopProductToLabelService.getBaseMapper().selectList(new QueryWrapper() + .eq("product_id", productId)); + List m_spl_ids = shopProduct.getShoproudLabels(); + //删除 + for (ShopProductToLabelEntity sn : shopProductToLabelEntities_now) { + if (!m_spl_ids.contains(sn.getSplId())) { + shopProductToLabelService.removeById(sn.getPtlId()); + } + } + //添加 + for (String m : m_spl_ids) { + Integer spl_id = Integer.valueOf(m); + ShopProductToLabelEntity byId = shopProductToLabelService.getBaseMapper().selectOne(new QueryWrapper() + .eq("spl_id", spl_id).eq("product_id", productId)); + if (byId == null) { + ShopProductToLabelEntity shopProductToLabelEntity = new ShopProductToLabelEntity(); + shopProductToLabelEntity.setProductId(productId); + shopProductToLabelEntity.setSplId(spl_id); + shopProductToLabelService.save(shopProductToLabelEntity); + } + } + + shopProductService.updateById(shopProduct); + return R.ok(); + } /** * 删除 */ @RequestMapping("/delete") - public R delete(@RequestBody Integer[] productIds){ + public R delete(@RequestBody Integer[] productIds) { - List bookEntityList = shopProudictBookService.getBaseMapper().selectList(new QueryWrapper() - .in("proudict_id", productIds) + List bookEntityList = shopProductBookService.getBaseMapper().selectList(new QueryWrapper() + .in("product_id", productIds) ); - for (ShopProudictBookEntity shopProudictBookEntity : bookEntityList) { - Integer id = shopProudictBookEntity.getId(); - shopProudictBookService.removeById(id); + for (ShopProductBookEntity shopProductBookEntity : bookEntityList) { + Integer id = shopProductBookEntity.getId(); + shopProductBookService.removeById(id); } - shopProductService.removeByIds(Arrays.asList(productIds)); + shopProductService.removeByIds(Arrays.asList(productIds)); return R.ok(); } - - - - - /** * 列表 */ @RequestMapping("/appGetList") - public R appGetList(@RequestParam Map params){ + public R appGetList(@RequestParam Map params) { PageUtils page = shopProductService.queryPage(params); return R.ok().put("page", page); } - - - - - /** * 获取分类下商品列表 */ @RequestMapping("/appGetCategoryList") - public R appGetCategoryList(@RequestParam("catId") Integer catId){ + public R appGetCategoryList(@RequestParam("catId") Integer catId) { List list1 = shopCategoryService.getBaseMapper().selectList(new QueryWrapper() - .eq("cat_id",catId)); + .eq("cat_id", catId)); if (catId == null) { } - if(catId == 0){ + if (catId == 0) { catId = null; } List list = shopProductService.appGetCategoryList(catId); @@ -485,7 +466,7 @@ public class ShopProductController { * 远程搜索 */ @RequestMapping("/prodSearch") - public R prodSearch(){ + public R prodSearch() { List list = shopProductService.list(new QueryWrapper().select("product_id,product_name")); List collect = list.stream().map(shopProductEntity -> { ShopProductVo shopProductVo = new ShopProductVo(); @@ -500,11 +481,10 @@ public class ShopProductController { * 优惠券获取商品信息 */ @RequestMapping("/backProdSearch") - public R backProdSearch(@RequestParam Map params){ + public R backProdSearch(@RequestParam Map params) { String productName = (String) params.get("productName"); List list = shopProductService.list(new QueryWrapper() - .like("product_name",productName)); + .like("product_name", productName)); return R.ok().put("list", list); } - } diff --git a/src/main/java/com/peanut/modules/book/controller/ShopProudictBookController.java b/src/main/java/com/peanut/modules/book/controller/ShopProudictBookController.java deleted file mode 100644 index 964d0c3d..00000000 --- a/src/main/java/com/peanut/modules/book/controller/ShopProudictBookController.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.peanut.modules.book.controller; -import com.peanut.common.utils.PageUtils; -import com.peanut.common.utils.R; -import com.peanut.modules.book.entity.ShopProudictBookEntity; -import com.peanut.modules.book.service.ShopProudictBookService; -import com.peanut.modules.book.vo.ProudictBookqueryVO; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; -import java.util.List; -import java.util.Map; - -@RestController -@RequestMapping("book/shopProudictBook") -public class ShopProudictBookController { - @Autowired - private ShopProudictBookService shopProudictBookService; - /** - * 列表 - */ - @RequestMapping("/list") - public R list(@RequestParam Map params ){ - PageUtils page = shopProudictBookService.queryPage(params); - return R.ok().put("page", page); - - } - /** - * 图书与商品信息 - */ - // 根据商品id查询图书信息,查询到图书信息,反向查找包含该图书id的所有商品返回 - @RequestMapping("/proudictBooklist") - public R proudictBooklist(@RequestParam Integer proudictId){ - List cartList = shopProudictBookService.getCartList(proudictId); - return R.ok().put("cartList", cartList); - - } - /** - * 保存 - */ - @RequestMapping("/save") - public R save(@RequestBody ShopProudictBookEntity shopProudictBookEntity){ - - for(Integer s : shopProudictBookEntity.getBookidlist()){ - Integer bookidlist = s; - if (bookidlist!=null){ - Integer proudict = shopProudictBookEntity.getProudictId(); - shopProudictBookEntity.setProudictId(proudict); - shopProudictBookEntity.setBookId(bookidlist); - shopProudictBookService.save(shopProudictBookEntity); - - } - } - return R.ok(); - } - - /** - * 修改 - */ - @RequestMapping("/update") - public R update(@RequestBody ShopProudictBookEntity shopProudictBookEntity){ - - shopProudictBookService.updateById(shopProudictBookEntity); - return R.ok(); - } - /** - * 删除 - */ - @RequestMapping("/delete") - public R delete(@RequestParam Integer id){ - shopProudictBookService.removeById(id); - return R.ok(); - } - - - - - - - - - - - - - - - - - - - - - - - -} diff --git a/src/main/java/com/peanut/modules/book/dao/ShopProudictBookDao.java b/src/main/java/com/peanut/modules/book/dao/ShopProductBookDao.java similarity index 60% rename from src/main/java/com/peanut/modules/book/dao/ShopProudictBookDao.java rename to src/main/java/com/peanut/modules/book/dao/ShopProductBookDao.java index 298bf77f..90f7942a 100644 --- a/src/main/java/com/peanut/modules/book/dao/ShopProudictBookDao.java +++ b/src/main/java/com/peanut/modules/book/dao/ShopProductBookDao.java @@ -1,13 +1,13 @@ package com.peanut.modules.book.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.peanut.modules.book.entity.ShopProudictBookEntity; +import com.peanut.modules.book.entity.ShopProductBookEntity; import org.apache.ibatis.annotations.Mapper; import java.util.List; @Mapper -public interface ShopProudictBookDao extends BaseMapper { +public interface ShopProductBookDao extends BaseMapper { List getOrderBookId(String orderSn); } diff --git a/src/main/java/com/peanut/modules/book/entity/ShopProudictBookEntity.java b/src/main/java/com/peanut/modules/book/entity/ShopProductBookEntity.java similarity index 53% rename from src/main/java/com/peanut/modules/book/entity/ShopProudictBookEntity.java rename to src/main/java/com/peanut/modules/book/entity/ShopProductBookEntity.java index 46e8e99a..b0f30516 100644 --- a/src/main/java/com/peanut/modules/book/entity/ShopProudictBookEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/ShopProductBookEntity.java @@ -1,21 +1,27 @@ package com.peanut.modules.book.entity; + import com.baomidou.mybatisplus.annotation.*; import lombok.Data; + import java.util.ArrayList; import java.util.Date; -@Data -@TableName("shop_proudict_book") -public class ShopProudictBookEntity { - @TableId - private Integer id; +@Data +@TableName("shop_product_book") +public class ShopProductBookEntity { + /** - * 商品id + * 主键 id */ - @TableField("proudict_id") - private Integer proudictId; + @TableId + private Integer id; /** - *图书id + * 商品id + */ + @TableField("product_id") + private Integer productId; + /** + * 图书id */ @TableField("book_id") private Integer bookId; @@ -23,18 +29,21 @@ public class ShopProudictBookEntity { * 多个图书id (备用) */ @TableField("book_ids") - private Integer bookdIds; - - + private Integer bookIds; + /** + * 删除标记 + */ @TableField("del_flag") @TableLogic - private Integer delFlag; + private Integer delFlag; /** * 创建日期 */ @TableField(fill = FieldFill.INSERT) private Date createTime; - // - @TableField(exist = false) - private ArrayList bookidlist; + /** + * 书籍列表 + */ + @TableField(exist = false) + private ArrayList bookIdList; } diff --git a/src/main/java/com/peanut/modules/book/service/ShopProductBookService.java b/src/main/java/com/peanut/modules/book/service/ShopProductBookService.java new file mode 100644 index 00000000..917fc925 --- /dev/null +++ b/src/main/java/com/peanut/modules/book/service/ShopProductBookService.java @@ -0,0 +1,24 @@ +package com.peanut.modules.book.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.peanut.common.utils.PageUtils; +import com.peanut.modules.book.entity.ShopProductBookEntity; +import com.peanut.modules.book.vo.ProductBookQueryVO; + +import java.util.List; +import java.util.Map; + +public interface ShopProductBookService extends IService { + PageUtils queryPage(Map params); + + PageUtils productBookQueryPage(Map params); + + List getCartList(Integer productId); + + List getBookIdsByProductId(Integer productId); + + Integer getProductByBookId(Integer bookId); + + List getOrderBookId(String orderSn); + +} diff --git a/src/main/java/com/peanut/modules/book/service/ShopProudictBookService.java b/src/main/java/com/peanut/modules/book/service/ShopProudictBookService.java deleted file mode 100644 index fde137a2..00000000 --- a/src/main/java/com/peanut/modules/book/service/ShopProudictBookService.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.peanut.modules.book.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.peanut.common.utils.PageUtils; -import com.peanut.modules.book.entity.ShopProudictBookEntity; -import com.peanut.modules.book.vo.ProudictBookqueryVO; - -import java.util.List; -import java.util.Map; - -public interface ShopProudictBookService extends IService { - PageUtils queryPage(Map params); - - PageUtils proudictBookqueryPage(Map params); - - List getCartList(Integer proudictId); - - List getBookidsByProductId(Integer productId); - - Integer getProductByBookId(Integer bookId); - - List getOrderBookId(String orderSn); - -} diff --git a/src/main/java/com/peanut/modules/book/service/impl/ShopProudictBookServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/ShopProductBookServiceImpl.java similarity index 53% rename from src/main/java/com/peanut/modules/book/service/impl/ShopProudictBookServiceImpl.java rename to src/main/java/com/peanut/modules/book/service/impl/ShopProductBookServiceImpl.java index 4e887746..68a75c2c 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/ShopProudictBookServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/ShopProductBookServiceImpl.java @@ -6,14 +6,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.Query; -import com.peanut.modules.book.dao.ShopProudictBookDao; +import com.peanut.modules.book.dao.ShopProductBookDao; import com.peanut.modules.book.entity.BookEntity; import com.peanut.modules.book.entity.ShopProductEntity; -import com.peanut.modules.book.entity.ShopProudictBookEntity; +import com.peanut.modules.book.entity.ShopProductBookEntity; import com.peanut.modules.book.service.BookService; import com.peanut.modules.book.service.ShopProductService; -import com.peanut.modules.book.service.ShopProudictBookService; -import com.peanut.modules.book.vo.ProudictBookqueryVO; +import com.peanut.modules.book.service.ShopProductBookService; +import com.peanut.modules.book.vo.ProductBookQueryVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,50 +22,50 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -@Service("shopProudictBookService") -public class ShopProudictBookServiceImpl extends ServiceImpl implements ShopProudictBookService { +@Service("shopProductBookService") +public class ShopProductBookServiceImpl extends ServiceImpl implements ShopProductBookService { @Autowired private ShopProductService shopProductService; @Autowired private BookService bookService; @Autowired - private ShopProudictBookDao shopProudictBookDao; + private ShopProductBookDao shopProductBookDao; @Override public PageUtils queryPage(Map params) { - IPage page = this.page( - new Query().getPage(params), - new QueryWrapper() + IPage page = this.page( + new Query().getPage(params), + new QueryWrapper<>() ); return new PageUtils(page); } @Override - public PageUtils proudictBookqueryPage(Map params) { + public PageUtils productBookQueryPage(Map params) { Object proudictId = params.get("proudictId"); - IPage page = this.page( - new Query().getPage(params), - new QueryWrapper().eq("proudict_id", proudictId) + IPage page = this.page( + new Query().getPage(params), + new QueryWrapper().eq("product_id", proudictId) ); - List records = page.getRecords(); + List records = page.getRecords(); return new PageUtils(page); } @Override - public List getCartList(Integer proudictId) { + public List getCartList(Integer productId) { - ShopProductEntity shopProductEntity = shopProductService.getBaseMapper().selectOne(new QueryWrapper().eq("proudict_id", proudictId)); - List proudictBooklist = this.list(new QueryWrapper().eq("proudict_id", proudictId)); + ShopProductEntity shopProductEntity = shopProductService.getBaseMapper().selectOne(new QueryWrapper().eq("product_id", productId)); + List proudictBooklist = this.list(new QueryWrapper().eq("product_id", productId)); List prList = new ArrayList<>(); List prLists = new ArrayList<>(); Map map = new HashMap<>(); - for (ShopProudictBookEntity shopProudictBookEntity : proudictBooklist) { - Integer bookId = shopProudictBookEntity.getBookId(); - List booklist = this.list(new QueryWrapper().eq("book_id", bookId)); - for (ShopProudictBookEntity shopProudictBook : booklist) { - Integer proudictId1 = shopProudictBook.getProudictId(); + for (ShopProductBookEntity shopProductBookEntity : proudictBooklist) { + Integer bookId = shopProductBookEntity.getBookId(); + List booklist = this.list(new QueryWrapper().eq("book_id", bookId)); + for (ShopProductBookEntity shopProudictBook : booklist) { + Integer proudictId1 = shopProudictBook.getProductId(); Integer bookId1 = shopProudictBook.getBookId(); BookEntity bookbyId = bookService.getById(bookId1); prList.add(bookbyId); @@ -78,10 +78,10 @@ public class ShopProudictBookServiceImpl extends ServiceImpl getBookidsByProductId(Integer productId) { - List spbs = this.list(new QueryWrapper().eq("del_flag", 0).eq("proudict_id", productId)); + public List getBookIdsByProductId(Integer productId) { + List spbs = this.list(new QueryWrapper().eq("del_flag", 0).eq("proudict_id", productId)); List ids = new ArrayList(); - for (ShopProudictBookEntity s : spbs) { + for (ShopProductBookEntity s : spbs) { ids.add(s.getBookId()); } return ids; @@ -89,14 +89,14 @@ public class ShopProudictBookServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(ShopProudictBookEntity::getBookId, bookId); - wrapper.eq(ShopProudictBookEntity::getDelFlag, 0); - wrapper.groupBy(ShopProudictBookEntity::getProudictId); - List shopProudictBookEntities = this.getBaseMapper().selectList(wrapper); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ShopProductBookEntity::getBookId, bookId); + wrapper.eq(ShopProductBookEntity::getDelFlag, 0); + wrapper.groupBy(ShopProductBookEntity::getProductId); + List shopProudictBookEntities = this.getBaseMapper().selectList(wrapper); List ids = new ArrayList(); - for (ShopProudictBookEntity s : shopProudictBookEntities) { - ids.add(s.getProudictId()); + for (ShopProductBookEntity s : shopProudictBookEntities) { + ids.add(s.getProductId()); } if (ids.size() == 0) { return null; @@ -114,7 +114,7 @@ public class ShopProudictBookServiceImpl extends ServiceImpl getOrderBookId(String orderSn) { - return shopProudictBookDao.getOrderBookId(orderSn); + return shopProductBookDao.getOrderBookId(orderSn); } diff --git a/src/main/java/com/peanut/modules/book/service/impl/ShopProductServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/ShopProductServiceImpl.java index eb3307e5..e80804ef 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/ShopProductServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/ShopProductServiceImpl.java @@ -1,14 +1,7 @@ package com.peanut.modules.book.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.peanut.common.utils.ExcludeEmptyQueryWrapper; -import com.peanut.modules.book.entity.ShopCategoryEntity; -import com.peanut.modules.book.entity.ShopProudictBookEntity; -import com.peanut.modules.book.service.ShopProudictBookService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; diff --git a/src/main/java/com/peanut/modules/book/vo/ProductBookQueryVO.java b/src/main/java/com/peanut/modules/book/vo/ProductBookQueryVO.java new file mode 100644 index 00000000..2de1d5bc --- /dev/null +++ b/src/main/java/com/peanut/modules/book/vo/ProductBookQueryVO.java @@ -0,0 +1,29 @@ +package com.peanut.modules.book.vo; + +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; + + +/** + * 返回图书与商品基本信息vo, + */ +@Data +public class ProductBookQueryVO { + + private Integer bookId; + private String bookName; + private Boolean canListen; + private Integer clockIn; + private String images; + private List products; + + private Integer productId; + private String productName; + private BigDecimal price; + private BigDecimal activityPrice; + private Integer sumSales; + private String productImages; + +} diff --git a/src/main/java/com/peanut/modules/book/vo/ProudictBookqueryVO.java b/src/main/java/com/peanut/modules/book/vo/ProudictBookqueryVO.java deleted file mode 100644 index f85c5762..00000000 --- a/src/main/java/com/peanut/modules/book/vo/ProudictBookqueryVO.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.peanut.modules.book.vo; - -import com.baomidou.mybatisplus.annotation.TableField; -import lombok.Data; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; - - -/** - * 返回图书与商品基本信息vo, - - */ -@Data -public class ProudictBookqueryVO { - - - - /** - *图书基本信息 - */ - private Integer bookId; - private String bookname; - private Boolean canListen; - private Integer clockIn; - private String images; - private List proudicts; - - /** - * 商品基本信息 - */ - private Integer proudictId; - private String productName; - private BigDecimal price; - private BigDecimal activityPrice; - private Integer sumSales; - private String proudictimages; - -} diff --git a/src/main/java/com/peanut/modules/pay/weChatPay/controller/WeChatPayController.java b/src/main/java/com/peanut/modules/pay/weChatPay/controller/WeChatPayController.java index 87b719a8..4daf6d9d 100644 --- a/src/main/java/com/peanut/modules/pay/weChatPay/controller/WeChatPayController.java +++ b/src/main/java/com/peanut/modules/pay/weChatPay/controller/WeChatPayController.java @@ -53,7 +53,7 @@ public class WeChatPayController { private TransactionDetailsService transactionDetailsService; @Autowired - private ShopProudictBookService shopProudictBookService; + private ShopProductBookService shopProudictBookService; @Autowired private UserEbookBuyService userEbookBuyService; diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 9853eb73..601b66fe 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,60 +1,73 @@ spring: - datasource: - type: com.alibaba.druid.pool.DruidDataSource - druid: - driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://59.110.212.44:3306/e_book_test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true - username: root - password: HSXY1234hsxy - initial-size: 10 - max-active: 100 - min-idle: 10 - max-wait: 60000 - pool-prepared-statements: true - max-pool-prepared-statement-per-connection-size: 20 - time-between-eviction-runs-millis: 60000 - min-evictable-idle-time-millis: 300000 - #Oracle需要打开注释 - #validation-query: SELECT 1 FROM DUAL - test-while-idle: true - test-on-borrow: false - test-on-return: false - stat-view-servlet: - enabled: true - url-pattern: /druid/* - #login-username: admin - #login-password: admin - filter: - stat: - log-slow-sql: true - slow-sql-millis: 1000 - merge-sql: false - wall: - config: - multi-statement-allow: true - tomcat: - initSQL: SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci + redis: + open: false # 是否开启redis缓存 true开启 false关闭 + database: 0 + host: 39.106.36.183 + port: 6379 + password: Jgll2015 # 密码(默认为空) + timeout: 6000000ms # 连接超时时长(毫秒) + jedis: + pool: + max-active: 1000 # 连接池最大连接数(使用负值表示没有限制) + max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制) + max-idle: 10 # 连接池中的最大空闲连接 + min-idle: 5 # 连接池中的最小空闲连接 + datasource: + type: com.alibaba.druid.pool.DruidDataSource + druid: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://59.110.212.44:3306/e_book_test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true + username: root + password: HSXY1234hsxy + initial-size: 10 + max-active: 100 + min-idle: 10 + max-wait: 60000 + pool-prepared-statements: true + max-pool-prepared-statement-per-connection-size: 20 + time-between-eviction-runs-millis: 60000 + min-evictable-idle-time-millis: 300000 + #Oracle需要打开注释 + #validation-query: SELECT 1 FROM DUAL + test-while-idle: true + test-on-borrow: false + test-on-return: false + stat-view-servlet: + enabled: true + url-pattern: /druid/* + #login-username: admin + #login-password: admin + filter: + stat: + log-slow-sql: true + slow-sql-millis: 1000 + merge-sql: false + wall: + config: + multi-statement-allow: true + tomcat: + initSQL: SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci - rabbitmq: - host: 59.110.212.44 - port: 5672 - username: admin - password: 751019 - virtualHost: / + rabbitmq: + host: 39.106.36.183 + port: 5672 + username: admin + password: 751019 + virtualHost: / aliyun: - oss: - file: - endpoint: oss-cn-beijing.aliyuncs.com - keyid: LTAIiSMeo8ztauV5 - keysecret: pVIYAOIFSUGg61lYfE8cjg2ZNpnLJA - bucketname: ehh-private-01 - sms: - accessKeyId: LTAI5tJbbw5fY97pnw635yq3 - accessKeySecret: LTXQ9v3OYVwNVbDWWfVpbbcVDKErKi - singName: 疯子读书 + oss: + file: + endpoint: oss-cn-beijing.aliyuncs.com + keyid: LTAIiSMeo8ztauV5 + keysecret: pVIYAOIFSUGg61lYfE8cjg2ZNpnLJA + bucketname: ehh-private-01 + sms: + accessKeyId: LTAI5tJbbw5fY97pnw635yq3 + accessKeySecret: LTXQ9v3OYVwNVbDWWfVpbbcVDKErKi + singName: 疯子读书 - templateCode: SMS_248840040 + templateCode: SMS_248840040 server: - port: 9200 \ No newline at end of file + port: 9200 \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 2ceaca9a..28030565 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -1,5 +1,18 @@ spring: + redis: + open: false # 是否开启redis缓存 true开启 false关闭 + database: 0 + host: 59.110.212.44 + port: 6379 + password: Jgll2015 # 密码(默认为空) + timeout: 6000000ms # 连接超时时长(毫秒) + jedis: + pool: + max-active: 1000 # 连接池最大连接数(使用负值表示没有限制) + max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制) + max-idle: 10 # 连接池中的最大空闲连接 + min-idle: 5 # 连接池中的最小空闲连接 datasource: type: com.alibaba.druid.pool.DruidDataSource druid: diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e7477840..e167c270 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,7 +11,7 @@ connection-timeout: 6000000ms spring: # 环境 dev|test|prod profiles: - active: prod + active: dev # jackson时间格式化 jackson: time-zone: GMT+8 @@ -21,19 +21,6 @@ spring: max-file-size: 100MB max-request-size: 100MB enabled: true - redis: - open: false # 是否开启redis缓存 true开启 false关闭 - database: 0 - host: 59.110.212.44 - port: 6379 - password: Jgll2015 # 密码(默认为空) - timeout: 6000000ms # 连接超时时长(毫秒) - jedis: - pool: - max-active: 1000 # 连接池最大连接数(使用负值表示没有限制) - max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制) - max-idle: 10 # 连接池中的最大空闲连接 - min-idle: 5 # 连接池中的最小空闲连接 mvc: throw-exception-if-no-handler-found: true pathmatch: diff --git a/src/main/resources/mapper/book/ShopProudictBookDao.xml b/src/main/resources/mapper/book/ShopProductBookDao.xml similarity index 56% rename from src/main/resources/mapper/book/ShopProudictBookDao.xml rename to src/main/resources/mapper/book/ShopProductBookDao.xml index 63237def..b3ff6d29 100644 --- a/src/main/resources/mapper/book/ShopProudictBookDao.xml +++ b/src/main/resources/mapper/book/ShopProductBookDao.xml @@ -1,24 +1,25 @@ - + - + - + - +