Parcourir la source

feat(game): 添加运动员和队伍编号唯一性校验- 在保存运动员信息前校验编号唯一性
- 在保存队伍信息前校验队伍编号唯一性- 添加 ServiceException 异常处理依赖
- 优化队伍名称和编号字段设置逻辑

zhou il y a 2 semaines
Parent
commit
daef5b2a4d

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

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.dromara.common.core.exception.ServiceException;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.PageQuery;
@@ -337,6 +338,14 @@ public class GameAthleteServiceImpl implements IGameAthleteService {
      */
     private void validEntityBeforeSave(GameAthlete entity) {
         //TODO 做一些数据校验,如唯一约束
+        //校验运动员编号是否存在重复值
+        if (entity.getAthleteCode() != null){
+            List<GameAthlete> list = baseMapper.selectList(new LambdaQueryWrapper<GameAthlete>()
+                .eq(GameAthlete::getAthleteCode, entity.getAthleteCode()));
+            if (!list.isEmpty()){
+                throw new ServiceException(entity.getName()+"的编号已存在!");
+            }
+        }
     }
 
     /**

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

@@ -357,11 +357,12 @@ public class GameScoreServiceImpl implements IGameScoreService {
             if (athlete.getTeamId() != null) {
                 GameTeamVo team = gameTeamService.queryById(athlete.getTeamId());
                 if (team != null) {
-                    teamName = team.getTeamName();
+                    data.put("teamName", team.getTeamName()); // 添加teamName字段
+                    data.put("teamCode", team.getTeamCode());
                     log.debug("获取到队伍名称: teamId={}, teamName={}", athlete.getTeamId(), teamName);
                 }
             }
-            data.put("teamName", teamName); // 添加teamName字段
+
 
             // 查询成绩信息
             GameScoreVo score = getScoreByAthleteIdAndProjectId(athlete.getAthleteId(), projectId);

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

@@ -266,6 +266,16 @@ public class GameTeamServiceImpl implements IGameTeamService {
      */
     private void validEntityBeforeSave(GameTeam entity) {
         //TODO 做一些数据校验,如唯一约束
+        //校验队伍编号的唯一性
+        if (entity.getTeamCode() != null){
+            Long count = baseMapper.selectCount(
+                Wrappers.lambdaQuery(GameTeam.class)
+                    .eq(GameTeam::getTeamCode, entity.getTeamCode())
+            );
+            if (count > 0) {
+                throw new ServiceException(entity.getTeamName()+"的编号已存在!");
+            }
+        }
     }
 
     /**