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-06 23:15:37 +08:00
parent 3d2e9b6dfa
commit 61ecc5600a
5 changed files with 91 additions and 2 deletions

View File

@@ -41,7 +41,7 @@
</span>`,
管理: `<span class="overflow-omit" style="max-width: ${columnWidth[5] * mainDivWidth / 100}vw; max-height: 2em; margin: 0 auto;">
<a href="<%= pageUrl %>detail?id=${element.id}">修改</a>
<a href="">删除</a>
<a href="javascript:deleteBook(${element.id});">删除</a>
</span>`,
})
});
@@ -78,4 +78,32 @@
alert("无法连接到服务器,请检查网络连接!");
});
}
function deleteBook(deleteBookId) {
if (!confirm(`确认要删除编号为 ${deleteBookId} 的书籍吗?`)) return;
postRequest("/book/delete", { token: localStorageUtils.getToken(), id: deleteBookId })
.then(function (responseData) {
var axiosData = responseData.data;
var status = axiosData.status;
var data = axiosData.data;
if (status === "success") {
console.log(data)
if (data == "success") {
search({
tableElementId: "book-table",
searchText: $("#searchInput").val(),
categoryId: null
});
} else {
alert("删除失败!");
}
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
}
}).catch(function (error) {
console.log(error);
alert("无法连接到服务器,请检查网络连接!");
});
}
</script>

View File

@@ -64,7 +64,7 @@
searchText: $("#searchInput").val(),
categoryId: null
});
})
});
</script>
</body>
</html>

View File

@@ -169,6 +169,22 @@ public class BookController extends BaseController {
}
}
@ApiOperation(value = "【管理员】删除书籍", notes = "管理员在后台删除书籍")
@RequestMapping(value = "delete", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
@ResponseBody
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) {
return CommonReturnType.create("success");
} else {
return CommonReturnType.create("failed");
}
}
private BookVO convertFromModel(BookModel bookModel) {
BookVO bookVO = new BookVO();

View File

@@ -35,6 +35,11 @@ public class BookServiceImpl implements BookService {
@Autowired
ValidatorImpl validator;
/**
* 通过 书籍id 查找图书
* @param id
* @return
*/
@Override
@Transactional
public BookModel getBookById(Integer id) {
@@ -44,6 +49,12 @@ public class BookServiceImpl implements BookService {
return bookModel;
}
/**
* 查找图书
* @param bookModel
* @return
* @throws BusinessException
*/
@Override
public List<BookModel> searchBooks(BookModel bookModel) throws BusinessException {
@@ -72,6 +83,12 @@ public class BookServiceImpl implements BookService {
return convertFromDataObjecctList(bookDOs);
}
/**
* 添加图书
* @param bookModel
* @return
* @throws BusinessException
*/
@Override
public Integer addBook(BookModel bookModel) throws BusinessException {
// 校验入参
@@ -84,6 +101,12 @@ public class BookServiceImpl implements BookService {
return bookDOMapper.insertSelective(bookDO);
}
/**
* 修改图书信息
* @param bookModel
* @return
* @throws BusinessException
*/
@Override
public Integer modifyBook(BookModel bookModel) throws BusinessException {
// 校验入参
@@ -96,6 +119,20 @@ public class BookServiceImpl implements BookService {
return bookDOMapper.updateByPrimaryKeySelective(bookDO);
}
/**
* 通过 id 删除图书
* @param bookId
* @return
* @throws BusinessException
*/
@Override
public Integer deleteBook(Integer bookId) throws BusinessException {
if(bookId == null || bookId == 0) {
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "书籍id不能为空");
}
return bookDOMapper.deleteByPrimaryKey(bookId);
}
/**
* 用户收藏书籍
*

View File

@@ -39,6 +39,14 @@ public interface BookService {
*/
Integer modifyBook(BookModel bookModel) throws BusinessException;
/**
* 删除书籍信息
* @param bookId
* @return
* @throws BusinessException
*/
Integer deleteBook(Integer bookId) throws BusinessException;
/**
* 用户收藏书籍
*