package com.xjrsoft.module.room.service.impl; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.yulichang.base.MPJBaseServiceImpl; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.xjrsoft.common.page.ConventPage; import com.xjrsoft.common.utils.VoToColumnUtil; import com.xjrsoft.module.room.dto.RoomStudentAppointPageDto; import com.xjrsoft.module.room.entity.RoomBed; import com.xjrsoft.module.room.entity.RoomStudentAppoint; import com.xjrsoft.module.room.mapper.RoomBedMapper; import com.xjrsoft.module.room.mapper.RoomStudentAppointMapper; import com.xjrsoft.module.room.service.IRoomStudentAppointService; import com.xjrsoft.module.room.vo.AppointPageRoomBedVo; import com.xjrsoft.module.room.vo.HeadTeaRoomCadreAppointPageVo; import com.xjrsoft.module.room.vo.RoomStudentAppointVo; import com.xjrsoft.module.student.entity.BaseStudentPost; import com.xjrsoft.module.teacher.entity.XjrUser; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; /** * @title: 寝室长任命 * @Author dzx * @Date: 2023-12-30 * @Version 1.0 */ @Service @AllArgsConstructor public class RoomStudentAppointServiceImpl extends MPJBaseServiceImpl implements IRoomStudentAppointService { private final RoomStudentAppointMapper roomStudentAppointMapper; private final RoomBedMapper roomBedMapper; @Override public IPage getPage(RoomStudentAppointPageDto dto) { dto.setTeacherId(StpUtil.getLoginIdAsLong()); IPage headTeaRoomCadreAppointPageVoIPage = roomStudentAppointMapper.getPage(ConventPage.getPage(dto), dto); //找到每个寝室的每个床位的人 for (HeadTeaRoomCadreAppointPageVo headTeaRoomCadreAppointPageVo : headTeaRoomCadreAppointPageVoIPage.getRecords()) { List appointPageRoomBedVoList = this.getStuByRoomId(Long.parseLong(headTeaRoomCadreAppointPageVo.getRoomId())); if (ObjectUtil.isNotNull(appointPageRoomBedVoList) && appointPageRoomBedVoList.size() > 0){ //找到每个人的职位 for (AppointPageRoomBedVo appointPageRoomBedVo : appointPageRoomBedVoList) { MPJLambdaWrapper queryPost = new MPJLambdaWrapper<>(); queryPost .selectAs(BaseStudentPost::getPost, RoomStudentAppointVo::getPostIdCN) .select(RoomStudentAppoint.class, x -> VoToColumnUtil.fieldsToColumns(RoomStudentAppointVo.class).contains(x.getProperty())) .leftJoin(BaseStudentPost.class,BaseStudentPost::getId,RoomStudentAppoint::getPostId) .eq(RoomStudentAppoint::getRoomId,appointPageRoomBedVo.getRoomId()) .eq(RoomStudentAppoint::getRoomBedId,appointPageRoomBedVo.getRoomBedId()) .eq(RoomStudentAppoint::getStudentUserId,appointPageRoomBedVo.getStudentUserId()); List roomStudentAppointList = this.selectJoinList(RoomStudentAppointVo.class,queryPost); if (ObjectUtil.isNotNull(roomStudentAppointList) && roomStudentAppointList.size() > 0){ List postList = new ArrayList<>(); for (RoomStudentAppointVo roomStudentAppointVo : roomStudentAppointList) { postList.add(roomStudentAppointVo.getPostIdCN()); } appointPageRoomBedVo.setPostList(postList); } } headTeaRoomCadreAppointPageVo.setRoomBedList(appointPageRoomBedVoList); } } return headTeaRoomCadreAppointPageVoIPage; } @Override public List getStuByRoomId(RoomStudentAppointPageDto dto) { return this.getStuByRoomId(dto.getRoomId()); } private List getStuByRoomId(Long roomId) { MPJLambdaWrapper queryRoomBed = new MPJLambdaWrapper<>(); queryRoomBed .selectAs(RoomBed::getId,AppointPageRoomBedVo::getRoomBedId) .selectAs(XjrUser::getName, AppointPageRoomBedVo::getStudentUserIdCN) .select(RoomBed.class, x -> VoToColumnUtil.fieldsToColumns(AppointPageRoomBedVo.class).contains(x.getProperty())) .leftJoin(XjrUser.class,XjrUser::getId,RoomBed::getStudentUserId) .eq(RoomBed::getRoomId,roomId) .eq(RoomBed::getIsCheckIn,1); List appointPageRoomBedVoList = roomBedMapper.selectJoinList(AppointPageRoomBedVo.class,queryRoomBed); return appointPageRoomBedVoList; } }