课程资源删除

master
wenyu441069198 5 months ago
parent c5b4c8829d
commit bf05b81a0b
  1. 4
      src/main/java/com/teaching/backend/controller/courseResource/CourseResourceController.java
  2. 35
      src/main/java/com/teaching/backend/service/impl/CourseResourcesServiceImpl.java
  3. 29
      src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java

@ -52,8 +52,8 @@ public class CourseResourceController {
@ApiOperation("根据ids删除")
@DeleteMapping("/delete")
public BaseResponse<String> deleteRecords(@RequestParam List<Long> ids){
// courseResourcesService.removeCourseResources(ids);
courseResourcesService.removeBatchByIds(ids);
courseResourcesService.removeCourseResources(ids);
// courseResourcesService.removeBatchByIds(ids);
return ResultUtils.success("删除成功!!");
}

@ -7,9 +7,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.mapper.records.LearningRecordsMapper;
import com.teaching.backend.mapper.resource.CourseResourcesMapper;
import com.teaching.backend.model.entity.CourseResources;
import com.teaching.backend.model.entity.ResourceRelationship;
import com.teaching.backend.model.entity.records.LearningRecords;
import com.teaching.backend.service.impl.records.LearningRecordsServiceImpl;
import com.teaching.backend.service.resource.CourseResourcesService;
import com.teaching.backend.service.resource.ResourcesRelationshipService;
import org.apache.commons.io.FileUtils;
@ -21,7 +24,9 @@ import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
/**
* ClassName: FileTableImpl
@ -39,6 +44,8 @@ public class CourseResourcesServiceImpl extends ServiceImpl<CourseResourcesMappe
@Autowired
private CourseResourcesMapper courseResourcesMapper;
@Autowired
private LearningRecordsMapper learningRecordsMapper;
@Override
public void updateFile(Integer type, String fileName, String filePath) {
@ -132,12 +139,20 @@ public class CourseResourcesServiceImpl extends ServiceImpl<CourseResourcesMappe
@Override
public void removeCourseResources(List<Long> ids) {
LambdaQueryWrapper<CourseResources> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.in(CourseResources::getId, ids);
List<CourseResources> list = this.list(lambdaQueryWrapper);
courseResourcesMapper.deleteBatchIds(list);
// System.out.println(this.updateBatchById(list));
// this.remove(lambdaQueryWrapper);
//删除资源在记录表里对应的记录
List<LearningRecords> list = new ArrayList<>();
for (Long id: ids) {
LambdaQueryWrapper<LearningRecords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//System.out.println("id:"+id);
lambdaQueryWrapper.eq(LearningRecords::getCoursesId, id).eq(LearningRecords::getType, 4);
//System.out.println("资源对应的记录:"+learningRecordsMapper.selectList(lambdaQueryWrapper));
list.addAll(learningRecordsMapper.selectList(lambdaQueryWrapper));
//System.out.println("添加完后的集合:"+list);
}
learningRecordsMapper.deleteBatchIds(list);
//System.out.println(list);
//删除课程资源
courseResourcesMapper.deleteBatchIds(ids);
}
@Override
@ -148,8 +163,8 @@ public class CourseResourcesServiceImpl extends ServiceImpl<CourseResourcesMappe
switch (courseResources.getType()){
case 1 : courseResources.setImg("src\\assets\\icons\\ppt (2).png");//ppt的默认图片
break;
// case 2 : courseResources.setImg(""); //图片
// break;
case 2 : courseResources.setImg(courseResources.getImg()); //图片
break;
case 3 : courseResources.setImg("src\\assets\\images\\video.png"); //视频
break;
case 4 : courseResources.setImg("src\\assets\\images\\PDF .png"); //pdf
@ -160,14 +175,14 @@ public class CourseResourcesServiceImpl extends ServiceImpl<CourseResourcesMappe
break;
default: courseResources.setImg(""); //暂无默认图片
}
this.save(courseResources);
}
@Override
public CourseResources editCourseResource(String resourceId) {
//根据id查数据
CourseResources courseResources = this.getById(resourceId);
return courseResources;
return this.getById(resourceId);
}

@ -91,23 +91,44 @@ public class LearningRecordsServiceImpl extends ServiceImpl<LearningRecordsMappe
// System.out.println(learningRecords.getResourceId());
// System.out.println("1");
String name;
//添加课程名称
switch (learningRecords.getType()) {
case "4": //如果是资源学习
// if (courseResourcesService.getById(learningRecords.getCoursesId()) != null){
// name=courseResourcesService.getById(learningRecords.getCoursesId()).getName();
// }else {
// name = "查无次记录";
// }
//如果对应的资源不存在
learningRecordsVo.setCoursesName(courseResourcesService.getById(learningRecords.getCoursesId()).getName());//设置名称 --------------------------------------------待完善
break;
case "3": //如果是知识点学习记录
// if (knowledgePointService.getById(learningRecords.getCoursesId()) != null){
// name=knowledgePointService.getById(learningRecords.getCoursesId()).getName();
// }else {
// name = "查无次记录";
// }
learningRecordsVo.setCoursesName(knowledgePointService.getById(learningRecords.getCoursesId()).getName());
//如果对应的资源不存在
break;
case "2": //如果是章节学习记录
// if (chapterService.getById(learningRecords.getCoursesId()) != null){
// name=chapterService.getById(learningRecords.getCoursesId()).getName();
// }else {
// name = "查无次记录";
// }
learningRecordsVo.setCoursesName(chapterService.getById(learningRecords.getCoursesId()).getName());
//如果对应的资源不存在
break;
case "1": //如果是课程学习记录
System.out.println();
// if (coursesService.getById(learningRecords.getCoursesId()) != null){
// name=coursesService.getById(learningRecords.getCoursesId()).getName();
// }else {
// name = "查无次记录";
// }
learningRecordsVo.setCoursesName(coursesService.getById(learningRecords.getCoursesId()).getName());
//如果对应的资源不存在
break;
}
//添加观看人数

Loading…
Cancel
Save