1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-01 22:53:29 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

删除书籍前取消书籍与文件的关联

This commit is contained in:
2022-04-20 00:02:31 +08:00
parent 493d9f970a
commit e493458406
8 changed files with 46 additions and 9 deletions

View File

@@ -1,7 +1,6 @@
package plus.bookshelf.Common.MarkdownUtils;
import org.apache.commons.lang3.StringUtils;
import org.yaml.snakeyaml.error.Mark;
public class MarkdownUtils {

View File

@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@@ -13,6 +14,7 @@ import plus.bookshelf.Common.Error.BusinessErrorCode;
import plus.bookshelf.Common.Error.BusinessException;
import plus.bookshelf.Common.Response.CommonReturnType;
import plus.bookshelf.Controller.VO.BookVO;
import plus.bookshelf.Service.Impl.FileServiceImpl;
import plus.bookshelf.Service.Impl.UserServiceImpl;
import plus.bookshelf.Service.Model.BookModel;
import plus.bookshelf.Service.Model.CategoryModel;
@@ -33,6 +35,9 @@ public class BookController extends BaseController {
@Autowired
UserServiceImpl userService;
@Autowired
FileServiceImpl fileService;
@ApiOperation(value = "获取书籍信息", notes = "获取书籍信息")
// @ApiImplicitParam(name = "book", value = "图书详细实体", required = true, dataType = "Book")
@RequestMapping(value = "get", method = {RequestMethod.GET})
@@ -184,13 +189,19 @@ public class BookController extends BaseController {
@ApiOperation(value = "【管理员】删除书籍", notes = "管理员在后台删除书籍")
@RequestMapping(value = "delete", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
@ResponseBody
@Transactional
public CommonReturnType deleteBook(@RequestParam(value = "token", required = false) String token,
@RequestParam(required = true, value = "id") Integer bookId) throws BusinessException {
// 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断
UserModel userModel = userService.getUserByToken(redisTemplate, token);
Integer affectRows = bookService.deleteBook(bookId);
if (affectRows > 0) {
// 取消书籍与文件的关联
fileService.unbindBook(bookId);
// 删除书籍
Integer affectRows2 = bookService.deleteBook(bookId);
if (affectRows2 > 0) {
return CommonReturnType.create("success");
} else {
return CommonReturnType.create("failed");
@@ -199,7 +210,7 @@ public class BookController extends BaseController {
private BookVO convertFromModel(BookModel bookModel) {
if(bookModel == null) {
if (bookModel == null) {
return null;
}
BookVO bookVO = new BookVO();

View File

@@ -141,9 +141,8 @@ public class ExportController extends BaseController {
@ResponseBody
public CommonReturnType exportMarkdown(@RequestParam(value = "token", required = false) String token) throws BusinessException {
// TODO 暂时注释掉
// // 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断
// UserModel userModel = userService.getUserByToken(redisTemplate, token);
// 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断
UserModel userModel = userService.getUserByToken(redisTemplate, token);
// 查询出系统中所有的分类、书籍、文件、文件对象数据
CategoryDO[] allCategorys = categoryDOMapper.selectAll();

View File

@@ -74,6 +74,13 @@ public interface FileDOMapper {
*/
FileDO[] selectAvailableByBookId(Integer bookId);
/**
* 取消文件和书籍的关联
*
* @return
*/
int unbindBook(Integer bookId);
/**
* 获取上一次插入的主键Id
*

View File

@@ -11,7 +11,6 @@ import plus.bookshelf.Dao.DO.FileDO;
import plus.bookshelf.Dao.Mapper.FileDOMapper;
import plus.bookshelf.Dao.Mapper.FileObjectDOMapper;
import plus.bookshelf.Service.Model.FileModel;
import plus.bookshelf.Service.Model.UserModel;
import plus.bookshelf.Service.Service.CosPresignedUrlGenerateLogService;
import plus.bookshelf.Service.Service.FileService;
@@ -132,6 +131,16 @@ public class FileServiceImpl implements FileService {
return fileDO;
}
/**
* 取消文件和书籍的关联
*
* @return
*/
@Override
public Integer unbindBook(Integer bookId) {
return fileDOMapper.unbindBook(bookId);
}
/**
* 获取上一步添加的文件Id
*

View File

@@ -43,6 +43,13 @@ public interface FileService {
*/
Boolean addFile(FileModel fileModel) throws InvocationTargetException, IllegalAccessException;
/**
* 取消文件和书籍的关联
*
* @return
*/
Integer unbindBook(Integer bookId);
/**
* 获取上一步添加的文件Id
*