Pārlūkot izejas kodu

更新用户头像,加入房间

wuweihao 3 gadi atpakaļ
vecāks
revīzija
8a8c69c2d1

+ 0 - 9
gis_cms/src/main/java/com/gis/cms/controller/RoomController.java

@@ -45,21 +45,12 @@ public class RoomController {
     }
 
 
-
-
     @ApiOperation("详情")
     @GetMapping("/detail/{id}")
     public Result detail(@PathVariable Long id) {
         return entityService.detail(id);
     }
 
-//    @WebControllerLog(description = "房间管理-加入房间", addDb = true)
-//    @ApiOperation(value = "加入房间", notes = "使用房间创建者id, 这里不一定知道房间号")
-//    @GetMapping("/join/{code}/{creatorId}")
-//    public Result join(@PathVariable String code, @PathVariable Long creatorId) {
-//        return entityService.join(code, creatorId);
-//    }
-
 
     @WebControllerLog(description = "房间管理-加入房间", addDb = true)
     @ApiOperation(value = "加入房间", notes = "code口令当验证码使用")

+ 1 - 1
gis_cms/src/main/java/com/gis/cms/mapper/RoomMapper.java

@@ -30,7 +30,7 @@ public interface RoomMapper extends BaseMapper<RoomEntity> {
     @SelectProvider(type = BaseProvider.class, method = "selectSql")
     List<WxUserVo> selectWxUserVo(String toString);
 
-    @Select("SELECT  * FROM tb_room where is_delete=0 and code=#{code} and creator_id=#{creatorId} limit 1")
+    @Select("SELECT  * FROM tb_room where is_delete=0 and status=0 and code=#{code} and creator_id=#{creatorId} limit 1")
     RoomEntity findByCode(String code, Long creatorId);
 
     @Select("SELECT id FROM tb_room where is_delete=0 and name=#{name} limit 1")

+ 23 - 38
gis_cms/src/main/java/com/gis/cms/service/impl/RoomServiceImpl.java

@@ -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<>();