组用户功能修订
ci-userbase-service / build-and-push (push) Failing after 1m45s

This commit is contained in:
chenxing
2026-08-12 19:16:22 +08:00
parent f55c865ab1
commit a5ced786b4
28 changed files with 1488 additions and 202 deletions
@@ -11,17 +11,18 @@ import com.yunhai.userbase.repository.SysGroupAppRelRepository;
import com.yunhai.userbase.repository.SysGroupModulePermRepository;
import com.yunhai.userbase.repository.SysUserAppRoleRelRepository;
import com.yunhai.userbase.service.IApplicationInfoService;
import com.yunhai.userbase.service.SignKeyCacheService;
import com.yunhai.platform.utils.exception.DException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import com.yunhai.userbase.model.application.ApplicationInfoQuery;
import com.yunhai.userbase.model.application.ApplicationInfoRequest;
import com.yunhai.userbase.model.application.ApplicationInfoSortVo;
import com.yunhai.userbase.model.application.ApplicationInfoVo;
import com.yunhai.userbase.event.ApplicationInfoCacheChangedEvent;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;
@@ -38,7 +39,6 @@ import java.util.List;
import java.util.Objects;
import java.util.UUID;
@Service
public class ApplicationInfoService implements IApplicationInfoService {
@@ -66,6 +66,9 @@ public class ApplicationInfoService implements IApplicationInfoService {
@Autowired
private SignKeyCacheService signKeyCacheService;
@Autowired
private ApplicationEventPublisher eventPublisher;
/**
* 查询缓存:sync = true 防击穿;底层优先 Redis,Redis 故障时自动降级 Caffeine。
*/
@@ -81,7 +84,9 @@ public class ApplicationInfoService implements IApplicationInfoService {
@Override
@CachePut(value = "appInfo", key = "#info.id")
public ApplicationInfo save(ApplicationInfo info) {
return applicationInfoRepository.save(info);
ApplicationInfo saved = applicationInfoRepository.save(info);
eventPublisher.publishEvent(ApplicationInfoCacheChangedEvent.upsert(this, saved));
return saved;
}
/**
@@ -90,7 +95,11 @@ public class ApplicationInfoService implements IApplicationInfoService {
@Override
@CacheEvict(value = "appInfo", key = "#id")
public void deleteById(Integer id) {
ApplicationInfo existing = applicationInfoRepository.findById(id).orElse(null);
applicationInfoRepository.deleteById(id);
if (existing != null && existing.getAppKey() != null) {
eventPublisher.publishEvent(ApplicationInfoCacheChangedEvent.delete(this, existing.getAppKey()));
}
}
@Override
@@ -111,7 +120,7 @@ public class ApplicationInfoService implements IApplicationInfoService {
// appSecret:32 位 UUID(去除连字符)
entity.setAppSecret(UUID.randomUUID().toString().replace("-", ""));
ApplicationInfo saved = applicationInfoRepository.save(entity);
signKeyCacheService.syncOne(saved);
eventPublisher.publishEvent(ApplicationInfoCacheChangedEvent.upsert(this, saved));
}
@Override
@@ -127,7 +136,7 @@ public class ApplicationInfoService implements IApplicationInfoService {
.orElseThrow(() -> new RuntimeException("应用不存在: " + id));
BeanUtils.copyProperties(request, entity, "id", "appKey", "appSecret");
ApplicationInfo saved = applicationInfoRepository.save(entity);
signKeyCacheService.syncOne(saved);
eventPublisher.publishEvent(ApplicationInfoCacheChangedEvent.upsert(this, saved));
}
@Override
@@ -164,7 +173,7 @@ public class ApplicationInfoService implements IApplicationInfoService {
// 先删模块(整棵子树随 appId 一并清除),再删应用,避免残留孤儿数据
appModuleRepository.deleteByAppId(id);
applicationInfoRepository.deleteById(id);
signKeyCacheService.removeOne(appKey);
eventPublisher.publishEvent(ApplicationInfoCacheChangedEvent.delete(this, appKey));
}
@Override
@@ -223,7 +232,7 @@ public class ApplicationInfoService implements IApplicationInfoService {
.orElseThrow(() -> new RuntimeException("应用不存在: " + id));
entity.setAppSecret(UUID.randomUUID().toString().replace("-", ""));
ApplicationInfo saved = applicationInfoRepository.save(entity);
signKeyCacheService.syncOne(saved);
eventPublisher.publishEvent(ApplicationInfoCacheChangedEvent.upsert(this, saved));
}
@Override