update 优化 简化一些方法的写法

2.X
疯狂的狮子li 2 years ago
parent a3d3826118
commit 96f7482da5

@ -1,10 +1,10 @@
package com.ruoyi.common.dict.service.impl; package com.ruoyi.common.dict.service.impl;
import cn.dev33.satoken.context.SaHolder; import cn.dev33.satoken.context.SaHolder;
import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.constant.CacheConstants; import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.service.DictService; import com.ruoyi.common.core.service.DictService;
import com.ruoyi.common.core.utils.StreamUtils;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.api.RemoteDictService; import com.ruoyi.system.api.RemoteDictService;
import com.ruoyi.system.api.domain.SysDictData; import com.ruoyi.system.api.domain.SysDictData;
@ -45,7 +45,7 @@ public class DictServiceImpl implements DictService {
SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas); SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas);
} }
Map<String, String> map = CollStreamUtil.toMap(datas, SysDictData::getDictValue, SysDictData::getDictLabel); Map<String, String> map = StreamUtils.toMap(datas, SysDictData::getDictValue, SysDictData::getDictLabel);
if (StringUtils.containsAny(dictValue, separator)) { if (StringUtils.containsAny(dictValue, separator)) {
return Arrays.stream(dictValue.split(separator)) return Arrays.stream(dictValue.split(separator))
.map(v -> map.getOrDefault(v, StringUtils.EMPTY)) .map(v -> map.getOrDefault(v, StringUtils.EMPTY))
@ -73,7 +73,7 @@ public class DictServiceImpl implements DictService {
SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas); SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas);
} }
Map<String, String> map = CollStreamUtil.toMap(datas, SysDictData::getDictLabel, SysDictData::getDictValue); Map<String, String> map = StreamUtils.toMap(datas, SysDictData::getDictLabel, SysDictData::getDictValue);
if (StringUtils.containsAny(dictLabel, separator)) { if (StringUtils.containsAny(dictLabel, separator)) {
return Arrays.stream(dictLabel.split(separator)) return Arrays.stream(dictLabel.split(separator))
.map(l -> map.getOrDefault(l, StringUtils.EMPTY)) .map(l -> map.getOrDefault(l, StringUtils.EMPTY))

@ -2,6 +2,7 @@ package com.ruoyi.common.satoken.utils;
import cn.dev33.satoken.context.SaHolder; import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.enums.DeviceType; import com.ruoyi.common.core.enums.DeviceType;
@ -80,18 +81,12 @@ public class LoginHelper {
LoginUser loginUser = getLoginUser(); LoginUser loginUser = getLoginUser();
if (ObjectUtil.isNull(loginUser)) { if (ObjectUtil.isNull(loginUser)) {
String loginId = StpUtil.getLoginIdAsString(); String loginId = StpUtil.getLoginIdAsString();
String userId = null;
for (UserType value : UserType.values()) {
if (StringUtils.contains(loginId, value.getUserType())) {
String[] strs = StringUtils.split(loginId, JOIN_CODE); String[] strs = StringUtils.split(loginId, JOIN_CODE);
// 用户id在总是在最后 if (!ArrayUtil.containsAny(strs, UserType.values())) {
userId = strs[strs.length - 1];
}
}
if (StringUtils.isBlank(userId)) {
throw new UtilException("登录用户: LoginId异常 => " + loginId); throw new UtilException("登录用户: LoginId异常 => " + loginId);
} }
return Long.parseLong(userId); // 用户id在总是在最后
return Long.parseLong(strs[strs.length - 1]);
} }
return loginUser.getUserId(); return loginUser.getUserId();
} }

@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.utils.StreamUtils;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.TreeBuildUtils; import com.ruoyi.common.core.utils.TreeBuildUtils;
import com.ruoyi.common.satoken.utils.LoginHelper; import com.ruoyi.common.satoken.utils.LoginHelper;
@ -426,13 +427,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
* *
*/ */
private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t) { private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t) {
List<SysMenu> tlist = new ArrayList<SysMenu>(); return StreamUtils.filter(list, n -> n.getParentId().equals(t.getMenuId()));
for (SysMenu n : list) {
if (n.getParentId().longValue() == t.getMenuId().longValue()) {
tlist.add(n);
}
}
return tlist;
} }
/** /**

Loading…
Cancel
Save