parent
							
								
									f4a8658562
								
							
						
					
					
						commit
						5f8719721c
					
				@ -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);
 | 
				
			||||
    }
 | 
				
			||||
}
 | 
				
			||||
@ -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);
 | 
				
			||||
    }
 | 
				
			||||
}
 | 
				
			||||
@ -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<Long> getLikedPostIdsByUserId(@Param("userId") Long userId);
 | 
				
			||||
}
 | 
				
			||||
@ -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<Category> categories = categoryMapper.getList(status);
 | 
				
			||||
        
 | 
				
			||||
        // 获取分类总数
 | 
				
			||||
        Integer count = categoryMapper.getCount(status);
 | 
				
			||||
        
 | 
				
			||||
        // 返回结果
 | 
				
			||||
        Map<String, Object> 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<String, Object> 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, "删除成功");
 | 
				
			||||
    }
 | 
				
			||||
}
 | 
				
			||||
@ -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<String, Object> 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<Course> courses = courseMapper.getListByUserId(userId);
 | 
				
			||||
 | 
				
			||||
        // 转换为VO
 | 
				
			||||
        List<CourseVO> courseVOs = courses.stream().map(course -> {
 | 
				
			||||
            CourseVO courseVO = new CourseVO();
 | 
				
			||||
            BeanUtil.copyProperties(course, courseVO);
 | 
				
			||||
            return courseVO;
 | 
				
			||||
        }).collect(Collectors.toList());
 | 
				
			||||
 | 
				
			||||
        // 返回结果
 | 
				
			||||
        Map<String, Object> 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<Course> courses = courseMapper.getListByUserIdAndDayOfWeek(userId, dayOfWeek);
 | 
				
			||||
 | 
				
			||||
        // 转换为VO
 | 
				
			||||
        List<CourseVO> courseVOs = courses.stream().map(course -> {
 | 
				
			||||
            CourseVO courseVO = new CourseVO();
 | 
				
			||||
            BeanUtil.copyProperties(course, courseVO);
 | 
				
			||||
            return courseVO;
 | 
				
			||||
        }).collect(Collectors.toList());
 | 
				
			||||
 | 
				
			||||
        // 返回结果
 | 
				
			||||
        Map<String, Object> 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<String, Object> data = new HashMap<>();
 | 
				
			||||
        data.put("hasConflict", conflictCount > 0);
 | 
				
			||||
        data.put("conflictCount", conflictCount);
 | 
				
			||||
        
 | 
				
			||||
        return Result.success(data);
 | 
				
			||||
    }
 | 
				
			||||
}
 | 
				
			||||
@ -0,0 +1,67 @@
 | 
				
			||||
<?xml version="1.0" encoding="UTF-8" ?>
 | 
				
			||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 | 
				
			||||
<mapper namespace="com.unilife.mapper.CategoryMapper">
 | 
				
			||||
    <resultMap id="categoryResultMap" type="com.unilife.model.entity.Category">
 | 
				
			||||
        <id column="id" property="id"/>
 | 
				
			||||
        <result column="name" property="name"/>
 | 
				
			||||
        <result column="description" property="description"/>
 | 
				
			||||
        <result column="icon" property="icon"/>
 | 
				
			||||
        <result column="sort" property="sort"/>
 | 
				
			||||
        <result column="status" property="status"/>
 | 
				
			||||
        <result column="created_at" property="createdAt"/>
 | 
				
			||||
        <result column="updated_at" property="updatedAt"/>
 | 
				
			||||
    </resultMap>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getById" resultMap="categoryResultMap">
 | 
				
			||||
        SELECT id, name, description, icon, sort, status, created_at, updated_at
 | 
				
			||||
        FROM categories
 | 
				
			||||
        WHERE id = #{id}
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getList" resultMap="categoryResultMap">
 | 
				
			||||
        SELECT id, name, description, icon, sort, status, created_at, updated_at
 | 
				
			||||
        FROM categories
 | 
				
			||||
        <where>
 | 
				
			||||
            <if test="status != null">
 | 
				
			||||
                status = #{status}
 | 
				
			||||
            </if>
 | 
				
			||||
        </where>
 | 
				
			||||
        ORDER BY sort ASC, id ASC
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <insert id="insert" parameterType="com.unilife.model.entity.Category" useGeneratedKeys="true" keyProperty="id">
 | 
				
			||||
        INSERT INTO categories (
 | 
				
			||||
            name, description, icon, sort, status, created_at, updated_at
 | 
				
			||||
        ) VALUES (
 | 
				
			||||
            #{name}, #{description}, #{icon}, #{sort}, #{status}, NOW(), NOW()
 | 
				
			||||
        )
 | 
				
			||||
    </insert>
 | 
				
			||||
    
 | 
				
			||||
    <update id="update" parameterType="com.unilife.model.entity.Category">
 | 
				
			||||
        UPDATE categories
 | 
				
			||||
        SET name = #{name},
 | 
				
			||||
            description = #{description},
 | 
				
			||||
            icon = #{icon},
 | 
				
			||||
            sort = #{sort},
 | 
				
			||||
            status = #{status},
 | 
				
			||||
            updated_at = NOW()
 | 
				
			||||
        WHERE id = #{id}
 | 
				
			||||
    </update>
 | 
				
			||||
    
 | 
				
			||||
    <update id="delete">
 | 
				
			||||
        UPDATE categories
 | 
				
			||||
        SET status = 0,
 | 
				
			||||
            updated_at = NOW()
 | 
				
			||||
        WHERE id = #{id}
 | 
				
			||||
    </update>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getCount" resultType="java.lang.Integer">
 | 
				
			||||
        SELECT COUNT(*)
 | 
				
			||||
        FROM categories
 | 
				
			||||
        <where>
 | 
				
			||||
            <if test="status != null">
 | 
				
			||||
                status = #{status}
 | 
				
			||||
            </if>
 | 
				
			||||
        </where>
 | 
				
			||||
    </select>
 | 
				
			||||
</mapper>
 | 
				
			||||
@ -0,0 +1,75 @@
 | 
				
			||||
<?xml version="1.0" encoding="UTF-8" ?>
 | 
				
			||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 | 
				
			||||
<mapper namespace="com.unilife.mapper.CommentMapper">
 | 
				
			||||
    <resultMap id="commentResultMap" type="com.unilife.model.entity.Comment">
 | 
				
			||||
        <id column="id" property="id"/>
 | 
				
			||||
        <result column="post_id" property="postId"/>
 | 
				
			||||
        <result column="user_id" property="userId"/>
 | 
				
			||||
        <result column="content" property="content"/>
 | 
				
			||||
        <result column="parent_id" property="parentId"/>
 | 
				
			||||
        <result column="like_count" property="likeCount"/>
 | 
				
			||||
        <result column="status" property="status"/>
 | 
				
			||||
        <result column="created_at" property="createdAt"/>
 | 
				
			||||
        <result column="updated_at" property="updatedAt"/>
 | 
				
			||||
    </resultMap>
 | 
				
			||||
    
 | 
				
			||||
    <insert id="insert" parameterType="com.unilife.model.entity.Comment" useGeneratedKeys="true" keyProperty="id">
 | 
				
			||||
        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()
 | 
				
			||||
        )
 | 
				
			||||
    </insert>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getById" resultMap="commentResultMap">
 | 
				
			||||
        SELECT id, post_id, user_id, content, parent_id, like_count, status, created_at, updated_at
 | 
				
			||||
        FROM comments
 | 
				
			||||
        WHERE id = #{id} AND status != 0
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getTopLevelCommentsByPostId" resultMap="commentResultMap">
 | 
				
			||||
        SELECT id, post_id, user_id, content, parent_id, like_count, status, created_at, updated_at
 | 
				
			||||
        FROM comments
 | 
				
			||||
        WHERE post_id = #{postId} AND parent_id IS NULL AND status != 0
 | 
				
			||||
        ORDER BY created_at DESC
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getRepliesByParentId" resultMap="commentResultMap">
 | 
				
			||||
        SELECT id, post_id, user_id, content, parent_id, like_count, status, created_at, updated_at
 | 
				
			||||
        FROM comments
 | 
				
			||||
        WHERE parent_id = #{parentId} AND status != 0
 | 
				
			||||
        ORDER BY created_at ASC
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getCountByPostId" resultType="java.lang.Integer">
 | 
				
			||||
        SELECT COUNT(*)
 | 
				
			||||
        FROM comments
 | 
				
			||||
        WHERE post_id = #{postId} AND status != 0
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <update id="update" parameterType="com.unilife.model.entity.Comment">
 | 
				
			||||
        UPDATE comments
 | 
				
			||||
        SET content = #{content},
 | 
				
			||||
            updated_at = NOW()
 | 
				
			||||
        WHERE id = #{id}
 | 
				
			||||
    </update>
 | 
				
			||||
    
 | 
				
			||||
    <update id="delete">
 | 
				
			||||
        UPDATE comments
 | 
				
			||||
        SET status = 0,
 | 
				
			||||
            updated_at = NOW()
 | 
				
			||||
        WHERE id = #{id}
 | 
				
			||||
    </update>
 | 
				
			||||
    
 | 
				
			||||
    <update id="incrementLikeCount">
 | 
				
			||||
        UPDATE comments
 | 
				
			||||
        SET like_count = like_count + 1
 | 
				
			||||
        WHERE id = #{id}
 | 
				
			||||
    </update>
 | 
				
			||||
    
 | 
				
			||||
    <update id="decrementLikeCount">
 | 
				
			||||
        UPDATE comments
 | 
				
			||||
        SET like_count = GREATEST(like_count - 1, 0)
 | 
				
			||||
        WHERE id = #{id}
 | 
				
			||||
    </update>
 | 
				
			||||
</mapper>
 | 
				
			||||
@ -0,0 +1,89 @@
 | 
				
			||||
<?xml version="1.0" encoding="UTF-8" ?>
 | 
				
			||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 | 
				
			||||
<mapper namespace="com.unilife.mapper.CourseMapper">
 | 
				
			||||
    <resultMap id="courseResultMap" type="com.unilife.model.entity.Course">
 | 
				
			||||
        <id column="id" property="id"/>
 | 
				
			||||
        <result column="user_id" property="userId"/>
 | 
				
			||||
        <result column="name" property="name"/>
 | 
				
			||||
        <result column="teacher" property="teacher"/>
 | 
				
			||||
        <result column="location" property="location"/>
 | 
				
			||||
        <result column="day_of_week" property="dayOfWeek"/>
 | 
				
			||||
        <result column="start_time" property="startTime"/>
 | 
				
			||||
        <result column="end_time" property="endTime"/>
 | 
				
			||||
        <result column="start_week" property="startWeek"/>
 | 
				
			||||
        <result column="end_week" property="endWeek"/>
 | 
				
			||||
        <result column="color" property="color"/>
 | 
				
			||||
        <result column="status" property="status"/>
 | 
				
			||||
        <result column="created_at" property="createdAt"/>
 | 
				
			||||
        <result column="updated_at" property="updatedAt"/>
 | 
				
			||||
    </resultMap>
 | 
				
			||||
    
 | 
				
			||||
    <insert id="insert" parameterType="com.unilife.model.entity.Course" useGeneratedKeys="true" keyProperty="id">
 | 
				
			||||
        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()
 | 
				
			||||
        )
 | 
				
			||||
    </insert>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getById" resultMap="courseResultMap">
 | 
				
			||||
        SELECT id, user_id, name, teacher, location, day_of_week, start_time, end_time, 
 | 
				
			||||
               start_week, end_week, color, status, created_at, updated_at
 | 
				
			||||
        FROM courses
 | 
				
			||||
        WHERE id = #{id} AND status != 0
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getListByUserId" resultMap="courseResultMap">
 | 
				
			||||
        SELECT id, user_id, name, teacher, location, day_of_week, start_time, end_time, 
 | 
				
			||||
               start_week, end_week, color, status, created_at, updated_at
 | 
				
			||||
        FROM courses
 | 
				
			||||
        WHERE user_id = #{userId} AND status != 0
 | 
				
			||||
        ORDER BY day_of_week ASC, start_time ASC
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <update id="update" parameterType="com.unilife.model.entity.Course">
 | 
				
			||||
        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>
 | 
				
			||||
    
 | 
				
			||||
    <update id="delete">
 | 
				
			||||
        UPDATE courses
 | 
				
			||||
        SET status = 0,
 | 
				
			||||
            updated_at = NOW()
 | 
				
			||||
        WHERE id = #{id} AND user_id = #{userId}
 | 
				
			||||
    </update>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getListByUserIdAndDayOfWeek" resultMap="courseResultMap">
 | 
				
			||||
        SELECT id, user_id, name, teacher, location, day_of_week, start_time, end_time, 
 | 
				
			||||
               start_week, end_week, color, status, created_at, updated_at
 | 
				
			||||
        FROM courses
 | 
				
			||||
        WHERE user_id = #{userId} AND day_of_week = #{dayOfWeek} AND status != 0
 | 
				
			||||
        ORDER BY start_time ASC
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <select id="checkConflict" resultType="java.lang.Integer">
 | 
				
			||||
        SELECT COUNT(*)
 | 
				
			||||
        FROM courses
 | 
				
			||||
        WHERE user_id = #{userId} 
 | 
				
			||||
          AND day_of_week = #{dayOfWeek} 
 | 
				
			||||
          AND status != 0
 | 
				
			||||
          AND (
 | 
				
			||||
              (start_time < #{endTime} AND end_time > #{startTime})
 | 
				
			||||
          )
 | 
				
			||||
          <if test="excludeCourseId != null">
 | 
				
			||||
              AND id != #{excludeCourseId}
 | 
				
			||||
          </if>
 | 
				
			||||
    </select>
 | 
				
			||||
</mapper>
 | 
				
			||||
@ -0,0 +1,36 @@
 | 
				
			||||
<?xml version="1.0" encoding="UTF-8" ?>
 | 
				
			||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 | 
				
			||||
<mapper namespace="com.unilife.mapper.PostLikeMapper">
 | 
				
			||||
    
 | 
				
			||||
    <select id="isLiked" resultType="java.lang.Boolean">
 | 
				
			||||
        SELECT COUNT(*) > 0
 | 
				
			||||
        FROM post_likes
 | 
				
			||||
        WHERE post_id = #{postId} AND user_id = #{userId}
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <insert id="insert">
 | 
				
			||||
        INSERT INTO post_likes (
 | 
				
			||||
            user_id, post_id, created_at
 | 
				
			||||
        ) VALUES (
 | 
				
			||||
            #{userId}, #{postId}, NOW()
 | 
				
			||||
        )
 | 
				
			||||
    </insert>
 | 
				
			||||
    
 | 
				
			||||
    <delete id="delete">
 | 
				
			||||
        DELETE FROM post_likes
 | 
				
			||||
        WHERE post_id = #{postId} AND user_id = #{userId}
 | 
				
			||||
    </delete>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getCountByPostId" resultType="java.lang.Integer">
 | 
				
			||||
        SELECT COUNT(*)
 | 
				
			||||
        FROM post_likes
 | 
				
			||||
        WHERE post_id = #{postId}
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getLikedPostIdsByUserId" resultType="java.lang.Long">
 | 
				
			||||
        SELECT post_id
 | 
				
			||||
        FROM post_likes
 | 
				
			||||
        WHERE user_id = #{userId}
 | 
				
			||||
        ORDER BY created_at DESC
 | 
				
			||||
    </select>
 | 
				
			||||
</mapper>
 | 
				
			||||
@ -0,0 +1,119 @@
 | 
				
			||||
<?xml version="1.0" encoding="UTF-8" ?>
 | 
				
			||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 | 
				
			||||
<mapper namespace="com.unilife.mapper.ResourceMapper">
 | 
				
			||||
    <resultMap id="resourceResultMap" type="com.unilife.model.entity.Resource">
 | 
				
			||||
        <id column="id" property="id"/>
 | 
				
			||||
        <result column="user_id" property="userId"/>
 | 
				
			||||
        <result column="title" property="title"/>
 | 
				
			||||
        <result column="description" property="description"/>
 | 
				
			||||
        <result column="file_url" property="fileUrl"/>
 | 
				
			||||
        <result column="file_size" property="fileSize"/>
 | 
				
			||||
        <result column="file_type" property="fileType"/>
 | 
				
			||||
        <result column="category_id" property="categoryId"/>
 | 
				
			||||
        <result column="download_count" property="downloadCount"/>
 | 
				
			||||
        <result column="like_count" property="likeCount"/>
 | 
				
			||||
        <result column="status" property="status"/>
 | 
				
			||||
        <result column="created_at" property="createdAt"/>
 | 
				
			||||
        <result column="updated_at" property="updatedAt"/>
 | 
				
			||||
    </resultMap>
 | 
				
			||||
    
 | 
				
			||||
    <insert id="insert" parameterType="com.unilife.model.entity.Resource" useGeneratedKeys="true" keyProperty="id">
 | 
				
			||||
        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()
 | 
				
			||||
        )
 | 
				
			||||
    </insert>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getById" resultMap="resourceResultMap">
 | 
				
			||||
        SELECT id, user_id, title, description, file_url, file_size, file_type, category_id, 
 | 
				
			||||
               download_count, like_count, status, created_at, updated_at
 | 
				
			||||
        FROM resources
 | 
				
			||||
        WHERE id = #{id} AND status != 0
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getList" resultMap="resourceResultMap">
 | 
				
			||||
        SELECT id, user_id, title, description, file_url, file_size, file_type, category_id, 
 | 
				
			||||
               download_count, like_count, status, created_at, updated_at
 | 
				
			||||
        FROM resources
 | 
				
			||||
        <where>
 | 
				
			||||
            status != 0
 | 
				
			||||
            <if test="categoryId != null">
 | 
				
			||||
                AND category_id = #{categoryId}
 | 
				
			||||
            </if>
 | 
				
			||||
            <if test="userId != null">
 | 
				
			||||
                AND user_id = #{userId}
 | 
				
			||||
            </if>
 | 
				
			||||
            <if test="keyword != null and keyword != ''">
 | 
				
			||||
                AND (title LIKE CONCAT('%', #{keyword}, '%') OR description LIKE CONCAT('%', #{keyword}, '%'))
 | 
				
			||||
            </if>
 | 
				
			||||
        </where>
 | 
				
			||||
        ORDER BY created_at DESC
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getCount" resultType="java.lang.Integer">
 | 
				
			||||
        SELECT COUNT(*)
 | 
				
			||||
        FROM resources
 | 
				
			||||
        <where>
 | 
				
			||||
            status != 0
 | 
				
			||||
            <if test="categoryId != null">
 | 
				
			||||
                AND category_id = #{categoryId}
 | 
				
			||||
            </if>
 | 
				
			||||
            <if test="userId != null">
 | 
				
			||||
                AND user_id = #{userId}
 | 
				
			||||
            </if>
 | 
				
			||||
            <if test="keyword != null and keyword != ''">
 | 
				
			||||
                AND (title LIKE CONCAT('%', #{keyword}, '%') OR description LIKE CONCAT('%', #{keyword}, '%'))
 | 
				
			||||
            </if>
 | 
				
			||||
        </where>
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <update id="update" parameterType="com.unilife.model.entity.Resource">
 | 
				
			||||
        UPDATE resources
 | 
				
			||||
        SET title = #{title},
 | 
				
			||||
            description = #{description},
 | 
				
			||||
            category_id = #{categoryId},
 | 
				
			||||
            status = #{status},
 | 
				
			||||
            updated_at = NOW()
 | 
				
			||||
        WHERE id = #{id}
 | 
				
			||||
    </update>
 | 
				
			||||
    
 | 
				
			||||
    <update id="delete">
 | 
				
			||||
        UPDATE resources
 | 
				
			||||
        SET status = 0,
 | 
				
			||||
            updated_at = NOW()
 | 
				
			||||
        WHERE id = #{id}
 | 
				
			||||
    </update>
 | 
				
			||||
    
 | 
				
			||||
    <update id="incrementDownloadCount">
 | 
				
			||||
        UPDATE resources
 | 
				
			||||
        SET download_count = download_count + 1
 | 
				
			||||
        WHERE id = #{id}
 | 
				
			||||
    </update>
 | 
				
			||||
    
 | 
				
			||||
    <update id="incrementLikeCount">
 | 
				
			||||
        UPDATE resources
 | 
				
			||||
        SET like_count = like_count + 1
 | 
				
			||||
        WHERE id = #{id}
 | 
				
			||||
    </update>
 | 
				
			||||
    
 | 
				
			||||
    <update id="decrementLikeCount">
 | 
				
			||||
        UPDATE resources
 | 
				
			||||
        SET like_count = GREATEST(like_count - 1, 0)
 | 
				
			||||
        WHERE id = #{id}
 | 
				
			||||
    </update>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getCountByUserId" resultType="java.lang.Integer">
 | 
				
			||||
        SELECT COUNT(*)
 | 
				
			||||
        FROM resources
 | 
				
			||||
        WHERE user_id = #{userId} AND status != 0
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getCountByCategoryId" resultType="java.lang.Integer">
 | 
				
			||||
        SELECT COUNT(*)
 | 
				
			||||
        FROM resources
 | 
				
			||||
        WHERE category_id = #{categoryId} AND status != 0
 | 
				
			||||
    </select>
 | 
				
			||||
</mapper>
 | 
				
			||||
@ -0,0 +1,102 @@
 | 
				
			||||
<?xml version="1.0" encoding="UTF-8" ?>
 | 
				
			||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 | 
				
			||||
<mapper namespace="com.unilife.mapper.ScheduleMapper">
 | 
				
			||||
    <resultMap id="scheduleResultMap" type="com.unilife.model.entity.Schedule">
 | 
				
			||||
        <id column="id" property="id"/>
 | 
				
			||||
        <result column="user_id" property="userId"/>
 | 
				
			||||
        <result column="title" property="title"/>
 | 
				
			||||
        <result column="description" property="description"/>
 | 
				
			||||
        <result column="start_time" property="startTime"/>
 | 
				
			||||
        <result column="end_time" property="endTime"/>
 | 
				
			||||
        <result column="location" property="location"/>
 | 
				
			||||
        <result column="is_all_day" property="isAllDay"/>
 | 
				
			||||
        <result column="reminder" property="reminder"/>
 | 
				
			||||
        <result column="color" property="color"/>
 | 
				
			||||
        <result column="status" property="status"/>
 | 
				
			||||
        <result column="created_at" property="createdAt"/>
 | 
				
			||||
        <result column="updated_at" property="updatedAt"/>
 | 
				
			||||
    </resultMap>
 | 
				
			||||
    
 | 
				
			||||
    <insert id="insert" parameterType="com.unilife.model.entity.Schedule" useGeneratedKeys="true" keyProperty="id">
 | 
				
			||||
        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()
 | 
				
			||||
        )
 | 
				
			||||
    </insert>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getById" resultMap="scheduleResultMap">
 | 
				
			||||
        SELECT id, user_id, title, description, start_time, end_time, location, 
 | 
				
			||||
               is_all_day, reminder, color, status, created_at, updated_at
 | 
				
			||||
        FROM schedules
 | 
				
			||||
        WHERE id = #{id} AND status != 0
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getListByUserId" resultMap="scheduleResultMap">
 | 
				
			||||
        SELECT id, user_id, title, description, start_time, end_time, location, 
 | 
				
			||||
               is_all_day, reminder, color, status, created_at, updated_at
 | 
				
			||||
        FROM schedules
 | 
				
			||||
        WHERE user_id = #{userId} AND status != 0
 | 
				
			||||
        ORDER BY start_time ASC
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getListByUserIdAndTimeRange" resultMap="scheduleResultMap">
 | 
				
			||||
        SELECT id, user_id, title, description, start_time, end_time, location, 
 | 
				
			||||
               is_all_day, reminder, color, status, created_at, updated_at
 | 
				
			||||
        FROM schedules
 | 
				
			||||
        WHERE user_id = #{userId} 
 | 
				
			||||
          AND status != 0
 | 
				
			||||
          AND (
 | 
				
			||||
              (start_time <= #{endTime} AND end_time >= #{startTime})
 | 
				
			||||
              OR (is_all_day = 1 AND DATE(start_time) <= DATE(#{endTime}) AND DATE(end_time) >= DATE(#{startTime}))
 | 
				
			||||
          )
 | 
				
			||||
        ORDER BY start_time ASC
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <update id="update" parameterType="com.unilife.model.entity.Schedule">
 | 
				
			||||
        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>
 | 
				
			||||
    
 | 
				
			||||
    <update id="delete">
 | 
				
			||||
        UPDATE schedules
 | 
				
			||||
        SET status = 0,
 | 
				
			||||
            updated_at = NOW()
 | 
				
			||||
        WHERE id = #{id} AND user_id = #{userId}
 | 
				
			||||
    </update>
 | 
				
			||||
    
 | 
				
			||||
    <select id="checkConflict" resultType="java.lang.Integer">
 | 
				
			||||
        SELECT COUNT(*)
 | 
				
			||||
        FROM schedules
 | 
				
			||||
        WHERE user_id = #{userId} 
 | 
				
			||||
          AND status != 0
 | 
				
			||||
          AND (
 | 
				
			||||
              (start_time < #{endTime} AND end_time > #{startTime})
 | 
				
			||||
          )
 | 
				
			||||
          <if test="excludeScheduleId != null">
 | 
				
			||||
              AND id != #{excludeScheduleId}
 | 
				
			||||
          </if>
 | 
				
			||||
    </select>
 | 
				
			||||
    
 | 
				
			||||
    <select id="getSchedulesToRemind" resultMap="scheduleResultMap">
 | 
				
			||||
        SELECT id, user_id, title, description, start_time, end_time, location, 
 | 
				
			||||
               is_all_day, reminder, color, status, created_at, updated_at
 | 
				
			||||
        FROM schedules
 | 
				
			||||
        WHERE status != 0
 | 
				
			||||
          AND reminder IS NOT NULL
 | 
				
			||||
          AND DATE_ADD(#{currentTime}, INTERVAL reminder MINUTE) >= start_time
 | 
				
			||||
          AND DATE_ADD(#{currentTime}, INTERVAL reminder + #{reminderMinutes} MINUTE) <= start_time
 | 
				
			||||
        ORDER BY start_time ASC
 | 
				
			||||
    </select>
 | 
				
			||||
</mapper>
 | 
				
			||||
					Loading…
					
					
				
		Reference in new issue