diff --git a/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java b/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java index 761df024..d26e5ccf 100644 --- a/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java +++ b/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java @@ -149,6 +149,7 @@ public class HomeController { wrapper.select(BookEntity::getImages); wrapper.select(BookEntity::getName); wrapper.eq(BookAbroadToLable::getLableId,params.get("lableId")); + wrapper.orderByAsc(BookAbroadToLable::getSort); List> list = toLableService.listMaps(wrapper); for (Map map : list) { int readCount = bookReadRateService.count(new LambdaQueryWrapper() diff --git a/src/main/java/com/peanut/modules/common/entity/BookAbroadLable.java b/src/main/java/com/peanut/modules/common/entity/BookAbroadLable.java index 5ad0ffcf..3c72c420 100644 --- a/src/main/java/com/peanut/modules/common/entity/BookAbroadLable.java +++ b/src/main/java/com/peanut/modules/common/entity/BookAbroadLable.java @@ -32,6 +32,11 @@ public class BookAbroadLable implements Serializable { */ private String title; + /** + * 标题 + */ + private String etitle; + /** * 0否1是 */ diff --git a/src/main/java/com/peanut/modules/master/controller/BookAbroadController.java b/src/main/java/com/peanut/modules/master/controller/BookAbroadController.java index 4980e106..9fe55008 100644 --- a/src/main/java/com/peanut/modules/master/controller/BookAbroadController.java +++ b/src/main/java/com/peanut/modules/master/controller/BookAbroadController.java @@ -4,9 +4,11 @@ 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; @@ -27,6 +29,8 @@ public class BookAbroadController { private com.peanut.modules.bookAbroad.service.BookAbroadLableService labelService; @Autowired private com.peanut.modules.bookAbroad.service.BookAbroadToLableService toLableService; + @Autowired + private BookService bookService; //评论列表 @RequestMapping("/getBookAbroadCommentList") @@ -47,7 +51,7 @@ public class BookAbroadController { @RequestMapping("/insertBookAbroadLable") public R insertBookAbroadLable(@RequestBody BookAbroadLable lable){ labelService.save(lable); - return R.ok(); + return R.ok().put("bookAbroadLable",lable); } //标签详情 @@ -76,6 +80,9 @@ public class BookAbroadController { @RequestMapping("/delBookAbroadLable") public R delBookAbroadLable(@RequestBody Map params){ BookAbroadLable oldLable = labelService.getById(params.get("id").toString()); + if (oldLable.getIsLast()!=1){ + return R.error("不是最下级,禁止删除"); + } int count = toLableService.count(new LambdaQueryWrapper() .eq(BookAbroadToLable::getLableId,params.get("id").toString())); if (count > 0){ @@ -88,6 +95,10 @@ public class BookAbroadController { //绑定图书和标签 @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() .eq(BookAbroadToLable::getBookId,toLable.getBookId()) .eq(BookAbroadToLable::getLableId,toLable.getLableId())); @@ -106,6 +117,21 @@ public class BookAbroadController { return R.ok(); } + //标签可绑定图书 + @RequestMapping("/getBookListCanToLable") + public R getBookListCanToLable(@RequestBody Map params) { + List collect = toLableService.list(new LambdaQueryWrapper() + .eq(BookAbroadToLable::getLableId, params.get("lableId"))) + .stream().map(BookAbroadToLable::getBookId).collect(Collectors.toList()); + LambdaQueryWrapper 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 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 params) { @@ -113,13 +139,25 @@ public class BookAbroadController { 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 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 List getLableTree(@RequestBody Map params) { + public R getLableTree(@RequestBody Map params) { List labels = labelService.list(new LambdaQueryWrapper() .eq(BookAbroadLable::getType,params.get("type"))); List labelsTree = labels.stream().filter((bookAbroadLable) -> @@ -130,7 +168,7 @@ public class BookAbroadController { }).sorted((label1,label2)->{ return (label1.getSort() == null? 0 : label1.getSort()) - (label2.getSort()==null?0:label2.getSort()); }).collect(Collectors.toList()); - return labelsTree; + return R.ok().put("labelsTree",labelsTree); } private List getLabelChildrens(BookAbroadLable root,List all){