clock in and comment finished waitting for test
This commit is contained in:
@@ -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<Object> list = new ArrayList<>();
|
||||
//查询用户id图书id 根据第一天打卡天数开始计算
|
||||
BookClockinPunchEntity bookClockinEntity = bookClockinPunchService.getBaseMapper().selectOne(new QueryWrapper<BookClockinPunchEntity>()
|
||||
.eq("book_id", bookid)
|
||||
.eq("user_id", userid)
|
||||
.eq("days",1)
|
||||
);
|
||||
List<BookClockinPunchEntity> bookClockinEntityList = bookClockinPunchService.getBaseMapper().selectList(new QueryWrapper<BookClockinPunchEntity>()
|
||||
.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<UserEbookBuyEntity> 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<BookEntity> userBookEntityPage = userEbookBuyDao.selectJoinPage(new Page<BookEntity>(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<BookEntity> 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<BookEntity> 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<Object> list = new ArrayList<>();
|
||||
List<BookClockinCommentEntity> bookClockinCommentEntities = bookClockinCommentService.getBaseMapper().selectList(new QueryWrapper<BookClockinCommentEntity>()
|
||||
.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<Object, Object> map = new HashMap<>();
|
||||
String name = "";
|
||||
String avatar="";
|
||||
for (BookClockinCommentEntity bookClockinCommentEntity : bookClockinCommentEntities) {
|
||||
HashMap<Object, Object> 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<MyUserEntity> id = myUserService.getBaseMapper().selectList(new QueryWrapper<MyUserEntity>().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<MyUserEntity> id = myUserService.getBaseMapper().selectList(new QueryWrapper<MyUserEntity>().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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user