From fa18e1c70857ce3e31cc2aa5f0386b45927c5fc3 Mon Sep 17 00:00:00 2001 From: LingandRX <56020800+LingandRX@users.noreply.github.com> Date: Mon, 31 Mar 2025 22:02:17 +0800 Subject: [PATCH] add . --- gradlew | 8 +- gradlew.bat | 22 ++--- .../copykamanotes/mapper/CategoryMapper.java | 28 ++++++ .../mapper/CollectionMapper.java | 71 +++++++++++++++ .../mapper/CollectionNoteMapper.java | 61 +++++++++++++ .../mapper/CommentLikeMapper.java | 44 +++++++++ .../copykamanotes/mapper/CommentMapper.java | 91 +++++++++++++++++++ .../mapper/NoteCollectMapper.java | 47 ++++++++++ .../mapper/NoteCommentMapper.java | 31 +++++++ .../mapper/QuestionListItemMapper.java | 79 ++++++++++++++++ .../copykamanotes/mapper/StatisticMapper.java | 31 +++++++ .../model/dto/comment/CommentQueryParams.java | 42 +++++++++ .../model/vo/question/BaseQuestionVO.java | 38 ++++++++ .../questionListItem/QuestionListItemVO.java | 23 +++++ 14 files changed, 599 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/example/copykamanotes/mapper/CategoryMapper.java create mode 100644 src/main/java/com/example/copykamanotes/mapper/CollectionMapper.java create mode 100644 src/main/java/com/example/copykamanotes/mapper/CollectionNoteMapper.java create mode 100644 src/main/java/com/example/copykamanotes/mapper/CommentLikeMapper.java create mode 100644 src/main/java/com/example/copykamanotes/mapper/CommentMapper.java create mode 100644 src/main/java/com/example/copykamanotes/mapper/NoteCollectMapper.java create mode 100644 src/main/java/com/example/copykamanotes/mapper/NoteCommentMapper.java create mode 100644 src/main/java/com/example/copykamanotes/mapper/QuestionListItemMapper.java create mode 100644 src/main/java/com/example/copykamanotes/mapper/StatisticMapper.java create mode 100644 src/main/java/com/example/copykamanotes/model/dto/comment/CommentQueryParams.java create mode 100644 src/main/java/com/example/copykamanotes/model/vo/question/BaseQuestionVO.java create mode 100644 src/main/java/com/example/copykamanotes/model/vo/questionListItem/QuestionListItemVO.java diff --git a/gradlew b/gradlew index faf9300..1aa94a4 100644 --- a/gradlew +++ b/gradlew @@ -15,8 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# SPDX-License-Identifier: Apache-2.0 -# ############################################################################## # @@ -57,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -86,7 +84,7 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -205,7 +203,7 @@ fi DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, # and any embedded shellness will be escaped. # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be # treated as '${Hostname}' itself on the command line. diff --git a/gradlew.bat b/gradlew.bat index 9d21a21..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,6 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem -@rem SPDX-License-Identifier: Apache-2.0 -@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -45,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. goto fail @@ -59,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. goto fail diff --git a/src/main/java/com/example/copykamanotes/mapper/CategoryMapper.java b/src/main/java/com/example/copykamanotes/mapper/CategoryMapper.java new file mode 100644 index 0000000..37a8692 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/mapper/CategoryMapper.java @@ -0,0 +1,28 @@ +package com.example.copykamanotes.mapper; + +import com.example.copykamanotes.model.entity.Category; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface CategoryMapper { + int insert(Category category); + + int insertBatch(@Param("entities") List entities); + + List categoryList(@Param("entities") List entities); + + Category findById(@Param("id") Integer id); + + Category findByIdBatch(@Param("ids") List ids); + + Category findByIdOrParentId(@Param("id") Integer id, @Param("parentId") Integer parentId); + + int deleteById(@Param("id") Integer id); + + int deleteByIdBatch(@Param("ids") List ids); + + int update(@Param("entities") Category category); +} diff --git a/src/main/java/com/example/copykamanotes/mapper/CollectionMapper.java b/src/main/java/com/example/copykamanotes/mapper/CollectionMapper.java new file mode 100644 index 0000000..9d33d7d --- /dev/null +++ b/src/main/java/com/example/copykamanotes/mapper/CollectionMapper.java @@ -0,0 +1,71 @@ +package com.example.copykamanotes.mapper; + +import com.example.copykamanotes.model.entity.Collection; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface CollectionMapper { + /** + * 根据ID查询收藏夹 + * + * @param collectionId 收藏夹的ID + * @return 返回查询到的收藏夹对象 + */ + Collection findById(@Param("collectionId") Integer collectionId); + + /** + * 根据创建者 ID 查询收藏夹 + * + * @param creatorId 创建者 ID + * @return 返回查询到的收藏夹列表 + */ + List findByCreatorId(@Param("creatorId") Long creatorId); + + /** + * 根据收藏夹 ID 和创建者 ID 查询收藏夹 + * + * @param collectionId 收藏夹 ID + * @param creatorId 创建者 ID + * @return 返回查询到的收藏夹对象 + */ + Collection findByIdAndCreatorId(@Param("collectionId") Integer collectionId, @Param("creatorId") Long creatorId); + + /** + * 根据收藏夹 ID、创建者 ID 和笔记 ID 查询收藏夹 + * + * @param collectionId 收藏夹 ID + * @param creatorId 创建者 ID + * @param noteId 笔记 ID + * @return 返回查询到的收藏夹对象 + */ + int countByCreatorIdAndNoteId( + @Param("creatorId") Long creatorId, + @Param("noteId") Integer noteId); + + /** + * 创建收藏夹 + * + * @param collection 要创建的收藏夹对象 + * @return 返回插入操作的影响行数 + */ + int insert(Collection collection); + + /** + * 更新收藏夹 + * + * @param collection 要更新的收藏夹对象 + * @return 返回更新操作的影响行数 + */ + int update(Collection collection); + + /** + * 删除收藏夹 + * + * @param collectionId 要删除的收藏夹的ID + * @return 返回删除操作的影响行数 + */ + int deleteById(@Param("collectionId") Integer collectionId); +} \ No newline at end of file diff --git a/src/main/java/com/example/copykamanotes/mapper/CollectionNoteMapper.java b/src/main/java/com/example/copykamanotes/mapper/CollectionNoteMapper.java new file mode 100644 index 0000000..7815974 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/mapper/CollectionNoteMapper.java @@ -0,0 +1,61 @@ +package com.example.copykamanotes.mapper; + +import com.example.copykamanotes.model.entity.CollectionNote; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Set; + +@Mapper +public interface CollectionNoteMapper { + /** + * 查询用户收藏的笔记 ID 列表 + * + * @param userId 用户 ID + * @param noteIds 笔记 ID 列表 + * @return 用户收藏的笔记 ID 列表 + */ + List findUserCollectedNoteIds( + @Param("userId") Long userId, + @Param("noteIds") List noteIds + ); + + /** + * 筛选出所给的收藏夹 ID 列表中,收藏了 noteId 对应的 note 的记录 + * + * @param noteId 笔记 ID + * @param collectionIds 收藏夹 ID 列表 + * @return 筛选结果 + */ + Set filterCollectionIdsByNoteId( + @Param("noteId") Integer noteId, + @Param("collectionIds") List collectionIds); + + /** + * 插入记录 + * + * @param collectionNote 收藏笔记记录 + * @return 插入记录数 + */ + int insert(CollectionNote collectionNote); + + /** + * 根据 collectionId 删除记录 + * + * @param collectionId 收藏夹 ID + * @return 删除记录数 + */ + int deleteByCollectionId(@Param("collectionId") Integer collectionId); + + /** + * 根据 collectionId 和 noteId 删除记录 + * + * @param collectionId 收藏夹 ID + * @param noteId 笔记 ID + * @return 删除记录数 + */ + int deleteByCollectionIdAndNoteId( + @Param("collectionId") Integer collectionId, + @Param("noteId") Integer noteId); +} \ No newline at end of file diff --git a/src/main/java/com/example/copykamanotes/mapper/CommentLikeMapper.java b/src/main/java/com/example/copykamanotes/mapper/CommentLikeMapper.java new file mode 100644 index 0000000..22ce5bc --- /dev/null +++ b/src/main/java/com/example/copykamanotes/mapper/CommentLikeMapper.java @@ -0,0 +1,44 @@ +package com.example.copykamanotes.mapper; + +import com.example.copykamanotes.model.entity.CommentLike; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; +import java.util.Set; + +/** + * 评论点赞Mapper接口 + */ +@Mapper +public interface CommentLikeMapper { + /** + * 插入评论点赞 + * + * @param commentLike 评论点赞实体 + */ + void insert(CommentLike commentLike); + + /** + * 删除评论点赞 + * + * @param commentId 评论ID + * @param userId 用户ID + */ + void delete(@Param("commentId") Integer commentId, @Param("userId") Long userId); + + /** + * 查询用户点赞的评论ID列表 + * + * @param userId 用户ID + * @param commentIds 评论ID列表 + * @return 用户点赞的评论ID集合 + */ + Set findUserLikedCommentIds(@Param("userId") Long userId, + @Param("commentIds") List commentIds); + + @Select("SELECT COUNT(*) > 0 FROM comment_like " + + "WHERE user_id = #{userId} AND comment_id = #{commentId}") + Boolean checkIsLiked(@Param("userId") Long userId, @Param("commentId") Integer commentId); +} diff --git a/src/main/java/com/example/copykamanotes/mapper/CommentMapper.java b/src/main/java/com/example/copykamanotes/mapper/CommentMapper.java new file mode 100644 index 0000000..56f5b61 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/mapper/CommentMapper.java @@ -0,0 +1,91 @@ +package com.example.copykamanotes.mapper; + +import com.example.copykamanotes.model.dto.comment.CommentQueryParams; +import com.example.copykamanotes.model.entity.Comment; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 评论Mapper接口 + */ +@Mapper +public interface CommentMapper { + /** + * 插入评论 + * + * @param comment 评论实体 + */ + void insert(Comment comment); + + /** + * 更新评论 + * + * @param comment 评论实体 + */ + void update(Comment comment); + + /** + * 删除评论 + * + * @param commentId 评论ID + */ + void deleteById(Integer commentId); + + /** + * 根据ID查询评论 + * + * @param commentId 评论ID + * @return 评论实体 + */ + Comment findById(Integer commentId); + + /** + * 查询评论列表 + * + * @param params 查询参数 + * @param pageSize 每页大小 + * @param offset 偏移量 + * @return 评论列表 + */ + List findByQueryParam(@Param("params") CommentQueryParams params, + @Param("pageSize") Integer pageSize, + @Param("offset") Integer offset); + + /** + * 统计评论数量 + * + * @param params 查询参数 + * @return 评论数量 + */ + int countByQueryParam(@Param("params") CommentQueryParams params); + + /** + * 增加评论点赞数 + * + * @param commentId 评论ID + */ + void incrementLikeCount(Integer commentId); + + /** + * 减少评论点赞数 + * + * @param commentId 评论ID + */ + void decrementLikeCount(Integer commentId); + + /** + * 增加评论回复数 + * + * @param commentId 评论ID + */ + void incrementReplyCount(Integer commentId); + + /** + * 减少评论回复数 + * + * @param commentId 评论ID + */ + void decrementReplyCount(Integer commentId); +} diff --git a/src/main/java/com/example/copykamanotes/mapper/NoteCollectMapper.java b/src/main/java/com/example/copykamanotes/mapper/NoteCollectMapper.java new file mode 100644 index 0000000..8fc8fa0 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/mapper/NoteCollectMapper.java @@ -0,0 +1,47 @@ +package com.example.copykamanotes.mapper; + +import com.example.copykamanotes.model.entity.NoteCollect; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 笔记收藏Mapper接口 + */ +@Mapper +public interface NoteCollectMapper { + /** + * 插入收藏记录 + * + * @param noteCollect 收藏记录 + * @return 影响的行数 + */ + int insert(NoteCollect noteCollect); + + /** + * 删除收藏记录 + * + * @param noteId 笔记ID + * @param userId 用户ID + * @return 影响的行数 + */ + int delete(@Param("noteId") Integer noteId, @Param("userId") Long userId); + + /** + * 查找收藏记录 + * + * @param noteId 笔记ID + * @param userId 用户ID + * @return 收藏记录 + */ + NoteCollect findByNoteIdAndUserId(@Param("noteId") Integer noteId, @Param("userId") Long userId); + + /** + * 获取用户收藏的笔记ID列表 + * + * @param userId 用户ID + * @return 笔记ID列表 + */ + List findNoteIdsByUserId(@Param("userId") Long userId); +} diff --git a/src/main/java/com/example/copykamanotes/mapper/NoteCommentMapper.java b/src/main/java/com/example/copykamanotes/mapper/NoteCommentMapper.java new file mode 100644 index 0000000..9757f4e --- /dev/null +++ b/src/main/java/com/example/copykamanotes/mapper/NoteCommentMapper.java @@ -0,0 +1,31 @@ +package com.example.copykamanotes.mapper; + +import com.example.copykamanotes.model.entity.NoteComment; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface NoteCommentMapper { + + /** + * 插入评论 + */ + void insert(NoteComment comment); + + /** + * 更新评论 + */ + void update(NoteComment comment); + + /** + * 根据ID查询评论 + */ + NoteComment findById(@Param("id") Integer id); + + /** + * 查询笔记的评论列表 + */ + List findByNoteId(@Param("noteId") Integer noteId); +} diff --git a/src/main/java/com/example/copykamanotes/mapper/QuestionListItemMapper.java b/src/main/java/com/example/copykamanotes/mapper/QuestionListItemMapper.java new file mode 100644 index 0000000..e020575 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/mapper/QuestionListItemMapper.java @@ -0,0 +1,79 @@ +package com.example.copykamanotes.mapper; + +import com.example.copykamanotes.model.entity.QuestionListItem; +import com.example.copykamanotes.model.vo.questionListItem.QuestionListItemVO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface QuestionListItemMapper { + /** + * 插入一个题单项 + * + * @param questionListItem 题单项对象,包含需要插入的题单项的信息 + * @return 影响的行数,表示插入操作是否成功 + */ + int insert(QuestionListItem questionListItem); + + /** + * 根据题单ID查找题单项 + * + * @param questionListId 题单的唯一标识符 + * @return 返回一个包含题单项的列表如果找不到对应的项,则返回空列表 + */ + List findByQuestionListId(@Param("questionListId") Integer questionListId); + + /** + * 根据题单ID查找题单项的数量 + * + * @param questionListId 题单的ID,用于标识要查找的题单项数量 + * @return 返回题单项的数量 + */ + int countByQuestionListId(@Param("questionListId") Integer questionListId); + + /** + * 根据题单ID查找题单项(分页) + * + * @param questionListId 题单的ID,用于标识要查找的题单项 + * @param limit 每页显示的记录数 + * @param offset 从第几条记录开始查询 + */ + List findByQuestionListIdPage(@Param("questionListId") Integer questionListId, + @Param("limit") Integer limit, + @Param("offset") Integer offset); + + /** + * 根据题单ID删除题单项 + * + * @param questionListId 题单的ID,用于标识要删除的题单项 + * @return 影响的行数,表示删除操作是否成功 + */ + int deleteByQuestionListId(Integer questionListId); + + /** + * 根据题单ID和题目ID删除题单项 + * + * @param questionListId 题单的ID,用于标识要删除的题单项 + * @param questionId 题目的ID,用于标识要删除的题单项 + * @return 影响的行数,表示删除操作是否成功 + */ + int deleteByQuestionListIdAndQuestionId(@Param("questionListId") Integer questionListId, @Param("questionId") Integer questionId); + + /** + * 根据题单ID获取下一个序号 + * + * @param questionListId 题单的ID + * @return 返回下一个序号 + */ + int nextRank(Integer questionListId); + + /** + * 更新题单项的序号 + * + * @param questionListItem 新顺序的题单项 + * @return 影响的行数,表示更新操作是否成功 + */ + int updateQuestionRank(QuestionListItem questionListItem); +} diff --git a/src/main/java/com/example/copykamanotes/mapper/StatisticMapper.java b/src/main/java/com/example/copykamanotes/mapper/StatisticMapper.java new file mode 100644 index 0000000..cb4f5ac --- /dev/null +++ b/src/main/java/com/example/copykamanotes/mapper/StatisticMapper.java @@ -0,0 +1,31 @@ +package com.example.copykamanotes.mapper; + +import com.example.copykamanotes.model.entity.Statistic; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface StatisticMapper { + /** + * 添加统计数据 + * @param statistic 统计数据 + * @return 添加的记录数 + */ + int insert(Statistic statistic); + + /** + * 获取统计数据的 total + * @return total + */ + int countStatistic(); + + /** + * 查询统计数据 + * @param limit 限制 + * @param offset 偏移 + * @return 统计数据 + */ + List findByPage(@Param("limit") Integer limit, @Param("offset") Integer offset); +} diff --git a/src/main/java/com/example/copykamanotes/model/dto/comment/CommentQueryParams.java b/src/main/java/com/example/copykamanotes/model/dto/comment/CommentQueryParams.java new file mode 100644 index 0000000..39f29d1 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/model/dto/comment/CommentQueryParams.java @@ -0,0 +1,42 @@ +package com.example.copykamanotes.model.dto.comment; + +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +/** + * 评论查询参数 + */ +@Data +public class CommentQueryParams { + /** + * 笔记ID + */ + @NotNull(message = "笔记ID不能为空") + private Integer noteId; + + /** + * 父评论ID + */ + private Integer parentId; + + /** + * 作者ID + */ + private Long authorId; + + /** + * 页码 + */ + @NotNull(message = "页码不能为空") + @Min(value = 1, message = "页码必须大于0") + private Integer page; + + /** + * 每页大小 + */ + @NotNull(message = "每页大小不能为空") + @Min(value = 1, message = "每页大小必须大于0") + private Integer pageSize; +} diff --git a/src/main/java/com/example/copykamanotes/model/vo/question/BaseQuestionVO.java b/src/main/java/com/example/copykamanotes/model/vo/question/BaseQuestionVO.java new file mode 100644 index 0000000..1de6446 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/model/vo/question/BaseQuestionVO.java @@ -0,0 +1,38 @@ +package com.example.copykamanotes.model.vo.question; + +import lombok.Data; + +@Data +public class BaseQuestionVO { + /* + * 问题ID(主键) + */ + private Integer questionId; + + /* + * 问题所属分类ID + */ + private Integer categoryId; + + /* + * 问题标题 + */ + private String title; + + /* + * 问题难度 + * 1=简单,2=中等,3=困难 + */ + private Integer difficulty; + + /* + * 题目考点 + */ + private String examPoint; + + /* + * 浏览量 + */ + private Integer viewCount; +} + diff --git a/src/main/java/com/example/copykamanotes/model/vo/questionListItem/QuestionListItemVO.java b/src/main/java/com/example/copykamanotes/model/vo/questionListItem/QuestionListItemVO.java new file mode 100644 index 0000000..ff92099 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/model/vo/questionListItem/QuestionListItemVO.java @@ -0,0 +1,23 @@ +package com.example.copykamanotes.model.vo.questionListItem; + +import com.example.copykamanotes.model.vo.question.BaseQuestionVO; +import lombok.Data; + +@Data +public class QuestionListItemVO { + /* + * 题单ID(联合主键) + */ + private Integer questionListId; + + /* + * 题目ID(联合主键) + */ + private BaseQuestionVO question; + + /* + * 题单内题目的顺序,从1开始 + */ + private Integer rank; +} +