From 2435a7b7e170011da7ed0416e2e0293523ea9432 Mon Sep 17 00:00:00 2001 From: xiaoCJ <406612557@qq.com> Date: Tue, 23 Jul 2024 14:29:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CaseController.java | 72 +++++++++++------- .../controller/CaseStepController.java | 9 ++- .../controller/CourseConfigController.java | 3 +- .../controller/CourseManageController.java | 24 ++++-- .../controller/CourseTagManageController.java | 49 +++++++------ .../LearningResourceController.java | 8 +- .../controller/TopicResourceController.java | 73 +++++++++++++++++-- .../controller/api/CaseApi.java | 16 ++-- .../controller/api/ObjectiveApi.java | 65 +++++++++++++++-- .../controller/api/ResourceApi.java | 3 + .../api/SysKnowledgeSummaryApi.java | 4 +- .../entity/SysCaseQuestion.java | 3 + .../mapper/SysCaseQuestionMapper.java | 2 - .../mapper/SysCaseQuestionStepMapper.java | 2 + .../mapper/SysOneCatalogMapper.java | 3 + .../mapper/SysThreeCatalogMapper.java | 4 + .../mapper/SysTopicAndCourseMapper.java | 3 + .../mapper/SysTwoCatalogMapper.java | 3 + .../mapper/SysCaseQuestionMapper.xml | 16 +--- .../mapper/SysCaseQuestionStepMapper.xml | 9 ++- .../mapper/SysTopicAndCourseMapper.xml | 17 +++++ 21 files changed, 286 insertions(+), 102 deletions(-) diff --git a/src/main/java/com/sztzjy/resource_center/controller/CaseController.java b/src/main/java/com/sztzjy/resource_center/controller/CaseController.java index 555df45..437e070 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/CaseController.java +++ b/src/main/java/com/sztzjy/resource_center/controller/CaseController.java @@ -119,6 +119,24 @@ public class CaseController { @PostMapping("selectCaseByConditionsByID") public ResultEntity selectCaseByConditionsByID(@RequestParam String caseId) { SysCaseQuestion sysCaseQuestion = caseQuestionMapper.selectByPrimaryKey(caseId); + + SysTopicAndCourseExample example = new SysTopicAndCourseExample(); + example.createCriteria().andTopicIdEqualTo(caseId); + List topicAndCourseList = topicAndCourseMapper.selectByExample(example); + if (!topicAndCourseList.isEmpty()) { + SysTopicAndCourse sysTopicAndCourse = topicAndCourseList.get(0); + sysCaseQuestion.setOneId(sysTopicAndCourse.getOneId()); + sysCaseQuestion.setOneName(sysTopicAndCourse.getOneName()); + + if (StringUtils.isNotBlank(sysTopicAndCourse.getTwoId())) { + sysCaseQuestion.setTwoId(sysTopicAndCourse.getTwoId()); + sysCaseQuestion.setTwoName(sysTopicAndCourse.getTwoName()); + } + if (StringUtils.isNotBlank(sysCaseQuestion.getThreeId())) { + sysCaseQuestion.setThreeName(sysTopicAndCourse.getThreeName()); + sysCaseQuestion.setThreeId(sysTopicAndCourse.getThreeId()); + } + } return new ResultEntity(sysCaseQuestion); } @@ -130,25 +148,25 @@ public class CaseController { public ResultEntity updateCase(@RequestBody SysCaseQuestion sysCaseQuestion, @ApiParam("谁调的请求,传管理员/学校ID") @RequestParam String source) { List sysTopicAndCourses = getSysTopicAndCourses(sysCaseQuestion.getCaseId(), sysCaseQuestion.getOneId()); - if (!sysTopicAndCourses.isEmpty()) { - return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该案例题正在被使用!"); - } else { - //todo 管理员任意修改,老师只能改自己的 - if ("管理员".equals(source) || source.equals(sysCaseQuestion.getSource())) { - if (!sysTopicAndCourses.isEmpty()) { - SysTopicAndCourse sysTopicAndCourse = sysTopicAndCourses.get(0); - sysTopicAndCourse.setTwoId(sysCaseQuestion.getTwoId()); - sysTopicAndCourse.setThreeId(sysCaseQuestion.getThreeId()); - sysTopicAndCourse.setTwoName(sysCaseQuestion.getTwoName()); - sysTopicAndCourse.setThreeName(sysCaseQuestion.getThreeName()); - topicAndCourseMapper.updateByPrimaryKeySelective(sysTopicAndCourse); - } - caseQuestionMapper.updateByPrimaryKeySelective(sysCaseQuestion); - return new ResultEntity<>(HttpStatus.OK, "编辑成功!"); - } else { - return new ResultEntity<>(HttpStatus.BAD_REQUEST, "权限不足!"); +// if (!sysTopicAndCourses.isEmpty()) { +// return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该案例题正在被使用!"); +// } else { + //todo 管理员任意修改,老师只能改自己的 + if ("管理员".equals(source) || source.equals(sysCaseQuestion.getSource())) { + if (!sysTopicAndCourses.isEmpty()) { + SysTopicAndCourse sysTopicAndCourse = sysTopicAndCourses.get(0); + sysTopicAndCourse.setTwoId(sysCaseQuestion.getTwoId()); + sysTopicAndCourse.setThreeId(sysCaseQuestion.getThreeId()); + sysTopicAndCourse.setTwoName(sysCaseQuestion.getTwoName()); + sysTopicAndCourse.setThreeName(sysCaseQuestion.getThreeName()); + topicAndCourseMapper.updateByPrimaryKeySelective(sysTopicAndCourse); } + caseQuestionMapper.updateByPrimaryKeySelective(sysCaseQuestion); + return new ResultEntity<>(HttpStatus.OK, "编辑成功!"); + } else { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "权限不足!"); } +// } } @@ -159,18 +177,18 @@ public class CaseController { public ResultEntity deleteCase(@RequestBody SysCaseQuestion sysCaseQuestion, @ApiParam("哪个用的掉的请求,传管理员/学校ID") @RequestParam String source) { List sysTopicAndCourses = getSysTopicAndCourses(sysCaseQuestion.getCaseId(), sysCaseQuestion.getOneId()); - if (!sysTopicAndCourses.isEmpty()) { - return new ResultEntity<>(HttpStatus.BAD_REQUEST, "无法删除!该案例题正在被使用!"); +// if (!sysTopicAndCourses.isEmpty()) { +// return new ResultEntity<>(HttpStatus.BAD_REQUEST, "无法删除!该案例题正在被使用!"); +// } else { + //todo 管理员任意删除 老师只能删除自己上传的 + if ("管理员".equals(source) || source.equals(sysCaseQuestion.getSource())) { + topicAndCourseMapper.deleteByPrimaryKey(sysTopicAndCourses.get(0).getId()); + caseQuestionMapper.deleteByPrimaryKey(sysCaseQuestion.getCaseId()); + return new ResultEntity<>(HttpStatus.OK, "删除成功!"); } else { - //todo 管理员任意删除 老师只能删除自己上传的 - if ("管理员".equals(source) || source.equals(sysCaseQuestion.getSource())) { - topicAndCourseMapper.deleteByPrimaryKey(sysTopicAndCourses.get(0).getId()); - caseQuestionMapper.deleteByPrimaryKey(sysCaseQuestion.getCaseId()); - return new ResultEntity<>(HttpStatus.OK, "删除成功!"); - } else { - return new ResultEntity<>(HttpStatus.BAD_REQUEST, "权限不足!"); - } + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "权限不足!"); } +// } } private List getSysTopicAndCourses(String caseId, String oneId) { diff --git a/src/main/java/com/sztzjy/resource_center/controller/CaseStepController.java b/src/main/java/com/sztzjy/resource_center/controller/CaseStepController.java index 2636809..f078878 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/CaseStepController.java +++ b/src/main/java/com/sztzjy/resource_center/controller/CaseStepController.java @@ -56,9 +56,10 @@ public class CaseStepController { public ResultEntity updateCase(@RequestBody SysCaseQuestionStepWithBLOBs caseQuestionStepWithBLOBs, @ApiParam("谁调的请求,传管理员/学校ID") @RequestParam String source) { List sysTopicAndCourses = getSysTopicAndCourses(caseQuestionStepWithBLOBs.getCaseId()); - if (!sysTopicAndCourses.isEmpty()) { - return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该案例题正在被使用!"); - } else { +// if (!sysTopicAndCourses.isEmpty()) { +// return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该案例题正在被使用!"); +// } +// else { //todo 管理员任意修改,老师只能改自己的 SysCaseQuestion sysCaseQuestion = sysCaseQuestionMapper.selectByPrimaryKey(caseQuestionStepWithBLOBs.getCaseId()); if ("管理员".equals(source) || source.equals(sysCaseQuestion.getSource())) { @@ -67,7 +68,7 @@ public class CaseStepController { } else { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "权限不足!"); } - } +// } } diff --git a/src/main/java/com/sztzjy/resource_center/controller/CourseConfigController.java b/src/main/java/com/sztzjy/resource_center/controller/CourseConfigController.java index e787d70..974f601 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/CourseConfigController.java +++ b/src/main/java/com/sztzjy/resource_center/controller/CourseConfigController.java @@ -67,8 +67,7 @@ public class CourseConfigController { //判断文件type //todo 格式可能不够全 if (extension.equals(".pdf") || extension.equals(".ppt") || extension.equals(".pptx") || extension.equals(".xlsx") || extension.equals(".xls") - || extension.equals(".doc") || extension.equals(".docx") - || extension.equals(".txt")) { + || extension.equals(".doc") || extension.equals(".docx")){ sysResource.setResourceType("课件"); } else if (extension.equals(".mp4") || extension.equals(".wmv") || extension.equals(".avi")) { sysResource.setResourceType("视频"); diff --git a/src/main/java/com/sztzjy/resource_center/controller/CourseManageController.java b/src/main/java/com/sztzjy/resource_center/controller/CourseManageController.java index 18a3aa3..25291b7 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/CourseManageController.java +++ b/src/main/java/com/sztzjy/resource_center/controller/CourseManageController.java @@ -6,10 +6,7 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.sztzjy.resource_center.annotation.AnonymousAccess; import com.sztzjy.resource_center.entity.*; -import com.sztzjy.resource_center.mapper.SysOneCatalogMapper; -import com.sztzjy.resource_center.mapper.SysResourceAndCourseMapper; -import com.sztzjy.resource_center.mapper.SysThreeCatalogMapper; -import com.sztzjy.resource_center.mapper.SysTwoCatalogMapper; +import com.sztzjy.resource_center.mapper.*; import com.sztzjy.resource_center.util.ResultEntity; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -39,6 +36,9 @@ public class CourseManageController { private SysThreeCatalogMapper sysThreeCatalogMapper; @Autowired private SysResourceAndCourseMapper sysResourceAndCourseMapper; + @Autowired + private SysTopicAndCourseMapper sysTopicAndCourseMapper; + @AnonymousAccess @ApiOperation("新增课程") @@ -67,9 +67,14 @@ public class CourseManageController { @AnonymousAccess @ApiOperation("编辑课程/启用停用") @PostMapping("updateSysOneCatalog") - public ResultEntity updateSysOneCatalog(@ApiParam("课程链接必填,课程简介选填") @RequestBody SysOneCatalog sysOneCatalog) { - sysOneCatalogMapper.updateByPrimaryKey(sysOneCatalog); - return new ResultEntity<>(HttpStatus.OK, "编辑成功"); + public ResultEntity updateSysOneCatalog(@ApiParam("课程链接必填,课程简介选填,停用传0") @RequestBody SysOneCatalog sysOneCatalog) { + try { + sysOneCatalogMapper.updateByPrimaryKey(sysOneCatalog); + return new ResultEntity<>(HttpStatus.OK, "编辑成功"); + } catch (Exception e) { + e.printStackTrace(); + return new ResultEntity<>(HttpStatus.INTERNAL_SERVER_ERROR, "编辑失败,请联系管理员"); + } } @@ -93,6 +98,11 @@ public class CourseManageController { SysResourceAndCourseExample example = new SysResourceAndCourseExample(); example.createCriteria().andOneIdEqualTo(oneId); sysResourceAndCourseMapper.deleteByExample(example); + + //删除课程题目的绑定关系 + SysTopicAndCourseExample example1 = new SysTopicAndCourseExample(); + example1.createCriteria().andOneIdEqualTo(oneId); + sysTopicAndCourseMapper.deleteByExample(example1); return new ResultEntity<>(HttpStatus.OK, "删除成功"); } diff --git a/src/main/java/com/sztzjy/resource_center/controller/CourseTagManageController.java b/src/main/java/com/sztzjy/resource_center/controller/CourseTagManageController.java index 71839d3..49fb103 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/CourseTagManageController.java +++ b/src/main/java/com/sztzjy/resource_center/controller/CourseTagManageController.java @@ -130,27 +130,34 @@ public class CourseTagManageController { @PostMapping("deleteTwoAndThreeCatalog") public ResultEntity deleteTwoAndThreeCatalog(@ApiParam("二级目录传2/三级传3") @RequestParam int type, @RequestParam String id) { - if (type == 2) { - //删除资源 - SysResourceAndCourseExample example1 = new SysResourceAndCourseExample(); - example1.createCriteria().andTwoIdEqualTo(id); - sysResourceAndCourseMapper.deleteByExample(example1); - - //删除题目 - SysTopicAndCourseExample example = new SysTopicAndCourseExample(); - example.createCriteria().andTwoIdEqualTo(id); - sysTopicAndCourseMapper.deleteByExample(example); - } else { - //删除资源 - SysResourceAndCourseExample example1 = new SysResourceAndCourseExample(); - example1.createCriteria().andThreeIdEqualTo(id); - sysResourceAndCourseMapper.deleteByExample(example1); - - //删除题目 - SysTopicAndCourseExample example = new SysTopicAndCourseExample(); - example.createCriteria().andThreeIdEqualTo(id); - sysTopicAndCourseMapper.deleteByExample(example); - sysThreeCatalogMapper.deleteByPrimaryKey(id); + try { + if (type == 2) { + sysTwoCatalogMapper.deleteByPrimaryKey(id); + //删除资源 + SysResourceAndCourseExample example1 = new SysResourceAndCourseExample(); + example1.createCriteria().andTwoIdEqualTo(id); + sysResourceAndCourseMapper.deleteByExample(example1); + + //删除题目 + SysTopicAndCourseExample example = new SysTopicAndCourseExample(); + example.createCriteria().andTwoIdEqualTo(id); + sysTopicAndCourseMapper.deleteByExample(example); + } else { + sysThreeCatalogMapper.deleteByPrimaryKey(id); + //删除资源 + SysResourceAndCourseExample example1 = new SysResourceAndCourseExample(); + example1.createCriteria().andThreeIdEqualTo(id); + sysResourceAndCourseMapper.deleteByExample(example1); + + //删除题目 + SysTopicAndCourseExample example = new SysTopicAndCourseExample(); + example.createCriteria().andThreeIdEqualTo(id); + sysTopicAndCourseMapper.deleteByExample(example); + sysThreeCatalogMapper.deleteByPrimaryKey(id); + } + } catch (Exception e) { + e.printStackTrace(); + return new ResultEntity<>(HttpStatus.INTERNAL_SERVER_ERROR,"删除失败,请联系管理员"); } return new ResultEntity<>(HttpStatus.OK, "删除成功"); } diff --git a/src/main/java/com/sztzjy/resource_center/controller/LearningResourceController.java b/src/main/java/com/sztzjy/resource_center/controller/LearningResourceController.java index e125965..a40d6e3 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/LearningResourceController.java +++ b/src/main/java/com/sztzjy/resource_center/controller/LearningResourceController.java @@ -4,7 +4,9 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.sztzjy.resource_center.annotation.AnonymousAccess; import com.sztzjy.resource_center.entity.SysResource; +import com.sztzjy.resource_center.entity.SysResourceAndCourseExample; import com.sztzjy.resource_center.entity.dto.SysResourceDto; +import com.sztzjy.resource_center.mapper.SysResourceAndCourseMapper; import com.sztzjy.resource_center.mapper.SysResourceMapper; import com.sztzjy.resource_center.util.ResultEntity; import com.sztzjy.resource_center.util.file.IFileUtil; @@ -38,7 +40,8 @@ public class LearningResourceController { private String filePath; @Autowired private IFileUtil fileUtil; - + @Autowired + private SysResourceAndCourseMapper sysResourceAndCourseMapper; @AnonymousAccess @ApiOperation("学习资源/资源列表展示/有重复数据") @@ -61,6 +64,9 @@ public class LearningResourceController { @PostMapping("deleteResource") public ResultEntity deleteResource(@ApiParam("来源是学校的不允许传过来") @RequestParam String id) { sysResourceMapper.deleteByPrimaryKey(id); + SysResourceAndCourseExample example = new SysResourceAndCourseExample(); + example.createCriteria().andResourceIdEqualTo(id); + sysResourceAndCourseMapper.deleteByExample(example); return new ResultEntity<>(HttpStatus.OK, "删除成功!"); } diff --git a/src/main/java/com/sztzjy/resource_center/controller/TopicResourceController.java b/src/main/java/com/sztzjy/resource_center/controller/TopicResourceController.java index e8fe7a6..3337522 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/TopicResourceController.java +++ b/src/main/java/com/sztzjy/resource_center/controller/TopicResourceController.java @@ -9,8 +9,7 @@ import com.sztzjy.resource_center.entity.SysObjectiveQuestionsExample; import com.sztzjy.resource_center.entity.SysTopicAndCourse; import com.sztzjy.resource_center.entity.SysTopicAndCourseExample; import com.sztzjy.resource_center.entity.dto.SysObjectiveQuestionsDto; -import com.sztzjy.resource_center.mapper.SysObjectiveQuestionsMapper; -import com.sztzjy.resource_center.mapper.SysTopicAndCourseMapper; +import com.sztzjy.resource_center.mapper.*; import com.sztzjy.resource_center.util.ResultEntity; import com.sztzjy.resource_center.util.file.IFileUtil; import io.swagger.annotations.Api; @@ -39,7 +38,8 @@ import java.util.*; @RestController @RequestMapping("api/sys/topic/resource") public class TopicResourceController { - + @Autowired + SysOneCatalogMapper oneCatalogMapper; @Autowired private SysObjectiveQuestionsMapper sysObjectiveQuestionMapper; @Autowired @@ -48,7 +48,10 @@ public class TopicResourceController { IFileUtil fileUtil; @Value("${file.path}") private String filePath; - + @Autowired + private SysTwoCatalogMapper sysTwoCatalogMapper; + @Autowired + private SysThreeCatalogMapper sysThreeCatalogMapper; @AnonymousAccess @ApiOperation("新增单个试题") //新增 题干不允许重复 @@ -292,9 +295,17 @@ public class TopicResourceController { //如果是老师增加 则只需要提供课程信息 public ResultEntity insertObjectiveByExcel(MultipartFile file, String source) throws IOException, InvalidFormatException { List objectiveQuestionList = new ArrayList<>(); + List topicAndCourseList = new ArrayList<>(); + Workbook workbook = WorkbookFactory.create(file.getInputStream()); Sheet sheet = workbook.getSheetAt(0); + + //创建三级的ID和名称Map + Map oneIdMap = new HashMap<>(); + Map twoIdMap = new HashMap<>(); + Map threeIdMap = new HashMap<>(); + // 迭代每一行 Iterator iterator = sheet.iterator(); iterator.next(); @@ -312,6 +323,10 @@ public class TopicResourceController { Cell cell7 = row.getCell(7); Cell cell8 = row.getCell(8); Cell cell9 = row.getCell(9); + Cell cell10 = row.getCell(10); + Cell cell11 = row.getCell(11); + Cell cell12 = row.getCell(12); + //判断题的BCDE选项和解析可能为空 if (cell0 == null || cell1 == null || cell2 == null || cell6 == null || cell7 == null || cell9 == null) { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "必填项不能为空"); @@ -323,6 +338,9 @@ public class TopicResourceController { String type = this.getCellValue(cell6);//题型 String answer = this.getCellValue(cell7);//答案 String score = this.getCellValue(cell9);//分值 + String oneName = this.getCellValue(cell10);//一级目录名称 + String twoName = this.getCellValue(cell11);//二级目录名称 + String threeName = this.getCellValue(cell12);//三级目录名称 String c = cell3 != null ? this.getCellValue(cell3) : null; String d = cell4 != null ? this.getCellValue(cell4) : null; String e = cell5 != null ? this.getCellValue(cell5) : null; @@ -330,7 +348,8 @@ public class TopicResourceController { SysObjectiveQuestions obj = new SysObjectiveQuestions(); - obj.setObjectiveId(String.valueOf(UUID.randomUUID())); + String topicId = IdUtil.randomUUID(); + obj.setObjectiveId(topicId); obj.setContent(content); obj.setType(type); obj.setSource(source); @@ -345,7 +364,51 @@ public class TopicResourceController { obj.setCreateTime(new Date()); obj.setIsDelete(false); objectiveQuestionList.add(obj); + + + //判断名称是否被查出来过 + String oneId = oneIdMap.get(oneName); + if (oneId == null) { + oneId = oneCatalogMapper.getIdByName(oneName); + if (oneId == null) { + return new ResultEntity(HttpStatus.INTERNAL_SERVER_ERROR, "导入关联的系统不存在,请在添加后重新导入"); + } + oneIdMap.put(oneName, oneId); + } + + String twoId = twoIdMap.get(twoName); + if (twoId == null) { + twoId = sysTwoCatalogMapper.getIdByName(twoName); + if (twoId == null) { + return new ResultEntity(HttpStatus.INTERNAL_SERVER_ERROR, "导入关联的课程不存在,请在添加后重新导入"); + } + twoIdMap.put(twoName, twoId); + } + + String threeId = threeIdMap.get(threeName); + if (threeId == null) { + threeId = sysThreeCatalogMapper.getIdByName(twoName, threeName); + if (threeId==null){ + return new ResultEntity(HttpStatus.INTERNAL_SERVER_ERROR,"导入关联的章节不存在,请在添加后重新导入"); + } + threeIdMap.put(threeName, threeId); + } + + + SysTopicAndCourse sysTopicAndCourse = new SysTopicAndCourse(); + sysTopicAndCourse.setId(IdUtil.randomUUID()); + sysTopicAndCourse.setTopicId(topicId); + sysTopicAndCourse.setTopicType("0"); + sysTopicAndCourse.setOneName(oneName); + sysTopicAndCourse.setOneId(oneId); + sysTopicAndCourse.setTwoName(twoName); + sysTopicAndCourse.setTwoId(twoId); + sysTopicAndCourse.setThreeId(threeId); + sysTopicAndCourse.setThreeName(threeName); + topicAndCourseList.add(sysTopicAndCourse); } + + sysTopicAndCourseMapper.batchInsert(topicAndCourseList); int result = sysObjectiveQuestionMapper.insertBatch(objectiveQuestionList); if (result > 0) { return new ResultEntity<>(HttpStatus.OK, "批量导入成功!"); diff --git a/src/main/java/com/sztzjy/resource_center/controller/api/CaseApi.java b/src/main/java/com/sztzjy/resource_center/controller/api/CaseApi.java index 7bc3250..43571b3 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/api/CaseApi.java +++ b/src/main/java/com/sztzjy/resource_center/controller/api/CaseApi.java @@ -40,6 +40,8 @@ public class CaseApi { @PostMapping("insertCase") public Boolean insertCase(@ApiParam("目前二级三级ID可以为空,来源和题型要传,上架状态传true") @RequestBody SysCaseQuestion sysCaseQuestion) { SysOneCatalog sysOneCatalogs1 = getSysOneCatalogs(sysCaseQuestion.getOneName()); + String oneId = sysOneCatalogs1.getOneId(); + if (("3").equals(sysCaseQuestion.getType())) { return false; } @@ -54,7 +56,7 @@ public class CaseApi { } String title = sysCaseQuestion.getTitle(); SysCaseQuestionExample example = new SysCaseQuestionExample(); - example.createCriteria().andTitleEqualTo(title).andUnmountStatusEqualTo(false).andOneIdEqualTo(sysOneCatalogs1.getOneId()); + example.createCriteria().andTitleEqualTo(title).andUnmountStatusEqualTo(false).andOneIdEqualTo(oneId); List sysCaseQuestions = caseQuestionMapper.selectByExample(example); if (!sysCaseQuestions.isEmpty()) { return false; @@ -70,9 +72,8 @@ public class CaseApi { sysTopicAndCourse.setId(IdUtil.randomUUID()); sysTopicAndCourse.setTopicType("1"); sysTopicAndCourse.setTopicId(uuid); - String oneId = sysOneCatalogs1.getOneId(); sysTopicAndCourse.setOneId(oneId); - sysTopicAndCourse.setOneName(sysCaseQuestion.getOneName()); + sysTopicAndCourse.setOneName(sysOneCatalogs1.getOneName()); if (StringUtils.isNotBlank(sysCaseQuestion.getTwoId())) { sysTopicAndCourse.setTwoId(sysCaseQuestion.getTwoId()); sysTopicAndCourse.setTwoName(sysCaseQuestion.getTwoName()); @@ -389,11 +390,8 @@ public class CaseApi { @PostMapping("selectAllStepBySystemOwner") public List selectAllStepBySystemOwner(@RequestParam String systemOwner) { SysOneCatalog sysOneCatalogs = getSysOneCatalogs(systemOwner); - List ids = topicAndCourseMapper.getCaseIdsBySourceIsAdmin(sysOneCatalogs.getOneId()); - SysCaseQuestionStepExample example1 = new SysCaseQuestionStepExample(); - example1.createCriteria().andCaseIdIn(ids); - return caseQuestionStepMapper.selectByExampleWithBLOBs(example1); + return caseQuestionStepMapper.getCaseStepByIds(ids); } @@ -412,9 +410,9 @@ public class CaseApi { chapterIdList.add(chapter.getThreeId()); } - List> results = caseQuestionMapper.selectCaseIdByCourseAndChapterIds(courseIdList, chapterIdList); + List> results = topicAndCourseMapper.selectCaseIdByCourseAndChapterIds(courseIdList, chapterIdList); for (Map result : results) { - String chapterId = (String) result.get("chapter_id"); + String chapterId = (String) result.get("three_id"); String caseId = (String) result.get("case_id"); if (!caseIdMap.containsKey(chapterId)) { caseIdMap.put(chapterId, new ArrayList<>()); diff --git a/src/main/java/com/sztzjy/resource_center/controller/api/ObjectiveApi.java b/src/main/java/com/sztzjy/resource_center/controller/api/ObjectiveApi.java index de89976..ec9bf56 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/api/ObjectiveApi.java +++ b/src/main/java/com/sztzjy/resource_center/controller/api/ObjectiveApi.java @@ -5,9 +5,7 @@ import com.github.pagehelper.PageInfo; import com.sztzjy.resource_center.annotation.AnonymousAccess; import com.sztzjy.resource_center.entity.*; import com.sztzjy.resource_center.entity.dto.SysObjectiveQuestionsDto; -import com.sztzjy.resource_center.mapper.SysObjectiveQuestionsMapper; -import com.sztzjy.resource_center.mapper.SysOneCatalogMapper; -import com.sztzjy.resource_center.mapper.SysTopicAndCourseMapper; +import com.sztzjy.resource_center.mapper.*; import com.sztzjy.resource_center.util.PageUtil; import com.sztzjy.resource_center.util.file.IFileUtil; import io.swagger.annotations.Api; @@ -19,6 +17,7 @@ import org.apache.poi.ss.usermodel.*; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -42,7 +41,10 @@ public class ObjectiveApi { IFileUtil fileUtil; @Value("${file.path}") private String filePath; - + @Autowired + private SysTwoCatalogMapper sysTwoCatalogMapper; + @Autowired + private SysThreeCatalogMapper sysThreeCatalogMapper; private SysOneCatalog getSysOneCatalogs(String systemOwner) { SysOneCatalogExample example = new SysOneCatalogExample(); @@ -252,8 +254,9 @@ public class ObjectiveApi { @AnonymousAccess @ApiOperation("本地excel导入试题") @PostMapping("insertObjectiveByExcel") - private Boolean importTopicByLocal(@RequestParam MultipartFile file, - @RequestParam String schoolId) throws IOException, InvalidFormatException { + @Transactional + Boolean importTopicByLocal(@RequestParam MultipartFile file, + @RequestParam String schoolId) throws IOException, InvalidFormatException { if (file == null) { return false; } @@ -264,9 +267,17 @@ public class ObjectiveApi { //如果是老师增加 则只需要提供课程信息 public Boolean insertObjectiveByExcel(MultipartFile file, String schoolId) throws IOException, InvalidFormatException { List objectiveQuestionList = new ArrayList<>(); + List topicAndCourseList = new ArrayList<>(); + + Workbook workbook = WorkbookFactory.create(file.getInputStream()); Sheet sheet = workbook.getSheetAt(0); + //创建三级的ID和名称Map + Map oneIdMap = new HashMap<>(); + Map twoIdMap = new HashMap<>(); + Map threeIdMap = new HashMap<>(); + // 迭代每一行 Iterator iterator = sheet.iterator(); iterator.next(); @@ -284,6 +295,9 @@ public class ObjectiveApi { Cell cell7 = row.getCell(7); Cell cell8 = row.getCell(8); Cell cell9 = row.getCell(9); + Cell cell10 = row.getCell(10); + Cell cell11 = row.getCell(11); + Cell cell12 = row.getCell(12); //判断题的BCDE选项和解析可能为空 if (cell0 == null || cell1 == null || cell2 == null || cell6 == null || cell7 == null || cell9 == null) { return false; @@ -295,6 +309,9 @@ public class ObjectiveApi { String type = this.getCellValue(cell6);//题型 String answer = this.getCellValue(cell7);//答案 String score = this.getCellValue(cell9);//分值 + String oneName = this.getCellValue(cell10);//一级目录名称 + String twoName = this.getCellValue(cell11);//二级目录名称 + String threeName = this.getCellValue(cell12);//三级目录名称 String c = cell3 != null ? this.getCellValue(cell3) : null; String d = cell4 != null ? this.getCellValue(cell4) : null; String e = cell5 != null ? this.getCellValue(cell5) : null; @@ -302,7 +319,8 @@ public class ObjectiveApi { SysObjectiveQuestions obj = new SysObjectiveQuestions(); - obj.setObjectiveId(String.valueOf(UUID.randomUUID())); + String topicId = IdUtil.randomUUID(); + obj.setObjectiveId(topicId); obj.setContent(content); obj.setType(type); obj.setSource(schoolId); @@ -317,7 +335,40 @@ public class ObjectiveApi { obj.setCreateTime(new Date()); obj.setIsDelete(false); objectiveQuestionList.add(obj); + + //判断名称是否被查出来过 + String oneId = oneIdMap.get(oneName); + if (oneId == null) { + oneId = oneCatalogMapper.getIdByName(oneName); + oneIdMap.put(oneName, oneId); + } + + String twoId = twoIdMap.get(twoName); + if (twoId == null) { + twoId = sysTwoCatalogMapper.getIdByName(twoName); + twoIdMap.put(twoName, twoId); + } + + String threeId = threeIdMap.get(threeName); + if (threeId == null) { + threeId = sysThreeCatalogMapper.getIdByName(threeName,twoName); + threeIdMap.put(threeName, threeId); + } + + + SysTopicAndCourse sysTopicAndCourse = new SysTopicAndCourse(); + sysTopicAndCourse.setId(IdUtil.randomUUID()); + sysTopicAndCourse.setTopicId(topicId); + sysTopicAndCourse.setTopicType("0"); + sysTopicAndCourse.setOneName(oneName); + sysTopicAndCourse.setOneId(oneId); + sysTopicAndCourse.setTwoName(twoName); + sysTopicAndCourse.setTwoId(twoId); + sysTopicAndCourse.setThreeId(threeId); + sysTopicAndCourse.setThreeName(threeName); + topicAndCourseList.add(sysTopicAndCourse); } + sysTopicAndCourseMapper.batchInsert(topicAndCourseList); int result = sysObjectiveQuestionMapper.insertBatch(objectiveQuestionList); if (result > 0) { return true; diff --git a/src/main/java/com/sztzjy/resource_center/controller/api/ResourceApi.java b/src/main/java/com/sztzjy/resource_center/controller/api/ResourceApi.java index ab8fccb..496f118 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/api/ResourceApi.java +++ b/src/main/java/com/sztzjy/resource_center/controller/api/ResourceApi.java @@ -288,6 +288,9 @@ public class ResourceApi { if (!sysResource.getSource().equals(source)) { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "删除失败!"); } + SysResourceAndCourseExample example = new SysResourceAndCourseExample(); + example.createCriteria().andResourceIdEqualTo(id); + sysResourceAndCourseMapper.deleteByExample(example); sysResourceMapper.deleteByPrimaryKey(id); return new ResultEntity<>(HttpStatus.OK, "删除成功!"); } diff --git a/src/main/java/com/sztzjy/resource_center/controller/api/SysKnowledgeSummaryApi.java b/src/main/java/com/sztzjy/resource_center/controller/api/SysKnowledgeSummaryApi.java index ecd0138..4c63633 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/api/SysKnowledgeSummaryApi.java +++ b/src/main/java/com/sztzjy/resource_center/controller/api/SysKnowledgeSummaryApi.java @@ -39,8 +39,8 @@ public class SysKnowledgeSummaryApi { @AnonymousAccess - @ApiOperation("getSysKnowledgeSummary") - @PostMapping("uploadResourceData") + @ApiOperation("获取知识概要") + @PostMapping("getSysKnowledgeSummary") private SysKnowledgeSummary getSysKnowledgeSummary(@RequestParam String schoolId, @RequestParam String systemOwner, @RequestParam String courseId, diff --git a/src/main/java/com/sztzjy/resource_center/entity/SysCaseQuestion.java b/src/main/java/com/sztzjy/resource_center/entity/SysCaseQuestion.java index 159de42..e42a872 100644 --- a/src/main/java/com/sztzjy/resource_center/entity/SysCaseQuestion.java +++ b/src/main/java/com/sztzjy/resource_center/entity/SysCaseQuestion.java @@ -28,16 +28,19 @@ public class SysCaseQuestion { @ApiModelProperty("一级目录ID") private String oneId; + @ApiModelProperty("一级名称") private String oneName; @ApiModelProperty("二级目录ID") private String twoId; + @ApiModelProperty("二级名称") private String twoName; @ApiModelProperty("三级目录ID") private String threeId; + @ApiModelProperty("三级名称") private String threeName; @ApiModelProperty("上下架状态") diff --git a/src/main/java/com/sztzjy/resource_center/mapper/SysCaseQuestionMapper.java b/src/main/java/com/sztzjy/resource_center/mapper/SysCaseQuestionMapper.java index 73ee095..e6c6046 100644 --- a/src/main/java/com/sztzjy/resource_center/mapper/SysCaseQuestionMapper.java +++ b/src/main/java/com/sztzjy/resource_center/mapper/SysCaseQuestionMapper.java @@ -43,6 +43,4 @@ public interface SysCaseQuestionMapper { @Param("source") String source); List selectCaseByConditionsByBind(@Param("title") String title); - - List> selectCaseIdByCourseAndChapterIds(@Param("courseIdList") List courseIdList, @Param("chapterIdList") List chapterIdList); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/resource_center/mapper/SysCaseQuestionStepMapper.java b/src/main/java/com/sztzjy/resource_center/mapper/SysCaseQuestionStepMapper.java index a119cef..007d1ec 100644 --- a/src/main/java/com/sztzjy/resource_center/mapper/SysCaseQuestionStepMapper.java +++ b/src/main/java/com/sztzjy/resource_center/mapper/SysCaseQuestionStepMapper.java @@ -43,4 +43,6 @@ public interface SysCaseQuestionStepMapper { @Param("oneId") String oneId); List selectTrainingByIds(@Param("list") List caseStepIdList); + + List getCaseStepByIds(@Param("ids") List ids); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/resource_center/mapper/SysOneCatalogMapper.java b/src/main/java/com/sztzjy/resource_center/mapper/SysOneCatalogMapper.java index 7414739..58c3a86 100644 --- a/src/main/java/com/sztzjy/resource_center/mapper/SysOneCatalogMapper.java +++ b/src/main/java/com/sztzjy/resource_center/mapper/SysOneCatalogMapper.java @@ -37,4 +37,7 @@ public interface SysOneCatalogMapper { List> getAllOneCatalogListByDropDown(); void updateByBatch(@Param("sysOneCatalogs") List sysOneCatalogs); + + @Select("select one_id from sys_one_catalog where one_name =#{name}") + String getIdByName(@Param("name") String oneName); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/resource_center/mapper/SysThreeCatalogMapper.java b/src/main/java/com/sztzjy/resource_center/mapper/SysThreeCatalogMapper.java index 3f1358e..b1e358b 100644 --- a/src/main/java/com/sztzjy/resource_center/mapper/SysThreeCatalogMapper.java +++ b/src/main/java/com/sztzjy/resource_center/mapper/SysThreeCatalogMapper.java @@ -48,4 +48,8 @@ public interface SysThreeCatalogMapper { "where s.creator in ('管理员',#{source})") List selectNameByCourseID(@Param("oneId") String oneId, @Param("source") String source); + + @Select("select three_id from sys_three_catalog where three_name =#{threeName} and two_name ={twoName}") + String getIdByName(@Param("threeName") String threeName, + @Param("twoName") String twoName); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/resource_center/mapper/SysTopicAndCourseMapper.java b/src/main/java/com/sztzjy/resource_center/mapper/SysTopicAndCourseMapper.java index 42dcc60..93dbc6d 100644 --- a/src/main/java/com/sztzjy/resource_center/mapper/SysTopicAndCourseMapper.java +++ b/src/main/java/com/sztzjy/resource_center/mapper/SysTopicAndCourseMapper.java @@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.List; +import java.util.Map; @Mapper public interface SysTopicAndCourseMapper { @@ -44,4 +45,6 @@ public interface SysTopicAndCourseMapper { @Select("select sq.case_id from sys_topic_and_course sc LEFT JOIN sys_case_questions sq on sc.topic_id = sq.case_id where sq.source = '管理员' and sc.one_id = #{oneId}") List getCaseIdsBySourceIsAdmin(@Param("oneId") String oneId); + + List> selectCaseIdByCourseAndChapterIds(@Param("courseIdList") List courseIdList, @Param("chapterIdList") List chapterIdList); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/resource_center/mapper/SysTwoCatalogMapper.java b/src/main/java/com/sztzjy/resource_center/mapper/SysTwoCatalogMapper.java index 1972e9f..c69fbd4 100644 --- a/src/main/java/com/sztzjy/resource_center/mapper/SysTwoCatalogMapper.java +++ b/src/main/java/com/sztzjy/resource_center/mapper/SysTwoCatalogMapper.java @@ -36,4 +36,7 @@ public interface SysTwoCatalogMapper { List> getAllTwoCatalogList(@Param("oneId")String oneId); void updateByBatch(@Param("sysTwoCatalogs")List sysTwoCatalogs); + + @Select("select two_id from sys_two_catalog where two_name =#{twoName}") + String getIdByName(String twoName); } \ No newline at end of file diff --git a/src/main/resources/mapper/SysCaseQuestionMapper.xml b/src/main/resources/mapper/SysCaseQuestionMapper.xml index 89b68e6..8dbd9f7 100644 --- a/src/main/resources/mapper/SysCaseQuestionMapper.xml +++ b/src/main/resources/mapper/SysCaseQuestionMapper.xml @@ -458,7 +458,8 @@ - - \ No newline at end of file diff --git a/src/main/resources/mapper/SysCaseQuestionStepMapper.xml b/src/main/resources/mapper/SysCaseQuestionStepMapper.xml index fd39172..0a95801 100644 --- a/src/main/resources/mapper/SysCaseQuestionStepMapper.xml +++ b/src/main/resources/mapper/SysCaseQuestionStepMapper.xml @@ -432,5 +432,12 @@ GROUP BY sq.title, s3.three_name,sqs.case_id; - + \ No newline at end of file diff --git a/src/main/resources/mapper/SysTopicAndCourseMapper.xml b/src/main/resources/mapper/SysTopicAndCourseMapper.xml index 78baacf..8a07311 100644 --- a/src/main/resources/mapper/SysTopicAndCourseMapper.xml +++ b/src/main/resources/mapper/SysTopicAndCourseMapper.xml @@ -328,4 +328,21 @@ #{id} + + + + + \ No newline at end of file