|
@@ -3,20 +3,25 @@ package org.dromara.system.service.impl.app;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.system.domain.GameAthlete;
|
|
|
import org.dromara.system.domain.GameEventProject;
|
|
|
import org.dromara.system.domain.GameScore;
|
|
|
+import org.dromara.system.domain.bo.GameAthleteBo;
|
|
|
import org.dromara.system.domain.vo.app.PhysicalDeviceVo;
|
|
|
import org.dromara.system.domain.vo.app.PhysicalTestVo;
|
|
|
import org.dromara.system.mapper.GameAthleteMapper;
|
|
|
import org.dromara.system.mapper.GameEventProjectMapper;
|
|
|
import org.dromara.system.mapper.GameScoreMapper;
|
|
|
+import org.dromara.system.service.IGameAthleteService;
|
|
|
import org.dromara.system.service.app.IPhysicalTestService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -34,6 +39,7 @@ public class PhysicalTestServiceImpl implements IPhysicalTestService {
|
|
|
|
|
|
private final GameEventProjectMapper projectMapper;
|
|
|
private final GameAthleteMapper athleteMapper;
|
|
|
+ private final IGameAthleteService athleteService;
|
|
|
private final GameScoreMapper scoreMapper;
|
|
|
|
|
|
@Override
|
|
@@ -51,7 +57,7 @@ public class PhysicalTestServiceImpl implements IPhysicalTestService {
|
|
|
log.debug("项目处理完成,projectId: {}", projectId);
|
|
|
|
|
|
// 2. 处理运动员数据
|
|
|
- Long athleteId = processAthlete(result, eventId);
|
|
|
+ Long athleteId = processAthlete(result, eventId,projectId);
|
|
|
log.debug("运动员处理完成,athleteId: {}", athleteId);
|
|
|
|
|
|
// 3. 处理成绩数据
|
|
@@ -82,7 +88,7 @@ public class PhysicalTestServiceImpl implements IPhysicalTestService {
|
|
|
log.debug("处理设备记录: stuNo={}, name={}", record.getStuNo(), record.getName());
|
|
|
|
|
|
// 3. 处理运动员数据 - 根据stuNo作为身份证号查找或创建运动员
|
|
|
- Long athleteId = processDeviceAthlete(record, eventId);
|
|
|
+ Long athleteId = processDeviceAthlete(record, eventId, projectId);
|
|
|
log.debug("设备运动员处理完成,athleteId: {}", athleteId);
|
|
|
|
|
|
// 4. 处理成绩数据 - 将testTime、resultData、referee存为JSON
|
|
@@ -144,7 +150,7 @@ public class PhysicalTestServiceImpl implements IPhysicalTestService {
|
|
|
/**
|
|
|
* 处理运动员数据
|
|
|
*/
|
|
|
- private Long processAthlete(PhysicalTestVo result, Long eventId) {
|
|
|
+ private Long processAthlete(PhysicalTestVo result, Long eventId, Long projectId) {
|
|
|
// 根据身份证号查找运动员
|
|
|
LambdaQueryWrapper<GameAthlete> athleteWrapper = Wrappers.lambdaQuery(GameAthlete.class)
|
|
|
.eq(GameAthlete::getEventId, eventId)
|
|
@@ -160,19 +166,23 @@ public class PhysicalTestServiceImpl implements IPhysicalTestService {
|
|
|
log.info("要更新的运动员姓名不符: {} -> {}", existingAthlete.getName(), result.getName());
|
|
|
throw new RuntimeException("要更新的运动员姓名不符");
|
|
|
}
|
|
|
+ // 更新项目列表
|
|
|
+ updateAthleteProjectList(existingAthlete, projectId);
|
|
|
return existingAthlete.getAthleteId();
|
|
|
} else {
|
|
|
// 创建新运动员
|
|
|
log.info("创建新运动员: name={}, idCard={}", result.getName(), result.getUserId());
|
|
|
- GameAthlete newAthlete = new GameAthlete();
|
|
|
+ GameAthleteBo newAthlete = new GameAthleteBo();
|
|
|
newAthlete.setEventId(eventId);
|
|
|
newAthlete.setIdCard(result.getUserId());
|
|
|
newAthlete.setName(result.getName());
|
|
|
+ // 初始化项目列表并添加项目ID
|
|
|
+ newAthlete.setProjectList(new ArrayList<>());
|
|
|
+ newAthlete.getProjectList().add(projectId.toString());
|
|
|
newAthlete.setStatus("0"); // 正常状态
|
|
|
- newAthlete.setDelFlag("0");
|
|
|
|
|
|
- int insertResult = athleteMapper.insert(newAthlete);
|
|
|
- if (insertResult > 0) {
|
|
|
+ boolean res = athleteService.insertByBo(newAthlete);
|
|
|
+ if (res) {
|
|
|
log.info("新运动员创建成功,athleteId: {}", newAthlete.getAthleteId());
|
|
|
return newAthlete.getAthleteId();
|
|
|
} else {
|
|
@@ -206,7 +216,6 @@ public class PhysicalTestServiceImpl implements IPhysicalTestService {
|
|
|
log.info("更新现有成绩记录,scoreId: {}, 新分数: {}", existingScore.getScoreId(), result.getResultScore());
|
|
|
existingScore.setIndividualPerformance(result.getResultScore());
|
|
|
existingScore.setRemark(remarkJson);
|
|
|
- existingScore.setStatusFlag("1"); // 处理完毕
|
|
|
scoreMapper.updateById(existingScore);
|
|
|
} else {
|
|
|
// 创建新成绩记录
|
|
@@ -219,7 +228,6 @@ public class PhysicalTestServiceImpl implements IPhysicalTestService {
|
|
|
newScore.setIndividualPerformance(result.getResultScore());
|
|
|
newScore.setRemark(remarkJson);
|
|
|
newScore.setScoreType("physicalTest"); // 默认成绩类型
|
|
|
- newScore.setStatusFlag("1"); // 处理完毕
|
|
|
newScore.setStatus("0"); // 正常状态
|
|
|
newScore.setDelFlag("0");
|
|
|
|
|
@@ -251,14 +259,14 @@ public class PhysicalTestServiceImpl implements IPhysicalTestService {
|
|
|
} else {
|
|
|
log.error(testName + "项目不存在"); //不能创建项目,因为没有项目key
|
|
|
throw new RuntimeException(testName + "项目不存在");
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 处理设备运动员数据
|
|
|
*/
|
|
|
- private Long processDeviceAthlete(PhysicalDeviceVo.Record record, Long eventId) {
|
|
|
+ private Long processDeviceAthlete(PhysicalDeviceVo.Record record, Long eventId, Long projectId) {
|
|
|
// 根据stuNo作为身份证号查找运动员
|
|
|
LambdaQueryWrapper<GameAthlete> athleteWrapper = Wrappers.lambdaQuery(GameAthlete.class)
|
|
|
.eq(GameAthlete::getEventId, eventId)
|
|
@@ -274,19 +282,23 @@ public class PhysicalTestServiceImpl implements IPhysicalTestService {
|
|
|
log.info("要更新的运动员姓名不符: {} -> {}", existingAthlete.getName(), record.getName());
|
|
|
throw new RuntimeException("要更新的运动员姓名不符");
|
|
|
}
|
|
|
+ // 更新项目列表
|
|
|
+ updateAthleteProjectList(existingAthlete, projectId);
|
|
|
return existingAthlete.getAthleteId();
|
|
|
} else {
|
|
|
// 创建新运动员
|
|
|
log.info("创建新运动员: name={}, stuNo={}", record.getName(), record.getStuNo());
|
|
|
- GameAthlete newAthlete = new GameAthlete();
|
|
|
+ GameAthleteBo newAthlete = new GameAthleteBo();
|
|
|
newAthlete.setEventId(eventId);
|
|
|
newAthlete.setIdCard(record.getStuNo()); // stuNo映射到IdCard
|
|
|
newAthlete.setName(record.getName()); // name映射到name
|
|
|
+ // 初始化项目列表并添加项目ID
|
|
|
+ newAthlete.setProjectList(new ArrayList<>());
|
|
|
+ newAthlete.getProjectList().add(projectId.toString());
|
|
|
newAthlete.setStatus("0"); // 正常状态
|
|
|
- newAthlete.setDelFlag("0");
|
|
|
|
|
|
- int insertResult = athleteMapper.insert(newAthlete);
|
|
|
- if (insertResult > 0) {
|
|
|
+ boolean res = athleteService.insertByBo(newAthlete);
|
|
|
+ if (res) {
|
|
|
log.info("新运动员创建成功,athleteId: {}", newAthlete.getAthleteId());
|
|
|
return newAthlete.getAthleteId();
|
|
|
} else {
|
|
@@ -320,7 +332,6 @@ public class PhysicalTestServiceImpl implements IPhysicalTestService {
|
|
|
// 更新现有成绩
|
|
|
log.info("更新现有成绩记录,scoreId: {}", existingScore.getScoreId());
|
|
|
existingScore.setRemark(remarkJson);
|
|
|
- existingScore.setStatusFlag("1"); // 处理完毕
|
|
|
scoreMapper.updateById(existingScore);
|
|
|
} else {
|
|
|
// 创建新成绩记录
|
|
@@ -331,7 +342,6 @@ public class PhysicalTestServiceImpl implements IPhysicalTestService {
|
|
|
newScore.setAthleteId(athleteId);
|
|
|
newScore.setRemark(remarkJson);
|
|
|
newScore.setScoreType("physicalDevice"); // 默认成绩类型
|
|
|
- newScore.setStatusFlag("1"); // 处理完毕
|
|
|
newScore.setStatus("0"); // 正常状态
|
|
|
newScore.setDelFlag("0");
|
|
|
|
|
@@ -344,4 +354,33 @@ public class PhysicalTestServiceImpl implements IPhysicalTestService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新运动员的项目列表
|
|
|
+ */
|
|
|
+ private void updateAthleteProjectList(GameAthlete athlete, Long projectId) {
|
|
|
+ try {
|
|
|
+ // 解析现有的项目列表
|
|
|
+ List<String> projectList = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotBlank(athlete.getProjectValue())) {
|
|
|
+ projectList = JSONUtil.toList(athlete.getProjectValue(), String.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查项目是否已存在
|
|
|
+ String projectIdStr = projectId.toString();
|
|
|
+ if (!projectList.contains(projectIdStr)) {
|
|
|
+ projectList.add(projectIdStr);
|
|
|
+
|
|
|
+ // 转换为Bo对象并更新
|
|
|
+ GameAthleteBo athleteBo = MapstructUtils.convert(athlete, GameAthleteBo.class);
|
|
|
+ athleteBo.setProjectList(projectList);
|
|
|
+
|
|
|
+ athleteService.updateByBo(athleteBo);
|
|
|
+ log.info("已为运动员 {} 添加项目 {}", athlete.getName(), projectIdStr);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("更新运动员项目列表失败", e);
|
|
|
+ // 这里不抛异常,避免影响主流程
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|