⚡ 一点微不足道的优化
This commit is contained in:
1 parent
2adebc1304
commit
0eb14f1bf4
6 files changed
+59
-16
No files matched your search
+10
-2
@@ -8,6 +8,7 @@ import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.KeyStrResolver;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.core.util.RetOps;
|
||||
import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -26,6 +27,7 @@ import org.springframework.security.oauth2.provider.token.TokenStore;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -85,10 +87,16 @@ public class PigxTokenDealServiceImpl {
|
||||
* @return R
|
||||
*/
|
||||
public R queryTokenByUsername(Page page, String username) {
|
||||
List<OAuth2AccessToken> oAuth2AccessTokenList = clientDetailsService
|
||||
.listClientDetails(SecurityConstants.FROM_IN).getData().stream().map(SysOauthClientDetails::getClientId)
|
||||
// @formatter:off
|
||||
List<OAuth2AccessToken> oAuth2AccessTokenList =
|
||||
RetOps.of(clientDetailsService.listClientDetails(SecurityConstants.FROM_IN))
|
||||
.getData()
|
||||
.orElseGet(Collections::emptyList)
|
||||
.stream().map(SysOauthClientDetails::getClientId)
|
||||
.flatMap(clientId -> tokenStore.findTokensByClientIdAndUserName(clientId, username).stream()).distinct()
|
||||
.collect(Collectors.toList());
|
||||
// @formatter:on
|
||||
|
||||
page.setRecords(oAuth2AccessTokenList);
|
||||
page.setTotal(oAuth2AccessTokenList.size());
|
||||
return R.ok(page);
|
||||
|
||||
+14
-2
@@ -23,12 +23,14 @@ import com.pig4cloud.pigx.admin.api.entity.SysDeptRelation;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRole;
|
||||
import com.pig4cloud.pigx.admin.api.feign.RemoteDataScopeService;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.RetOps;
|
||||
import com.pig4cloud.pigx.common.security.service.PigxUser;
|
||||
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -59,8 +61,13 @@ public class PigxDefaultDatascopeHandle implements DataScopeHandle {
|
||||
if (CollectionUtil.isEmpty(roleIdList)) {
|
||||
return false;
|
||||
}
|
||||
SysRole role = dataScopeService.getRoleList(roleIdList).getData().stream()
|
||||
// @formatter:off
|
||||
SysRole role = RetOps.of(dataScopeService.getRoleList(roleIdList))
|
||||
.getData()
|
||||
.orElseGet(Collections::emptyList)
|
||||
.stream()
|
||||
.min(Comparator.comparingInt(SysRole::getDsType)).orElse(null);
|
||||
// @formatter:on
|
||||
// 角色有可能已经删除了
|
||||
if (role == null) {
|
||||
return false;
|
||||
@@ -78,8 +85,13 @@ public class PigxDefaultDatascopeHandle implements DataScopeHandle {
|
||||
}
|
||||
// 查询本级及其下级
|
||||
if (DataScopeTypeEnum.OWN_CHILD_LEVEL.getType() == dsType) {
|
||||
List<Long> deptIdList = dataScopeService.getDescendantList(user.getDeptId()).getData().stream()
|
||||
// @formatter:off
|
||||
List<Long> deptIdList = RetOps.of(dataScopeService.getDescendantList(user.getDeptId()))
|
||||
.getData()
|
||||
.orElseGet(Collections::emptyList)
|
||||
.stream()
|
||||
.map(SysDeptRelation::getDescendant).collect(Collectors.toList());
|
||||
// @formatter:on
|
||||
deptList.addAll(deptIdList);
|
||||
}
|
||||
// 只查询本级
|
||||
|
||||
+15
-4
@@ -22,6 +22,7 @@ import com.pig4cloud.pigx.admin.api.entity.SysUser;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.core.util.RetOps;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
@@ -62,13 +63,23 @@ public interface PigxUserDetailsService extends UserDetailsService, Ordered {
|
||||
* 构建userdetails
|
||||
* @param result 用户信息
|
||||
* @return UserDetails
|
||||
* @throws UsernameNotFoundException
|
||||
*/
|
||||
default UserDetails getUserDetails(R<UserInfo> result) {
|
||||
if (result == null || result.getData() == null) {
|
||||
throw new UsernameNotFoundException("用户不存在");
|
||||
}
|
||||
// @formatter:off
|
||||
return RetOps.of(result)
|
||||
.getData()
|
||||
.map(this::convertUserDetails)
|
||||
.orElseThrow(() -> new UsernameNotFoundException("用户不存在"));
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
UserInfo info = result.getData();
|
||||
/**
|
||||
* UserInfo 转 UserDetails
|
||||
* @param info
|
||||
* @return 返回UserDetails对象
|
||||
*/
|
||||
default UserDetails convertUserDetails(UserInfo info) {
|
||||
Set<String> dbAuthsSet = new HashSet<>();
|
||||
if (ArrayUtil.isNotEmpty(info.getRoles())) {
|
||||
// 获取角色
|
||||
|
||||
+2
-1
@@ -62,6 +62,7 @@ public interface RemoteTokenService {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/token/query-token")
|
||||
R queryToken(@RequestParam("token") String token, @RequestHeader(SecurityConstants.FROM) String from);
|
||||
R<Map<String, Object>> queryToken(@RequestParam("token") String token,
|
||||
@RequestHeader(SecurityConstants.FROM) String from);
|
||||
|
||||
}
|
||||
+7
-5
@@ -4,6 +4,7 @@ import com.pig4cloud.pigx.admin.api.feign.RemoteTokenService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.core.util.RetOps;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jeecg.modules.jmreport.api.JmReportTokenServiceI;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -24,11 +25,12 @@ public class JimuReportTokenService implements JmReportTokenServiceI {
|
||||
|
||||
@Override
|
||||
public String getUsername(String token) {
|
||||
R<Map<String, Object>> result = tokenService.queryToken(token, SecurityConstants.FROM_IN);
|
||||
if (CommonConstants.SUCCESS.equals(result.getCode())) {
|
||||
return (String) result.getData().get("username");
|
||||
}
|
||||
return null;
|
||||
// @formatter:off
|
||||
return RetOps.of(tokenService.queryToken(token, SecurityConstants.FROM_IN))
|
||||
.getDataIf(RetOps.CODE_SUCCESS)
|
||||
.map(o -> (String)o.get("username"))
|
||||
.orElse(null);
|
||||
// @formatter:off
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+11
-2
@@ -4,6 +4,7 @@ import com.google.common.collect.Maps;
|
||||
import com.pig4cloud.pigx.admin.api.feign.RemoteTenantService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.RetOps;
|
||||
import com.pig4cloud.pigx.common.data.tenant.TenantBroker;
|
||||
import com.pig4cloud.pigx.mp.entity.WxAccount;
|
||||
import com.pig4cloud.pigx.mp.handler.*;
|
||||
@@ -23,6 +24,8 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -85,8 +88,14 @@ public class WxMpInitConfigRunner {
|
||||
public void initServices() {
|
||||
// 获取全部租户 遍历所有租户对应的公众号列表
|
||||
List<WxAccount> accountList = new ArrayList<>();
|
||||
tenantService.list(SecurityConstants.FROM_IN).getData().forEach(
|
||||
tenant -> TenantBroker.runAs(tenant.getId(), (id) -> accountList.addAll(accountService.list())));
|
||||
// @formatter:off
|
||||
RetOps.of(tenantService.list(SecurityConstants.FROM_IN))
|
||||
.getData()
|
||||
.orElseGet(Collections::emptyList)
|
||||
.forEach(
|
||||
tenant -> TenantBroker.runAs(tenant.getId(), (id) -> accountList.addAll(accountService.list()))
|
||||
);
|
||||
// @formatter:on
|
||||
|
||||
mpServices = accountList.stream().map(a -> {
|
||||
WxMpInRedisConfigStorage configStorage = new WxMpInRedisConfigStorage(redisTemplate);
|
||||
|
||||
Reference in new issue
Block a user