Bläddra i källkod

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

sakura 1 år sedan
förälder
incheckning
c73fc5eed3

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

@@ -26,6 +26,7 @@ public class TeacherClassRelationController extends BaseController {
     }
 
 
+    @Operation(summary = "绑定/解绑-班级班主任关系", description = "teacherMain参数发送Y 就是绑定;发送N 就是解绑")
     @PostMapping("/bind/class/teacherMain")
     public AjaxResult bindClassTeacherMain(@Validated @RequestBody BindClassTeacherMain form) {
         return success(teacherClassRelationService.bindClassTeacherMain(form));

+ 11 - 0
school-in-out-common/src/main/java/com/schoolinout/common/constant/DictConstants.java

@@ -0,0 +1,11 @@
+package com.schoolinout.common.constant;
+
+/**
+ * @author sakura
+ * @date 2024/1/4 20:20:52 Thu
+ */
+public class DictConstants {
+
+    public static final String SYS_DICT_YES = "Y";
+    public static final String SYS_DICT_NO = "N";
+}

+ 11 - 0
school-in-out-system/src/main/java/com/schoolinout/system/domain/Clazz.java

@@ -59,11 +59,22 @@ public class Clazz extends BaseEntity {
     @TableField(exist = false)
     private String teacherName;
 
+    @TableField(exist = false)
+    private String teacherMain;
+
     /**
      * 删除标志(0代表存在 2代表删除)
      */
     private String delFlag;
 
+    public String getTeacherMain() {
+        return teacherMain;
+    }
+
+    public void setTeacherMain(String teacherMain) {
+        this.teacherMain = teacherMain;
+    }
+
     public String getTeacherName() {
         return teacherName;
     }

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

@@ -13,13 +13,17 @@ import javax.validation.constraints.NotNull;
 public class BindClassTeacherMain {
 
     @NotNull(message = "所属学校不能为空")
+    @Schema(description = "学校id", requiredMode = Schema.RequiredMode.REQUIRED)
     private Long schoolId;
     @NotNull(message = "班级不能为空")
+    @Schema(description = "班级id", requiredMode = Schema.RequiredMode.REQUIRED)
     private Long classId;
     @NotNull(message = "教师不能为空")
+    @Schema(description = "教师id", requiredMode = Schema.RequiredMode.REQUIRED)
     private Long teacherId;
 
     @NotBlank(message = "关系不能为空")
+    @Schema(description = "班级与教师的关系,Y或N;Y为绑定班主任关系,N是非班主任关系", requiredMode = Schema.RequiredMode.REQUIRED)
     private String teacherMain;
 
     public Long getSchoolId() {

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

@@ -72,5 +72,5 @@ public interface TeacherClassRelationMapper extends BaseMapper<TeacherClassRelat
 
     List<TeacherClassInfoVo> selectTeacherClass(@Param("schoolId") Long schoolId, @Param("teacherId") Long teacherId, @Param("classId") Long classId);
 
-    TeacherClassRelation selectRelationTeacherMain(@Param("relation") TeacherClassRelation relation);
+    void updateTeacherMainBindRelation(@Param("schoolId") Long schoolId, @Param("classId") Long classId, @Param("teacherId") Long teacherId, @Param("teacherMain") String teacherMain, @Param("setTeacherMain") String setTeacherMain);
 }

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

@@ -2,6 +2,7 @@ package com.schoolinout.system.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.schoolinout.system.domain.Teacher;
+import com.schoolinout.system.domain.TeacherClassRelation;
 import com.schoolinout.system.domain.vo.OptionVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -67,4 +68,6 @@ public interface TeacherMapper extends BaseMapper<Teacher> {
     List<OptionVo> selectTeacherOption(Long schoolId);
 
     Teacher selectTeacherByIdAndSchoolId(@Param("teacherId") Long teacherId, @Param("schoolId") Long schoolId);
+
+    TeacherClassRelation selectTeacherMain(@Param("schoolId") Long schoolId, @Param("teacherId") Long teacherId, @Param("classId") Long classId);
 }

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

@@ -1,8 +1,8 @@
 package com.schoolinout.system.service.impl;
 
+import com.schoolinout.common.constant.DictConstants;
 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;
@@ -133,12 +133,28 @@ public class TeacherClassRelationServiceImpl implements ITeacherClassRelationSer
         if (clazz == null) {
             throw new ServiceException("当前学校不存在该班级");
         }
-        // step2:检测当前教师是否已经绑定了其他班的班主任
-        TeacherClassRelation relation = new TeacherClassRelation();
-        BeanUtils.copyBeanProp(relation, form);
-        TeacherClassRelation isTeacherMain = teacherClassRelationMapper.selectRelationTeacherMain(relation);
 
-        // step3:满足上面的条件则更新关系
-        return null;
+        // step2:判断是否是要绑定
+        String teacherMain = form.getTeacherMain();
+        String ans = "";
+        if (DictConstants.SYS_DICT_YES.equals(teacherMain)) {
+            // step3:校验当前要绑定的教师是否已经绑定了其他班级的班主任
+            TeacherClassRelation teacherMainRelation = teacherMapper.selectTeacherMain(form.getSchoolId(), form.getTeacherId(), null);
+            if (teacherMainRelation != null) {
+                throw new ServiceException("当前教师已经绑定有其他班的班主任,无法再次绑定");
+            }
+            // step3:解绑和更新绑定的操作
+            // 解绑
+            teacherClassRelationMapper.updateTeacherMainBindRelation(form.getSchoolId(), form.getClassId(), null, form.getTeacherMain(), DictConstants.SYS_DICT_NO);
+            // 更新绑定
+            teacherClassRelationMapper.updateTeacherMainBindRelation(form.getSchoolId(), form.getClassId(), form.getTeacherId(), null, DictConstants.SYS_DICT_YES);
+            ans = "绑定成功!";
+        } else if (DictConstants.SYS_DICT_NO.equals(teacherMain)) { // step3:解绑操作
+            // 解绑
+            teacherClassRelationMapper.updateTeacherMainBindRelation(form.getSchoolId(), form.getClassId(), form.getTeacherId(), null, DictConstants.SYS_DICT_NO);
+            ans = "解绑成功";
+        }
+
+        return ans;
     }
 }

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

@@ -11,6 +11,7 @@
         <result property="classCount" column="class_count"/>
         <result property="phone" column="phone"/>
         <result property="teacherName" column="teacher_name"/>
+        <result property="teacherMain" column="teacher_main"/>
         <result property="delFlag" column="del_flag"/>
         <result property="createBy" column="create_by"/>
         <result property="createTime" column="create_time"/>
@@ -39,6 +40,7 @@
         tb_school_class.class_count,
         tb_school_class.phone,
         teacher.teacher_name,
+        relation.teacher_main,
         tb_school_class.del_flag,
         tb_school_class.create_by,
         tb_school_class.create_time,

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

@@ -68,23 +68,6 @@
             </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"
@@ -133,6 +116,24 @@
         </trim>
         where id = #{id}
     </update>
+    <update id="updateTeacherMainBindRelation">
+        UPDATE tb_school_teacher_class_relation
+        SET teacher_main = #{setTeacherMain}
+        <where>
+            <if test="schoolId != null">
+                AND school_id = #{schoolId}
+            </if>
+            <if test="classId != null">
+                AND class_id = #{classId}
+            </if>
+            <if test="teacherId != null">
+                AND teacher_id = #{teacherId}
+            </if>
+            <if test="teacherMain != null">
+                AND teacher_main = #{teacherMain}
+            </if>
+        </where>
+    </update>
 
     <delete id="deleteTeacherClassRelationById" parameterType="Long">
         delete

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

@@ -60,6 +60,21 @@
         AND
         school_id = #{schoolId}
     </select>
+    <select id="selectTeacherMain" resultType="com.schoolinout.system.domain.TeacherClassRelation">
+        <include refid="selectTeacherVo"/>
+        <where>
+            <if test="schoolId != null">
+                AND school_id = #{schoolId}
+            </if>
+            <if test="teacherId != null">
+                AND teacher_id = #{teacherId}
+            </if>
+            <if test="classId != null">
+                AND class_id = #{classId}
+            </if>
+            AND teacher_main = 'Y'
+        </where>
+    </select>
 
     <insert id="insertTeacher" parameterType="Teacher" useGeneratedKeys="true" keyProperty="id">
         insert into tb_school_teacher

+ 10 - 0
school-in-out-ui/src/api/system/teacher_class_relation.js

@@ -0,0 +1,10 @@
+import request from '@/utils/request'
+
+// 解绑/绑定班主任关系
+export function updateTeacherClassRelation(data) {
+  return request({
+    url: '/system/relation/bind/class/teacherMain',
+    method: 'post',
+    data
+  })
+}

+ 19 - 0
school-in-out-ui/src/views/system/clazz/index.vue

@@ -103,6 +103,19 @@
             @click="handleDelete(scope.row)"
             v-hasPermi="['system:clazz:remove']"
           >删除</el-button>
+          <!-- 要弹出对话框 让其进行选择 -->
+          <el-button 
+            v-if="scope.row.teacherMain === 'N' || scope.row.teacherMain === null" 
+            size="mini" type="text"
+            @click="handleTeacherClassBind(scope.row)"
+          >
+            <i class="el-icon-bind"></i>
+            绑定班主任
+          </el-button>
+          <el-button v-if="scope.row.teacherMain === 'Y'" size="mini" type="text">
+            <i class="el-icon-bind"></i>
+            解绑班主任
+          </el-button>
         </template>
       </el-table-column>
     </el-table>
@@ -115,6 +128,7 @@
       @pagination="getList"
     />
 
+    <!-- 新增 修改 班级信息 组件-->
     <clazz-form
       ref="clazzForm"
       @submit="submitForm"
@@ -125,11 +139,13 @@
 
 <script>
 import { listClazz, getClazz, delClazz, addClazz, updateClazz } from "@/api/system/clazz";
+import {updateTeacherClassRelation} from '@/api/system/teacher_class_relation'
 import ClazzForm from "./module/ClazzForm";
 import Textyixia from "@/mixin/Textyixia"
 export default {
   name: "Clazz",
   mixins: [Textyixia],
+  dicts: ['sys_yes_no'],
   components: {
     ClazzForm
   },
@@ -260,6 +276,9 @@ export default {
       this.download('system/clazz/export', {
         ...this.queryParams
       }, `clazz_${new Date().getTime()}.xlsx`)
+    },
+    handleTeacherClassBind(row) {
+      // 弹出对话框,并让用户设置对应的教师
     }
   }
 };