|
@@ -0,0 +1,131 @@
|
|
|
+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.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.zanxiang.erp.base.ErpServer;
|
|
|
+import com.zanxiang.erp.base.rpc.ISysUserRpc;
|
|
|
+import com.zanxiang.erp.security.util.SecurityUtil;
|
|
|
+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.GameAuthAddParam;
|
|
|
+import com.zanxiang.game.module.manage.pojo.params.GameAuthListParam;
|
|
|
+import com.zanxiang.game.module.manage.pojo.params.GameAuthUpdateParam;
|
|
|
+import com.zanxiang.game.module.manage.pojo.vo.GameAuthVO;
|
|
|
+import com.zanxiang.game.module.manage.service.IGameAuthService;
|
|
|
+import com.zanxiang.game.module.manage.service.IGameService;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.GameAuth;
|
|
|
+import com.zanxiang.game.module.mybatis.mapper.GameAuthMapper;
|
|
|
+import com.zanxiang.module.util.bean.BeanUtil;
|
|
|
+import com.zanxiang.module.util.exception.BaseException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+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.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author : lingfeng
|
|
|
+ * @time : 2023-08-16
|
|
|
+ * @description : 游戏授权
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class GameAuthServiceImpl extends ServiceImpl<GameAuthMapper, GameAuth> implements IGameAuthService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGameService gameService;
|
|
|
+
|
|
|
+ @DubboReference(providedBy = ErpServer.SERVER_DUBBO_NAME)
|
|
|
+ private ISysUserRpc sysUserRpc;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean gameAuthAdd(GameAuthAddParam param) {
|
|
|
+ //游戏id
|
|
|
+ Long gameId = param.getGameId();
|
|
|
+ List<GameAuthAddParam.GameAuthUserBean> userAuthList = param.getUserAuthList();
|
|
|
+ List<GameAuth> addList = new ArrayList<>();
|
|
|
+ userAuthList.forEach(userAuth -> {
|
|
|
+ //判断提交的参数数据是否已经存在
|
|
|
+ if (super.count(new LambdaQueryWrapper<GameAuth>()
|
|
|
+ .eq(GameAuth::getGameId, gameId)
|
|
|
+ .eq(GameAuth::getUserId, userAuth.getUserId())
|
|
|
+ .eq(GameAuth::getType, userAuth.getType())
|
|
|
+ ) > 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ addList.add(this.transform(gameId, userAuth));
|
|
|
+ });
|
|
|
+ if (addList.isEmpty()) {
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+ return super.saveBatch(addList);
|
|
|
+ }
|
|
|
+
|
|
|
+ private GameAuth transform(Long gameId, GameAuthAddParam.GameAuthUserBean gameAuthUserBean) {
|
|
|
+ return GameAuth.builder()
|
|
|
+ .gameId(gameId)
|
|
|
+ .userId(gameAuthUserBean.getUserId())
|
|
|
+ .type(gameAuthUserBean.getType())
|
|
|
+ .isDelete(DeleteEnum.NO.getCode())
|
|
|
+ .createBy(SecurityUtil.getUserId())
|
|
|
+ .createTime(LocalDateTime.now())
|
|
|
+ .updateBy(SecurityUtil.getUserId())
|
|
|
+ .updateTime(LocalDateTime.now())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean gameAuthUpdate(GameAuthUpdateParam param) {
|
|
|
+ //判断提交的参数数据是否已经存在
|
|
|
+ if (super.count(new LambdaQueryWrapper<GameAuth>()
|
|
|
+ .eq(GameAuth::getGameId, param.getGameId())
|
|
|
+ .eq(GameAuth::getUserId, param.getUserId())
|
|
|
+ .eq(GameAuth::getType, param.getType())
|
|
|
+ ) > 0) {
|
|
|
+ throw new BaseException("参数错误, 要修改的数据已经存在相同数据");
|
|
|
+ }
|
|
|
+ //修改
|
|
|
+ return super.update(new LambdaUpdateWrapper<GameAuth>()
|
|
|
+ .set(GameAuth::getGameId, param.getGameId())
|
|
|
+ .set(GameAuth::getUserId, param.getUserId())
|
|
|
+ .set(GameAuth::getType, param.getType())
|
|
|
+ .set(GameAuth::getUpdateBy, SecurityUtil.getUserId())
|
|
|
+ .set(GameAuth::getUpdateTime, LocalDateTime.now())
|
|
|
+ .eq(GameAuth::getId, param.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<GameAuthVO> listOfPage(GameAuthListParam param) {
|
|
|
+ return page(param.toPage(), new QueryWrapper<GameAuth>().lambda()
|
|
|
+ .eq(param.getGameId() != null, GameAuth::getGameId, param.getGameId())
|
|
|
+ .eq(param.getUserId() != null, GameAuth::getUserId, param.getUserId())
|
|
|
+ .orderByDesc(GameAuth::getUpdateTime)
|
|
|
+ ).convert(this::toVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ private GameAuthVO toVo(GameAuth gameAuth) {
|
|
|
+ if (Objects.isNull(gameAuth)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ GameAuthVO gameAuthVO = BeanUtil.copy(gameAuth, GameAuthVO.class);
|
|
|
+ GameDTO gameDTO = gameService.getById(gameAuthVO.getGameId());
|
|
|
+ gameAuthVO.setGameName(gameDTO == null ? null : gameDTO.getName());
|
|
|
+ Map<Long, String> userMap = sysUserRpc.getUserNameByIds(Collections.singletonList(gameAuthVO.getUserId())).getData();
|
|
|
+ gameAuthVO.setUserName(userMap.get(gameAuthVO.getUserId()));
|
|
|
+ return gameAuthVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean deleteById(Long id) {
|
|
|
+ return super.removeById(id);
|
|
|
+ }
|
|
|
+}
|