|
@@ -0,0 +1,168 @@
|
|
|
+package com.zanxiang.manage.service.Impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.zanxiang.common.utils.StringUtils;
|
|
|
+import com.zanxiang.common.utils.bean.BeanUtils;
|
|
|
+import com.zanxiang.manage.domain.dto.GameDTO;
|
|
|
+import com.zanxiang.manage.domain.dto.UserDTO;
|
|
|
+import com.zanxiang.manage.domain.dto.UserExtDTO;
|
|
|
+import com.zanxiang.manage.domain.params.GameUserRoleListParam;
|
|
|
+import com.zanxiang.manage.domain.vo.GameUserRoleListVO;
|
|
|
+import com.zanxiang.manage.service.GameService;
|
|
|
+import com.zanxiang.manage.service.GameUserRoleService;
|
|
|
+import com.zanxiang.manage.service.UserExtService;
|
|
|
+import com.zanxiang.manage.service.UserService;
|
|
|
+import com.zanxiang.mybatis.entity.GameUserRole;
|
|
|
+import com.zanxiang.mybatis.mapper.GameUserRoleMapper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.logging.log4j.util.Strings;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author : lingfeng
|
|
|
+ * @time : 2022-07-01
|
|
|
+ * @description : 玩家角色
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, GameUserRole> implements GameUserRoleService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserExtService userExtService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GameService gameService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询玩家角色列表
|
|
|
+ *
|
|
|
+ * @param param : 角色列表查询参数
|
|
|
+ * @return : 玩家角色单页信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<GameUserRoleListVO> list(GameUserRoleListParam param) {
|
|
|
+ //玩家条件处理
|
|
|
+ Map<Long, UserDTO> userMap = userService.userCondition(param.getUserId(), param.getChannelId(), param.getUserName(), param.getNickname());
|
|
|
+ //根据条件, 匹配不到玩家
|
|
|
+ if (userMap != null && userMap.isEmpty()) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+ //玩家注册ip条件处理
|
|
|
+ Map<Long, UserExtDTO> userExtMap = userExtService.regIpCondition(param.getRegIp());
|
|
|
+ //根据ip, 匹配不到玩家
|
|
|
+ if (userExtMap != null && userExtMap.isEmpty()) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+ //玩家信息和拓展信息合并
|
|
|
+ Set<Long> userIdSet = this.getUserId(userMap, userExtMap);
|
|
|
+ //用户信息取交集不存在玩家信息
|
|
|
+ if (userIdSet != null && userIdSet.isEmpty()) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+ //游戏条件处理
|
|
|
+ Map<Long, GameDTO> gameMap = gameService.gameCondition(param.getCpId(), param.getGameId(), param.getGameCategoryId());
|
|
|
+ //根据条件, 匹配不到游戏
|
|
|
+ if (gameMap != null && gameMap.isEmpty()) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+ //执行查询
|
|
|
+ return page(param.toPage(), new QueryWrapper<GameUserRole>().lambda()
|
|
|
+ .in(CollectionUtils.isNotEmpty(userIdSet), GameUserRole::getUserId, userIdSet)
|
|
|
+ .eq(Strings.isNotBlank(param.getServerName()), GameUserRole::getServerName, param.getServerName())
|
|
|
+ .eq(Strings.isNotBlank(param.getRoleName()), GameUserRole::getRoleName, param.getRoleName())
|
|
|
+ .in(gameMap != null, GameUserRole::getGameId, gameMap != null ? gameMap.keySet() : null)
|
|
|
+ .eq(Strings.isNotBlank(param.getOs()), GameUserRole::getOs, param.getOs())
|
|
|
+ .gt(Objects.equals(param.getIsRecharge(), Boolean.TRUE), GameUserRole::getRechargeCount, 0)
|
|
|
+ .eq(Objects.equals(param.getIsRecharge(), Boolean.FALSE), GameUserRole::getRechargeCount, 0)
|
|
|
+ .eq(param.getVipLevel() != null && param.getVipLevel() <= 10, GameUserRole::getRoleVipLevel, param.getVipLevel())
|
|
|
+ .gt(param.getVipLevel() != null && param.getVipLevel() > 10, GameUserRole::getRoleVipLevel, param.getVipLevel())
|
|
|
+ .ge(param.getBeginDate() != null, GameUserRole::getCreateTime, param.getBeginDate() == null ? null : LocalDateTime.of(param.getBeginDate(), LocalTime.MIN))
|
|
|
+ .le(param.getEndDate() != null, GameUserRole::getCreateTime, param.getEndDate() == null ? null : LocalDateTime.of(param.getEndDate(), LocalTime.MAX))
|
|
|
+ .ge(param.getRechargeBeginDate() != null, GameUserRole::getLastRechargeTime, param.getRechargeBeginDate() == null ? null : LocalDateTime.of(param.getRechargeBeginDate(), LocalTime.MIN))
|
|
|
+ .le(param.getRechargeEndDate() != null, GameUserRole::getLastRechargeTime, param.getRechargeEndDate() == null ? null : LocalDateTime.of(param.getRechargeEndDate(), LocalTime.MAX))
|
|
|
+ .orderByDesc(GameUserRole::getCreateTime)
|
|
|
+ ).convert(u -> this.toVo(u, userMap, userExtMap, gameMap));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 玩家角色信息对象转换
|
|
|
+ *
|
|
|
+ * @param gameUserRole : 玩家角色信息
|
|
|
+ * @return : 玩家角色信息展示对象
|
|
|
+ */
|
|
|
+ private GameUserRoleListVO toVo(GameUserRole gameUserRole, Map<Long, UserDTO> userMap, Map<Long, UserExtDTO> userExtMap, Map<Long, GameDTO> gameMap) {
|
|
|
+ GameUserRoleListVO gameUserRoleListVO = BeanUtils.copy(gameUserRole, GameUserRoleListVO.class);
|
|
|
+ if (Objects.isNull(gameUserRoleListVO)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ UserDTO userDTO = StringUtils.isEmpty(userMap) ? null : userMap.get(gameUserRoleListVO.getUserId());
|
|
|
+ if (userDTO == null) {
|
|
|
+ userDTO = userService.getById(gameUserRoleListVO.getUserId());
|
|
|
+ }
|
|
|
+ if (userDTO != null) {
|
|
|
+ gameUserRoleListVO.setUsername(userDTO.getUsername());
|
|
|
+ gameUserRoleListVO.setNickname(userDTO.getNickname());
|
|
|
+ gameUserRoleListVO.setChannelId(userDTO.getChannel());
|
|
|
+ }
|
|
|
+ UserExtDTO userExtDTO = StringUtils.isEmpty(userExtMap) ? null : userExtMap.get(gameUserRoleListVO.getUserId());
|
|
|
+ if (userExtDTO == null) {
|
|
|
+ userExtDTO = userExtService.getById(gameUserRoleListVO.getUserId());
|
|
|
+ }
|
|
|
+ if (userExtDTO != null) {
|
|
|
+ gameUserRoleListVO.setRegIp(userExtDTO.getRegIp());
|
|
|
+ gameUserRoleListVO.setRegTime(userExtDTO.getCreateTime());
|
|
|
+ }
|
|
|
+ GameDTO gameDTO = StringUtils.isEmpty(gameMap) ? null : gameMap.get(gameUserRoleListVO.getGameId());
|
|
|
+ if (gameDTO == null) {
|
|
|
+ gameDTO = gameService.getById(gameUserRoleListVO.getGameId());
|
|
|
+ }
|
|
|
+ if (gameDTO != null) {
|
|
|
+ gameUserRoleListVO.setCpId(gameDTO.getCpId());
|
|
|
+ gameUserRoleListVO.setGameCategoryId(gameDTO.getCategory());
|
|
|
+ }
|
|
|
+ return gameUserRoleListVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取查询相关的玩家用户id
|
|
|
+ *
|
|
|
+ * @param userMap : 玩家信息
|
|
|
+ * @param userExtMap : 玩家拓展信息
|
|
|
+ * @return : 返回玩家id列表
|
|
|
+ */
|
|
|
+ private Set<Long> getUserId(Map<Long, UserDTO> userMap, Map<Long, UserExtDTO> userExtMap) {
|
|
|
+ if (userMap == null && userExtMap == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (userMap == null) {
|
|
|
+ return userExtMap.keySet();
|
|
|
+ }
|
|
|
+ if (userExtMap == null) {
|
|
|
+ return userMap.keySet();
|
|
|
+ }
|
|
|
+ //两者都不为空, 取交集
|
|
|
+ Set<Long> set = new HashSet<>();
|
|
|
+ Set<Long> userExtMapKeySet = userExtMap.keySet();
|
|
|
+ userMap.keySet().forEach(u -> {
|
|
|
+ if (userExtMapKeySet.contains(u)) {
|
|
|
+ set.add(u);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return set;
|
|
|
+ }
|
|
|
+}
|