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 22:52:07 +08:00
parent ca0ede8917
commit 3d2e9b6dfa
14 changed files with 288 additions and 52 deletions

View File

@@ -117,19 +117,21 @@ public class BookController extends BaseController {
return CommonReturnType.create(favoritesStatus);
}
@ApiOperation(value = "【管理员】添加书籍", notes = "管理员在后台添加书籍")
@RequestMapping(value = "add", method = {RequestMethod.GET})
@ApiOperation(value = "【管理员】添加/修改书籍", notes = "管理员在后台添加/修改书籍bookId 传 0 或 null 或 不传 即为添加)")
@RequestMapping(value = "detail", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
@ResponseBody
public CommonReturnType add(@RequestParam(value = "token", required = false) String token,
@RequestParam(required = false, value = "bookName") String bookName,
@RequestParam(required = false, value = "description") String description,
@RequestParam(required = false, value = "categoryId") Integer categoryId,
@RequestParam(required = false, value = "publishingHouse") String publishingHouse,
@RequestParam(required = false, value = "language") String language,
@RequestParam(required = false, value = "copyright") String copyright,
@RequestParam(required = false, value = "isDelete") Boolean isDelete,
@RequestParam(required = false, value = "thumbnail") String thumbnail,
@RequestParam(required = false, value = "author") String author) throws BusinessException {
public CommonReturnType detail(@RequestParam(value = "token", required = false) String token,
@RequestParam(required = false, value = "id") Integer bookId,
@RequestParam(required = false, value = "bookName") String bookName,
@RequestParam(required = false, value = "description") String description,
@RequestParam(required = false, value = "categoryId") Integer categoryId,
@RequestParam(required = false, value = "publishingHouse") String publishingHouse,
@RequestParam(required = false, value = "language") String language,
@RequestParam(required = false, value = "copyright") String copyright,
// 【前端未提交到后端的参数】 isDelete thumbnail
@RequestParam(required = false, value = "isDelete") Boolean isDelete,
@RequestParam(required = false, value = "thumbnail") String thumbnail,
@RequestParam(required = false, value = "author") String author) throws BusinessException {
// 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断
UserModel userModel = userService.getUserByToken(redisTemplate, token);
@@ -149,7 +151,17 @@ public class BookController extends BaseController {
bookModel.setCategory(categoryModel);
}
Integer affectRows = bookService.addBook(bookModel);
Integer affectRows = 0;
if (bookId == null || bookId == 0) {
// 新增图书
isDelete = false;
affectRows = bookService.addBook(bookModel);
} else {
//修改图书
bookModel.setId(bookId);
affectRows = bookService.modifyBook(bookModel);
}
if (affectRows > 0) {
return CommonReturnType.create("success");
} else {

View File

@@ -74,7 +74,6 @@ public class BookServiceImpl implements BookService {
@Override
public Integer addBook(BookModel bookModel) throws BusinessException {
// 校验入参
ValidationResult result = validator.validate(bookModel);
if (result.isHasErrors()) {
@@ -85,6 +84,18 @@ public class BookServiceImpl implements BookService {
return bookDOMapper.insertSelective(bookDO);
}
@Override
public Integer modifyBook(BookModel bookModel) throws BusinessException {
// 校验入参
ValidationResult result = validator.validate(bookModel);
if (result.isHasErrors()) {
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, result.getErrMsg());
}
BookDO bookDO = convertToDataObjecct(bookModel);
return bookDOMapper.updateByPrimaryKeySelective(bookDO);
}
/**
* 用户收藏书籍
*

View File

@@ -7,7 +7,9 @@ public class ThirdPartyUserAuthModel {
private Integer id;
// 用户 Id
private String userId;
// 用户第三方授权 Id
private String thirdPartyUserId;
}

View File

@@ -31,6 +31,14 @@ public interface BookService {
*/
Integer addBook(BookModel bookModel) throws BusinessException;
/**
* 修改书籍
* @param bookModel
* @return
* @throws BusinessException
*/
Integer modifyBook(BookModel bookModel) throws BusinessException;
/**
* 用户收藏书籍
*