Browse Source

feat(game-event): 解决队伍导入bug

zhou 1 month ago
parent
commit
9fbd433926

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

@@ -22,6 +22,7 @@ import org.dromara.system.domain.GameTeam;
 import org.dromara.system.domain.bo.GameTeamBo;
 import org.dromara.system.domain.request.UpdateTeamAthletesRequest;
 import org.dromara.system.domain.vo.GameTeamVo;
+import org.dromara.system.service.IGameEventService;
 import org.dromara.system.service.IGameTeamService;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
@@ -30,6 +31,7 @@ import org.springframework.web.multipart.MultipartFile;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 参赛队伍
@@ -45,6 +47,7 @@ import java.util.List;
 public class GameTeamController extends BaseController {
 
     private final IGameTeamService gameTeamService;
+    private final IGameEventService gameEventService;
 
     /**
      * 查询参赛队伍列表
@@ -65,6 +68,13 @@ public class GameTeamController extends BaseController {
         ExcelResult<GameTeamVo> excelResult = null;
         try {
             excelResult = ExcelUtil.importExcel(file.getInputStream(), GameTeamVo.class, true);
+            Map<String, Long> eventIdNameMap = gameEventService.getEventIdNameMap();
+            excelResult.getList().stream().forEach(item -> {
+                //根据导入的赛事名称查询对应的赛事ID
+                if (eventIdNameMap.containsKey(item.getEventName())){
+                    item.setEventId(eventIdNameMap.get(item.getEventName()));
+                }
+            });
             List<GameTeam> list = MapstructUtils.convert(excelResult.getList(), GameTeam.class);
             gameTeamService.saveBatch(list);
         } catch (IOException e) {

+ 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;
 
     /**

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

@@ -298,6 +298,10 @@ public class GameTeamServiceImpl implements IGameTeamService {
                 .eq(GameTeam::getEventId, eventId)
                 .in(GameTeam::getTeamName, names)
         );
+        //批量添加队伍时,运动员列表为空列表而不是null
+        list.forEach(team -> {
+            team.setAthleteValue(new ArrayList<Long>().toString());
+        });
         if (count > 0) {
             throw new ServiceException("导入失败,有队伍名称重复");
         }