From 99c88317c053138e0f9d4c5178911aa176209cb1 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Sun, 7 Apr 2024 14:46:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B7=AE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/JTCompanyDomainService.java | 26 +++++-------------- .../repository/JTCompanyRepositoryImpl.java | 1 + 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/chint/domain/service/JTCompanyDomainService.java b/src/main/java/com/chint/domain/service/JTCompanyDomainService.java index a55b2b45..8930dcc3 100644 --- a/src/main/java/com/chint/domain/service/JTCompanyDomainService.java +++ b/src/main/java/com/chint/domain/service/JTCompanyDomainService.java @@ -10,8 +10,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.util.HashSet; -import java.util.Set; +import java.util.List; @Slf4j @Component @@ -23,42 +22,29 @@ public class JTCompanyDomainService { @Autowired private SystemCodeRepository systemCodeRepository; - private Set companyBlackList = new HashSet<>(); - @PostConstruct public void init() { // 在Bean创建后加载黑名单到内存中 log.info("加载集团公司名单"); - companyBlackList.addAll(jtCompanyRepository.findAll()); + jtCompanyRepository.findAll(); } public boolean ifCompanyInJT(String companyName, String companyCode) { + List all = jtCompanyRepository.findAll(); if (companyName != null) { - boolean contains = companyBlackList.stream().map(JTCompany::getCompanyName).toList().contains(companyName); - //如果找不到的话, 再次查询数据进行一次查找 - if (!contains) { - companyBlackList.addAll(jtCompanyRepository.findAll()); - contains = companyBlackList.stream().map(JTCompany::getCompanyName).toList().contains(companyName); - } - return contains; + return all.stream().map(JTCompany::getCompanyName).toList().contains(companyName); } if (companyCode != null) { - boolean contains = companyBlackList.stream().map(JTCompany::getCompanyCode).toList().contains(companyCode); - //如果找不到的话, 再次查询数据进行一次查找 - if (!contains) { - companyBlackList.addAll(jtCompanyRepository.findAll()); - contains = companyBlackList.stream().map(JTCompany::getCompanyCode).toList().contains(companyCode); - } - return contains; + return all.stream().map(JTCompany::getCompanyCode).toList().contains(companyCode); } return false; } public String findSystemCodeByCompanyCode(String companyCode) { JTCompany byCompanyCode = jtCompanyRepository.findByCompanyCode(companyCode); - if(byCompanyCode == null){ + if (byCompanyCode == null) { throw new AuthException("用户所在公司不在实施范围内"); } return systemCodeRepository.findById(byCompanyCode.getSystemCodeId()).getSystemCode(); diff --git a/src/main/java/com/chint/infrastructure/repository/JTCompanyRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/JTCompanyRepositoryImpl.java index 53952109..90bdda2f 100644 --- a/src/main/java/com/chint/infrastructure/repository/JTCompanyRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/JTCompanyRepositoryImpl.java @@ -15,6 +15,7 @@ public class JTCompanyRepositoryImpl implements JTCompanyRepository { @Autowired private JdbcJTCompanyRepositoryImpl jdbcJTCompanyRepository; + @Cacheable(value = "JTCompanyAll") @Override public List findAll() { return jdbcJTCompanyRepository.findBySystemCodeId(1L);