-- 新版提交

This commit is contained in:
yc13649764453
2023-09-09 13:51:35 +08:00
parent 763e24b4e0
commit 0b193caa03
92 changed files with 3451 additions and 1120 deletions

View File

@@ -1,9 +1,10 @@
package com.peanut.modules.book.controller;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.text.Collator;
import java.util.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
@@ -36,7 +37,6 @@ public class BookChapterController {
* 列表
*/
@RequestMapping("/list")
// @RequiresPermissions("book:bookchapter:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = bookChapterService.queryPage(params);
@@ -44,11 +44,19 @@ public class BookChapterController {
}
@RequestMapping("/booklist")
public R booklist(@RequestParam Map<String, Object> params){
PageUtils page = bookChapterService.queryPage1(params);
return R.ok().put("page", page);
}
/**
* 信息
*/
@RequestMapping("/info/{id}")
// @RequiresPermissions("book:bookchapter:info")
public R info(@PathVariable("id") Integer id){
BookChapterEntity bookChapter = bookChapterService.getById(id);
@@ -59,36 +67,176 @@ public class BookChapterController {
* 保存
*/
@RequestMapping("/save")
// @RequiresPermissions("book:bookchapter:save")
public R save(@RequestBody BookChapterEntity bookChapter){
bookChapterService.save(bookChapter);
public R save(@RequestBody BookChapterEntity bookChapter) {
BookChapterEntity bookChapterEntity = new BookChapterEntity();
Integer number = bookChapter.getNumber();
Integer bookId = bookChapter.getBookId();
List<BookChapterEntity> bookChapterEntities = this.bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
.eq("book_id", bookId)
.ge("number", number));
for(BookChapterEntity entity: bookChapterEntities){
entity.setNumber(entity.getNumber() + 1);
this.bookChapterService.updateById(entity);
}
bookChapterService.save(bookChapter);
// if (number != null && bookId != null) {
// BookChapterEntity chapter = bookChapterService.getBaseMapper().selectOne(new QueryWrapper<BookChapterEntity>()
// .eq("number", number)
// .eq("book_id", bookId));
// if (chapter != null) {
// return R.error("该章节已存在,请修改或重新上传");
// } else {
// bookChapterEntity.setBookId(bookChapter.getBookId());
// bookChapterEntity.setNumber(bookChapter.getNumber());
// bookChapterEntity.setContent(bookChapter.getContent());
// bookChapterEntity.setChapter(bookChapter.getChapter());
// bookChapterEntity.setVoices(bookChapter.getVoices());
// bookChapterService.save(bookChapterEntity);
// }
//
// }
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/contentupdate")
public R contentupdate(@RequestBody BookChapterEntity bookChapter) {
Integer id = bookChapter.getId();
String content = bookChapter.getContent();
//
// bookChapterService.updateById(bookChapter); // 更新对象的属性
//
// return R.ok();
BookChapterEntity byId = bookChapterService.getById(id);
String content1 = byId.getContent();
if (content.equals(content1)) {
} else {
// 如果content字段和原来数据库的content内容不同则voices字段为空
bookChapter.setVoices(""); // 设置voices字段为空
}
bookChapterService.updateById(bookChapter); // 更新对象的属性
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
// @RequiresPermissions("book:bookchapter:update")
public R update(@RequestBody BookChapterEntity bookChapter){
bookChapterService.updateById(bookChapter);
public R update(@RequestBody BookChapterEntity bookChapter) {
bookChapterService.updateById(bookChapter); // 更新对象的属性
return R.ok();
}
public static List<BookChapterEntity> sort(List<BookChapterEntity> list){
//根据指定比较器产生的顺序对指定列表进行排序。
Collections.sort(list, new Comparator<BookChapterEntity>() {
@Override
public int compare(BookChapterEntity o1, BookChapterEntity o2) {
//获取所需语言环境的 Collator根据所需切换其他语言环境
//Collator collator = Collator.getInstance(Locale.ENGLISH);
//return collator.compare(o1.getAddress(), o2.getAddress());
Collator collator = Collator.getInstance(Locale.CANADA);
return collator.compare(o1.getNumber(), o2.getNumber());
}
});
return list;
}
/**
* 优化删除,暂时报错未修改
*/
//TODO 优化删除,暂时报错未修改
@RequestMapping("/deletess")
public R deletess(@RequestBody Integer[] ids){
for(Integer id : ids){
BookChapterEntity chapter = bookChapterService.getBaseMapper().selectOne(new QueryWrapper<BookChapterEntity>()
.eq("id", id)
);
List<BookChapterEntity> bookChapterEntities = this.bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
.eq("book_id", chapter.getBookId())
.gt("number", chapter.getNumber()));
this.bookChapterService.removeById(id);
for(BookChapterEntity entity: bookChapterEntities){
entity.setNumber(entity.getNumber() - 1);
}
List<BookChapterEntity> bookChapterEntities2 = sort(bookChapterEntities);
List<BookChapterEntity> tempEntity = this.bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
.eq("book_id", chapter.getBookId()).orderByAsc("number")
);
int index = tempEntity.size() - bookChapterEntities.size();
for(BookChapterEntity entity: bookChapterEntities2){
index ++;
entity.setNumber(index);
this.bookChapterService.updateById(entity);
}
}
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
// @RequiresPermissions("book:bookchapter:delete")
public R delete(@RequestBody Integer[] ids){
bookChapterService.removeByIds(Arrays.asList(ids));
public R delete(@RequestBody Integer[] ids) {
for(Integer id : ids){
BookChapterEntity chapter = bookChapterService.getBaseMapper().selectOne(new QueryWrapper<BookChapterEntity>()
.eq("id", id)
);
List<BookChapterEntity> bookChapterEntities = this.bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
.eq("book_id", chapter.getBookId())
.gt("number", chapter.getNumber()));
this.bookChapterService.removeById(id);
for(BookChapterEntity entity: bookChapterEntities){
entity.setNumber(entity.getNumber() - 1);
this.bookChapterService.updateById(entity);
}
List<BookChapterEntity> tempEntity = this.bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
.eq("book_id", chapter.getBookId()).orderByAsc("number")
);
int index = 0;
for(BookChapterEntity entity: tempEntity){
index ++;
entity.setNumber(index);
this.bookChapterService.updateById(entity);
}
}
return R.ok();
}
}
}