第一次修改

master
小萌新 4 months ago
parent 79a8fd2444
commit 3b2394b77d
  1. 1
      src/main/java/com/teaching/backend/controller/chapter/ChapterController.java
  2. 74
      src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java
  3. 91
      src/main/java/com/teaching/backend/controller/courses/CoursesController2.java
  4. 9
      src/main/java/com/teaching/backend/mapper/chapter/ChapterMapper.java
  5. 4
      src/main/java/com/teaching/backend/mapper/courses/CoursesMapper.java
  6. 4
      src/main/java/com/teaching/backend/mapper/resource/CourseResourcesMapper.java
  7. 2
      src/main/java/com/teaching/backend/mapper/resource/ResourcesRelationshipMapper.java
  8. 89
      src/main/java/com/teaching/backend/model/dto/chapter/ChapterDTO.java
  9. 34
      src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java
  10. 9
      src/main/java/com/teaching/backend/service/chapter/IChapterService.java
  11. 3
      src/main/java/com/teaching/backend/service/courses/ICoursesService.java
  12. 6
      src/main/java/com/teaching/backend/service/impl/CourseResourcesServiceImpl.java
  13. 61
      src/main/java/com/teaching/backend/service/impl/ResourcesRelationshipServiceImpl.java
  14. 122
      src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java
  15. 47
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  16. 5
      src/main/java/com/teaching/backend/service/resource/ResourcesRelationshipService.java

@ -76,4 +76,5 @@ public class ChapterController {
.count(); .count();
return ResultUtils.success(count); return ResultUtils.success(count);
} }
} }

@ -0,0 +1,74 @@
package com.teaching.backend.controller.chapter;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.model.dto.chapter.ChapterDTO;
import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.service.chapter.IChapterService;
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;
import java.util.List;
/**
* ClassName: ChapterController2
* Package: com.teaching.backend.controller.chapter
* Description:
*
* @Author 姜钧瀚
* @Create 2024/7/23 17:16
* @Version 1.0
*/
@Api(tags = "课程章节管理接口2")
@RestController
@RequestMapping("/chapter2")
public class ChapterController2 {
@Autowired
IChapterService chapterService;
@ApiOperation("查询全部的章节")
@GetMapping("/list")
public BaseResponse<List<Chapter>> AllList(){
List<Chapter> list= chapterService.list();
return ResultUtils.success(list);
}
@ApiOperation("根据课程id查出对应的父子章节")
@GetMapping("/chapter")
public BaseResponse<List<Chapter>> getCourseChapters2(@RequestParam String courseId){
return ResultUtils.success(chapterService.getChapterTree(courseId));
}
@ApiOperation("添加章节")
@PostMapping("/add")
public BaseResponse<String> addChapter2(@RequestBody ChapterDTO chapterDTO){
chapterService.saveChapter(chapterDTO);
return ResultUtils.success("添加成功!!!!!!!!");
}
@ApiOperation("删除章节")
@DeleteMapping("/delete/{id}")
public BaseResponse<String> dlChapter(@PathVariable String id){
chapterService.deleteChapter(id);
return ResultUtils.success("删除成功");
}
@ApiOperation("修改章节")
@PutMapping("/update")
public BaseResponse<String> udChapter(@RequestBody Chapter chapter){
chapter.setUpdateTime(LocalDateTime.now());
chapterService.updateById(chapter);
return ResultUtils.success("修改成功");
}
}

@ -0,0 +1,91 @@
package com.teaching.backend.controller.courses;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.filter.ValidateParams;
import com.teaching.backend.mapper.courses.CoursesMapper;
import com.teaching.backend.model.dto.courses.CoursesDTO;
import com.teaching.backend.model.entity.CourseResources;
import com.teaching.backend.model.entity.ResourceRelationship;
import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.vo.courses.CoursesVO;
import com.teaching.backend.service.courses.ICoursesService;
import com.teaching.backend.service.resource.ResourcesRelationshipService;
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.HashMap;
import java.util.List;
import java.util.Map;
/**
* ClassName: CoursesController2
* Package: com.teaching.backend.controller.courses
* Description:
*
* @Author 姜钧瀚
* @Create 2024/7/22 17:52
* @Version 1.0
*/
@RestController
@RequestMapping("/api/coursesteacher2")
public class CoursesController2 {
@Autowired
ICoursesService coursesService;
@Autowired
ResourcesRelationshipService resourcesRelationshipService;
@ApiOperation("网站首页2")
@GetMapping("/index2")
public BaseResponse<Map<String,Object>> getData(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) {
Map<String, Object> result = coursesService.getPagePageSize2(page, pageSize);
// 将结果放入新的Map对象中返回
Map<String, Object> objectMap = new HashMap<>();
objectMap.put("content", result.get("courses"));
objectMap.put("totalcount", result.get("totalcount"));
objectMap.put("totalPages", result.get("totalPages"));
objectMap.put("currentPage", result.get("currentPage"));
return ResultUtils.success(objectMap);
}
@ApiOperation("根据id查询课程")
@ValidateParams({"id"})
@GetMapping("/{id}")
public BaseResponse<CoursesDTO> getByIdCourse(@PathVariable String id){
if(id==null){
throw new BusinessException(ErrorCode.PARAMS_ERROR,"课程id为空");
}
Courses course = coursesService.getById(id);
CoursesDTO coursesDTO = new CoursesDTO();
BeanUtils.copyProperties(course,coursesDTO);
return ResultUtils.success(coursesDTO);
}
@ApiOperation("点击详情课程根据id查询对应课程的资源")
@GetMapping("/resource/{id}")
public BaseResponse<List<CourseResources>> getResource(@PathVariable String id) {
List<CourseResources> relatedResources = resourcesRelationshipService.getResource(id);
return ResultUtils.success(relatedResources);
}
@ApiOperation("点击详情课程根据id和type查询对应课程的资源")
@GetMapping("/resource/list")
public BaseResponse<List<CourseResources>> getResource2(@RequestParam String id,@RequestParam Integer type) {
List<CourseResources> relatedResources = resourcesRelationshipService.getResource2(id,type);
return ResultUtils.success(relatedResources);
}
}

@ -3,6 +3,10 @@ package com.teaching.backend.mapper.chapter;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.chapter.Chapter; import com.teaching.backend.model.entity.chapter.Chapter;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/** /**
* <p> * <p>
@ -13,5 +17,10 @@ import com.teaching.backend.model.entity.chapter.Chapter;
* @since 2024-05-31 * @since 2024-05-31
*/ */
public interface ChapterMapper extends BaseMapper<Chapter> { public interface ChapterMapper extends BaseMapper<Chapter> {
@Select("SELECT * FROM chapter WHERE course_id = #{courseId}")
List<Chapter> selectSectionsByCourseId(@Param("courseId") String courseId);
@Select("SELECT * FROM course_chapter WHERE course_id = #{courseId} AND (pid = #{parentId} )")
List<Chapter> selectSectionsWithChildren(@Param("courseId") String courseId, @Param("parentId") String parentId);
} }

@ -1,7 +1,10 @@
package com.teaching.backend.mapper.courses; package com.teaching.backend.mapper.courses;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.vo.courses.CoursesVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
@ -21,4 +24,5 @@ public interface CoursesMapper extends BaseMapper<Courses> {
@Select("SELECT * FROM courses LIMIT #{start}, #{pageSize}") @Select("SELECT * FROM courses LIMIT #{start}, #{pageSize}")
List<Courses> getItemsByPage(@Param("start") int start, @Param("pageSize") int pageSize); List<Courses> getItemsByPage(@Param("start") int start, @Param("pageSize") int pageSize);
} }

@ -3,6 +3,9 @@ package com.teaching.backend.mapper.resource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.CourseResources; import com.teaching.backend.model.entity.CourseResources;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/** /**
* ClassName: FileTableMapper * ClassName: FileTableMapper
@ -15,4 +18,5 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface CourseResourcesMapper extends BaseMapper<CourseResources> { public interface CourseResourcesMapper extends BaseMapper<CourseResources> {
} }

@ -1,6 +1,8 @@
package com.teaching.backend.mapper.resource; package com.teaching.backend.mapper.resource;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.CourseResources;
import com.teaching.backend.model.entity.ResourceRelationship; import com.teaching.backend.model.entity.ResourceRelationship;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.tomcat.websocket.BackgroundProcess; import org.apache.tomcat.websocket.BackgroundProcess;

@ -0,0 +1,89 @@
package com.teaching.backend.model.dto.chapter;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.xml.soap.Text;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* ClassName: ChapterDTO
* Package: com.teaching.backend.model.dto.chapter
* Description:
*
* @Author 姜钧瀚
* @Create 2024/7/23 23:16
* @Version 1.0
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ChapterDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "创建人")
private String createBy;
@ApiModelProperty(value = "创建日期")
private LocalDateTime createTime;
@ApiModelProperty(value = "更新人")
private String updateBy;
@ApiModelProperty(value = "更新日期")
private LocalDateTime updateTime;
@ApiModelProperty(value = "所属部门")
private String sysOrgCode;
@ApiModelProperty(value = "序号")
private int orderNum;
@ApiModelProperty(value = "章节名称")
private String name;
@ApiModelProperty(value = "简介")
private String content;
@ApiModelProperty(value = "父章节")
private String pid;
@ApiModelProperty(value = "课程id")
private String courseId;
@ApiModelProperty(value = "课程目标")
private String courseObjectivesId;
@ApiModelProperty(value = "总学时")
private String totalClassHours;
@ApiModelProperty(value = "要求")
private String requirement;
@ApiModelProperty(value = "线上学时")
private String onlineClassHours;
@ApiModelProperty(value = "周次")
private String zc;
@ApiModelProperty(value = "资源")
private String ziyuan;
@ApiModelProperty(value = "资源文件")
private String zywj;
@ApiModelProperty(value = "内部序号显示")
private String numshow;
}

@ -12,6 +12,7 @@ import lombok.experimental.Accessors;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
/** /**
* <p> * <p>
@ -34,77 +35,62 @@ public class Chapter implements Serializable {
private String id; private String id;
@ApiModelProperty(value = "创建人") @ApiModelProperty(value = "创建人")
@TableField("create_by")
private String createBy; private String createBy;
@ApiModelProperty(value = "创建日期") @ApiModelProperty(value = "创建日期")
@TableField("create_time")
private LocalDateTime createTime; private LocalDateTime createTime;
@ApiModelProperty(value = "更新人") @ApiModelProperty(value = "更新人")
@TableField("update_by")
private String updateBy; private String updateBy;
@ApiModelProperty(value = "更新日期") @ApiModelProperty(value = "更新日期")
@TableField("update_time")
private LocalDateTime updateTime; private LocalDateTime updateTime;
@ApiModelProperty(value = "所属部门") @ApiModelProperty(value = "所属部门")
@TableField("sys_org_code")
private String sysOrgCode; private String sysOrgCode;
@ApiModelProperty(value = "序号") @ApiModelProperty(value = "序号")
@TableField("num") private int orderNum;
private Integer num;
@ApiModelProperty(value = "名称") @ApiModelProperty(value = "名称")
@TableField("name")
private String name; private String name;
@ApiModelProperty(value = "简介") @ApiModelProperty(value = "简介")
@TableField("content")
private String content; private String content;
@ApiModelProperty(value = "父级节点") @ApiModelProperty(value = "父级节点")
@TableField("pid")
private String pid; private String pid;
@ApiModelProperty(value = "课程") @ApiModelProperty(value = "课程")
@TableField("courseid")
private String courseid; private String courseId;
@ApiModelProperty(value = "课程目标") @ApiModelProperty(value = "课程目标")
@TableField("courseobjectivesid") private String courseObjectivesId;
private String courseobjectivesid;
@ApiModelProperty(value = "总学时") @ApiModelProperty(value = "总学时")
@TableField("totalclasshours") private String totalClassHours;
private String totalclasshours;
@ApiModelProperty(value = "要求") @ApiModelProperty(value = "要求")
@TableField("requirement")
private String requirement; private String requirement;
@ApiModelProperty(value = "线上学时") @ApiModelProperty(value = "线上学时")
@TableField("onlinclasshours") private String onlineClassHours;
private String onlinclasshours;
@ApiModelProperty(value = "周次") @ApiModelProperty(value = "周次")
@TableField("zc")
private String zc; private String zc;
@ApiModelProperty(value = "资源") @ApiModelProperty(value = "资源")
@TableField("ziyuan")
private String ziyuan; private String ziyuan;
@ApiModelProperty(value = "资源文件") @ApiModelProperty(value = "资源文件")
@TableField("zywj")
private String zywj; private String zywj;
@ApiModelProperty(value = "内部序号显示") @ApiModelProperty(value = "内部序号显示")
@TableField("numshow")
private String numshow; private String numshow;
@ApiModelProperty(value = "子章节")
@TableField(exist = false)
private List<Chapter> children; // 用于存储子章节
} }

@ -2,6 +2,7 @@ package com.teaching.backend.service.chapter;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.dto.chapter.ChapterDTO;
import com.teaching.backend.model.entity.chapter.Chapter; import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.model.vo.chapter.ChapterVo; import com.teaching.backend.model.vo.chapter.ChapterVo;
@ -23,4 +24,12 @@ public interface IChapterService extends IService<Chapter> {
Boolean deleteAfterUpdate(String id); Boolean deleteAfterUpdate(String id);
List<Chapter> getChapterTree(String courseId);
void saveChapter(ChapterDTO chapterDTO);
void deleteChapter(String id);
} }

@ -10,6 +10,7 @@ import com.teaching.backend.model.vo.courses.CoursesVO;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
@ -38,4 +39,6 @@ public interface ICoursesService extends IService<Courses> {
void down(HttpServletResponse response, String id) throws Exception; void down(HttpServletResponse response, String id) throws Exception;
CoursesVO getByIdCourseVo(String courseid); CoursesVO getByIdCourseVo(String courseid);
Map<String, Object> getPagePageSize2(int page, int pageSize);
} }

@ -39,8 +39,8 @@ import java.util.function.Consumer;
*/ */
@Service @Service
public class CourseResourcesServiceImpl extends ServiceImpl<CourseResourcesMapper, CourseResources> implements CourseResourcesService { public class CourseResourcesServiceImpl extends ServiceImpl<CourseResourcesMapper, CourseResources> implements CourseResourcesService {
@Resource // @Resource
ResourcesRelationshipService resourcesRelationshipService; // ResourcesRelationshipService resourcesRelationshipService;
@Autowired @Autowired
private CourseResourcesMapper courseResourcesMapper; private CourseResourcesMapper courseResourcesMapper;
@ -64,7 +64,7 @@ public class CourseResourcesServiceImpl extends ServiceImpl<CourseResourcesMappe
resourcesRelationship.setResourceid(String.valueOf(resourceId)); resourcesRelationship.setResourceid(String.valueOf(resourceId));
resourcesRelationshipService.save(resourcesRelationship); // resourcesRelationshipService.save(resourcesRelationship);
} }
@Override @Override

@ -1,12 +1,21 @@
package com.teaching.backend.service.impl; package com.teaching.backend.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.mapper.resource.CourseResourcesMapper;
import com.teaching.backend.mapper.resource.ResourcesRelationshipMapper; import com.teaching.backend.mapper.resource.ResourcesRelationshipMapper;
import com.teaching.backend.model.entity.CourseResources; import com.teaching.backend.model.entity.CourseResources;
import com.teaching.backend.model.entity.ResourceRelationship; import com.teaching.backend.model.entity.ResourceRelationship;
import com.teaching.backend.service.resource.CourseResourcesService;
import com.teaching.backend.service.resource.ResourcesRelationshipService; import com.teaching.backend.service.resource.ResourcesRelationshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* ClassName: ResourcesRelationshipServiceImpl * ClassName: ResourcesRelationshipServiceImpl
* Package: com.teaching.backend.service.impl * Package: com.teaching.backend.service.impl
@ -19,5 +28,57 @@ import org.springframework.stereotype.Service;
@Service @Service
public class ResourcesRelationshipServiceImpl extends ServiceImpl<ResourcesRelationshipMapper, ResourceRelationship> implements ResourcesRelationshipService { public class ResourcesRelationshipServiceImpl extends ServiceImpl<ResourcesRelationshipMapper, ResourceRelationship> implements ResourcesRelationshipService {
@Autowired
CourseResourcesService courseResourcesService;
@Override
public List<CourseResources> getResource(String id) {
LambdaQueryWrapper<ResourceRelationship> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(ResourceRelationship::getCourseid, id);
List<ResourceRelationship> resourceRelationshipList = this.list(lambdaQueryWrapper);
List<String> resourceIds = resourceRelationshipList.stream()
.map(ResourceRelationship::getResourceid)
.collect(Collectors.toList());
if (!resourceIds.isEmpty()) {
LambdaQueryWrapper<CourseResources> courseResourcesQueryWrapper = new LambdaQueryWrapper<>();
courseResourcesQueryWrapper.in(CourseResources::getId, resourceIds);
return courseResourcesService.list(courseResourcesQueryWrapper);
}
return Collections.emptyList();
}
@Override
public List<CourseResources> getResource2(String id, Integer type) {
LambdaQueryWrapper<ResourceRelationship> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(ResourceRelationship::getCourseid, id);
List<ResourceRelationship> resourceRelationshipList = this.list(lambdaQueryWrapper);
List<String> resourceIds = resourceRelationshipList.stream()
.map(ResourceRelationship::getResourceid)
.collect(Collectors.toList());
if (type==null){
if (!resourceIds.isEmpty()) {
LambdaQueryWrapper<CourseResources> courseResourcesQueryWrapper = new LambdaQueryWrapper<>();
courseResourcesQueryWrapper.in(CourseResources::getId, resourceIds);
return courseResourcesService.list(courseResourcesQueryWrapper);
}
}else {
LambdaQueryWrapper<CourseResources> courseResourcesQueryWrapper = new LambdaQueryWrapper<>();
courseResourcesQueryWrapper.in(CourseResources::getId, resourceIds)
.in(CourseResources::getType,type);
return courseResourcesService.list(courseResourcesQueryWrapper);
}
return Collections.emptyList();
}
} }

@ -1,19 +1,21 @@
package com.teaching.backend.service.impl.chapter; package com.teaching.backend.service.impl.chapter;
import cn.hutool.core.annotation.Link;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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.chapter.ChapterMapper; import com.teaching.backend.mapper.chapter.ChapterMapper;
import com.teaching.backend.model.dto.chapter.ChapterDTO;
import com.teaching.backend.model.entity.chapter.Chapter; import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.model.vo.chapter.ChapterVo; import com.teaching.backend.model.vo.chapter.ChapterVo;
import com.teaching.backend.model.vo.courses.CoursesVO;
import com.teaching.backend.service.chapter.IChapterService; import com.teaching.backend.service.chapter.IChapterService;
import org.jetbrains.annotations.TestOnly; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -34,14 +36,15 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
public String updateNumShow(Chapter chapter) { public String updateNumShow(Chapter chapter) {
String finalNumShow; String finalNumShow;
String courseid = chapter.getCourseid(); String courseid = chapter.getCourseId();
String pid = chapter.getPid(); String pid = chapter.getPid();
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>();
Long countChapter ; Long countChapter ;
// pid为0时,说明为章 // pid为0时,说明为章
if("0".equals(pid)|| "".equals(pid)){ if("0".equals(pid)|| "".equals(pid)){
wrapper.eq(Chapter::getCourseid,courseid); wrapper.eq(Chapter::getCourseId,courseid);
countChapter = chapterMapper.selectCount(wrapper); countChapter = chapterMapper.selectCount(wrapper);
finalNumShow=String.valueOf(countChapter+1); finalNumShow=String.valueOf(countChapter+1);
// chapter.setNumshow(String.valueOf(countChapter+1)); // chapter.setNumshow(String.valueOf(countChapter+1));
// System.out.println(chapter.getNumshow()); // System.out.println(chapter.getNumshow());
@ -51,7 +54,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
String parentNumShow =chapter1.getNumshow(); String parentNumShow =chapter1.getNumshow();
System.out.println("909090"); System.out.println("909090");
System.out.println(parentNumShow); System.out.println(parentNumShow);
wrapper.eq(Chapter::getCourseid,courseid) wrapper.eq(Chapter::getCourseId,courseid)
.eq(Chapter::getPid,pid); .eq(Chapter::getPid,pid);
countChapter = chapterMapper.selectCount(wrapper); countChapter = chapterMapper.selectCount(wrapper);
System.out.println("-=-=-=-=-="+countChapter); System.out.println("-=-=-=-=-="+countChapter);
@ -79,7 +82,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
@Override @Override
public LinkedList<Chapter> getCourseChapter(String courseid) { public LinkedList<Chapter> getCourseChapter(String courseid) {
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Chapter::getCourseid,courseid) wrapper.eq(Chapter::getCourseId,courseid)
.orderByAsc(Chapter::getNumshow); .orderByAsc(Chapter::getNumshow);
List<Chapter> list = chapterMapper.selectList(wrapper); List<Chapter> list = chapterMapper.selectList(wrapper);
LinkedList<Chapter> linkedList = new LinkedList<>(list); LinkedList<Chapter> linkedList = new LinkedList<>(list);
@ -91,7 +94,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
// LinkedList<Chapter> list = new LinkedList<>(); // LinkedList<Chapter> list = new LinkedList<>();
// 获得所有的节,并按顺序进行排列 // 获得所有的节,并按顺序进行排列
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Chapter::getCourseid,courseid) wrapper.eq(Chapter::getCourseId,courseid)
.like(Chapter::getNumshow,"-") .like(Chapter::getNumshow,"-")
.orderByAsc(Chapter::getNumshow); .orderByAsc(Chapter::getNumshow);
List<Chapter> prelist = chapterMapper.selectList(wrapper); List<Chapter> prelist = chapterMapper.selectList(wrapper);
@ -99,7 +102,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
System.out.println(prelist); System.out.println(prelist);
// 获得所有的章节信息 // 获得所有的章节信息
LambdaQueryWrapper<Chapter> wrapper1 = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Chapter> wrapper1 = new LambdaQueryWrapper<>();
wrapper1.eq(Chapter::getCourseid,courseid) wrapper1.eq(Chapter::getCourseId,courseid)
.notLike(Chapter::getNumshow,"-") .notLike(Chapter::getNumshow,"-")
.orderByAsc(Chapter::getNumshow); .orderByAsc(Chapter::getNumshow);
List<Chapter> chapterList = chapterMapper.selectList(wrapper1); List<Chapter> chapterList = chapterMapper.selectList(wrapper1);
@ -140,17 +143,114 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
public Boolean deleteAfterUpdate(String id) { public Boolean deleteAfterUpdate(String id) {
Chapter chapter = chapterMapper.selectById(id); Chapter chapter = chapterMapper.selectById(id);
String numshow = chapter.getNumshow(); String numshow = chapter.getNumshow();
String courseid = chapter.getCourseid(); String courseid = chapter.getCourseId();
updateNumShow(numshow, courseid); updateNumShow(numshow, courseid);
chapterMapper.deleteById(id); chapterMapper.deleteById(id);
return true; return true;
} }
@Override
public List<Chapter> getChapterTree(String courseId) {
System.out.println(courseId);
List<Chapter> chapters=baseMapper.selectSectionsByCourseId(courseId);
System.out.println(chapters);
Map<String,Chapter> chapterMap=new HashMap<>();
List<Chapter> roots=new ArrayList<>();
for (Chapter chapter:chapters){
chapter.setChildren(new ArrayList<>());
chapterMap.put(chapter.getId(),chapter);
}
System.out.println(chapterMap);
for (Chapter chapter:chapters){
String parentId=chapter.getPid();
if (parentId!=null){
Chapter parentChapter=chapterMap.get(parentId);
if (parentChapter != null) {
parentChapter.getChildren().add(chapter);
}
}else {
roots.add(chapter);
}
}
System.out.println(roots);
return roots;
}
@Override
public void saveChapter(ChapterDTO chapterDTO) {
Chapter chapter = new Chapter();
try {
BeanUtils.copyProperties(chapterDTO, chapter);
} catch (Exception e) {
throw new RuntimeException("复制数据出错", e);
}
System.out.println(chapter);
String pid = chapter.getPid();
if (pid == null || pid.isEmpty()) {
System.out.println("这是新增的一个父节点");
chapter.setCreateTime(LocalDateTime.now());
chapter.setUpdateTime(LocalDateTime.now());
this.save(chapter);
} else {
System.out.println("这是新增的一个子节点");
Chapter parentChapter = this.getById(pid);
if (parentChapter != null) {
parentChapter.setUpdateTime(LocalDateTime.now());
this.updateById(parentChapter);
chapter.setCreateTime(LocalDateTime.now());
chapter.setUpdateTime(LocalDateTime.now());
this.save(chapter);
} else {
throw new BusinessException(ErrorCode.PARAMS_ERROR,"未找到父章节,ID 为: " + pid);
}
}
}
@Override
public void deleteChapter(String id) {
if (id==null||id.isEmpty()){
throw new BusinessException(ErrorCode.PARAMS_ERROR,"请求参数不能为空");
}
LambdaQueryWrapper<Chapter>queryWrapper=new LambdaQueryWrapper<>();
queryWrapper.eq(Chapter::getId,id);
LambdaQueryWrapper<Chapter>lambdaQueryWrapper=new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Chapter::getPid,id);
Long count= this.count(lambdaQueryWrapper);
if (count>0){
throw new BusinessException(ErrorCode.OPERATION_ERROR,"存在子章节,无法删除");
}
this.remove(queryWrapper);
}
public void updateNumShow(String numshow, String courseid){ public void updateNumShow(String numshow, String courseid){
// 查询课程章节 getCourseChapter // 查询课程章节 getCourseChapter
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Chapter::getCourseid,courseid) wrapper.eq(Chapter::getCourseId,courseid)
.orderByAsc(Chapter::getNumshow); .orderByAsc(Chapter::getNumshow);
List<Chapter> chapterList = chapterMapper.selectList(wrapper); List<Chapter> chapterList = chapterMapper.selectList(wrapper);
System.out.println("0-0-0-0-00-------"); System.out.println("0-0-0-0-00-------");

@ -43,7 +43,6 @@ import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* <p> * <p>
@ -59,6 +58,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
@Autowired @Autowired
private CourseObjectivesServiceImpl objectivesService; private CourseObjectivesServiceImpl objectivesService;
@Autowired @Autowired
ChapterMapper chapterMapper; ChapterMapper chapterMapper;
@ -304,6 +304,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
@Override @Override
public CoursesVO getByIdCourseVo(String courseid) { public CoursesVO getByIdCourseVo(String courseid) {
Courses courses = coursesMapper.selectById(courseid); Courses courses = coursesMapper.selectById(courseid);
CoursesVO coursesVO = BeanUtil.copyProperties(courses,CoursesVO.class); CoursesVO coursesVO = BeanUtil.copyProperties(courses,CoursesVO.class);
coursesVO.setTotalchapter(countChapters(courseid)); coursesVO.setTotalchapter(countChapters(courseid));
coursesVO.setTotalHours(countHours(courseid)); coursesVO.setTotalHours(countHours(courseid));
@ -314,6 +315,43 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
return coursesVO; return coursesVO;
} }
@Override
public Map<String, Object> getPagePageSize2(int page, int pageSize) {
Page<Courses> pageInfo=new Page<>(page,pageSize);
LambdaQueryWrapper<Courses> queryWrapper=new LambdaQueryWrapper<>();
this.page(pageInfo,queryWrapper);
List<Courses> list=pageInfo.getRecords();
List<CoursesVO> coursesVo = BeanUtil.copyToList(list, CoursesVO.class);
coursesVo = coursesVo.stream().map((item) -> {
item.setTotalHours(countHours(item.getId()));
item.setTotalchapter(countChapters(item.getId()));
item.setTotalKnow(countKnow(item.getId()));
return item;
}).collect(Collectors.toList());
// 获取总记录数和总页数
long totalcount = pageInfo.getTotal();
long totalPages = pageInfo.getPages();
// 将总记录数和总页数放入Map中返回
Map<String, Object> result = new HashMap<>();
result.put("courses", coursesVo);
result.put("totalcount", totalcount);
result.put("totalPages", totalPages);
result.put("currentPage", page);
return result;
}
@Override @Override
public List<CoursesVO> getPagePageSize(int page, int pageSize) { public List<CoursesVO> getPagePageSize(int page, int pageSize) {
int startIndex = (page-1) * pageSize; int startIndex = (page-1) * pageSize;
@ -341,12 +379,12 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
// 计算课程已分配的学时 计算章的学时(即已包含了小节的学时) // 计算课程已分配的学时 计算章的学时(即已包含了小节的学时)
public int countChaptersHours(String courseid){ public int countChaptersHours(String courseid){
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Chapter::getCourseid,courseid) wrapper.eq(Chapter::getCourseId,courseid)
.like(Chapter::getNumshow,"-"); .like(Chapter::getNumshow,"-");
List<Chapter> list = chapterMapper.selectList(wrapper); List<Chapter> list = chapterMapper.selectList(wrapper);
int total=0; int total=0;
for (Chapter sum: list){ for (Chapter sum: list){
String totalclasshours = sum.getTotalclasshours(); String totalclasshours = sum.getTotalClassHours();
total= total+Integer.parseInt(totalclasshours); total= total+Integer.parseInt(totalclasshours);
} }
// System.out.println(size); // System.out.println(size);
@ -354,8 +392,9 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
} }
// 计算课程总章节 // 计算课程总章节
public int countChapters(String courseid){ public int countChapters(String courseid){
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Chapter::getCourseid,courseid); wrapper.eq(Chapter::getCourseId,courseid);
List<Chapter> list = chapterMapper.selectList(wrapper); List<Chapter> list = chapterMapper.selectList(wrapper);
int size = list.size(); int size = list.size();
// System.out.println(size); // System.out.println(size);

@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.CourseResources; import com.teaching.backend.model.entity.CourseResources;
import com.teaching.backend.model.entity.ResourceRelationship; import com.teaching.backend.model.entity.ResourceRelationship;
import java.util.List;
/** /**
* ClassName: ResourcesRelationshipService * ClassName: ResourcesRelationshipService
@ -17,4 +19,7 @@ import com.teaching.backend.model.entity.ResourceRelationship;
public interface ResourcesRelationshipService extends IService<ResourceRelationship> { public interface ResourcesRelationshipService extends IService<ResourceRelationship> {
List<CourseResources> getResource(String id);
List<CourseResources> getResource2(String id, Integer type);
} }

Loading…
Cancel
Save