|
@@ -1,5 +1,6 @@
|
|
|
package org.dromara.system.service.impl;
|
|
package org.dromara.system.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
@@ -18,6 +19,7 @@ import org.dromara.system.domain.GameRankGroup;
|
|
|
import org.dromara.system.mapper.GameRankGroupMapper;
|
|
import org.dromara.system.mapper.GameRankGroupMapper;
|
|
|
import org.dromara.system.service.IGameRankGroupService;
|
|
import org.dromara.system.service.IGameRankGroupService;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
@@ -43,7 +45,7 @@ public class GameRankGroupServiceImpl implements IGameRankGroupService {
|
|
|
* @return 排名分组
|
|
* @return 排名分组
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
- public GameRankGroupVo queryById(Long rgId){
|
|
|
|
|
|
|
+ public GameRankGroupVo queryById(Long rgId) {
|
|
|
return baseMapper.selectVoById(rgId);
|
|
return baseMapper.selectVoById(rgId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -59,7 +61,7 @@ public class GameRankGroupServiceImpl implements IGameRankGroupService {
|
|
|
if (bo.getEventId() == null) {
|
|
if (bo.getEventId() == null) {
|
|
|
Object cacheObject = RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID);
|
|
Object cacheObject = RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID);
|
|
|
if (cacheObject instanceof Integer) {
|
|
if (cacheObject instanceof Integer) {
|
|
|
- bo.setEventId(((Integer) cacheObject).longValue()); // 显式转换为 Long 类型
|
|
|
|
|
|
|
+ bo.setEventId(((Integer) cacheObject).longValue()); // 显式转换为 Long 类型
|
|
|
} else if (cacheObject instanceof Long) {
|
|
} else if (cacheObject instanceof Long) {
|
|
|
bo.setEventId((Long) cacheObject);
|
|
bo.setEventId((Long) cacheObject);
|
|
|
}
|
|
}
|
|
@@ -84,8 +86,9 @@ public class GameRankGroupServiceImpl implements IGameRankGroupService {
|
|
|
private LambdaQueryWrapper<GameRankGroup> buildQueryWrapper(GameRankGroupBo bo) {
|
|
private LambdaQueryWrapper<GameRankGroup> buildQueryWrapper(GameRankGroupBo bo) {
|
|
|
Map<String, Object> params = bo.getParams();
|
|
Map<String, Object> params = bo.getParams();
|
|
|
LambdaQueryWrapper<GameRankGroup> lqw = Wrappers.lambdaQuery();
|
|
LambdaQueryWrapper<GameRankGroup> lqw = Wrappers.lambdaQuery();
|
|
|
- lqw.orderByAsc(GameRankGroup::getRgId);
|
|
|
|
|
|
|
+ lqw.orderByAsc(GameRankGroup::getCreateTime);
|
|
|
lqw.eq(bo.getEventId() != null, GameRankGroup::getEventId, bo.getEventId());
|
|
lqw.eq(bo.getEventId() != null, GameRankGroup::getEventId, bo.getEventId());
|
|
|
|
|
+ lqw.eq(bo.getParentId() != null, GameRankGroup::getParentId, bo.getParentId());
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getRgName()), GameRankGroup::getRgName, bo.getRgName());
|
|
lqw.like(StringUtils.isNotBlank(bo.getRgName()), GameRankGroup::getRgName, bo.getRgName());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), GameRankGroup::getStatus, bo.getStatus());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), GameRankGroup::getStatus, bo.getStatus());
|
|
|
return lqw;
|
|
return lqw;
|
|
@@ -100,7 +103,21 @@ public class GameRankGroupServiceImpl implements IGameRankGroupService {
|
|
|
@Override
|
|
@Override
|
|
|
public Boolean insertByBo(GameRankGroupBo bo) {
|
|
public Boolean insertByBo(GameRankGroupBo bo) {
|
|
|
GameRankGroup add = MapstructUtils.convert(bo, GameRankGroup.class);
|
|
GameRankGroup add = MapstructUtils.convert(bo, GameRankGroup.class);
|
|
|
|
|
+
|
|
|
validEntityBeforeSave(add);
|
|
validEntityBeforeSave(add);
|
|
|
|
|
+
|
|
|
|
|
+ // 设置祖级列表
|
|
|
|
|
+ if (add.getParentId() != 0) {
|
|
|
|
|
+ GameRankGroup parent = baseMapper.selectById(add.getParentId());
|
|
|
|
|
+ if (parent != null) {
|
|
|
|
|
+ add.setAncestors(parent.getAncestors() + "," + parent.getRgId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ add.setAncestors("0");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ add.setAncestors("0");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
if (flag) {
|
|
|
bo.setRgId(add.getRgId());
|
|
bo.setRgId(add.getRgId());
|
|
@@ -118,14 +135,53 @@ public class GameRankGroupServiceImpl implements IGameRankGroupService {
|
|
|
public Boolean updateByBo(GameRankGroupBo bo) {
|
|
public Boolean updateByBo(GameRankGroupBo bo) {
|
|
|
GameRankGroup update = MapstructUtils.convert(bo, GameRankGroup.class);
|
|
GameRankGroup update = MapstructUtils.convert(bo, GameRankGroup.class);
|
|
|
validEntityBeforeSave(update);
|
|
validEntityBeforeSave(update);
|
|
|
|
|
+
|
|
|
|
|
+ GameRankGroup oldEntity = baseMapper.selectById(update.getRgId());
|
|
|
|
|
+ // 如果修改了上级,需要更新所有下级的祖级列表
|
|
|
|
|
+ if (oldEntity != null && !oldEntity.getParentId().equals(update.getParentId())) {
|
|
|
|
|
+ // 设置新的祖级列表
|
|
|
|
|
+ if (update.getParentId() != 0) {
|
|
|
|
|
+ GameRankGroup parent = baseMapper.selectById(update.getParentId());
|
|
|
|
|
+ if (parent != null) {
|
|
|
|
|
+ update.setAncestors(parent.getAncestors() + "," + parent.getRgId());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ update.setAncestors("0");
|
|
|
|
|
+ }
|
|
|
|
|
+ updateChildrenAncestors(update.getRgId(), update.getAncestors(), oldEntity.getAncestors());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return baseMapper.updateById(update) > 0;
|
|
return baseMapper.updateById(update) > 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新子元素祖级列表
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param rgId 当前ID
|
|
|
|
|
+ * @param newAncestors 新祖级列表
|
|
|
|
|
+ * @param oldAncestors 旧祖级列表
|
|
|
|
|
+ */
|
|
|
|
|
+ private void updateChildrenAncestors(Long rgId, String newAncestors, String oldAncestors) {
|
|
|
|
|
+ List<GameRankGroup> list = baseMapper.selectList(Wrappers.<GameRankGroup>lambdaQuery()
|
|
|
|
|
+ .like(GameRankGroup::getAncestors, oldAncestors + "," + rgId));
|
|
|
|
|
+ if (CollUtil.isNotEmpty(list)) {
|
|
|
|
|
+ for (GameRankGroup child : list) {
|
|
|
|
|
+ child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
|
|
|
|
|
+ }
|
|
|
|
|
+ baseMapper.updateById(list);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 保存前的数据校验
|
|
* 保存前的数据校验
|
|
|
*/
|
|
*/
|
|
|
- private void validEntityBeforeSave(GameRankGroup entity){
|
|
|
|
|
- //TODO 做一些数据校验,如唯一约束
|
|
|
|
|
|
|
+ private void validEntityBeforeSave(GameRankGroup entity) {
|
|
|
|
|
+ if (entity.getParentId() == null) {
|
|
|
|
|
+ entity.setParentId(0L);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (entity.getRgId() != null && entity.getRgId().equals(entity.getParentId())) {
|
|
|
|
|
+ throw new RuntimeException("上级分组不能是自己");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -137,9 +193,65 @@ public class GameRankGroupServiceImpl implements IGameRankGroupService {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
- if(isValid){
|
|
|
|
|
- //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
|
|
|
|
+ if (isValid) {
|
|
|
|
|
+ for (Long id : ids) {
|
|
|
|
|
+ if (hasChildByRgId(id)) {
|
|
|
|
|
+ throw new RuntimeException("存在下级分组,不允许删除");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<GameRankGroupVo> buildTree(List<GameRankGroupVo> groups) {
|
|
|
|
|
+ List<GameRankGroupVo> returnList = new ArrayList<>();
|
|
|
|
|
+ List<Long> tempList = groups.stream().map(GameRankGroupVo::getRgId).toList();
|
|
|
|
|
+ for (GameRankGroupVo group : groups) {
|
|
|
|
|
+ // 如果是顶级节点, 遍历该父节点的所有子节点
|
|
|
|
|
+ if (!tempList.contains(group.getParentId())) {
|
|
|
|
|
+ recursionFn(groups, group);
|
|
|
|
|
+ returnList.add(group);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (returnList.isEmpty()) {
|
|
|
|
|
+ returnList = groups;
|
|
|
|
|
+ }
|
|
|
|
|
+ return returnList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean hasChildByRgId(Long rgId) {
|
|
|
|
|
+ return baseMapper.exists(Wrappers.<GameRankGroup>lambdaQuery().eq(GameRankGroup::getParentId, rgId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 递归列表
|
|
|
|
|
+ */
|
|
|
|
|
+ private void recursionFn(List<GameRankGroupVo> list, GameRankGroupVo t) {
|
|
|
|
|
+ // 得到子节点列表
|
|
|
|
|
+ List<GameRankGroupVo> childList = getChildList(list, t);
|
|
|
|
|
+ t.setChildren(childList);
|
|
|
|
|
+ for (GameRankGroupVo tChild : childList) {
|
|
|
|
|
+ if (hasChild(list, tChild)) {
|
|
|
|
|
+ recursionFn(list, tChild);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 得到子节点列表
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<GameRankGroupVo> getChildList(List<GameRankGroupVo> list, GameRankGroupVo t) {
|
|
|
|
|
+ return list.stream()
|
|
|
|
|
+ .filter(n -> n.getParentId() != null && n.getParentId().equals(t.getRgId()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 判断是否有子节点
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean hasChild(List<GameRankGroupVo> list, GameRankGroupVo t) {
|
|
|
|
|
+ return !getChildList(list, t).isEmpty();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|