|
|
@@ -3,15 +3,14 @@ package org.dromara.system.controller;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
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.common.redis.utils.RedisUtils;
|
|
|
-import org.dromara.system.domain.GameAthlete;
|
|
|
import org.dromara.system.domain.bo.ProjectSelectionValidationBo;
|
|
|
import org.dromara.system.domain.constant.GameEventConstant;
|
|
|
import org.dromara.system.domain.vo.AthleteScoreVo;
|
|
|
@@ -27,6 +26,7 @@ import org.dromara.common.core.validate.AddGroup;
|
|
|
import org.dromara.common.core.validate.EditGroup;
|
|
|
import org.dromara.common.log.enums.BusinessType;
|
|
|
import org.dromara.common.excel.utils.ExcelUtil;
|
|
|
+import org.dromara.system.domain.vo.GameAthleteImportVo;
|
|
|
import org.dromara.system.domain.vo.GameAthleteVo;
|
|
|
import org.dromara.system.domain.bo.GameAthleteBo;
|
|
|
import org.dromara.system.service.IGameAthleteService;
|
|
|
@@ -74,25 +74,26 @@ public class GameAthleteController extends BaseController {
|
|
|
@SaCheckPermission("system:gameAthlete:import")
|
|
|
@Log(title = "参赛队员", businessType = BusinessType.IMPORT)
|
|
|
@PostMapping("/import")
|
|
|
- public R<Void> importExcel(@RequestPart("file") MultipartFile file) {
|
|
|
- ExcelResult<GameAthleteVo> excelResult = null;
|
|
|
+ public R<String> importExcel(@RequestPart("file") MultipartFile file) {
|
|
|
try {
|
|
|
// 从redis中获取默认参赛赛事
|
|
|
- Long defaultEventId = Long.valueOf(RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID).toString());
|
|
|
- excelResult = ExcelUtil.importExcel(file.getInputStream(), GameAthleteVo.class, true);
|
|
|
- List<GameAthlete> list = MapstructUtils.convert(excelResult.getList(), GameAthlete.class);
|
|
|
- Long finalDefaultEventId = defaultEventId;
|
|
|
- list.stream()
|
|
|
- .map(gameAthlete -> {
|
|
|
- gameAthlete.setEventId(finalDefaultEventId);
|
|
|
- return gameAthlete;
|
|
|
- })
|
|
|
- .toList();
|
|
|
- gameAthleteService.saveOrEditBatch(list);
|
|
|
+ long defaultEventId = Long
|
|
|
+ .parseLong(RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID).toString());
|
|
|
+ ExcelResult<GameAthleteImportVo> excelResult = ExcelUtil.importExcel(file.getInputStream(),
|
|
|
+ GameAthleteImportVo.class, true);
|
|
|
+ if (excelResult == null || CollUtil.isEmpty(excelResult.getList())) {
|
|
|
+ return R.fail("导入数据不能为空");
|
|
|
+ }
|
|
|
+ // 调用新的业务逻辑方法
|
|
|
+ String message = gameAthleteService.importAthletes(excelResult.getList(), defaultEventId);
|
|
|
+ return R.ok(message);
|
|
|
} catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("读取导入文件失败", e);
|
|
|
+ return R.fail("导入失败,读取文件异常");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导入数据失败", e);
|
|
|
+ return R.fail(e.getMessage());
|
|
|
}
|
|
|
- return R.ok(excelResult.getAnalysis());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -100,7 +101,7 @@ public class GameAthleteController extends BaseController {
|
|
|
*/
|
|
|
@PostMapping("/importTemplate")
|
|
|
public void importTemplate(HttpServletResponse response) {
|
|
|
- ExcelUtil.exportExcel(new ArrayList<>(), "参数队员数据", GameAthleteVo.class, response);
|
|
|
+ ExcelUtil.exportExcel(new ArrayList<>(), "参赛队员导入模板", GameAthleteImportVo.class, response);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -110,8 +111,7 @@ public class GameAthleteController extends BaseController {
|
|
|
*/
|
|
|
@SaCheckPermission("system:gameAthlete:query")
|
|
|
@GetMapping("/{athleteId}")
|
|
|
- public R<GameAthleteVo> getInfo(@NotNull(message = "主键不能为空")
|
|
|
- @PathVariable Long athleteId) {
|
|
|
+ public R<GameAthleteVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long athleteId) {
|
|
|
return R.ok(gameAthleteService.queryById(athleteId));
|
|
|
}
|
|
|
|
|
|
@@ -157,8 +157,7 @@ public class GameAthleteController extends BaseController {
|
|
|
@SaCheckPermission("system:gameAthlete:remove")
|
|
|
@Log(title = "参赛队员", businessType = BusinessType.DELETE)
|
|
|
@DeleteMapping("/{athleteIds}")
|
|
|
- public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
|
|
- @PathVariable Long[] athleteIds) {
|
|
|
+ public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] athleteIds) {
|
|
|
return toAjax(gameAthleteService.deleteWithValidByIds(List.of(athleteIds), true));
|
|
|
}
|
|
|
|
|
|
@@ -171,15 +170,18 @@ public class GameAthleteController extends BaseController {
|
|
|
|
|
|
/**
|
|
|
* 根据项目ID获取参赛人数
|
|
|
+ *
|
|
|
* @param projectId 项目ID
|
|
|
*/
|
|
|
@GetMapping("/count/{projectId}")
|
|
|
- public R<Long> getAthleteCountByProjectId(@PathVariable Long projectId, @RequestParam(required = false) Long eventId) {
|
|
|
+ public R<Long> getAthleteCountByProjectId(@PathVariable Long projectId,
|
|
|
+ @RequestParam(required = false) Long eventId) {
|
|
|
return R.ok(gameAthleteService.selectAthleteCountByProjectId(eventId, projectId));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据项目ID分页查询队伍详细信息
|
|
|
+ *
|
|
|
* @param projectId 项目ID
|
|
|
*/
|
|
|
@GetMapping("/teamListByProject/{projectId}")
|