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 2c21a85..1e5f3e4 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/CaseController.java +++ b/src/main/java/com/sztzjy/resource_center/controller/CaseController.java @@ -4,11 +4,10 @@ import cn.hutool.core.util.IdUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.sztzjy.resource_center.annotation.AnonymousAccess; -import com.sztzjy.resource_center.entity.SysCaseQuestion; -import com.sztzjy.resource_center.entity.SysCaseQuestionExample; -import com.sztzjy.resource_center.entity.SysTopicAndCourse; +import com.sztzjy.resource_center.entity.*; import com.sztzjy.resource_center.mapper.SysCaseQuestionMapper; import com.sztzjy.resource_center.mapper.SysCaseQuestionStepMapper; +import com.sztzjy.resource_center.mapper.SysOneCatalogMapper; import com.sztzjy.resource_center.mapper.SysTopicAndCourseMapper; import com.sztzjy.resource_center.util.ResultEntity; import io.swagger.annotations.Api; @@ -21,6 +20,7 @@ import org.springframework.web.bind.annotation.*; import java.util.Date; import java.util.List; +import java.util.UUID; /** * @Author xcj @@ -37,7 +37,8 @@ public class CaseController { private SysCaseQuestionMapper caseQuestionMapper; @Autowired private SysTopicAndCourseMapper topicAndCourseMapper; - + @Autowired + private SysOneCatalogMapper sysOneCatalogMapper; @AnonymousAccess @ApiOperation("案例题新增") @@ -84,7 +85,7 @@ public class CaseController { @AnonymousAccess - @ApiOperation("案例题查询") + @ApiOperation("案例题页面查询") @PostMapping("selectCaseByConditions") public ResultEntity> selectCaseByConditions(@RequestParam Integer index, @RequestParam Integer size, @@ -96,26 +97,92 @@ public class CaseController { return new ResultEntity>(pageInfo); } + @AnonymousAccess + @ApiOperation("案例题详细内容展示") + @PostMapping("selectCaseByConditionsByID") + public ResultEntity selectCaseByConditionsByID(@RequestParam String caseId) { + SysCaseQuestion sysCaseQuestion = caseQuestionMapper.selectByPrimaryKey(caseId); + return new ResultEntity(sysCaseQuestion); + } + + //案例库自动同步课程配置新增的和老师新增的案例,老师新增的案例正在使用时只能查看,如果老师删除了这个案例,这个案例可以编辑删除。 @AnonymousAccess @ApiOperation("案例题编辑") @PostMapping("updateCase") - public ResultEntity updateCase() { - return null; + public ResultEntity updateCase(@RequestBody SysCaseQuestion sysCaseQuestion, + @ApiParam("谁调的请求,传管理员/学校ID") @RequestParam String source) { + List sysTopicAndCourses = getSysTopicAndCourses(sysCaseQuestion.getCaseId()); + if (!sysTopicAndCourses.isEmpty()) { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该案例题正在被使用!"); + } else { + //todo 管理员任意修改,老师只能改自己的 + if ("管理员".equals(source) || source.equals(sysCaseQuestion.getSource())) { + caseQuestionMapper.updateByPrimaryKey(sysCaseQuestion); + return new ResultEntity<>(HttpStatus.OK, "编辑成功!"); + } else { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "权限不足!"); + } + } } - //删除案例时如果案例正在被使用则不能删除,提示该案例正在被xx课程xx章节使用,不能删除。 + + //删除案例时如果案例正在被使用,则不能删除,提示该案例正在被xx课程xx章节使用,不能删除。 @AnonymousAccess - @ApiOperation("案例题删除") + @ApiOperation("案例题删除") //逻辑删除 @PostMapping("deleteCase") - public ResultEntity deleteCase() { - return null; + public ResultEntity deleteCase(@RequestBody SysCaseQuestion sysCaseQuestion, + @ApiParam("哪个用的掉的请求,传管理员/学校ID") @RequestParam String source) { + List sysTopicAndCourses = getSysTopicAndCourses(sysCaseQuestion.getCaseId()); + if (!sysTopicAndCourses.isEmpty()) { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "无法删除!该案例题正在被使用!"); + } else { + //todo 管理员任意删除 老师只能删除自己上传的 + if ("管理员".equals(source) || source.equals(sysCaseQuestion.getSource())) { + SysCaseQuestion dataSysCaseQuestion = caseQuestionMapper.selectByPrimaryKey(sysCaseQuestion.getCaseId()); + dataSysCaseQuestion.setUnmountStatus(true); + caseQuestionMapper.updateByPrimaryKey(dataSysCaseQuestion); + return new ResultEntity<>(HttpStatus.OK, "编辑成功!"); + } else { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "权限不足!"); + } + } + } + + private List getSysTopicAndCourses(String caseId) { + SysTopicAndCourseExample example = new SysTopicAndCourseExample(); + example.createCriteria().andTopicIdEqualTo(caseId).andTopicTypeEqualTo("1"); + List sysTopicAndCourses = topicAndCourseMapper.selectByExample(example); + return sysTopicAndCourses; } @AnonymousAccess @ApiOperation("案例题添加步骤") @PostMapping("insertCaseStepByCaseId") - public ResultEntity insertCaseStepByCaseId() { - return null; + public ResultEntity insertCaseStepByCaseId(@RequestBody SysCaseQuestionStepWithBLOBs caseQuestionStep, + @RequestParam @ApiParam("管理员/学校ID") String source) { + if (caseQuestionStep.getCaseId().isEmpty()) { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "案例步骤新增失败,未选择添加案例"); + } + if (caseQuestionStep.getTitle().isEmpty() + || caseQuestionStep.getQuestion().isEmpty() + || caseQuestionStep.getAnswer().isEmpty() + || caseQuestionStep.getContent().isEmpty()) { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "案例步骤新增失败,必填内容为空"); + } + + //todo 现在逻辑是 管理员和老师只能给各自新增的案例题加步骤 + SysCaseQuestion sysCaseQuestion = caseQuestionMapper.selectByPrimaryKey(caseQuestionStep.getCaseId()); + if (!source.equals(sysCaseQuestion.getSource())) { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "权限不足"); + } else { + try { + caseQuestionStep.setCaseStepId(String.valueOf(UUID.randomUUID())); + caseQuestionStepMapper.insert(caseQuestionStep); + return new ResultEntity<>(HttpStatus.OK, "案例步骤新增成功"); + } catch (Exception e) { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "案例步骤新增失败"); + } + } } } 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 91864b2..ae31e3f 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/CaseStepController.java +++ b/src/main/java/com/sztzjy/resource_center/controller/CaseStepController.java @@ -1,8 +1,19 @@ package com.sztzjy.resource_center.controller; +import com.sztzjy.resource_center.annotation.AnonymousAccess; +import com.sztzjy.resource_center.entity.*; +import com.sztzjy.resource_center.mapper.SysCaseQuestionMapper; +import com.sztzjy.resource_center.mapper.SysCaseQuestionStepMapper; +import com.sztzjy.resource_center.mapper.SysTopicAndCourseMapper; +import com.sztzjy.resource_center.util.ResultEntity; import io.swagger.annotations.Api; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import java.util.List; /** * @Author xcj @@ -12,7 +23,80 @@ import org.springframework.web.bind.annotation.RestController; @Api(tags = "案例题步骤") @RequestMapping("api/sys/case/step") public class CaseStepController { + @Autowired + private SysCaseQuestionStepMapper caseQuestionStepMapper; + @Autowired + private SysTopicAndCourseMapper topicAndCourseMapper; + @Autowired + private SysCaseQuestionMapper sysCaseQuestionMapper; + + + @AnonymousAccess + @ApiOperation("案例步骤展示") + @PostMapping("selectCaseStep") + public ResultEntity> selectCaseStep(@ApiParam("案例题ID") @RequestParam String caseId) { + SysCaseQuestionStepExample example = new SysCaseQuestionStepExample(); + example.createCriteria().andCaseIdEqualTo(caseId); +// example.setOrderByClause("sort ASC"); + List stepList = caseQuestionStepMapper.selectByExampleWithBLOBs(example); + return new ResultEntity<>(stepList); + } + + @GetMapping("selectCaseStepDetails") + @ApiOperation("案例题步骤内容查看") + public ResultEntity selectCaseStepDetails(@ApiParam("案例题步骤ID") @RequestParam String caseStepId) { + SysCaseQuestionStep sysCaseQuestionStep = caseQuestionStepMapper.selectByPrimaryKey(caseStepId); + return new ResultEntity<>(HttpStatus.OK, "案例题步骤内容查看成功", sysCaseQuestionStep); + } + + + @AnonymousAccess + @ApiOperation("案例题步骤编辑") + @PostMapping("updateCase") + 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 { + //todo 管理员任意修改,老师只能改自己的 + SysCaseQuestion sysCaseQuestion = sysCaseQuestionMapper.selectByPrimaryKey(caseQuestionStepWithBLOBs.getCaseId()); + if ("管理员".equals(source) || source.equals(sysCaseQuestion.getSource())) { + caseQuestionStepMapper.updateByPrimaryKey(caseQuestionStepWithBLOBs); + return new ResultEntity<>(HttpStatus.OK, "编辑成功!"); + } else { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "权限不足!"); + } + } + } + + + @AnonymousAccess + @ApiOperation("案例题步骤删除") + @PostMapping("deleteCase") + public ResultEntity deleteCase(@RequestBody SysCaseQuestionStepWithBLOBs sysCaseQuestionStep, + @ApiParam("哪个用的掉的请求,传管理员/学校ID") @RequestParam String source) { + List sysTopicAndCourses = getSysTopicAndCourses(sysCaseQuestionStep.getCaseId()); + if (!sysTopicAndCourses.isEmpty()) { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "无法删除!该案例题正在被使用!"); + } else { + //todo 管理员任意删除 老师只能删除自己上传的 + SysCaseQuestion sysCaseQuestion = sysCaseQuestionMapper.selectByPrimaryKey(sysCaseQuestionStep.getCaseId()); + if ("管理员".equals(source) || source.equals(sysCaseQuestion.getSource())) { + caseQuestionStepMapper.deleteByPrimaryKey(sysCaseQuestionStep.getCaseStepId()); + return new ResultEntity<>(HttpStatus.OK, "删除成功!"); + } else { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "权限不足!"); + } + } + } + private List getSysTopicAndCourses(String caseId) { + SysTopicAndCourseExample example = new SysTopicAndCourseExample(); + example.createCriteria().andTopicIdEqualTo(caseId).andTopicTypeEqualTo("1"); + List sysTopicAndCourses = topicAndCourseMapper.selectByExample(example); + return sysTopicAndCourses; + } } diff --git a/src/main/resources/mapper/SysCaseQuestionMapper.xml b/src/main/resources/mapper/SysCaseQuestionMapper.xml index cc792c0..9eacb36 100644 --- a/src/main/resources/mapper/SysCaseQuestionMapper.xml +++ b/src/main/resources/mapper/SysCaseQuestionMapper.xml @@ -390,6 +390,7 @@ and s.title = #{title} + and s.unmount_status is false