123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- 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;
- /**
- * @title: 寝室床位
- * @Author dzx
- * @Date: 2023-12-27
- * @Version 1.0
- */
- @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);
- return result;
- }
- @Override
- public Boolean clearStudentInfo(List<Long> ids) {
- for (Long id : ids) {
- RoomBed roomBed = roomBedMapper.selectById(id);
- roomBed.setStudentUserId(null);
- roomBedMapper.updateById(roomBed);
- }
- return true;
- }
- @Override
- public Page<DistributeClassPageVo> getDistributeClassInfo(Page<DistributeClassPageVo> page, DistributeClassPageDto dto) {
- return roomBedMapper.getDistributeClassInfo(page, dto);
- }
- @Override
- 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) {
- if(i > bedInfoList.size()){
- continue;
- }
- 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;
- }
- }
|