|
|
@@ -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())); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据有效期变更剩余天数逻辑 |
|
|
|
* |