diff --git a/src/main/java/com/teaching/backend/controller/chapter/ChapterController.java b/src/main/java/com/teaching/backend/controller/chapter/ChapterController.java index 83069df..3aee720 100644 --- a/src/main/java/com/teaching/backend/controller/chapter/ChapterController.java +++ b/src/main/java/com/teaching/backend/controller/chapter/ChapterController.java @@ -76,4 +76,5 @@ public class ChapterController { .count(); return ResultUtils.success(count); } + } diff --git a/src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java b/src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java new file mode 100644 index 0000000..3d29175 --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java @@ -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> AllList(){ + List list= chapterService.list(); + return ResultUtils.success(list); + } + + @ApiOperation("根据课程id查出对应的父子章节") + @GetMapping("/chapter") +public BaseResponse> getCourseChapters2(@RequestParam String courseId){ + return ResultUtils.success(chapterService.getChapterTree(courseId)); + + } + + + @ApiOperation("添加章节") + @PostMapping("/add") + public BaseResponse addChapter2(@RequestBody ChapterDTO chapterDTO){ + chapterService.saveChapter(chapterDTO); + return ResultUtils.success("添加成功!!!!!!!!"); + } + + @ApiOperation("删除章节") + @DeleteMapping("/delete/{id}") + public BaseResponse dlChapter(@PathVariable String id){ + chapterService.deleteChapter(id); + return ResultUtils.success("删除成功"); + } + + + @ApiOperation("修改章节") + @PutMapping("/update") + public BaseResponse udChapter(@RequestBody Chapter chapter){ + + chapter.setUpdateTime(LocalDateTime.now()); + chapterService.updateById(chapter); + return ResultUtils.success("修改成功"); + } +} + + + diff --git a/src/main/java/com/teaching/backend/controller/courses/CoursesController2.java b/src/main/java/com/teaching/backend/controller/courses/CoursesController2.java new file mode 100644 index 0000000..4dd5bf2 --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController2.java @@ -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> getData(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) { + Map result = coursesService.getPagePageSize2(page, pageSize); + + // 将结果放入新的Map对象中返回 + Map 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 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> getResource(@PathVariable String id) { + List relatedResources = resourcesRelationshipService.getResource(id); + return ResultUtils.success(relatedResources); + } + + @ApiOperation("点击详情课程根据id和type查询对应课程的资源") + @GetMapping("/resource/list") + public BaseResponse> getResource2(@RequestParam String id,@RequestParam Integer type) { + List relatedResources = resourcesRelationshipService.getResource2(id,type); + return ResultUtils.success(relatedResources); + } + + } + + + + + diff --git a/src/main/java/com/teaching/backend/mapper/chapter/ChapterMapper.java b/src/main/java/com/teaching/backend/mapper/chapter/ChapterMapper.java index 17a366f..6825636 100644 --- a/src/main/java/com/teaching/backend/mapper/chapter/ChapterMapper.java +++ b/src/main/java/com/teaching/backend/mapper/chapter/ChapterMapper.java @@ -3,6 +3,10 @@ package com.teaching.backend.mapper.chapter; import com.baomidou.mybatisplus.core.mapper.BaseMapper; 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; /** *

@@ -13,5 +17,10 @@ import com.teaching.backend.model.entity.chapter.Chapter; * @since 2024-05-31 */ public interface ChapterMapper extends BaseMapper { + @Select("SELECT * FROM chapter WHERE course_id = #{courseId}") + List selectSectionsByCourseId(@Param("courseId") String courseId); + + @Select("SELECT * FROM course_chapter WHERE course_id = #{courseId} AND (pid = #{parentId} )") + List selectSectionsWithChildren(@Param("courseId") String courseId, @Param("parentId") String parentId); } diff --git a/src/main/java/com/teaching/backend/mapper/courses/CoursesMapper.java b/src/main/java/com/teaching/backend/mapper/courses/CoursesMapper.java index 2a01805..cf5b179 100644 --- a/src/main/java/com/teaching/backend/mapper/courses/CoursesMapper.java +++ b/src/main/java/com/teaching/backend/mapper/courses/CoursesMapper.java @@ -1,7 +1,10 @@ package com.teaching.backend.mapper.courses; 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.vo.courses.CoursesVO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; @@ -21,4 +24,5 @@ public interface CoursesMapper extends BaseMapper { @Select("SELECT * FROM courses LIMIT #{start}, #{pageSize}") List getItemsByPage(@Param("start") int start, @Param("pageSize") int pageSize); + } diff --git a/src/main/java/com/teaching/backend/mapper/resource/CourseResourcesMapper.java b/src/main/java/com/teaching/backend/mapper/resource/CourseResourcesMapper.java index 3fbe380..896f2bc 100644 --- a/src/main/java/com/teaching/backend/mapper/resource/CourseResourcesMapper.java +++ b/src/main/java/com/teaching/backend/mapper/resource/CourseResourcesMapper.java @@ -3,6 +3,9 @@ package com.teaching.backend.mapper.resource; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.teaching.backend.model.entity.CourseResources; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.List; /** * ClassName: FileTableMapper @@ -15,4 +18,5 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface CourseResourcesMapper extends BaseMapper { + } diff --git a/src/main/java/com/teaching/backend/mapper/resource/ResourcesRelationshipMapper.java b/src/main/java/com/teaching/backend/mapper/resource/ResourcesRelationshipMapper.java index b5c8707..7c44c6d 100644 --- a/src/main/java/com/teaching/backend/mapper/resource/ResourcesRelationshipMapper.java +++ b/src/main/java/com/teaching/backend/mapper/resource/ResourcesRelationshipMapper.java @@ -1,6 +1,8 @@ package com.teaching.backend.mapper.resource; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.teaching.backend.model.entity.CourseResources; import com.teaching.backend.model.entity.ResourceRelationship; import org.apache.ibatis.annotations.Mapper; import org.apache.tomcat.websocket.BackgroundProcess; diff --git a/src/main/java/com/teaching/backend/model/dto/chapter/ChapterDTO.java b/src/main/java/com/teaching/backend/model/dto/chapter/ChapterDTO.java new file mode 100644 index 0000000..bff9e24 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/dto/chapter/ChapterDTO.java @@ -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; + + + + +} diff --git a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java index 3ca053a..0606c87 100644 --- a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java +++ b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java @@ -12,6 +12,7 @@ import lombok.experimental.Accessors; import java.io.Serializable; import java.time.LocalDateTime; +import java.util.List; /** *

@@ -34,77 +35,62 @@ public class Chapter implements Serializable { private String id; @ApiModelProperty(value = "创建人") - @TableField("create_by") private String createBy; @ApiModelProperty(value = "创建日期") - @TableField("create_time") private LocalDateTime createTime; @ApiModelProperty(value = "更新人") - @TableField("update_by") private String updateBy; @ApiModelProperty(value = "更新日期") - @TableField("update_time") private LocalDateTime updateTime; @ApiModelProperty(value = "所属部门") - @TableField("sys_org_code") private String sysOrgCode; @ApiModelProperty(value = "序号") - @TableField("num") - private Integer num; + private int orderNum; @ApiModelProperty(value = "名称") - @TableField("name") private String name; @ApiModelProperty(value = "简介") - @TableField("content") private String content; @ApiModelProperty(value = "父级节点") - @TableField("pid") private String pid; @ApiModelProperty(value = "课程") - @TableField("courseid") - private String courseid; + + private String courseId; @ApiModelProperty(value = "课程目标") - @TableField("courseobjectivesid") - private String courseobjectivesid; + private String courseObjectivesId; @ApiModelProperty(value = "总学时") - @TableField("totalclasshours") - private String totalclasshours; + private String totalClassHours; @ApiModelProperty(value = "要求") - @TableField("requirement") private String requirement; @ApiModelProperty(value = "线上学时") - @TableField("onlinclasshours") - private String onlinclasshours; - + private String onlineClassHours; @ApiModelProperty(value = "周次") - @TableField("zc") private String zc; @ApiModelProperty(value = "资源") - @TableField("ziyuan") private String ziyuan; @ApiModelProperty(value = "资源文件") - @TableField("zywj") private String zywj; @ApiModelProperty(value = "内部序号显示") - @TableField("numshow") private String numshow; + @ApiModelProperty(value = "子章节") + @TableField(exist = false) + private List children; // 用于存储子章节 } diff --git a/src/main/java/com/teaching/backend/service/chapter/IChapterService.java b/src/main/java/com/teaching/backend/service/chapter/IChapterService.java index a32fa02..e2cd18d 100644 --- a/src/main/java/com/teaching/backend/service/chapter/IChapterService.java +++ b/src/main/java/com/teaching/backend/service/chapter/IChapterService.java @@ -2,6 +2,7 @@ package com.teaching.backend.service.chapter; 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.vo.chapter.ChapterVo; @@ -23,4 +24,12 @@ public interface IChapterService extends IService { Boolean deleteAfterUpdate(String id); + + + List getChapterTree(String courseId); + + + void saveChapter(ChapterDTO chapterDTO); + + void deleteChapter(String id); } diff --git a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java index a812058..7d3014b 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java @@ -10,6 +10,7 @@ import com.teaching.backend.model.vo.courses.CoursesVO; import javax.servlet.http.HttpServletResponse; import java.util.List; +import java.util.Map; /** @@ -38,4 +39,6 @@ public interface ICoursesService extends IService { void down(HttpServletResponse response, String id) throws Exception; CoursesVO getByIdCourseVo(String courseid); + + Map getPagePageSize2(int page, int pageSize); } diff --git a/src/main/java/com/teaching/backend/service/impl/CourseResourcesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/CourseResourcesServiceImpl.java index 5340db3..0057f19 100644 --- a/src/main/java/com/teaching/backend/service/impl/CourseResourcesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/CourseResourcesServiceImpl.java @@ -39,8 +39,8 @@ import java.util.function.Consumer; */ @Service public class CourseResourcesServiceImpl extends ServiceImpl implements CourseResourcesService { - @Resource - ResourcesRelationshipService resourcesRelationshipService; +// @Resource +// ResourcesRelationshipService resourcesRelationshipService; @Autowired private CourseResourcesMapper courseResourcesMapper; @@ -64,7 +64,7 @@ public class CourseResourcesServiceImpl extends ServiceImpl implements ResourcesRelationshipService { +@Autowired + CourseResourcesService courseResourcesService; + @Override + public List getResource(String id) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + + lambdaQueryWrapper.eq(ResourceRelationship::getCourseid, id); + List resourceRelationshipList = this.list(lambdaQueryWrapper); + + List resourceIds = resourceRelationshipList.stream() + .map(ResourceRelationship::getResourceid) + .collect(Collectors.toList()); + + if (!resourceIds.isEmpty()) { + + LambdaQueryWrapper courseResourcesQueryWrapper = new LambdaQueryWrapper<>(); + courseResourcesQueryWrapper.in(CourseResources::getId, resourceIds); + return courseResourcesService.list(courseResourcesQueryWrapper); + } + + return Collections.emptyList(); + } + + @Override + public List getResource2(String id, Integer type) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(ResourceRelationship::getCourseid, id); + List resourceRelationshipList = this.list(lambdaQueryWrapper); + + List resourceIds = resourceRelationshipList.stream() + .map(ResourceRelationship::getResourceid) + .collect(Collectors.toList()); +if (type==null){ + + if (!resourceIds.isEmpty()) { + + LambdaQueryWrapper courseResourcesQueryWrapper = new LambdaQueryWrapper<>(); + courseResourcesQueryWrapper.in(CourseResources::getId, resourceIds); + return courseResourcesService.list(courseResourcesQueryWrapper); + } + +}else { + LambdaQueryWrapper courseResourcesQueryWrapper = new LambdaQueryWrapper<>(); + courseResourcesQueryWrapper.in(CourseResources::getId, resourceIds) + .in(CourseResources::getType,type); + return courseResourcesService.list(courseResourcesQueryWrapper); +} + + + return Collections.emptyList(); + } + } diff --git a/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java index 3e99829..26c8c5c 100644 --- a/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java @@ -1,19 +1,21 @@ package com.teaching.backend.service.impl.chapter; -import cn.hutool.core.annotation.Link; 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.chapter.ChapterMapper; +import com.teaching.backend.model.dto.chapter.ChapterDTO; import com.teaching.backend.model.entity.chapter.Chapter; import com.teaching.backend.model.vo.chapter.ChapterVo; -import com.teaching.backend.model.vo.courses.CoursesVO; 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.stereotype.Service; +import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -34,14 +36,15 @@ public class ChapterServiceImpl extends ServiceImpl impl public String updateNumShow(Chapter chapter) { String finalNumShow; - String courseid = chapter.getCourseid(); + String courseid = chapter.getCourseId(); String pid = chapter.getPid(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); Long countChapter ; // pid为0时,说明为章 if("0".equals(pid)|| "".equals(pid)){ - wrapper.eq(Chapter::getCourseid,courseid); + wrapper.eq(Chapter::getCourseId,courseid); countChapter = chapterMapper.selectCount(wrapper); + finalNumShow=String.valueOf(countChapter+1); // chapter.setNumshow(String.valueOf(countChapter+1)); // System.out.println(chapter.getNumshow()); @@ -51,7 +54,7 @@ public class ChapterServiceImpl extends ServiceImpl impl String parentNumShow =chapter1.getNumshow(); System.out.println("909090"); System.out.println(parentNumShow); - wrapper.eq(Chapter::getCourseid,courseid) + wrapper.eq(Chapter::getCourseId,courseid) .eq(Chapter::getPid,pid); countChapter = chapterMapper.selectCount(wrapper); System.out.println("-=-=-=-=-="+countChapter); @@ -79,7 +82,7 @@ public class ChapterServiceImpl extends ServiceImpl impl @Override public LinkedList getCourseChapter(String courseid) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(Chapter::getCourseid,courseid) + wrapper.eq(Chapter::getCourseId,courseid) .orderByAsc(Chapter::getNumshow); List list = chapterMapper.selectList(wrapper); LinkedList linkedList = new LinkedList<>(list); @@ -91,7 +94,7 @@ public class ChapterServiceImpl extends ServiceImpl impl // LinkedList list = new LinkedList<>(); // 获得所有的节,并按顺序进行排列 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(Chapter::getCourseid,courseid) + wrapper.eq(Chapter::getCourseId,courseid) .like(Chapter::getNumshow,"-") .orderByAsc(Chapter::getNumshow); List prelist = chapterMapper.selectList(wrapper); @@ -99,7 +102,7 @@ public class ChapterServiceImpl extends ServiceImpl impl System.out.println(prelist); // 获得所有的章节信息 LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); - wrapper1.eq(Chapter::getCourseid,courseid) + wrapper1.eq(Chapter::getCourseId,courseid) .notLike(Chapter::getNumshow,"-") .orderByAsc(Chapter::getNumshow); List chapterList = chapterMapper.selectList(wrapper1); @@ -140,17 +143,114 @@ public class ChapterServiceImpl extends ServiceImpl impl public Boolean deleteAfterUpdate(String id) { Chapter chapter = chapterMapper.selectById(id); String numshow = chapter.getNumshow(); - String courseid = chapter.getCourseid(); + String courseid = chapter.getCourseId(); + updateNumShow(numshow, courseid); chapterMapper.deleteById(id); return true; } + + @Override + public List getChapterTree(String courseId) { + System.out.println(courseId); + + List chapters=baseMapper.selectSectionsByCourseId(courseId); + System.out.println(chapters); + Map chapterMap=new HashMap<>(); + + List 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,"请求参数不能为空"); + } + LambdaQueryWrapperqueryWrapper=new LambdaQueryWrapper<>(); + queryWrapper.eq(Chapter::getId,id); + + + LambdaQueryWrapperlambdaQueryWrapper=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){ // 查询课程章节 getCourseChapter LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(Chapter::getCourseid,courseid) + wrapper.eq(Chapter::getCourseId,courseid) .orderByAsc(Chapter::getNumshow); List chapterList = chapterMapper.selectList(wrapper); System.out.println("0-0-0-0-00-------"); diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index 7c383bf..67f5c47 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -43,7 +43,6 @@ import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; -import java.util.stream.Stream; /** *

@@ -59,6 +58,7 @@ public class CoursesServiceImpl extends ServiceImpl impl @Autowired private CourseObjectivesServiceImpl objectivesService; + @Autowired ChapterMapper chapterMapper; @@ -304,6 +304,7 @@ public class CoursesServiceImpl extends ServiceImpl impl @Override public CoursesVO getByIdCourseVo(String courseid) { Courses courses = coursesMapper.selectById(courseid); + CoursesVO coursesVO = BeanUtil.copyProperties(courses,CoursesVO.class); coursesVO.setTotalchapter(countChapters(courseid)); coursesVO.setTotalHours(countHours(courseid)); @@ -314,6 +315,43 @@ public class CoursesServiceImpl extends ServiceImpl impl return coursesVO; } + @Override + public Map getPagePageSize2(int page, int pageSize) { + Page pageInfo=new Page<>(page,pageSize); + + LambdaQueryWrapper queryWrapper=new LambdaQueryWrapper<>(); + + this.page(pageInfo,queryWrapper); + + List list=pageInfo.getRecords(); + + + List 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 result = new HashMap<>(); + result.put("courses", coursesVo); + result.put("totalcount", totalcount); + result.put("totalPages", totalPages); + result.put("currentPage", page); + + return result; + + } + @Override public List getPagePageSize(int page, int pageSize) { int startIndex = (page-1) * pageSize; @@ -341,12 +379,12 @@ public class CoursesServiceImpl extends ServiceImpl impl // 计算课程已分配的学时 计算章的学时(即已包含了小节的学时) public int countChaptersHours(String courseid){ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(Chapter::getCourseid,courseid) + wrapper.eq(Chapter::getCourseId,courseid) .like(Chapter::getNumshow,"-"); List list = chapterMapper.selectList(wrapper); int total=0; for (Chapter sum: list){ - String totalclasshours = sum.getTotalclasshours(); + String totalclasshours = sum.getTotalClassHours(); total= total+Integer.parseInt(totalclasshours); } // System.out.println(size); @@ -354,8 +392,9 @@ public class CoursesServiceImpl extends ServiceImpl impl } // 计算课程总章节 public int countChapters(String courseid){ + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(Chapter::getCourseid,courseid); + wrapper.eq(Chapter::getCourseId,courseid); List list = chapterMapper.selectList(wrapper); int size = list.size(); // System.out.println(size); diff --git a/src/main/java/com/teaching/backend/service/resource/ResourcesRelationshipService.java b/src/main/java/com/teaching/backend/service/resource/ResourcesRelationshipService.java index 22b7e06..937abc9 100644 --- a/src/main/java/com/teaching/backend/service/resource/ResourcesRelationshipService.java +++ b/src/main/java/com/teaching/backend/service/resource/ResourcesRelationshipService.java @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.teaching.backend.model.entity.CourseResources; import com.teaching.backend.model.entity.ResourceRelationship; +import java.util.List; + /** * ClassName: ResourcesRelationshipService @@ -17,4 +19,7 @@ import com.teaching.backend.model.entity.ResourceRelationship; public interface ResourcesRelationshipService extends IService { + List getResource(String id); + + List getResource2(String id, Integer type); }