From bb3417e2d899ce6736276d74460cfc37e9f5e009 Mon Sep 17 00:00:00 2001
From: xiaoCJ <406612557@qq.com>
Date: Thu, 27 Jun 2024 14:56:53 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E8=87=B4=E5=AE=8C=E6=88=90=E6=A1=88?=
 =?UTF-8?q?=E4=BE=8B=E9=A2=98=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=EF=BC=8C?=
 =?UTF-8?q?=E7=BB=86=E8=8A=82=E9=83=A8=E5=88=86=E5=90=8E=E6=9C=9F=E9=9C=80?=
 =?UTF-8?q?=E6=B1=82=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../controller/CaseController.java            | 93 ++++++++++++++++---
 .../controller/CaseStepController.java        | 88 +++++++++++++++++-
 .../mapper/SysCaseQuestionMapper.xml          |  1 +
 3 files changed, 167 insertions(+), 15 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 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<PageInfo<SysCaseQuestion>> selectCaseByConditions(@RequestParam Integer index,
                                                                           @RequestParam Integer size,
@@ -96,26 +97,92 @@ public class CaseController {
         return new ResultEntity<PageInfo<SysCaseQuestion>>(pageInfo);
     }
 
+    @AnonymousAccess
+    @ApiOperation("案例题详细内容展示")
+    @PostMapping("selectCaseByConditionsByID")
+    public ResultEntity<SysCaseQuestion> selectCaseByConditionsByID(@RequestParam String caseId) {
+        SysCaseQuestion sysCaseQuestion = caseQuestionMapper.selectByPrimaryKey(caseId);
+        return new ResultEntity<SysCaseQuestion>(sysCaseQuestion);
+    }
+
+
     //案例库自动同步课程配置新增的和老师新增的案例,老师新增的案例正在使用时只能查看,如果老师删除了这个案例,这个案例可以编辑删除。
     @AnonymousAccess
     @ApiOperation("案例题编辑")
     @PostMapping("updateCase")
-    public ResultEntity<HttpStatus> updateCase() {
-        return null;
+    public ResultEntity<HttpStatus> updateCase(@RequestBody SysCaseQuestion sysCaseQuestion,
+                                               @ApiParam("谁调的请求,传管理员/学校ID") @RequestParam String source) {
+        List<SysTopicAndCourse> 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<HttpStatus> deleteCase() {
-        return null;
+    public ResultEntity<HttpStatus> deleteCase(@RequestBody SysCaseQuestion sysCaseQuestion,
+                                               @ApiParam("哪个用的掉的请求,传管理员/学校ID") @RequestParam String source) {
+        List<SysTopicAndCourse> 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<SysTopicAndCourse> getSysTopicAndCourses(String caseId) {
+        SysTopicAndCourseExample example = new SysTopicAndCourseExample();
+        example.createCriteria().andTopicIdEqualTo(caseId).andTopicTypeEqualTo("1");
+        List<SysTopicAndCourse> sysTopicAndCourses = topicAndCourseMapper.selectByExample(example);
+        return sysTopicAndCourses;
     }
 
     @AnonymousAccess
     @ApiOperation("案例题添加步骤")
     @PostMapping("insertCaseStepByCaseId")
-    public ResultEntity<HttpStatus> insertCaseStepByCaseId() {
-        return null;
+    public ResultEntity<HttpStatus> 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<List<SysCaseQuestionStepWithBLOBs>> selectCaseStep(@ApiParam("案例题ID") @RequestParam String caseId) {
+        SysCaseQuestionStepExample example = new SysCaseQuestionStepExample();
+        example.createCriteria().andCaseIdEqualTo(caseId);
+//        example.setOrderByClause("sort ASC");
+        List<SysCaseQuestionStepWithBLOBs> stepList = caseQuestionStepMapper.selectByExampleWithBLOBs(example);
+        return new ResultEntity<>(stepList);
+    }
+
+    @GetMapping("selectCaseStepDetails")
+    @ApiOperation("案例题步骤内容查看")
+    public ResultEntity<SysCaseQuestionStep> selectCaseStepDetails(@ApiParam("案例题步骤ID") @RequestParam String caseStepId) {
+        SysCaseQuestionStep sysCaseQuestionStep = caseQuestionStepMapper.selectByPrimaryKey(caseStepId);
+        return new ResultEntity<>(HttpStatus.OK, "案例题步骤内容查看成功", sysCaseQuestionStep);
+    }
+
+
+    @AnonymousAccess
+    @ApiOperation("案例题步骤编辑")
+    @PostMapping("updateCase")
+    public ResultEntity<HttpStatus> updateCase(@RequestBody SysCaseQuestionStepWithBLOBs caseQuestionStepWithBLOBs,
+                                               @ApiParam("谁调的请求,传管理员/学校ID") @RequestParam String source) {
+        List<SysTopicAndCourse> 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<HttpStatus> deleteCase(@RequestBody SysCaseQuestionStepWithBLOBs sysCaseQuestionStep,
+                                               @ApiParam("哪个用的掉的请求,传管理员/学校ID") @RequestParam String source) {
+        List<SysTopicAndCourse> 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<SysTopicAndCourse> getSysTopicAndCourses(String caseId) {
+        SysTopicAndCourseExample example = new SysTopicAndCourseExample();
+        example.createCriteria().andTopicIdEqualTo(caseId).andTopicTypeEqualTo("1");
+        List<SysTopicAndCourse> 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 @@
             <if test="title != null and title != ''">
                 and s.title = #{title}
             </if>
+                and s.unmount_status is false
         </where>
     </select>