修改删除逻辑,增加限制

master
xiaoCJ 2 months ago
parent f11181f771
commit 06fb5e27e5

@ -93,10 +93,17 @@ public class CourseManageController {
@ApiOperation("删除课程")
@PostMapping("deleteOneCatalog")
public ResultEntity<String> deleteOneCatalog(@RequestParam String oneId) {
SysTwoCatalogExample sysTwoCatalogExample = new SysTwoCatalogExample();
sysTwoCatalogExample.createCriteria().andOneIdEqualTo(oneId);
List<SysTwoCatalog> sysTwoCatalogs = sysTwoCatalogMapper.selectByExample(sysTwoCatalogExample);
if (!sysTwoCatalogs.isEmpty()) {
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "请先删除二级目录!");
}
sysOneCatalogMapper.deleteByPrimaryKey(oneId);
//删除课程资源的绑定关系
SysResourceAndCourseExample example = new SysResourceAndCourseExample();
example.createCriteria().andOneIdEqualTo(oneId);
List<SysResourceAndCourse> sysResourceAndCourses = sysResourceAndCourseMapper.selectByExample(example);
sysResourceAndCourseMapper.deleteByExample(example);
//删除课程题目的绑定关系

@ -138,80 +138,101 @@ public class CourseTagManageController {
@RequestParam String id) {
try {
if (type == 2) {
sysTwoCatalogMapper.deleteByPrimaryKey(id);
//删除资源关系表
SysResourceAndCourseExample example1 = new SysResourceAndCourseExample();
example1.createCriteria().andTwoIdEqualTo(id);
List<SysResourceAndCourse> sysResourceAndCourses = sysResourceAndCourseMapper.selectByExample(example1);
List<String> resourceIds = sysResourceAndCourses.stream().map(SysResourceAndCourse::getResourceId).collect(Collectors.toList());
sysResourceAndCourseMapper.deleteByExample(example1);
//删除资源
if (!resourceIds.isEmpty()) {
SysResourceExample sysResourceExample = new SysResourceExample();
sysResourceExample.createCriteria().andResourceIdIn(resourceIds);
sysResourceMapper.deleteByExample(sysResourceExample);
//下面有三级目录就不让删除
SysThreeCatalogExample sysThreeCatalogExample =new SysThreeCatalogExample();
sysThreeCatalogExample.createCriteria().andTwoIdEqualTo(id);
List<SysThreeCatalog> sysThreeCatalogs = sysThreeCatalogMapper.selectByExample(sysThreeCatalogExample);
if (!sysThreeCatalogs.isEmpty()){
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "请先删除该目录下的三级目录!");
}
//删除题目关系表
SysTopicAndCourseExample example = new SysTopicAndCourseExample();
example.createCriteria().andTwoIdEqualTo(id);
List<SysTopicAndCourse> topicAndCourseList = sysTopicAndCourseMapper.selectByExample(example);
List<String> topicIds = topicAndCourseList.stream().map(SysTopicAndCourse::getTopicId).collect(Collectors.toList());
sysTopicAndCourseMapper.deleteByExample(example);
if (!topicAndCourseList.isEmpty()){
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "请先删除改目录下案例题的绑定关系!");
}
//删除案例题
if (!topicIds.isEmpty()) {
SysCaseQuestionExample sysCaseQuestionExample = new SysCaseQuestionExample();
sysCaseQuestionExample.createCriteria().andCaseIdIn(topicIds);
sysCaseQuestionMapper.deleteByExample(sysCaseQuestionExample);
//删除客观题
SysObjectiveQuestionsExample sysObjectiveQuestionsExample = new SysObjectiveQuestionsExample();
sysObjectiveQuestionsExample.createCriteria().andObjectiveIdIn(topicIds);
sysObjectiveQuestionsMapper.deleteByExample(sysObjectiveQuestionsExample);
//删除资源关系表
SysResourceAndCourseExample example1 = new SysResourceAndCourseExample();
example1.createCriteria().andTwoIdEqualTo(id);
List<SysResourceAndCourse> sysResourceAndCourses = sysResourceAndCourseMapper.selectByExample(example1);
if (!sysResourceAndCourses.isEmpty()){
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "请先删除改目录下资源的绑定关系!");
}
// //删除题目关系表
// sysTopicAndCourseMapper.deleteByExample(example);
// //删除资源绑定关系
// sysResourceAndCourseMapper.deleteByExample(example1);
//删除二级目录
sysTwoCatalogMapper.deleteByPrimaryKey(id);
//删除案例题
// List<String> topicIds = topicAndCourseList.stream().map(SysTopicAndCourse::getTopicId).collect(Collectors.toList());
// if (!topicIds.isEmpty()) {
// SysCaseQuestionExample sysCaseQuestionExample = new SysCaseQuestionExample();
// sysCaseQuestionExample.createCriteria().andCaseIdIn(topicIds);
// sysCaseQuestionMapper.deleteByExample(sysCaseQuestionExample);
//
// //删除客观题
// SysObjectiveQuestionsExample sysObjectiveQuestionsExample = new SysObjectiveQuestionsExample();
// sysObjectiveQuestionsExample.createCriteria().andObjectiveIdIn(topicIds);
// sysObjectiveQuestionsMapper.deleteByExample(sysObjectiveQuestionsExample);
// }
// List<String> resourceIds = sysResourceAndCourses.stream().map(SysResourceAndCourse::getResourceId).collect(Collectors.toList());
// if (!resourceIds.isEmpty()) {
// SysResourceExample sysResourceExample = new SysResourceExample();
// sysResourceExample.createCriteria().andResourceIdIn(resourceIds);
// sysResourceMapper.deleteByExample(sysResourceExample);
// }
} else {
sysThreeCatalogMapper.deleteByPrimaryKey(id);
SysTopicAndCourseExample sysTopicAndCourseExample = new SysTopicAndCourseExample();
sysTopicAndCourseExample.createCriteria().andThreeIdEqualTo(id);
List<SysTopicAndCourse> topicAndCourseList = sysTopicAndCourseMapper.selectByExample(sysTopicAndCourseExample);
if (!topicAndCourseList.isEmpty()){
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "请先删除改目录下案例题的绑定关系!");
}
//删除资源关系表
SysResourceAndCourseExample sysResourceAndCourseExample = new SysResourceAndCourseExample();
sysResourceAndCourseExample.createCriteria().andThreeIdEqualTo(id);
List<SysResourceAndCourse> sysResourceAndCourses = sysResourceAndCourseMapper.selectByExample(sysResourceAndCourseExample);
List<String> resourceIds = sysResourceAndCourses.stream().map(SysResourceAndCourse::getResourceId).collect(Collectors.toList());
sysResourceAndCourseMapper.deleteByExample(sysResourceAndCourseExample);
//删除资源
if (!resourceIds.isEmpty()) {
SysResourceExample sysResourceExample = new SysResourceExample();
sysResourceExample.createCriteria().andResourceIdIn(resourceIds);
sysResourceMapper.deleteByExample(sysResourceExample);
if (!sysResourceAndCourses.isEmpty()){
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "请先删除目录下资源的绑定关系!");
}
//删除题目关系表
SysTopicAndCourseExample sysTopicAndCourseExample = new SysTopicAndCourseExample();
sysTopicAndCourseExample.createCriteria().andThreeIdEqualTo(id);
List<SysTopicAndCourse> topicAndCourseList = sysTopicAndCourseMapper.selectByExample(sysTopicAndCourseExample);
List<String> topicIds = topicAndCourseList.stream().map(SysTopicAndCourse::getTopicId).collect(Collectors.toList());
sysThreeCatalogMapper.deleteByPrimaryKey(id);
// //删除题目绑定关系
// sysTopicAndCourseMapper.deleteByExample(sysTopicAndCourseExample);
// //删除资源绑定关系
// sysResourceAndCourseMapper.deleteByExample(sysResourceAndCourseExample);
sysTopicAndCourseMapper.deleteByExample(sysTopicAndCourseExample);
//删除资源
// List<String> resourceIds = sysResourceAndCourses.stream().map(SysResourceAndCourse::getResourceId).collect(Collectors.toList());
// if (!resourceIds.isEmpty()) {
// SysResourceExample sysResourceExample = new SysResourceExample();
// sysResourceExample.createCriteria().andResourceIdIn(resourceIds);
// sysResourceMapper.deleteByExample(sysResourceExample);
// }
//删除案例题
if (!topicIds.isEmpty()) {
SysCaseQuestionExample sysCaseQuestionExample = new SysCaseQuestionExample();
sysCaseQuestionExample.createCriteria().andCaseIdIn(topicIds);
sysCaseQuestionMapper.deleteByExample(sysCaseQuestionExample);
//删除客观题
SysObjectiveQuestionsExample sysObjectiveQuestionsExample = new SysObjectiveQuestionsExample();
sysObjectiveQuestionsExample.createCriteria().andObjectiveIdIn(topicIds);
sysObjectiveQuestionsMapper.deleteByExample(sysObjectiveQuestionsExample);
}
// List<String> topicIds = topicAndCourseList.stream().map(SysTopicAndCourse::getTopicId).collect(Collectors.toList());
// if (!topicIds.isEmpty()) {
// SysCaseQuestionExample sysCaseQuestionExample = new SysCaseQuestionExample();
// sysCaseQuestionExample.createCriteria().andCaseIdIn(topicIds);
// sysCaseQuestionMapper.deleteByExample(sysCaseQuestionExample);
//
// //删除客观题
// SysObjectiveQuestionsExample sysObjectiveQuestionsExample = new SysObjectiveQuestionsExample();
// sysObjectiveQuestionsExample.createCriteria().andObjectiveIdIn(topicIds);
// sysObjectiveQuestionsMapper.deleteByExample(sysObjectiveQuestionsExample);
// }
}
} catch (Exception e) {
e.printStackTrace();

Loading…
Cancel
Save