Browse Source

Merge remote-tracking branch 'origin/dev' into dev

phoenix 1 year ago
parent
commit
8a006c455d

+ 38 - 0
src/main/java/com/xjrsoft/module/room/controller/DistributeRoomBedController.java

@@ -0,0 +1,38 @@
+package com.xjrsoft.module.room.controller;
+
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import com.xjrsoft.common.model.result.RT;
+import com.xjrsoft.module.room.dto.DistributeRoomBedDto;
+import com.xjrsoft.module.room.service.IRoomBedService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+
+/**
+* @title: 寝室床位
+* @Author dzx
+* @Date: 2023-12-27
+* @Version 1.0
+*/
+@RestController
+@RequestMapping("/room" + "/distributeRoomBed")
+@Api(value = "/room"  + "/distributeRoomBed",tags = "分配床位")
+@AllArgsConstructor
+public class DistributeRoomBedController {
+
+
+    private final IRoomBedService roomBedService;
+
+    @PutMapping
+    @ApiOperation(value = "修改寝室床位")
+    @SaCheckPermission("roombed:edit")
+    public RT<Boolean> distributeRoomBed(@Valid @RequestBody DistributeRoomBedDto dto){
+        return RT.ok(roomBedService.distributeRoomBed(dto));
+    }
+}

+ 1 - 1
src/main/java/com/xjrsoft/module/room/controller/RoomBedController.java

@@ -10,6 +10,7 @@ import com.xjrsoft.common.page.ConventPage;
 import com.xjrsoft.common.page.PageOutput;
 import com.xjrsoft.module.room.dto.AddRoomBedDto;
 import com.xjrsoft.module.room.dto.DistributeClassPageDto;
+import com.xjrsoft.module.room.dto.DistributeRoomBedDto;
 import com.xjrsoft.module.room.dto.DistributeRoomBedPageDto;
 import com.xjrsoft.module.room.dto.RoomBedPageDto;
 import com.xjrsoft.module.room.dto.UpdateRoomBedDto;
@@ -112,7 +113,6 @@ public class RoomBedController {
         return RT.ok(roomBedService.updateById(roomBed));
 
     }
-
     @DeleteMapping
     @ApiOperation(value = "删除寝室床位")
     @SaCheckPermission("roombed:delete")

+ 27 - 0
src/main/java/com/xjrsoft/module/room/dto/DistributeRoomBedDto.java

@@ -0,0 +1,27 @@
+package com.xjrsoft.module.room.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+
+/**
+* @title: 寝室床位
+* @Author dzx
+* @Date: 2023-12-27
+* @Version 1.0
+*/
+@Data
+public class DistributeRoomBedDto implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty("班级ids")
+    private List<Long> classIds;
+
+    @ApiModelProperty("寝室ids")
+    private List<Long> roomIds;
+
+}

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

@@ -9,8 +9,11 @@ import com.xjrsoft.module.room.entity.RoomBed;
 import com.xjrsoft.module.room.vo.DistributeClassPageVo;
 import com.xjrsoft.module.room.vo.DistributeRoomBedPageVo;
 import com.xjrsoft.module.room.vo.RoomBedPageVo;
+import com.xjrsoft.module.room.vo.RoomBedVo;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
 * @title: 寝室床位
 * @Author dzx
@@ -36,4 +39,6 @@ public interface RoomBedMapper extends MPJBaseMapper<RoomBed> {
     Page<DistributeClassPageVo> getDistributeClassInfo(Page<DistributeClassPageVo> page, DistributeClassPageDto dto);
 
     Page<DistributeRoomBedPageVo> getDistributeRoomBedInfo(Page<DistributeRoomBedPageVo> page, DistributeRoomBedPageDto dto);
+
+    List<RoomBedVo> getBedInfo(List<Long> ids);
 }

+ 5 - 1
src/main/java/com/xjrsoft/module/room/mapper/RoomMapper.java

@@ -1,14 +1,16 @@
 package com.xjrsoft.module.room.mapper;
 
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.base.MPJBaseMapper;
 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.RoomPageVo;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
 * @title: 寝室
 * @Author dzx
@@ -36,4 +38,6 @@ public interface RoomMapper extends MPJBaseMapper<Room> {
      * @return
      */
     Integer getMaxSortCode();
+
+    List<RoomClassCountVo> getRoomClassCount(List<Long> ids);
 }

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

@@ -3,6 +3,7 @@ package com.xjrsoft.module.room.service;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.base.MPJBaseService;
 import com.xjrsoft.module.room.dto.DistributeClassPageDto;
+import com.xjrsoft.module.room.dto.DistributeRoomBedDto;
 import com.xjrsoft.module.room.dto.DistributeRoomBedPageDto;
 import com.xjrsoft.module.room.dto.RoomBedPageDto;
 import com.xjrsoft.module.room.entity.RoomBed;
@@ -47,4 +48,7 @@ public interface IRoomBedService extends MPJBaseService<RoomBed> {
      * @return
      */
     Page<DistributeRoomBedPageVo> getDistributeRoomBedInfo(Page<DistributeRoomBedPageVo> page, DistributeRoomBedPageDto dto);
+
+    Boolean distributeRoomBed(DistributeRoomBedDto dto);
+
 }

+ 60 - 0
src/main/java/com/xjrsoft/module/room/service/impl/RoomBedServiceImpl.java

@@ -1,19 +1,30 @@
 package com.xjrsoft.module.room.service.impl;
 
+import cn.dev33.satoken.stp.StpUtil;
+import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.base.MPJBaseServiceImpl;
 import com.xjrsoft.module.room.dto.DistributeClassPageDto;
+import com.xjrsoft.module.room.dto.DistributeRoomBedDto;
 import com.xjrsoft.module.room.dto.DistributeRoomBedPageDto;
 import com.xjrsoft.module.room.dto.RoomBedPageDto;
+import com.xjrsoft.module.room.entity.Room;
 import com.xjrsoft.module.room.entity.RoomBed;
 import com.xjrsoft.module.room.mapper.RoomBedMapper;
+import com.xjrsoft.module.room.mapper.RoomMapper;
 import com.xjrsoft.module.room.service.IRoomBedService;
 import com.xjrsoft.module.room.vo.DistributeClassPageVo;
 import com.xjrsoft.module.room.vo.DistributeRoomBedPageVo;
 import com.xjrsoft.module.room.vo.RoomBedPageVo;
+import com.xjrsoft.module.room.vo.RoomBedVo;
+import com.xjrsoft.module.room.vo.RoomClassCountVo;
+import com.xjrsoft.module.student.dto.DistributeStudentDto;
+import com.xjrsoft.module.student.mapper.BaseStudentMapper;
+import com.xjrsoft.module.student.vo.StudentInfoVo;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -25,7 +36,9 @@ import java.util.List;
 @Service
 @AllArgsConstructor
 public class RoomBedServiceImpl extends MPJBaseServiceImpl<RoomBedMapper, RoomBed> implements IRoomBedService {
+    private final RoomMapper roomMapper;
     private final RoomBedMapper roomBedMapper;
+    private final BaseStudentMapper baseStudentMapper;
     @Override
     public Page<RoomBedPageVo> getPage(Page<RoomBedPageVo> page, RoomBedPageDto dto) {
         Page<RoomBedPageVo> result = roomBedMapper.getPage(page, dto);
@@ -51,4 +64,51 @@ public class RoomBedServiceImpl extends MPJBaseServiceImpl<RoomBedMapper, RoomBe
     public Page<DistributeRoomBedPageVo> getDistributeRoomBedInfo(Page<DistributeRoomBedPageVo> page, DistributeRoomBedPageDto dto) {
         return roomBedMapper.getDistributeRoomBedInfo(page, dto);
     }
+
+    @Override
+    public Boolean distributeRoomBed(DistributeRoomBedDto dto) {
+        //查询出所有床位信息
+        List<RoomBedVo> bedInfoList = roomBedMapper.getBedInfo(dto.getRoomIds());
+
+        Room room = roomMapper.selectById(dto.getRoomIds().get(0));
+        String gender = room.getGender();
+        Integer genderNumber = null;
+        if("SB10001".equals(gender)){
+            genderNumber = 1;
+        }else if("SB10002".equals(gender)){
+            genderNumber = 2;
+        }
+
+        Date modifyDate = new Date();
+        Long modifyUserId = StpUtil.getLoginIdAsLong();
+
+        //查询每个班的学生,修改床位信息
+        int i = 0;
+        for (Long classId : dto.getClassIds()) {
+            DistributeStudentDto classDto = new DistributeStudentDto();
+            classDto.setClassId(classId);
+            classDto.setGender(genderNumber);
+            List<StudentInfoVo> studentList = baseStudentMapper.getClassStudent(classDto);
+            for (StudentInfoVo studentInfoVo : studentList) {
+                RoomBedVo roomBedVo = bedInfoList.get(i);
+                RoomBed roomBed = BeanUtil.toBean(roomBedVo, RoomBed.class);
+                roomBed.setStudentUserId(studentInfoVo.getUserId());
+                roomBed.setModifyDate(modifyDate);
+                roomBed.setModifyUserId(modifyUserId);
+                roomBedMapper.updateById(roomBed);
+                i ++;
+            }
+        }
+
+        //查询每个寝室住入的班级数量,大于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;
+    }
 }

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

@@ -0,0 +1,27 @@
+package com.xjrsoft.module.room.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+* @title: 寝室表单出参
+* @Author dzx
+* @Date: 2023-12-27
+* @Version 1.0
+*/
+@Data
+public class RoomClassCountVo {
+
+    /**
+    * 主键编号
+    */
+    @ApiModelProperty("主键编号")
+    private Long id;
+    /**
+    * 序号
+    */
+    @ApiModelProperty("班级数量")
+    private Integer classCount;
+
+
+}

+ 19 - 0
src/main/java/com/xjrsoft/module/student/dto/DistributeStudentDto.java

@@ -0,0 +1,19 @@
+package com.xjrsoft.module.student.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class DistributeStudentDto {
+    /**
+     * 用户ID(xjr_user)
+     */
+    @ApiModelProperty("班级id")
+    private Long classId;
+    /**
+     * 学号
+     */
+    @ApiModelProperty("性别")
+    private Integer gender;
+
+}

+ 4 - 0
src/main/java/com/xjrsoft/module/student/mapper/BaseStudentMapper.java

@@ -1,10 +1,13 @@
 package com.xjrsoft.module.student.mapper;
 
 import com.github.yulichang.base.MPJBaseMapper;
+import com.xjrsoft.module.student.dto.DistributeStudentDto;
 import com.xjrsoft.module.student.entity.BaseStudent;
 import com.xjrsoft.module.student.vo.StudentInfoVo;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
  * @title: mapper
  * @Author 管理员
@@ -18,4 +21,5 @@ public interface BaseStudentMapper extends MPJBaseMapper<BaseStudent> {
      * @return
      */
     StudentInfoVo getStudentInfo(Long userId);
+    List<StudentInfoVo> getClassStudent(DistributeStudentDto dto);
 }

+ 12 - 2
src/main/resources/mapper/room/RoomBedMapper.xml

@@ -50,7 +50,7 @@
         LEFT JOIN base_student_school_roll c2 ON c1.user_id = c2.user_id
         LEFT JOIN xjr_dictionary_detail c3 ON c2.stduy_status = c3.code AND c3.item_id = 2023000000000000030
         WHERE c1.delete_mark = 0 AND c2.delete_mark = 0
-        AND c3.code = 'FB3002' AND c2.class_id = t1.id) AS need_count,(
+        AND c3.code = 'FB3001' AND c2.class_id = t1.id) AS need_count,(
         SELECT COUNT(*) FROM room_bed a1
         LEFT JOIN base_student_school_roll a2 ON a1.student_user_id = a2.user_id
         WHERE a1.delete_mark = 0 AND a2.delete_mark = 0
@@ -64,7 +64,7 @@
         LEFT JOIN base_student_school_roll c2 ON c1.user_id = c2.user_id
         LEFT JOIN xjr_dictionary_detail c3 ON c2.stduy_status = c3.code AND c3.item_id = 2023000000000000030
         WHERE c1.delete_mark = 0 AND c2.delete_mark = 0
-        AND c3.code = 'FB3002' AND c2.class_id = t1.id
+        AND c3.code = 'FB3001' AND c2.class_id = t1.id
         ) !=
         (
         SELECT COUNT(*) FROM room_bed a1
@@ -98,4 +98,14 @@
             ) != t1.bed_count
         ORDER BY t1.sort_code
     </select>
+
+    <select id="getBedInfo" resultType="com.xjrsoft.module.room.vo.RoomBedVo">
+        SELECT t1.* FROM room_bed t1
+        LEFT JOIN room t2 ON t1.room_id = t2.id
+        WHERE t1.delete_mark = 0 AND t1.room_id IN
+        <foreach item="roomId" index="index" collection="ids" open="(" close=")" separator=",">
+            #{roomId}
+        </foreach>
+        ORDER BY t2.sort_code,t1.sort_code
+    </select>
 </mapper>

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

@@ -32,4 +32,19 @@
     <select id="getMaxSortCode" resultType="java.lang.Integer">
         SELECT IFNULL(MAX(sort_code),1) FROM room WHERE delete_mark = 0
     </select>
+
+    <select id="getRoomClassCount" resultType="com.xjrsoft.module.room.vo.RoomClassCountVo">
+        SELECT id,(
+        SELECT COUNT(*) FROM (
+        SELECT COUNT(*) FROM base_class t1
+        LEFT JOIN base_student_school_roll t2 ON t2.class_id = t1.id
+        LEFT JOIN room_bed t3 ON t2.user_id = t3.student_user_id
+        WHERE t3.room_id = room.id GROUP BY t1.id
+        ) class_data
+        ) AS class_count FROM room
+        where id in
+        <foreach item="roomId" index="index" collection="ids" open="(" close=")" separator=",">
+            #{roomId}
+        </foreach>
+    </select>
 </mapper>

+ 11 - 0
src/main/resources/mapper/student/BaseStudentMapper.xml

@@ -12,4 +12,15 @@
         LEFT JOIN base_major_set t6 ON t3.major_set_id = t6.id
         where  t1.delete_mark=0 and t2.delete_mark=0 and t1.user_id=#{userId};
     </select>
+
+    <select id="getClassStudent" parameterType="com.xjrsoft.module.student.dto.DistributeStudentDto" resultType="com.xjrsoft.module.student.vo.StudentInfoVo">
+        SELECT t1.user_id,t5.id as grade_id,t5.name AS grade_name,t4.id as class_id,t4.name AS class_name,t2.name AS student_name,t1.student_id,t2.gender,t3.enrollment_type,t6.id as major_id,t6.name AS major_name FROM base_student t1
+        INNER JOIN xjr_user t2 ON t1.user_id = t2.id
+        LEFT JOIN base_student_school_roll t3 ON t1.user_id = t3.user_id
+        LEFT JOIN base_class t4 ON t3.class_id = t4.id
+        LEFT JOIN base_grade t5 ON t3.grade_id = t5.id
+        LEFT JOIN base_major_set t6 ON t3.major_set_id = t6.id
+        where  t1.delete_mark=0 and t2.delete_mark=0 and t4.id = #{dto.classId}
+        AND t3.stduy_status = 'FB3001' AND t4.gender = #{dto.gender}
+    </select>
 </mapper>