String username = adjustRoom.getUsername(); //当前房间号 int currentRoomId = adjustRoom.getCurrentRoomId(); //当前床位名称 String currentBedName = JudgeBedName.getBedName(adjustRoom.getCurrentBedId()); //目标房间号 int towardsRoomId = adjustRoom.getTowardsRoomId(); //目标目标房间号 String towardsBedName = JudgeBedName.getBedName(adjustRoom.getTowardsBedId()); QueryWrapper qw = new QueryWrapper(); qw.eq("dormroom_id", currentRoomId); qw.isNotNull(currentBedName); DormRoom dormRoom1 = dormRoomMapper.selectOne(qw); if (dormRoom1 == null) { return -2; } int currentCapacity1 = calNum(dormRoom1); UpdateWrapper uw1 = new UpdateWrapper(); uw1.eq("dormroom_id", currentRoomId); uw1.set(currentBedName, null); uw1.set("current_capacity", currentCapacity1 - 1); int result1 = dormRoomMapper.update(null, uw1); DormRoom dormRoom2 = dormRoomMapper.selectById(towardsRoomId); int currentCapacity2 = calNum(dormRoom2); if (result1 == 1) { UpdateWrapper uw2 = new UpdateWrapper(); uw2.eq("dormroom_id", towardsRoomId); uw2.set(towardsBedName, username); uw2.set("current_capacity", currentCapacity2 + 1); int result2 = dormRoomMapper.update(null, uw2); return result2; } return -1; }
时间: 2024-02-14 12:35:35 浏览: 18
这段代码实现的功能是调整宿舍房间床位,将当前房间中的一个床位调整到目标房间的一个床位上。具体实现过程如下:
1. 获取调整信息中的当前房间号、当前床位名称、目标房间号、目标床位名称和用户名。
2. 根据当前房间号和当前床位名称在数据库中查询当前房间的记录,并判断当前床位是否为空床位。如果为空床位,则返回错误码-2。
3. 计算当前房间的当前容量,即除去当前床位后该房间剩余的床位数量。
4. 使用UpdateWrapper更新当前房间记录,将当前床位设置为空床位,同时将当前容量减1。
5. 根据目标房间号在数据库中查询目标房间的记录,并计算目标房间的当前容量。
6. 如果更新当前房间记录成功,则使用UpdateWrapper更新目标房间记录,将目标床位设置为当前用户名,同时将目标房间的当前容量加1。
7. 如果更新目标房间记录成功,则返回更新结果,否则返回错误码-1。
该段代码中使用了MyBatis-Plus的QueryWrapper和UpdateWrapper实现了数据库的查询和更新操作。同时,也使用了自定义的JudgeBedName类和calNum方法实现了一些辅助计算。
相关问题
public int adjustRoomUpdate(AdjustRoom adjustRoom) { String username = adjustRoom.getUsername(); int towardsRoomId = adjustRoom.getTowardsRoomId(); String towardsBedName = JudgeBedName.getBedName(adjustRoom.getTowardsBedId()); DormRoom dormRoom2 = dormRoomMapper.selectById(towardsRoomId); int currentCapacity2 = calNum(dormRoom2); UpdateWrapper uw2 = new UpdateWrapper(); uw2.eq("dormroom_id", towardsRoomId); uw2.set(towardsBedName, username); uw2.set("current_capacity", currentCapacity2 + 1); int result2 = dormRoomMapper.update(null, uw2); return result2; }
这是一个 Java 方法,它的作用是对宿舍房间的床位进行调整,并将调整结果更新到数据库中。具体实现过程如下:
1. 从参数 `adjustRoom` 中获取用户名和目标房间的 ID 和床位 ID。
2. 根据目标房间的 ID 从数据库中查询该房间的信息,并计算当前房间的使用情况。
3. 创建一个 UpdateWrapper 对象,用于更新数据库中的宿舍房间信息。
4. 设置 UpdateWrapper 的查询条件为目标房间的 ID,将目标床位对应的字段设置为当前用户的用户名。
5. 将该房间的当前使用情况设置为原来的使用情况加上 1。
6. 调用 dormRoomMapper 的 update 方法,将更新后的信息保存到数据库中,并返回更新结果。
该方法实现了对宿舍房间床位的调整,并将调整结果保存到数据库中。
解释下面这段代码:Map<String, Object> map = new HashMap<>(); if (courseId != null) { EasUser easUser = (EasUser) SecurityUtils.getSubject().getPrincipal();//获取EasUser对象 String username = easUser.getUsername(); EasStudent
很抱歉,作为AI语言模型,我不能确切地知道您的代码执行情况以及涉及到的上下文。但是,这段代码看起来是在创建一个HashMap并且如果courseId不为空,则从Subject中获取当前用户(EasUser对象),然后把用户名存储到EasStudent对象中。由于缺少上下文信息,我无法确定这段代码确切的目的和作用。