|
@@ -0,0 +1,87 @@
|
|
|
|
+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.erp.security.util.SecurityUtil;
|
|
|
|
+import com.zanxiang.game.module.manage.pojo.dto.GameDTO;
|
|
|
|
+import com.zanxiang.game.module.manage.pojo.params.GameUserConfigAddUpdateParam;
|
|
|
|
+import com.zanxiang.game.module.manage.pojo.params.GameUserConfigListParam;
|
|
|
|
+import com.zanxiang.game.module.manage.pojo.vo.GameUserConfigListVO;
|
|
|
|
+import com.zanxiang.game.module.manage.service.IGameService;
|
|
|
|
+import com.zanxiang.game.module.manage.service.IGameUserConfigService;
|
|
|
|
+import com.zanxiang.game.module.mybatis.entity.GameUserConfig;
|
|
|
|
+import com.zanxiang.game.module.mybatis.mapper.GameUserConfigMapper;
|
|
|
|
+import com.zanxiang.module.util.bean.BeanUtil;
|
|
|
|
+import com.zanxiang.module.util.exception.BaseException;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author : lingfeng
|
|
|
|
+ * @time : 2023-08-09
|
|
|
|
+ * @description : 有效用户配置
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+public class GameUserConfigServiceImpl extends ServiceImpl<GameUserConfigMapper, GameUserConfig> implements IGameUserConfigService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IGameService gameService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean addOrUpdate(GameUserConfigAddUpdateParam param) {
|
|
|
|
+ //判断游戏配置不可重复
|
|
|
|
+ if (super.count(new LambdaQueryWrapper<GameUserConfig>()
|
|
|
|
+ .eq(GameUserConfig::getGameId, param.getGameId())
|
|
|
|
+ .ne(param.getId() != null, GameUserConfig::getId, param.getId())
|
|
|
|
+ ) > 0) {
|
|
|
|
+ throw new BaseException("该游戏已经存在配置, 禁止添加或者修改");
|
|
|
|
+ }
|
|
|
|
+ //添加或者更新
|
|
|
|
+ return super.saveOrUpdate(this.transform(param));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private GameUserConfig transform(GameUserConfigAddUpdateParam param) {
|
|
|
|
+ return GameUserConfig.builder()
|
|
|
|
+ .id(param.getId())
|
|
|
|
+ .gameId(param.getGameId())
|
|
|
|
+ .roleLevel(param.getRoleLevel())
|
|
|
|
+ .createBy(param.getId() == null ? SecurityUtil.getUserId() : null)
|
|
|
|
+ .createTime(param.getId() == null ? LocalDateTime.now() : null)
|
|
|
|
+ .updateBy(SecurityUtil.getUserId())
|
|
|
|
+ .updateTime(LocalDateTime.now())
|
|
|
|
+ .build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public IPage<GameUserConfigListVO> listOfPage(GameUserConfigListParam param) {
|
|
|
|
+ return page(param.toPage(), new QueryWrapper<GameUserConfig>().lambda()
|
|
|
|
+ .eq(GameUserConfig::getGameId, param.getGameId())
|
|
|
|
+ .orderByDesc(GameUserConfig::getCreateTime)
|
|
|
|
+ ).convert(this::toVo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private GameUserConfigListVO toVo(GameUserConfig gameUserConfig) {
|
|
|
|
+ if (Objects.isNull(gameUserConfig)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ GameUserConfigListVO gameUserConfigListVO = BeanUtil.copy(gameUserConfig, GameUserConfigListVO.class);
|
|
|
|
+ GameDTO gameDTO = gameService.getById(gameUserConfigListVO.getGameId());
|
|
|
|
+ gameUserConfigListVO.setGameName(gameDTO == null ? null : gameDTO.getName());
|
|
|
|
+ return gameUserConfigListVO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean deleteById(Long id) {
|
|
|
|
+ return super.removeById(id);
|
|
|
|
+ }
|
|
|
|
+}
|