Parcourir la source

Merge branch 'develop' of gitadmin/tuoheng_oidc into release

tags/v2.5.3
xuziqing il y a 11 mois
Parent
révision
60c4a3e282
3 fichiers modifiés avec 55 ajouts et 7 suppressions
  1. +1
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/mapper/AuthoritiesMapper.java
  2. +42
    -6
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/TenantServiceImpl.java
  3. +12
    -1
      tuoheng_oidc_admin/src/main/resources/mapper/AuthoritiesMapper.xml

+ 1
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/mapper/AuthoritiesMapper.java Voir le fichier

@@ -25,4 +25,5 @@ public interface AuthoritiesMapper {

void deleteByUserIdAndClient(Long userId, String clientId);

List<AuthoritiesPo> selectByUserIdsAndClient(@Param("list") List<Long> userIdList,@Param("clientId") String clientId);
}

+ 42
- 6
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/TenantServiceImpl.java Voir le fichier

@@ -9,12 +9,12 @@ import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.org.apache.regexp.internal.RE;
import com.tuoheng.common.CommonConfig;
import com.tuoheng.common.ServiceException;
import com.tuoheng.common.ServiceExceptionEnum;
import com.tuoheng.constant.CommonConstant;
import com.tuoheng.constant.DictConstant;
import com.tuoheng.constant.TenantConstant;
import com.tuoheng.enums.MarkTypeEnum;
import com.tuoheng.mapper.*;
import com.tuoheng.model.dto.LoginUser;
@@ -40,7 +40,6 @@ import com.tuoheng.third.service.impl.ThirdServiceImpl;
import com.tuoheng.until.JacksonUtil;
import com.tuoheng.until.JsonResult;
import com.tuoheng.until.MapUtils;
import com.tuoheng.until.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -56,6 +55,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
@@ -337,12 +337,20 @@ public class TenantServiceImpl implements TenantService {
query.checkParam();
//开启分页
List<TenantVo> tenantVos = tenantMapper.findList(query);
//公共数据预热 ,避免循环中复杂查询导致接口响应时间过长
Map<Long, TenantItem> tenantItemMap = getTenantItemMap(tenantVos);
Map<Long, List<AuthoritiesPo>> authoritiesPoMap = getAuthoritiesPoMap(tenantVos, query.getClientId());
List<DictData> dictDataList = dictDataMapper.selectList(Wrappers.<DictData>lambdaQuery()
.eq(DictData::getMark, MarkTypeEnum.VALID.getCode()).eq(DictData::getCode, DictConstant.CLIENT));


List<TenantVo> collect = tenantVos.stream().map(x -> {
TenantVo vo = new TenantVo();
BeanUtils.copyProperties(x, vo);
//并不是真正意义上的租户id
vo.setTenantId(x.getUserId());
TenantItem tenantItem = tenantItemMapper.selectOne(Wrappers.<TenantItem>lambdaQuery().eq(TenantItem::getTenantId, x.getId()));
//TenantItem tenantItem = tenantItemMapper.selectOne(Wrappers.<TenantItem>lambdaQuery().eq(TenantItem::getTenantId, x.getId()));
TenantItem tenantItem = tenantItemMap.get(x.getId());
if (ObjectUtil.isNotNull(tenantItem)) {
//获取有效期等
vo.setEffectiveDate(DateUtil.formatDate(tenantItem.getBeginTime()) + CommonConstant.TILDE + DateUtil.formatDate(tenantItem.getEndTime()));
@@ -365,7 +373,8 @@ public class TenantServiceImpl implements TenantService {
vo.setRemainDays(day);
}
//此处userId = tenantId 效果一致
List<AuthoritiesPo> poList = authoritiesMapper.selectListByUserIdAndClientId(x.getUserId(), query);
//List<AuthoritiesPo> poList = authoritiesMapper.selectListByUserIdAndClientId(x.getUserId(), query);
List<AuthoritiesPo> poList = authoritiesPoMap.get(x.getUserId());
if (ObjectUtil.isEmpty(poList)) {
return null;
}
@@ -374,8 +383,6 @@ public class TenantServiceImpl implements TenantService {
List<BusinessSystemVo> businessSystemVoList = new ArrayList<>();
for (AuthoritiesPo authoritiesPo : list) {
//TODO 后期维护各个业务平台
List<DictData> dictDataList = dictDataMapper.selectList(Wrappers.<DictData>lambdaQuery()
.eq(DictData::getMark, MarkTypeEnum.VALID.getCode()).eq(DictData::getCode, DictConstant.CLIENT));
for (DictData dictData : dictDataList) {
if (authoritiesPo.getAuthority().contains(dictData.getValue())) {
//获取对应平台
@@ -399,6 +406,35 @@ public class TenantServiceImpl implements TenantService {
return JsonResult.success(page.setRecords(subList));
}

/**
* 提前获取数据 放到map,减少循环次数
*
* @param tenantVos
* @return
*/
private Map<Long, List<AuthoritiesPo>> getAuthoritiesPoMap(List<TenantVo> tenantVos, String clientId) {
List<Long> collect = tenantVos.stream().map(TenantVo::getUserId).collect(Collectors.toList());
if (ObjectUtil.isNotEmpty(clientId)) {
return authoritiesMapper.selectByUserIdsAndClient(collect, clientId)
.parallelStream().collect(Collectors.groupingBy(AuthoritiesPo::getUserId));
} else {
return authoritiesMapper.selectByUserIds(collect)
.parallelStream().collect(Collectors.groupingBy(AuthoritiesPo::getUserId));
}
}

/**
* 提前获取数据 放到map,减少循环次数
*
* @param tenantVos
* @return
*/
private Map<Long, TenantItem> getTenantItemMap(List<TenantVo> tenantVos) {
List<Long> collect = tenantVos.stream().map(TenantVo::getTenantId).collect(Collectors.toList());
return tenantItemMapper.selectList(Wrappers.<TenantItem>lambdaQuery().in(TenantItem::getTenantId, collect))
.stream().collect(Collectors.toMap(TenantItem::getTenantId, Function.identity()));
}

/**
* 根据有效期变更剩余天数逻辑
*

+ 12
- 1
tuoheng_oidc_admin/src/main/resources/mapper/AuthoritiesMapper.xml Voir le fichier

@@ -31,7 +31,18 @@
<select id="selectByUserIds" resultType="com.tuoheng.model.po.AuthoritiesPo">
SELECT id, user_id, username, authority
FROM authorities
where user_id IN
where
user_id IN
<foreach collection="list" item="id" separator=",">
(#{id})
</foreach>
</select>
<select id="selectByUserIdsAndClient" resultType="com.tuoheng.model.po.AuthoritiesPo">
SELECT id, user_id, username, authority
FROM authorities
WHERE authority LIKE concat('%', #{clientId}, '%')
and
user_id IN
<foreach collection="list" item="id" separator=",">
(#{id})
</foreach>

Chargement…
Annuler
Enregistrer