Browse Source

家校互动代码跟新

guq 6 years ago
parent
commit
ffceeb539b

+ 16 - 4
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/basic/controller/ClassController.java

@@ -2,11 +2,10 @@ package com.usoftchina.smartschool.school.basic.controller;
 
 import com.usoftchina.smartschool.base.Result;
 import com.usoftchina.smartschool.school.basic.service.ClassService;
+import com.usoftchina.smartschool.school.dto.DocBaseDTO;
 import com.usoftchina.smartschool.school.po.ClassForm;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * @author: guq
@@ -19,9 +18,22 @@ public class ClassController {
     @Autowired
     private ClassService classService;
 
-    @RequestMapping("/read/{id}")
+    @GetMapping("/read/{id}")
     public Result getClass(@PathVariable("id") Long id) {
         ClassForm classForm = classService.getFormdata(id);
         return Result.success(classForm);
     }
+
+    @PostMapping("/save")
+    public Result getFormData(@RequestBody ClassForm form) {
+        DocBaseDTO formData = classService.saveFormData(form);
+        return Result.success(formData);
+    }
+
+    @PostMapping("/delete/{id}")
+    public Result delete(@PathVariable("id") Long id) {
+        classService.delete(id);
+        return Result.success();
+    }
+
 }

+ 5 - 0
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/basic/service/ClassService.java

@@ -1,7 +1,12 @@
 package com.usoftchina.smartschool.school.basic.service;
 
+import com.usoftchina.smartschool.school.dto.DocBaseDTO;
 import com.usoftchina.smartschool.school.po.ClassForm;
 
 public interface ClassService {
     ClassForm getFormdata(Long id);
+
+    DocBaseDTO saveFormData(ClassForm form);
+
+    void delete(Long id);
 }

+ 24 - 0
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/basic/service/impl/ClassServiceImpl.java

@@ -3,6 +3,7 @@ package com.usoftchina.smartschool.school.basic.service.impl;
 import com.usoftchina.smartschool.context.BaseContextHolder;
 import com.usoftchina.smartschool.exception.BizException;
 import com.usoftchina.smartschool.school.basic.service.ClassService;
+import com.usoftchina.smartschool.school.dto.DocBaseDTO;
 import com.usoftchina.smartschool.school.exception.BizExceptionCode;
 import com.usoftchina.smartschool.school.mapper.SysClazzMapper;
 import com.usoftchina.smartschool.school.mapper.SysStudentMapper;
@@ -43,4 +44,27 @@ public class ClassServiceImpl implements ClassService{
         cf.setItems2(teacherDetails);
         return cf;
     }
+
+    @Override
+    public DocBaseDTO saveFormData(ClassForm formdata) {
+        if (null == formdata || null == formdata.getMain()){
+            throw new BizException(BizExceptionCode.EMPTY_DATA);
+        }
+        SysClazz clazz = formdata.getMain();
+        List<SysStudent> students = formdata.getItems1();
+
+        return null;
+    }
+
+    @Override
+    public void delete(Long id) {
+        if (null == id || "0".equals(id)) {
+            return;
+        }
+        Integer count = sysStudentMapper.checkStu(id);
+        if (count > 0) {
+            throw new BizException(BizExceptionCode.EXISTS_STU);
+        }
+        sysClazzMapper.deleteByPrimaryKey(id);
+    }
 }

+ 1 - 0
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/exception/BizExceptionCode.java

@@ -10,6 +10,7 @@ public enum BizExceptionCode implements BaseExceptionCode {
 
     BIZ_IMPORT_ERROREXCEL(500002, "请选用正确的导入模板"),
     EMPTY_DATA(76100,"数据为空,请填写后再保存"),
+    EXISTS_STU(500003,"该班级存在学生,无法删除"),
     USELESS_DATA(50001, "无效数据");
 
     private int code;

+ 2 - 0
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/mapper/SysStudentMapper.java

@@ -40,4 +40,6 @@ public interface SysStudentMapper {
     void insertrelationDetail(@Param("id") Long id, @Param("pr_id") Long pr_id, @Param("relation") String relation);
 
     void deleteRelation(Long id);
+
+    Integer checkStu(Long id);
 }

+ 4 - 0
applications/school/school-server/src/main/resources/mapper/SysStudentMapper.xml

@@ -353,4 +353,8 @@
   <delete id="deleteRelation" parameterType="long">
     delete  from sys_parents_stu where stu_id = #{id}
   </delete>
+
+  <select id="checkStu" parameterType="long" resultType="integer">
+    select count(1) from sys_student where clazz_id=#{id}
+  </select>
 </mapper>