|
@@ -32,10 +32,7 @@ import org.springframework.stereotype.Service;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -79,7 +76,7 @@ public class RoomServiceImpl extends ServiceImpl<RoomMapper, RoomEntity> impleme
|
|
|
Long userId = iBaseService.getUserId();
|
|
|
entity.setCreatorId(userId);
|
|
|
|
|
|
- //检查房间号唯一性, 允许为空
|
|
|
+ //检查房间号唯一性, 允许为空: 同一用户、进行中的房间,口令唯一
|
|
|
String code = param.getCode();
|
|
|
if (StringUtils.isNotBlank(code)){
|
|
|
RoomEntity room = baseMapper.findByCode(param.getCode(), userId);
|
|
@@ -87,41 +84,15 @@ public class RoomServiceImpl extends ServiceImpl<RoomMapper, RoomEntity> impleme
|
|
|
}
|
|
|
|
|
|
this.save(entity);
|
|
|
+
|
|
|
+ // 2022-6-22 将新建者加入房间
|
|
|
+ this.join(null, entity.getId());
|
|
|
+
|
|
|
return Result.success(entity);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-// @Override
|
|
|
-// public Result join(String code, Long creatorId) {
|
|
|
-// RoomEntity roomEntity = baseMapper.findByCode(code, creatorId);
|
|
|
-// if (roomEntity==null){
|
|
|
-// log.error("该房间号不存在: {}", code);
|
|
|
-// return Result.failure("该房间不存在: " + code );
|
|
|
-// }
|
|
|
-//
|
|
|
-// LocalDateTime endTime = roomEntity.getEndTime();
|
|
|
-// BaseRuntimeException.isTrue(endTime.isBefore(LocalDateTime.now()) , null, "活动已结束");
|
|
|
-//
|
|
|
-// Long roomId = roomEntity.getId();
|
|
|
-// Long userId = iBaseService.getUserId();
|
|
|
-// String type = "activity";
|
|
|
-// // 加入房间记录
|
|
|
-// GameLogEntity entity = gameLogService.findByRoomIdAndUserId(roomId, userId, type);
|
|
|
-// if (entity == null){
|
|
|
-// log.info("需要创建该房间的游戏记录");
|
|
|
-// // 用户加入房间
|
|
|
-// entity = new GameLogEntity();
|
|
|
-// entity.setCreatorId(userId);
|
|
|
-// entity.setType(type);
|
|
|
-// entity.setScore(0);
|
|
|
-// entity.setRoomId(roomId);
|
|
|
-// gameLogService.save(entity);
|
|
|
-// }
|
|
|
-//
|
|
|
-// return Result.success(entity);
|
|
|
-// }
|
|
|
-
|
|
|
@Override
|
|
|
public Result join(String code, Long roomId) {
|
|
|
|
|
@@ -164,7 +135,7 @@ public class RoomServiceImpl extends ServiceImpl<RoomMapper, RoomEntity> impleme
|
|
|
// 获取用户房间列表
|
|
|
List<RoomEntity> rooms = countByCreatorIdAndDate(param);
|
|
|
// 获取房间用户头像
|
|
|
- handleAvatarUrlByRoom(rooms);
|
|
|
+ doAvatarUrlByRoom(rooms);
|
|
|
|
|
|
return Result.success(rooms);
|
|
|
}
|
|
@@ -174,7 +145,7 @@ public class RoomServiceImpl extends ServiceImpl<RoomMapper, RoomEntity> impleme
|
|
|
* @param rooms
|
|
|
* @return
|
|
|
*/
|
|
|
- private void handleAvatarUrlByRoom(List<RoomEntity> rooms) {
|
|
|
+ private void doAvatarUrlByRoom(List<RoomEntity> rooms) {
|
|
|
// 房间ids
|
|
|
log.info("准备封装用户头像");
|
|
|
List<Long> collect = rooms.stream().map(RoomEntity::getId).collect(Collectors.toList());
|
|
@@ -204,7 +175,7 @@ public class RoomServiceImpl extends ServiceImpl<RoomMapper, RoomEntity> impleme
|
|
|
}
|
|
|
|
|
|
/***
|
|
|
- * 获取该房间的用户头像
|
|
|
+ * 批量获取该房间的用户头像
|
|
|
* @param roomIds
|
|
|
* @return
|
|
|
*/
|
|
@@ -220,10 +191,24 @@ public class RoomServiceImpl extends ServiceImpl<RoomMapper, RoomEntity> impleme
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 2022-06-22
|
|
|
+ * 根据房间id获取用户头像
|
|
|
+ * @param roomId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<String> getAvatarUrlByRoomId(Long roomId){
|
|
|
+ List<RoomVo> list = getAvatarUrlByRoomId(Collections.singletonList(roomId));
|
|
|
+ return list.stream().map(RoomVo::getAvatarUrl).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Result detail(Long id) {
|
|
|
// 房间总分
|
|
|
RoomEntity roomEntity = countTotalByRoomId(id);
|
|
|
+ // 2022-06-22 获取房间头像
|
|
|
+ roomEntity.setAvatarUrls(getAvatarUrlByRoomId(id));
|
|
|
+
|
|
|
// 房间用户排名
|
|
|
List<WxUserVo> users = ranking(id);
|
|
|
HashMap<Object, Object> result = new HashMap<>();
|