|
|
@@ -14,12 +14,22 @@ import org.dromara.xg.domain.bo.XgDormBedBo;
|
|
|
import org.dromara.xg.domain.vo.XgDormBedVo;
|
|
|
import org.dromara.xg.domain.vo.XgDormBedDetailVo;
|
|
|
import org.dromara.xg.domain.XgDormBed;
|
|
|
+import org.dromara.xg.domain.XgDormRoom;
|
|
|
+import org.dromara.xg.domain.XgDormBedStudent;
|
|
|
+import org.dromara.xg.domain.XgSysDept;
|
|
|
import org.dromara.xg.mapper.XgDormBedMapper;
|
|
|
+import org.dromara.xg.mapper.XgDormRoomMapper;
|
|
|
+import org.dromara.xg.mapper.XgDormBedStudentMapper;
|
|
|
+import org.dromara.xg.mapper.XgSysDeptMapper;
|
|
|
import org.dromara.xg.service.IXgDormBedService;
|
|
|
+import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
|
/**
|
|
|
* 宿舍床位信息Service业务层处理
|
|
|
@@ -33,6 +43,9 @@ import java.util.Collection;
|
|
|
public class XgDormBedServiceImpl implements IXgDormBedService {
|
|
|
|
|
|
private final XgDormBedMapper baseMapper;
|
|
|
+ private final XgDormRoomMapper xgDormRoomMapper;
|
|
|
+ private final XgDormBedStudentMapper xgDormBedStudentMapper;
|
|
|
+ private final XgSysDeptMapper xgSysDeptMapper;
|
|
|
|
|
|
/**
|
|
|
* 查询宿舍床位信息
|
|
|
@@ -41,7 +54,7 @@ public class XgDormBedServiceImpl implements IXgDormBedService {
|
|
|
* @return 宿舍床位信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public XgDormBedVo queryById(Long id){
|
|
|
+ public XgDormBedVo queryById(Long id) {
|
|
|
return baseMapper.selectVoById(id);
|
|
|
}
|
|
|
|
|
|
@@ -117,8 +130,8 @@ public class XgDormBedServiceImpl implements IXgDormBedService {
|
|
|
/**
|
|
|
* 保存前的数据校验
|
|
|
*/
|
|
|
- private void validEntityBeforeSave(XgDormBed entity){
|
|
|
- //TODO 做一些数据校验,如唯一约束
|
|
|
+ private void validEntityBeforeSave(XgDormBed entity) {
|
|
|
+ // TODO 做一些数据校验,如唯一约束
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -130,8 +143,8 @@ public class XgDormBedServiceImpl implements IXgDormBedService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
- if(isValid){
|
|
|
- //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ if (isValid) {
|
|
|
+ // TODO 做一些业务上的校验,判断是否需要校验
|
|
|
}
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
|
}
|
|
|
@@ -147,6 +160,26 @@ public class XgDormBedServiceImpl implements IXgDormBedService {
|
|
|
return baseMapper.selectBedDetailsByRoomId(roomId);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询当前用户所在学院的指定房间床位详细信息列表(包含学生信息)
|
|
|
+ *
|
|
|
+ * @param roomId 房间ID
|
|
|
+ * @return 床位详细信息列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<XgDormBedDetailVo> queryBedDetailsByRoomIdForCurrentUserCollege(Long roomId) {
|
|
|
+ // 1. 获取当前用户的学院ID
|
|
|
+ Long currentUserCollegeId = getCurrentUserCollegeId();
|
|
|
+ if (currentUserCollegeId == null) {
|
|
|
+ log.warn("无法获取当前用户的学院信息,返回空结果");
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 直接查询指定房间中属于当前学院的床位详细信息
|
|
|
+ // 通过SQL关联xg_dorm_bed_student表,只返回分配给当前学院的床位
|
|
|
+ return baseMapper.selectBedDetailsByRoomIdAndCollegeId(roomId, currentUserCollegeId);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询指定宿舍楼的床位详细信息列表(包含学生信息)
|
|
|
*
|
|
|
@@ -157,4 +190,105 @@ public class XgDormBedServiceImpl implements IXgDormBedService {
|
|
|
public List<XgDormBedDetailVo> queryBedDetailsByBuildingId(Long buildingId) {
|
|
|
return baseMapper.selectBedDetailsByBuildingId(buildingId);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前用户的二级学院ID
|
|
|
+ * 通过当前用户的部门id,向上寻找包括他自己,找到dept_category前几位是xy-的就是二级学院
|
|
|
+ * 或者parent_id = 101的部门就是二级学院
|
|
|
+ */
|
|
|
+ private Long getCurrentUserCollegeId() {
|
|
|
+ try {
|
|
|
+ Long currentUserId = LoginHelper.getUserId();
|
|
|
+ Long currentDeptId = LoginHelper.getDeptId();
|
|
|
+
|
|
|
+ if (currentUserId == null || currentDeptId == null) {
|
|
|
+ log.warn("用户未登录或没有部门信息");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 首先查找parent_id = 101的部门(使用LambdaQueryWrapper)
|
|
|
+ LambdaQueryWrapper<XgSysDept> parentQuery = Wrappers.lambdaQuery();
|
|
|
+ parentQuery.eq(XgSysDept::getParentId, 101L)
|
|
|
+ .eq(XgSysDept::getStatus, "0")
|
|
|
+ .eq(XgSysDept::getDelFlag, "0")
|
|
|
+ .and(wrapper -> wrapper.eq(XgSysDept::getDeptId, currentDeptId)
|
|
|
+ .or().like(XgSysDept::getAncestors, "," + currentDeptId + ",") // 中间位置
|
|
|
+ .or().likeRight(XgSysDept::getAncestors, currentDeptId + ",") // 开头位置
|
|
|
+ .or().likeLeft(XgSysDept::getAncestors, "," + currentDeptId) // 末尾位置
|
|
|
+ .or().eq(XgSysDept::getAncestors, currentDeptId.toString())) // 单独一个值
|
|
|
+ .last("LIMIT 1");
|
|
|
+
|
|
|
+ List<XgSysDept> parentColleges = xgSysDeptMapper.selectList(parentQuery);
|
|
|
+ if (!parentColleges.isEmpty()) {
|
|
|
+ return parentColleges.get(0).getDeptId();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果上面的查询没找到,尝试通过dept_category查找
|
|
|
+ LambdaQueryWrapper<XgSysDept> categoryQuery = Wrappers.lambdaQuery();
|
|
|
+ categoryQuery.likeRight(XgSysDept::getDeptCategory, "xy-")
|
|
|
+ .eq(XgSysDept::getStatus, "0")
|
|
|
+ .eq(XgSysDept::getDelFlag, "0")
|
|
|
+ .and(wrapper -> wrapper.eq(XgSysDept::getDeptId, currentDeptId)
|
|
|
+ .or().like(XgSysDept::getAncestors, "," + currentDeptId + ",") // 中间位置
|
|
|
+ .or().likeRight(XgSysDept::getAncestors, currentDeptId + ",") // 开头位置
|
|
|
+ .or().likeLeft(XgSysDept::getAncestors, "," + currentDeptId) // 末尾位置
|
|
|
+ .or().eq(XgSysDept::getAncestors, currentDeptId.toString())) // 单独一个值
|
|
|
+ .last("LIMIT 1");
|
|
|
+
|
|
|
+ List<XgSysDept> categoryColleges = xgSysDeptMapper.selectList(categoryQuery);
|
|
|
+ return categoryColleges.isEmpty() ? null : categoryColleges.get(0).getDeptId();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取当前用户二级学院ID失败", e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取分配给指定学院的房间ID列表
|
|
|
+ */
|
|
|
+ private Set<Long> getCollegeAllocatedRoomIds(Long collegeId) {
|
|
|
+ try {
|
|
|
+ LambdaQueryWrapper<XgDormBedStudent> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.select(XgDormBedStudent::getRoomId)
|
|
|
+ .eq(XgDormBedStudent::getCollegeId, collegeId)
|
|
|
+ .eq(XgDormBedStudent::getStatus, "0")
|
|
|
+ .eq(XgDormBedStudent::getDeleted, "0")
|
|
|
+ .isNotNull(XgDormBedStudent::getRoomId)
|
|
|
+ .groupBy(XgDormBedStudent::getRoomId);
|
|
|
+
|
|
|
+ List<XgDormBedStudent> roomRecords = xgDormBedStudentMapper.selectList(queryWrapper);
|
|
|
+ return roomRecords.stream()
|
|
|
+ .map(XgDormBedStudent::getRoomId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取学院 {} 分配的房间ID列表失败", collegeId, e);
|
|
|
+ return Set.of();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取分配给指定学院的宿舍楼ID列表
|
|
|
+ */
|
|
|
+ private Set<Long> getCollegeAllocatedBuildingIds(Long collegeId) {
|
|
|
+ try {
|
|
|
+ LambdaQueryWrapper<XgDormBedStudent> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.select(XgDormBedStudent::getBuildingId)
|
|
|
+ .eq(XgDormBedStudent::getCollegeId, collegeId)
|
|
|
+ .eq(XgDormBedStudent::getStatus, "0")
|
|
|
+ .eq(XgDormBedStudent::getDeleted, "0")
|
|
|
+ .isNotNull(XgDormBedStudent::getBuildingId)
|
|
|
+ .groupBy(XgDormBedStudent::getBuildingId);
|
|
|
+
|
|
|
+ List<XgDormBedStudent> buildingRecords = xgDormBedStudentMapper.selectList(queryWrapper);
|
|
|
+ return buildingRecords.stream()
|
|
|
+ .map(XgDormBedStudent::getBuildingId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取学院 {} 分配的宿舍楼ID列表失败", collegeId, e);
|
|
|
+ return Set.of();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|