RoomBedServiceImpl.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package com.xjrsoft.module.room.service.impl;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import cn.hutool.core.bean.BeanUtil;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.github.yulichang.base.MPJBaseServiceImpl;
  6. import com.xjrsoft.module.room.dto.DistributeClassPageDto;
  7. import com.xjrsoft.module.room.dto.DistributeRoomBedDto;
  8. import com.xjrsoft.module.room.dto.DistributeRoomBedPageDto;
  9. import com.xjrsoft.module.room.dto.RoomBedPageDto;
  10. import com.xjrsoft.module.room.entity.Room;
  11. import com.xjrsoft.module.room.entity.RoomBed;
  12. import com.xjrsoft.module.room.mapper.RoomBedMapper;
  13. import com.xjrsoft.module.room.mapper.RoomMapper;
  14. import com.xjrsoft.module.room.service.IRoomBedService;
  15. import com.xjrsoft.module.room.vo.DistributeClassPageVo;
  16. import com.xjrsoft.module.room.vo.DistributeRoomBedPageVo;
  17. import com.xjrsoft.module.room.vo.RoomBedPageVo;
  18. import com.xjrsoft.module.room.vo.RoomBedVo;
  19. import com.xjrsoft.module.room.vo.RoomClassCountVo;
  20. import com.xjrsoft.module.student.dto.DistributeStudentDto;
  21. import com.xjrsoft.module.student.mapper.BaseStudentMapper;
  22. import com.xjrsoft.module.student.vo.StudentInfoVo;
  23. import lombok.AllArgsConstructor;
  24. import org.springframework.stereotype.Service;
  25. import java.util.Date;
  26. import java.util.List;
  27. /**
  28. * @title: 寝室床位
  29. * @Author dzx
  30. * @Date: 2023-12-27
  31. * @Version 1.0
  32. */
  33. @Service
  34. @AllArgsConstructor
  35. public class RoomBedServiceImpl extends MPJBaseServiceImpl<RoomBedMapper, RoomBed> implements IRoomBedService {
  36. private final RoomMapper roomMapper;
  37. private final RoomBedMapper roomBedMapper;
  38. private final BaseStudentMapper baseStudentMapper;
  39. @Override
  40. public Page<RoomBedPageVo> getPage(Page<RoomBedPageVo> page, RoomBedPageDto dto) {
  41. Page<RoomBedPageVo> result = roomBedMapper.getPage(page, dto);
  42. return result;
  43. }
  44. @Override
  45. public Boolean clearStudentInfo(List<Long> ids) {
  46. for (Long id : ids) {
  47. RoomBed roomBed = roomBedMapper.selectById(id);
  48. roomBed.setStudentUserId(null);
  49. roomBedMapper.updateById(roomBed);
  50. }
  51. return true;
  52. }
  53. @Override
  54. public Page<DistributeClassPageVo> getDistributeClassInfo(Page<DistributeClassPageVo> page, DistributeClassPageDto dto) {
  55. return roomBedMapper.getDistributeClassInfo(page, dto);
  56. }
  57. @Override
  58. public Page<DistributeRoomBedPageVo> getDistributeRoomBedInfo(Page<DistributeRoomBedPageVo> page, DistributeRoomBedPageDto dto) {
  59. return roomBedMapper.getDistributeRoomBedInfo(page, dto);
  60. }
  61. @Override
  62. public Boolean distributeRoomBed(DistributeRoomBedDto dto) {
  63. //查询出所有床位信息
  64. List<RoomBedVo> bedInfoList = roomBedMapper.getBedInfo(dto.getRoomIds());
  65. Room room = roomMapper.selectById(dto.getRoomIds().get(0));
  66. String gender = room.getGender();
  67. Integer genderNumber = null;
  68. if("SB10001".equals(gender)){
  69. genderNumber = 1;
  70. }else if("SB10002".equals(gender)){
  71. genderNumber = 2;
  72. }
  73. Date modifyDate = new Date();
  74. Long modifyUserId = StpUtil.getLoginIdAsLong();
  75. //查询每个班的学生,修改床位信息
  76. int i = 0;
  77. for (Long classId : dto.getClassIds()) {
  78. DistributeStudentDto classDto = new DistributeStudentDto();
  79. classDto.setClassId(classId);
  80. classDto.setGender(genderNumber);
  81. List<StudentInfoVo> studentList = baseStudentMapper.getClassStudent(classDto);
  82. for (StudentInfoVo studentInfoVo : studentList) {
  83. if(i > bedInfoList.size()){
  84. continue;
  85. }
  86. RoomBedVo roomBedVo = bedInfoList.get(i);
  87. RoomBed roomBed = BeanUtil.toBean(roomBedVo, RoomBed.class);
  88. roomBed.setStudentUserId(studentInfoVo.getUserId());
  89. roomBed.setModifyDate(modifyDate);
  90. roomBed.setModifyUserId(modifyUserId);
  91. roomBedMapper.updateById(roomBed);
  92. i ++;
  93. }
  94. }
  95. //查询每个寝室住入的班级数量,大于2的设置为混合寝室
  96. List<RoomClassCountVo> classCountVoList = roomMapper.getRoomClassCount(dto.getRoomIds());
  97. for (RoomClassCountVo roomClassCountVo : classCountVoList) {
  98. if(roomClassCountVo.getClassCount() > 1){
  99. Room updRoom = roomMapper.selectById(roomClassCountVo.getId());
  100. updRoom.setIsMax(1);
  101. roomMapper.updateById(updRoom);
  102. }
  103. }
  104. return true;
  105. }
  106. }