| | |
| | | import com.vincent.rsf.server.ai.dto.AiParamValidateResultDto; |
| | | import com.vincent.rsf.server.ai.entity.AiParam; |
| | | import com.vincent.rsf.server.ai.mapper.AiParamMapper; |
| | | import com.vincent.rsf.server.ai.store.AiConfigCacheStore; |
| | | import com.vincent.rsf.server.ai.store.AiConversationCacheStore; |
| | | import com.vincent.rsf.server.ai.service.AiParamService; |
| | | import com.vincent.rsf.server.system.enums.StatusType; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | public class AiParamServiceImpl extends ServiceImpl<AiParamMapper, AiParam> implements AiParamService { |
| | | |
| | | private final AiParamValidationSupport aiParamValidationSupport; |
| | | private final AiRedisSupport aiRedisSupport; |
| | | private final AiConfigCacheStore aiConfigCacheStore; |
| | | private final AiConversationCacheStore aiConversationCacheStore; |
| | | |
| | | @Override |
| | | public AiParam getActiveParam(Long tenantId) { |
| | |
| | | if (!super.updateById(target)) { |
| | | throw new CoolException("设置默认 AI 参数失败"); |
| | | } |
| | | aiRedisSupport.evictTenantConfigCaches(tenantId); |
| | | aiConfigCacheStore.evictTenantConfigCaches(tenantId); |
| | | aiConversationCacheStore.evictTenantRuntimeCaches(tenantId); |
| | | return target; |
| | | } |
| | | |
| | |
| | | public boolean save(AiParam entity) { |
| | | boolean saved = super.save(entity); |
| | | if (saved && entity != null && entity.getTenantId() != null) { |
| | | aiRedisSupport.evictTenantConfigCaches(entity.getTenantId()); |
| | | aiConfigCacheStore.evictTenantConfigCaches(entity.getTenantId()); |
| | | aiConversationCacheStore.evictTenantRuntimeCaches(entity.getTenantId()); |
| | | } |
| | | return saved; |
| | | } |
| | |
| | | public boolean updateById(AiParam entity) { |
| | | boolean updated = super.updateById(entity); |
| | | if (updated && entity != null && entity.getTenantId() != null) { |
| | | aiRedisSupport.evictTenantConfigCaches(entity.getTenantId()); |
| | | aiConfigCacheStore.evictTenantConfigCaches(entity.getTenantId()); |
| | | aiConversationCacheStore.evictTenantRuntimeCaches(entity.getTenantId()); |
| | | } |
| | | return updated; |
| | | } |
| | |
| | | .map(AiParam::getTenantId) |
| | | .filter(java.util.Objects::nonNull) |
| | | .distinct() |
| | | .forEach(aiRedisSupport::evictTenantConfigCaches); |
| | | .forEach(tenantId -> { |
| | | aiConfigCacheStore.evictTenantConfigCaches(tenantId); |
| | | aiConversationCacheStore.evictTenantRuntimeCaches(tenantId); |
| | | }); |
| | | } |
| | | return removed; |
| | | } |