|
@@ -1,23 +1,29 @@
|
|
|
package org.jeecg.modules.system.app.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import lombok.Setter;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.jeecg.common.exception.JeecgBootException;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
-import org.jeecg.modules.system.app.dto.AppGameDTO;
|
|
|
+import org.jeecg.modules.system.app.dto.*;
|
|
|
import org.jeecg.modules.system.app.entity.AppGame;
|
|
|
import org.jeecg.modules.system.app.entity.AppGamePriceRules;
|
|
|
+import org.jeecg.modules.system.app.entity.AppGameSchedule;
|
|
|
import org.jeecg.modules.system.app.mapper.AppGameMapper;
|
|
|
import org.jeecg.modules.system.app.mapper.AppGamePriceRulesMapper;
|
|
|
+import org.jeecg.modules.system.app.mapper.AppGameScheduleMapper;
|
|
|
import org.jeecg.modules.system.app.service.IAppGameService;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
import static org.jeecg.common.constant.CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
|
|
@@ -25,96 +31,174 @@ import static org.jeecg.common.constant.CommonConstant.SC_INTERNAL_SERVER_ERROR_
|
|
|
/**
|
|
|
* @Description: 赛事表
|
|
|
* @Author: jeecg-boot
|
|
|
- * @Date: 2025-07-03
|
|
|
+ * @Date: 2025-07-03
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
|
@Service
|
|
|
public class AppGameServiceImpl extends ServiceImpl<AppGameMapper, AppGame> implements IAppGameService {
|
|
|
@Resource
|
|
|
private AppGamePriceRulesMapper rulesMapper;
|
|
|
+ @Resource
|
|
|
+ AppGameScheduleMapper scheduleMapper;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean saveWitchPriceRules(AppGameDTO gameDTO) {
|
|
|
- AppGame game=gameDTO.getGame();
|
|
|
- if (null==game.getType()) throw new JeecgBootException("请选择赛事类型");
|
|
|
+ AppGameCuDTO gameCuDTO = gameDTO.getGame();
|
|
|
+ AppGame game = new AppGame();
|
|
|
+ BeanUtils.copyProperties(gameCuDTO, game);
|
|
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
game.setOrgCode(sysUser.getOrgCode());
|
|
|
game.setTenantId(sysUser.getOrgId());
|
|
|
int saveGameResult = baseMapper.insert(game);
|
|
|
- if (saveGameResult<1) {
|
|
|
+ if (saveGameResult < 1) {
|
|
|
throw new JeecgBootException("赛事信息保存失败");
|
|
|
}
|
|
|
- List<AppGamePriceRules> priceRulesList = gameDTO.getGamePriceRules();
|
|
|
- for (AppGamePriceRules rule : priceRulesList) {
|
|
|
- rule.setGameId(game.getId());
|
|
|
- rule.setOrgCode(game.getOrgCode());
|
|
|
- rule.setTenantId(game.getTenantId());
|
|
|
- int savePriceResult = rulesMapper.insert(rule); // 保证每个操作都在事务中
|
|
|
- if (savePriceResult<1) {
|
|
|
+ gameDTO.getGamePriceRules().forEach(gameRuleDtos -> {
|
|
|
+ AppGamePriceRules appGamePriceRules = new AppGamePriceRules();
|
|
|
+ BeanUtils.copyProperties(gameRuleDtos, appGamePriceRules);
|
|
|
+ appGamePriceRules.setGameId(game.getId());
|
|
|
+ appGamePriceRules.setOrgCode(game.getOrgCode());
|
|
|
+ appGamePriceRules.setTenantId(game.getTenantId());
|
|
|
+ int savePriceResult = rulesMapper.insert(appGamePriceRules); // 保证每个操作都在事务中
|
|
|
+ if (savePriceResult < 1) {
|
|
|
throw new JeecgBootException("赛事价格规则保存失败");
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
+ gameDTO.getScheduleDTOS().forEach(scheduleDTO -> {
|
|
|
+ AppGameSchedule appGameSchedule = new AppGameSchedule();
|
|
|
+ BeanUtils.copyProperties(scheduleDTO, appGameSchedule);
|
|
|
+ appGameSchedule.setGameId(game.getId());
|
|
|
+ appGameSchedule.setOrgCode(game.getOrgCode());
|
|
|
+ appGameSchedule.setTenantId(game.getTenantId());
|
|
|
+ int saveScheduleResult = scheduleMapper.insert(appGameSchedule);
|
|
|
+ if (saveScheduleResult < 1) {
|
|
|
+ throw new JeecgBootException("赛事安排保存失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
return Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean editWitchPriceRules(AppGameDTO gameDTO) {
|
|
|
- AppGame game=gameDTO.getGame();
|
|
|
- if (null==game.getType()) throw new JeecgBootException("请选择赛事类型");
|
|
|
+ AppGameCuDTO gameCuDTO = gameDTO.getGame();
|
|
|
+ AppGame game = new AppGame();
|
|
|
+ BeanUtils.copyProperties(gameCuDTO, game);
|
|
|
AppGame dbGame = baseMapper.selectById(game.getId());
|
|
|
- if (null==dbGame) throw new JeecgBootException("未找到对应数据", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ if (null == dbGame) throw new JeecgBootException("未找到对应数据", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
- checkPermission(sysUser,dbGame);
|
|
|
+// checkPermission(sysUser,dbGame);
|
|
|
game.setOrgCode(sysUser.getOrgCode());
|
|
|
game.setTenantId(sysUser.getOrgId());
|
|
|
int updateGameResult = baseMapper.updateById(game);
|
|
|
- if (updateGameResult<1) {
|
|
|
+ if (updateGameResult < 1) {
|
|
|
throw new JeecgBootException("赛事信息保存失败");
|
|
|
}
|
|
|
- List<AppGamePriceRules> priceRulesList = gameDTO.getGamePriceRules();
|
|
|
- for (AppGamePriceRules rule : priceRulesList) {
|
|
|
- rule.setGameId(game.getId());
|
|
|
- rule.setOrgCode(game.getOrgCode());
|
|
|
- rule.setTenantId(game.getTenantId());
|
|
|
- int savePriceResult = rulesMapper.updateById(rule);
|
|
|
- if (savePriceResult<1) {
|
|
|
+ gameDTO.getGamePriceRules().forEach(gameRuleDTO -> {
|
|
|
+ AppGamePriceRules appGamePriceRules = new AppGamePriceRules();
|
|
|
+ BeanUtils.copyProperties(gameRuleDTO, appGamePriceRules);
|
|
|
+ appGamePriceRules.setGameId(game.getId());
|
|
|
+ appGamePriceRules.setOrgCode(game.getOrgCode());
|
|
|
+ appGamePriceRules.setTenantId(game.getTenantId());
|
|
|
+ int savePriceResult = rulesMapper.updateById(appGamePriceRules);
|
|
|
+ if (savePriceResult < 1) {
|
|
|
throw new JeecgBootException("赛事价格规则保存失败");
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
+ });
|
|
|
+ gameDTO.getScheduleDTOS().forEach(scheduleDTO -> {
|
|
|
+ AppGameSchedule appGameSchedule = new AppGameSchedule();
|
|
|
+ BeanUtils.copyProperties(scheduleDTO, appGameSchedule);
|
|
|
+ appGameSchedule.setGameId(game.getId());
|
|
|
+ appGameSchedule.setOrgCode(game.getOrgCode());
|
|
|
+ appGameSchedule.setTenantId(game.getTenantId());
|
|
|
+ int saveScheduleResult = scheduleMapper.updateById(appGameSchedule);
|
|
|
+ if (saveScheduleResult < 1) {
|
|
|
+ throw new JeecgBootException("赛事安排保存失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
return Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public AppGameDTO queryWitchPriceRulesById(String id) {
|
|
|
AppGame dbGame = baseMapper.selectById(id);
|
|
|
- if (null==dbGame) throw new JeecgBootException("未找到对应数据", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ if (null == dbGame) throw new JeecgBootException("未找到对应数据", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ AppGameCuDTO appGameCuDTO = new AppGameCuDTO();
|
|
|
+ BeanUtils.copyProperties(dbGame, appGameCuDTO);
|
|
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
- checkPermission(sysUser,dbGame);
|
|
|
- List<AppGamePriceRules> priceRulesList = rulesMapper.selectList(Wrappers.<AppGamePriceRules>lambdaQuery().eq(AppGamePriceRules::getGameId, id));
|
|
|
- return new AppGameDTO(dbGame,priceRulesList);
|
|
|
+// checkPermission(sysUser,dbGame);
|
|
|
+ List<AppGameRuleDTO> gameRuleDTOS = new ArrayList<>();
|
|
|
+ rulesMapper.selectList(Wrappers.<AppGamePriceRules>lambdaQuery().eq(AppGamePriceRules::getGameId, id)).forEach(priceRules -> {
|
|
|
+ AppGameRuleDTO priceRulesDTO = new AppGameRuleDTO();
|
|
|
+ BeanUtils.copyProperties(priceRules, priceRulesDTO);
|
|
|
+ gameRuleDTOS.add(priceRulesDTO);
|
|
|
+ });
|
|
|
+ List<AppGameScheduleDTO> scheduleDTOS = new ArrayList<>();
|
|
|
+ scheduleMapper.selectList(Wrappers.<AppGameSchedule>lambdaQuery().eq(AppGameSchedule::getGameId, id)).forEach(schedule -> {
|
|
|
+ AppGameScheduleDTO scheduleDTO = new AppGameScheduleDTO();
|
|
|
+ BeanUtils.copyProperties(schedule, scheduleDTO);
|
|
|
+ scheduleDTOS.add(scheduleDTO);
|
|
|
+ });
|
|
|
+ return new AppGameDTO(appGameCuDTO, gameRuleDTOS, scheduleDTOS);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Boolean deleteWitchPriceRulesById(String id) {
|
|
|
AppGame dbGame = baseMapper.selectById(id);
|
|
|
- if (null==dbGame) throw new JeecgBootException("未找到对应数据", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ if (null == dbGame) throw new JeecgBootException("未找到对应数据", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
- checkPermission(sysUser,dbGame);
|
|
|
+// checkPermission(sysUser, dbGame);
|
|
|
int deleteGameResult = baseMapper.deleteById(id);
|
|
|
- if (deleteGameResult<1) {
|
|
|
+ if (deleteGameResult < 1) {
|
|
|
throw new JeecgBootException("赛事信息删除失败");
|
|
|
}
|
|
|
+ int deletePriceResult = rulesMapper.delete(Wrappers.<AppGamePriceRules>lambdaQuery().eq(AppGamePriceRules::getGameId, id));
|
|
|
+ if (deletePriceResult<1) throw new JeecgBootException("赛事价格规则删除失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ int deleteScheduleResult = scheduleMapper.delete(Wrappers.<AppGameSchedule>lambdaQuery().eq(AppGameSchedule::getGameId, id));
|
|
|
+ if (deleteScheduleResult<1) throw new JeecgBootException("赛事安排删除失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
return Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public IPage<AppGameDTO> queryWitchPriceRulesPage(AppGamePageDTO dto) {
|
|
|
+ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ Page<AppGame> page = new Page<>(dto.getPageNum(), dto.getPageSize());
|
|
|
+ LambdaQueryWrapper<AppGame> wrapper = Wrappers.<AppGame>lambdaQuery()
|
|
|
+ .like(StringUtils.isNotBlank(dto.getName()), AppGame::getName, dto.getName());
|
|
|
+// .eq(AppGame::getOrgCode, loginUser.getOrgCode());
|
|
|
+
|
|
|
+ IPage<AppGame> resultPage = baseMapper.selectPage(page, wrapper);
|
|
|
+ return resultPage.convert(record -> {
|
|
|
+ AppGameCuDTO cuDTO = new AppGameCuDTO();
|
|
|
+ BeanUtils.copyProperties(cuDTO, record);
|
|
|
+ List<AppGameRuleDTO> priceRulesDTOList = new ArrayList<>();
|
|
|
+ rulesMapper.selectList(Wrappers.<AppGamePriceRules>lambdaQuery().eq(AppGamePriceRules::getGameId, record.getId())).forEach(rule-> {
|
|
|
+ AppGameRuleDTO appGameRuleDTO = new AppGameRuleDTO();
|
|
|
+ BeanUtils.copyProperties(rule, appGameRuleDTO);
|
|
|
+ priceRulesDTOList.add(appGameRuleDTO);
|
|
|
+ });
|
|
|
+ List<AppGameScheduleDTO> scheduleDTOS = new ArrayList<>();
|
|
|
+ scheduleMapper.selectList(Wrappers.<AppGameSchedule>lambdaQuery().eq(AppGameSchedule::getGameId, record.getId())).forEach(schedule-> {
|
|
|
+ AppGameScheduleDTO appGameScheduleDTO = new AppGameScheduleDTO();
|
|
|
+ BeanUtils.copyProperties(schedule, appGameScheduleDTO);
|
|
|
+ scheduleDTOS.add(appGameScheduleDTO);
|
|
|
+ });
|
|
|
+ return new AppGameDTO(cuDTO, priceRulesDTOList, scheduleDTOS);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
- * 校验权限
|
|
|
+ * 校验权限
|
|
|
+ *
|
|
|
* @param sysUser
|
|
|
* @param game
|
|
|
*/
|
|
|
private void checkPermission(LoginUser sysUser, AppGame game) {
|
|
|
- if (!sysUser.getOrgCode().equals(game.getOrgCode())) throw new JeecgBootException("无权限操作", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ if (!sysUser.getOrgCode().equals(game.getOrgCode()))
|
|
|
+ throw new JeecgBootException("无权限操作", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
}
|
|
|
}
|