| | |
| | | import com.vincent.rsf.server.ai.dto.AiPromptPreviewRequest; |
| | | import com.vincent.rsf.server.ai.entity.AiPrompt; |
| | | import com.vincent.rsf.server.ai.mapper.AiPromptMapper; |
| | | import com.vincent.rsf.server.ai.store.AiConfigCacheStore; |
| | | import com.vincent.rsf.server.ai.store.AiConversationCacheStore; |
| | | import com.vincent.rsf.server.ai.service.AiPromptService; |
| | | import com.vincent.rsf.server.system.enums.StatusType; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | public class AiPromptServiceImpl extends ServiceImpl<AiPromptMapper, AiPrompt> implements AiPromptService { |
| | | |
| | | private final AiPromptRenderSupport aiPromptRenderSupport; |
| | | private final AiConfigCacheStore aiConfigCacheStore; |
| | | private final AiConversationCacheStore aiConversationCacheStore; |
| | | |
| | | @Override |
| | | public AiPrompt getActivePrompt(String code, Long tenantId) { |
| | |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | | public boolean save(AiPrompt entity) { |
| | | boolean saved = super.save(entity); |
| | | if (saved && entity != null && entity.getTenantId() != null) { |
| | | aiConfigCacheStore.evictTenantConfigCaches(entity.getTenantId()); |
| | | aiConversationCacheStore.evictTenantRuntimeCaches(entity.getTenantId()); |
| | | } |
| | | return saved; |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateById(AiPrompt entity) { |
| | | boolean updated = super.updateById(entity); |
| | | if (updated && entity != null && entity.getTenantId() != null) { |
| | | aiConfigCacheStore.evictTenantConfigCaches(entity.getTenantId()); |
| | | aiConversationCacheStore.evictTenantRuntimeCaches(entity.getTenantId()); |
| | | } |
| | | return updated; |
| | | } |
| | | |
| | | @Override |
| | | public boolean removeByIds(java.util.Collection<?> list) { |
| | | java.util.List<java.io.Serializable> ids = list == null ? java.util.List.of() : list.stream() |
| | | .filter(java.util.Objects::nonNull) |
| | | .map(item -> (java.io.Serializable) item) |
| | | .toList(); |
| | | java.util.List<AiPrompt> records = this.listByIds(ids); |
| | | boolean removed = super.removeByIds(list); |
| | | if (removed) { |
| | | records.stream() |
| | | .map(AiPrompt::getTenantId) |
| | | .filter(java.util.Objects::nonNull) |
| | | .distinct() |
| | | .forEach(tenantId -> { |
| | | aiConfigCacheStore.evictTenantConfigCaches(tenantId); |
| | | aiConversationCacheStore.evictTenantRuntimeCaches(tenantId); |
| | | }); |
| | | } |
| | | return removed; |
| | | } |
| | | |
| | | private void ensureRequiredFields(AiPrompt aiPrompt) { |
| | | if (!StringUtils.hasText(aiPrompt.getName())) { |
| | | throw new CoolException("Prompt 名称不能为空"); |