Эх сурвалжийг харах

增加提示词模版删除功能

luoshi 11 сар өмнө
parent
commit
1c5488a6f6

+ 7 - 0
src/main/java/com/qmth/ops/api/controller/admin/LlmModelController.java

@@ -69,4 +69,11 @@ public class LlmModelController {
         return llmPromptTemplateService.findById(template.getId());
     }
 
+    @PostMapping("/prompt_template/delete")
+    public Long deletePromptTemplate(@RequestAttribute AdminSession adminSession, @RequestParam Long id) {
+        adminSession.hasPermission(Permission.LLM_MODEL_EDIT);
+        llmPromptTemplateService.delete(llmPromptTemplateService.findById(id));
+        return id;
+    }
+
 }

+ 6 - 0
src/main/java/com/qmth/ops/biz/service/LlmOrgConfigService.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.boot.core.ai.model.llm.LlmAppType;
 import com.qmth.ops.biz.dao.LlmOrgConfigDao;
 import com.qmth.ops.biz.domain.LlmOrgConfig;
+import com.qmth.ops.biz.domain.LlmPromptTemplate;
 import com.qmth.ops.biz.query.LlmOrgConfigQuery;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -23,6 +24,11 @@ public class LlmOrgConfigService extends ServiceImpl<LlmOrgConfigDao, LlmOrgConf
         return llmOrgConfigDao.findByQuery(query);
     }
 
+    public int countByPromptTemplate(LlmPromptTemplate template) {
+        return llmOrgConfigDao
+                .selectCount(new LambdaQueryWrapper<LlmOrgConfig>().eq(LlmOrgConfig::getPromptId, template.getId()));
+    }
+
     public LlmOrgConfig findByOrgAndAppType(Long orgId, LlmAppType appType) {
         return llmOrgConfigDao.selectOne(new LambdaQueryWrapper<LlmOrgConfig>().eq(LlmOrgConfig::getOrgId, orgId)
                 .eq(LlmOrgConfig::getAppType, appType));

+ 16 - 2
src/main/java/com/qmth/ops/biz/service/LlmPromptTemplateService.java

@@ -3,10 +3,9 @@ package com.qmth.ops.biz.service;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.qmth.boot.core.ai.model.llm.LlmAppType;
+import com.qmth.boot.core.exception.ParameterException;
 import com.qmth.ops.biz.dao.LlmPromptTemplateDao;
 import com.qmth.ops.biz.domain.LlmPromptTemplate;
-import org.springframework.cache.annotation.CachePut;
-import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -18,6 +17,9 @@ public class LlmPromptTemplateService {
 
     private static final String CACHE_NAME = "llm_prompt_template";
 
+    @Resource
+    private LlmOrgConfigService llmOrgConfigService;
+
     @Resource
     private LlmPromptTemplateDao llmPromptTemplateDao;
 
@@ -48,5 +50,17 @@ public class LlmPromptTemplateService {
                         .eq(LlmPromptTemplate::getId, template.getId()));
     }
 
+    @Transactional
+    //@CacheEvict(value = CACHE_NAME, key = "#template.id", unless = "#template==null")
+    public void delete(LlmPromptTemplate template) {
+        if (template == null) {
+            throw new ParameterException("提示词模版ID不存在");
+        }
+        if (llmOrgConfigService.countByPromptTemplate(template) > 0) {
+            throw new ParameterException("提示词模版有关联机构,不能删除");
+        }
+        llmPromptTemplateDao.deleteById(template.getId());
+    }
+
 }