소스 검색

参赛队伍导入

wenkai 2 주 전
부모
커밋
97966e580f

+ 36 - 1
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/controller/GameTeamController.java

@@ -1,11 +1,17 @@
 package org.dromara.system.controller;
 
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import lombok.RequiredArgsConstructor;
 import jakarta.servlet.http.HttpServletResponse;
 import jakarta.validation.constraints.*;
 import cn.dev33.satoken.annotation.SaCheckPermission;
+import lombok.extern.slf4j.Slf4j;
+import org.dromara.common.core.utils.MapstructUtils;
+import org.dromara.common.excel.core.ExcelResult;
+import org.dromara.system.domain.GameTeam;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.validation.annotation.Validated;
 import org.dromara.common.idempotent.annotation.RepeatSubmit;
@@ -21,6 +27,7 @@ import org.dromara.system.domain.vo.GameTeamVo;
 import org.dromara.system.domain.bo.GameTeamBo;
 import org.dromara.system.service.IGameTeamService;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * 参赛队伍
@@ -28,6 +35,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
  * @author zlt
  * @date 2025-07-30
  */
+@Slf4j
 @Validated
 @RequiredArgsConstructor
 @RestController
@@ -45,6 +53,33 @@ public class GameTeamController extends BaseController {
         return gameTeamService.queryPageList(bo, pageQuery);
     }
 
+    /**
+     * 导入参赛队伍列表
+     */
+    @SaCheckPermission("system:gameTeam:import")
+    @Log(title = "参赛队伍", businessType = BusinessType.IMPORT)
+    @PostMapping("/import")
+    public R<Void> importExcel(@RequestPart("file") MultipartFile file) {
+        ExcelResult<GameTeamVo> excelResult = null;
+        try {
+            excelResult = ExcelUtil.importExcel(file.getInputStream(), GameTeamVo.class, true);
+            List<GameTeam> list = MapstructUtils.convert(excelResult.getList(), GameTeam.class);
+            log.info("转换后的列表:", list);
+            gameTeamService.saveBatch(list);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return R.ok(excelResult.getAnalysis());
+    }
+
+    /**
+     * 获取导入模板
+     */
+    @PostMapping("/importTemplate")
+    public void importTemplate(HttpServletResponse response) {
+        ExcelUtil.exportExcel(new ArrayList<>(), "参数队伍数据", GameTeamVo.class, response);
+    }
+
     /**
      * 导出参赛队伍列表
      */
@@ -64,7 +99,7 @@ public class GameTeamController extends BaseController {
     @SaCheckPermission("system:gameTeam:query")
     @GetMapping("/{teamId}")
     public R<GameTeamVo> getInfo(@NotNull(message = "主键不能为空")
-                                     @PathVariable Long teamId) {
+                                 @PathVariable Long teamId) {
         return R.ok(gameTeamService.queryById(teamId));
     }
 

+ 1 - 1
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/domain/vo/GameTeamVo.java

@@ -28,7 +28,7 @@ public class GameTeamVo implements Serializable {
     @Serial
     private static final long serialVersionUID = 1L;
 
-//    @ExcelProperty(value = "主键")
+   @ExcelProperty(value = "主键")
     private Long teamId;
 
     /**

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

@@ -1,5 +1,6 @@
 package org.dromara.system.service;
 
+import org.dromara.system.domain.GameTeam;
 import org.dromara.system.domain.vo.GameTeamVo;
 import org.dromara.system.domain.bo.GameTeamBo;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -65,4 +66,12 @@ public interface IGameTeamService {
      * @return 是否删除成功
      */
     Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
+
+    /**
+     * 批量保存参赛队伍信息
+     *
+     * @param list 参赛队伍信息
+     */
+
+    Boolean saveBatch(List<GameTeam> list);
 }

+ 13 - 3
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/service/impl/GameTeamServiceImpl.java

@@ -40,7 +40,7 @@ public class GameTeamServiceImpl implements IGameTeamService {
      * @return 参赛队伍
      */
     @Override
-    public GameTeamVo queryById(Long teamId){
+    public GameTeamVo queryById(Long teamId) {
         return baseMapper.selectVoById(teamId);
     }
 
@@ -120,7 +120,7 @@ public class GameTeamServiceImpl implements IGameTeamService {
     /**
      * 保存前的数据校验
      */
-    private void validEntityBeforeSave(GameTeam entity){
+    private void validEntityBeforeSave(GameTeam entity) {
         //TODO 做一些数据校验,如唯一约束
     }
 
@@ -133,9 +133,19 @@ public class GameTeamServiceImpl implements IGameTeamService {
      */
     @Override
     public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
-        if(isValid){
+        if (isValid) {
             //TODO 做一些业务上的校验,判断是否需要校验
         }
         return baseMapper.deleteByIds(ids) > 0;
     }
+
+    /**
+     * 批量保存参赛队伍信息
+     *
+     * @param list 参赛队伍信息
+     */
+    @Override
+    public Boolean saveBatch(List<GameTeam> list) {
+        return baseMapper.insertBatch(list);
+    }
 }