|
|
@@ -1,18 +1,28 @@
|
|
|
package com.yingyangfly.core.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.yingyangfly.core.domain.AppUser;
|
|
|
import com.yingyangfly.core.domain.Game;
|
|
|
import com.yingyangfly.core.domain.GamePastRecords;
|
|
|
+import com.yingyangfly.core.domain.GameUser;
|
|
|
+import com.yingyangfly.core.enums.StatusEnums;
|
|
|
+import com.yingyangfly.core.mapper.GameMapper;
|
|
|
import com.yingyangfly.core.mapper.GamePastRecordsMapper;
|
|
|
import com.yingyangfly.core.service.GamePastRecordsService;
|
|
|
import com.yingyangfly.core.service.GameService;
|
|
|
+import com.yingyangfly.core.service.GameUserService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
|
@Service
|
|
|
@@ -22,6 +32,15 @@ public class GamePastRecordsServiceImpl extends ServiceImpl<GamePastRecordsMappe
|
|
|
@Resource
|
|
|
private GameService gameService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private GameMapper gameMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AppUserService appUserService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private GameUserService gameUserService;
|
|
|
+
|
|
|
/**
|
|
|
* 恢复游戏
|
|
|
* @return
|
|
|
@@ -33,8 +52,49 @@ public class GamePastRecordsServiceImpl extends ServiceImpl<GamePastRecordsMappe
|
|
|
Game game = new Game();
|
|
|
BeanUtils.copyProperties(gamePastRecords,game);
|
|
|
game.setId(IdWorker.getId());
|
|
|
- gameService.saveGame(game);
|
|
|
+ Game game1 = gameService.selectByGameCode(game.getGameCode());
|
|
|
+ if (ObjectUtils.isNotNull(game1)){
|
|
|
+ Game gameDb = gameMapper.selectMaxGameCode();
|
|
|
+ Integer gamecode = Integer.parseInt(gameDb.getGameCode())+1;
|
|
|
+ game.setGameCode(String.valueOf(gamecode));
|
|
|
+ }
|
|
|
+ game.setStatus(StatusEnums.OK.getIntCode());
|
|
|
+ // 新增给所有用户加上游戏
|
|
|
+ List<AppUser> appUsers = appUserService.list();
|
|
|
+ List<GameUser> gameUsers = buildGameUsers(game, appUsers);
|
|
|
+ gameUserService.saveBatch(gameUsers);
|
|
|
+ gameService.save(game);
|
|
|
// 历史游戏表中删除
|
|
|
int result = baseMapper.deleteById(gamePastRecords.getId());
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private List<GameUser> buildGameUsers(Game game, List<AppUser> appUsers){
|
|
|
+ Date current = DateUtil.date();
|
|
|
+ List<GameUser> gameUsers = new ArrayList<>();
|
|
|
+ for (AppUser appUser : appUsers) {
|
|
|
+ GameUser gameUser = new GameUser();
|
|
|
+ gameUser.setId(IdWorker.getId());
|
|
|
+ gameUser.setGameCode(game.getGameCode());
|
|
|
+ gameUser.setGameName(game.getGameName());
|
|
|
+ gameUser.setGameUrl(game.getGameUrl());
|
|
|
+ gameUser.setGameType(game.getGameType());
|
|
|
+ gameUser.setUserId(appUser.getId());
|
|
|
+ gameUser.setUserName(appUser.getName());
|
|
|
+ gameUser.setPlayClass("C");
|
|
|
+ gameUser.setStatus("1");
|
|
|
+ gameUser.setCurrentLevel(1);
|
|
|
+ gameUser.setTotalNum(game.getTotalNum());
|
|
|
+ gameUser.setCreateTime(current);
|
|
|
+ gameUser.setUpdateTime(current);
|
|
|
+ gameUser.setOrgCode(game.getOrgCode());
|
|
|
+ gameUser.setOrgName(game.getOrgName());
|
|
|
+ gameUser.setGameDifficulty(game.getGameDifficulty());
|
|
|
+ gameUser.setGameDifficultyRate(game.getGameDifficultyRate());
|
|
|
+ gameUser.setGameDuration(game.getGameDuration());
|
|
|
+ gameUser.setGameCoverImage(game.getGameCoverImage());
|
|
|
+ gameUsers.add(gameUser);
|
|
|
+ }
|
|
|
+ return gameUsers;
|
|
|
+ }
|
|
|
}
|