|
@@ -1,6 +1,8 @@
|
|
|
package org.dromara.system.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
@@ -17,10 +19,8 @@ import org.dromara.system.domain.GameEvent;
|
|
|
import org.dromara.system.domain.bo.GameEventBo;
|
|
|
import org.dromara.system.domain.constant.GameEventConstant;
|
|
|
import org.dromara.system.domain.vo.GameEventVo;
|
|
|
-import org.dromara.system.domain.vo.SysDictDataVo;
|
|
|
import org.dromara.system.mapper.GameEventMapper;
|
|
|
import org.dromara.system.service.IGameEventService;
|
|
|
-import org.dromara.system.service.ISysDictTypeService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.dromara.system.domain.bo.GameEventProjectBo;
|
|
|
import org.dromara.system.domain.vo.GameEventProjectVo;
|
|
@@ -28,7 +28,10 @@ import org.dromara.system.domain.GameEventProject;
|
|
|
import org.dromara.system.mapper.GameEventProjectMapper;
|
|
|
import org.dromara.system.service.IGameEventProjectService;
|
|
|
|
|
|
-import java.util.*;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -44,7 +47,6 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
|
|
|
private final GameEventProjectMapper baseMapper;
|
|
|
private final GameEventMapper gameEventMapper;
|
|
|
- private final ISysDictTypeService sysDictTypeService;
|
|
|
|
|
|
/**
|
|
|
* 查询赛事项目
|
|
@@ -54,7 +56,9 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
*/
|
|
|
@Override
|
|
|
public GameEventProjectVo queryById(Long projectId) {
|
|
|
- return baseMapper.selectVoById(projectId);
|
|
|
+ GameEventProjectVo vo = baseMapper.selectVoById(projectId);
|
|
|
+ vo.setRefereeIds(JSONUtil.toList(vo.getRefereeId(), String.class));
|
|
|
+ return vo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -66,22 +70,31 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
*/
|
|
|
@Override
|
|
|
public TableDataInfo<GameEventProjectVo> queryPageList(GameEventProjectBo bo, PageQuery pageQuery) {
|
|
|
- if (bo.getEventId() == null) {
|
|
|
+ if (bo.getEventId() == null){
|
|
|
bo.setEventId(RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID));
|
|
|
}
|
|
|
LambdaQueryWrapper<GameEventProject> lqw = buildQueryWrapper(bo);
|
|
|
Page<GameEventProjectVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
- result.getRecords().stream()
|
|
|
- .map(vo -> {
|
|
|
- Optional.ofNullable(vo.getEventId())
|
|
|
- .filter(ObjectUtil::isNotEmpty)
|
|
|
- .ifPresent(projectValue -> {
|
|
|
- GameEvent gameEvent = gameEventMapper.selectById(vo.getEventId());
|
|
|
+
|
|
|
+ // 使用 forEach 直接修改原对象
|
|
|
+ result.getRecords().forEach(vo -> {
|
|
|
+ Optional.ofNullable(vo.getEventId())
|
|
|
+ .filter(ObjectUtil::isNotEmpty)
|
|
|
+ .ifPresent(eventId -> {
|
|
|
+ GameEvent gameEvent = gameEventMapper.selectById(eventId);
|
|
|
+ if (gameEvent != null) {
|
|
|
vo.setEventName(gameEvent.getEventName());
|
|
|
- });
|
|
|
- return vo;
|
|
|
- })
|
|
|
- .collect(Collectors.toList()); // 收集结果
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Optional.ofNullable(vo.getRefereeId())
|
|
|
+ .filter(ObjectUtil::isNotEmpty)
|
|
|
+ .ifPresent(refereeIdStr -> {
|
|
|
+ List<String> refereeList = JSONUtil.toList(refereeIdStr.toString(), String.class);
|
|
|
+ vo.setRefereeIds(refereeList);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
return TableDataInfo.build(result);
|
|
|
}
|
|
|
|
|
@@ -93,7 +106,7 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
*/
|
|
|
@Override
|
|
|
public List<GameEventProjectVo> queryList(GameEventProjectBo bo) {
|
|
|
- if (bo.getEventId() == null) {
|
|
|
+ if (bo.getEventId() == null){
|
|
|
bo.setEventId(RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID));
|
|
|
}
|
|
|
LambdaQueryWrapper<GameEventProject> lqw = buildQueryWrapper(bo);
|
|
@@ -107,18 +120,18 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
lqw.eq(bo.getEventId() != null, GameEventProject::getEventId, bo.getEventId());
|
|
|
// 通过名称模糊查询
|
|
|
Optional.ofNullable(bo.getEventName())
|
|
|
- .ifPresent(eventName -> {
|
|
|
+ .ifPresent(eventName->{
|
|
|
List<GameEvent> gameEvents = gameEventMapper.selectList(
|
|
|
Wrappers.lambdaQuery(GameEvent.class)
|
|
|
.like(GameEvent::getEventName, bo.getEventName())
|
|
|
.select(GameEvent::getEventId)
|
|
|
);
|
|
|
- if (CollectionUtils.isNotEmpty(gameEvents)) {
|
|
|
+ if(CollectionUtils.isNotEmpty(gameEvents)){
|
|
|
List<Long> ids = gameEvents.stream()
|
|
|
.map(GameEvent::getEventId)
|
|
|
.collect(Collectors.toList());
|
|
|
lqw.in(GameEventProject::getEventId, ids);
|
|
|
- } else {
|
|
|
+ }else{
|
|
|
lqw.apply("1=0");
|
|
|
}
|
|
|
});
|
|
@@ -139,11 +152,14 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Boolean insertByBo(GameEventProjectBo bo) {
|
|
|
- if (bo.getEventId() == null) {
|
|
|
+ if (bo.getEventId() == null){
|
|
|
bo.setEventId(RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID));
|
|
|
}
|
|
|
GameEventProject add = MapstructUtils.convert(bo, GameEventProject.class);
|
|
|
validEntityBeforeSave(add);
|
|
|
+ if (StrUtil.isNotEmpty(bo.getRefereeId())) {
|
|
|
+ add.setRefereeId(JSONUtil.toJsonStr(bo.getRefereeIds()));
|
|
|
+ }
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
|
bo.setProjectId(add.getProjectId());
|
|
@@ -159,7 +175,7 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Boolean updateByBo(GameEventProjectBo bo) {
|
|
|
- if (bo.getEventId() == null) {
|
|
|
+ if (bo.getEventId() == null){
|
|
|
bo.setEventId(RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID));
|
|
|
}
|
|
|
GameEventProject update = MapstructUtils.convert(bo, GameEventProject.class);
|
|
@@ -204,32 +220,4 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
Wrappers.lambdaQuery(GameEventProject.class)
|
|
|
);
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public Map<String, List<String>> mapProjectTypeAndProject() {
|
|
|
- Long defaultEventId = RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID);
|
|
|
- List<GameEventProject> list = baseMapper.selectList(
|
|
|
- Wrappers.lambdaQuery(GameEventProject.class)
|
|
|
- .eq(GameEventProject::getEventId, defaultEventId)
|
|
|
- .select(GameEventProject::getProjectType, GameEventProject::getProjectName)
|
|
|
- );
|
|
|
-
|
|
|
- // 从字典中获取项目类型映射:projectType (dictValue) -> dictLabel
|
|
|
- List<SysDictDataVo> projectTypeDictList = sysDictTypeService.selectDictDataByType("game_project_type");
|
|
|
- Map<String, String> dictMap = projectTypeDictList.stream()
|
|
|
- .collect(Collectors.toMap(SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel));
|
|
|
-
|
|
|
- // 按照项目类型(中文 label)分组,每个类型对应一个项目名称列表
|
|
|
- Map<String, List<String>> result = new HashMap<>();
|
|
|
- for (GameEventProject project : list) {
|
|
|
- String projectType = project.getProjectType();
|
|
|
- String projectName = project.getProjectName();
|
|
|
- String label = dictMap.getOrDefault(projectType, projectType); // 使用中文标签作为 key
|
|
|
-
|
|
|
- // 将项目名添加到对应类型的列表中
|
|
|
- result.computeIfAbsent(label, k -> new ArrayList<>()).add(projectName);
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
}
|