diff --git a/bookshelfplus-frontend/routes/index.js b/bookshelfplus-frontend/routes/index.js index 4547215..b6222dc 100644 --- a/bookshelfplus-frontend/routes/index.js +++ b/bookshelfplus-frontend/routes/index.js @@ -114,14 +114,14 @@ router.get('/dashboard/:group/:page', function (req, res) { title: "仪表盘", baseTemplate: "index", }, - "myBookshelf": { - title: "我的书架", - baseTemplate: "form", - pageTemplate: "myBookshelf", - }, + // "myBookshelf": { + // title: "我的书架", + // baseTemplate: "form", + // pageTemplate: "myBookshelf", + // }, "myCollection": { title: "我的收藏", - baseTemplate: "form", + baseTemplate: "blank", pageTemplate: "myCollection", }, "myAccount": { diff --git a/bookshelfplus.sql b/bookshelfplus.sql index 8b4e728..5df07ee 100644 --- a/bookshelfplus.sql +++ b/bookshelfplus.sql @@ -11,7 +11,7 @@ Target Server Version : 50726 File Encoding : 65001 - Date: 04/04/2022 17:06:31 + Date: 05/04/2022 17:54:17 */ SET NAMES utf8mb4; @@ -205,6 +205,23 @@ CREATE TABLE `third_party_user_info` ( -- Records of third_party_user_info -- ---------------------------- +-- ---------------------------- +-- Table structure for user_book_favorites_relation +-- ---------------------------- +DROP TABLE IF EXISTS `user_book_favorites_relation`; +CREATE TABLE `user_book_favorites_relation` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL, + `book_id` int(11) NOT NULL, + `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `user_id`(`user_id`, `book_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of user_book_favorites_relation +-- ---------------------------- + -- ---------------------------- -- Table structure for user_info -- ---------------------------- diff --git a/bookshelfplus/docs/asciidoc/generated/all.adoc b/bookshelfplus/docs/asciidoc/generated/all.adoc index 82f9453..bd0de7d 100644 --- a/bookshelfplus/docs/asciidoc/generated/all.adoc +++ b/bookshelfplus/docs/asciidoc/generated/all.adoc @@ -170,6 +170,79 @@ __必填__|id|integer (int32) ---- +[[_addfavoritesusingpost_1]] +==== 【用户】收藏/取消收藏书籍 +.... +POST /api/book/getFavoritesStatus +.... + + +===== 说明 +用户收藏书籍 + + +===== 参数 + +[options="header", cols=".^2a,.^3a,.^4a"] +|=== +|类型|名称|类型 +|**FormData**|**bookId** + +__可选__|integer (int32) +|**FormData**|**token** + +__可选__|string +|=== + + +===== 响应 + +[options="header", cols=".^2a,.^14a,.^4a"] +|=== +|HTTP代码|说明|类型 +|**200**|OK|<<_commonreturntype,CommonReturnType>> +|**201**|Created|无内容 +|**401**|Unauthorized|无内容 +|**403**|Forbidden|无内容 +|**404**|Not Found|无内容 +|=== + + +===== 消耗 + +* `application/x-www-form-urlencoded` + + +===== 生成 + +* `\*/*` + + +===== HTTP请求示例 + +====== 请求 path +---- +/api/book/getFavoritesStatus +---- + + +====== 请求 formData +[source,json] +---- +"string" +---- + + +===== HTTP响应示例 + +====== 响应 200 +[source,json] +---- +{ + "data" : "object", + "status" : "string" +} +---- + + [[_searchusingget]] ==== 查询书籍列表 .... @@ -238,6 +311,81 @@ __可选__|publishingHouse|string ---- +[[_addfavoritesusingpost]] +==== 【用户】收藏/取消收藏书籍 +.... +POST /api/book/toggleFavorites +.... + + +===== 说明 +用户收藏书籍 + + +===== 参数 + +[options="header", cols=".^2a,.^3a,.^4a"] +|=== +|类型|名称|类型 +|**FormData**|**bookId** + +__可选__|integer (int32) +|**FormData**|**status** + +__可选__|boolean +|**FormData**|**token** + +__可选__|string +|=== + + +===== 响应 + +[options="header", cols=".^2a,.^14a,.^4a"] +|=== +|HTTP代码|说明|类型 +|**200**|OK|<<_commonreturntype,CommonReturnType>> +|**201**|Created|无内容 +|**401**|Unauthorized|无内容 +|**403**|Forbidden|无内容 +|**404**|Not Found|无内容 +|=== + + +===== 消耗 + +* `application/x-www-form-urlencoded` + + +===== 生成 + +* `\*/*` + + +===== HTTP请求示例 + +====== 请求 path +---- +/api/book/toggleFavorites +---- + + +====== 请求 formData +[source,json] +---- +"string" +---- + + +===== HTTP响应示例 + +====== 响应 200 +[source,json] +---- +{ + "data" : "object", + "status" : "string" +} +---- + + [[_82c2171949c312f17a084ab9b31e7d55]] === 书籍分类信息 Category Controller @@ -354,6 +502,79 @@ GET /api/category/list User Controller +[[_cancelaccountusingpost]] +==== 账号注销 +.... +POST /api/user/cancelAccount +.... + + +===== 说明 +传入用户 token ,以及密码明文,后台计算密码SHA1值,进行注销 + + +===== 参数 + +[options="header", cols=".^2a,.^3a,.^4a"] +|=== +|类型|名称|类型 +|**FormData**|**password** + +__可选__|string +|**FormData**|**token** + +__可选__|string +|=== + + +===== 响应 + +[options="header", cols=".^2a,.^14a,.^4a"] +|=== +|HTTP代码|说明|类型 +|**200**|OK|<<_commonreturntype,CommonReturnType>> +|**201**|Created|无内容 +|**401**|Unauthorized|无内容 +|**403**|Forbidden|无内容 +|**404**|Not Found|无内容 +|=== + + +===== 消耗 + +* `application/x-www-form-urlencoded` + + +===== 生成 + +* `\*/*` + + +===== HTTP请求示例 + +====== 请求 path +---- +/api/user/cancelAccount +---- + + +====== 请求 formData +[source,json] +---- +"string" +---- + + +===== HTTP响应示例 + +====== 响应 200 +[source,json] +---- +{ + "data" : "object", + "status" : "string" +} +---- + + [[_getuserstatususingpost]] ==== 获取用户登录状态 .... @@ -719,6 +940,64 @@ __可选__|token|string ---- +[[_getbindingstatususingget]] +==== 获取用户已绑定的第三方平台 +.... +GET /api/third-party/getBindingStatus +.... + + +===== 说明 +传入当前登录用户 token ,返回已绑定的第三方平台 + + +===== 参数 + +[options="header", cols=".^2a,.^3a,.^9a,.^4a"] +|=== +|类型|名称|说明|类型 +|**Query**|**token** + +__可选__|token|string +|=== + + +===== 响应 + +[options="header", cols=".^2a,.^14a,.^4a"] +|=== +|HTTP代码|说明|类型 +|**200**|OK|<<_commonreturntype,CommonReturnType>> +|**401**|Unauthorized|无内容 +|**403**|Forbidden|无内容 +|**404**|Not Found|无内容 +|=== + + +===== 生成 + +* `\*/*` + + +===== HTTP请求示例 + +====== 请求 path +---- +/api/third-party/getBindingStatus +---- + + +===== HTTP响应示例 + +====== 响应 200 +[source,json] +---- +{ + "data" : "object", + "status" : "string" +} +---- + + [[_loginusingget]] ==== 第三方用户登录跳转地址 .... @@ -777,6 +1056,79 @@ __必填__|platform|string ---- +[[_unbindthirdpartaccountusingpost]] +==== 取消第三方平台绑定 +.... +POST /api/third-party/withdrawThirdPartyBings +.... + + +===== 说明 +传入当前登录用户 token 和平台 platform (不区分大小写),返回 bool 值,true 为取消绑定成功 + + +===== 参数 + +[options="header", cols=".^2a,.^3a,.^4a"] +|=== +|类型|名称|类型 +|**FormData**|**platform** + +__可选__|string +|**FormData**|**token** + +__可选__|string +|=== + + +===== 响应 + +[options="header", cols=".^2a,.^14a,.^4a"] +|=== +|HTTP代码|说明|类型 +|**200**|OK|<<_commonreturntype,CommonReturnType>> +|**201**|Created|无内容 +|**401**|Unauthorized|无内容 +|**403**|Forbidden|无内容 +|**404**|Not Found|无内容 +|=== + + +===== 消耗 + +* `application/x-www-form-urlencoded` + + +===== 生成 + +* `\*/*` + + +===== HTTP请求示例 + +====== 请求 path +---- +/api/third-party/withdrawThirdPartyBings +---- + + +====== 请求 formData +[source,json] +---- +"string" +---- + + +===== HTTP响应示例 + +====== 响应 200 +[source,json] +---- +{ + "data" : "object", + "status" : "string" +} +---- + + [[_aca0f16a4237edba915fe70c9b07871c]] === 系统调试接口 Debug Controller diff --git a/bookshelfplus/src/main/java/plus/bookshelf/Common/Error/BusinessErrorCode.java b/bookshelfplus/src/main/java/plus/bookshelf/Common/Error/BusinessErrorCode.java index e8ad36a..88ef4bd 100644 --- a/bookshelfplus/src/main/java/plus/bookshelf/Common/Error/BusinessErrorCode.java +++ b/bookshelfplus/src/main/java/plus/bookshelf/Common/Error/BusinessErrorCode.java @@ -18,8 +18,15 @@ public enum BusinessErrorCode implements CommonError { // 40000开头为第三方登录相关错误定义 THIRD_PARTY_LOGIN_FAIL(40001, "第三方登录失败"), THIRD_PARTY_ACCOUNT_ALREADY_BOUND(40002, "该账号已被其他账号绑定"), - THIRD_PARTY_UNBIND_FAIL(40003, "第三方账号解绑失败"); + THIRD_PARTY_UNBIND_FAIL(40003, "第三方账号解绑失败"), + // 50000开头为书籍相关错误定义 + BOOK_NOT_EXIST(50001, "书籍不存在"), + BOOK_FAVORITES_ALREADY_EXIST(50002, "书籍已经在收藏夹中"), + BOOK_FAVORITES_NOT_EXIST(50003, "书籍不在收藏夹中"), + + // 占位 + PLACE_HOLDER(99999, "这是一个占位符错误"); private BusinessErrorCode(int errCode, String errMsg) { this.errCode = errCode; diff --git a/bookshelfplus/src/main/java/plus/bookshelf/Controller/Controller/BookController.java b/bookshelfplus/src/main/java/plus/bookshelf/Controller/Controller/BookController.java index fe0ecd1..9767c83 100644 --- a/bookshelfplus/src/main/java/plus/bookshelf/Controller/Controller/BookController.java +++ b/bookshelfplus/src/main/java/plus/bookshelf/Controller/Controller/BookController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import plus.bookshelf.Common.Error.BusinessErrorCode; import plus.bookshelf.Common.Error.BusinessException; import plus.bookshelf.Common.Response.CommonReturnType; import plus.bookshelf.Controller.VO.BookVO; @@ -19,6 +20,7 @@ import plus.bookshelf.Service.Model.UserModel; import plus.bookshelf.Service.Service.BookService; import java.util.List; +import java.util.Map; @Api(tags = "书籍信息") @Controller("book") @@ -71,6 +73,49 @@ public class BookController extends BaseController { return CommonReturnType.create(bookModels); } + @ApiOperation(value = "【用户】收藏/取消收藏书籍", notes = "用户收藏书籍") + @RequestMapping(value = "toggleFavorites", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED}) + @ResponseBody + public CommonReturnType addFavorites(@RequestParam(value = "token", required = false) String token, + @RequestParam(value = "bookId", required = false) Integer bookId, + @RequestParam(value = "status", required = true) Boolean isFavoritesNow) throws BusinessException { + + // 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断 + UserModel userModel = userService.getUserByToken(redisTemplate, token); + + if (isFavoritesNow) { + // 这里查询一次书籍的用处是为了防止用户收藏的书籍不存在 + BookModel bookModel = bookService.getBookById(bookId); + if (bookModel == null) { + throw new BusinessException(BusinessErrorCode.BOOK_NOT_EXIST, "书籍不存在"); + } + + Boolean isSuccess = bookService.addFavorites(userModel.getId(), bookModel.getId()); + if (!isSuccess) { + throw new BusinessException(BusinessErrorCode.BOOK_FAVORITES_ALREADY_EXIST, "书籍已经收藏"); + } + } else { + // 不用担心书籍不存在的情况,因为书籍不存在数据库中不会删除成功 + Boolean isSuccess = bookService.removeFavorites(userModel.getId(), bookId); + if (!isSuccess) { + throw new BusinessException(BusinessErrorCode.BOOK_FAVORITES_NOT_EXIST, "书籍尚未收藏"); + } + } + return CommonReturnType.create("success"); + } + + @ApiOperation(value = "【用户】收藏/取消收藏书籍", notes = "用户收藏书籍") + @RequestMapping(value = "getFavoritesStatus", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED}) + @ResponseBody + public CommonReturnType addFavorites(@RequestParam(value = "token", required = false) String token, + @RequestParam(value = "bookId", required = false) Integer bookId) throws BusinessException { + + // 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断 + UserModel userModel = userService.getUserByToken(redisTemplate, token); + + Map favoritesStatus = bookService.getFavoritesStatus(userModel.getId(), bookId); + return CommonReturnType.create(favoritesStatus); + } @ApiOperation(value = "【管理员】添加书籍", notes = "管理员在后台添加书籍") @RequestMapping(value = "add", method = {RequestMethod.GET}) diff --git a/bookshelfplus/src/main/java/plus/bookshelf/Dao/DO/UserFavoritesDO.java b/bookshelfplus/src/main/java/plus/bookshelf/Dao/DO/UserFavoritesDO.java new file mode 100644 index 0000000..88818bf --- /dev/null +++ b/bookshelfplus/src/main/java/plus/bookshelf/Dao/DO/UserFavoritesDO.java @@ -0,0 +1,137 @@ +package plus.bookshelf.Dao.DO; + +import java.util.Date; + +public class UserFavoritesDO { + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_book_favorites_relation.id + * + * @mbg.generated + */ + private Integer id; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_book_favorites_relation.user_id + * + * @mbg.generated + */ + private Integer userId; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_book_favorites_relation.book_id + * + * @mbg.generated + */ + private Integer bookId; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_book_favorites_relation.create_time + * + * @mbg.generated + */ + private Date createTime; + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_book_favorites_relation.id + * + * @return the value of user_book_favorites_relation.id + * + * @mbg.generated + */ + public Integer getId() { + return id; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_book_favorites_relation.id + * + * @param id the value for user_book_favorites_relation.id + * + * @mbg.generated + */ + public void setId(Integer id) { + this.id = id; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_book_favorites_relation.user_id + * + * @return the value of user_book_favorites_relation.user_id + * + * @mbg.generated + */ + public Integer getUserId() { + return userId; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_book_favorites_relation.user_id + * + * @param userId the value for user_book_favorites_relation.user_id + * + * @mbg.generated + */ + public void setUserId(Integer userId) { + this.userId = userId; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_book_favorites_relation.book_id + * + * @return the value of user_book_favorites_relation.book_id + * + * @mbg.generated + */ + public Integer getBookId() { + return bookId; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_book_favorites_relation.book_id + * + * @param bookId the value for user_book_favorites_relation.book_id + * + * @mbg.generated + */ + public void setBookId(Integer bookId) { + this.bookId = bookId; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_book_favorites_relation.create_time + * + * @return the value of user_book_favorites_relation.create_time + * + * @mbg.generated + */ + public Date getCreateTime() { + return createTime; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_book_favorites_relation.create_time + * + * @param createTime the value for user_book_favorites_relation.create_time + * + * @mbg.generated + */ + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } +} \ No newline at end of file diff --git a/bookshelfplus/src/main/java/plus/bookshelf/Dao/Mapper/UserFavoritesDOMapper.java b/bookshelfplus/src/main/java/plus/bookshelf/Dao/Mapper/UserFavoritesDOMapper.java new file mode 100644 index 0000000..09af61b --- /dev/null +++ b/bookshelfplus/src/main/java/plus/bookshelf/Dao/Mapper/UserFavoritesDOMapper.java @@ -0,0 +1,69 @@ +package plus.bookshelf.Dao.Mapper; + +import plus.bookshelf.Dao.DO.UserFavoritesDO; + +public interface UserFavoritesDOMapper { + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table user_book_favorites_relation + * + * @mbg.generated + */ + int deleteByPrimaryKey(Integer id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table user_book_favorites_relation + * + * @mbg.generated + */ + int insert(UserFavoritesDO record); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table user_book_favorites_relation + * + * @mbg.generated + */ + int insertSelective(UserFavoritesDO record); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table user_book_favorites_relation + * + * @mbg.generated + */ + UserFavoritesDO selectByPrimaryKey(Integer id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table user_book_favorites_relation + * + * @mbg.generated + */ + int updateByPrimaryKeySelective(UserFavoritesDO record); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table user_book_favorites_relation + * + * @mbg.generated + */ + int updateByPrimaryKey(UserFavoritesDO record); + + /** + * 通过用户id和书籍id删除用户收藏状态 + * @param userId + * @param bookId + * @return + */ + int deleteByUserIdAndBookId(Integer userId, Integer bookId); + + /** + * 通过用户id和书籍id获取用户收藏状态 + * @param userId + * @param bookId + * @return + */ + UserFavoritesDO selectCountByUserIdAndBookId(Integer userId, Integer bookId); +} \ No newline at end of file diff --git a/bookshelfplus/src/main/java/plus/bookshelf/Service/Impl/BookServiceImpl.java b/bookshelfplus/src/main/java/plus/bookshelf/Service/Impl/BookServiceImpl.java index a098825..55f1d97 100644 --- a/bookshelfplus/src/main/java/plus/bookshelf/Service/Impl/BookServiceImpl.java +++ b/bookshelfplus/src/main/java/plus/bookshelf/Service/Impl/BookServiceImpl.java @@ -1,8 +1,6 @@ package plus.bookshelf.Service.Impl; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.math.NumberUtils; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -12,14 +10,18 @@ import plus.bookshelf.Common.Validator.ValidationResult; import plus.bookshelf.Common.Validator.ValidatorImpl; import plus.bookshelf.Dao.DO.BookDO; import plus.bookshelf.Dao.DO.BookDOExample; +import plus.bookshelf.Dao.DO.UserFavoritesDO; import plus.bookshelf.Dao.Mapper.BookDOMapper; +import plus.bookshelf.Dao.Mapper.UserFavoritesDOMapper; import plus.bookshelf.Service.Model.BookModel; import plus.bookshelf.Service.Model.CategoryModel; import plus.bookshelf.Service.Service.BookService; import plus.bookshelf.Service.Service.CategoryService; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Service public class BookServiceImpl implements BookService { @@ -30,6 +32,9 @@ public class BookServiceImpl implements BookService { @Autowired private CategoryService categoryService; + @Autowired + private UserFavoritesDOMapper userFavoritesDOMapper; + @Autowired ValidatorImpl validator; @@ -83,6 +88,62 @@ public class BookServiceImpl implements BookService { return bookDOMapper.insertSelective(bookDO); } + /** + * 用户收藏书籍 + * + * @param userId 用户id + * @param bookId 书籍id + * @return + * @throws BusinessException + */ + @Override + public Boolean addFavorites(Integer userId, Integer bookId) throws BusinessException { + UserFavoritesDO userFavoritesDO = new UserFavoritesDO(); + userFavoritesDO.setBookId(bookId); + userFavoritesDO.setUserId(userId); + int affectRows = userFavoritesDOMapper.insert(userFavoritesDO); + return affectRows > 0; + } + + /** + * 用户取消收藏书籍 + * + * @param userId 用户id + * @param bookId 书籍id + * @return + * @throws BusinessException + */ + @Override + public Boolean removeFavorites(Integer userId, Integer bookId) throws BusinessException { + int affectRows = userFavoritesDOMapper.deleteByUserIdAndBookId(userId, bookId); + return affectRows > 0; + } + + /** + * 获取用户收藏状态 + * + * @param userId 用户id + * @param bookId 书籍id + * @return + * @throws BusinessException + */ + @Override + public Map getFavoritesStatus(Integer userId, Integer bookId) throws BusinessException { + UserFavoritesDO userFavoritesDO = userFavoritesDOMapper.selectCountByUserIdAndBookId(userId, bookId); + + Map result = new HashMap<>(); + if (userFavoritesDO == null) { + // 用户未收藏 + result.put("status", "0"); + result.put("time", null); + } else { + // 用户已收藏,返回收藏时间 + result.put("status", "1"); + result.put("time", userFavoritesDO.getCreateTime().toString()); + } + return result; + } + private BookModel convertFromDataObjecct(BookDO bookDO) { if (bookDO == null) { return null; diff --git a/bookshelfplus/src/main/java/plus/bookshelf/Service/Service/BookService.java b/bookshelfplus/src/main/java/plus/bookshelf/Service/Service/BookService.java index 78bd473..a2ff146 100644 --- a/bookshelfplus/src/main/java/plus/bookshelf/Service/Service/BookService.java +++ b/bookshelfplus/src/main/java/plus/bookshelf/Service/Service/BookService.java @@ -5,6 +5,7 @@ import plus.bookshelf.Dao.DO.BookDO; import plus.bookshelf.Service.Model.BookModel; import java.util.List; +import java.util.Map; public interface BookService { /** @@ -29,4 +30,30 @@ public interface BookService { * @return */ Integer addBook(BookModel bookModel) throws BusinessException; + + /** + * 用户收藏书籍 + * + * @param bookId 书籍id + * @return + */ + Boolean addFavorites(Integer userId, Integer bookId) throws BusinessException; + + /** + * 用户取消收藏书籍 + * @param userId + * @param bookId + * @return + * @throws BusinessException + */ + Boolean removeFavorites(Integer userId, Integer bookId) throws BusinessException; + + /** + * 获取用户收藏状态 + * @param userId 用户id + * @param bookId 书籍id + * @return + * @throws BusinessException + */ + Map getFavoritesStatus(Integer userId, Integer bookId) throws BusinessException; } diff --git a/bookshelfplus/src/main/resources/mapping/UserFavoritesDOMapper.xml b/bookshelfplus/src/main/resources/mapping/UserFavoritesDOMapper.xml new file mode 100644 index 0000000..7c65d03 --- /dev/null +++ b/bookshelfplus/src/main/resources/mapping/UserFavoritesDOMapper.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + id, user_id, book_id, create_time + + + + + delete from user_book_favorites_relation + where id = #{id,jdbcType=INTEGER} + + + + insert into user_book_favorites_relation (id, user_id, book_id, + create_time) + values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{bookId,jdbcType=INTEGER}, + #{createTime,jdbcType=TIMESTAMP}) + + + + insert into user_book_favorites_relation + + + id, + + + user_id, + + + book_id, + + + create_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{userId,jdbcType=INTEGER}, + + + #{bookId,jdbcType=INTEGER}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + + + + update user_book_favorites_relation + + + user_id = #{userId,jdbcType=INTEGER}, + + + book_id = #{bookId,jdbcType=INTEGER}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + + update user_book_favorites_relation + set user_id = #{userId,jdbcType=INTEGER}, + book_id = #{bookId,jdbcType=INTEGER}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + + delete from user_book_favorites_relation + where user_id = #{userId,jdbcType=INTEGER} and book_id = #{bookId,jdbcType=INTEGER} limit 1 + + + \ No newline at end of file diff --git a/bookshelfplus/src/main/resources/mybatis-generator.xml b/bookshelfplus/src/main/resources/mybatis-generator.xml index d6146ce..cc56e18 100644 --- a/bookshelfplus/src/main/resources/mybatis-generator.xml +++ b/bookshelfplus/src/main/resources/mybatis-generator.xml @@ -94,5 +94,8 @@ + + + \ No newline at end of file