|
@@ -1,12 +1,26 @@
|
|
|
package org.dromara.system.controller;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
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.GameTeam;
|
|
|
+import org.dromara.system.domain.constant.GameEventConstant;
|
|
|
import org.dromara.system.domain.vo.AthleteScoreVo;
|
|
|
+import org.dromara.system.domain.vo.GameTeamVo;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
|
@@ -22,6 +36,7 @@ import org.dromara.system.domain.vo.GameAthleteVo;
|
|
|
import org.dromara.system.domain.bo.GameAthleteBo;
|
|
|
import org.dromara.system.service.IGameAthleteService;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
/**
|
|
|
* 参赛队员
|
|
@@ -29,6 +44,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
* @author zlt
|
|
|
* @date 2025-07-30
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Validated
|
|
|
@RequiredArgsConstructor
|
|
|
@RestController
|
|
@@ -57,6 +73,41 @@ public class GameAthleteController extends BaseController {
|
|
|
ExcelUtil.exportExcel(list, "参赛队员", GameAthleteVo.class, response);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导入参赛队员列表
|
|
|
+ */
|
|
|
+ @SaCheckPermission("system:gameAthlete:import")
|
|
|
+ @Log(title = "参赛队员", businessType = BusinessType.IMPORT)
|
|
|
+ @PostMapping("/import")
|
|
|
+ public R<Void> importExcel(@RequestPart("file") MultipartFile file) {
|
|
|
+ ExcelResult<GameAthleteVo> excelResult = null;
|
|
|
+ try {
|
|
|
+ // 从redis中获取默认参赛赛事
|
|
|
+ Long defaultEventId = Long.valueOf(RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID_KEY).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;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ gameAthleteService.saveOrEditBatch(list);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return R.ok(excelResult.getAnalysis());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取导入模板
|
|
|
+ */
|
|
|
+ @PostMapping("/importTemplate")
|
|
|
+ public void importTemplate(HttpServletResponse response) {
|
|
|
+ ExcelUtil.exportExcel(new ArrayList<>(), "参数队员数据", GameAthleteVo.class, response);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取参赛队员详细信息
|
|
|
*
|
|
@@ -76,7 +127,7 @@ public class GameAthleteController extends BaseController {
|
|
|
*/
|
|
|
@SaCheckPermission("system:gameAthlete:list")
|
|
|
@GetMapping("/listByEventId")
|
|
|
- public R<List<AthleteScoreVo>> getAthleteScoreList(@NotNull(message = "赛事ID不能为空") @RequestParam Long eventId){
|
|
|
+ public R<List<AthleteScoreVo>> getAthleteScoreList(@NotNull(message = "赛事ID不能为空") @RequestParam Long eventId) {
|
|
|
List<AthleteScoreVo> list = gameAthleteService.queryAthleteScoreList(eventId);
|
|
|
return R.ok(list);
|
|
|
}
|
|
@@ -115,4 +166,14 @@ public class GameAthleteController extends BaseController {
|
|
|
@PathVariable Long[] athleteIds) {
|
|
|
return toAjax(gameAthleteService.deleteWithValidByIds(List.of(athleteIds), true));
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ List<String> strings = List.of("1", "2", "3");
|
|
|
+ String str = JSONUtil.toJsonStr(strings);
|
|
|
+ System.out.println(str);
|
|
|
+ String s="["1","2","3"]"
|
|
|
+ List<String> list = JSONUtil.toList(str, String.class);
|
|
|
+ System.out.println(list);
|
|
|
+ }
|
|
|
}
|