Forráskód Böngészése

床位分配,已经分配的寝室还可以继续分配产生混合寝室

dzx 1 éve
szülő
commit
40e4abaa89

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

@@ -143,4 +143,5 @@ public interface RoomBedMapper extends MPJBaseMapper<RoomBed> {
      * @return
      */
     List<AdjustBedClassPageVo> getClassTeacherInfo(@Param("dto") AdjustClassPageDto dto);
+
 }

+ 20 - 0
src/main/java/com/xjrsoft/module/room/mapper/RoomMapper.java

@@ -6,6 +6,7 @@ import com.xjrsoft.module.room.dto.AddRoomDto;
 import com.xjrsoft.module.room.dto.RoomPageDto;
 import com.xjrsoft.module.room.entity.Room;
 import com.xjrsoft.module.room.vo.RoomClassCountVo;
+import com.xjrsoft.module.room.vo.RoomClassExistentVo;
 import com.xjrsoft.module.room.vo.RoomExcelVo;
 import com.xjrsoft.module.room.vo.RoomPageVo;
 import org.apache.ibatis.annotations.Mapper;
@@ -42,4 +43,23 @@ public interface RoomMapper extends MPJBaseMapper<Room> {
     Integer getMaxSortCode();
 
     List<RoomClassCountVo> getRoomClassCount(List<Long> ids);
+
+    /**
+     * 查询每个寝室已经入住的班级有哪些
+     * @param ids
+     * @return
+     */
+    List<RoomClassExistentVo> getRoomClassExistent(List<Long> ids);
+
+    /**
+     * 将有多个班级的寝室设置为混合寝室
+     * @return
+     */
+    Boolean setIsmaxTrue();
+
+    /**
+     * 将没有多个班级的混合寝室清除掉
+     * @return
+     */
+    Boolean setIsmaxFalse();
 }

+ 26 - 27
src/main/java/com/xjrsoft/module/room/service/impl/RoomBedServiceImpl.java

@@ -42,6 +42,7 @@ import com.xjrsoft.module.room.vo.NoBedStudentPageVo;
 import com.xjrsoft.module.room.vo.RoomBedExcelVo;
 import com.xjrsoft.module.room.vo.RoomBedPageVo;
 import com.xjrsoft.module.room.vo.RoomClassCountVo;
+import com.xjrsoft.module.room.vo.RoomClassExistentVo;
 import com.xjrsoft.module.room.vo.StudentPayStatusVo;
 import com.xjrsoft.module.student.entity.BaseStudent;
 import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
@@ -277,7 +278,12 @@ public class RoomBedServiceImpl extends MPJBaseServiceImpl<RoomBedMapper, RoomBe
             genderSet.add(room.getGender());
             roomClassMaps.put(room.getId(), null);
         }
-
+        //
+        List<RoomClassExistentVo> roomClassExistent = roomMapper.getRoomClassExistent(dto.getRoomIds());
+        Map<Long, String> roomClassExistentMaps = new HashMap<>();
+        for (RoomClassExistentVo roomClassExistentVo : roomClassExistent) {
+            roomClassExistentMaps.put(roomClassExistentVo.getId(), roomClassExistentVo.getClassIds());
+        }
         Date modifyDate = new Date();
         Long modifyUserId = StpUtil.getLoginIdAsLong();
         //查询每个班的学生,修改床位信息
@@ -337,7 +343,10 @@ public class RoomBedServiceImpl extends MPJBaseServiceImpl<RoomBedMapper, RoomBe
                 if(dto.getIsNeedMaxRoom() == 0 && i <= bedInfoList.size()){
                     //预先查看下一个床位所属寝室是否已经有其他班级入住,有就直接跳过
                     for (int j = i; j < bedInfoList.size(); j ++) {
-                        if(roomClassMaps.get(bedInfoList.get(j).getRoomId()) != null && !classId.equals(roomClassMaps.get(bedInfoList.get(j).getRoomId())) ){
+                        Long roomId = bedInfoList.get(j).getRoomId();
+                        if((roomClassMaps.get(roomId) != null
+                                && !classId.equals(roomClassMaps.get(roomId)))
+                                && (roomClassExistentMaps.get(roomId) != null && roomClassExistentMaps.get(roomId).contains(classId.toString()))){
                             i ++;
                         }
                     }
@@ -383,16 +392,18 @@ public class RoomBedServiceImpl extends MPJBaseServiceImpl<RoomBedMapper, RoomBe
             record.setDeleteMark(DeleteMark.NODELETE.getCode());
             roomBedRecordMapper.insert(record);
         }
-
-        //查询每个寝室住入的班级数量,大于2的设置为混合寝室
-        List<RoomClassCountVo> classCountVoList = roomMapper.getRoomClassCount(dto.getRoomIds());
-        for (RoomClassCountVo roomClassCountVo : classCountVoList) {
-            if(roomClassCountVo.getClassCount() > 1){
-                Room updRoom = roomMapper.selectById(roomClassCountVo.getId());
-                updRoom.setIsMax(1);
-                roomMapper.updateById(updRoom);
-            }
+        if(dto.getIsNeedMaxRoom() == 1){
+            roomMapper.setIsmaxTrue();
         }
+        //查询每个寝室住入的班级数量,大于2的设置为混合寝室
+//        List<RoomClassCountVo> classCountVoList = roomMapper.getRoomClassCount(dto.getRoomIds());
+//        for (RoomClassCountVo roomClassCountVo : classCountVoList) {
+//            if(roomClassCountVo.getClassCount() > 1){
+//                Room updRoom = roomMapper.selectById(roomClassCountVo.getId());
+//                updRoom.setIsMax(1);
+//                roomMapper.updateById(updRoom);
+//            }
+//        }
         return true;
     }
 
@@ -609,22 +620,10 @@ public class RoomBedServiceImpl extends MPJBaseServiceImpl<RoomBedMapper, RoomBe
                     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{
-                    Room updRoom = roomMapper.selectById(roomClassCountVo.getId());
-                    if(updRoom != null){
-                        updRoom.setIsMax(0);
-                        roomMapper.updateById(updRoom);
-                    }
-
-                }
-            }
+            //将有多个班级的寝室设置为混合寝室
+            roomMapper.setIsmaxTrue();
+            //将没有多个班级的混合寝室清除掉
+            roomMapper.setIsmaxFalse();
         }else{
             String boyMsg = "学生";
             int i = 0;

+ 27 - 0
src/main/java/com/xjrsoft/module/room/vo/RoomClassExistentVo.java

@@ -0,0 +1,27 @@
+package com.xjrsoft.module.room.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+* @title: 寝室表单出参
+* @Author dzx
+* @Date: 2024年3月20日
+* @Version 1.0
+*/
+@Data
+public class RoomClassExistentVo {
+
+    /**
+    * 主键编号
+    */
+    @ApiModelProperty("主键编号")
+    private Long id;
+    /**
+    * 序号
+    */
+    @ApiModelProperty("班级ids")
+    private String classIds;
+
+
+}

+ 38 - 0
src/main/resources/mapper/room/RoomMapper.xml

@@ -76,4 +76,42 @@
             </foreach>
         </if>
     </select>
+
+    <select id="getRoomClassExistent" resultType="com.xjrsoft.module.room.vo.RoomClassExistentVo">
+        SELECT id,(
+        SELECT GROUP_CONCAT(DISTINCT t1.class_id) FROM base_student_school_roll t1
+        LEFT JOIN room_bed t3 ON t1.user_id = t3.student_user_id
+        WHERE t3.room_id = room.id AND t3.delete_mark = 0
+        ) AS class_count FROM room
+        where delete_mark = 0
+        <if test="ids != null and ids.size() > 0">
+            and id in
+            <foreach item="roomId" index="index" collection="ids" open="(" close=")" separator=",">
+                #{roomId}
+            </foreach>
+        </if>
+    </select>
+
+    <!-- 将有多个班级的寝室设置为混合寝室 -->
+    <update id="setIsmaxTrue">
+        UPDATE room SET is_max = 0 WHERE delete_mark = 0
+        AND (
+        SELECT COUNT(*) FROM (
+        SELECT COUNT(*) FROM base_student_school_roll t1
+        LEFT JOIN room_bed t3 ON t1.user_id = t3.student_user_id
+        WHERE t3.room_id = room.id AND t3.delete_mark = 0 GROUP BY t1.class_id
+        ) class_data
+        ) > 1
+    </update>
+    <!-- 将没有多个班级的混合寝室清除掉 -->
+    <update id="setIsmaxFalse">
+        UPDATE room SET is_max = 0 WHERE delete_mark = 0
+        AND 1 >(
+        SELECT COUNT(*) FROM (
+        SELECT COUNT(*) FROM base_student_school_roll t1
+        LEFT JOIN room_bed t3 ON t1.user_id = t3.student_user_id
+        WHERE t3.room_id = room.id AND t3.delete_mark = 0 GROUP BY t1.class_id
+        ) class_data
+        )
+    </update>
 </mapper>

+ 1 - 0
src/main/resources/sqlScript/20240311_sql.sql

@@ -50,6 +50,7 @@ CREATE TABLE `pb_semester_config` (
   `enabled_mark` INT DEFAULT NULL,
   `base_semester_id` BIGINT DEFAULT NULL COMMENT '学期',
   `beltcode` VARCHAR(30) DEFAULT NULL COMMENT '攀宝学期code',
+  `beltname` VARCHAR(30) DEFAULT NULL COMMENT '攀宝学期名称',
   PRIMARY KEY (`id`) USING BTREE
 ) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='攀宝学期对应';