Compare commits
2 Commits
a4fe5c17e6
...
132b020763
Author | SHA1 | Date | |
---|---|---|---|
![]() |
132b020763 | ||
![]() |
8f1fec0169 |
@ -19,6 +19,7 @@ import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.config.shiro.IgnoreAuth;
|
||||
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.entity.*;
|
||||
import org.jeecg.modules.aiol.service.IAiolCourseService;
|
||||
@ -27,6 +28,8 @@ import org.jeecg.modules.aiol.service.IAiolEntityPermissionService;
|
||||
import org.jeecg.modules.aiol.constant.EntityPermissionConst;
|
||||
import org.jeecg.modules.aiol.mapper.AiolCourseSignupMapper;
|
||||
import org.jeecg.modules.aiol.mapper.AiolCourseTeacherMapper;
|
||||
import org.jeecg.modules.aiol.mapper.AiolEntityLinkMapper;
|
||||
import org.jeecg.modules.aiol.mapper.AiolClassStudentMapper;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.mapper.SysUserMapper;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@ -47,6 +50,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -100,8 +104,93 @@ public class AiolCourseController extends JeecgController<AiolCourse, IAiolCours
|
||||
@Operation(summary = "课程-添加")
|
||||
@RequiresPermissions("aiol:aiol_course:add")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<String> add(@RequestBody AiolCourse aiolCourse) {
|
||||
aiolCourseService.save(aiolCourse);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<String> add(@RequestBody AiolCourse dto) {
|
||||
aiolCourseService.save(dto);
|
||||
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param aiolCourse
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "课程-教师端添加")
|
||||
@Operation(summary = "课程-教师端添加", description = "添加课程并关联分类,同时根据班级ID将班级学生添加到课程报名表")
|
||||
@RequiresPermissions("aiol:aiol_course:add")
|
||||
@PostMapping(value = "/teacher_add")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<String> teacherAdd(@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);
|
||||
}
|
||||
|
||||
// 如果提供了班级ID,将班级学生添加到课程报名表
|
||||
String classId = dto.getClassId();
|
||||
if (classId != null && !classId.trim().isEmpty()) {
|
||||
try {
|
||||
// 1. 根据班级ID查询学生列表
|
||||
QueryWrapper<AiolClassStudent> studentWrapper = new QueryWrapper<>();
|
||||
studentWrapper.eq("class_id", classId);
|
||||
List<AiolClassStudent> classStudents = classStudentMapper.selectList(studentWrapper);
|
||||
|
||||
if (!classStudents.isEmpty()) {
|
||||
// 2. 检查已存在的报名记录,避免重复添加
|
||||
List<String> studentIds = classStudents.stream()
|
||||
.map(AiolClassStudent::getStudentId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
QueryWrapper<AiolCourseSignup> existingWrapper = new QueryWrapper<>();
|
||||
existingWrapper.eq("course_id", dto.getId())
|
||||
.in("user_id", studentIds);
|
||||
List<AiolCourseSignup> existingSignups = courseSignupMapper.selectList(existingWrapper);
|
||||
|
||||
// 3. 过滤掉已存在的学生ID
|
||||
Set<String> existingStudentIds = existingSignups.stream()
|
||||
.map(AiolCourseSignup::getUserId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<String> newStudentIds = studentIds.stream()
|
||||
.filter(id -> !existingStudentIds.contains(id))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 4. 为未报名的学生创建报名记录
|
||||
if (!newStudentIds.isEmpty()) {
|
||||
for (String studentId : newStudentIds) {
|
||||
AiolCourseSignup signup = new AiolCourseSignup();
|
||||
signup.setCourseId(dto.getId());
|
||||
signup.setUserId(studentId);
|
||||
signup.setCreateBy(dto.getCreateBy());
|
||||
signup.setCreateTime(new Date());
|
||||
courseSignupMapper.insert(signup);
|
||||
}
|
||||
|
||||
log.info("成功为课程 {} 添加班级 {} 的学生,新增报名记录 {} 条",
|
||||
dto.getId(), classId, newStudentIds.size());
|
||||
} else {
|
||||
log.info("班级 {} 的所有学生已报名课程 {}", classId, dto.getId());
|
||||
}
|
||||
} else {
|
||||
log.warn("班级 {} 中没有找到学生", classId);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("为课程 {} 添加班级 {} 学生失败: {}", dto.getId(), classId, e.getMessage(), e);
|
||||
// 不抛出异常,避免影响课程创建
|
||||
}
|
||||
}
|
||||
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
@ -116,8 +205,27 @@ public class AiolCourseController extends JeecgController<AiolCourse, IAiolCours
|
||||
@Operation(summary = "课程-编辑")
|
||||
@RequiresPermissions("aiol:aiol_course:edit")
|
||||
@RequestMapping(value = "/edit", method = { RequestMethod.PUT, RequestMethod.POST })
|
||||
public Result<String> edit(@RequestBody AiolCourse aiolCourse) {
|
||||
aiolCourseService.updateById(aiolCourse);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
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("编辑成功!");
|
||||
}
|
||||
|
||||
@ -205,6 +313,10 @@ public class AiolCourseController extends JeecgController<AiolCourse, IAiolCours
|
||||
private SysUserMapper sysUserMapper;
|
||||
@Autowired
|
||||
private AiolCourseTeacherMapper courseTeacherMapper;
|
||||
@Autowired
|
||||
private AiolEntityLinkMapper entityLinkMapper;
|
||||
@Autowired
|
||||
private AiolClassStudentMapper classStudentMapper;
|
||||
|
||||
@GetMapping("/query_list")
|
||||
@Operation(summary = "学员端-查询课程列表", description = "可根据分类、难度、专题进行检索,三个参数可任意传递其中之一、之二或全部,每个参数可传递多个值,用英文逗号分割,不传参或传递all则查询所有课程,携带讲师信息")
|
||||
|
@ -16,6 +16,10 @@ import org.jeecg.common.system.query.QueryRuleEnum;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.aiol.entity.AiolUserFollow;
|
||||
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.metadata.IPage;
|
||||
@ -33,6 +37,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import java.util.Date;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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> {
|
||||
@Autowired
|
||||
private IAiolUserFollowService aiolUserFollowService;
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseApi;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
@ -154,6 +161,97 @@ public class AiolUserFollowController extends JeecgController<AiolUserFollow, IA
|
||||
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
|
||||
*
|
||||
|
@ -0,0 +1,20 @@
|
||||
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;
|
||||
|
||||
@Schema(description = "班级ID")
|
||||
private String classId;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user