1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-10-03 22:45:15 +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

@@ -94,7 +94,7 @@
} }
function deleteBook(deleteBookId) { function deleteBook(deleteBookId) {
if (!confirm(`确认要删除编号为 ${deleteBookId} 的书籍吗?`)) return; if (!confirm(`确认要删除编号为 ${deleteBookId} 的书籍吗?(关联文件不会被删除)`)) return;
postRequest("/book/delete", { token: localStorageUtils.getToken(), id: deleteBookId }) postRequest("/book/delete", { token: localStorageUtils.getToken(), id: deleteBookId })
.then(function (responseData) { .then(function (responseData) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -237,4 +237,9 @@
<select id="getLastInsertId" resultType="java.lang.Integer"> <select id="getLastInsertId" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID(); SELECT LAST_INSERT_ID();
</select> </select>
<update id="unbindBook" parameterType="java.lang.Integer">
update file_info
set book_id = 0
where book_id = #{bookId,jdbcType=INTEGER}
</update>
</mapper> </mapper>