|
@@ -0,0 +1,97 @@
|
|
|
+package com.zanxiang.game.module.manage.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.zanxiang.game.module.base.pojo.enums.DeleteEnum;
|
|
|
+import com.zanxiang.game.module.manage.pojo.dto.GameDTO;
|
|
|
+import com.zanxiang.game.module.manage.pojo.params.GameServerAddUpdateParam;
|
|
|
+import com.zanxiang.game.module.manage.pojo.params.GameServerListParam;
|
|
|
+import com.zanxiang.game.module.manage.pojo.vo.GameServerListVO;
|
|
|
+import com.zanxiang.game.module.manage.service.IGameServerService;
|
|
|
+import com.zanxiang.game.module.manage.service.IGameService;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.GameServer;
|
|
|
+import com.zanxiang.game.module.mybatis.mapper.GameServerMapper;
|
|
|
+import com.zanxiang.module.util.bean.BeanUtil;
|
|
|
+import com.zanxiang.module.util.exception.BaseException;
|
|
|
+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 org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author : lingfeng
|
|
|
+ * @time : 2023-08-07
|
|
|
+ * @description : 游戏区服
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class GameServerServiceImpl extends ServiceImpl<GameServerMapper, GameServer> implements IGameServerService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGameService gameService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean addOrUpdate(GameServerAddUpdateParam param) {
|
|
|
+ //判断单游戏内区服id不可重复
|
|
|
+ if (super.count(new LambdaQueryWrapper<GameServer>()
|
|
|
+ .eq(GameServer::getGameId, param.getGameId())
|
|
|
+ .eq(GameServer::getServerId, param.getServerId())
|
|
|
+ .ne(param.getId() != null, GameServer::getId, param.getId())
|
|
|
+ ) > 0) {
|
|
|
+ throw new BaseException("该游戏区服id已存在, 禁止添加或者修改");
|
|
|
+ }
|
|
|
+ //添加或者更新
|
|
|
+ return super.saveOrUpdate(this.transform(param));
|
|
|
+ }
|
|
|
+
|
|
|
+ private GameServer transform(GameServerAddUpdateParam param) {
|
|
|
+ return GameServer.builder()
|
|
|
+ .id(param.getId())
|
|
|
+ .gameId(param.getGameId())
|
|
|
+ .serverId(param.getServerId())
|
|
|
+ .serverName(param.getServerName())
|
|
|
+ .nickName(param.getNickName())
|
|
|
+ .startTime(param.getStartTime())
|
|
|
+ .isDelete(DeleteEnum.NO.getCode())
|
|
|
+ .createTime(param.getId() == null ? null : LocalDateTime.now())
|
|
|
+ .updateTime(LocalDateTime.now())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<GameServerListVO> listOfPage(GameServerListParam param) {
|
|
|
+ return page(param.toPage(), new QueryWrapper<GameServer>().lambda()
|
|
|
+ .eq(param.getGameId() != null, GameServer::getGameId, param.getGameId())
|
|
|
+ .eq(param.getServerId() != null, GameServer::getServerId, param.getServerId())
|
|
|
+ .like(Strings.isNotBlank(param.getServerName()), GameServer::getServerName, param.getServerName())
|
|
|
+ .like(Strings.isNotBlank(param.getNickName()), GameServer::getNickName, param.getNickName())
|
|
|
+ .ge(param.getStartTime() != null, GameServer::getStartTime, param.getStartTime() == null ? null : LocalDateTime.of(param.getStartTime(), LocalTime.MIN))
|
|
|
+ .le(param.getEndTime() != null, GameServer::getStartTime, param.getEndTime() == null ? null : LocalDateTime.of(param.getEndTime(), LocalTime.MAX))
|
|
|
+ .orderByDesc(GameServer::getUpdateTime)
|
|
|
+ ).convert(this::toVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ private GameServerListVO toVo(GameServer gameServer) {
|
|
|
+ if (Objects.isNull(gameServer)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ GameServerListVO gameServerListVO = BeanUtil.copy(gameServer, GameServerListVO.class);
|
|
|
+ GameDTO gameDTO = gameService.getById(gameServer.getGameId());
|
|
|
+ gameServerListVO.setGameName(gameDTO == null ? null : gameDTO.getName());
|
|
|
+ return gameServerListVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean deleteById(Long id) {
|
|
|
+ return super.removeById(id);
|
|
|
+ }
|
|
|
+}
|