feat:部门查询和权限设置查询增加缓存
This commit is contained in:
parent
bc3af1c109
commit
9ef85d82e7
|
@ -101,6 +101,7 @@ public class ApprovalPlatformAN implements ApprovalPlatform {
|
|||
approvalPlatformInfo.changeUrl()
|
||||
.ifPresent(url -> {
|
||||
ApprovalScheduleParam approvalScheduleParam = createApprovalScheduleParam(approvalData);
|
||||
System.out.println(Json.gson().toJson(approvalScheduleParam));
|
||||
CompletableFuture.runAsync(() -> DelayDispatch.attemptToSend(() -> postRequest.post(url, approvalScheduleParam, ANResponse.class)
|
||||
.getSuccess(), 0));
|
||||
});
|
||||
|
|
|
@ -446,4 +446,13 @@ public class Leg implements Serializable, EventManageable {
|
|||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Optional<LegEvent> getLastChangeEvent() {
|
||||
if (this.eventList == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return this.eventList.stream()
|
||||
.filter(legEvent -> legEvent.getEventType().equals(LEG_EVENT_CHANGE))
|
||||
.max(Comparator.comparing(LegEvent::getHappenTime));
|
||||
}
|
||||
}
|
|
@ -15,5 +15,7 @@ public interface SystemCodeRepository {
|
|||
|
||||
SystemCode findById(Long id);
|
||||
|
||||
List<SystemCode> findByIds(Set<Long> ids);
|
||||
|
||||
List<SystemCode> findBySysCodeIn(Set<String> sysCodes);
|
||||
}
|
||||
|
|
|
@ -11,14 +11,12 @@ import com.chint.domain.aggregates.system.SystemCode;
|
|||
import com.chint.domain.aggregates.system.SystemOrganization;
|
||||
import com.chint.domain.repository.*;
|
||||
import com.chint.domain.value_object.enums.RoutePermission;
|
||||
import com.chint.infrastructure.util.StringCheck;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.chint.domain.aggregates.approval.ApprovalType.LEG_ADD_CHANGE_BATCH;
|
||||
|
@ -79,6 +77,7 @@ public class RouteApprovalDomainService {
|
|||
// 提取所有 approveOrderNo 和 sysCode
|
||||
Set<String> accountCompanyCodes = routeOrderList.stream()
|
||||
.map(routeOrder -> routeOrder.getApproveOrderNo().getAccountCompany())
|
||||
.filter(it-> !StringCheck.isFirstCharacterChinese(it))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Set<String> sysCodes = routeOrderList.stream()
|
||||
|
@ -88,11 +87,13 @@ public class RouteApprovalDomainService {
|
|||
// 批量查询 systemOrganizationRepository 和 systemCodeRepository
|
||||
Map<String, String> accountCompanyToApprovalType = systemOrganizationRepository.findByOrgCodeIn(accountCompanyCodes)
|
||||
.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(it -> it.getApprovalType() != null && !it.getApprovalType().isEmpty())
|
||||
.collect(Collectors.toMap(SystemOrganization::getOrgCode, SystemOrganization::getApprovalType));
|
||||
|
||||
Map<String, String> sysCodeToApprovalType = systemCodeRepository.findBySysCodeIn(sysCodes)
|
||||
.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(it -> it.getApprovalType() != null && !it.getApprovalType().isEmpty())
|
||||
.collect(Collectors.toMap(SystemCode::getSystemCode, SystemCode::getApprovalType));
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
package com.chint.infrastructure.echo_framework.repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
|
||||
public abstract class AbstractGenericRepository<T, ID> {
|
||||
|
||||
// protected final GenericCacheRepository<T, ID> cacheRepository;
|
||||
// protected final JdbcGenericRepository<T, ID> jdbcRepository;
|
||||
// protected final String cachePrefix;
|
||||
//
|
||||
// protected AbstractGenericRepository(GenericCacheRepository<T, ID> cacheRepository,
|
||||
// JdbcGenericRepository<T, ID> jdbcRepository,
|
||||
// String cachePrefix) {
|
||||
// this.cacheRepository = cacheRepository;
|
||||
// this.jdbcRepository = jdbcRepository;
|
||||
// this.cachePrefix = cachePrefix;
|
||||
// }
|
||||
//
|
||||
// public T save(T entity) {
|
||||
// T savedEntity = jdbcRepository.save(entity);
|
||||
// updateCache(savedEntity);
|
||||
// return savedEntity;
|
||||
// }
|
||||
//
|
||||
// public T findById(ID id) {
|
||||
// T entity = cacheRepository.findFromCache(cachePrefix, id);
|
||||
// if (entity == null) {
|
||||
// Optional<T> optionalEntity = jdbcRepository.findById(id);
|
||||
// if (optionalEntity.isPresent()) {
|
||||
// entity = optionalEntity.get();
|
||||
// T finalEntity = entity;
|
||||
// CompletableFuture.runAsync(() -> updateCache(finalEntity));
|
||||
// }
|
||||
// }
|
||||
// return entity;
|
||||
// }
|
||||
|
||||
// public <V> T findByField(Function<T, V> fieldGetter, String fieldPrefix, String fieldValue) {
|
||||
// ID id = cacheRepository.findIdFromCache(fieldPrefix, fieldValue.toString());
|
||||
// if (id == null) {
|
||||
// T entity = findByFieldFromDatabase(fieldValue);
|
||||
// if (entity != null) {
|
||||
// CompletableFuture.runAsync(() -> updateCache(entity));
|
||||
// }
|
||||
// return entity;
|
||||
// }
|
||||
// return findById(id);
|
||||
// }
|
||||
|
||||
// protected abstract String getPrefix();
|
||||
//
|
||||
// protected abstract List<T> findByFieldFromDatabase(String fieldValue);
|
||||
//
|
||||
// protected abstract List<T> findByFieldInFromDatabase(List<String> fieldValueList);
|
||||
//
|
||||
// protected abstract void updateCache(T entity);
|
||||
//
|
||||
// protected void updateFieldCache(String fieldName, String fieldValue, ID id) {
|
||||
// cacheRepository.cacheEvictFieldToId(fieldName, fieldValue);
|
||||
// cacheRepository.cacheFieldToId(fieldName, fieldValue, id);
|
||||
// }
|
||||
//
|
||||
// protected String getFieldPrefix(String fieldName) {
|
||||
// return cachePrefix + "::" + fieldName;
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.chint.infrastructure.echo_framework.repository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//@Component
|
||||
public class GenericCacheRepository<T, ID> {
|
||||
|
||||
// @Autowired
|
||||
// private RedisTemplate<String, T> redisTemplate;
|
||||
//
|
||||
// @Autowired
|
||||
// private RedisTemplate<String, ID> redisTemplateId;
|
||||
//
|
||||
// private final Class<T> entityType;
|
||||
// private final Class<ID> idType;
|
||||
//
|
||||
// public GenericCacheRepository(Class<T> entityType, Class<ID> idType) {
|
||||
// this.entityType = entityType;
|
||||
// this.idType = idType;
|
||||
// }
|
||||
//
|
||||
// private String getKey(String prefix, Object value) {
|
||||
// return prefix + "::" + value;
|
||||
// }
|
||||
//
|
||||
// public T cache(String prefix, ID id, T entity) {
|
||||
// String key = getKey(prefix, id);
|
||||
// redisTemplate.opsForValue().set(key, entity);
|
||||
// return entity;
|
||||
// }
|
||||
//
|
||||
// public void cacheEvict(String prefix, ID id) {
|
||||
// String key = getKey(prefix, id);
|
||||
// redisTemplate.delete(key);
|
||||
// }
|
||||
//
|
||||
// public T findFromCache(String prefix, ID id) {
|
||||
// String key = getKey(prefix, id);
|
||||
// return redisTemplate.opsForValue().get(key);
|
||||
// }
|
||||
//
|
||||
// public List<T> cacheBatchByIds(String prefix, List<ID> ids) {
|
||||
// List<String> keys = ids.stream().map(id -> getKey(prefix, id)).toList();
|
||||
// return redisTemplate.opsForValue().multiGet(keys);
|
||||
// }
|
||||
//
|
||||
// public ID cacheFieldToId(String fieldPrefix, String fieldValue, ID id) {
|
||||
// String key = getKey(fieldPrefix, fieldValue);
|
||||
// redisTemplateId.opsForValue().set(key, id);
|
||||
// return id;
|
||||
// }
|
||||
//
|
||||
// public ID findIdFromCache(String fieldPrefix, String fieldValue) {
|
||||
// String key = getKey(fieldPrefix, fieldValue);
|
||||
// return redisTemplateId.opsForValue().get(key);
|
||||
// }
|
||||
//
|
||||
// public List<ID> findIdsFromCache(String fieldPrefix, List<String> fieldValueList) {
|
||||
// List<String> keys = fieldValueList.stream().map(fieldValue -> getKey(fieldPrefix, fieldValue)).toList();
|
||||
// return redisTemplateId.opsForValue().multiGet(keys);
|
||||
// }
|
||||
//
|
||||
// public void cacheEvictFieldToId(String fieldPrefix, String fieldValue) {
|
||||
// String key = getKey(fieldPrefix, fieldValue);
|
||||
// redisTemplateId.delete(key);
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.chint.infrastructure.echo_framework.repository;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface JdbcGenericRepository<T, ID> extends CrudRepository<T, ID> {
|
||||
Optional<T> findById(ID id);
|
||||
|
||||
List<T> findAll();
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.chint.infrastructure.repository;
|
|||
|
||||
import com.chint.domain.aggregates.base.PermissionConfig;
|
||||
import com.chint.domain.repository.PermissionConfigRepository;
|
||||
import com.chint.infrastructure.repository.cache.CachePermissionConfigRepository;
|
||||
import com.chint.infrastructure.repository.jdbc.JdbcPermissionConfigRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
@ -11,6 +12,7 @@ import java.util.List;
|
|||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Repository
|
||||
public class PermissionConfigRepositoryImpl implements PermissionConfigRepository {
|
||||
|
@ -18,14 +20,41 @@ public class PermissionConfigRepositoryImpl implements PermissionConfigRepositor
|
|||
@Autowired
|
||||
private JdbcPermissionConfigRepository jdbcPermissionConfigRepository;
|
||||
|
||||
@Autowired
|
||||
private CachePermissionConfigRepository cachePermissionConfigRepository;
|
||||
|
||||
@Cacheable(value = "PermissionConfig", key = "#permissionName")
|
||||
@Override
|
||||
public Optional<PermissionConfig> findByPermissionName(String permissionName) {
|
||||
return jdbcPermissionConfigRepository.findByPermissionName(permissionName).stream().findFirst();
|
||||
return jdbcPermissionConfigRepository.findByPermissionName(permissionName)
|
||||
.stream()
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PermissionConfig> findByPermissionNameIn(Set<String> approvalTypes) {
|
||||
return jdbcPermissionConfigRepository.findByPermissionNameIn(approvalTypes.stream().filter(Objects::nonNull).toList());
|
||||
List<PermissionConfig> permissionConfigs = cachePermissionConfigRepository
|
||||
.cachePermissionConfigBatch(approvalTypes);
|
||||
List<String> cachedNames = permissionConfigs.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(PermissionConfig::getPermissionName)
|
||||
.toList();
|
||||
List<String> missingNames = approvalTypes.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(name -> !cachedNames.contains(name))
|
||||
.toList();
|
||||
if (!missingNames.isEmpty()) {
|
||||
List<PermissionConfig> fetchedPermissionConfigs = jdbcPermissionConfigRepository
|
||||
.findByPermissionNameIn(missingNames);
|
||||
permissionConfigs.addAll(fetchedPermissionConfigs);
|
||||
CompletableFuture.runAsync(() -> fetchedPermissionConfigs.forEach(this::updateCache));
|
||||
}
|
||||
return permissionConfigs;
|
||||
}
|
||||
|
||||
private void updateCache(PermissionConfig permissionConfig) {
|
||||
// 更新缓存的逻辑
|
||||
cachePermissionConfigRepository.cacheEvictByName(permissionConfig.getPermissionName());
|
||||
cachePermissionConfigRepository.cacheByName(permissionConfig);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package com.chint.infrastructure.repository;
|
||||
|
||||
import com.chint.domain.aggregates.system.SystemCode;
|
||||
import com.chint.domain.exceptions.NotFoundException;
|
||||
import com.chint.domain.repository.SystemCodeRepository;
|
||||
import com.chint.infrastructure.echo_framework.repository.AbstractGenericRepository;
|
||||
import com.chint.infrastructure.echo_framework.repository.GenericCacheRepository;
|
||||
import com.chint.infrastructure.echo_framework.repository.JdbcGenericRepository;
|
||||
import com.chint.infrastructure.repository.cache.CacheSystemCodeRepository;
|
||||
import com.chint.infrastructure.repository.jdbc.JdbcSystemCodeRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Repository
|
||||
public class SystemCodeRepositoryImpl implements SystemCodeRepository {
|
||||
|
@ -18,24 +19,90 @@ public class SystemCodeRepositoryImpl implements SystemCodeRepository {
|
|||
@Autowired
|
||||
private JdbcSystemCodeRepository jdbcSystemCodeRepository;
|
||||
|
||||
@Autowired
|
||||
private CacheSystemCodeRepository cacheSystemCodeRepository;
|
||||
|
||||
// private static final String SYSTEM_CODE_PREFIX = "SystemCode";
|
||||
|
||||
// @Autowired
|
||||
// public SystemCodeRepositoryImpl(GenericCacheRepository<SystemCode, Long> cacheRepository,
|
||||
// JdbcGenericRepository<SystemCode, Long> jdbcRepository) {
|
||||
// super(cacheRepository, jdbcRepository, SYSTEM_CODE_PREFIX);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public SystemCode save(SystemCode systemCode) {
|
||||
return jdbcSystemCodeRepository.save(systemCode);
|
||||
SystemCode save = jdbcSystemCodeRepository.save(systemCode);
|
||||
updateCache(save);
|
||||
return save;
|
||||
}
|
||||
|
||||
@Cacheable(value = "SystemCode", key = "#sysCode")
|
||||
@Override
|
||||
public SystemCode findBySysCode(String sysCode) {
|
||||
return jdbcSystemCodeRepository.findBySystemCode(sysCode);
|
||||
Long id = cacheSystemCodeRepository.cacheSysCodeMapToId(sysCode, null);
|
||||
if (id == null) {
|
||||
SystemCode systemCode = jdbcSystemCodeRepository.findBySystemCode(sysCode);
|
||||
if (systemCode != null) {
|
||||
CompletableFuture.runAsync(() -> updateCache(systemCode));
|
||||
}
|
||||
return systemCode;
|
||||
}
|
||||
return findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemCode findById(Long id) {
|
||||
return jdbcSystemCodeRepository.findById(id).orElseThrow(() -> new NotFoundException("该产业公司不在实施范围内"));
|
||||
SystemCode systemCode = cacheSystemCodeRepository.cache(id, null);
|
||||
if (systemCode == null) {
|
||||
Optional<SystemCode> optionalSystemCode = jdbcSystemCodeRepository.findById(id);
|
||||
if (optionalSystemCode.isPresent()) {
|
||||
SystemCode foundSystemCode = optionalSystemCode.get();
|
||||
systemCode = foundSystemCode;
|
||||
CompletableFuture.runAsync(() -> updateCache(foundSystemCode));
|
||||
}
|
||||
}
|
||||
return systemCode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<SystemCode> findByIds(Set<Long> ids) {
|
||||
List<SystemCode> systemCodes = cacheSystemCodeRepository.cacheBatchByIds(new ArrayList<>(ids));
|
||||
List<Long> cachedIds = systemCodes.stream().filter(Objects::nonNull).map(SystemCode::getId).toList();
|
||||
List<Long> missingIds = ids.stream().filter(Objects::nonNull).filter(id -> !cachedIds.contains(id)).toList();
|
||||
if (!missingIds.isEmpty()) {
|
||||
List<SystemCode> fetchedSystemCodes = jdbcSystemCodeRepository.findByIdIn(missingIds);
|
||||
systemCodes.addAll(fetchedSystemCodes);
|
||||
CompletableFuture.runAsync(() -> fetchedSystemCodes.forEach(this::updateCache));
|
||||
}
|
||||
return systemCodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemCode> findBySysCodeIn(Set<String> sysCodes) {
|
||||
return jdbcSystemCodeRepository.findBySystemCodeIn(sysCodes.stream().filter(Objects::nonNull).toList());
|
||||
List<Long> cachedIds = cacheSystemCodeRepository.cacheIdsBatchBySysCodeList(new ArrayList<>(sysCodes));
|
||||
List<SystemCode> systemCodes = findByIds(new HashSet<>(cachedIds));
|
||||
List<String> cachedSysCodes = systemCodes.stream().filter(Objects::nonNull).map(SystemCode::getSystemCode).toList();
|
||||
List<String> missingSysCodes = sysCodes.stream().filter(Objects::nonNull).filter(sysCode -> !cachedSysCodes.contains(sysCode)).toList();
|
||||
if (!missingSysCodes.isEmpty()) {
|
||||
List<SystemCode> fetchedSystemCodes = jdbcSystemCodeRepository.findBySystemCodeIn(missingSysCodes);
|
||||
systemCodes = new ArrayList<>(systemCodes);
|
||||
systemCodes.addAll(fetchedSystemCodes);
|
||||
CompletableFuture.runAsync(() -> fetchedSystemCodes.forEach(this::updateCache));
|
||||
}
|
||||
return systemCodes;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected void updateCache(SystemCode entity) {
|
||||
//
|
||||
// }
|
||||
|
||||
private void updateCache(SystemCode systemCode) {
|
||||
cacheSystemCodeRepository.cacheEvict(systemCode);
|
||||
cacheSystemCodeRepository.cache(systemCode.getId(), systemCode);
|
||||
cacheSystemCodeRepository.cacheEvictSysCodeMapToId(systemCode.getSystemCode());
|
||||
cacheSystemCodeRepository.cacheSysCodeMapToId(systemCode.getSystemCode(), systemCode.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@ import com.chint.domain.repository.SystemOrganizationRepository;
|
|||
import com.chint.infrastructure.repository.cache.CacheSystemOrganizationRepository;
|
||||
import com.chint.infrastructure.repository.jdbc.JdbcSystemOrganizationRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Repository
|
||||
|
@ -48,6 +48,40 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
|
|||
return systemOrganizationList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<SystemOrganization> findByOrgCode(String orgCode) {
|
||||
return jdbcSystemOrganizationRepository.findByOrgCode(orgCode).stream().findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemOrganization> findByOrgCodeIn(Set<String> accountCompanyCodes) {
|
||||
List<Long> inCacheIdList = cacheSystemOrganizationRepository
|
||||
.getOrgIdsFromCacheByOrgCodeList(accountCompanyCodes.stream().filter(Objects::nonNull).toList());
|
||||
List<SystemOrganization> byIdIn = findByIdIn(inCacheIdList);
|
||||
List<String> codes = byIdIn.stream().filter(Objects::nonNull).map(SystemOrganization::getOrgCode).toList();
|
||||
List<String> notInCache = accountCompanyCodes.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(code -> !codes.contains(code)).toList();
|
||||
if (!notInCache.isEmpty()) {
|
||||
//如果确实有些没有缓存到redis, 将从数据库查询出来然后异步保存到redis,然后返回
|
||||
List<SystemOrganization> byOrgCodeIn = jdbcSystemOrganizationRepository
|
||||
.findByOrgCodeIn(notInCache);
|
||||
CompletableFuture.runAsync(() -> {
|
||||
byOrgCodeIn.forEach(this::updateSystemOrganizationCache);
|
||||
});
|
||||
byIdIn.addAll(byOrgCodeIn);
|
||||
}
|
||||
return byIdIn;
|
||||
}
|
||||
|
||||
private void updateSystemOrganizationCache(SystemOrganization systemOrganization) {
|
||||
cacheSystemOrganizationRepository.cacheEvict(systemOrganization);
|
||||
cacheSystemOrganizationRepository.cache(systemOrganization);
|
||||
cacheSystemOrganizationRepository.cacheEvictOrgCodeById(systemOrganization.getOrgCode());
|
||||
cacheSystemOrganizationRepository.cacheOrgCodeById(systemOrganization.getOrgCode(), systemOrganization.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemOrganization> findByIdIn(List<Long> ids) {
|
||||
List<SystemOrganization> fromCacheByIdIn = cacheSystemOrganizationRepository.getFromCacheByIdIn(ids);
|
||||
|
@ -55,7 +89,7 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
|
|||
.filter(Objects::nonNull)
|
||||
.map(SystemOrganization::getId)
|
||||
.toList();
|
||||
List<Long> list = ids.stream().filter(it -> !fromCacheOrg.contains(it)).toList();
|
||||
List<Long> list = ids.stream().filter(it -> !fromCacheOrg.contains(it)).filter(Objects::nonNull).toList();
|
||||
if (!list.isEmpty()) {
|
||||
List<SystemOrganization> fromDBByIdIn = jdbcSystemOrganizationRepository.findByIdIn(list);
|
||||
fromDBByIdIn.forEach(it -> cacheSystemOrganizationRepository.cache(it)); // 更新缓存
|
||||
|
@ -143,10 +177,7 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<SystemOrganization> findByOrgCode(String orgCode) {
|
||||
return jdbcSystemOrganizationRepository.findByOrgCode(orgCode).stream().findFirst();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> queryOrgCodeListByUserId(Long userId) {
|
||||
|
@ -154,11 +185,6 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<SystemOrganization> findByOrgCodeIn(Set<String> accountCompanyCodes) {
|
||||
return jdbcSystemOrganizationRepository.findByOrgCodeIn(accountCompanyCodes.stream().filter(Objects::nonNull).toList());
|
||||
}
|
||||
|
||||
private void expandOrganizationRecursively(SystemOrganization org,
|
||||
List<SystemOrganization> allOrganizations) {
|
||||
if (org == null) {
|
||||
|
|
34
src/main/java/com/chint/infrastructure/repository/cache/CachePermissionConfigRepository.java
vendored
Normal file
34
src/main/java/com/chint/infrastructure/repository/cache/CachePermissionConfigRepository.java
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
package com.chint.infrastructure.repository.cache;
|
||||
|
||||
import com.chint.domain.aggregates.base.PermissionConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@Repository
|
||||
public class CachePermissionConfigRepository {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, PermissionConfig> redisTemplate;
|
||||
|
||||
public List<PermissionConfig> cachePermissionConfigBatch(Set<String> permissionNameList) {
|
||||
List<String> keys = permissionNameList.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(name -> "PermissionConfig::" + name).toList();
|
||||
return redisTemplate.opsForValue().multiGet(keys);
|
||||
}
|
||||
|
||||
@Cacheable(value = "PermissionConfig", key = "#permissionConfig.permissionName")
|
||||
public PermissionConfig cacheByName(PermissionConfig permissionConfig) {
|
||||
return permissionConfig;
|
||||
}
|
||||
|
||||
@Cacheable(value = "PermissionConfig", key = "#permissionName")
|
||||
public void cacheEvictByName(String permissionName) {
|
||||
}
|
||||
}
|
60
src/main/java/com/chint/infrastructure/repository/cache/CacheSystemCodeRepository.java
vendored
Normal file
60
src/main/java/com/chint/infrastructure/repository/cache/CacheSystemCodeRepository.java
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
package com.chint.infrastructure.repository.cache;
|
||||
|
||||
|
||||
import com.chint.domain.aggregates.system.SystemCode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Repository
|
||||
public class CacheSystemCodeRepository {
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, SystemCode> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Long> redisTemplateId;
|
||||
|
||||
public List<SystemCode> cacheBatchByIds(List<Long> ids) {
|
||||
List<String> keys = ids.stream().filter(Objects::nonNull).map(id -> "SystemCode::" + id).toList();
|
||||
if(keys.isEmpty()){
|
||||
return List.of();
|
||||
}
|
||||
List<SystemCode> systemCodes = redisTemplate.opsForValue().multiGet(keys);
|
||||
return systemCodes == null ? List.of() : systemCodes;
|
||||
}
|
||||
|
||||
public List<Long> cacheIdsBatchBySysCodeList(List<String> systemCodeList) {
|
||||
List<String> keys = systemCodeList.stream().filter(Objects::nonNull).map(systemCode -> "SystemCode::mapToId::" + systemCode).toList();
|
||||
if(keys.isEmpty()){
|
||||
return List.of();
|
||||
}
|
||||
List<Long> ids = redisTemplateId.opsForValue().multiGet(keys);
|
||||
return ids == null ? List.of() : ids;
|
||||
}
|
||||
|
||||
@Cacheable(value = "SystemCode", key = "#id")
|
||||
public SystemCode cache(Long id, SystemCode systemCode) {
|
||||
return systemCode;
|
||||
}
|
||||
|
||||
@CacheEvict(value = "SystemCode", key = "#systemCode.id")
|
||||
public void cacheEvict(SystemCode systemCode) {
|
||||
}
|
||||
|
||||
|
||||
@Cacheable(value = "SystemCode::mapToId", key = "#sysCode")
|
||||
public Long cacheSysCodeMapToId(String sysCode, Long systemId) {
|
||||
return systemId;
|
||||
}
|
||||
|
||||
@CacheEvict(value = "SystemCode::mapToId", key = "#sysCode")
|
||||
public void cacheEvictSysCodeMapToId(String sysCode) {
|
||||
}
|
||||
}
|
|
@ -17,6 +17,9 @@ public class CacheSystemOrganizationRepository {
|
|||
@Autowired
|
||||
private RedisTemplate<String, SystemOrganization> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Long> redisTemplateId;
|
||||
|
||||
public List<SystemOrganization> getFromCacheByIdIn(List<Long> ids) {
|
||||
List<String> routeOrderKeys = ids.stream().map(id -> "SystemOrganization::" + id).toList();
|
||||
List<SystemOrganization> systemOrganizationList = redisTemplate.opsForValue().multiGet(routeOrderKeys);
|
||||
|
@ -42,4 +45,19 @@ public class CacheSystemOrganizationRepository {
|
|||
@CacheEvict(value = "SystemOrganization::ParentId", key = "#parentId")
|
||||
public void cacheEvictIdsByParentId(Long parentId) {
|
||||
}
|
||||
|
||||
@Cacheable(value = "SystemOrganization::OrgCode", key = "#orgCode")
|
||||
public Long cacheOrgCodeById(String orgCode, Long systemOrganizationId) {
|
||||
return systemOrganizationId;
|
||||
}
|
||||
|
||||
@CacheEvict(value = "SystemOrganization::OrgCode", key = "#orgCode")
|
||||
public void cacheEvictOrgCodeById(String orgCode) {
|
||||
}
|
||||
|
||||
public List<Long> getOrgIdsFromCacheByOrgCodeList(List<String> OrgCodeList) {
|
||||
List<String> routeOrderKeys = OrgCodeList.stream().map(orgCode -> "SystemOrganization::OrgCode::" + orgCode).toList();
|
||||
List<Long> ids = redisTemplateId.opsForValue().multiGet(routeOrderKeys);
|
||||
return Objects.requireNonNullElseGet(ids, List::of);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.chint.domain.aggregates.system.SystemCode;
|
|||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
|
@ -12,4 +13,6 @@ public interface JdbcSystemCodeRepository extends CrudRepository<SystemCode, Lon
|
|||
SystemCode findBySystemCode(String systemCode);
|
||||
|
||||
List<SystemCode> findBySystemCodeIn(List<String> systemCodes);
|
||||
|
||||
List<SystemCode> findByIdIn(Collection<Long> id);
|
||||
}
|
||||
|
|
|
@ -23,4 +23,16 @@ public class StringCheck {
|
|||
char firstChar = str.charAt(0);
|
||||
return Character.isLetter(firstChar);
|
||||
}
|
||||
|
||||
public boolean containsChinese(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (char c : str.toCharArray()) {
|
||||
if (Character.UnicodeScript.of(c) == Character.UnicodeScript.HAN) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue