Przeglądaj źródła

feat:添加绑定班主任接口-待完善

sakura 1 rok temu
rodzic
commit
ffd3ee5ba1

+ 10 - 0
school-in-out-admin/src/main/java/com/schoolinout/web/controller/system/TeacherClassRelationController.java

@@ -3,7 +3,9 @@ package com.schoolinout.web.controller.system;
 import com.schoolinout.common.core.controller.BaseController;
 import com.schoolinout.common.core.domain.AjaxResult;
 import com.schoolinout.system.domain.dto.AddTeacherClassRelationDto;
+import com.schoolinout.system.domain.dto.BindClassTeacherMain;
 import com.schoolinout.system.service.ITeacherClassRelationService;
+import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
@@ -23,6 +25,13 @@ public class TeacherClassRelationController extends BaseController {
         this.teacherClassRelationService = teacherClassRelationService;
     }
 
+
+    @PostMapping("/bind/class/teacherMain")
+    public AjaxResult bindClassTeacherMain(@Validated @RequestBody BindClassTeacherMain form) {
+        return success(teacherClassRelationService.bindClassTeacherMain(form));
+    }
+
+    @Operation(description = "获取关系列表")
     @GetMapping("/teacher/info/{schoolId}/{teacherId}")
     public AjaxResult getTeacherClassInfo(@PathVariable Long schoolId, @PathVariable Long teacherId) {
         return success(teacherClassRelationService.queryTeacherBindClassList(schoolId, teacherId));
@@ -31,6 +40,7 @@ public class TeacherClassRelationController extends BaseController {
     /**
      * 以老师为主,绑定多个班级的关系
      */
+    @Operation(summary = "以老师为主,绑定多个班级的关系")
     @PostMapping("/bind/teacher")
     public AjaxResult bindTeacherClass(@Validated @RequestBody AddTeacherClassRelationDto form) {
         return toAjax(teacherClassRelationService.bindTeacherClass(form));

+ 56 - 0
school-in-out-system/src/main/java/com/schoolinout/system/domain/dto/BindClassTeacherMain.java

@@ -0,0 +1,56 @@
+package com.schoolinout.system.domain.dto;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author sakura
+ * @date 2024/1/4 17:17:28 Thu
+ */
+@Schema(name = "绑定班级的班主任")
+public class BindClassTeacherMain {
+
+    @NotNull(message = "所属学校不能为空")
+    private Long schoolId;
+    @NotNull(message = "班级不能为空")
+    private Long classId;
+    @NotNull(message = "教师不能为空")
+    private Long teacherId;
+
+    @NotBlank(message = "关系不能为空")
+    private String teacherMain;
+
+    public Long getSchoolId() {
+        return schoolId;
+    }
+
+    public void setSchoolId(Long schoolId) {
+        this.schoolId = schoolId;
+    }
+
+    public Long getClassId() {
+        return classId;
+    }
+
+    public void setClassId(Long classId) {
+        this.classId = classId;
+    }
+
+    public Long getTeacherId() {
+        return teacherId;
+    }
+
+    public void setTeacherId(Long teacherId) {
+        this.teacherId = teacherId;
+    }
+
+    public String getTeacherMain() {
+        return teacherMain;
+    }
+
+    public void setTeacherMain(String teacherMain) {
+        this.teacherMain = teacherMain;
+    }
+}

+ 3 - 0
school-in-out-system/src/main/java/com/schoolinout/system/mapper/ClazzMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.schoolinout.system.domain.Clazz;
 import com.schoolinout.system.domain.vo.OptionVo;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -64,4 +65,6 @@ public interface ClazzMapper extends BaseMapper<Clazz> {
     public int deleteClazzByIds(Long[] ids);
 
     List<OptionVo> selectClazzOptionBySchoolId(Long schoolId);
+
+    Clazz selectClazzByIdAndSchoolId(@Param("classId") Long classId, @Param("schoolId") Long schoolId);
 }

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

@@ -71,4 +71,6 @@ public interface TeacherClassRelationMapper extends BaseMapper<TeacherClassRelat
     int insertTeacherClassRelationBatch(@Param("list") List<InsertTeacherClassRelationDto> list);
 
     List<TeacherClassInfoVo> selectTeacherClass(@Param("schoolId") Long schoolId, @Param("teacherId") Long teacherId, @Param("classId") Long classId);
+
+    TeacherClassRelation selectRelationTeacherMain(@Param("relation") TeacherClassRelation relation);
 }

+ 3 - 0
school-in-out-system/src/main/java/com/schoolinout/system/mapper/TeacherMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.schoolinout.system.domain.Teacher;
 import com.schoolinout.system.domain.vo.OptionVo;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -64,4 +65,6 @@ public interface TeacherMapper extends BaseMapper<Teacher> {
     public int deleteTeacherByIds(Long[] ids);
 
     List<OptionVo> selectTeacherOption(Long schoolId);
+
+    Teacher selectTeacherByIdAndSchoolId(@Param("teacherId") Long teacherId, @Param("schoolId") Long schoolId);
 }

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

@@ -2,6 +2,7 @@ package com.schoolinout.system.service;
 
 import com.schoolinout.system.domain.TeacherClassRelation;
 import com.schoolinout.system.domain.dto.AddTeacherClassRelationDto;
+import com.schoolinout.system.domain.dto.BindClassTeacherMain;
 import com.schoolinout.system.domain.vo.TeacherClassInfoVo;
 
 import java.util.List;
@@ -77,4 +78,12 @@ public interface ITeacherClassRelationService {
      * @return 结果
      */
     public List<TeacherClassInfoVo> queryTeacherBindClassList(Long schoolId, Long teacherId);
+
+    /**
+     * 绑定班级的班主任
+     *
+     * @param form 表单
+     * @return 结果
+     */
+    public String bindClassTeacherMain(BindClassTeacherMain form);
 }

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

@@ -2,11 +2,17 @@ package com.schoolinout.system.service.impl;
 
 import com.schoolinout.common.exception.ServiceException;
 import com.schoolinout.common.utils.DateUtils;
+import com.schoolinout.common.utils.bean.BeanUtils;
+import com.schoolinout.system.domain.Clazz;
+import com.schoolinout.system.domain.Teacher;
 import com.schoolinout.system.domain.TeacherClassRelation;
 import com.schoolinout.system.domain.dto.AddTeacherClassRelationDto;
+import com.schoolinout.system.domain.dto.BindClassTeacherMain;
 import com.schoolinout.system.domain.dto.InsertTeacherClassRelationDto;
 import com.schoolinout.system.domain.vo.TeacherClassInfoVo;
+import com.schoolinout.system.mapper.ClazzMapper;
 import com.schoolinout.system.mapper.TeacherClassRelationMapper;
+import com.schoolinout.system.mapper.TeacherMapper;
 import com.schoolinout.system.service.ITeacherClassRelationService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -25,6 +31,10 @@ import java.util.stream.Collectors;
 public class TeacherClassRelationServiceImpl implements ITeacherClassRelationService {
     @Autowired
     private TeacherClassRelationMapper teacherClassRelationMapper;
+    @Autowired
+    private TeacherMapper teacherMapper;
+    @Autowired
+    private ClazzMapper clazzMapper;
 
     /**
      * 查询老师-班级关系
@@ -111,4 +121,24 @@ public class TeacherClassRelationServiceImpl implements ITeacherClassRelationSer
     public List<TeacherClassInfoVo> queryTeacherBindClassList(Long schoolId, Long teacherId) {
         return teacherClassRelationMapper.selectTeacherClass(schoolId, teacherId, null);
     }
+
+    @Override
+    public String bindClassTeacherMain(BindClassTeacherMain form) {
+        // step1:检测该学校下面是否存在对应的班级和教师
+        Teacher teacher = teacherMapper.selectTeacherByIdAndSchoolId(form.getTeacherId(), form.getSchoolId());
+        if (teacher == null) {
+            throw new ServiceException("当前学校不存在该教师");
+        }
+        Clazz clazz = clazzMapper.selectClazzByIdAndSchoolId(form.getClassId(), form.getSchoolId());
+        if (clazz == null) {
+            throw new ServiceException("当前学校不存在该班级");
+        }
+        // step2:检测当前教师是否已经绑定了其他班的班主任
+        TeacherClassRelation relation = new TeacherClassRelation();
+        BeanUtils.copyBeanProp(relation, form);
+        TeacherClassRelation isTeacherMain = teacherClassRelationMapper.selectRelationTeacherMain(relation);
+
+        // step3:满足上面的条件则更新关系
+        return null;
+    }
 }

+ 4 - 0
school-in-out-system/src/main/resources/mapper/system/ClazzMapper.xml

@@ -66,6 +66,10 @@
         FROM tb_school_class
         where school_id = #{schoolId}
     </select>
+    <select id="selectClazzByIdAndSchoolId" resultType="com.schoolinout.system.domain.Clazz">
+        <include refid="selectClazzVo"/>
+        where id = #{classId} AND school_id #{schoolId}
+    </select>
 
     <insert id="insertClazz" parameterType="Clazz" useGeneratedKeys="true" keyProperty="id">
         insert into tb_school_class

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

@@ -68,6 +68,23 @@
             </if>
         </where>
     </select>
+    <select id="selectRelationTeacherMain" resultType="com.schoolinout.system.domain.TeacherClassRelation">
+        <include refid="selectTeacherClassRelationVo"/>
+        <where>
+            <if test="relation.schoolId != null">
+                AND school_id = #{relation.schoolId}
+            </if>
+            <if test="relation.teacherId != null">
+                AND teacher_id = #{relation.teacherId}
+            </if>
+            <if test="relation.classId != null">
+                AND class_id = #{relation.classId}
+            </if>
+            <if test="relation.teacherMain != null">
+                AND teacher_main = #{relation.teacherMain}
+            </if>
+        </where>
+    </select>
 
 
     <insert id="insertTeacherClassRelation" parameterType="TeacherClassRelation" useGeneratedKeys="true"

+ 7 - 0
school-in-out-system/src/main/resources/mapper/system/TeacherMapper.xml

@@ -53,6 +53,13 @@
         FROM tb_school_teacher
         where school_id = #{schoolId}
     </select>
+    <select id="selectTeacherByIdAndSchoolId" resultType="com.schoolinout.system.domain.Teacher">
+        <include refid="selectTeacherVo"/>
+        where
+        id = #{teacherId}
+        AND
+        school_id = #{schoolId}
+    </select>
 
     <insert id="insertTeacher" parameterType="Teacher" useGeneratedKeys="true" keyProperty="id">
         insert into tb_school_teacher