Przeglądaj źródła

床位调整:
1、左右列表增加班主任信息返回
2、增加批量调整床位的接口

dzx 1 rok temu
rodzic
commit
3439c93f30

+ 8 - 0
src/main/java/com/xjrsoft/module/room/controller/RoomBedAdjustController.java

@@ -98,4 +98,12 @@ public class RoomBedAdjustController {
         Boolean result = roomBedService.adjustBed(dto);
         return RT.ok(result);
     }
+
+    @PutMapping("/adjustBedBatch")
+    @ApiOperation(value = "批量修改学生的寝室床位")
+    @SaCheckPermission("roomBedAdjust:edit")
+    public RT<Boolean> adjustBedBatch(@Valid @RequestBody List<AdjustStudentBedDto> dto){
+        Boolean result = roomBedService.adjustBedBatch(dto);
+        return RT.ok(result);
+    }
 }

+ 6 - 0
src/main/java/com/xjrsoft/module/room/mapper/RoomBedMapper.java

@@ -137,4 +137,10 @@ public interface RoomBedMapper extends MPJBaseMapper<RoomBed> {
      */
     List<StudentPayStatusVo> getStudentPayStatus(@Param("dto") DistributeRoomBedDto dto);
 
+    /**
+     * 查询班级id、名称和班主任信息
+     * @param dto
+     * @return
+     */
+    List<AdjustBedClassPageVo> getClassTeacherInfo(@Param("dto") AdjustClassPageDto dto);
 }

+ 11 - 0
src/main/java/com/xjrsoft/module/room/service/IRoomBedService.java

@@ -94,8 +94,19 @@ public interface IRoomBedService extends MPJBaseService<RoomBed> {
      */
     Page<NoBedStudentPageVo> getNoBedStudent(Page<AdjustBedPageDto> page, AdjustBedPageDto dto);
 
+    /**
+     * 单个学生调整床位
+     * @param dto
+     */
     Boolean adjustBed(AdjustStudentBedDto dto);
 
 
+    /**
+     * 批量学生调整床位
+     * @param dtoList 批量传入学生id和床位id
+     */
+    Boolean adjustBedBatch(List<AdjustStudentBedDto> dtoList);
+
+
 
 }

+ 94 - 9
src/main/java/com/xjrsoft/module/room/service/impl/RoomBedServiceImpl.java

@@ -11,6 +11,7 @@ import com.github.yulichang.base.MPJBaseServiceImpl;
 import com.github.yulichang.toolkit.MPJWrappers;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.enums.DeleteMark;
+import com.xjrsoft.common.enums.GenderDictionaryEnum;
 import com.xjrsoft.common.exception.MyException;
 import com.xjrsoft.common.utils.VoToColumnUtil;
 import com.xjrsoft.module.base.entity.BaseClass;
@@ -421,20 +422,15 @@ public class RoomBedServiceImpl extends MPJBaseServiceImpl<RoomBedMapper, RoomBe
 
     @Override
     public List<AdjustBedClassPageVo> getClassStudetBed(AdjustClassPageDto dto) {
-        List<BaseClass> classList = baseClassMapper.selectList(
-            new QueryWrapper<BaseClass>().lambda()
-            .eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
-            .eq(ObjectUtil.isNotNull(dto.getClassId()), BaseClass::getId, dto.getClassId())
-            .eq(ObjectUtil.isNotNull(dto.getGradeId()), BaseClass::getGradeId, dto.getGradeId())
-        );
+        List<AdjustBedClassPageVo> classList = roomBedMapper.getClassTeacherInfo(dto);
         List<AdjustBedClassPageVo> result = new ArrayList<>();
         List<AdjustBedClassStudentPageVo> allStudent = roomBedMapper.getClassStudetBed(dto);
 
         //查询缴费状态
         DistributeRoomBedDto distributeRoomBedDto = new DistributeRoomBedDto();
         List<Long> classIds = new ArrayList<>();
-        for (BaseClass baseClass : classList) {
-            classIds.add(baseClass.getId());
+        for (AdjustBedClassPageVo baseClass : classList) {
+            classIds.add(Long.parseLong(baseClass.getId()));
         }
         distributeRoomBedDto.setClassIds(classIds);
         List<StudentPayStatusVo> studentPayStatusVoList = roomBedMapper.getStudentPayStatus(distributeRoomBedDto);
@@ -446,7 +442,7 @@ public class RoomBedServiceImpl extends MPJBaseServiceImpl<RoomBedMapper, RoomBe
             }
             payStatusMap.put(statusVo.getId(), payStatus);
         }
-        for (BaseClass classOne : classList) {
+        for (AdjustBedClassPageVo classOne : classList) {
             List<AdjustBedClassStudentPageVo> studentList = new ArrayList<>();
             for (AdjustBedClassStudentPageVo adjustBedClassStudentPageVo : allStudent) {
                 if(!classOne.getId().toString().equals(adjustBedClassStudentPageVo.getClassId())){
@@ -538,4 +534,93 @@ public class RoomBedServiceImpl extends MPJBaseServiceImpl<RoomBedMapper, RoomBe
         }
         return true;
     }
+
+    /**
+     * 1、先做性别校验,如果学生性别和入住寝室的性别不一致,不进行数据保存并返回学生的姓名到前端
+     * 2、参数中可能存在学生id不为空,床位id为空的,根据学生id清空学生相应的床位信息
+     * 3、如果一个学生被安排了多个床位,需要新增提示
+     * @param dtoList
+     * @return
+     */
+    @Override
+    public Boolean adjustBedBatch(List<AdjustStudentBedDto> dtoList) {
+        //存分配到女生寝室的男生名字
+        List<String> boyStudents = new ArrayList<>();
+        //存分配到男生寝室的女生名字
+        List<String> girlStudents = new ArrayList<>();
+        //需要清空床位的学生
+        List<AdjustStudentBedDto> todoStudents = new ArrayList<>();
+        for (AdjustStudentBedDto dto : dtoList) {
+            if(dto.getStudentUserId() != null && dto.getBedId() != null){
+                //查询学生的性别
+                XjrUser xjrUser = xjrUserMapper.selectById(dto.getStudentUserId());
+                String studentGender = xjrUser.getGender();
+
+                RoomBed roomBedInfo = roomBedMapper.selectById(dto.getBedId());
+                Room room = roomMapper.selectById(roomBedInfo.getRoomId());
+                if(!room.getGender().equals(studentGender)){
+                    if(GenderDictionaryEnum.MALE.getCode().equals(room.getGender())){//男生
+                        boyStudents.add(xjrUser.getName());
+                    }else if(GenderDictionaryEnum.FEMALE.getCode().equals(room.getGender())){//女生
+                        girlStudents.add(xjrUser.getName());
+                    }
+                    continue;
+                }
+                //校验通过
+                todoStudents.add(dto);
+            }
+        }
+        //存这次处理过的寝室,查看是否需要设置为混合寝室
+        List<Long> roomIds = new ArrayList<>();
+        if(boyStudents.isEmpty() && girlStudents.isEmpty()){
+            for (AdjustStudentBedDto todoStudent : todoStudents) {
+                //先清空原来的床位
+                UpdateWrapper<RoomBed> updateWrapper = new UpdateWrapper<>();
+                updateWrapper.eq("student_user_id", todoStudent.getStudentUserId());
+                updateWrapper.setSql("student_user_id = null");
+                updateWrapper.setSql("is_check_in = 0");
+                List<RoomBed> roomBedList = roomBedMapper.selectList(new QueryWrapper<RoomBed>().lambda().eq(RoomBed::getStudentUserId, todoStudent.getStudentUserId()));
+                for (RoomBed roomBed : roomBedList) {
+                    roomBedMapper.update(roomBed, updateWrapper);
+                    roomIds.add(roomBed.getRoomId());
+                }
+                //再把学生保存到新的床位
+                roomBedMapper.updateById(new RoomBed(){{
+                    setId(todoStudent.getBedId());
+                    setStudentUserId(todoStudent.getStudentUserId());
+                }});
+            }
+            //如果寝室的人是多个班级,将混合寝室改为是
+            List<RoomClassCountVo> classCountVoList = roomMapper.getRoomClassCount(roomIds);
+            for (RoomClassCountVo roomClassCountVo : classCountVoList) {
+                if(roomClassCountVo.getClassCount() > 1){
+                    Room updRoom = roomMapper.selectById(roomClassCountVo.getId());
+                    updRoom.setIsMax(1);
+                    roomMapper.updateById(updRoom);
+                }
+            }
+        }else{
+            String boyMsg = "学生";
+            for (int i = 0; i < boyStudents.size(); i ++){
+                if(i > 0){
+                    boyMsg += "、";
+                }
+                boyMsg += boyStudents.get(i);
+            }
+            boyMsg += "被分配到女生寝室";
+
+            String girlMsg = "学生";
+            for (int i = 0; i < girlStudents.size(); i ++){
+                if(i > 0){
+                    girlMsg += "、";
+                }
+                girlMsg += girlStudents.get(i);
+            }
+            girlMsg += "被分配到女生寝室";
+
+            throw new MyException(boyMsg + ";" + girlMsg);
+        }
+        return true;
+    }
+
 }

+ 7 - 0
src/main/java/com/xjrsoft/module/room/vo/AdjustBedClassPageVo.java

@@ -29,4 +29,11 @@ public class AdjustBedClassPageVo {
     @ApiModelProperty("学生信息")
     private List<AdjustBedClassStudentPageVo> studentList;
 
+    @ContentStyle(dataFormat = 49)
+    @ApiModelProperty("班主任id")
+    private String teacherId;
+
+    @ContentStyle(dataFormat = 49)
+    @ApiModelProperty("班主任名称")
+    private String teacherName;
 }

+ 8 - 0
src/main/java/com/xjrsoft/module/room/vo/AdjustBedStudentPageVo.java

@@ -62,4 +62,12 @@ public class AdjustBedStudentPageVo {
     @ApiModelProperty("年级名称")
     private String gradeName;
 
+    @ContentStyle(dataFormat = 49)
+    @ApiModelProperty("班主任id")
+    private String teacherId;
+
+    @ContentStyle(dataFormat = 49)
+    @ApiModelProperty("班主任名称")
+    private String teacherName;
+
 }

+ 14 - 1
src/main/resources/mapper/room/RoomBedMapper.xml

@@ -319,7 +319,7 @@
 
     <select id="getBedStudentInfo" parameterType="com.xjrsoft.module.room.dto.AdjustBedPageDto" resultType="com.xjrsoft.module.room.vo.AdjustBedStudentPageVo">
         SELECT t1.id,t3.name AS build_name,t2.room_name,t5.name AS gender_cn,t1.bed_number,t4.name AS student_name,
-        t4.id as student_user_id,t2.is_max,t2.id as room_id,t8.name as class_name,t9.name as grade_name FROM room_bed t1
+        t4.id as student_user_id,t2.is_max,t2.id as room_id,t8.name as class_name,t9.name as grade_name,t10.id as teacher_id,t10.name as teacher_name FROM room_bed t1
         LEFT JOIN room t2 ON t1.room_id = t2.id
         LEFT JOIN base_office_build t3 ON t2.office_build_id = t3.id
         LEFT JOIN xjr_user t4 ON t1.student_user_id = t4.id
@@ -327,6 +327,7 @@
         LEFT JOIN base_student_school_roll t7 ON t4.id = t7.user_id
         left join base_class t8 on t7.class_id = t8.id
         LEFT JOIN base_grade t9 ON t7.grade_id = t9.id
+        left join xjr_user t10 on t8.teacher_id = t10.id
         WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
         <if test="dto.isEmptyRoom != null">
             <if test="dto.isEmptyRoom == 1">
@@ -396,4 +397,16 @@
             </foreach>
         </if>
     </select>
+
+    <select id="getClassTeacherInfo" parameterType="com.xjrsoft.module.room.dto.AdjustClassPageDto" resultType="com.xjrsoft.module.room.vo.AdjustBedClassPageVo">
+        SELECT t1.id,t1.name,t1.id AS teacher_id, t2.name AS teacher_name FROM base_class t1
+        LEFT JOIN xjr_user t2 ON t1.teacher_id = t2.id
+        WHERE t1.delete_mark = 0
+        <if test="dto.gradeId != null">
+            and t1.grade_id = #{dto.gradeId}
+        </if>
+        <if test="dto.classId != null">
+            and t1.id = #{dto.classId}
+        </if>
+    </select>
 </mapper>