feat: 🎸 新建课程携带分类id

This commit is contained in:
GoCo 2025-09-12 17:45:21 +08:00
parent a4fe5c17e6
commit 8f1fec0169
3 changed files with 156 additions and 4 deletions

View File

@ -19,6 +19,7 @@ import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils; import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.shiro.IgnoreAuth; import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.aiol.dto.CourseWithTeacherInfo; import org.jeecg.modules.aiol.dto.CourseWithTeacherInfo;
import org.jeecg.modules.aiol.dto.AiolCourseSaveDTO;
import org.jeecg.modules.aiol.dto.TeacherInfo; import org.jeecg.modules.aiol.dto.TeacherInfo;
import org.jeecg.modules.aiol.entity.*; import org.jeecg.modules.aiol.entity.*;
import org.jeecg.modules.aiol.service.IAiolCourseService; import org.jeecg.modules.aiol.service.IAiolCourseService;
@ -27,6 +28,7 @@ import org.jeecg.modules.aiol.service.IAiolEntityPermissionService;
import org.jeecg.modules.aiol.constant.EntityPermissionConst; import org.jeecg.modules.aiol.constant.EntityPermissionConst;
import org.jeecg.modules.aiol.mapper.AiolCourseSignupMapper; import org.jeecg.modules.aiol.mapper.AiolCourseSignupMapper;
import org.jeecg.modules.aiol.mapper.AiolCourseTeacherMapper; import org.jeecg.modules.aiol.mapper.AiolCourseTeacherMapper;
import org.jeecg.modules.aiol.mapper.AiolEntityLinkMapper;
import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.mapper.SysUserMapper; import org.jeecg.modules.system.mapper.SysUserMapper;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@ -47,6 +49,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -100,8 +103,21 @@ public class AiolCourseController extends JeecgController<AiolCourse, IAiolCours
@Operation(summary = "课程-添加") @Operation(summary = "课程-添加")
@RequiresPermissions("aiol:aiol_course:add") @RequiresPermissions("aiol:aiol_course:add")
@PostMapping(value = "/add") @PostMapping(value = "/add")
public Result<String> add(@RequestBody AiolCourse aiolCourse) { @Transactional(rollbackFor = Exception.class)
aiolCourseService.save(aiolCourse); public Result<String> add(@RequestBody AiolCourseSaveDTO dto) {
aiolCourseService.save(dto);
String categoryId = dto.getCategoryId();
if (categoryId != null && !categoryId.trim().isEmpty()) {
AiolEntityLink link = new AiolEntityLink();
link.setSourceType("course_category");
link.setSourceId(categoryId);
link.setTargetType("course");
link.setTargetId(dto.getId());
link.setCreateBy(dto.getCreateBy());
link.setCreateTime(new Date());
entityLinkMapper.insert(link);
}
return Result.OK("添加成功!"); return Result.OK("添加成功!");
} }
@ -116,8 +132,27 @@ public class AiolCourseController extends JeecgController<AiolCourse, IAiolCours
@Operation(summary = "课程-编辑") @Operation(summary = "课程-编辑")
@RequiresPermissions("aiol:aiol_course:edit") @RequiresPermissions("aiol:aiol_course:edit")
@RequestMapping(value = "/edit", method = { RequestMethod.PUT, RequestMethod.POST }) @RequestMapping(value = "/edit", method = { RequestMethod.PUT, RequestMethod.POST })
public Result<String> edit(@RequestBody AiolCourse aiolCourse) { @Transactional(rollbackFor = Exception.class)
aiolCourseService.updateById(aiolCourse); public Result<String> edit(@RequestBody AiolCourseSaveDTO dto) {
aiolCourseService.updateById(dto);
QueryWrapper<AiolEntityLink> deleteWrapper = new QueryWrapper<>();
deleteWrapper.eq("target_type", "course").eq("target_id", dto.getId())
.eq("source_type", "course_category");
entityLinkMapper.delete(deleteWrapper);
String categoryId = dto.getCategoryId();
if (categoryId != null && !categoryId.trim().isEmpty()) {
AiolEntityLink link = new AiolEntityLink();
link.setSourceType("course_category");
link.setSourceId(categoryId);
link.setTargetType("course");
link.setTargetId(dto.getId());
link.setCreateBy(dto.getUpdateBy());
link.setCreateTime(new Date());
entityLinkMapper.insert(link);
}
return Result.OK("编辑成功!"); return Result.OK("编辑成功!");
} }
@ -205,6 +240,8 @@ public class AiolCourseController extends JeecgController<AiolCourse, IAiolCours
private SysUserMapper sysUserMapper; private SysUserMapper sysUserMapper;
@Autowired @Autowired
private AiolCourseTeacherMapper courseTeacherMapper; private AiolCourseTeacherMapper courseTeacherMapper;
@Autowired
private AiolEntityLinkMapper entityLinkMapper;
@GetMapping("/query_list") @GetMapping("/query_list")
@Operation(summary = "学员端-查询课程列表", description = "可根据分类、难度、专题进行检索三个参数可任意传递其中之一、之二或全部每个参数可传递多个值用英文逗号分割不传参或传递all则查询所有课程携带讲师信息") @Operation(summary = "学员端-查询课程列表", description = "可根据分类、难度、专题进行检索三个参数可任意传递其中之一、之二或全部每个参数可传递多个值用英文逗号分割不传参或传递all则查询所有课程携带讲师信息")

View File

@ -16,6 +16,10 @@ import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.common.util.oConvertUtils; import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.aiol.entity.AiolUserFollow; import org.jeecg.modules.aiol.entity.AiolUserFollow;
import org.jeecg.modules.aiol.service.IAiolUserFollowService; import org.jeecg.modules.aiol.service.IAiolUserFollowService;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.LoginUser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@ -33,6 +37,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.util.Date;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -51,6 +56,8 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
public class AiolUserFollowController extends JeecgController<AiolUserFollow, IAiolUserFollowService> { public class AiolUserFollowController extends JeecgController<AiolUserFollow, IAiolUserFollowService> {
@Autowired @Autowired
private IAiolUserFollowService aiolUserFollowService; private IAiolUserFollowService aiolUserFollowService;
@Autowired
private ISysBaseAPI sysBaseApi;
/** /**
* 分页列表查询 * 分页列表查询
@ -154,6 +161,97 @@ public class AiolUserFollowController extends JeecgController<AiolUserFollow, IA
return Result.OK(aiolUserFollow); return Result.OK(aiolUserFollow);
} }
/**
* 关注用户
*
* @param followedId 被关注者ID
* @param request
* @return
*/
@AutoLog(value = "关注关系-关注用户")
@Operation(summary="关注用户", description = "当前登录用户关注指定用户")
@PostMapping(value = "/follow")
public Result<String> follow(@RequestParam(name="followedId", required=true) String followedId,
HttpServletRequest request) {
try {
// 1. 获取当前登录用户信息
String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
String username = JwtUtil.getUsername(token);
LoginUser sysUser = sysBaseApi.getUserByName(username);
if (sysUser == null) {
return Result.error("用户未登录或登录已过期");
}
// 2. 检查是否已经关注
QueryWrapper<AiolUserFollow> checkWrapper = new QueryWrapper<>();
checkWrapper.eq("follower_id", sysUser.getId())
.eq("followed_id", followedId);
AiolUserFollow existingFollow = aiolUserFollowService.getOne(checkWrapper);
if (existingFollow != null) {
return Result.error("已经关注过该用户");
}
// 3. 检查是否关注自己
if (sysUser.getId().equals(followedId)) {
return Result.error("不能关注自己");
}
// 4. 创建关注关系
AiolUserFollow userFollow = new AiolUserFollow();
userFollow.setFollowerId(sysUser.getId());
userFollow.setFollowedId(followedId);
userFollow.setCreateBy(sysUser.getUsername());
userFollow.setCreateTime(new Date());
aiolUserFollowService.save(userFollow);
return Result.OK("关注成功!");
} catch (Exception e) {
log.error("关注用户失败: followedId={}, error={}", followedId, e.getMessage(), e);
return Result.error("关注失败: " + e.getMessage());
}
}
/**
* 取消关注用户
*
* @param followedId 被关注者ID
* @param request
* @return
*/
@AutoLog(value = "关注关系-取消关注用户")
@Operation(summary="取消关注用户", description = "当前登录用户取消关注指定用户")
@DeleteMapping(value = "/unfollow")
public Result<String> unfollow(@RequestParam(name="followedId", required=true) String followedId,
HttpServletRequest request) {
try {
// 1. 获取当前登录用户信息
String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
String username = JwtUtil.getUsername(token);
LoginUser sysUser = sysBaseApi.getUserByName(username);
if (sysUser == null) {
return Result.error("用户未登录或登录已过期");
}
// 2. 查找关注关系
QueryWrapper<AiolUserFollow> deleteWrapper = new QueryWrapper<>();
deleteWrapper.eq("follower_id", sysUser.getId())
.eq("followed_id", followedId);
boolean removed = aiolUserFollowService.remove(deleteWrapper);
if (removed) {
return Result.OK("取消关注成功!");
} else {
return Result.error("未找到关注关系");
}
} catch (Exception e) {
log.error("取消关注用户失败: followedId={}, error={}", followedId, e.getMessage(), e);
return Result.error("取消关注失败: " + e.getMessage());
}
}
/** /**
* 导出excel * 导出excel
* *

View File

@ -0,0 +1,17 @@
package org.jeecg.modules.aiol.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.jeecg.modules.aiol.entity.AiolCourse;
@Data
@EqualsAndHashCode(callSuper = false)
@Schema(description = "课程保存DTO扩展课程分类")
public class AiolCourseSaveDTO extends AiolCourse {
@Schema(description = "课程分类ID")
private String categoryId;
}