| | |
| | | synchronized (("ai_prompt_scene_init_" + scene.getCode()).intern()) { |
| | | prompt = findPublished(scene.getCode()); |
| | | if (prompt == null) { |
| | | if (findLatest(scene.getCode()) == null) { |
| | | prompt = ensurePublishedScene(scene); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (prompt == null) { |
| | | throw new IllegalStateException("未找到已发布的 Prompt,sceneCode=" + scene.getCode()); |
| | | throw new IllegalStateException("当前场景没有已发布 Prompt,sceneCode=" + scene.getCode()); |
| | | } |
| | | return prompt; |
| | | } |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AiPromptTemplate cancelPublish(Long id, Long operatorUserId) { |
| | | if (id == null) { |
| | | throw new IllegalArgumentException("id 不能为空"); |
| | | } |
| | | AiPromptTemplate db = this.getById(id); |
| | | if (db == null) { |
| | | throw new IllegalArgumentException("Prompt 不存在"); |
| | | } |
| | | if (!Short.valueOf((short) 1).equals(db.getPublished())) { |
| | | throw new IllegalArgumentException("当前 Prompt 不是已发布状态"); |
| | | } |
| | | db.setPublished((short) 0); |
| | | db.setPublishedBy(operatorUserId); |
| | | db.setPublishedTime(null); |
| | | this.updateById(db); |
| | | return db; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean deletePrompt(Long id) { |
| | | if (id == null) { |
| | | return false; |
| | |
| | | public int initDefaultsIfMissing() { |
| | | int changed = 0; |
| | | for (AiPromptScene scene : AiPromptScene.values()) { |
| | | AiPromptTemplate prompt = findPublished(scene.getCode()); |
| | | if (prompt == null) { |
| | | AiPromptTemplate latest = findLatest(scene.getCode()); |
| | | if (latest == null) { |
| | | ensurePublishedScene(scene); |
| | | changed++; |
| | | } |