海外读书
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
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.common.entity.*;
|
||||
import com.peanut.modules.master.service.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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;
|
||||
|
||||
//评论列表
|
||||
@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();
|
||||
}
|
||||
|
||||
//标签详情
|
||||
@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());
|
||||
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){
|
||||
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("/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.eq(BookAbroadToLable::getLableId,params.get("lableId"));
|
||||
return R.ok().put("bookList",toLableService.listMaps(wrapper));
|
||||
}
|
||||
|
||||
//标签树
|
||||
@RequestMapping("/getLableTree")
|
||||
public List<BookAbroadLable> 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 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.peanut.modules.master.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.common.entity.BookAbroadCommentLike;
|
||||
|
||||
public interface BookAbroadCommentLikeService extends IService<BookAbroadCommentLike> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.peanut.modules.master.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.common.entity.BookAbroadComment;
|
||||
|
||||
public interface BookAbroadCommentService extends IService<BookAbroadComment> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.peanut.modules.master.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.common.entity.BookAbroadLable;
|
||||
|
||||
public interface BookAbroadLableService extends IService<BookAbroadLable> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.peanut.modules.master.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.common.entity.BookAbroadToLable;
|
||||
|
||||
public interface BookAbroadToLableService extends IService<BookAbroadToLable> {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.peanut.modules.master.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.modules.common.dao.BookAbroadCommentLikeDao;
|
||||
import com.peanut.modules.common.entity.BookAbroadCommentLike;
|
||||
import com.peanut.modules.master.service.BookAbroadCommentLikeService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service("masterBookAbroadCommentLikeService")
|
||||
public class BookAbroadCommentLikeServiceImpl extends ServiceImpl<BookAbroadCommentLikeDao, BookAbroadCommentLike> implements BookAbroadCommentLikeService {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.peanut.modules.master.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.modules.common.dao.BookAbroadCommentDao;
|
||||
import com.peanut.modules.common.entity.BookAbroadComment;
|
||||
import com.peanut.modules.master.service.BookAbroadCommentService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service("masterBookAbroadCommentService")
|
||||
public class BookAbroadCommentServiceImpl extends ServiceImpl<BookAbroadCommentDao, BookAbroadComment> implements BookAbroadCommentService {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.peanut.modules.master.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.modules.common.dao.BookAbroadLableDao;
|
||||
import com.peanut.modules.common.entity.BookAbroadLable;
|
||||
import com.peanut.modules.master.service.BookAbroadLableService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service("masterBookAbroadLableService")
|
||||
public class BookAbroadLableServiceImpl extends ServiceImpl<BookAbroadLableDao, BookAbroadLable> implements BookAbroadLableService {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.peanut.modules.master.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.modules.common.dao.BookAbroadToLableDao;
|
||||
import com.peanut.modules.common.entity.BookAbroadToLable;
|
||||
import com.peanut.modules.master.service.BookAbroadToLableService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service("masterBookAbroadToLableService")
|
||||
public class BookAbroadToLableServiceImpl extends ServiceImpl<BookAbroadToLableDao, BookAbroadToLable> implements BookAbroadToLableService {
|
||||
}
|
||||
Reference in New Issue
Block a user