350 lines
12 KiB
Java
350 lines
12 KiB
Java
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.*;
|
|
import com.peanut.modules.book.service.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.*;
|
|
/**
|
|
* 签到内容信息
|
|
*
|
|
*/
|
|
@RestController
|
|
@RequestMapping("book/clockin")
|
|
public class BookClockinController {
|
|
@Autowired
|
|
private BookClockInService bookClockinService;
|
|
@Autowired
|
|
private BookTaskService bookTaskService;
|
|
@Autowired
|
|
private BookClockinCommentService bookClockinCommentService;
|
|
@Autowired
|
|
private MyUserService myUserService;
|
|
@Autowired
|
|
private BookService bookService;
|
|
@Autowired
|
|
private BookClockinPunchService bookClockinPunchService;
|
|
/**
|
|
* 列表 app post请求
|
|
*/
|
|
@RequestMapping("/applistSS")
|
|
public R applist(@RequestParam Map<String, Object> params) {
|
|
PageUtils page = bookClockinService.queryPage(params);
|
|
|
|
return R.ok().put("page", page);
|
|
}
|
|
|
|
|
|
/**
|
|
* 查看全部评价
|
|
*/
|
|
@RequestMapping("/applist")
|
|
public R applist(@RequestParam("bookid") String bookid,
|
|
@RequestParam("taskid") String taskid) {
|
|
|
|
List<BookClockInEntity> bookClockinEntityList = bookClockinService.getBaseMapper().selectList(new QueryWrapper<BookClockInEntity>()
|
|
.eq("book_id", bookid).eq("task_id", taskid));
|
|
List list = new ArrayList<>();
|
|
for (BookClockInEntity bookClockinEntity : bookClockinEntityList) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
String name = "";
|
|
String avatar="";
|
|
Integer id2 =null;
|
|
Integer userId = bookClockinEntity.getUserId();
|
|
Integer taskId = bookClockinEntity.getTaskId();
|
|
Integer bookId = bookClockinEntity.getBookId();
|
|
String conTent = bookClockinEntity.getContent();
|
|
Integer id1 = bookClockinEntity.getId();
|
|
String images = (String)bookClockinEntity.getImages();
|
|
Date createTime = bookClockinEntity.getCreateTime();
|
|
List<MyUserEntity> id = myUserService.getBaseMapper().selectList(new QueryWrapper<MyUserEntity>().eq("id", userId));
|
|
for (MyUserEntity user : id) {
|
|
name = user.getNickname();
|
|
id2 = user.getId();
|
|
avatar = user.getAvatar();
|
|
}
|
|
|
|
//评论信息
|
|
map.put("userid", id2);
|
|
map.put("name", name);
|
|
map.put("avatar", avatar);
|
|
map.put("bookid", bookId);
|
|
map.put("taskId", taskId);
|
|
map.put("content", conTent);
|
|
map.put("images", images);
|
|
map.put("createdate", createTime);
|
|
list.add(map);
|
|
}
|
|
Collections.reverse(list);
|
|
return R.ok().put("list", list);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 列表 后台get请求
|
|
*/
|
|
@RequestMapping("/list")
|
|
public R list(@RequestParam Map<String, Object> params) {
|
|
PageUtils page = bookClockinService.queryPage(params);
|
|
|
|
return R.ok().put("page", page);
|
|
}
|
|
|
|
|
|
/**
|
|
* 信息
|
|
*/
|
|
@RequestMapping("/info/{id}")
|
|
public R info(@PathVariable("id") Integer id) {
|
|
BookClockInEntity bookClockinEntity = bookClockinService.getById(id);
|
|
return R.ok().put("bookBuyConfig", bookClockinEntity);
|
|
}
|
|
|
|
/**
|
|
* 保存
|
|
*/
|
|
@RequestMapping("/save")
|
|
public R save(@RequestBody BookClockInEntity bookClockinEntity) {
|
|
|
|
Integer bookId = bookClockinEntity.getBookId();
|
|
Integer userId = bookClockinEntity.getUserId();
|
|
Integer taskId = bookClockinEntity.getTaskId();
|
|
Integer dayId = bookClockinEntity.getDayId();
|
|
BookClockinPunchEntity bookClockinPunchEntity = bookClockinPunchService.getBaseMapper().selectOne(new QueryWrapper<BookClockinPunchEntity>()
|
|
.eq("book_id", bookId)
|
|
.eq("t_id", taskId)
|
|
.eq("days", dayId)
|
|
.eq("user_id", userId)
|
|
);
|
|
if (bookClockinPunchEntity==null) {
|
|
return R.error("当天打卡内容未发布");
|
|
}
|
|
BookClockInEntity bookClockin = bookClockinService.getBaseMapper().selectOne(new QueryWrapper<BookClockInEntity>()
|
|
.eq("book_id", bookId)
|
|
.eq("task_id", taskId)
|
|
.eq("day_id", dayId)
|
|
.eq("user_id", userId)
|
|
);
|
|
if (bookClockin!=null) {
|
|
return R.error("您已参与第"+dayId+"天签到评论");
|
|
}
|
|
List<Map<String, String>> imageList = (ArrayList<Map<String, String>>) bookClockinEntity.getImageeStrings();
|
|
String imageStr = "";
|
|
for (Map m : imageList) {
|
|
imageStr += m.get("url") + ",";
|
|
|
|
}
|
|
|
|
if (imageStr!=null &&!imageStr.isEmpty()){
|
|
String substring = imageStr.substring(0, imageStr.length() - 1);
|
|
bookClockinEntity.setImages(substring);
|
|
}else {
|
|
bookClockinEntity.setImages("");
|
|
}
|
|
|
|
|
|
|
|
bookClockinEntity.setDelFlag(0);
|
|
bookClockinService.save(bookClockinEntity);
|
|
return R.ok();
|
|
}
|
|
|
|
|
|
/**
|
|
* 修改
|
|
*/
|
|
@RequestMapping("/update")
|
|
public R update(@RequestBody BookClockInEntity bookClockinEntity) {
|
|
bookClockinService.updateById(bookClockinEntity);
|
|
return R.ok("提交成功");
|
|
}
|
|
|
|
|
|
/**
|
|
* 删除
|
|
*/
|
|
@RequestMapping("/delete")
|
|
public R delete(@RequestBody Integer[] ids) {
|
|
bookClockinService.removeByIds(Arrays.asList(ids));
|
|
return R.ok();
|
|
}
|
|
|
|
|
|
/**
|
|
* 全部评价
|
|
*
|
|
* @param bookId
|
|
* @return
|
|
*/
|
|
@RequestMapping("commentAll")
|
|
public R commentAll(@RequestParam("bookId") Integer bookId) {
|
|
List applist = new ArrayList<>();
|
|
Map<String, Object> productMap = new HashMap<>();
|
|
//根据bookid查找出签到表中签到的用户数据
|
|
List<BookClockInEntity> bookid = bookClockinService.getBaseMapper().selectList(new QueryWrapper<BookClockInEntity>()
|
|
.eq("book_id", bookId)
|
|
.orderByDesc("create_time"));
|
|
|
|
for (BookClockInEntity book : bookid) {
|
|
HashMap<Object, Object> map = new HashMap<>();
|
|
|
|
Integer bookid1 = book.getBookId();
|
|
//BookClockinEntity获取点赞总数
|
|
String likes = book.getLikeSum();
|
|
|
|
Integer userid1 = book.getUserId();
|
|
Integer taskId = book.getTaskId();
|
|
Integer id1 = book.getId();
|
|
applist.add(taskId);
|
|
//根据id和bookid查询出对应的签到下评论的全部数据
|
|
|
|
productMap.put("bookid",bookid1);
|
|
productMap.put("userid",userid1);
|
|
}
|
|
PageUtils pages = bookClockinService.queryPage(productMap);
|
|
return R.ok().put("days",applist).put("pages",pages);
|
|
}
|
|
|
|
|
|
/**
|
|
* 我的 :我的签到记录
|
|
* @param id
|
|
* @param bookId
|
|
* @return
|
|
*/
|
|
@RequestMapping("/myinfo")
|
|
public R myinfo(@RequestParam("userid") Integer id,
|
|
@RequestParam("bookid") Integer bookId) {
|
|
|
|
|
|
List<BookClockInEntity> bookClockinEntityList = bookClockinService.getBaseMapper().selectList(new QueryWrapper<BookClockInEntity>()
|
|
.eq("user_id",id) .eq("book_id",bookId).orderByDesc("create_time"));
|
|
List list = new ArrayList<>();
|
|
|
|
for (BookClockInEntity bookClockinEntity : bookClockinEntityList) {
|
|
Map<String, Object> productMap = new HashMap<>();
|
|
Integer userId = bookClockinEntity.getUserId();
|
|
Integer dayId = bookClockinEntity.getDayId();
|
|
Integer bookIds = bookClockinEntity.getBookId();
|
|
Integer typeId = bookClockinEntity.getTaskId();
|
|
String content = bookClockinEntity.getContent();
|
|
Object images = bookClockinEntity.getImages();
|
|
Date createTime = bookClockinEntity.getCreateTime();
|
|
BookEntity byId = bookService.getById(bookId);
|
|
String name = byId.getName();
|
|
String images1 = byId.getImages();
|
|
BookTaskEntity bookTaskEntity = bookTaskService.getById(typeId);
|
|
String heading = bookTaskEntity.getHeading();
|
|
|
|
|
|
String myUsername = "";
|
|
String avatar="";
|
|
List<MyUserEntity> myUserid = myUserService.getBaseMapper().selectList(new QueryWrapper<MyUserEntity>().eq("id", userId));
|
|
for (MyUserEntity user : myUserid) {
|
|
myUsername = user.getNickname();
|
|
avatar = user.getAvatar();
|
|
}
|
|
|
|
productMap.put("myUseravatar",avatar);
|
|
productMap.put("myUsername",myUsername);
|
|
|
|
productMap.put("dayId",dayId);
|
|
productMap.put("userId",userId);
|
|
productMap.put("taskId",typeId);
|
|
productMap.put("content",content);
|
|
productMap.put("clockinimages",images);
|
|
productMap.put("createTime",createTime);
|
|
productMap.put("bookId",bookIds);
|
|
productMap.put("bookname",name);
|
|
productMap.put("bookimages",images1);
|
|
productMap.put("TaskHeading",heading);
|
|
list.add(productMap);
|
|
|
|
}
|
|
// Collections.sort(list);
|
|
// Collections.reverse(list);
|
|
return R.ok().put("ClockinList", list);
|
|
}
|
|
|
|
|
|
/**
|
|
* 详情页我的签到评论
|
|
* @param id
|
|
* @param taskid
|
|
* @param bookId
|
|
* @return
|
|
*/
|
|
@RequestMapping("/myinfolist")
|
|
public R myinfolist(@RequestParam("userid") Integer id,
|
|
@RequestParam("taskid") Integer taskid,
|
|
@RequestParam("bookid") Integer bookId
|
|
) {
|
|
List list = new ArrayList<>();
|
|
Map<String, Object> productMap = new HashMap<>();
|
|
BookClockInEntity bookClockin = bookClockinService.getBaseMapper().selectOne(new QueryWrapper<BookClockInEntity>()
|
|
.eq("user_id",id)
|
|
.eq("task_id",taskid)
|
|
.eq("book_id",bookId)
|
|
);
|
|
BookClockinPunchEntity bookClockinPunchEntity = bookClockinPunchService.getBaseMapper().selectOne(new QueryWrapper<BookClockinPunchEntity>()
|
|
.eq("user_id",id)
|
|
.eq("t_id",taskid)
|
|
.eq("book_id",bookId)
|
|
);
|
|
|
|
|
|
if (bookClockin == null ) {
|
|
return R.ok();
|
|
}
|
|
|
|
Integer userId = bookClockin.getUserId();
|
|
Integer bookIds = bookClockin.getBookId();
|
|
Integer taskId = bookClockin.getTaskId();
|
|
Integer dayId = bookClockin.getDayId();
|
|
String content = bookClockin.getContent();
|
|
Object images = bookClockin.getImages();
|
|
Date createTime = bookClockin.getCreateTime();
|
|
BookEntity byId = bookService.getById(bookId);
|
|
String name = byId.getName();
|
|
String images1 = byId.getImages();
|
|
BookTaskEntity bookTaskEntity = bookTaskService.getById(taskId);
|
|
String heading = bookTaskEntity.getHeading();
|
|
|
|
|
|
|
|
String myUsername = "";
|
|
String avatar="";
|
|
List<MyUserEntity> myUserid = myUserService.getBaseMapper().selectList(new QueryWrapper<MyUserEntity>().eq("id", userId));
|
|
for (MyUserEntity user : myUserid) {
|
|
myUsername = user.getNickname();
|
|
avatar = user.getAvatar();
|
|
}
|
|
|
|
productMap.put("myUseravatar",avatar);
|
|
productMap.put("myUsername",myUsername);
|
|
|
|
|
|
|
|
productMap.put("userId",userId);
|
|
productMap.put("taskId",taskId);
|
|
productMap.put("dayId",dayId);
|
|
|
|
productMap.put("content",content);
|
|
productMap.put("clockinimages",images);
|
|
productMap.put("createTime",createTime);
|
|
productMap.put("bookId",bookIds);
|
|
productMap.put("bookname",name);
|
|
productMap.put("bookimages",images1);
|
|
productMap.put("TaskHeading",heading);
|
|
list.add(productMap);
|
|
|
|
Collections.reverse(list);
|
|
return R.ok().put("productlist", list);
|
|
}
|
|
|
|
} |