--新版提交

This commit is contained in:
yc13649764453
2023-09-09 14:01:15 +08:00
parent 0b193caa03
commit 408782f7aa
70 changed files with 3706 additions and 0 deletions

View File

@@ -0,0 +1,225 @@
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.BookClockinCommentEntity;
import com.peanut.modules.book.entity.BookClockinPunchEntity;
import com.peanut.modules.book.entity.BookEntity;
import com.peanut.modules.book.entity.MyUserEntity;
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 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;
/**
* 列表 app post请求 /applistSS
*/
@RequestMapping("/applist")
public R applist(@RequestParam Map<String, Object> params) {
PageUtils page = bookClockinPunchService.queryPage(params);
return R.ok().put("page", page);
}
/**
* 计算打卡天数
*/
@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();
//获取第一次打卡天数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 );
}
return R.error("无信息记录");
}
/**
* 信息
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Integer id) {
BookClockinPunchEntity bookClockinPunchEntity = bookClockinPunchService.getById(id);
return R.ok().put("bookClockinPunchEntity", bookClockinPunchEntity);
}
/**
* 保存
*/
@RequestMapping("/save")
//请求接口时是从task的info或者list中发出的理论上
public R save(@RequestBody BookClockinPunchEntity bookClockinPunchEntity) {
Integer bookid1 = bookClockinPunchEntity.getBookId();
Integer userId = bookClockinPunchEntity.getUserId();
Integer taskId = bookClockinPunchEntity.getTId();
BookEntity bookEntity = bookService.getBaseMapper().selectById(bookid1);
Boolean canListen = bookEntity.getCanListen();
BookClockinPunchEntity bookClock = bookClockinPunchService.getBaseMapper().selectOne(new QueryWrapper<BookClockinPunchEntity>()
.eq("book_id", bookid1)
.eq("user_id", userId)
.eq("t_id", taskId)
);
if (bookClock !=null) {
return R.error("您已经签到,请勿重复签到");
}
if(canListen == true){
boolean b = myUserService.bookAuthenticate(bookid1,userId);
if (b){
bookClockinPunchEntity.setDelFlag(0);
bookClockinPunchService.save(bookClockinPunchEntity);
return R.ok("签到成功");
}
}else {
return R.error("购买此书即可参与签到");
}
return R.ok("跳方法001");
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody BookClockinPunchEntity bookClockinPunchEntity) {
bookClockinPunchService.updateById(bookClockinPunchEntity);
return R.ok("提交成功");
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids) {
bookClockinPunchService.removeByIds(Arrays.asList(ids));
return R.ok();
}
/**
* 获取评论
* @param bookClockinPunchEntity
* @return
*/
@RequestMapping("/punchcoments")
public R punchcoments(@RequestBody BookClockinPunchEntity bookClockinPunchEntity) {
//图书Id
Integer bookId = bookClockinPunchEntity.getBookId();
//用户id
Integer userId = bookClockinPunchEntity.getUserId();
//天数
Integer days = bookClockinPunchEntity.getDays();
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)
//pid等于1时为一级评论
// .eq("pid",1)
);
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();
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);
}
}