From 5f8719721cf4a702c0d3fbf4383bdaade08b0633 Mon Sep 17 00:00:00 2001 From: 2991692032 Date: Mon, 5 May 2025 00:20:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB=E7=AE=A1=E7=90=86,=E8=AF=84?= =?UTF-8?q?=E8=AE=BA,=E8=B5=84=E6=BA=90,=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CategoryController.java | 84 +++++ .../unilife/controller/CommentController.java | 62 ++++ .../unilife/controller/CourseController.java | 104 ++++++ .../controller/ResourceController.java | 127 +++++++ .../controller/ScheduleController.java | 116 ++++++ .../com/unilife/mapper/CategoryMapper.java | 52 +++ .../com/unilife/mapper/CommentMapper.java | 71 ++++ .../java/com/unilife/mapper/CourseMapper.java | 69 ++++ .../com/unilife/mapper/PostLikeMapper.java | 46 +++ .../com/unilife/mapper/ResourceMapper.java | 92 +++++ .../com/unilife/mapper/ScheduleMapper.java | 83 +++++ .../unilife/model/dto/CreateCommentDTO.java | 29 ++ .../unilife/model/dto/CreateCourseDTO.java | 60 ++++ .../unilife/model/dto/CreateResourceDTO.java | 34 ++ .../unilife/model/dto/CreateScheduleDTO.java | 55 +++ .../java/com/unilife/model/entity/Course.java | 92 +++++ .../com/unilife/model/entity/Resource.java | 86 +++++ .../com/unilife/model/entity/Schedule.java | 86 +++++ .../java/com/unilife/model/vo/CommentVO.java | 73 ++++ .../java/com/unilife/model/vo/CourseVO.java | 88 +++++ .../java/com/unilife/model/vo/ResourceVO.java | 97 +++++ .../java/com/unilife/model/vo/ScheduleVO.java | 82 +++++ .../com/unilife/service/CategoryService.java | 45 +++ .../com/unilife/service/CommentService.java | 41 +++ .../com/unilife/service/CourseService.java | 68 ++++ .../com/unilife/service/ResourceService.java | 80 +++++ .../com/unilife/service/ScheduleService.java | 77 ++++ .../service/impl/CategoryServiceImpl.java | 96 +++++ .../service/impl/CommentServiceImpl.java | 189 ++++++++++ .../service/impl/CourseServiceImpl.java | 192 ++++++++++ .../unilife/service/impl/PostServiceImpl.java | 21 +- .../service/impl/ResourceServiceImpl.java | 339 ++++++++++++++++++ .../service/impl/ScheduleServiceImpl.java | 262 ++++++++++++++ .../main/resources/mappers/CategoryMapper.xml | 67 ++++ .../main/resources/mappers/CommentMapper.xml | 75 ++++ .../main/resources/mappers/CourseMapper.xml | 89 +++++ .../main/resources/mappers/PostLikeMapper.xml | 36 ++ .../main/resources/mappers/ResourceMapper.xml | 119 ++++++ .../main/resources/mappers/ScheduleMapper.xml | 102 ++++++ 39 files changed, 3576 insertions(+), 10 deletions(-) create mode 100644 unilife-server/src/main/java/com/unilife/controller/CategoryController.java create mode 100644 unilife-server/src/main/java/com/unilife/controller/CommentController.java create mode 100644 unilife-server/src/main/java/com/unilife/controller/CourseController.java create mode 100644 unilife-server/src/main/java/com/unilife/controller/ResourceController.java create mode 100644 unilife-server/src/main/java/com/unilife/controller/ScheduleController.java create mode 100644 unilife-server/src/main/java/com/unilife/mapper/CategoryMapper.java create mode 100644 unilife-server/src/main/java/com/unilife/mapper/CommentMapper.java create mode 100644 unilife-server/src/main/java/com/unilife/mapper/CourseMapper.java create mode 100644 unilife-server/src/main/java/com/unilife/mapper/PostLikeMapper.java create mode 100644 unilife-server/src/main/java/com/unilife/mapper/ResourceMapper.java create mode 100644 unilife-server/src/main/java/com/unilife/mapper/ScheduleMapper.java create mode 100644 unilife-server/src/main/java/com/unilife/model/dto/CreateCommentDTO.java create mode 100644 unilife-server/src/main/java/com/unilife/model/dto/CreateCourseDTO.java create mode 100644 unilife-server/src/main/java/com/unilife/model/dto/CreateResourceDTO.java create mode 100644 unilife-server/src/main/java/com/unilife/model/dto/CreateScheduleDTO.java create mode 100644 unilife-server/src/main/java/com/unilife/model/entity/Course.java create mode 100644 unilife-server/src/main/java/com/unilife/model/entity/Resource.java create mode 100644 unilife-server/src/main/java/com/unilife/model/entity/Schedule.java create mode 100644 unilife-server/src/main/java/com/unilife/model/vo/CommentVO.java create mode 100644 unilife-server/src/main/java/com/unilife/model/vo/CourseVO.java create mode 100644 unilife-server/src/main/java/com/unilife/model/vo/ResourceVO.java create mode 100644 unilife-server/src/main/java/com/unilife/model/vo/ScheduleVO.java create mode 100644 unilife-server/src/main/java/com/unilife/service/CategoryService.java create mode 100644 unilife-server/src/main/java/com/unilife/service/CommentService.java create mode 100644 unilife-server/src/main/java/com/unilife/service/CourseService.java create mode 100644 unilife-server/src/main/java/com/unilife/service/ResourceService.java create mode 100644 unilife-server/src/main/java/com/unilife/service/ScheduleService.java create mode 100644 unilife-server/src/main/java/com/unilife/service/impl/CategoryServiceImpl.java create mode 100644 unilife-server/src/main/java/com/unilife/service/impl/CommentServiceImpl.java create mode 100644 unilife-server/src/main/java/com/unilife/service/impl/CourseServiceImpl.java create mode 100644 unilife-server/src/main/java/com/unilife/service/impl/ResourceServiceImpl.java create mode 100644 unilife-server/src/main/java/com/unilife/service/impl/ScheduleServiceImpl.java create mode 100644 unilife-server/src/main/resources/mappers/CategoryMapper.xml create mode 100644 unilife-server/src/main/resources/mappers/CommentMapper.xml create mode 100644 unilife-server/src/main/resources/mappers/CourseMapper.xml create mode 100644 unilife-server/src/main/resources/mappers/PostLikeMapper.xml create mode 100644 unilife-server/src/main/resources/mappers/ResourceMapper.xml create mode 100644 unilife-server/src/main/resources/mappers/ScheduleMapper.xml diff --git a/unilife-server/src/main/java/com/unilife/controller/CategoryController.java b/unilife-server/src/main/java/com/unilife/controller/CategoryController.java new file mode 100644 index 0000000..2216171 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/controller/CategoryController.java @@ -0,0 +1,84 @@ +package com.unilife.controller; + +import com.unilife.common.result.Result; +import com.unilife.model.entity.Category; +import com.unilife.service.CategoryService; +import com.unilife.utils.BaseContext; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@Tag(name = "分类管理") +@RestController +@RequestMapping("/categories") +@Slf4j +public class CategoryController { + + @Autowired + private CategoryService categoryService; + + @Operation(summary = "获取分类详情") + @GetMapping("/{id}") + public Result getCategoryDetail(@PathVariable("id") Long categoryId) { + return categoryService.getCategoryDetail(categoryId); + } + + @Operation(summary = "获取分类列表") + @GetMapping + public Result getCategoryList( + @RequestParam(value = "status", required = false) Byte status) { + return categoryService.getCategoryList(status); + } + + @Operation(summary = "创建分类") + @PostMapping + public Result createCategory(@RequestBody Category category) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + + // 检查用户权限(只有管理员可以创建分类) + // 实际项目中应该从用户服务获取用户角色信息 + // 这里简化处理,假设已经检查了权限 + + return categoryService.createCategory(category); + } + + @Operation(summary = "更新分类") + @PutMapping("/{id}") + public Result updateCategory( + @PathVariable("id") Long categoryId, + @RequestBody Category category) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + + // 检查用户权限(只有管理员可以更新分类) + // 实际项目中应该从用户服务获取用户角色信息 + // 这里简化处理,假设已经检查了权限 + + return categoryService.updateCategory(categoryId, category); + } + + @Operation(summary = "删除分类") + @DeleteMapping("/{id}") + public Result deleteCategory(@PathVariable("id") Long categoryId) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + + // 检查用户权限(只有管理员可以删除分类) + // 实际项目中应该从用户服务获取用户角色信息 + // 这里简化处理,假设已经检查了权限 + + return categoryService.deleteCategory(categoryId); + } +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/controller/CommentController.java b/unilife-server/src/main/java/com/unilife/controller/CommentController.java new file mode 100644 index 0000000..b647cbb --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/controller/CommentController.java @@ -0,0 +1,62 @@ +package com.unilife.controller; + +import com.unilife.common.result.Result; +import com.unilife.model.dto.CreateCommentDTO; +import com.unilife.service.CommentService; +import com.unilife.utils.BaseContext; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@Tag(name = "评论管理") +@RestController +@RequestMapping("/comments") +@Slf4j +public class CommentController { + + @Autowired + private CommentService commentService; + + @Operation(summary = "创建评论") + @PostMapping + public Result createComment(@RequestBody CreateCommentDTO createCommentDTO) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return commentService.createComment(userId, createCommentDTO); + } + + @Operation(summary = "获取帖子评论列表") + @GetMapping("/post/{postId}") + public Result getCommentsByPostId(@PathVariable("postId") Long postId) { + // 从当前上下文获取用户ID,可能为null(未登录用户) + Long userId = BaseContext.getId(); + return commentService.getCommentsByPostId(postId, userId); + } + + @Operation(summary = "删除评论") + @DeleteMapping("/{id}") + public Result deleteComment(@PathVariable("id") Long commentId) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return commentService.deleteComment(commentId, userId); + } + + @Operation(summary = "点赞/取消点赞评论") + @PostMapping("/{id}/like") + public Result likeComment(@PathVariable("id") Long commentId) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return commentService.likeComment(commentId, userId); + } +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/controller/CourseController.java b/unilife-server/src/main/java/com/unilife/controller/CourseController.java new file mode 100644 index 0000000..92f807a --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/controller/CourseController.java @@ -0,0 +1,104 @@ +package com.unilife.controller; + +import com.unilife.common.result.Result; +import com.unilife.model.dto.CreateCourseDTO; +import com.unilife.service.CourseService; +import com.unilife.utils.BaseContext; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@Tag(name = "课程管理") +@RestController +@RequestMapping("/courses") +@Slf4j +public class CourseController { + + @Autowired + private CourseService courseService; + + @Operation(summary = "创建课程") + @PostMapping + public Result createCourse(@RequestBody CreateCourseDTO createCourseDTO) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return courseService.createCourse(userId, createCourseDTO); + } + + @Operation(summary = "获取课程详情") + @GetMapping("/{id}") + public Result getCourseDetail(@PathVariable("id") Long courseId) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return courseService.getCourseDetail(courseId, userId); + } + + @Operation(summary = "获取用户的所有课程") + @GetMapping + public Result getCourseList() { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return courseService.getCourseList(userId); + } + + @Operation(summary = "获取用户在指定星期几的课程") + @GetMapping("/day/{dayOfWeek}") + public Result getCourseListByDayOfWeek(@PathVariable("dayOfWeek") Byte dayOfWeek) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return courseService.getCourseListByDayOfWeek(userId, dayOfWeek); + } + + @Operation(summary = "更新课程") + @PutMapping("/{id}") + public Result updateCourse( + @PathVariable("id") Long courseId, + @RequestBody CreateCourseDTO createCourseDTO) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return courseService.updateCourse(courseId, userId, createCourseDTO); + } + + @Operation(summary = "删除课程") + @DeleteMapping("/{id}") + public Result deleteCourse(@PathVariable("id") Long courseId) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return courseService.deleteCourse(courseId, userId); + } + + @Operation(summary = "检查课程时间冲突") + @GetMapping("/check-conflict") + public Result checkCourseConflict( + @RequestParam("dayOfWeek") Byte dayOfWeek, + @RequestParam("startTime") String startTime, + @RequestParam("endTime") String endTime, + @RequestParam(value = "excludeCourseId", required = false) Long excludeCourseId) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return courseService.checkCourseConflict(userId, dayOfWeek, startTime, endTime, excludeCourseId); + } +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/controller/ResourceController.java b/unilife-server/src/main/java/com/unilife/controller/ResourceController.java new file mode 100644 index 0000000..e09e95c --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/controller/ResourceController.java @@ -0,0 +1,127 @@ +package com.unilife.controller; + +import com.unilife.common.result.Result; +import com.unilife.model.dto.CreateResourceDTO; +import com.unilife.service.ResourceService; +import com.unilife.utils.BaseContext; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +@Tag(name = "资源管理") +@RestController +@RequestMapping("/resources") +@Slf4j +public class ResourceController { + + @Autowired + private ResourceService resourceService; + + @Operation(summary = "上传资源") + @PostMapping + public Result uploadResource(@RequestParam("file") MultipartFile file, + @RequestParam("title") String title, + @RequestParam("description") String description, + @RequestParam("categoryId") Long categoryId) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + + // 创建DTO + CreateResourceDTO createResourceDTO = new CreateResourceDTO(); + createResourceDTO.setTitle(title); + createResourceDTO.setDescription(description); + createResourceDTO.setCategoryId(categoryId); + + return resourceService.uploadResource(userId, createResourceDTO, file); + } + + @Operation(summary = "获取资源详情") + @GetMapping("/{id}") + public Result getResourceDetail(@PathVariable("id") Long resourceId) { + // 从当前上下文获取用户ID,可能为null(未登录用户) + Long userId = BaseContext.getId(); + return resourceService.getResourceDetail(resourceId, userId); + } + + @Operation(summary = "获取资源列表") + @GetMapping + public Result getResourceList( + @RequestParam(value = "category", required = false) Long categoryId, + @RequestParam(value = "user", required = false) Long userId, + @RequestParam(value = "keyword", required = false) String keyword, + @RequestParam(value = "page", defaultValue = "1") Integer page, + @RequestParam(value = "size", defaultValue = "10") Integer size) { + return resourceService.getResourceList(categoryId, userId, keyword, page, size); + } + + @Operation(summary = "更新资源") + @PutMapping("/{id}") + public Result updateResource( + @PathVariable("id") Long resourceId, + @RequestBody CreateResourceDTO createResourceDTO) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return resourceService.updateResource(resourceId, userId, createResourceDTO); + } + + @Operation(summary = "删除资源") + @DeleteMapping("/{id}") + public Result deleteResource(@PathVariable("id") Long resourceId) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return resourceService.deleteResource(resourceId, userId); + } + + @Operation(summary = "下载资源") + @GetMapping("/{id}/download") + public Result downloadResource(@PathVariable("id") Long resourceId) { + // 从当前上下文获取用户ID,可能为null(未登录用户) + Long userId = BaseContext.getId(); + return resourceService.downloadResource(resourceId, userId); + } + + @Operation(summary = "点赞/取消点赞资源") + @PostMapping("/{id}/like") + public Result likeResource(@PathVariable("id") Long resourceId) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return resourceService.likeResource(resourceId, userId); + } + + @Operation(summary = "获取用户上传的资源列表") + @GetMapping("/user/{userId}") + public Result getUserResources( + @PathVariable("userId") Long targetUserId, + @RequestParam(value = "page", defaultValue = "1") Integer page, + @RequestParam(value = "size", defaultValue = "10") Integer size) { + return resourceService.getUserResources(targetUserId, page, size); + } + + @Operation(summary = "获取当前用户上传的资源列表") + @GetMapping("/my") + public Result getMyResources( + @RequestParam(value = "page", defaultValue = "1") Integer page, + @RequestParam(value = "size", defaultValue = "10") Integer size) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return resourceService.getUserResources(userId, page, size); + } +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/controller/ScheduleController.java b/unilife-server/src/main/java/com/unilife/controller/ScheduleController.java new file mode 100644 index 0000000..e813fd0 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/controller/ScheduleController.java @@ -0,0 +1,116 @@ +package com.unilife.controller; + +import com.unilife.common.result.Result; +import com.unilife.model.dto.CreateScheduleDTO; +import com.unilife.service.ScheduleService; +import com.unilife.utils.BaseContext; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.web.bind.annotation.*; + +import java.time.LocalDateTime; + +@Tag(name = "日程管理") +@RestController +@RequestMapping("/schedules") +@Slf4j +public class ScheduleController { + + @Autowired + private ScheduleService scheduleService; + + @Operation(summary = "创建日程") + @PostMapping + public Result createSchedule(@RequestBody CreateScheduleDTO createScheduleDTO) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return scheduleService.createSchedule(userId, createScheduleDTO); + } + + @Operation(summary = "获取日程详情") + @GetMapping("/{id}") + public Result getScheduleDetail(@PathVariable("id") Long scheduleId) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return scheduleService.getScheduleDetail(scheduleId, userId); + } + + @Operation(summary = "获取用户的所有日程") + @GetMapping + public Result getScheduleList() { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return scheduleService.getScheduleList(userId); + } + + @Operation(summary = "获取用户在指定时间范围内的日程") + @GetMapping("/range") + public Result getScheduleListByTimeRange( + @RequestParam("startTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime startTime, + @RequestParam("endTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endTime) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return scheduleService.getScheduleListByTimeRange(userId, startTime, endTime); + } + + @Operation(summary = "更新日程") + @PutMapping("/{id}") + public Result updateSchedule( + @PathVariable("id") Long scheduleId, + @RequestBody CreateScheduleDTO createScheduleDTO) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return scheduleService.updateSchedule(scheduleId, userId, createScheduleDTO); + } + + @Operation(summary = "删除日程") + @DeleteMapping("/{id}") + public Result deleteSchedule(@PathVariable("id") Long scheduleId) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return scheduleService.deleteSchedule(scheduleId, userId); + } + + @Operation(summary = "检查日程时间冲突") + @GetMapping("/check-conflict") + public Result checkScheduleConflict( + @RequestParam("startTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime startTime, + @RequestParam("endTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endTime, + @RequestParam(value = "excludeScheduleId", required = false) Long excludeScheduleId) { + // 从当前上下文获取用户ID + Long userId = BaseContext.getId(); + if (userId == null) { + return Result.error(401, "未登录"); + } + return scheduleService.checkScheduleConflict(userId, startTime, endTime, excludeScheduleId); + } + + @Operation(summary = "处理日程提醒") + @PostMapping("/process-reminders") + public Result processScheduleReminders() { + // 此接口通常由系统定时任务调用,不需要用户认证 + // 实际项目中应该添加适当的安全措施,如API密钥验证 + return scheduleService.processScheduleReminders(); + } +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/mapper/CategoryMapper.java b/unilife-server/src/main/java/com/unilife/mapper/CategoryMapper.java new file mode 100644 index 0000000..68fa6ae --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/mapper/CategoryMapper.java @@ -0,0 +1,52 @@ +package com.unilife.mapper; + +import com.unilife.model.entity.Category; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 分类数据访问层 + */ +@Mapper +public interface CategoryMapper { + /** + * 根据ID获取分类 + * @param id 分类ID + * @return 分类实体 + */ + Category getById(Long id); + + /** + * 获取所有分类 + * @param status 状态(可为null,表示获取所有状态) + * @return 分类列表 + */ + List getList(@Param("status") Byte status); + + /** + * 插入分类 + * @param category 分类实体 + */ + void insert(Category category); + + /** + * 更新分类 + * @param category 分类实体 + */ + void update(Category category); + + /** + * 删除分类(逻辑删除) + * @param id 分类ID + */ + void delete(Long id); + + /** + * 获取分类总数 + * @param status 状态(可为null) + * @return 分类总数 + */ + Integer getCount(@Param("status") Byte status); +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/mapper/CommentMapper.java b/unilife-server/src/main/java/com/unilife/mapper/CommentMapper.java new file mode 100644 index 0000000..3021fec --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/mapper/CommentMapper.java @@ -0,0 +1,71 @@ +package com.unilife.mapper; + +import com.unilife.model.entity.Comment; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 评论数据访问层 + */ +@Mapper +public interface CommentMapper { + /** + * 插入评论 + * @param comment 评论实体 + */ + void insert(Comment comment); + + /** + * 根据ID获取评论 + * @param id 评论ID + * @return 评论实体 + */ + Comment getById(Long id); + + /** + * 获取帖子的一级评论列表(不包含回复) + * @param postId 帖子ID + * @return 评论列表 + */ + List getTopLevelCommentsByPostId(@Param("postId") Long postId); + + /** + * 获取评论的回复列表 + * @param parentId 父评论ID + * @return 回复列表 + */ + List getRepliesByParentId(@Param("parentId") Long parentId); + + /** + * 获取帖子的评论总数 + * @param postId 帖子ID + * @return 评论总数 + */ + Integer getCountByPostId(@Param("postId") Long postId); + + /** + * 更新评论 + * @param comment 评论实体 + */ + void update(Comment comment); + + /** + * 删除评论(逻辑删除) + * @param id 评论ID + */ + void delete(Long id); + + /** + * 增加点赞次数 + * @param id 评论ID + */ + void incrementLikeCount(Long id); + + /** + * 减少点赞次数 + * @param id 评论ID + */ + void decrementLikeCount(Long id); +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/mapper/CourseMapper.java b/unilife-server/src/main/java/com/unilife/mapper/CourseMapper.java new file mode 100644 index 0000000..2ef6aab --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/mapper/CourseMapper.java @@ -0,0 +1,69 @@ +package com.unilife.mapper; + +import com.unilife.model.entity.Course; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 课程数据访问层 + */ +@Mapper +public interface CourseMapper { + /** + * 插入课程 + * @param course 课程实体 + */ + void insert(Course course); + + /** + * 根据ID获取课程 + * @param id 课程ID + * @return 课程实体 + */ + Course getById(Long id); + + /** + * 获取用户的所有课程 + * @param userId 用户ID + * @return 课程列表 + */ + List getListByUserId(Long userId); + + /** + * 更新课程 + * @param course 课程实体 + */ + void update(Course course); + + /** + * 删除课程(逻辑删除) + * @param id 课程ID + * @param userId 用户ID(确保只能删除自己的课程) + */ + void delete(@Param("id") Long id, @Param("userId") Long userId); + + /** + * 获取用户在指定星期几的课程 + * @param userId 用户ID + * @param dayOfWeek 星期几(1-7) + * @return 课程列表 + */ + List getListByUserIdAndDayOfWeek(@Param("userId") Long userId, @Param("dayOfWeek") Byte dayOfWeek); + + /** + * 检查用户在指定时间段是否有课程冲突 + * @param userId 用户ID + * @param dayOfWeek 星期几(1-7) + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param excludeCourseId 排除的课程ID(用于更新时排除自身) + * @return 冲突的课程数量 + */ + Integer checkConflict(@Param("userId") Long userId, + @Param("dayOfWeek") Byte dayOfWeek, + @Param("startTime") String startTime, + @Param("endTime") String endTime, + @Param("excludeCourseId") Long excludeCourseId); +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/mapper/PostLikeMapper.java b/unilife-server/src/main/java/com/unilife/mapper/PostLikeMapper.java new file mode 100644 index 0000000..c42d5c5 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/mapper/PostLikeMapper.java @@ -0,0 +1,46 @@ +package com.unilife.mapper; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 帖子点赞数据访问层 + */ +@Mapper +public interface PostLikeMapper { + /** + * 检查用户是否已点赞帖子 + * @param postId 帖子ID + * @param userId 用户ID + * @return 是否已点赞 + */ + Boolean isLiked(@Param("postId") Long postId, @Param("userId") Long userId); + + /** + * 添加点赞记录 + * @param postId 帖子ID + * @param userId 用户ID + */ + void insert(@Param("postId") Long postId, @Param("userId") Long userId); + + /** + * 删除点赞记录 + * @param postId 帖子ID + * @param userId 用户ID + */ + void delete(@Param("postId") Long postId, @Param("userId") Long userId); + + /** + * 获取帖子点赞数 + * @param postId 帖子ID + * @return 点赞数 + */ + Integer getCountByPostId(@Param("postId") Long postId); + + /** + * 获取用户点赞的帖子ID列表 + * @param userId 用户ID + * @return 帖子ID列表 + */ + java.util.List getLikedPostIdsByUserId(@Param("userId") Long userId); +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/mapper/ResourceMapper.java b/unilife-server/src/main/java/com/unilife/mapper/ResourceMapper.java new file mode 100644 index 0000000..03acd97 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/mapper/ResourceMapper.java @@ -0,0 +1,92 @@ +package com.unilife.mapper; + +import com.unilife.model.entity.Resource; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 资源数据访问层 + */ +@Mapper +public interface ResourceMapper { + /** + * 插入资源 + * @param resource 资源实体 + */ + void insert(Resource resource); + + /** + * 根据ID获取资源 + * @param id 资源ID + * @return 资源实体 + */ + Resource getById(Long id); + + /** + * 获取资源列表 + * @param categoryId 分类ID,可为null + * @param userId 用户ID,可为null + * @param keyword 关键词,可为null + * @return 资源列表 + */ + List getList(@Param("categoryId") Long categoryId, + @Param("userId") Long userId, + @Param("keyword") String keyword); + + /** + * 获取资源总数 + * @param categoryId 分类ID,可为null + * @param userId 用户ID,可为null + * @param keyword 关键词,可为null + * @return 资源总数 + */ + Integer getCount(@Param("categoryId") Long categoryId, + @Param("userId") Long userId, + @Param("keyword") String keyword); + + /** + * 更新资源 + * @param resource 资源实体 + */ + void update(Resource resource); + + /** + * 删除资源(逻辑删除) + * @param id 资源ID + */ + void delete(Long id); + + /** + * 增加下载次数 + * @param id 资源ID + */ + void incrementDownloadCount(Long id); + + /** + * 增加点赞次数 + * @param id 资源ID + */ + void incrementLikeCount(Long id); + + /** + * 减少点赞次数 + * @param id 资源ID + */ + void decrementLikeCount(Long id); + + /** + * 获取用户上传的资源数量 + * @param userId 用户ID + * @return 资源数量 + */ + Integer getCountByUserId(Long userId); + + /** + * 获取分类下的资源数量 + * @param categoryId 分类ID + * @return 资源数量 + */ + Integer getCountByCategoryId(Long categoryId); +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/mapper/ScheduleMapper.java b/unilife-server/src/main/java/com/unilife/mapper/ScheduleMapper.java new file mode 100644 index 0000000..b37df7c --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/mapper/ScheduleMapper.java @@ -0,0 +1,83 @@ +package com.unilife.mapper; + +import com.unilife.model.entity.Schedule; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 日程数据访问层 + */ +@Mapper +public interface ScheduleMapper { + /** + * 插入日程 + * @param schedule 日程实体 + */ + void insert(Schedule schedule); + + /** + * 根据ID获取日程 + * @param id 日程ID + * @return 日程实体 + */ + Schedule getById(Long id); + + /** + * 获取用户的所有日程 + * @param userId 用户ID + * @return 日程列表 + */ + List getListByUserId(Long userId); + + /** + * 获取用户在指定时间范围内的日程 + * @param userId 用户ID + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return 日程列表 + */ + List getListByUserIdAndTimeRange( + @Param("userId") Long userId, + @Param("startTime") LocalDateTime startTime, + @Param("endTime") LocalDateTime endTime); + + /** + * 更新日程 + * @param schedule 日程实体 + */ + void update(Schedule schedule); + + /** + * 删除日程(逻辑删除) + * @param id 日程ID + * @param userId 用户ID(确保只能删除自己的日程) + */ + void delete(@Param("id") Long id, @Param("userId") Long userId); + + /** + * 检查用户在指定时间段是否有日程冲突 + * @param userId 用户ID + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param excludeScheduleId 排除的日程ID(用于更新时排除自身) + * @return 冲突的日程数量 + */ + Integer checkConflict( + @Param("userId") Long userId, + @Param("startTime") LocalDateTime startTime, + @Param("endTime") LocalDateTime endTime, + @Param("excludeScheduleId") Long excludeScheduleId); + + /** + * 获取需要提醒的日程 + * @param currentTime 当前时间 + * @param reminderMinutes 提醒时间(分钟) + * @return 需要提醒的日程列表 + */ + List getSchedulesToRemind( + @Param("currentTime") LocalDateTime currentTime, + @Param("reminderMinutes") Integer reminderMinutes); +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/model/dto/CreateCommentDTO.java b/unilife-server/src/main/java/com/unilife/model/dto/CreateCommentDTO.java new file mode 100644 index 0000000..bcf23fe --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/dto/CreateCommentDTO.java @@ -0,0 +1,29 @@ +package com.unilife.model.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 创建评论的数据传输对象 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CreateCommentDTO { + /** + * 帖子ID + */ + private Long postId; + + /** + * 评论内容 + */ + private String content; + + /** + * 父评论ID(回复某条评论) + * 如果是直接评论帖子,则为null + */ + private Long parentId; +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/model/dto/CreateCourseDTO.java b/unilife-server/src/main/java/com/unilife/model/dto/CreateCourseDTO.java new file mode 100644 index 0000000..65f8a33 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/dto/CreateCourseDTO.java @@ -0,0 +1,60 @@ +package com.unilife.model.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalTime; + +/** + * 创建课程的数据传输对象 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CreateCourseDTO { + /** + * 课程名称 + */ + private String name; + + /** + * 教师姓名 + */ + private String teacher; + + /** + * 上课地点 + */ + private String location; + + /** + * 星期几(1-7) + */ + private Byte dayOfWeek; + + /** + * 开始时间 + */ + private LocalTime startTime; + + /** + * 结束时间 + */ + private LocalTime endTime; + + /** + * 开始周次 + */ + private Byte startWeek; + + /** + * 结束周次 + */ + private Byte endWeek; + + /** + * 显示颜色 + */ + private String color; +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/model/dto/CreateResourceDTO.java b/unilife-server/src/main/java/com/unilife/model/dto/CreateResourceDTO.java new file mode 100644 index 0000000..8cb44a8 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/dto/CreateResourceDTO.java @@ -0,0 +1,34 @@ +package com.unilife.model.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 创建资源的数据传输对象 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CreateResourceDTO { + /** + * 资源标题 + */ + private String title; + + /** + * 资源描述 + */ + private String description; + + /** + * 分类ID + */ + private Long categoryId; + + /** + * 文件类型(由后端根据上传文件自动判断) + * 此字段在前端可选,后端会根据实际上传文件覆盖 + */ + private String fileType; +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/model/dto/CreateScheduleDTO.java b/unilife-server/src/main/java/com/unilife/model/dto/CreateScheduleDTO.java new file mode 100644 index 0000000..c0e96ca --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/dto/CreateScheduleDTO.java @@ -0,0 +1,55 @@ +package com.unilife.model.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +/** + * 创建日程的数据传输对象 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CreateScheduleDTO { + /** + * 日程标题 + */ + private String title; + + /** + * 日程描述 + */ + private String description; + + /** + * 开始时间 + */ + private LocalDateTime startTime; + + /** + * 结束时间 + */ + private LocalDateTime endTime; + + /** + * 地点 + */ + private String location; + + /** + * 是否全天(0-否, 1-是) + */ + private Byte isAllDay; + + /** + * 提醒时间(分钟) + */ + private Byte reminder; + + /** + * 显示颜色 + */ + private String color; +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/model/entity/Course.java b/unilife-server/src/main/java/com/unilife/model/entity/Course.java new file mode 100644 index 0000000..bd60138 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/entity/Course.java @@ -0,0 +1,92 @@ +package com.unilife.model.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.time.LocalTime; + +/** + * 课程实体类 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Course implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 课程ID + */ + private Long id; + + /** + * 用户ID + */ + private Long userId; + + /** + * 课程名称 + */ + private String name; + + /** + * 教师姓名 + */ + private String teacher; + + /** + * 上课地点 + */ + private String location; + + /** + * 星期几(1-7) + */ + private Byte dayOfWeek; + + /** + * 开始时间 + */ + private LocalTime startTime; + + /** + * 结束时间 + */ + private LocalTime endTime; + + /** + * 开始周次 + */ + private Byte startWeek; + + /** + * 结束周次 + */ + private Byte endWeek; + + /** + * 显示颜色 + */ + private String color; + + /** + * 状态(0-删除, 1-正常) + */ + private Byte status = 1; + + /** + * 创建时间 + */ + private LocalDateTime createdAt; + + /** + * 更新时间 + */ + private LocalDateTime updatedAt; +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/model/entity/Resource.java b/unilife-server/src/main/java/com/unilife/model/entity/Resource.java new file mode 100644 index 0000000..f0f141f --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/entity/Resource.java @@ -0,0 +1,86 @@ +package com.unilife.model.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * 资源实体类 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Resource implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 资源ID + */ + private Long id; + + /** + * 上传用户ID + */ + private Long userId; + + /** + * 资源标题 + */ + private String title; + + /** + * 资源描述 + */ + private String description; + + /** + * 文件URL + */ + private String fileUrl; + + /** + * 文件大小(字节) + */ + private Long fileSize; + + /** + * 文件类型 + */ + private String fileType; + + /** + * 分类ID + */ + private Long categoryId; + + /** + * 下载次数 + */ + private Integer downloadCount = 0; + + /** + * 点赞次数 + */ + private Integer likeCount = 0; + + /** + * 状态(0-删除, 1-正常) + */ + private Byte status = 1; + + /** + * 创建时间 + */ + private LocalDateTime createdAt; + + /** + * 更新时间 + */ + private LocalDateTime updatedAt; +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/model/entity/Schedule.java b/unilife-server/src/main/java/com/unilife/model/entity/Schedule.java new file mode 100644 index 0000000..5bea3f7 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/entity/Schedule.java @@ -0,0 +1,86 @@ +package com.unilife.model.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * 日程实体类 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Schedule implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 日程ID + */ + private Long id; + + /** + * 用户ID + */ + private Long userId; + + /** + * 日程标题 + */ + private String title; + + /** + * 日程描述 + */ + private String description; + + /** + * 开始时间 + */ + private LocalDateTime startTime; + + /** + * 结束时间 + */ + private LocalDateTime endTime; + + /** + * 地点 + */ + private String location; + + /** + * 是否全天(0-否, 1-是) + */ + private Byte isAllDay = 0; + + /** + * 提醒时间(分钟) + */ + private Byte reminder; + + /** + * 显示颜色 + */ + private String color; + + /** + * 状态(0-删除, 1-正常) + */ + private Byte status = 1; + + /** + * 创建时间 + */ + private LocalDateTime createdAt; + + /** + * 更新时间 + */ + private LocalDateTime updatedAt; +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/model/vo/CommentVO.java b/unilife-server/src/main/java/com/unilife/model/vo/CommentVO.java new file mode 100644 index 0000000..39f7ead --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/vo/CommentVO.java @@ -0,0 +1,73 @@ +package com.unilife.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 评论视图对象 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CommentVO { + /** + * 评论ID + */ + private Long id; + + /** + * 帖子ID + */ + private Long postId; + + /** + * 评论用户ID + */ + private Long userId; + + /** + * 评论用户昵称 + */ + private String nickname; + + /** + * 评论用户头像 + */ + private String avatar; + + /** + * 评论内容 + */ + private String content; + + /** + * 父评论ID(回复某条评论) + */ + private Long parentId; + + /** + * 点赞次数 + */ + private Integer likeCount; + + /** + * 当前用户是否点赞 + */ + private Boolean isLiked; + + /** + * 创建时间 + */ + private LocalDateTime createdAt; + + /** + * 回复列表 + */ + private List replies; +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/model/vo/CourseVO.java b/unilife-server/src/main/java/com/unilife/model/vo/CourseVO.java new file mode 100644 index 0000000..a55a813 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/vo/CourseVO.java @@ -0,0 +1,88 @@ +package com.unilife.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; +import java.time.LocalTime; + +/** + * 课程视图对象 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CourseVO { + /** + * 课程ID + */ + private Long id; + + /** + * 用户ID + */ + private Long userId; + + /** + * 课程名称 + */ + private String name; + + /** + * 教师姓名 + */ + private String teacher; + + /** + * 上课地点 + */ + private String location; + + /** + * 星期几(1-7) + */ + private Byte dayOfWeek; + + /** + * 开始时间 + */ + private LocalTime startTime; + + /** + * 结束时间 + */ + private LocalTime endTime; + + /** + * 开始周次 + */ + private Byte startWeek; + + /** + * 结束周次 + */ + private Byte endWeek; + + /** + * 显示颜色 + */ + private String color; + + /** + * 状态(0-删除, 1-正常) + */ + private Byte status; + + /** + * 创建时间 + */ + private LocalDateTime createdAt; + + /** + * 更新时间 + */ + private LocalDateTime updatedAt; +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/model/vo/ResourceVO.java b/unilife-server/src/main/java/com/unilife/model/vo/ResourceVO.java new file mode 100644 index 0000000..fe0268b --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/vo/ResourceVO.java @@ -0,0 +1,97 @@ +package com.unilife.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +/** + * 资源视图对象 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ResourceVO { + /** + * 资源ID + */ + private Long id; + + /** + * 资源标题 + */ + private String title; + + /** + * 资源描述 + */ + private String description; + + /** + * 文件URL + */ + private String fileUrl; + + /** + * 文件大小(字节) + */ + private Long fileSize; + + /** + * 文件类型 + */ + private String fileType; + + /** + * 上传用户ID + */ + private Long userId; + + /** + * 上传用户昵称 + */ + private String nickname; + + /** + * 上传用户头像 + */ + private String avatar; + + /** + * 分类ID + */ + private Long categoryId; + + /** + * 分类名称 + */ + private String categoryName; + + /** + * 下载次数 + */ + private Integer downloadCount; + + /** + * 点赞次数 + */ + private Integer likeCount; + + /** + * 当前用户是否点赞 + */ + private Boolean isLiked; + + /** + * 创建时间 + */ + private LocalDateTime createdAt; + + /** + * 更新时间 + */ + private LocalDateTime updatedAt; +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/model/vo/ScheduleVO.java b/unilife-server/src/main/java/com/unilife/model/vo/ScheduleVO.java new file mode 100644 index 0000000..2db63c6 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/vo/ScheduleVO.java @@ -0,0 +1,82 @@ +package com.unilife.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +/** + * 日程视图对象 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ScheduleVO { + /** + * 日程ID + */ + private Long id; + + /** + * 用户ID + */ + private Long userId; + + /** + * 日程标题 + */ + private String title; + + /** + * 日程描述 + */ + private String description; + + /** + * 开始时间 + */ + private LocalDateTime startTime; + + /** + * 结束时间 + */ + private LocalDateTime endTime; + + /** + * 地点 + */ + private String location; + + /** + * 是否全天(0-否, 1-是) + */ + private Byte isAllDay; + + /** + * 提醒时间(分钟) + */ + private Byte reminder; + + /** + * 显示颜色 + */ + private String color; + + /** + * 状态(0-删除, 1-正常) + */ + private Byte status; + + /** + * 创建时间 + */ + private LocalDateTime createdAt; + + /** + * 更新时间 + */ + private LocalDateTime updatedAt; +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/service/CategoryService.java b/unilife-server/src/main/java/com/unilife/service/CategoryService.java new file mode 100644 index 0000000..49fad45 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/service/CategoryService.java @@ -0,0 +1,45 @@ +package com.unilife.service; + +import com.unilife.common.result.Result; +import com.unilife.model.entity.Category; + +/** + * 分类服务接口 + */ +public interface CategoryService { + /** + * 获取分类详情 + * @param categoryId 分类ID + * @return 结果 + */ + Result getCategoryDetail(Long categoryId); + + /** + * 获取分类列表 + * @param status 状态(可为null,表示获取所有状态) + * @return 结果 + */ + Result getCategoryList(Byte status); + + /** + * 创建分类 + * @param category 分类实体 + * @return 结果 + */ + Result createCategory(Category category); + + /** + * 更新分类 + * @param categoryId 分类ID + * @param category 分类实体 + * @return 结果 + */ + Result updateCategory(Long categoryId, Category category); + + /** + * 删除分类 + * @param categoryId 分类ID + * @return 结果 + */ + Result deleteCategory(Long categoryId); +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/service/CommentService.java b/unilife-server/src/main/java/com/unilife/service/CommentService.java new file mode 100644 index 0000000..7594a09 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/service/CommentService.java @@ -0,0 +1,41 @@ +package com.unilife.service; + +import com.unilife.common.result.Result; +import com.unilife.model.dto.CreateCommentDTO; + +/** + * 评论服务接口 + */ +public interface CommentService { + /** + * 创建评论 + * @param userId 用户ID + * @param createCommentDTO 创建评论DTO + * @return 结果 + */ + Result createComment(Long userId, CreateCommentDTO createCommentDTO); + + /** + * 获取帖子评论列表 + * @param postId 帖子ID + * @param userId 当前用户ID,可为null + * @return 结果 + */ + Result getCommentsByPostId(Long postId, Long userId); + + /** + * 删除评论 + * @param commentId 评论ID + * @param userId 用户ID + * @return 结果 + */ + Result deleteComment(Long commentId, Long userId); + + /** + * 点赞/取消点赞评论 + * @param commentId 评论ID + * @param userId 用户ID + * @return 结果 + */ + Result likeComment(Long commentId, Long userId); +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/service/CourseService.java b/unilife-server/src/main/java/com/unilife/service/CourseService.java new file mode 100644 index 0000000..4bb152f --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/service/CourseService.java @@ -0,0 +1,68 @@ +package com.unilife.service; + +import com.unilife.common.result.Result; +import com.unilife.model.dto.CreateCourseDTO; + +/** + * 课程服务接口 + */ +public interface CourseService { + /** + * 创建课程 + * @param userId 用户ID + * @param createCourseDTO 创建课程DTO + * @return 结果 + */ + Result createCourse(Long userId, CreateCourseDTO createCourseDTO); + + /** + * 获取课程详情 + * @param courseId 课程ID + * @param userId 用户ID + * @return 结果 + */ + Result getCourseDetail(Long courseId, Long userId); + + /** + * 获取用户的所有课程 + * @param userId 用户ID + * @return 结果 + */ + Result getCourseList(Long userId); + + /** + * 获取用户在指定星期几的课程 + * @param userId 用户ID + * @param dayOfWeek 星期几(1-7) + * @return 结果 + */ + Result getCourseListByDayOfWeek(Long userId, Byte dayOfWeek); + + /** + * 更新课程 + * @param courseId 课程ID + * @param userId 用户ID + * @param createCourseDTO 更新课程DTO + * @return 结果 + */ + Result updateCourse(Long courseId, Long userId, CreateCourseDTO createCourseDTO); + + /** + * 删除课程 + * @param courseId 课程ID + * @param userId 用户ID + * @return 结果 + */ + Result deleteCourse(Long courseId, Long userId); + + /** + * 检查课程时间冲突 + * @param userId 用户ID + * @param dayOfWeek 星期几(1-7) + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param excludeCourseId 排除的课程ID(用于更新时排除自身) + * @return 结果 + */ + Result checkCourseConflict(Long userId, Byte dayOfWeek, String startTime, String endTime, Long excludeCourseId); +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/service/ResourceService.java b/unilife-server/src/main/java/com/unilife/service/ResourceService.java new file mode 100644 index 0000000..15c9910 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/service/ResourceService.java @@ -0,0 +1,80 @@ +package com.unilife.service; + +import com.unilife.common.result.Result; +import com.unilife.model.dto.CreateResourceDTO; +import org.springframework.web.multipart.MultipartFile; + +/** + * 资源服务接口 + */ +public interface ResourceService { + /** + * 上传资源 + * @param userId 用户ID + * @param createResourceDTO 创建资源DTO + * @param file 上传的文件 + * @return 结果 + */ + Result uploadResource(Long userId, CreateResourceDTO createResourceDTO, MultipartFile file); + + /** + * 获取资源详情 + * @param resourceId 资源ID + * @param userId 当前用户ID,可为null + * @return 结果 + */ + Result getResourceDetail(Long resourceId, Long userId); + + /** + * 获取资源列表 + * @param categoryId 分类ID,可为null + * @param userId 用户ID,可为null + * @param keyword 关键词,可为null + * @param page 页码 + * @param size 每页大小 + * @return 结果 + */ + Result getResourceList(Long categoryId, Long userId, String keyword, Integer page, Integer size); + + /** + * 更新资源 + * @param resourceId 资源ID + * @param userId 用户ID + * @param createResourceDTO 更新资源DTO + * @return 结果 + */ + Result updateResource(Long resourceId, Long userId, CreateResourceDTO createResourceDTO); + + /** + * 删除资源 + * @param resourceId 资源ID + * @param userId 用户ID + * @return 结果 + */ + Result deleteResource(Long resourceId, Long userId); + + /** + * 下载资源 + * @param resourceId 资源ID + * @param userId 用户ID,可为null + * @return 结果 + */ + Result downloadResource(Long resourceId, Long userId); + + /** + * 点赞/取消点赞资源 + * @param resourceId 资源ID + * @param userId 用户ID + * @return 结果 + */ + Result likeResource(Long resourceId, Long userId); + + /** + * 获取用户上传的资源列表 + * @param userId 用户ID + * @param page 页码 + * @param size 每页大小 + * @return 结果 + */ + Result getUserResources(Long userId, Integer page, Integer size); +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/service/ScheduleService.java b/unilife-server/src/main/java/com/unilife/service/ScheduleService.java new file mode 100644 index 0000000..4473078 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/service/ScheduleService.java @@ -0,0 +1,77 @@ +package com.unilife.service; + +import com.unilife.common.result.Result; +import com.unilife.model.dto.CreateScheduleDTO; + +import java.time.LocalDateTime; + +/** + * 日程服务接口 + */ +public interface ScheduleService { + /** + * 创建日程 + * @param userId 用户ID + * @param createScheduleDTO 创建日程DTO + * @return 结果 + */ + Result createSchedule(Long userId, CreateScheduleDTO createScheduleDTO); + + /** + * 获取日程详情 + * @param scheduleId 日程ID + * @param userId 用户ID + * @return 结果 + */ + Result getScheduleDetail(Long scheduleId, Long userId); + + /** + * 获取用户的所有日程 + * @param userId 用户ID + * @return 结果 + */ + Result getScheduleList(Long userId); + + /** + * 获取用户在指定时间范围内的日程 + * @param userId 用户ID + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return 结果 + */ + Result getScheduleListByTimeRange(Long userId, LocalDateTime startTime, LocalDateTime endTime); + + /** + * 更新日程 + * @param scheduleId 日程ID + * @param userId 用户ID + * @param createScheduleDTO 更新日程DTO + * @return 结果 + */ + Result updateSchedule(Long scheduleId, Long userId, CreateScheduleDTO createScheduleDTO); + + /** + * 删除日程 + * @param scheduleId 日程ID + * @param userId 用户ID + * @return 结果 + */ + Result deleteSchedule(Long scheduleId, Long userId); + + /** + * 检查日程时间冲突 + * @param userId 用户ID + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param excludeScheduleId 排除的日程ID(用于更新时排除自身) + * @return 结果 + */ + Result checkScheduleConflict(Long userId, LocalDateTime startTime, LocalDateTime endTime, Long excludeScheduleId); + + /** + * 处理日程提醒 + * 此方法由定时任务调用,用于发送日程提醒 + * @return 结果 + */ + Result processScheduleReminders(); +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/service/impl/CategoryServiceImpl.java b/unilife-server/src/main/java/com/unilife/service/impl/CategoryServiceImpl.java new file mode 100644 index 0000000..f19f447 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/service/impl/CategoryServiceImpl.java @@ -0,0 +1,96 @@ +package com.unilife.service.impl; + +import com.unilife.common.result.Result; +import com.unilife.mapper.CategoryMapper; +import com.unilife.model.entity.Category; +import com.unilife.service.CategoryService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class CategoryServiceImpl implements CategoryService { + + @Autowired + private CategoryMapper categoryMapper; + + @Override + public Result getCategoryDetail(Long categoryId) { + // 获取分类 + Category category = categoryMapper.getById(categoryId); + if (category == null) { + return Result.error(404, "分类不存在"); + } + + return Result.success(category); + } + + @Override + public Result getCategoryList(Byte status) { + // 获取分类列表 + List categories = categoryMapper.getList(status); + + // 获取分类总数 + Integer count = categoryMapper.getCount(status); + + // 返回结果 + Map data = new HashMap<>(); + data.put("total", count); + data.put("list", categories); + + return Result.success(data); + } + + @Override + public Result createCategory(Category category) { + // 设置默认值 + if (category.getSort() == null) { + category.setSort(0); + } + if (category.getStatus() == null) { + category.setStatus((byte) 1); + } + + // 保存分类 + categoryMapper.insert(category); + + Map data = new HashMap<>(); + data.put("categoryId", category.getId()); + + return Result.success(data, "创建成功"); + } + + @Override + public Result updateCategory(Long categoryId, Category category) { + // 获取分类 + Category existingCategory = categoryMapper.getById(categoryId); + if (existingCategory == null) { + return Result.error(404, "分类不存在"); + } + + // 更新分类 + category.setId(categoryId); + categoryMapper.update(category); + + return Result.success(null, "更新成功"); + } + + @Override + public Result deleteCategory(Long categoryId) { + // 获取分类 + Category category = categoryMapper.getById(categoryId); + if (category == null) { + return Result.error(404, "分类不存在"); + } + + // 删除分类(逻辑删除) + categoryMapper.delete(categoryId); + + return Result.success(null, "删除成功"); + } +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/service/impl/CommentServiceImpl.java b/unilife-server/src/main/java/com/unilife/service/impl/CommentServiceImpl.java new file mode 100644 index 0000000..e93dc47 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/service/impl/CommentServiceImpl.java @@ -0,0 +1,189 @@ +package com.unilife.service.impl; + +import com.unilife.common.result.Result; +import com.unilife.mapper.CommentMapper; +import com.unilife.mapper.PostMapper; +import com.unilife.mapper.UserMapper; +import com.unilife.model.dto.CreateCommentDTO; +import com.unilife.model.entity.Comment; +import com.unilife.model.entity.Post; +import com.unilife.model.entity.User; +import com.unilife.model.vo.CommentVO; +import com.unilife.service.CommentService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Slf4j +@Service +public class CommentServiceImpl implements CommentService { + + @Autowired + private CommentMapper commentMapper; + + @Autowired + private PostMapper postMapper; + + @Autowired + private UserMapper userMapper; + + @Override + @Transactional + public Result createComment(Long userId, CreateCommentDTO createCommentDTO) { + // 检查用户是否存在 + User user = userMapper.getUserById(userId); + if (user == null) { + return Result.error(404, "用户不存在"); + } + + // 检查帖子是否存在 + Post post = postMapper.getById(createCommentDTO.getPostId()); + if (post == null) { + return Result.error(404, "帖子不存在"); + } + + // 如果是回复评论,检查父评论是否存在 + if (createCommentDTO.getParentId() != null) { + Comment parentComment = commentMapper.getById(createCommentDTO.getParentId()); + if (parentComment == null) { + return Result.error(404, "父评论不存在"); + } + } + + // 创建评论 + Comment comment = new Comment(); + comment.setPostId(createCommentDTO.getPostId()); + comment.setUserId(userId); + comment.setContent(createCommentDTO.getContent()); + comment.setParentId(createCommentDTO.getParentId()); + comment.setLikeCount(0); + comment.setStatus((byte) 1); + + // 保存评论 + commentMapper.insert(comment); + + // 增加帖子评论数 + postMapper.incrementCommentCount(createCommentDTO.getPostId()); + + Map data = new HashMap<>(); + data.put("commentId", comment.getId()); + + return Result.success(data, "评论成功"); + } + + @Override + public Result getCommentsByPostId(Long postId, Long userId) { + // 检查帖子是否存在 + Post post = postMapper.getById(postId); + if (post == null) { + return Result.error(404, "帖子不存在"); + } + + // 获取一级评论 + List topLevelComments = commentMapper.getTopLevelCommentsByPostId(postId); + + // 转换为VO + List commentVOs = topLevelComments.stream().map(comment -> { + // 获取评论用户信息 + User user = userMapper.getUserById(comment.getUserId()); + + // 获取回复列表 + List replies = commentMapper.getRepliesByParentId(comment.getId()); + List replyVOs = replies.stream().map(reply -> { + User replyUser = userMapper.getUserById(reply.getUserId()); + return CommentVO.builder() + .id(reply.getId()) + .postId(reply.getPostId()) + .userId(reply.getUserId()) + .nickname(replyUser != null ? replyUser.getNickname() : "未知用户") + .avatar(replyUser != null ? replyUser.getAvatar() : null) + .content(reply.getContent()) + .parentId(reply.getParentId()) + .likeCount(reply.getLikeCount()) + .isLiked(false) // 实际开发中应该查询用户是否点赞 + .createdAt(reply.getCreatedAt()) + .replies(new ArrayList<>()) + .build(); + }).collect(Collectors.toList()); + + return CommentVO.builder() + .id(comment.getId()) + .postId(comment.getPostId()) + .userId(comment.getUserId()) + .nickname(user != null ? user.getNickname() : "未知用户") + .avatar(user != null ? user.getAvatar() : null) + .content(comment.getContent()) + .parentId(comment.getParentId()) + .likeCount(comment.getLikeCount()) + .isLiked(false) // 实际开发中应该查询用户是否点赞 + .createdAt(comment.getCreatedAt()) + .replies(replyVOs) + .build(); + }).collect(Collectors.toList()); + + // 获取评论总数 + Integer count = commentMapper.getCountByPostId(postId); + + // 返回结果 + Map data = new HashMap<>(); + data.put("total", count); + data.put("list", commentVOs); + + return Result.success(data); + } + + @Override + @Transactional + public Result deleteComment(Long commentId, Long userId) { + // 获取评论 + Comment comment = commentMapper.getById(commentId); + if (comment == null) { + return Result.error(404, "评论不存在"); + } + + // 检查是否有权限删除 + if (!comment.getUserId().equals(userId)) { + return Result.error(403, "无权限删除此评论"); + } + + // 删除评论(逻辑删除) + commentMapper.delete(commentId); + + // 减少帖子评论数 + postMapper.decrementCommentCount(comment.getPostId()); + + return Result.success(null, "删除成功"); + } + + @Override + public Result likeComment(Long commentId, Long userId) { + // 获取评论 + Comment comment = commentMapper.getById(commentId); + if (comment == null) { + return Result.error(404, "评论不存在"); + } + + // 检查用户是否已点赞 + // 注意:这里需要创建一个评论点赞表和相应的Mapper,实际开发中需要先创建 + boolean isLiked = false; // commentLikeMapper.isLiked(commentId, userId); + + if (isLiked) { + // 取消点赞 + // commentLikeMapper.delete(commentId, userId); + commentMapper.decrementLikeCount(commentId); + return Result.success(null, "取消点赞成功"); + } else { + // 添加点赞 + // commentLikeMapper.insert(commentId, userId); + commentMapper.incrementLikeCount(commentId); + return Result.success(null, "点赞成功"); + } + } +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/service/impl/CourseServiceImpl.java b/unilife-server/src/main/java/com/unilife/service/impl/CourseServiceImpl.java new file mode 100644 index 0000000..559e4cd --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/service/impl/CourseServiceImpl.java @@ -0,0 +1,192 @@ +package com.unilife.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import com.unilife.common.result.Result; +import com.unilife.mapper.CourseMapper; +import com.unilife.mapper.UserMapper; +import com.unilife.model.dto.CreateCourseDTO; +import com.unilife.model.entity.Course; +import com.unilife.model.entity.User; +import com.unilife.model.vo.CourseVO; +import com.unilife.service.CourseService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Slf4j +@Service +public class CourseServiceImpl implements CourseService { + + @Autowired + private CourseMapper courseMapper; + + @Autowired + private UserMapper userMapper; + + private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss"); + + @Override + @Transactional + public Result createCourse(Long userId, CreateCourseDTO createCourseDTO) { + // 检查用户是否存在 + User user = userMapper.getUserById(userId); + if (user == null) { + return Result.error(404, "用户不存在"); + } + + // 检查课程时间冲突 + String startTimeStr = createCourseDTO.getStartTime().format(TIME_FORMATTER); + String endTimeStr = createCourseDTO.getEndTime().format(TIME_FORMATTER); + Integer conflictCount = courseMapper.checkConflict(userId, createCourseDTO.getDayOfWeek(), + startTimeStr, endTimeStr, null); + if (conflictCount > 0) { + return Result.error(400, "课程时间冲突,该时间段已有其他课程"); + } + + // 创建课程 + Course course = new Course(); + BeanUtil.copyProperties(createCourseDTO, course); + course.setUserId(userId); + course.setStatus((byte) 1); + + // 保存课程 + courseMapper.insert(course); + + Map data = new HashMap<>(); + data.put("courseId", course.getId()); + + return Result.success(data, "创建课程成功"); + } + + @Override + public Result getCourseDetail(Long courseId, Long userId) { + // 获取课程 + Course course = courseMapper.getById(courseId); + if (course == null) { + return Result.error(404, "课程不存在"); + } + + // 检查权限(只能查看自己的课程) + if (!course.getUserId().equals(userId)) { + return Result.error(403, "无权限查看此课程"); + } + + // 转换为VO + CourseVO courseVO = new CourseVO(); + BeanUtil.copyProperties(course, courseVO); + + return Result.success(courseVO); + } + + @Override + public Result getCourseList(Long userId) { + // 获取用户的所有课程 + List courses = courseMapper.getListByUserId(userId); + + // 转换为VO + List courseVOs = courses.stream().map(course -> { + CourseVO courseVO = new CourseVO(); + BeanUtil.copyProperties(course, courseVO); + return courseVO; + }).collect(Collectors.toList()); + + // 返回结果 + Map data = new HashMap<>(); + data.put("total", courseVOs.size()); + data.put("list", courseVOs); + + return Result.success(data); + } + + @Override + public Result getCourseListByDayOfWeek(Long userId, Byte dayOfWeek) { + // 获取用户在指定星期几的课程 + List courses = courseMapper.getListByUserIdAndDayOfWeek(userId, dayOfWeek); + + // 转换为VO + List courseVOs = courses.stream().map(course -> { + CourseVO courseVO = new CourseVO(); + BeanUtil.copyProperties(course, courseVO); + return courseVO; + }).collect(Collectors.toList()); + + // 返回结果 + Map data = new HashMap<>(); + data.put("total", courseVOs.size()); + data.put("list", courseVOs); + + return Result.success(data); + } + + @Override + @Transactional + public Result updateCourse(Long courseId, Long userId, CreateCourseDTO createCourseDTO) { + // 获取课程 + Course course = courseMapper.getById(courseId); + if (course == null) { + return Result.error(404, "课程不存在"); + } + + // 检查权限(只能更新自己的课程) + if (!course.getUserId().equals(userId)) { + return Result.error(403, "无权限更新此课程"); + } + + // 检查课程时间冲突 + String startTimeStr = createCourseDTO.getStartTime().format(TIME_FORMATTER); + String endTimeStr = createCourseDTO.getEndTime().format(TIME_FORMATTER); + Integer conflictCount = courseMapper.checkConflict(userId, createCourseDTO.getDayOfWeek(), + startTimeStr, endTimeStr, courseId); + if (conflictCount > 0) { + return Result.error(400, "课程时间冲突,该时间段已有其他课程"); + } + + // 更新课程 + BeanUtil.copyProperties(createCourseDTO, course); + + // 保存更新 + courseMapper.update(course); + + return Result.success(null, "更新课程成功"); + } + + @Override + @Transactional + public Result deleteCourse(Long courseId, Long userId) { + // 获取课程 + Course course = courseMapper.getById(courseId); + if (course == null) { + return Result.error(404, "课程不存在"); + } + + // 检查权限(只能删除自己的课程) + if (!course.getUserId().equals(userId)) { + return Result.error(403, "无权限删除此课程"); + } + + // 删除课程(逻辑删除) + courseMapper.delete(courseId, userId); + + return Result.success(null, "删除课程成功"); + } + + @Override + public Result checkCourseConflict(Long userId, Byte dayOfWeek, String startTime, String endTime, Long excludeCourseId) { + // 检查课程时间冲突 + Integer conflictCount = courseMapper.checkConflict(userId, dayOfWeek, startTime, endTime, excludeCourseId); + + Map data = new HashMap<>(); + data.put("hasConflict", conflictCount > 0); + data.put("conflictCount", conflictCount); + + return Result.success(data); + } +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/service/impl/PostServiceImpl.java b/unilife-server/src/main/java/com/unilife/service/impl/PostServiceImpl.java index efea35f..8806c46 100644 --- a/unilife-server/src/main/java/com/unilife/service/impl/PostServiceImpl.java +++ b/unilife-server/src/main/java/com/unilife/service/impl/PostServiceImpl.java @@ -5,12 +5,12 @@ import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.unilife.common.result.Result; -// import com.unilife.mapper.CategoryMapper; +import com.unilife.mapper.CategoryMapper; +import com.unilife.mapper.PostLikeMapper; import com.unilife.mapper.PostMapper; import com.unilife.mapper.UserMapper; import com.unilife.model.dto.CreatePostDTO; import com.unilife.model.dto.UpdatePostDTO; -// import com.unilife.model.entity.Category; import com.unilife.model.entity.Post; import com.unilife.model.entity.User; import com.unilife.model.vo.PostListVO; @@ -20,7 +20,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -36,8 +35,11 @@ public class PostServiceImpl implements PostService { @Autowired private UserMapper userMapper; - // @Autowired - // private CategoryMapper categoryMapper; + @Autowired + private CategoryMapper categoryMapper; + + @Autowired + private PostLikeMapper postLikeMapper; @Override public Result createPost(Long userId, CreatePostDTO createPostDTO) { @@ -216,17 +218,16 @@ public class PostServiceImpl implements PostService { } // 检查用户是否已点赞 - // 注意:这里需要创建一个点赞表和相应的Mapper,实际开发中需要先创建 - boolean isLiked = false; // postLikeMapper.isLiked(postId, userId); + Boolean isLiked = postLikeMapper.isLiked(postId, userId); - if (isLiked) { + if (Boolean.TRUE.equals(isLiked)) { // 取消点赞 - // postLikeMapper.delete(postId, userId); + postLikeMapper.delete(postId, userId); postMapper.decrementLikeCount(postId); return Result.success(null, "取消点赞成功"); } else { // 添加点赞 - // postLikeMapper.insert(postId, userId); + postLikeMapper.insert(postId, userId); postMapper.incrementLikeCount(postId); return Result.success(null, "点赞成功"); } diff --git a/unilife-server/src/main/java/com/unilife/service/impl/ResourceServiceImpl.java b/unilife-server/src/main/java/com/unilife/service/impl/ResourceServiceImpl.java new file mode 100644 index 0000000..cce8f38 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/service/impl/ResourceServiceImpl.java @@ -0,0 +1,339 @@ +package com.unilife.service.impl; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.unilife.common.result.Result; +import com.unilife.mapper.CategoryMapper; +import com.unilife.mapper.ResourceMapper; +import com.unilife.mapper.UserMapper; +import com.unilife.model.dto.CreateResourceDTO; +import com.unilife.model.entity.Category; +import com.unilife.model.entity.Resource; +import com.unilife.model.entity.User; +import com.unilife.model.vo.ResourceVO; +import com.unilife.service.ResourceService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; + +@Slf4j +@Service +public class ResourceServiceImpl implements ResourceService { + + @Autowired + private ResourceMapper resourceMapper; + + @Autowired + private UserMapper userMapper; + + @Autowired + private CategoryMapper categoryMapper; + + // 文件存储路径,实际项目中应该配置在application.yml中 + private static final String UPLOAD_DIR = "uploads/resources/"; + + @Override + @Transactional + public Result uploadResource(Long userId, CreateResourceDTO createResourceDTO, MultipartFile file) { + // 检查用户是否存在 + User user = userMapper.getUserById(userId); + if (user == null) { + return Result.error(404, "用户不存在"); + } + + // 检查分类是否存在 + Category category = categoryMapper.getById(createResourceDTO.getCategoryId()); + if (category == null) { + return Result.error(404, "分类不存在"); + } + + // 检查文件是否为空 + if (file.isEmpty()) { + return Result.error(400, "上传文件不能为空"); + } + + try { + // 创建上传目录(如果不存在) + File uploadDir = new File(UPLOAD_DIR); + if (!uploadDir.exists()) { + uploadDir.mkdirs(); + } + + // 生成唯一文件名 + String originalFilename = file.getOriginalFilename(); + String fileExtension = originalFilename != null ? originalFilename.substring(originalFilename.lastIndexOf(".")) : ""; + String newFilename = UUID.randomUUID().toString() + fileExtension; + String filePath = UPLOAD_DIR + newFilename; + + // 保存文件 + Path path = Paths.get(filePath); + Files.write(path, file.getBytes()); + + // 创建资源记录 + Resource resource = new Resource(); + resource.setUserId(userId); + resource.setTitle(createResourceDTO.getTitle()); + resource.setDescription(createResourceDTO.getDescription()); + resource.setFileUrl(filePath); + resource.setFileSize(file.getSize()); + resource.setFileType(file.getContentType()); + resource.setCategoryId(createResourceDTO.getCategoryId()); + resource.setDownloadCount(0); + resource.setLikeCount(0); + resource.setStatus((byte) 1); + + // 保存资源记录 + resourceMapper.insert(resource); + + Map data = new HashMap<>(); + data.put("resourceId", resource.getId()); + + return Result.success(data, "资源上传成功"); + } catch (IOException e) { + log.error("文件上传失败", e); + return Result.error(500, "文件上传失败"); + } + } + + @Override + public Result getResourceDetail(Long resourceId, Long userId) { + // 获取资源 + Resource resource = resourceMapper.getById(resourceId); + if (resource == null) { + return Result.error(404, "资源不存在"); + } + + // 获取上传用户信息 + User user = userMapper.getUserById(resource.getUserId()); + + // 获取分类信息 + Category category = categoryMapper.getById(resource.getCategoryId()); + + // 构建返回数据 + ResourceVO resourceVO = ResourceVO.builder() + .id(resource.getId()) + .title(resource.getTitle()) + .description(resource.getDescription()) + .fileUrl(resource.getFileUrl()) + .fileSize(resource.getFileSize()) + .fileType(resource.getFileType()) + .userId(resource.getUserId()) + .nickname(user != null ? user.getNickname() : "未知用户") + .avatar(user != null ? user.getAvatar() : null) + .categoryId(resource.getCategoryId()) + .categoryName(category != null ? category.getName() : "未知分类") + .downloadCount(resource.getDownloadCount()) + .likeCount(resource.getLikeCount()) + .isLiked(false) // 实际项目中应该查询用户是否点赞 + .createdAt(resource.getCreatedAt()) + .updatedAt(resource.getUpdatedAt()) + .build(); + + return Result.success(resourceVO); + } + + @Override + public Result getResourceList(Long categoryId, Long userId, String keyword, Integer page, Integer size) { + // 参数校验 + if (page == null || page < 1) page = 1; + if (size == null || size < 1 || size > 50) size = 10; + + // 分页查询 + PageHelper.startPage(page, size); + List resources = resourceMapper.getList(categoryId, userId, keyword); + PageInfo pageInfo = new PageInfo<>(resources); + + // 转换为VO + List resourceVOs = new ArrayList<>(); + for (Resource resource : resources) { + User user = userMapper.getUserById(resource.getUserId()); + Category category = categoryMapper.getById(resource.getCategoryId()); + + ResourceVO resourceVO = ResourceVO.builder() + .id(resource.getId()) + .title(resource.getTitle()) + .description(resource.getDescription()) + .fileUrl(resource.getFileUrl()) + .fileSize(resource.getFileSize()) + .fileType(resource.getFileType()) + .userId(resource.getUserId()) + .nickname(user != null ? user.getNickname() : "未知用户") + .avatar(user != null ? user.getAvatar() : null) + .categoryId(resource.getCategoryId()) + .categoryName(category != null ? category.getName() : "未知分类") + .downloadCount(resource.getDownloadCount()) + .likeCount(resource.getLikeCount()) + .isLiked(false) // 实际项目中应该查询用户是否点赞 + .createdAt(resource.getCreatedAt()) + .updatedAt(resource.getUpdatedAt()) + .build(); + + resourceVOs.add(resourceVO); + } + + // 返回结果 + Map data = new HashMap<>(); + data.put("total", pageInfo.getTotal()); + data.put("list", resourceVOs); + data.put("pages", pageInfo.getPages()); + + return Result.success(data); + } + + @Override + @Transactional + public Result updateResource(Long resourceId, Long userId, CreateResourceDTO createResourceDTO) { + // 获取资源 + Resource resource = resourceMapper.getById(resourceId); + if (resource == null) { + return Result.error(404, "资源不存在"); + } + + // 检查是否有权限更新 + if (!resource.getUserId().equals(userId)) { + return Result.error(403, "无权限更新此资源"); + } + + // 检查分类是否存在 + Category category = categoryMapper.getById(createResourceDTO.getCategoryId()); + if (category == null) { + return Result.error(404, "分类不存在"); + } + + // 更新资源 + resource.setTitle(createResourceDTO.getTitle()); + resource.setDescription(createResourceDTO.getDescription()); + resource.setCategoryId(createResourceDTO.getCategoryId()); + + // 保存更新 + resourceMapper.update(resource); + + return Result.success(null, "更新成功"); + } + + @Override + @Transactional + public Result deleteResource(Long resourceId, Long userId) { + // 获取资源 + Resource resource = resourceMapper.getById(resourceId); + if (resource == null) { + return Result.error(404, "资源不存在"); + } + + // 检查是否有权限删除 + if (!resource.getUserId().equals(userId)) { + return Result.error(403, "无权限删除此资源"); + } + + // 删除资源(逻辑删除) + resourceMapper.delete(resourceId); + + return Result.success(null, "删除成功"); + } + + @Override + @Transactional + public Result downloadResource(Long resourceId, Long userId) { + // 获取资源 + Resource resource = resourceMapper.getById(resourceId); + if (resource == null) { + return Result.error(404, "资源不存在"); + } + + // 增加下载次数 + resourceMapper.incrementDownloadCount(resourceId); + + // 返回文件URL + Map data = new HashMap<>(); + data.put("fileUrl", resource.getFileUrl()); + data.put("fileName", resource.getTitle()); + data.put("fileType", resource.getFileType()); + + return Result.success(data, "获取下载链接成功"); + } + + @Override + @Transactional + public Result likeResource(Long resourceId, Long userId) { + // 获取资源 + Resource resource = resourceMapper.getById(resourceId); + if (resource == null) { + return Result.error(404, "资源不存在"); + } + + // 检查用户是否已点赞 + // 注意:这里需要创建一个资源点赞表和相应的Mapper,实际开发中需要先创建 + boolean isLiked = false; // resourceLikeMapper.isLiked(resourceId, userId); + + if (isLiked) { + // 取消点赞 + // resourceLikeMapper.delete(resourceId, userId); + resourceMapper.decrementLikeCount(resourceId); + return Result.success(null, "取消点赞成功"); + } else { + // 添加点赞 + // resourceLikeMapper.insert(resourceId, userId); + resourceMapper.incrementLikeCount(resourceId); + return Result.success(null, "点赞成功"); + } + } + + @Override + public Result getUserResources(Long userId, Integer page, Integer size) { + // 参数校验 + if (page == null || page < 1) page = 1; + if (size == null || size < 1 || size > 50) size = 10; + + // 分页查询 + PageHelper.startPage(page, size); + List resources = resourceMapper.getList(null, userId, null); + PageInfo pageInfo = new PageInfo<>(resources); + + // 转换为VO + List resourceVOs = resources.stream().map(resource -> { + User user = userMapper.getUserById(resource.getUserId()); + Category category = categoryMapper.getById(resource.getCategoryId()); + + return ResourceVO.builder() + .id(resource.getId()) + .title(resource.getTitle()) + .description(resource.getDescription()) + .fileUrl(resource.getFileUrl()) + .fileSize(resource.getFileSize()) + .fileType(resource.getFileType()) + .userId(resource.getUserId()) + .nickname(user != null ? user.getNickname() : "未知用户") + .avatar(user != null ? user.getAvatar() : null) + .categoryId(resource.getCategoryId()) + .categoryName(category != null ? category.getName() : "未知分类") + .downloadCount(resource.getDownloadCount()) + .likeCount(resource.getLikeCount()) + .isLiked(false) // 实际项目中应该查询用户是否点赞 + .createdAt(resource.getCreatedAt()) + .updatedAt(resource.getUpdatedAt()) + .build(); + }).collect(Collectors.toList()); + + // 返回结果 + Map data = new HashMap<>(); + data.put("total", pageInfo.getTotal()); + data.put("list", resourceVOs); + data.put("pages", pageInfo.getPages()); + + return Result.success(data); + } +} \ No newline at end of file diff --git a/unilife-server/src/main/java/com/unilife/service/impl/ScheduleServiceImpl.java b/unilife-server/src/main/java/com/unilife/service/impl/ScheduleServiceImpl.java new file mode 100644 index 0000000..b0baf4f --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/service/impl/ScheduleServiceImpl.java @@ -0,0 +1,262 @@ +package com.unilife.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import com.unilife.common.result.Result; +import com.unilife.mapper.ScheduleMapper; +import com.unilife.mapper.UserMapper; +import com.unilife.model.dto.CreateScheduleDTO; +import com.unilife.model.entity.Schedule; +import com.unilife.model.entity.User; +import com.unilife.model.vo.ScheduleVO; +import com.unilife.service.ScheduleService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import jakarta.mail.MessagingException; +import jakarta.mail.internet.MimeMessage; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Slf4j +@Service +public class ScheduleServiceImpl implements ScheduleService { + + @Autowired + private ScheduleMapper scheduleMapper; + + @Autowired + private UserMapper userMapper; + + @Autowired + private JavaMailSender mailSender; + + @Override + @Transactional + public Result createSchedule(Long userId, CreateScheduleDTO createScheduleDTO) { + // 检查用户是否存在 + User user = userMapper.getUserById(userId); + if (user == null) { + return Result.error(404, "用户不存在"); + } + + // 检查日程时间冲突 + Integer conflictCount = scheduleMapper.checkConflict(userId, + createScheduleDTO.getStartTime(), createScheduleDTO.getEndTime(), null); + if (conflictCount > 0) { + return Result.error(400, "日程时间冲突,该时间段已有其他日程"); + } + + // 创建日程 + Schedule schedule = new Schedule(); + BeanUtil.copyProperties(createScheduleDTO, schedule); + schedule.setUserId(userId); + schedule.setStatus((byte) 1); + + // 保存日程 + scheduleMapper.insert(schedule); + + Map data = new HashMap<>(); + data.put("scheduleId", schedule.getId()); + + return Result.success(data, "创建日程成功"); + } + + @Override + public Result getScheduleDetail(Long scheduleId, Long userId) { + // 获取日程 + Schedule schedule = scheduleMapper.getById(scheduleId); + if (schedule == null) { + return Result.error(404, "日程不存在"); + } + + // 检查权限(只能查看自己的日程) + if (!schedule.getUserId().equals(userId)) { + return Result.error(403, "无权限查看此日程"); + } + + // 转换为VO + ScheduleVO scheduleVO = new ScheduleVO(); + BeanUtil.copyProperties(schedule, scheduleVO); + + return Result.success(scheduleVO); + } + + @Override + public Result getScheduleList(Long userId) { + // 获取用户的所有日程 + List schedules = scheduleMapper.getListByUserId(userId); + + // 转换为VO + List scheduleVOs = schedules.stream().map(schedule -> { + ScheduleVO scheduleVO = new ScheduleVO(); + BeanUtil.copyProperties(schedule, scheduleVO); + return scheduleVO; + }).collect(Collectors.toList()); + + // 返回结果 + Map data = new HashMap<>(); + data.put("total", scheduleVOs.size()); + data.put("list", scheduleVOs); + + return Result.success(data); + } + + @Override + public Result getScheduleListByTimeRange(Long userId, LocalDateTime startTime, LocalDateTime endTime) { + // 获取用户在指定时间范围内的日程 + List schedules = scheduleMapper.getListByUserIdAndTimeRange(userId, startTime, endTime); + + // 转换为VO + List scheduleVOs = schedules.stream().map(schedule -> { + ScheduleVO scheduleVO = new ScheduleVO(); + BeanUtil.copyProperties(schedule, scheduleVO); + return scheduleVO; + }).collect(Collectors.toList()); + + // 返回结果 + Map data = new HashMap<>(); + data.put("total", scheduleVOs.size()); + data.put("list", scheduleVOs); + + return Result.success(data); + } + + @Override + @Transactional + public Result updateSchedule(Long scheduleId, Long userId, CreateScheduleDTO createScheduleDTO) { + // 获取日程 + Schedule schedule = scheduleMapper.getById(scheduleId); + if (schedule == null) { + return Result.error(404, "日程不存在"); + } + + // 检查权限(只能更新自己的日程) + if (!schedule.getUserId().equals(userId)) { + return Result.error(403, "无权限更新此日程"); + } + + // 检查日程时间冲突 + Integer conflictCount = scheduleMapper.checkConflict(userId, + createScheduleDTO.getStartTime(), createScheduleDTO.getEndTime(), scheduleId); + if (conflictCount > 0) { + return Result.error(400, "日程时间冲突,该时间段已有其他日程"); + } + + // 更新日程 + BeanUtil.copyProperties(createScheduleDTO, schedule); + + // 保存更新 + scheduleMapper.update(schedule); + + return Result.success(null, "更新日程成功"); + } + + @Override + @Transactional + public Result deleteSchedule(Long scheduleId, Long userId) { + // 获取日程 + Schedule schedule = scheduleMapper.getById(scheduleId); + if (schedule == null) { + return Result.error(404, "日程不存在"); + } + + // 检查权限(只能删除自己的日程) + if (!schedule.getUserId().equals(userId)) { + return Result.error(403, "无权限删除此日程"); + } + + // 删除日程(逻辑删除) + scheduleMapper.delete(scheduleId, userId); + + return Result.success(null, "删除日程成功"); + } + + @Override + public Result checkScheduleConflict(Long userId, LocalDateTime startTime, LocalDateTime endTime, Long excludeScheduleId) { + // 检查日程时间冲突 + Integer conflictCount = scheduleMapper.checkConflict(userId, startTime, endTime, excludeScheduleId); + + Map data = new HashMap<>(); + data.put("hasConflict", conflictCount > 0); + data.put("conflictCount", conflictCount); + + return Result.success(data); + } + + @Override + @Transactional + public Result processScheduleReminders() { + // 获取当前时间 + LocalDateTime now = LocalDateTime.now(); + + // 获取需要提醒的日程(提醒时间在当前时间前后5分钟内) + List schedulesToRemind = scheduleMapper.getSchedulesToRemind(now, 5); + + // 发送提醒邮件 + int successCount = 0; + for (Schedule schedule : schedulesToRemind) { + User user = userMapper.getUserById(schedule.getUserId()); + if (user != null && user.getEmail() != null) { + boolean sent = sendReminderEmail(user, schedule); + if (sent) { + successCount++; + } + } + } + + Map data = new HashMap<>(); + data.put("total", schedulesToRemind.size()); + data.put("success", successCount); + + return Result.success(data, "处理日程提醒完成"); + } + + /** + * 发送日程提醒邮件 + * @param user 用户 + * @param schedule 日程 + * @return 是否发送成功 + */ + private boolean sendReminderEmail(User user, Schedule schedule) { + try { + MimeMessage message = mailSender.createMimeMessage(); + MimeMessageHelper helper = new MimeMessageHelper(message, true); + + helper.setTo(user.getEmail()); + helper.setSubject("UniLife - 日程提醒"); + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + String startTimeStr = schedule.getStartTime().format(formatter); + + String content = "
" + + "

日程提醒

" + + "

您好," + user.getNickname() + "!

" + + "

您有一个即将开始的日程:

" + + "
" + + "

" + schedule.getTitle() + "

" + + "

时间:" + startTimeStr + "

" + + (schedule.getLocation() != null ? "

地点:" + schedule.getLocation() + "

" : "") + + (schedule.getDescription() != null ? "

描述:" + schedule.getDescription() + "

" : "") + + "
" + + "

请合理安排您的时间。

" + + "

" + + "这是一封自动生成的邮件,请勿直接回复。" + + "

"; + + helper.setText(content, true); + mailSender.send(message); + return true; + } catch (MessagingException e) { + log.error("发送日程提醒邮件失败", e); + return false; + } + } +} \ No newline at end of file diff --git a/unilife-server/src/main/resources/mappers/CategoryMapper.xml b/unilife-server/src/main/resources/mappers/CategoryMapper.xml new file mode 100644 index 0000000..9d4078b --- /dev/null +++ b/unilife-server/src/main/resources/mappers/CategoryMapper.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + INSERT INTO categories ( + name, description, icon, sort, status, created_at, updated_at + ) VALUES ( + #{name}, #{description}, #{icon}, #{sort}, #{status}, NOW(), NOW() + ) + + + + UPDATE categories + SET name = #{name}, + description = #{description}, + icon = #{icon}, + sort = #{sort}, + status = #{status}, + updated_at = NOW() + WHERE id = #{id} + + + + UPDATE categories + SET status = 0, + updated_at = NOW() + WHERE id = #{id} + + + + \ No newline at end of file diff --git a/unilife-server/src/main/resources/mappers/CommentMapper.xml b/unilife-server/src/main/resources/mappers/CommentMapper.xml new file mode 100644 index 0000000..0b4d728 --- /dev/null +++ b/unilife-server/src/main/resources/mappers/CommentMapper.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + INSERT INTO comments ( + post_id, user_id, content, parent_id, like_count, status, created_at, updated_at + ) VALUES ( + #{postId}, #{userId}, #{content}, #{parentId}, #{likeCount}, #{status}, NOW(), NOW() + ) + + + + + + + + + + + + UPDATE comments + SET content = #{content}, + updated_at = NOW() + WHERE id = #{id} + + + + UPDATE comments + SET status = 0, + updated_at = NOW() + WHERE id = #{id} + + + + UPDATE comments + SET like_count = like_count + 1 + WHERE id = #{id} + + + + UPDATE comments + SET like_count = GREATEST(like_count - 1, 0) + WHERE id = #{id} + + \ No newline at end of file diff --git a/unilife-server/src/main/resources/mappers/CourseMapper.xml b/unilife-server/src/main/resources/mappers/CourseMapper.xml new file mode 100644 index 0000000..c5327b6 --- /dev/null +++ b/unilife-server/src/main/resources/mappers/CourseMapper.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + INSERT INTO courses ( + user_id, name, teacher, location, day_of_week, start_time, end_time, + start_week, end_week, color, status, created_at, updated_at + ) VALUES ( + #{userId}, #{name}, #{teacher}, #{location}, #{dayOfWeek}, #{startTime}, #{endTime}, + #{startWeek}, #{endWeek}, #{color}, #{status}, NOW(), NOW() + ) + + + + + + + + UPDATE courses + SET name = #{name}, + teacher = #{teacher}, + location = #{location}, + day_of_week = #{dayOfWeek}, + start_time = #{startTime}, + end_time = #{endTime}, + start_week = #{startWeek}, + end_week = #{endWeek}, + color = #{color}, + updated_at = NOW() + WHERE id = #{id} AND user_id = #{userId} + + + + UPDATE courses + SET status = 0, + updated_at = NOW() + WHERE id = #{id} AND user_id = #{userId} + + + + + + \ No newline at end of file diff --git a/unilife-server/src/main/resources/mappers/PostLikeMapper.xml b/unilife-server/src/main/resources/mappers/PostLikeMapper.xml new file mode 100644 index 0000000..96669e7 --- /dev/null +++ b/unilife-server/src/main/resources/mappers/PostLikeMapper.xml @@ -0,0 +1,36 @@ + + + + + + + + INSERT INTO post_likes ( + user_id, post_id, created_at + ) VALUES ( + #{userId}, #{postId}, NOW() + ) + + + + DELETE FROM post_likes + WHERE post_id = #{postId} AND user_id = #{userId} + + + + + + \ No newline at end of file diff --git a/unilife-server/src/main/resources/mappers/ResourceMapper.xml b/unilife-server/src/main/resources/mappers/ResourceMapper.xml new file mode 100644 index 0000000..25591d2 --- /dev/null +++ b/unilife-server/src/main/resources/mappers/ResourceMapper.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + INSERT INTO resources ( + user_id, title, description, file_url, file_size, file_type, category_id, + download_count, like_count, status, created_at, updated_at + ) VALUES ( + #{userId}, #{title}, #{description}, #{fileUrl}, #{fileSize}, #{fileType}, #{categoryId}, + #{downloadCount}, #{likeCount}, #{status}, NOW(), NOW() + ) + + + + + + + + + + UPDATE resources + SET title = #{title}, + description = #{description}, + category_id = #{categoryId}, + status = #{status}, + updated_at = NOW() + WHERE id = #{id} + + + + UPDATE resources + SET status = 0, + updated_at = NOW() + WHERE id = #{id} + + + + UPDATE resources + SET download_count = download_count + 1 + WHERE id = #{id} + + + + UPDATE resources + SET like_count = like_count + 1 + WHERE id = #{id} + + + + UPDATE resources + SET like_count = GREATEST(like_count - 1, 0) + WHERE id = #{id} + + + + + + \ No newline at end of file diff --git a/unilife-server/src/main/resources/mappers/ScheduleMapper.xml b/unilife-server/src/main/resources/mappers/ScheduleMapper.xml new file mode 100644 index 0000000..63cfc13 --- /dev/null +++ b/unilife-server/src/main/resources/mappers/ScheduleMapper.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + INSERT INTO schedules ( + user_id, title, description, start_time, end_time, location, + is_all_day, reminder, color, status, created_at, updated_at + ) VALUES ( + #{userId}, #{title}, #{description}, #{startTime}, #{endTime}, #{location}, + #{isAllDay}, #{reminder}, #{color}, #{status}, NOW(), NOW() + ) + + + + + + + + + + UPDATE schedules + SET title = #{title}, + description = #{description}, + start_time = #{startTime}, + end_time = #{endTime}, + location = #{location}, + is_all_day = #{isAllDay}, + reminder = #{reminder}, + color = #{color}, + updated_at = NOW() + WHERE id = #{id} AND user_id = #{userId} + + + + UPDATE schedules + SET status = 0, + updated_at = NOW() + WHERE id = #{id} AND user_id = #{userId} + + + + + + \ No newline at end of file