فهرست منبع

feat:完成绑定班级班主任接口

sakura 1 سال پیش
والد
کامیت
5eca1a436f

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

@@ -4,6 +4,7 @@ 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.domain.dto.RelationListDto;
 import com.schoolinout.system.service.ITeacherClassRelationService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -33,9 +34,9 @@ public class TeacherClassRelationController extends BaseController {
     }
 
     @Operation(description = "获取关系列表")
-    @GetMapping("/teacher/info/{schoolId}/{teacherId}")
-    public AjaxResult getTeacherClassInfo(@PathVariable Long schoolId, @PathVariable Long teacherId) {
-        return success(teacherClassRelationService.queryTeacherBindClassList(schoolId, teacherId));
+    @GetMapping("/info/list")
+    public AjaxResult getTeacherClassInfo(RelationListDto form) {
+        return success(teacherClassRelationService.queryTeacherBindClassList(form));
     }
 
     /**

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

@@ -18,8 +18,7 @@ public class BindClassTeacherMain {
     @NotNull(message = "班级不能为空")
     @Schema(description = "班级id", requiredMode = Schema.RequiredMode.REQUIRED)
     private Long classId;
-    @NotNull(message = "教师不能为空")
-    @Schema(description = "教师id", requiredMode = Schema.RequiredMode.REQUIRED)
+    @Schema(description = "教师id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
     private Long teacherId;
 
     @NotBlank(message = "关系不能为空")

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

@@ -0,0 +1,36 @@
+package com.schoolinout.system.domain.dto;
+
+/**
+ * @author sakura
+ * @date 2024/1/5 09:9:45 Fri
+ */
+public class RelationListDto {
+
+    private Long schoolId;
+    private Long teacherId;
+    private Long classId;
+
+    public Long getSchoolId() {
+        return schoolId;
+    }
+
+    public void setSchoolId(Long schoolId) {
+        this.schoolId = schoolId;
+    }
+
+    public Long getTeacherId() {
+        return teacherId;
+    }
+
+    public void setTeacherId(Long teacherId) {
+        this.teacherId = teacherId;
+    }
+
+    public Long getClassId() {
+        return classId;
+    }
+
+    public void setClassId(Long classId) {
+        this.classId = classId;
+    }
+}

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

@@ -73,4 +73,6 @@ public interface TeacherClassRelationMapper extends BaseMapper<TeacherClassRelat
     List<TeacherClassInfoVo> selectTeacherClass(@Param("schoolId") Long schoolId, @Param("teacherId") Long teacherId, @Param("classId") Long classId);
 
     void updateTeacherMainBindRelation(@Param("schoolId") Long schoolId, @Param("classId") Long classId, @Param("teacherId") Long teacherId, @Param("teacherMain") String teacherMain, @Param("setTeacherMain") String setTeacherMain);
+
+    TeacherClassRelation selectTeacherMain(@Param("schoolId") Long schoolId, @Param("teacherId") Long teacherId, @Param("classId") Long classId);
 }

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

@@ -2,7 +2,6 @@ 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;
@@ -68,6 +67,4 @@ 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);
 }

+ 2 - 1
school-in-out-system/src/main/java/com/schoolinout/system/service/ITeacherClassRelationService.java

@@ -3,6 +3,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.dto.RelationListDto;
 import com.schoolinout.system.domain.vo.TeacherClassInfoVo;
 
 import java.util.List;
@@ -77,7 +78,7 @@ public interface ITeacherClassRelationService {
      * @param teacherId 教师id
      * @return 结果
      */
-    public List<TeacherClassInfoVo> queryTeacherBindClassList(Long schoolId, Long teacherId);
+    public List<TeacherClassInfoVo> queryTeacherBindClassList(RelationListDto form);
 
     /**
      * 绑定班级的班主任

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

@@ -9,6 +9,7 @@ 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.dto.RelationListDto;
 import com.schoolinout.system.domain.vo.TeacherClassInfoVo;
 import com.schoolinout.system.mapper.ClazzMapper;
 import com.schoolinout.system.mapper.TeacherClassRelationMapper;
@@ -118,17 +119,13 @@ public class TeacherClassRelationServiceImpl implements ITeacherClassRelationSer
     }
 
     @Override
-    public List<TeacherClassInfoVo> queryTeacherBindClassList(Long schoolId, Long teacherId) {
-        return teacherClassRelationMapper.selectTeacherClass(schoolId, teacherId, null);
+    public List<TeacherClassInfoVo> queryTeacherBindClassList(RelationListDto form) {
+        return teacherClassRelationMapper.selectTeacherClass(form.getSchoolId(), form.getTeacherId(), form.getClassId());
     }
 
     @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("当前学校不存在该班级");
@@ -138,8 +135,15 @@ public class TeacherClassRelationServiceImpl implements ITeacherClassRelationSer
         String teacherMain = form.getTeacherMain();
         String ans = "";
         if (DictConstants.SYS_DICT_YES.equals(teacherMain)) {
+            if (form.getTeacherId() == null) {
+                throw new ServiceException("教师不能为空");
+            }
+            Teacher teacher = teacherMapper.selectTeacherByIdAndSchoolId(form.getTeacherId(), form.getSchoolId());
+            if (teacher == null) {
+                throw new ServiceException("当前学校不存在该教师");
+            }
             // step3:校验当前要绑定的教师是否已经绑定了其他班级的班主任
-            TeacherClassRelation teacherMainRelation = teacherMapper.selectTeacherMain(form.getSchoolId(), form.getTeacherId(), null);
+            TeacherClassRelation teacherMainRelation = teacherClassRelationMapper.selectTeacherMain(form.getSchoolId(), form.getTeacherId(), null);
             if (teacherMainRelation != null) {
                 throw new ServiceException("当前教师已经绑定有其他班的班主任,无法再次绑定");
             }
@@ -151,10 +155,11 @@ public class TeacherClassRelationServiceImpl implements ITeacherClassRelationSer
             ans = "绑定成功!";
         } else if (DictConstants.SYS_DICT_NO.equals(teacherMain)) { // step3:解绑操作
             // 解绑
-            teacherClassRelationMapper.updateTeacherMainBindRelation(form.getSchoolId(), form.getClassId(), form.getTeacherId(), null, DictConstants.SYS_DICT_NO);
+            teacherClassRelationMapper.updateTeacherMainBindRelation(form.getSchoolId(), form.getClassId(), null, DictConstants.SYS_DICT_YES, DictConstants.SYS_DICT_NO);
             ans = "解绑成功";
         }
 
+
         return ans;
     }
 }

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

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

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

@@ -46,13 +46,13 @@
     </select>
     <select id="selectTeacherClass" resultType="com.schoolinout.system.domain.vo.TeacherClassInfoVo">
         SELECT
-        id,
+        relation.id,
         relation.teacher_id,
         relation.class_id,
         relation.school_id,
         relation.teacher_main,
         class.class_name,
-        teacher.teacher_name,
+        teacher.teacher_name
         FROM tb_school_teacher_class_relation relation
         JOIN tb_school_class class ON relation.class_id = class.id
         JOIN tb_school_teacher teacher ON relation.school_id = teacher.school_id
@@ -68,6 +68,21 @@
             </if>
         </where>
     </select>
+    <select id="selectTeacherMain" resultType="com.schoolinout.system.domain.TeacherClassRelation">
+        <include refid="selectTeacherClassRelationVo"/>
+        <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="insertTeacherClassRelation" parameterType="TeacherClassRelation" useGeneratedKeys="true"

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

@@ -60,21 +60,6 @@
         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

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

@@ -8,3 +8,12 @@ export function updateTeacherClassRelation(data) {
     data
   })
 }
+
+// 获取关系列表
+export function getRelationInfoList(params) {
+  return request({
+    url: '/system/relation/info/list',
+    method: 'get',
+    params
+  })
+}

+ 49 - 2
school-in-out-ui/src/views/system/clazz/index.vue

@@ -112,7 +112,11 @@
             <i class="el-icon-bind"></i>
             绑定班主任
           </el-button>
-          <el-button v-if="scope.row.teacherMain === 'Y'" size="mini" type="text">
+          <el-button 
+            v-if="scope.row.teacherMain === 'Y'" 
+            size="mini" type="text"
+            @click="unbindTeacherMain(scope.row)"
+          >
             <i class="el-icon-bind"></i>
             解绑班主任
           </el-button>
@@ -134,6 +138,8 @@
       @submit="submitForm"
       @cancel="cancel"
     ></clazz-form>
+    <!-- 绑定班主任对话框 -->
+    <bind-teacher-class ref="bindTeacherClass" @resetTable="getList"/>
   </div>
 </template>
 
@@ -141,13 +147,18 @@
 import { listClazz, getClazz, delClazz, addClazz, updateClazz } from "@/api/system/clazz";
 import {updateTeacherClassRelation} from '@/api/system/teacher_class_relation'
 import ClazzForm from "./module/ClazzForm";
+import BindTeacherClass from "./module/BindTeacherClass";
 import Textyixia from "@/mixin/Textyixia"
+
+import { Loading } from 'element-ui';
+
 export default {
   name: "Clazz",
   mixins: [Textyixia],
   dicts: ['sys_yes_no'],
   components: {
-    ClazzForm
+    ClazzForm,
+    BindTeacherClass,
   },
   data() {
     return {
@@ -277,8 +288,44 @@ export default {
         ...this.queryParams
       }, `clazz_${new Date().getTime()}.xlsx`)
     },
+    /** 绑定班主任 */
     handleTeacherClassBind(row) {
       // 弹出对话框,并让用户设置对应的教师
+      this.$refs.bindTeacherClass.form.schoolId = row.schoolId;
+      this.$refs.bindTeacherClass.form.classId = row.id;
+      this.$refs.bindTeacherClass.openDialog();
+
+    },
+    /** 解绑班主任 */
+    unbindTeacherMain(row) {
+        this.form = {
+            schoolId: row.schoolId,
+            classId: row.id,
+            teacherMain: 'N',
+        }
+        // 解绑班主任关系
+        this.$confirm('确定解绑班主任?', '提示', {
+          confirmButtonText: '确定',
+          cancelButtonText: '取消',
+          type: 'warning'
+        }).then(() => {
+          const loadingInstance =  Loading.service({fullscreen: true, text: '正在解绑班主任...', background: 'rgba(0, 0, 0, 0.8)'})
+          updateTeacherClassRelation(this.form).then(res => {
+            console.log(res);
+            this.$message({
+              type:'success',
+              message: '解绑成功!'
+            });
+           
+          }).finally(() => {
+            setTimeout(() => {
+              this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
+                loadingInstance.close();
+              });
+            }, 500)
+            this.getList();
+          })
+        })
     }
   }
 };

+ 112 - 0
school-in-out-ui/src/views/system/clazz/module/BindTeacherClass.vue

@@ -0,0 +1,112 @@
+<template>
+  <el-dialog 
+    v-loading="loading"  
+    element-loading-text="正在绑定中..."
+    element-loading-spinner="el-icon-loading"
+    element-loading-background="rgba(0, 0, 0, 0.8)"
+    title="绑定班主任" width="450px" 
+    :visible.sync="open"
+  >
+    <el-form 
+        :model="form" 
+        :rules="rules" 
+        ref="bindRuleForm" 
+    >
+        <el-form-item label="教师" label-width="60px" prop="teacherId">
+            <el-select 
+                v-model="form.teacherId" 
+                :loading="bindOptionLoding" 
+                loading-text="正在加载中~~~"
+                reserve-keyword 
+                @visible-change="searchTeacherOption" 
+                placeholder="请选择该班级教师" style="width: 100%;">
+            <el-option 
+                v-for="item in teacherOptions" 
+                :key="item.value" 
+                :label="item.label" 
+                :value="item.value"></el-option>
+          </el-select>
+        </el-form-item>
+    </el-form>
+    <div slot="footer" class="dialog-footer">
+        <el-button @click="closeDialog">取 消</el-button>
+        <el-button type="primary" @click="submitForm">确 定</el-button>
+    </div>
+ </el-dialog>
+</template>
+
+<script>
+import {updateTeacherClassRelation, getRelationInfoList} from '@/api/system/teacher_class_relation'
+export default {
+    data() {
+        return {
+            loading: false,
+            form: {},
+            open: false,
+            option: [],
+            bindOptionLoding: false,
+            teacherOptions: [],
+            rules: {
+                teacherId: [
+                    { required: true, message: '请选择教师', trigger: 'change' }
+                ],
+            }
+        }
+    },
+    methods: {
+        openDialog() {
+            this.open = true;
+        },
+        closeDialog() {
+            this.open = false;
+            this.reset();
+            this.$refs.bindRuleForm.resetFields()
+        },
+        dialogFormVisibleChange(val) {
+            this.dialogFormVisible = val;
+        },
+        reset() {
+            this.form = {};
+        },
+        searchTeacherOption(openSelect) {
+            if (openSelect) {
+                // 发送请求
+                console.log("搜索数据");
+                getRelationInfoList(this.form).then(res => {
+                    console.log(res);
+                    let data = res.data;
+                    this.teacherOptions = data.map(item => {
+                        let obj = {};
+                        obj.label = item.teacherName;
+                        obj.value = item.teacherId;
+                        return obj;
+                    })
+                 
+                })
+            }
+        },
+        submitForm() {
+            this.$refs.bindRuleForm.validate(isOk => {
+                if (isOk) {
+                    this.loading = true
+                    this.form.teacherMain = 'Y';
+       
+                    updateTeacherClassRelation(this.form).then(res => {
+                        // 发送请求
+                        this.$message.success('绑定成功!');
+                        // 关闭表单
+                        this.closeDialog();
+                        // 重置列表
+                        this.$emit('resetTable');
+                        this.loading = false
+                    })
+                }
+            })
+        }
+    },
+}
+</script>
+
+<style>
+
+</style>