删除海外读书模块
This commit is contained in:
@@ -1,185 +0,0 @@
|
||||
package com.peanut.modules.master.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.book.service.BookService;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.master.service.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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.RestController;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@RestController("masterBookAbroad")
|
||||
@RequestMapping("master/bookAbroad")
|
||||
public class BookAbroadController {
|
||||
|
||||
@Autowired
|
||||
private BookAbroadCommentService bookAbroadCommentService;
|
||||
@Autowired
|
||||
private com.peanut.modules.bookAbroad.service.BookAbroadLableService labelService;
|
||||
@Autowired
|
||||
private com.peanut.modules.bookAbroad.service.BookAbroadToLableService toLableService;
|
||||
@Autowired
|
||||
private BookService bookService;
|
||||
|
||||
//评论列表
|
||||
@RequestMapping("/getBookAbroadCommentList")
|
||||
public R getBookAbroadCommentList(@RequestBody Map<String,Object> params) {
|
||||
Page comments = bookAbroadCommentService.page(
|
||||
new Page<>(Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),
|
||||
new LambdaQueryWrapper<BookAbroadComment>().like(BookAbroadComment::getContent,params.get("content")));
|
||||
return R.ok().put("comments",comments);
|
||||
}
|
||||
//删除评论
|
||||
@RequestMapping("/delBookAbroadComment")
|
||||
public R delBookAbroadComment(@RequestBody Map<String,Object> params){
|
||||
bookAbroadCommentService.removeById(params.get("commentId").toString());
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//新增标签
|
||||
@RequestMapping("/insertBookAbroadLable")
|
||||
public R insertBookAbroadLable(@RequestBody BookAbroadLable lable){
|
||||
labelService.save(lable);
|
||||
return R.ok().put("bookAbroadLable",lable);
|
||||
}
|
||||
|
||||
//标签详情
|
||||
@RequestMapping("/bookAbroadLableInfo")
|
||||
public R bookAbroadLableInfo(@RequestBody Map<String,Object> params){
|
||||
BookAbroadLable lable = labelService.getById(params.get("id").toString());
|
||||
return R.ok().put("lable",lable);
|
||||
}
|
||||
|
||||
//修改标签
|
||||
@RequestMapping("/updateBookAbroadLable")
|
||||
public R updateBookAbroadLable(@RequestBody BookAbroadLable lable){
|
||||
BookAbroadLable oldLable = labelService.getById(lable.getId());
|
||||
if (oldLable.getIsLast()!=lable.getIsLast()) {
|
||||
int count = toLableService.count(new LambdaQueryWrapper<BookAbroadToLable>()
|
||||
.eq(BookAbroadToLable::getLableId,lable.getId()));
|
||||
if (count > 0){
|
||||
return R.error("存在绑定书籍,删除后再操作");
|
||||
}
|
||||
}
|
||||
labelService.updateById(lable);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//删除标签
|
||||
@RequestMapping("/delBookAbroadLable")
|
||||
public R delBookAbroadLable(@RequestBody Map<String,Object> params){
|
||||
BookAbroadLable oldLable = labelService.getById(params.get("id").toString());
|
||||
if (oldLable.getIsLast()!=1){
|
||||
return R.error("不是最下级,禁止删除");
|
||||
}
|
||||
int count = toLableService.count(new LambdaQueryWrapper<BookAbroadToLable>()
|
||||
.eq(BookAbroadToLable::getLableId,params.get("id").toString()));
|
||||
if (count > 0){
|
||||
return R.error("存在绑定书籍,删除后再操作");
|
||||
}
|
||||
labelService.removeById(oldLable.getId());
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//绑定图书和标签
|
||||
@RequestMapping("/insertBookAbroadToLable")
|
||||
public R insertBookAbroadToLable(@RequestBody BookAbroadToLable toLable){
|
||||
BookAbroadLable oldLable = labelService.getById(toLable.getLableId());
|
||||
if (oldLable.getIsLast()!=1){
|
||||
return R.error("不是最下级,禁止绑定");
|
||||
}
|
||||
int count = toLableService.count(new LambdaQueryWrapper<BookAbroadToLable>()
|
||||
.eq(BookAbroadToLable::getBookId,toLable.getBookId())
|
||||
.eq(BookAbroadToLable::getLableId,toLable.getLableId()));
|
||||
if (count > 0) {
|
||||
return R.error("已存在");
|
||||
}
|
||||
toLableService.save(toLable);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//解绑
|
||||
@RequestMapping("/delBookAbroadToLable")
|
||||
public R delBookAbroadToLable(@RequestBody Map<String,Object> params){
|
||||
String[] strings = params.get("ids").toString().split(",");
|
||||
toLableService.removeByIds(Arrays.asList(strings));
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//标签可绑定图书
|
||||
@RequestMapping("/getBookListCanToLable")
|
||||
public R getBookListCanToLable(@RequestBody Map<String,Object> params) {
|
||||
List<Integer> collect = toLableService.list(new LambdaQueryWrapper<BookAbroadToLable>()
|
||||
.eq(BookAbroadToLable::getLableId, params.get("lableId")))
|
||||
.stream().map(BookAbroadToLable::getBookId).collect(Collectors.toList());
|
||||
LambdaQueryWrapper<BookEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
if (collect.size() != 0){
|
||||
wrapper.notIn(BookEntity::getId,collect);
|
||||
}
|
||||
wrapper.like(StringUtils.isNotBlank(params.get("bookName").toString()),BookEntity::getTitle,params.get("bookName"));
|
||||
Page<BookEntity> page = bookService.page(new Page<>(Long.valueOf(params.get("current").toString()),Long.valueOf(params.get("limit").toString())), wrapper);
|
||||
return R.ok().put("page",page);
|
||||
}
|
||||
|
||||
//通过标签获取绑定图书
|
||||
@RequestMapping("/getAbroadBookListByLable")
|
||||
public R getAbroadBookListByLable(@RequestBody Map<String,Object> params) {
|
||||
MPJLambdaWrapper<BookAbroadToLable> wrapper = new MPJLambdaWrapper();
|
||||
wrapper.leftJoin(BookEntity.class,BookEntity::getId,BookAbroadToLable::getBookId);
|
||||
wrapper.selectAs(BookAbroadToLable::getId,"id");
|
||||
wrapper.select(BookEntity::getName);
|
||||
wrapper.select(BookAbroadToLable::getSort);
|
||||
wrapper.select(BookAbroadToLable::getBookId);
|
||||
wrapper.eq(BookAbroadToLable::getLableId,params.get("lableId"));
|
||||
wrapper.orderByAsc(BookAbroadToLable::getSort);
|
||||
return R.ok().put("bookList",toLableService.listMaps(wrapper));
|
||||
}
|
||||
|
||||
//修改排序
|
||||
@RequestMapping("/updateToLableSort")
|
||||
public R updateToLableSort(@RequestBody Map<String,Object> params){
|
||||
BookAbroadToLable toLable = toLableService.getById(params.get("toLableId").toString());
|
||||
toLable.setSort(Integer.parseInt(params.get("sort").toString()));
|
||||
toLableService.updateById(toLable);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//标签树
|
||||
@RequestMapping("/getLableTree")
|
||||
public R getLableTree(@RequestBody Map<String,Object> params) {
|
||||
List<BookAbroadLable> labels = labelService.list(new LambdaQueryWrapper<BookAbroadLable>()
|
||||
.eq(BookAbroadLable::getType,params.get("type")));
|
||||
List<BookAbroadLable> labelsTree = labels.stream().filter((bookAbroadLable) ->
|
||||
bookAbroadLable.getPid() == 0
|
||||
).map((label)->{
|
||||
label.setChildren(getLabelChildrens(label,labels));
|
||||
return label;
|
||||
}).sorted((label1,label2)->{
|
||||
return (label1.getSort() == null? 0 : label1.getSort()) - (label2.getSort()==null?0:label2.getSort());
|
||||
}).collect(Collectors.toList());
|
||||
return R.ok().put("labelsTree",labelsTree);
|
||||
}
|
||||
|
||||
private List<BookAbroadLable> getLabelChildrens(BookAbroadLable root,List<BookAbroadLable> all){
|
||||
List<BookAbroadLable> children = all.stream().filter(bookAbroadLable -> {
|
||||
return root.getId().equals(bookAbroadLable.getPid());
|
||||
}).map(bookAbroadLable -> {
|
||||
bookAbroadLable.setChildren(getLabelChildrens(bookAbroadLable, all));
|
||||
return bookAbroadLable;
|
||||
}).sorted((label1,label2)->{
|
||||
return (label1.getSort()==null?0:label1.getSort()) - (label2.getSort()==null?0:label2.getSort());
|
||||
}).collect(Collectors.toList());
|
||||
return children;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user