#
Junjie
4 天以前 f0b4c2807c463698719d2f3de037f2225118cf9a
src/main/java/com/zy/ai/service/impl/AiPromptTemplateServiceImpl.java
@@ -34,13 +34,15 @@
            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;
    }
@@ -126,6 +128,26 @@
    @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;
@@ -145,8 +167,8 @@
    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++;
            }