Pārlūkot izejas kodu

feat(gameEventConfig): 添加批量保存赛事配置功能

- 在控制器中添加 saveBatch 接口支持批量保存赛事配置
- 在服务实现中添加 BeanUtil 工具类用于对象转换
- 实现批量保存事务处理,支持新增或修改操作
- 优化注释格式统一使用英文注释风格
- 更新数据库查询方法调用适配新的批量操作接口
zhou 1 dienu atpakaļ
vecāks
revīzija
886cec4219

+ 11 - 0
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/controller/GameEventConfigController.java

@@ -102,4 +102,15 @@ public class GameEventConfigController extends BaseController {
                           @PathVariable Long[] configIds) {
         return toAjax(gameEventConfigService.deleteWithValidByIds(List.of(configIds), true));
     }
+
+    /**
+     * 批量保存赛事配置
+     */
+    @SaCheckPermission("system:gameEventConfig:add")
+    @Log(title = "赛事配置", businessType = BusinessType.INSERT)
+    @RepeatSubmit()
+    @PostMapping("/saveBatch")
+    public R<Void> saveBatch(@RequestBody List<GameEventConfigBo> bos) {
+        return toAjax(gameEventConfigService.saveBatch(bos));
+    }
 }

+ 8 - 0
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/service/IGameEventConfigService.java

@@ -67,4 +67,12 @@ public interface IGameEventConfigService {
     Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
 
     Long queryBgUrlByEventId(Long eventId);
+
+    /**
+     * 批量保存赛事配置(新增或修改)
+     *
+     * @param bos 赛事配置列表
+     * @return 是否保存成功
+     */
+    Boolean saveBatch(List<GameEventConfigBo> bos);
 }

+ 29 - 12
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/service/impl/GameEventConfigServiceImpl.java

@@ -1,5 +1,6 @@
 package org.dromara.system.service.impl;
 
+import cn.hutool.core.bean.BeanUtil;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -17,6 +18,7 @@ import org.dromara.system.domain.vo.GameEventConfigVo;
 import org.dromara.system.domain.GameEventConfig;
 import org.dromara.system.mapper.GameEventConfigMapper;
 import org.dromara.system.service.IGameEventConfigService;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 import java.util.Map;
@@ -58,13 +60,14 @@ public class GameEventConfigServiceImpl implements IGameEventConfigService {
         if (bo.getEventId() == null) {
             Object cacheObject = RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID);
             if (cacheObject instanceof Integer) {
-                bo.setEventId(((Integer) cacheObject).longValue());  // 显式转换为 Long 类型
+                bo.setEventId(((Integer) cacheObject).longValue()); // 显式转换为 Long 类型
             } else if (cacheObject instanceof Long) {
                 bo.setEventId((Long) cacheObject);
             }
         }
         LambdaQueryWrapper<GameEventConfig> lqw = buildQueryWrapper(bo);
-//        Page<GameEventConfigVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
+        // Page<GameEventConfigVo> result = baseMapper.selectVoPage(pageQuery.build(),
+        // lqw);
         Page<GameEventConfigVo> result = baseMapper.selectPageEventConfigList(pageQuery.build(), lqw);
         return TableDataInfo.build(result);
     }
@@ -80,13 +83,13 @@ public class GameEventConfigServiceImpl implements IGameEventConfigService {
         if (bo.getEventId() == null) {
             Object cacheObject = RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID);
             if (cacheObject instanceof Integer) {
-                bo.setEventId(((Integer) cacheObject).longValue());  // 显式转换为 Long 类型
+                bo.setEventId(((Integer) cacheObject).longValue()); // 显式转换为 Long 类型
             } else if (cacheObject instanceof Long) {
                 bo.setEventId((Long) cacheObject);
             }
         }
         LambdaQueryWrapper<GameEventConfig> lqw = buildQueryWrapper(bo);
-//        return baseMapper.selectVoList(lqw);
+        // return baseMapper.selectVoList(lqw);
         return baseMapper.selectEventConfigList(lqw);
     }
 
@@ -113,7 +116,7 @@ public class GameEventConfigServiceImpl implements IGameEventConfigService {
         if (bo.getEventId() == null) {
             Object cacheObject = RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID);
             if (cacheObject instanceof Integer) {
-                bo.setEventId(((Integer) cacheObject).longValue());  // 显式转换为 Long 类型
+                bo.setEventId(((Integer) cacheObject).longValue()); // 显式转换为 Long 类型
             } else if (cacheObject instanceof Long) {
                 bo.setEventId((Long) cacheObject);
             }
@@ -138,7 +141,7 @@ public class GameEventConfigServiceImpl implements IGameEventConfigService {
         if (bo.getEventId() == null) {
             Object cacheObject = RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID);
             if (cacheObject instanceof Integer) {
-                bo.setEventId(((Integer) cacheObject).longValue());  // 显式转换为 Long 类型
+                bo.setEventId(((Integer) cacheObject).longValue()); // 显式转换为 Long 类型
             } else if (cacheObject instanceof Long) {
                 bo.setEventId((Long) cacheObject);
             }
@@ -152,7 +155,7 @@ public class GameEventConfigServiceImpl implements IGameEventConfigService {
      * 保存前的数据校验
      */
     private void validEntityBeforeSave(GameEventConfig entity) {
-        //TODO 做一些数据校验,如唯一约束
+        // TODO 做一些数据校验,如唯一约束
     }
 
     /**
@@ -165,7 +168,7 @@ public class GameEventConfigServiceImpl implements IGameEventConfigService {
     @Override
     public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
         if (isValid) {
-            //TODO 做一些业务上的校验,判断是否需要校验
+            // TODO 做一些业务上的校验,判断是否需要校验
         }
         return baseMapper.deleteByIds(ids) > 0;
     }
@@ -173,10 +176,9 @@ public class GameEventConfigServiceImpl implements IGameEventConfigService {
     @Override
     public Long queryBgUrlByEventId(Long eventId) {
         GameEventConfig backgroundImg = baseMapper.selectOne(
-            Wrappers.lambdaQuery(GameEventConfig.class)
-                .eq(GameEventConfig::getEventId, eventId)
-                .eq(GameEventConfig::getConfigKey, "background_img")
-        );
+                Wrappers.lambdaQuery(GameEventConfig.class)
+                        .eq(GameEventConfig::getEventId, eventId)
+                        .eq(GameEventConfig::getConfigKey, "background_img"));
         if (backgroundImg == null) {
             return 0L;
         }
@@ -186,4 +188,19 @@ public class GameEventConfigServiceImpl implements IGameEventConfigService {
         }
         return Long.valueOf(ossId);
     }
+
+    /**
+     * 批量保存赛事配置(新增或修改)
+     *
+     * @param bos 赛事配置列表
+     * @return 是否保存成功
+     */
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public Boolean saveBatch(List<GameEventConfigBo> bos) {
+        if (bos == null || bos.isEmpty()) {
+            return true;
+        }
+        return baseMapper.insertOrUpdateBatch(BeanUtil.copyToList(bos, GameEventConfig.class));
+    }
 }