feat: 🎸 课程报名&查询报名情况接口
This commit is contained in:
parent
3d9fda6230
commit
7188b7a500
@ -12,6 +12,7 @@ import org.jeecg.config.shiro.IgnoreAuth;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -29,6 +30,7 @@ import org.jeecg.modules.gen.resource.entity.Resource;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@ -139,6 +141,27 @@ public class CourseBizController {
|
||||
return Result.OK(list);
|
||||
}
|
||||
|
||||
@PostMapping("/{courseId}/enroll")
|
||||
@Operation(summary = "报名课程", description = "该接口需要携带用户登录token。根据课程id报名课程。返回值为报名结果,报名成功返回success")
|
||||
public Result<String> enrollCourse(@PathVariable(value = "courseId") String courseId, HttpServletRequest request, HttpServletResponse response) {
|
||||
String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
|
||||
String username = JwtUtil.getUsername(token);
|
||||
LoginUser sysUser = sysBaseApi.getUserByName(username);
|
||||
String result = courseBizService.enrollCourse(courseId, sysUser.getId());
|
||||
return Result.OK(result);
|
||||
}
|
||||
|
||||
@GetMapping("/{courseId}/is_enrolled")
|
||||
@Operation(summary = "查询课程是否已报名", description = "该接口需要携带用户登录token。根据课程id查询课程是否已报名。判断返回值的result是否为true")
|
||||
public Result<Boolean> isEnrolled(@PathVariable(value = "courseId") String courseId, HttpServletRequest request, HttpServletResponse response) {
|
||||
String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
|
||||
String username = JwtUtil.getUsername(token);
|
||||
LoginUser sysUser = sysBaseApi.getUserByName(username);
|
||||
|
||||
boolean isEnrolled = courseBizService.isEnrolled(courseId, sysUser.getId());
|
||||
return Result.OK(isEnrolled);
|
||||
}
|
||||
|
||||
@GetMapping("/test")
|
||||
@IgnoreAuth
|
||||
public Result<String> test() {
|
||||
|
@ -64,6 +64,22 @@ public interface CourseBizService extends IService<Course> {
|
||||
* @return
|
||||
*/
|
||||
List<TeacherInfo> getCourseTeacherList(String courseId);
|
||||
|
||||
/**
|
||||
* 报名课程
|
||||
* @param courseId
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
String enrollCourse(String courseId, String id);
|
||||
|
||||
/**
|
||||
* 查询课程是否已报名
|
||||
* @param courseId
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
boolean isEnrolled(String courseId, String id);
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,6 +16,8 @@ import org.jeecg.modules.gen.coursecategory.entity.CourseCategory;
|
||||
import org.jeecg.modules.gen.coursecategory.mapper.CourseCategoryMapper;
|
||||
import org.jeecg.modules.gen.coursesection.entity.CourseSection;
|
||||
import org.jeecg.modules.gen.coursesection.mapper.CourseSectionMapper;
|
||||
import org.jeecg.modules.gen.coursesignup.entity.CourseSignup;
|
||||
import org.jeecg.modules.gen.coursesignup.mapper.CourseSignupMapper;
|
||||
import org.jeecg.modules.gen.courseteacher.entity.CourseTeacher;
|
||||
import org.jeecg.modules.gen.courseteacher.mapper.CourseTeacherMapper;
|
||||
import org.jeecg.modules.gen.homework.mapper.HomeworkMapper;
|
||||
@ -27,6 +29,7 @@ import org.jeecg.modules.system.mapper.SysUserMapper;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@ -41,6 +44,7 @@ import java.nio.file.StandardCopyOption;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@ -73,6 +77,9 @@ public class CourseBizServiceImpl extends ServiceImpl<CourseMapper, Course> impl
|
||||
@Autowired
|
||||
private HomeworkMapper homeworkMapper;
|
||||
|
||||
@Autowired
|
||||
private CourseSignupMapper courseSignupMapper;
|
||||
|
||||
@Override
|
||||
public <T> List<T> getCourseSectionDetail(Integer type, String sectionId, Class<T> clazz) {
|
||||
// 1. 查询章节是否存在
|
||||
@ -352,6 +359,71 @@ public class CourseBizServiceImpl extends ServiceImpl<CourseMapper, Course> impl
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String enrollCourse(String courseId, String userId) {
|
||||
// 1. 参数校验
|
||||
if (courseId == null || courseId.trim().isEmpty()) {
|
||||
throw new RuntimeException("课程ID不能为空");
|
||||
}
|
||||
if (userId == null || userId.trim().isEmpty()) {
|
||||
throw new RuntimeException("用户ID不能为空");
|
||||
}
|
||||
|
||||
// 2. 查询课程是否存在
|
||||
Course course = courseMapper.selectById(courseId);
|
||||
if (course == null) {
|
||||
throw new RuntimeException("课程不存在");
|
||||
}
|
||||
|
||||
// 3. 检查用户是否已报名
|
||||
QueryWrapper<CourseSignup> signupQuery = new QueryWrapper<>();
|
||||
signupQuery.eq("user_id", userId).eq("course_id", courseId);
|
||||
CourseSignup existingSignup = courseSignupMapper.selectOne(signupQuery);
|
||||
if (existingSignup != null) {
|
||||
return "success"; // 已报名
|
||||
}
|
||||
|
||||
// 4. 检查课程是否可以报名
|
||||
if (course.getStatus() != null && course.getStatus() != 1) {
|
||||
throw new RuntimeException("课程当前状态不允许报名");
|
||||
}
|
||||
|
||||
// 5. 检查报名人数是否已满
|
||||
if (course.getMaxEnroll() != null && course.getEnrollCount() != null) {
|
||||
if (course.getEnrollCount() >= course.getMaxEnroll()) {
|
||||
throw new RuntimeException("报名人数已满");
|
||||
}
|
||||
}
|
||||
|
||||
// 6. 创建报名记录
|
||||
CourseSignup signup = new CourseSignup();
|
||||
signup.setUserId(userId);
|
||||
signup.setCourseId(courseId);
|
||||
signup.setCreateTime(new Date());
|
||||
signup.setCreateBy(userId);
|
||||
|
||||
int insertResult = courseSignupMapper.insert(signup);
|
||||
if (insertResult <= 0) {
|
||||
throw new RuntimeException("报名失败");
|
||||
}
|
||||
|
||||
// 7. 更新课程报名人数
|
||||
int currentEnrollCount = course.getEnrollCount() == null ? 0 : course.getEnrollCount();
|
||||
course.setEnrollCount(currentEnrollCount + 1);
|
||||
courseMapper.updateById(course);
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnrolled(String courseId, String userId) {
|
||||
QueryWrapper<CourseSignup> signupQuery = new QueryWrapper<>();
|
||||
signupQuery.eq("user_id", userId).eq("course_id", courseId);
|
||||
CourseSignup existingSignup = courseSignupMapper.selectOne(signupQuery);
|
||||
return existingSignup != null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,182 @@
|
||||
package org.jeecg.modules.gen.coursesignup.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.system.query.QueryRuleEnum;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.gen.coursesignup.entity.CourseSignup;
|
||||
import org.jeecg.modules.gen.coursesignup.service.ICourseSignupService;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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 com.alibaba.fastjson.JSON;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
/**
|
||||
* @Description: 课程报名
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-08-19
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Tag(name="课程报名")
|
||||
@RestController
|
||||
@RequestMapping("/gen/coursesignup/courseSignup")
|
||||
@Slf4j
|
||||
public class CourseSignupController extends JeecgController<CourseSignup, ICourseSignupService> {
|
||||
@Autowired
|
||||
private ICourseSignupService courseSignupService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param courseSignup
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "课程报名-分页列表查询")
|
||||
@Operation(summary="课程报名-分页列表查询")
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<CourseSignup>> queryPageList(CourseSignup courseSignup,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
|
||||
|
||||
QueryWrapper<CourseSignup> queryWrapper = QueryGenerator.initQueryWrapper(courseSignup, req.getParameterMap());
|
||||
Page<CourseSignup> page = new Page<CourseSignup>(pageNo, pageSize);
|
||||
IPage<CourseSignup> pageList = courseSignupService.page(page, queryWrapper);
|
||||
return Result.OK(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param courseSignup
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "课程报名-添加")
|
||||
@Operation(summary="课程报名-添加")
|
||||
@RequiresPermissions("gen.coursesignup:course_signup:add")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<String> add(@RequestBody CourseSignup courseSignup) {
|
||||
courseSignupService.save(courseSignup);
|
||||
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param courseSignup
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "课程报名-编辑")
|
||||
@Operation(summary="课程报名-编辑")
|
||||
@RequiresPermissions("gen.coursesignup:course_signup:edit")
|
||||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
||||
public Result<String> edit(@RequestBody CourseSignup courseSignup) {
|
||||
courseSignupService.updateById(courseSignup);
|
||||
return Result.OK("编辑成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "课程报名-通过id删除")
|
||||
@Operation(summary="课程报名-通过id删除")
|
||||
@RequiresPermissions("gen.coursesignup:course_signup:delete")
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
||||
courseSignupService.removeById(id);
|
||||
return Result.OK("删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "课程报名-批量删除")
|
||||
@Operation(summary="课程报名-批量删除")
|
||||
@RequiresPermissions("gen.coursesignup:course_signup:deleteBatch")
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
||||
this.courseSignupService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Result.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "课程报名-通过id查询")
|
||||
@Operation(summary="课程报名-通过id查询")
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<CourseSignup> queryById(@RequestParam(name="id",required=true) String id) {
|
||||
CourseSignup courseSignup = courseSignupService.getById(id);
|
||||
if(courseSignup==null) {
|
||||
return Result.error("未找到对应数据");
|
||||
}
|
||||
return Result.OK(courseSignup);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param courseSignup
|
||||
*/
|
||||
@RequiresPermissions("gen.coursesignup:course_signup:exportXls")
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, CourseSignup courseSignup) {
|
||||
return super.exportXls(request, courseSignup, CourseSignup.class, "课程报名");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("gen.coursesignup:course_signup:importExcel")
|
||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, CourseSignup.class);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package org.jeecg.modules.gen.coursesignup.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
import java.math.BigDecimal;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import org.jeecg.common.constant.ProvinceCityArea;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.jeecg.common.aspect.annotation.Dict;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @Description: 课程报名
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-08-19
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("course_signup")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Schema(description="课程报名")
|
||||
public class CourseSignup implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**主键*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "主键")
|
||||
private java.lang.String id;
|
||||
/**用户id*/
|
||||
@Excel(name = "用户id", width = 15)
|
||||
@Schema(description = "用户id")
|
||||
private java.lang.String userId;
|
||||
/**课程id*/
|
||||
@Excel(name = "课程id", width = 15)
|
||||
@Schema(description = "课程id")
|
||||
private java.lang.String courseId;
|
||||
/**创建人*/
|
||||
@Schema(description = "创建人")
|
||||
private java.lang.String createBy;
|
||||
/**创建日期*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "创建日期")
|
||||
private java.util.Date createTime;
|
||||
/**更新人*/
|
||||
@Schema(description = "更新人")
|
||||
private java.lang.String updateBy;
|
||||
/**更新日期*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "更新日期")
|
||||
private java.util.Date updateTime;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package org.jeecg.modules.gen.coursesignup.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.modules.gen.coursesignup.entity.CourseSignup;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @Description: 课程报名
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-08-19
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface CourseSignupMapper extends BaseMapper<CourseSignup> {
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
<?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="org.jeecg.modules.gen.coursesignup.mapper.CourseSignupMapper">
|
||||
|
||||
</mapper>
|
@ -0,0 +1,14 @@
|
||||
package org.jeecg.modules.gen.coursesignup.service;
|
||||
|
||||
import org.jeecg.modules.gen.coursesignup.entity.CourseSignup;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @Description: 课程报名
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-08-19
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface ICourseSignupService extends IService<CourseSignup> {
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package org.jeecg.modules.gen.coursesignup.service.impl;
|
||||
|
||||
import org.jeecg.modules.gen.coursesignup.entity.CourseSignup;
|
||||
import org.jeecg.modules.gen.coursesignup.mapper.CourseSignupMapper;
|
||||
import org.jeecg.modules.gen.coursesignup.service.ICourseSignupService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
/**
|
||||
* @Description: 课程报名
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-08-19
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class CourseSignupServiceImpl extends ServiceImpl<CourseSignupMapper, CourseSignup> implements ICourseSignupService {
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user