章节模块

master
叮叮咚咚 8 months ago
parent 05897862fa
commit 4c819cbc71
  1. 79
      src/main/java/com/teaching/backend/controller/chapter/ChapterController.java
  2. 3
      src/main/java/com/teaching/backend/controller/courses/CoursesController.java
  3. 42
      src/main/java/com/teaching/backend/controller/know/KnowRelationshipController.java
  4. 117
      src/main/java/com/teaching/backend/entity/Chapter.java
  5. 5
      src/main/java/com/teaching/backend/mapper/chapter/ChapterMapper.xml
  6. 18
      src/main/java/com/teaching/backend/mapper/know/KnowRelationshipMapper.java
  7. 15
      src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java
  8. 1
      src/main/java/com/teaching/backend/model/entity/know/Know.java
  9. 46
      src/main/java/com/teaching/backend/model/entity/know/KnowRelationship.java
  10. 58
      src/main/java/com/teaching/backend/model/vo/chapter/ChapterVo.java
  11. 9
      src/main/java/com/teaching/backend/model/vo/courses/CoursesVO.java
  12. 13
      src/main/java/com/teaching/backend/service/chapter/IChapterService.java
  13. 1
      src/main/java/com/teaching/backend/service/courses/ICoursesService.java
  14. 220
      src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java
  15. 73
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  16. 21
      src/main/java/com/teaching/backend/service/impl/know/KnowRelationshipServiceImpl.java
  17. 151
      src/test/java/com/teaching/TeachingBackendApplicationTests.java

@ -0,0 +1,79 @@
package com.teaching.backend.controller.chapter;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.model.vo.chapter.ChapterVo;
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.util.LinkedList;
import java.util.List;
@Api(tags = "课程章节管理接口")
@RestController
@RequestMapping("/chapter")
public class ChapterController {
@Autowired
private IChapterService chapterService;
@ApiOperation("查看所有章节")
@GetMapping("/list")
public BaseResponse<List<Chapter>> AllList(){
List<Chapter> list = chapterService.list();
return ResultUtils.success(list);
}
@ApiOperation("添加章节")
@PostMapping("/add")
public BaseResponse<Boolean> addChapter(@RequestBody Chapter chapter){
chapter.setNumshow(chapterService.updateNumShow(chapter));
System.out.println("-=-=--=-000"+chapter.getNumshow());
boolean save = chapterService.save(chapter);
return ResultUtils.success(save);
}
@ApiOperation("删除章节信息")
@DeleteMapping("/{id}")
public BaseResponse<Boolean> delete(@PathVariable String id){
Boolean chapter = chapterService.deleteAfterUpdate(id);
return ResultUtils.success(chapter);
}
@ApiOperation("更新章节")
@PutMapping
public BaseResponse<Boolean> updateChapter(@RequestBody Chapter chapter){
System.out.println(chapter);
boolean b = chapterService.updateById(chapter);
return ResultUtils.success(b);
}
@ApiOperation("查看所有章节linkedlist")
@GetMapping("/listall/{courseid}")
public BaseResponse<LinkedList<Chapter>> getAll(@PathVariable String courseid){
LinkedList<Chapter> list =chapterService.getCourseChapter(courseid);
System.out.println(list);
return ResultUtils.success(list);
}
@ApiOperation("章节顺序linkedlist")
@GetMapping("/aaa/{courseid}")
public BaseResponse<LinkedList<ChapterVo>> get(@PathVariable String courseid){
LinkedList<ChapterVo> list =chapterService.getChapterSection(courseid);
System.out.println(list);
return ResultUtils.success(list);
}
@ApiOperation("计算章的个数")
@GetMapping("/count/{courseid}")
public BaseResponse<Long> getChapterCount(@PathVariable String courseid){
LinkedList<Chapter> list =chapterService.getCourseChapter(courseid);
Long count=list.stream()
.filter( str -> !str.getNumshow().contains("-"))
.count();
return ResultUtils.success(count);
}
}

@ -77,6 +77,9 @@ public class CoursesController {
@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);

@ -0,0 +1,42 @@
package com.teaching.backend.controller.know;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.model.entity.know.Know;
import com.teaching.backend.model.entity.know.KnowRelationship;
import com.teaching.backend.service.know.IKnowRelationshipService;
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.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author author
* @since 2024-06-20
*/
@Api(tags = "知识点章节关系")
@RestController
@RequestMapping("/know-relationship")
public class KnowRelationshipController {
@Autowired
private IKnowRelationshipService knowRelationshipService;
@ApiOperation("添加课程知识点关系")
@PostMapping()
public BaseResponse<Boolean> add(@RequestBody KnowRelationship knowRelationship){
boolean save = knowRelationshipService.save(knowRelationship);
return ResultUtils.success(save);
}
@GetMapping()
public BaseResponse<List<KnowRelationship>> getAll(){
List<KnowRelationship> list = knowRelationshipService.list();
return ResultUtils.success(list);
}
}

@ -1,117 +0,0 @@
package com.teaching.backend.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
*
* </p>
*
* @author author
* @since 2024-06-07
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("chapter")
@ApiModel(value="Chapter对象", description="")
public class Chapter implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.AUTO)
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;
@ApiModelProperty(value = "名称")
@TableField("name")
private String name;
@ApiModelProperty(value = "简介")
@TableField("content")
private String content;
@ApiModelProperty(value = "父级节点")
@TableField("pid")
private String pid;
@ApiModelProperty(value = "是否有子节点")
@TableField("has_child")
private String hasChild;
@ApiModelProperty(value = "课程")
@TableField("courseid")
private String courseid;
@ApiModelProperty(value = "课程目标")
@TableField("courseobjectivesid")
private String courseobjectivesid;
@ApiModelProperty(value = "总学时")
@TableField("totalclasshours")
private String totalclasshours;
@ApiModelProperty(value = "要求")
@TableField("requirement")
private String requirement;
@ApiModelProperty(value = "线上学时")
@TableField("onlinclasshours")
private String onlinclasshours;
@ApiModelProperty(value = "知识点")
@TableField("knowid")
private String knowid;
@ApiModelProperty(value = "周次")
@TableField("zc")
private String zc;
@ApiModelProperty(value = "资源")
@TableField("ziyuan")
private String ziyuan;
@ApiModelProperty(value = "知识点")
@TableField("know")
private String know;
@ApiModelProperty(value = "内部序号显示")
@TableField("numshow")
private String numshow;
}

@ -1,5 +0,0 @@
<?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="com.teaching.backend.mapper.ChapterMapper">
</mapper>

@ -0,0 +1,18 @@
package com.teaching.backend.mapper.know;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.know.KnowRelationship;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author author
* @since 2024-06-20
*/
@Mapper
public interface KnowRelationshipMapper extends BaseMapper<KnowRelationship> {
}

@ -30,7 +30,7 @@ public class Chapter implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.AUTO)
@TableId(value = "id", type = IdType.ASSIGN_UUID)
private String id;
@ApiModelProperty(value = "创建人")
@ -69,10 +69,6 @@ public class Chapter implements Serializable {
@TableField("pid")
private String pid;
@ApiModelProperty(value = "是否有子节点")
@TableField("has_child")
private String hasChild;
@ApiModelProperty(value = "课程")
@TableField("courseid")
private String courseid;
@ -93,9 +89,6 @@ public class Chapter implements Serializable {
@TableField("onlinclasshours")
private String onlinclasshours;
@ApiModelProperty(value = "知识点")
@TableField("knowid")
private String knowid;
@ApiModelProperty(value = "周次")
@TableField("zc")
@ -105,9 +98,9 @@ public class Chapter implements Serializable {
@TableField("ziyuan")
private String ziyuan;
@ApiModelProperty(value = "知识点")
@TableField("know")
private String know;
@ApiModelProperty(value = "资源文件")
@TableField("zywj")
private String zywj;
@ApiModelProperty(value = "内部序号显示")
@TableField("numshow")

@ -17,6 +17,7 @@ import java.time.LocalDateTime;
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("know")
public class Know implements Serializable {

@ -0,0 +1,46 @@
package com.teaching.backend.model.entity.know;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
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;
/**
* <p>
*
* </p>
*
* @author author
* @since 2024-06-20
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("know_relationship")
@ApiModel(value="KnowRelationship对象", description="")
public class KnowRelationship implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "章节id")
@TableField("chapterId")
private String chapterId;
@ApiModelProperty(value = "课程id")
@TableField("courseId")
private String courseId;
@ApiModelProperty(value = "知识点id")
@TableField("knowId")
private int knowId;
}

@ -0,0 +1,58 @@
package com.teaching.backend.model.vo.chapter;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.teaching.backend.model.entity.chapter.Chapter;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Data
public class ChapterVo {
private String id;
@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;
@ApiModelProperty(value = "课程目标")
@TableField("courseobjectivesid")
private String courseobjectivesid;
@ApiModelProperty(value = "总学时")
@TableField("totalclasshours")
private String totalclasshours;
@ApiModelProperty(value = "线上学时")
@TableField("onlinclasshours")
private String onlinclasshours;
@ApiModelProperty(value = "知识点id")
@TableField("knowid")
private String knowid;
@ApiModelProperty(value = "周次")
@TableField("zc")
private String zc;
@ApiModelProperty(value = "内部序号显示")
@TableField("numshow")
private String numshow;
private List<Chapter> chapterSection;
}

@ -51,10 +51,19 @@ public class CoursesVO {
@ApiModelProperty(value = "课程总学时",required = true)
private Integer totalHours;
@ApiModelProperty(value = "课程已分配学时",required = true)
private Integer totalAssignHours;
@ApiModelProperty(value = "课程未分配学时",required = true)
private Integer totalNotAssignHours;
@ApiModelProperty(value = "课程章节总数",required = true)
private Integer totalchapter;
@ApiModelProperty(value = "课程知识点总数",required = true)
private Integer totalKnow;
@ApiModelProperty(value = "课程目标",required = true)
private String objectContent;
}

@ -3,6 +3,10 @@ package com.teaching.backend.service.chapter;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.model.vo.chapter.ChapterVo;
import java.util.LinkedList;
import java.util.List;
/**
*
@ -10,4 +14,13 @@ import com.teaching.backend.model.entity.chapter.Chapter;
* @since 2024-05-31
*/
public interface IChapterService extends IService<Chapter> {
String updateNumShow(Chapter chapter);
LinkedList<Chapter> getAll();
LinkedList<Chapter> getCourseChapter(String courseid);
LinkedList<ChapterVo> getChapterSection(String courseid);
Boolean deleteAfterUpdate(String id);
}

@ -37,4 +37,5 @@ public interface ICoursesService extends IService<Courses> {
void down(HttpServletResponse response, String id) throws Exception;
CoursesVO getByIdCourseVo(String courseid);
}

@ -1,12 +1,22 @@
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.mapper.chapter.ChapterMapper;
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.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
*
* @author author
@ -14,4 +24,214 @@ import org.springframework.stereotype.Service;
*/
@Service
public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> implements IChapterService {
@Autowired
private ChapterMapper chapterMapper;
// private int count=0;
List<Chapter> list=new ArrayList<>();
@Override
public String updateNumShow(Chapter chapter) {
String finalNumShow;
String courseid = chapter.getCourseid();
String pid = chapter.getPid();
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>();
Long countChapter ;
// pid为0时,说明为章
if("0".equals(pid)|| "".equals(pid)){
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());
}else{
// 为小节
Chapter chapter1 = chapterMapper.selectById(pid);
String parentNumShow =chapter1.getNumshow();
System.out.println("909090");
System.out.println(parentNumShow);
wrapper.eq(Chapter::getCourseid,courseid)
.eq(Chapter::getPid,pid);
countChapter = chapterMapper.selectCount(wrapper);
System.out.println("-=-=-=-=-="+countChapter);
finalNumShow=parentNumShow + "-" + String.valueOf(countChapter + 1);
}
System.out.println("-=-=-=-=11");
System.out.println(finalNumShow);
return finalNumShow;
}
@Override
public LinkedList<Chapter> getAll() {
List<Chapter> list = chapterMapper.selectList(null);
LinkedList<Chapter> linkedList = new LinkedList<>(list);
int i=0;
for (Chapter chapter:linkedList){
System.out.println(linkedList.get(i));
System.out.println(i+"----"+chapter);
i++;
}
System.out.println(linkedList);
return linkedList;
}
@Override
public LinkedList<Chapter> getCourseChapter(String courseid) {
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Chapter::getCourseid,courseid)
.orderByAsc(Chapter::getNumshow);
List<Chapter> list = chapterMapper.selectList(wrapper);
LinkedList<Chapter> linkedList = new LinkedList<>(list);
return linkedList;
}
@Override
public LinkedList<ChapterVo> getChapterSection(String courseid){
// LinkedList<Chapter> list = new LinkedList<>();
// 获得所有的节,并按顺序进行排列
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Chapter::getCourseid,courseid)
.like(Chapter::getNumshow,"-")
.orderByAsc(Chapter::getNumshow);
List<Chapter> prelist = chapterMapper.selectList(wrapper);
System.out.println("所有的节");
System.out.println(prelist);
// 获得所有的章节信息
LambdaQueryWrapper<Chapter> wrapper1 = new LambdaQueryWrapper<>();
wrapper1.eq(Chapter::getCourseid,courseid)
.notLike(Chapter::getNumshow,"-")
.orderByAsc(Chapter::getNumshow);
List<Chapter> chapterList = chapterMapper.selectList(wrapper1);
System.out.println("0-0-0-0所有的章------------");
System.out.println(chapterList);
// 类型转换chapter => chapterVo
List<ChapterVo> chapterVoList = BeanUtil.copyToList(chapterList, ChapterVo.class);
chapterVoList = chapterVoList.stream().map((item) ->{
for (int i=0;i<prelist.size();i++){
System.out.println("=====================");
// System.out.println(prelist.get(i).getNumshow().split("-")[0].equals(item.getNumshow()));
if (prelist.get(i).getNumshow().split("-")[0].equals(item.getNumshow())){
// System.out.println(item.getNumshow()+"[][][]"+i);
System.out.println("88888888888888888888888888"+prelist.get(i).getNumshow().split("-")[0]);
// Chapter chapter = prelist.get(i);
list.add(prelist.get(i));
item.setChapterSection(list);
System.out.println(prelist.get(i).getNumshow()+"-------------+121--");
}else {
// list1=list;
// System.out.println(item.getNumshow() + "[8888][][]");
// System.out.println(prelist.get(i).getNumshow().split("-")[0]);
// item.setChapterSection(list1);
System.out.println("000000000");
System.out.println(list);
list = new ArrayList<>();
}
}
return item;
}).collect(Collectors.toList());
System.out.println("11111111111111111111111111111111111111111");
System.out.println(chapterVoList);
LinkedList<ChapterVo> list2 = new LinkedList<>(chapterVoList);
return list2;
}
@Override
public Boolean deleteAfterUpdate(String id) {
Chapter chapter = chapterMapper.selectById(id);
String numshow = chapter.getNumshow();
String courseid = chapter.getCourseid();
updateNumShow(numshow, courseid);
chapterMapper.deleteById(id);
return true;
}
public void updateNumShow(String numshow, String courseid){
// 查询课程章节 getCourseChapter
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Chapter::getCourseid,courseid)
.orderByAsc(Chapter::getNumshow);
List<Chapter> chapterList = chapterMapper.selectList(wrapper);
System.out.println("0-0-0-0-00-------");
System.out.println(chapterList);
List<Chapter> newlist = new ArrayList<>();
int count=0,j=0;
int i = numshow.indexOf("-");
// 删除的为章
if(i==-1){
System.out.println("9999999");
for(int k=0;k<chapterList.size();k++){
// System.out.println("=-=-=--="+k+"-=-=-==-"+numshow);
// System.out.println(chapterList.get(k).getNumshow());
// System.out.println(chapterList.get(k).getNumshow().equals(numshow));
if (chapterList.get(k).getNumshow().equals(numshow)){
j=k;
}else if (chapterList.get(k).getNumshow().contains(numshow+"-")){
count++;
chapterMapper.deleteById(chapterList.get(k).getId());
}else{
System.out.println(chapterList.get(k));
newlist.add(chapterList.get(k));
}
}
System.out.println("======"+count+"======"+j);
System.out.println(newlist);
for (int k=j;k< newlist.size();k++){
Chapter chapter= newlist.get(k);
if (newlist.get(k).getNumshow().indexOf("-")==-1){
chapter.setNumshow(String.valueOf(Integer.parseInt(newlist.get(k).getNumshow())-1));
chapterMapper.updateById(chapter);
newlist.set(k,chapter);
}else{
String[] split = newlist.get(k).getNumshow().split("-");
String s = String.valueOf(Integer.parseInt(split[0]) - 1);
chapter.setNumshow(s+"-"+split[1]);
chapterMapper.updateById(chapter);
System.out.println(chapter);
newlist.set(k,chapter);
}
// if (list.get(k).getNumshow().contains(numshow+"-") ){
// chapterMapper.deleteById(list.get(i).getId());
// }else{
// int num = Integer.parseInt(list.get(i).getNumshow()) - 1;
// list.get(i).setNumshow( String.valueOf(num) );
// }
}
}
else{
String[] split = numshow.split("-");
for (int k=0;k< chapterList.size();k++){
System.out.println("009988"+String.valueOf(Integer.parseInt(split[0])+1));
// 找到下一章的起始点
if (chapterList.get(k).getNumshow().equals(String.valueOf(Integer.parseInt(split[0])+1))){
count=k;
}
if (chapterList.get(k).getNumshow().equals(numshow)){
j=k;
chapterMapper.deleteById(chapterList.get(k).getId());
}else{
newlist.add(chapterList.get(k));
}
}
System.out.println(count+"''''''"+j);
for (int k=j;k<count-1;k++){
// System.out.println(newlist.get(k));
String[] split1 = newlist.get(k).getNumshow().split("-");
String s = split1[0]+"-"+String.valueOf(Integer.parseInt(split1[1]) - 1);
Chapter chapter= newlist.get(k);
chapter.setNumshow(s);
chapterMapper.updateById(chapter);
newlist.set(k,chapter);
}
}
System.out.println("111111111110-0-0-0-00-------");
System.out.println(newlist);
}
// public LinkedList<ChapterVo> deleteChapterSection(String courseid,String numshow){
//
// }
}

@ -62,9 +62,15 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
@Autowired
private CourseObjectivesServiceImpl objectivesService;
@Autowired
ChapterMapper chapterMapper;
@Autowired
CoursesMapper coursesMapper;
@Autowired
KnowRelationshipMapper knowRelationshipMapper;
@Autowired
CourseObjectivesMapper courseObjectivesMapper;
@Autowired
@ -138,6 +144,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
} else {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "这个课程已经存在了!请联系系统相关人员为您导入课程数据!");
}
}
@Override
@ -277,6 +284,19 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
learningRecordsMapper.delete(lambdaQueryWrapper);
}
@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));
coursesVO.setTotalAssignHours(countChaptersHours(courseid));
coursesVO.setTotalNotAssignHours(coursesVO.getTotalHours()-coursesVO.getTotalAssignHours());
coursesVO.setTotalKnow(countKnow(courseid));
System.out.println(coursesVO);
return coursesVO;
}
@Override
public List<CoursesVO> getPagePageSize(int page, int pageSize) {
int startIndex = (page-1) * pageSize;
@ -284,20 +304,46 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
// List<Courses> list = coursesMapper.selectList(null);
List<CoursesVO> coursesVo = BeanUtil.copyToList(list, CoursesVO.class);
coursesVo = coursesVo.stream().map((item) -> {
item.setTotalHours(countHours(item.getId()));
item.setTotalchapter(100);
item.setTotalKnow(100);
// if (StringUtils.isBlank(item.getName()) ||
// StringUtils.isBlank(item.getDescription()) ){
// throw new BusinessException(ErrorCode.OPERATION_ERROR,"数据格式有问题,请修改");
// }
item.setTotalchapter(countChapters(item.getId()));
item.setTotalKnow(countKnow(item.getId()));
return item;
}).collect(Collectors.toList());
return coursesVo;
}
// 计算课程知识点个数
public int countKnow(String courseid){
LambdaQueryWrapper<KnowRelationship> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(KnowRelationship::getCourseId,courseid);
List<KnowRelationship> list = knowRelationshipMapper.selectList(wrapper);
int total=list.size();
return total;
}
// 计算课程已分配的学时 计算章的学时(即已包含了小节的学时)
public int countChaptersHours(String courseid){
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Chapter::getCourseid,courseid)
.like(Chapter::getNumshow,"-");
List<Chapter> list = chapterMapper.selectList(wrapper);
int total=0;
for (Chapter sum: list){
String totalclasshours = sum.getTotalclasshours();
total= total+Integer.parseInt(totalclasshours);
}
// System.out.println(size);
return total;
}
// 计算课程总章节
public int countChapters(String courseid){
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Chapter::getCourseid,courseid);
List<Chapter> list = chapterMapper.selectList(wrapper);
int size = list.size();
// System.out.println(size);
return size;
}
// 计算课程总学时
@Override
public int countHours(String id) {
Courses courses = coursesMapper.selectById(id);
@ -372,6 +418,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
Integer course_classhour = courses.getClasshours();
String course_description = courses.getDescription();
//查询课程目标
List<CourseObjectivesTreeVO> courseObjectivesTreeVO = objectivesService.queryCourseObjectivesTree(id);
//准备数据
@ -382,6 +429,8 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
ObjectiveContents content = contents.get(i);
overall_goal.append(content.getContent());
}
System.out.println(overall_goal);
//分项目标
StringBuilder sub_objectives = new StringBuilder();
//课程目标数
@ -398,6 +447,12 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
if (i != courseObjectivesTreeVO.get(0).getCourseObjectivesTrees().size() - 1){
sub_objectives.append("\r\n ");
}
//价值目标
if (i == 2){
for (ObjectiveContents c : content.getContents()) {
value_goals.append(c.getContent()).append("\n");
}
}
}
System.out.println("课程目标数:"+course_number);
Map<String,Object> params = new HashMap<String,Object>();
@ -461,7 +516,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
ServletOutputStream outputStream = response.getOutputStream();
response.setHeader( "Content-Disposition", "attachment;filename=" + new String(filename.getBytes(),"ISO8859-1"));
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
document.write(outputStream);
xwpfDocument.write(outputStream);
}

@ -0,0 +1,21 @@
package com.teaching.backend.service.impl.know;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.mapper.know.KnowRelationshipMapper;
import com.teaching.backend.model.entity.know.KnowRelationship;
import com.teaching.backend.service.know.IKnowRelationshipService;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author author
* @since 2024-06-20
*/
@Service
public class KnowRelationshipServiceImpl extends ServiceImpl<KnowRelationshipMapper, KnowRelationship> implements IKnowRelationshipService {
}

@ -8,7 +8,156 @@ import java.util.*;
@SpringBootTest
class TeachingBackendApplicationTests {
Map<String, List<String>> userLearningRecords = new HashMap<>();
// Map<String, List<String>> userLearningRecords = new HashMap<>();
public static void main(String[] args) {
// String[] data = {"1", "2", "3", "7", "4", "1-1", "1-5", "1-4", "1-9", "1-2", "3-1", "3-2","1-3","1-6"};
List<String> linkedList = new ArrayList<>();
linkedList.add("1");
linkedList.add("1-1");
linkedList.add("1-2");
linkedList.add("1-3");
linkedList.add("2");
linkedList.add("2-1");
linkedList.add("2-2");
linkedList.add("2-3");
linkedList.add("3");
linkedList.add("3-1");
linkedList.add("3-2");
linkedList.add("3-3");
linkedList.add("4");
linkedList.add("5");
// String x="1";
// String x1="1011-2456";
// String[] split = x1.split("-");
// System.out.println(split[0]);
// System.out.println(split[1]);
// int i = x.indexOf("-");
// System.out.println(i);
// for (String str : data) {
//
// insertInOrder(linkedList, str);
// }
System.out.println("9999");
System.out.println(linkedList);
// String x="2";
String x1="2-1";
int count=0,j=0;
List<String> list = new ArrayList<>();
String[] split1 = x1.split("-");
System.out.println(String.valueOf(Integer.parseInt(split1[0])+1));
for (int i=0;i<linkedList.size();i++){
if (linkedList.get(i).equals(String.valueOf(Integer.parseInt(split1[0])+1))){
j=i;
}
if (linkedList.get(i)==x1){
count=i;
}else{
list.add(linkedList.get(i));
}
}
System.out.println(j);
System.out.println(count);
for (int i=count;i<j-1;i++){
String[] split = list.get(i).split("-");
// System.out.println(split[0]);
// System.out.println(split[1]);
String s = String.valueOf(Integer.parseInt(split[1]) - 1);
list.set(i,split[0]+"-"+s);
}
// for (int i=0;i<linkedList.size();i++){
// if (linkedList.get(i)==x){
//
// j=i;
// }else if (linkedList.get(i).contains(x+"-")){
// count++;
// } else{
// list.add(linkedList.get(i));
// }
// }
// for (int i=j;i<list.size();i++){
// if (list.get(i).indexOf("-")==-1){
// list.set(i,String.valueOf(Integer.parseInt(list.get(i))-1));
// }else{
// String[] split = list.get(i).split("-");
// String s = String.valueOf(Integer.parseInt(split[0]) - 1);
// list.set(i,s+"-"+split[1]);
// }
//
// }
System.out.println(list);
//
// String newData = "1";
// insertInOrder(linkedList, newData);
// printList(linkedList);
//
// deleteEntry(linkedList, newData);
// printList(linkedList);
// deleteEntry(linkedList, "1");
// printList(linkedList);
}
// private static void insertInOrder(LinkedList<String> linkedList, String newData) {
// ListIterator<String> iterator = linkedList.listIterator();
//
// while (iterator.hasNext()) {
// String current = iterator.next();
//
// if (newData.compareTo(current) <= 0) {
// iterator.previous(); // 回到插入位置
// iterator.add(newData);
// return;
// }
// }
//
// linkedList.addLast(newData);
// }
// private static void deleteEntry(LinkedList<String> linkedList, String target) {
// ListIterator<String> iterator = linkedList.listIterator();
//
// while (iterator.hasNext()) {
// String current = iterator.next();
//
// if (current.equals(target)) {
// // 获取target的前缀和序号
// int dashIndex = target.indexOf("-");
// if (dashIndex != -1) {
// String prefix = target.substring(0, dashIndex);
// int number = Integer.parseInt(target.substring(dashIndex + 1));
//
// while (iterator.hasNext()) {
// String next = iterator.next();
// if (next.startsWith(prefix + "-")) {
// // 更新数据序号
// int nextNumber = Integer.parseInt(next.substring(dashIndex + 1));
// String newEntry = prefix + "-" + (nextNumber - 1);
// iterator.remove();
// iterator.add(newEntry);
// } else {
// iterator.previous(); // 回退到上一个位置
// break;
// }
// }
// }
// }
// }
// }
//
// private static void printList(List<String> list) {
// for (String str : list) {
// System.out.print(str + " ");
// }
// System.out.println();
// }
}

Loading…
Cancel
Save