课程(教师)增删改查,删除功能待完善

课程目标增删改,查需求不明确,待定
master
Alan 8 months ago
parent be5f518612
commit b2e1335220
  1. 6
      pom.xml
  2. 2
      src/main/java/com/teaching/backend/common/ErrorCode.java
  3. 64
      src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java
  4. 81
      src/main/java/com/teaching/backend/controller/courses/CoursesController.java
  5. 16
      src/main/java/com/teaching/backend/mapper/courses/CourseObjectivesMapper.java
  6. 16
      src/main/java/com/teaching/backend/mapper/courses/CoursesMapper.java
  7. 39
      src/main/java/com/teaching/backend/model/dto/courses/CourseObjectivesDTO.java
  8. 100
      src/main/java/com/teaching/backend/model/dto/courses/CoursesDTO.java
  9. 60
      src/main/java/com/teaching/backend/model/dto/courses/PageDTO.java
  10. 68
      src/main/java/com/teaching/backend/model/entity/courses/CourseObjectives.java
  11. 143
      src/main/java/com/teaching/backend/model/entity/courses/Courses.java
  12. 14
      src/main/java/com/teaching/backend/model/query/CourseQuery.java
  13. 44
      src/main/java/com/teaching/backend/model/query/PageQuery.java
  14. 48
      src/main/java/com/teaching/backend/model/vo/CoursesVO.java
  15. 20
      src/main/java/com/teaching/backend/service/courses/ICourseObjectivesService.java
  16. 27
      src/main/java/com/teaching/backend/service/courses/ICoursesService.java
  17. 94
      src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java
  18. 92
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  19. 5
      src/main/resources/mapper/CourseObjectivesMapper.xml
  20. 5
      src/main/resources/mapper/CoursesMapper.xml

@ -76,6 +76,12 @@
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
</dependency> </dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.11</version>
</dependency>
</dependencies> </dependencies>

@ -14,6 +14,8 @@ public enum ErrorCode {
NO_AUTH_ERROR(40101, "无权限"), NO_AUTH_ERROR(40101, "无权限"),
NOT_FOUND_ERROR(40400, "请求数据不存在"), NOT_FOUND_ERROR(40400, "请求数据不存在"),
FORBIDDEN_ERROR(40300, "禁止访问"), FORBIDDEN_ERROR(40300, "禁止访问"),
PARAMS_ILLEGAL(42000, "请求参数违法"),
SYSTEM_ERROR(50000, "系统内部异常"), SYSTEM_ERROR(50000, "系统内部异常"),
OPERATION_ERROR(50001, "操作失败"); OPERATION_ERROR(50001, "操作失败");

@ -0,0 +1,64 @@
package com.teaching.backend.controller.courses;
import cn.hutool.core.bean.BeanUtil;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.mapper.courses.CourseObjectivesMapper;
import com.teaching.backend.model.dto.courses.CourseObjectivesDTO;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.service.courses.ICourseObjectivesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
/**
* <p>
* 前端控制器
* </p>
*
* @author zjh
* @since 2024-05-31
*/
@Api(tags = "项目目标管理接口")
@RestController
@RequestMapping("/course_objectives")
public class CourseObjectivesController {
@Autowired
ICourseObjectivesService courseObjectivesService;
@Autowired
CourseObjectivesMapper courseObjectivesMapper;
@ApiOperation("新增分项目标-默认第一个必须添加思政目标")
@PostMapping("/addobjectives")
public BaseResponse<String> saveCourseObjectives(@RequestBody CourseObjectivesDTO courseObjectivesDTO){
String data = courseObjectivesService.addObjectives(courseObjectivesDTO);
return ResultUtils.success(data);
}
@ApiOperation("删除分项目标-只能最后一个删除思政目标")
@DeleteMapping("/{id}")
public BaseResponse<String> deleteCourseObjectivesByIds(@PathVariable String id){
String data = courseObjectivesService.deleteObjectives(id);
return ResultUtils.success(data);
}
@ApiOperation("编辑分项目标")
@PutMapping
public BaseResponse<String> updateCourseObjectives(@RequestBody CourseObjectivesDTO courseObjectivesDTO){
String pid = courseObjectivesDTO.getPid();
CourseObjectives courseObjectives = courseObjectivesMapper.selectById(pid);
BeanUtil.copyProperties(courseObjectivesDTO, courseObjectives);
courseObjectives.setUpdateTime(LocalDateTime.now());
courseObjectivesService.updateById(courseObjectives);
return ResultUtils.success("编辑成功");
}
}

@ -0,0 +1,81 @@
package com.teaching.backend.controller.courses;
import cn.hutool.core.bean.BeanUtil;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.model.dto.courses.CoursesDTO;
import com.teaching.backend.model.dto.courses.PageDTO;
import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.query.CourseQuery;
import com.teaching.backend.model.vo.CoursesVO;
import com.teaching.backend.service.courses.ICoursesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author zjh
* @since 2024-05-30
*/
@Api(tags = "教师管理课程接口")
@RestController
@RequestMapping("/coursesteacher")
public class CoursesController {
@Autowired
ICoursesService coursesService;
@ApiOperation("新增课程--同步新增课程的总体目标")
@PostMapping("/addcourse")
public BaseResponse<String> saveCourse(@RequestBody CoursesDTO coursesDTO, @RequestParam String teacherId){
String data = coursesService.saveCourseWithObjective(coursesDTO, teacherId);
return ResultUtils.success(data);
}
@ApiOperation("查询课程列表")
@GetMapping("/page")
public BaseResponse<PageDTO<CoursesVO>> getCourses(CourseQuery courseQuery, @RequestParam String teacherId){
PageDTO<CoursesVO> coursesList = coursesService.queryCourses(courseQuery,teacherId);
return ResultUtils.success(coursesList);
}
@ApiOperation("根据id查询课程")
@GetMapping("/{id}")
public BaseResponse<CoursesDTO> getByIdCourse(@PathVariable String id){
Courses course = coursesService.getById(id);
CoursesDTO coursesDTO = new CoursesDTO();
BeanUtils.copyProperties(course,coursesDTO);
return ResultUtils.success(coursesDTO);
}
@ApiOperation("根据id修改课程")
@PutMapping
public BaseResponse<String> editCourse(@RequestBody CoursesDTO coursesDTO){
String courseId = coursesDTO.getId();
Courses course = coursesService.getById(courseId);
BeanUtil.copyProperties(coursesDTO, course);
coursesService.updateById(course);
return ResultUtils.success("编辑成功");
}
//TODO:删除功能暂未完善,数据表缺失
@ApiOperation("根据ids批量删除课程")
@DeleteMapping("/{ids}")
public BaseResponse<String> deleteCourses(@PathVariable List<String> ids){
System.out.println(ids);
coursesService.removeBatchByIds(ids);
return ResultUtils.success("删除成功");
}
}

@ -0,0 +1,16 @@
package com.teaching.backend.mapper.courses;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.courses.CourseObjectives;
/**
* <p>
* Mapper 接口
* </p>
*
* @author zjh
* @since 2024-05-31
*/
public interface CourseObjectivesMapper extends BaseMapper<CourseObjectives> {
}

@ -0,0 +1,16 @@
package com.teaching.backend.mapper.courses;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.courses.Courses;
/**
* <p>
* Mapper 接口
* </p>
*
* @author zjh
* @since 2024-05-30
*/
public interface CoursesMapper extends BaseMapper<Courses> {
}

@ -0,0 +1,39 @@
package com.teaching.backend.model.dto.courses;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(description = "分项目标参数实体")
public class CourseObjectivesDTO {
/**
* 内部编号
*/
@ApiModelProperty("id")
private String id;
/**
* 分项目标名称
*/
@ApiModelProperty(value = "分项目标名称",required = true)
private String name;
/**
* 分项目标类型 思政1 知识2素质3价值4
*/
@ApiModelProperty(value = "分项目标类型 思政1 知识2、素质3、价值4",required = true)
private String type;
/**
* 分项目标描述
*/
@ApiModelProperty(value = "分项目标内容",required = true)
private String content;
/**
* 父节点
*/
@ApiModelProperty(value = "父节点pid",required = true)
private String pid;
}

@ -0,0 +1,100 @@
package com.teaching.backend.model.dto.courses;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@ApiModel(description = "教师创建课程参数实体")
public class CoursesDTO {
/**
* 内部编号
*/
@ApiModelProperty("id")
private String id;
/**
* 创建人 教师id
*/
@ApiModelProperty("负责教师")
private String teacher;
/**
* 创建日期
*/
@ApiModelProperty("创建日期")
private LocalDateTime createTime;
/**
* 课程封面
*/
@ApiModelProperty("图片")
private String img;
/**
* 课程类别 专业教育 通识教育
*/
@ApiModelProperty(value = "课程类别:专业教育 通识教育",required = true)
private String category;
/**
* 课程性质 必修选修任修
*/
@ApiModelProperty(value = "课程性质:必修,选修,任修",required = true)
private String nature;
/**
* 课程名称
*/
@ApiModelProperty(value = "课程名称",required = true)
private String name;
/**
* 课程编码
*/
@ApiModelProperty(value = "课程编码",required = true)
private String code;
/**
* 课程学分
*/
@ApiModelProperty(value = "课程学分",required = true)
private BigDecimal credit;
/**
* 课程学时
*/
@ApiModelProperty(value = "课程学时",required = true)
private Integer classhours;
/**
* 考核类型 考试 考查
*/
@ApiModelProperty(value = "考核类型:考试 考查",required = true)
private String assessmenttype;
/**
* 考核方式 开卷 闭卷 其他
*/
@ApiModelProperty(value = "考核方式:开卷 闭卷 其他",required = true)
private String assessmentway;
/**
* 教学方法
*/
@ApiModelProperty("教学方法")
private String teachermethod;
/**
* 教学方式
*/
@ApiModelProperty("教学方式")
private String teacherway;
/**
* 课程简介
*/
@ApiModelProperty("课程简介")
private String description;
}

@ -0,0 +1,60 @@
package com.teaching.backend.model.dto.courses;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
@Data
@ApiModel(description = "分页结果")
public class PageDTO<T> {
@ApiModelProperty("总条数")
private Long total;
@ApiModelProperty("总页数")
private Long pages;
@ApiModelProperty("集合")
private List<T> list;
public static <PO, VO> PageDTO<VO> of(Page<PO> p, Class<VO> clazz){
PageDTO<VO> dto = new PageDTO<>();
// 1.总条数
dto.setTotal(p.getTotal());
// 2.总页数
dto.setPages(p.getPages());
// 3.当前页数据
List<PO> records = p.getRecords();
if (CollUtil.isEmpty(records)) {
dto.setList(Collections.emptyList());
return dto;
}
// 4.拷贝user的VO
dto.setList(BeanUtil.copyToList(records, clazz));
// 5.返回
return dto;
}
public static <PO, VO> PageDTO<VO> of(Page<PO> p, Function<PO, VO> convertor){
PageDTO<VO> dto = new PageDTO<>();
// 1.总条数
dto.setTotal(p.getTotal());
// 2.总页数
dto.setPages(p.getPages());
// 3.当前页数据
List<PO> records = p.getRecords();
if (CollUtil.isEmpty(records)) {
dto.setList(Collections.emptyList());
return dto;
}
// 4.拷贝user的VO
dto.setList(records.stream().map(convertor).collect(Collectors.toList()));
// 5.返回
return dto;
}
}

@ -0,0 +1,68 @@
package com.teaching.backend.model.entity.courses;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
*
* </p>
*
* @author zjh
* @since 2024-05-31
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("course_objectives")
@ApiModel(value="CourseObjectives对象", description="")
public class CourseObjectives implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "内部编号")
@TableId(value = "id", type = IdType.ASSIGN_UUID)
private String id;
@ApiModelProperty(value = "创建日期")
private LocalDateTime createTime;
@ApiModelProperty(value = "更新日期")
private LocalDateTime updateTime;
@ApiModelProperty(value = "父级节点")
private String pid;
@ApiModelProperty(value = "是否有子节点")
private String hasChild;
@ApiModelProperty(value = "目标名称")
private String name;
@ApiModelProperty(value = "目标类型")
private String type;
@ApiModelProperty(value = "目标内容")
private String content;
@ApiModelProperty(value = "课程id")
private String courseid;
@ApiModelProperty(value = "毕业要求id")
private String requireid;
@ApiModelProperty(value = "毕业要求")
private String temp;
}

@ -0,0 +1,143 @@
package com.teaching.backend.model.entity.courses;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* <p>
*
* </p>
*
* @author zjh
* @since 2024-05-30
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("courses")
public class Courses implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 内部编号
*/
@TableId(value = "id", type = IdType.ASSIGN_UUID)
private String id;
/**
* 创建日期
*/
private LocalDateTime createTime;
/**
* 更新日期
*/
private LocalDateTime updateTime;
/**
* 课程封面
*/
private String img;
/**
* 课程类别
*/
private String category;
/**
* 课程性质
*/
private String nature;
/**
* 课程名称
*/
private String name;
/**
* 课程编码
*/
private String code;
/**
* 开课学期
*/
private String semester;
/**
* 课程学分
*/
private BigDecimal credit;
/**
* 课程学时
*/
private Integer classhours;
/**
* 理论学时
*/
private Integer theoryhours;
/**
* 实践学时
*/
private Integer practicehours;
/**
* 实验学时
*/
private Integer experimenthours;
/**
* 其他学时
*/
private Integer otherhours;
/**
* 上课周数
*/
private Integer weeks;
/**
* 考核类型
*/
private String assessmenttype;
/**
* 考核方式
*/
private String assessmentway;
/**
* 负责教师
*/
private String teacher;
/**
* 教学方法
*/
private String teachermethod;
/**
* 教学方式
*/
private String teacherway;
/**
* 课程简介
*/
private String description;
}

@ -0,0 +1,14 @@
package com.teaching.backend.model.query;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
@ApiModel(description = "课程查询条件实体")
public class CourseQuery extends PageQuery {
@ApiModelProperty("课程名称关键字")
private String name;
}

@ -0,0 +1,44 @@
package com.teaching.backend.model.query;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(description = "分页查询实体")
public class PageQuery {
@ApiModelProperty("页码")
private Integer pageNo = 1;
@ApiModelProperty("页码")
private Integer pageSize = 10;
@ApiModelProperty("排序字段")
private String sortBy;
@ApiModelProperty("是否升序")
private Boolean isAsc = true;
public <T> Page<T> toMpPage(OrderItem ... items){
// 1.分页条件
Page<T> page = Page.of(pageNo, pageSize);
// 2.排序条件
if(StrUtil.isNotBlank(sortBy)){
// 不为空
page.addOrder(new OrderItem(sortBy, isAsc));
}else if(items != null){
// 为空,默认排序
page.addOrder(items);
}
return page;
}
public <T> Page<T> toMpPage(String defaultSortBy, Boolean defaultAsc){
return toMpPage(new OrderItem(defaultSortBy, defaultAsc));
}
public <T> Page<T> toMpPageDefaultSortByCreateTime(){
return toMpPage(new OrderItem("create_time", false));
}
public <T> Page<T> toMpPageDefaultSortByUpdateTime(){
return toMpPage(new OrderItem("update_time", false));
}
}

@ -0,0 +1,48 @@
package com.teaching.backend.model.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
@Data
@ApiModel(description = "课程VO实体")
public class CoursesVO {
/**
* 内部编号
*/
@ApiModelProperty("id")
private String id;
/**
* 教师id
*/
@ApiModelProperty("教师id")
private String teacher;
/**
* 课程封面
*/
@ApiModelProperty("图片")
private String img;
/**
* 课程名称
*/
@ApiModelProperty(value = "课程名称",required = true)
private String name;
/**
* 课程学分
*/
@ApiModelProperty(value = "课程学分",required = true)
private BigDecimal credit;
/**
* 课程学时
*/
@ApiModelProperty(value = "课程学时",required = true)
private Integer classhours;
}

@ -0,0 +1,20 @@
package com.teaching.backend.service.courses;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.dto.courses.CourseObjectivesDTO;
import com.teaching.backend.model.entity.courses.CourseObjectives;
/**
* <p>
* 服务类
* </p>
*
* @author zjh
* @since 2024-05-31
*/
public interface ICourseObjectivesService extends IService<CourseObjectives> {
String addObjectives(CourseObjectivesDTO courseObjectivesDTO);
String deleteObjectives(String id);
}

@ -0,0 +1,27 @@
package com.teaching.backend.service.courses;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.dto.courses.CoursesDTO;
import com.teaching.backend.model.dto.courses.PageDTO;
import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.query.CourseQuery;
import com.teaching.backend.model.vo.CoursesVO;
/**
* <p>
* 服务类
* </p>
*
* @author zjh
* @since 2024-05-30
*/
public interface ICoursesService extends IService<Courses> {
String saveCourseWithObjective(CoursesDTO coursesDTO, String teacherId);
PageDTO<CoursesVO> queryCourses(CourseQuery courseQuery, String teacherId);
}

@ -0,0 +1,94 @@
package com.teaching.backend.service.impl.courses;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.courses.CourseObjectivesMapper;
import com.teaching.backend.model.dto.courses.CourseObjectivesDTO;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.service.courses.ICourseObjectivesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
/**
* <p>
* 服务实现类
* </p>
*
* @author zjh
* @since 2024-05-31
*/
@Service
public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMapper, CourseObjectives> implements ICourseObjectivesService {
@Autowired
CourseObjectivesMapper courseObjectivesMapper;
@Override
public String addObjectives(CourseObjectivesDTO courseObjectivesDTO) {
String pid = courseObjectivesDTO.getPid();
if(pid.equals(null)){
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR,"pid父节点不能为空");
}
String hasChild = courseObjectivesMapper.selectById(pid).getHasChild();
String type = courseObjectivesDTO.getType();
if (hasChild.equals("0") && !type.equals("1")){
throw new BusinessException(ErrorCode.PARAMS_ILLEGAL,"请在添加完思政目标以后再添加此类型目标!");
}
//判断是否已经添加过思政目标
// TODO:思政目标能不能有多个??
if (courseObjectivesDTO.getType().equals("1")){
LambdaQueryWrapper<CourseObjectives> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
.eq(CourseObjectives::getPid, pid)
.eq(CourseObjectives::getType, "1");
Long count = courseObjectivesMapper.selectCount(queryWrapper);
if (count>0){
throw new BusinessException(ErrorCode.OPERATION_ERROR,"思政目标已存在,禁止重复添加!");
}
}
//往表里面写分项目标
CourseObjectives courseObjectives = new CourseObjectives();
BeanUtil.copyProperties(courseObjectivesDTO,courseObjectives);
courseObjectives.setCreateTime(LocalDateTime.now());
courseObjectivesMapper.insert(courseObjectives);
//插入数据以后要把总体目标那边的haschild改成1
CourseObjectives objectives = courseObjectivesMapper.selectById(pid);
objectives.setHasChild("1");
courseObjectivesMapper.updateById(objectives);
return "添加成功";
}
@Override
public String deleteObjectives(String id) {
CourseObjectives courseObjectives = courseObjectivesMapper.selectById(id);
String type = courseObjectives.getType();
String pid = courseObjectives.getPid();
if (type.equals("1")){
LambdaQueryWrapper<CourseObjectives> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CourseObjectives::getPid, pid);
Long count = courseObjectivesMapper.selectCount(queryWrapper);
if (count==1){
courseObjectivesMapper.deleteById(id);
CourseObjectives courseObjectives1 = courseObjectivesMapper.selectById(pid);
courseObjectives1.setHasChild("0");
courseObjectivesMapper.updateById(courseObjectives1);
return "删除成功";
}
else
{
throw new BusinessException(ErrorCode.OPERATION_ERROR, "请删除其他类型的分目标后再来删除思政目标");
}
}
else {
courseObjectivesMapper.deleteById(id);
return "删除成功";
}
}
}

@ -0,0 +1,92 @@
package com.teaching.backend.service.impl.courses;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.courses.CourseObjectivesMapper;
import com.teaching.backend.mapper.courses.CoursesMapper;
import com.teaching.backend.model.dto.courses.CoursesDTO;
import com.teaching.backend.model.dto.courses.PageDTO;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.query.CourseQuery;
import com.teaching.backend.model.vo.CoursesVO;
import com.teaching.backend.service.courses.ICoursesService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
/**
* <p>
* 服务实现类
* </p>
*
* @author zjh
* @since 2024-05-30
*/
@Service
public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses>implements ICoursesService {
@Autowired
CoursesMapper coursesMapper;
@Autowired
CourseObjectivesMapper courseObjectivesMapper;
@Override
@Transactional
public String saveCourseWithObjective(CoursesDTO coursesDTO, String teacherId) {
Courses courses = new Courses();
CourseObjectives courseObjectives = new CourseObjectives();
BeanUtils.copyProperties(coursesDTO, courses);
// List<String> teacherIds = new ArrayList<>();
// teacherIds.add(teacherId);
// courses.setTeacher(String.valueOf(teacherIds));
courses.setTeacher(teacherId);
courses.setCreateTime(LocalDateTime.now());
String code = coursesDTO.getCode();
QueryWrapper<Courses> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("code", code);
Long count = coursesMapper.selectCount(queryWrapper);
if(count==0){
int insert = coursesMapper.insert(courses);
if (insert>0){
Courses courses1 = coursesMapper.selectOne(queryWrapper);
courseObjectives.setCourseid(courses1.getId());
courseObjectives.setCreateTime(courses1.getCreateTime());
courseObjectives.setName(courses1.getName()+"课程总体目标");
courseObjectivesMapper.insert(courseObjectives);
}
return "添加成功";
}else {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "这个课程已经存在了!请联系系统相关人员为您导入课程数据!");
}
}
@Override
public PageDTO<CoursesVO> queryCourses(CourseQuery courseQuery, String teacherId) {
//要搜索的课程名字
String name = courseQuery.getName();
// 1.1构建分页条件
Page<Courses> page = courseQuery.toMpPageDefaultSortByCreateTime();
// 2.分页查询
Page<Courses> p = lambdaQuery()
.like(name != null, Courses::getName, name)
// .eq(Courses::getTeacher,teacherId)
// .apply("JSON_CONTAINS(teacher, JSON_QUOTE({0}))", teacherId)
.apply("FIND_IN_SET({0}, teacher)", teacherId)
.page(page);
return PageDTO.of(p,CoursesVO.class);
}
}

@ -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="edu.huanghuai.mapper.CourseObjectivesMapper">
</mapper>

@ -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="edu.huanghuai.mapper.CoursesMapper">
</mapper>
Loading…
Cancel
Save