소스 검색

feat:添加客户端绑定学生接口

sakura 1 년 전
부모
커밋
54dd6762ba

+ 19 - 1
school-in-out-admin/src/main/java/com/schoolinout/web/controller/api/Api_ParentController.java

@@ -3,6 +3,7 @@ package com.schoolinout.web.controller.api;
 import com.schoolinout.api.service.IApiParentService;
 import com.schoolinout.api.service.IApiParentStudentRelationService;
 import com.schoolinout.api.service.IApiStudentService;
+import com.schoolinout.common.core.controller.BaseController;
 import com.schoolinout.common.core.domain.AjaxResult;
 import com.schoolinout.common.core.domain.entity.ParentLogin;
 import com.schoolinout.common.core.domain.entity.SysDictData;
@@ -43,7 +44,7 @@ import java.util.concurrent.TimeUnit;
 @Tag(name = "用户端-家长接口")
 @RequestMapping("/app/parent")
 @RestController
-public class Api_ParentController {
+public class Api_ParentController extends BaseController {
 
     public static final String CODE_CACHE_KEY = "validate:code:";
 
@@ -169,4 +170,21 @@ public class Api_ParentController {
         }
         return AjaxResult.success(data);
     }
+
+    @Operation(summary = "新增绑定学生")
+    @PostMapping("/bind/relation/{studentNum}")
+    public AjaxResult bindStudent(@PathVariable String studentNum) {
+
+        // step1:检测学号学生是否存在
+        Student student = new Student();
+        student.setStudentNum(studentNum);
+        Student studentDb = studentService.listStudentSimple(student);
+        if (studentDb == null) {
+            return AjaxResult.error("不存在该学号的学生");
+        }
+        // step2:存在及保证关系
+        Long parentId = getLoginUser().getParentLogin().getId();
+        parentService.saveOrUpdateRelation(parentId, studentDb.getId());
+        return success();
+    }
 }

+ 6 - 1
school-in-out-admin/src/main/java/com/schoolinout/web/controller/system/StudentController.java

@@ -28,7 +28,7 @@ import java.util.List;
 public class StudentController extends BaseController {
     @Autowired
     private IStudentService studentService;
-    
+
     @GetMapping("/list/all")
     public AjaxResult getAll(Student student) {
         return success(studentService.listAll(student));
@@ -73,6 +73,11 @@ public class StudentController extends BaseController {
     @Log(title = "学生管理", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@RequestBody Student student) {
+        // 根据 学校的id 加上 学号做唯一值,如果存在相同的则不给添加
+        Student studentDb = studentService.selectStudentByStudent(student);
+        if (studentDb != null) {
+            return AjaxResult.error("当前学校存在相同学号的学生");
+        }
         return toAjax(studentService.insertStudent(student));
     }
 

+ 9 - 1
school-in-out-system/src/main/java/com/schoolinout/api/service/IApiParentService.java

@@ -18,7 +18,15 @@ public interface IApiParentService {
     /**
      * 保存对应关系
      *
-     * @param form 表单
+     * @param parent 表单
      */
     public void saveParent(Parent parent);
+
+    /**
+     * 添加或更新家长绑定的学生的关系
+     *
+     * @param parentId  家长id
+     * @param studentId 学生id
+     */
+    void saveOrUpdateRelation(Long parentId, Long studentId);
 }

+ 9 - 0
school-in-out-system/src/main/java/com/schoolinout/api/service/impl/ApiParentServiceImpl.java

@@ -40,4 +40,13 @@ public class ApiParentServiceImpl implements IApiParentService {
         parentStudent.setStudentId(Long.valueOf(parent.getStudentIds()));
         relationMapper.insertOrUpdate(parentStudent);
     }
+
+    @Override
+    @Transactional(rollbackFor = RuntimeException.class)
+    public void saveOrUpdateRelation(Long parentId, Long studentId) {
+        ParentStudent parentStudent = new ParentStudent();
+        parentStudent.setStudentId(studentId);
+        parentStudent.setParentId(parentId);
+        relationMapper.insertOrUpdate(parentStudent);
+    }
 }

+ 2 - 0
school-in-out-system/src/main/java/com/schoolinout/system/mapper/StudentMapper.java

@@ -70,4 +70,6 @@ public interface StudentMapper extends BaseMapper<Student> {
      * @return 结果
      */
     List<StudentListVo> selectStudentListAll(Student student);
+
+    Student selectOnlyOne(Student student);
 }

+ 8 - 0
school-in-out-system/src/main/java/com/schoolinout/system/service/IStudentService.java

@@ -68,4 +68,12 @@ public interface IStudentService {
      * @return 结果
      */
     public int deleteStudentById(Long id);
+
+    /**
+     * 查询单个 学生对象
+     *
+     * @param student 对象实体
+     * @return 结果
+     */
+    public Student selectStudentByStudent(Student student);
 }

+ 7 - 0
school-in-out-system/src/main/java/com/schoolinout/system/service/impl/StudentServiceImpl.java

@@ -7,6 +7,7 @@ import com.schoolinout.system.mapper.StudentMapper;
 import com.schoolinout.system.service.IStudentService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 
@@ -55,6 +56,7 @@ public class StudentServiceImpl implements IStudentService {
      * @return 结果
      */
     @Override
+    @Transactional(rollbackFor = RuntimeException.class)
     public int insertStudent(Student student) {
         student.setCreateTime(DateUtils.getNowDate());
         return studentMapper.insertStudent(student);
@@ -93,4 +95,9 @@ public class StudentServiceImpl implements IStudentService {
     public int deleteStudentById(Long id) {
         return studentMapper.deleteStudentById(id);
     }
+
+    @Override
+    public Student selectStudentByStudent(Student student) {
+        return studentMapper.selectOnlyOne(student);
+    }
 }

+ 17 - 0
school-in-out-system/src/main/resources/mapper/system/StudentMapper.xml

@@ -74,6 +74,23 @@
             </if>
         </where>
     </select>
+    <select id="selectOnlyOne" resultType="com.schoolinout.system.domain.Student" resultMap="StudentResult">
+        <include refid="selectStudentVo"/>
+        <where>
+            <if test="id != null">
+                AND id = #{id}
+            </if>
+            <if test="schoolId != null">
+                AND school_id = #{schoolId}
+            </if>
+            <if test="id != null">
+                AND class_id = #{classId}
+            </if>
+            <if test="studentNum != null and studentNum != ''">
+                AND student_num = #{studentNum}
+            </if>
+        </where>
+    </select>
 
     <insert id="insertStudent" parameterType="Student" useGeneratedKeys="true" keyProperty="id">
         insert into tb_school_student