Browse Source

修改LlmPromptTemplate模型moduleId字段为supplierId,同时修改对应接口路径;调整dao.update方法的传参用法

luoshi 5 months ago
parent
commit
1ed77600ea

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

@@ -1,14 +1,11 @@
 package com.qmth.ops.api.controller.admin;
 
-import com.qmth.boot.core.ai.model.llm.LlmAppType;
 import com.qmth.ops.api.constants.OpsApiConstants;
 import com.qmth.ops.api.security.AdminSession;
 import com.qmth.ops.api.security.Permission;
 import com.qmth.ops.biz.domain.LlmModel;
-import com.qmth.ops.biz.domain.LlmPromptTemplate;
 import com.qmth.ops.biz.service.LlmClientService;
 import com.qmth.ops.biz.service.LlmModelService;
-import com.qmth.ops.biz.service.LlmPromptTemplateService;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -21,9 +18,6 @@ public class LlmModelController {
     @Resource
     private LlmModelService llmModelService;
 
-    @Resource
-    private LlmPromptTemplateService llmPromptTemplateService;
-
     @Resource
     private LlmClientService llmClientService;
 
@@ -48,32 +42,4 @@ public class LlmModelController {
         return llmModelService.getById(model.getId());
     }
 
-    @PostMapping("/prompt_template/list")
-    public List<LlmPromptTemplate> getPromptTemplate(@RequestParam Long modelId, @RequestParam LlmAppType appType) {
-        return llmPromptTemplateService.findByModelAndAppType(modelId, appType);
-    }
-
-    @PostMapping("/prompt_template/insert")
-    public LlmPromptTemplate insertPromptTemplate(@RequestAttribute AdminSession adminSession,
-            LlmPromptTemplate template) {
-        adminSession.hasPermission(Permission.LLM_MODEL_EDIT);
-        llmPromptTemplateService.insert(template);
-        return template;
-    }
-
-    @PostMapping("/prompt_template/update")
-    public LlmPromptTemplate updatePromptTemplate(@RequestAttribute AdminSession adminSession,
-            LlmPromptTemplate template) {
-        adminSession.hasPermission(Permission.LLM_MODEL_EDIT);
-        llmPromptTemplateService.update(template);
-        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;
-    }
-
 }

+ 49 - 0
src/main/java/com/qmth/ops/api/controller/admin/LlmPromptController.java

@@ -0,0 +1,49 @@
+package com.qmth.ops.api.controller.admin;
+
+import com.qmth.boot.core.ai.model.llm.LlmAppType;
+import com.qmth.ops.api.constants.OpsApiConstants;
+import com.qmth.ops.api.security.AdminSession;
+import com.qmth.ops.api.security.Permission;
+import com.qmth.ops.biz.domain.LlmPromptTemplate;
+import com.qmth.ops.biz.service.LlmPromptTemplateService;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@RestController
+@RequestMapping(OpsApiConstants.ADMIN_URI_PREFIX + "/llm/prompt_template")
+public class LlmPromptController {
+
+    @Resource
+    private LlmPromptTemplateService llmPromptTemplateService;
+
+    @PostMapping("/list")
+    public List<LlmPromptTemplate> getPromptTemplate(@RequestParam Long supplierId, @RequestParam LlmAppType appType) {
+        return llmPromptTemplateService.findBySupplierAndAppType(supplierId, appType);
+    }
+
+    @PostMapping("/insert")
+    public LlmPromptTemplate insertPromptTemplate(@RequestAttribute AdminSession adminSession,
+            LlmPromptTemplate template) {
+        adminSession.hasPermission(Permission.LLM_SUPPLIER_INSERT);
+        llmPromptTemplateService.insert(template);
+        return template;
+    }
+
+    @PostMapping("/update")
+    public LlmPromptTemplate updatePromptTemplate(@RequestAttribute AdminSession adminSession,
+            LlmPromptTemplate template) {
+        adminSession.hasPermission(Permission.LLM_SUPPLIER_EDIT);
+        llmPromptTemplateService.update(template);
+        return llmPromptTemplateService.findById(template.getId());
+    }
+
+    @PostMapping("/delete")
+    public Long deletePromptTemplate(@RequestAttribute AdminSession adminSession, @RequestParam Long id) {
+        adminSession.hasPermission(Permission.LLM_SUPPLIER_EDIT);
+        llmPromptTemplateService.delete(llmPromptTemplateService.findById(id));
+        return id;
+    }
+
+}

+ 9 - 9
src/main/java/com/qmth/ops/biz/domain/LlmPromptTemplate.java

@@ -15,7 +15,7 @@ public class LlmPromptTemplate implements Serializable {
     @TableId(type = IdType.AUTO)
     private Long id;
 
-    private Long modelId;
+    private Long supplierId;
 
     private LlmAppType appType;
 
@@ -33,20 +33,20 @@ public class LlmPromptTemplate implements Serializable {
         this.id = id;
     }
 
-    public LlmAppType getAppType() {
-        return appType;
+    public Long getSupplierId() {
+        return supplierId;
     }
 
-    public void setAppType(LlmAppType appType) {
-        this.appType = appType;
+    public void setSupplierId(Long supplierId) {
+        this.supplierId = supplierId;
     }
 
-    public Long getModelId() {
-        return modelId;
+    public LlmAppType getAppType() {
+        return appType;
     }
 
-    public void setModelId(Long modelId) {
-        this.modelId = modelId;
+    public void setAppType(LlmAppType appType) {
+        this.appType = appType;
     }
 
     public String getSystem() {

+ 1 - 1
src/main/java/com/qmth/ops/biz/service/AppService.java

@@ -29,7 +29,7 @@ public class AppService extends ServiceImpl<AppDao, App> {
 
     @Transactional
     public void update(App app) {
-        appDao.update(app, new LambdaUpdateWrapper<App>().set(app.getCode() != null, App::getCode, app.getCode())
+        appDao.update(null, new LambdaUpdateWrapper<App>().set(app.getCode() != null, App::getCode, app.getCode())
                 .set(app.getName() != null, App::getName, app.getName())
                 .set(App::getUpdateTime, System.currentTimeMillis()).eq(App::getId, app.getId()));
     }

+ 1 - 1
src/main/java/com/qmth/ops/biz/service/EnvService.java

@@ -28,7 +28,7 @@ public class EnvService extends ServiceImpl<EnvDao, Env> {
 
     @Transactional
     public Env update(Env env) {
-        envDao.update(env, new LambdaUpdateWrapper<Env>().set(env.getCode() != null, Env::getCode, env.getCode())
+        envDao.update(null, new LambdaUpdateWrapper<Env>().set(env.getCode() != null, Env::getCode, env.getCode())
                 .set(env.getName() != null, Env::getName, env.getName())
                 .set(env.getType() != null, Env::getType, env.getType())
                 .set(Env::getUpdateTime, System.currentTimeMillis()).eq(Env::getId, env.getId()));

+ 1 - 1
src/main/java/com/qmth/ops/biz/service/LlmModelService.java

@@ -26,7 +26,7 @@ public class LlmModelService extends ServiceImpl<LlmModelDao, LlmModel> {
 
     @Transactional
     public void update(LlmModel model) {
-        modelDao.update(model,
+        modelDao.update(null,
                 new LambdaUpdateWrapper<LlmModel>().set(model.getName() != null, LlmModel::getName, model.getName())
                         .set(model.getQpm() != null, LlmModel::getQpm, model.getQpm())
                         .set(model.getTpm() != null, LlmModel::getTpm, model.getTpm())

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

@@ -36,7 +36,7 @@ public class LlmOrgConfigService extends ServiceImpl<LlmOrgConfigDao, LlmOrgConf
 
     @Transactional
     public void updateModelAndPrompt(LlmOrgConfig llmOrgConfig) {
-        llmOrgConfigDao.update(llmOrgConfig,
+        llmOrgConfigDao.update(null,
                 new LambdaUpdateWrapper<LlmOrgConfig>().set(LlmOrgConfig::getModelId, llmOrgConfig.getModelId())
                         .set(LlmOrgConfig::getPromptId, llmOrgConfig.getPromptId())
                         .eq(LlmOrgConfig::getOrgId, llmOrgConfig.getOrgId())

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

@@ -28,10 +28,10 @@ public class LlmPromptTemplateService {
         return llmPromptTemplateDao.selectById(id);
     }
 
-    public List<LlmPromptTemplate> findByModelAndAppType(Long modelId, LlmAppType appType) {
-        return llmPromptTemplateDao.selectList(
-                new LambdaQueryWrapper<LlmPromptTemplate>().eq(modelId != null, LlmPromptTemplate::getModelId, modelId)
-                        .eq(appType != null, LlmPromptTemplate::getAppType, appType));
+    public List<LlmPromptTemplate> findBySupplierAndAppType(Long supplierId, LlmAppType appType) {
+        return llmPromptTemplateDao.selectList(new LambdaQueryWrapper<LlmPromptTemplate>()
+                .eq(supplierId != null, LlmPromptTemplate::getSupplierId, supplierId)
+                .eq(appType != null, LlmPromptTemplate::getAppType, appType));
     }
 
     @Transactional
@@ -43,7 +43,7 @@ public class LlmPromptTemplateService {
     @Transactional
     //@CachePut(value = CACHE_NAME, key = "#template.id", unless = "#template==null")
     public void update(LlmPromptTemplate template) {
-        llmPromptTemplateDao.update(template,
+        llmPromptTemplateDao.update(null,
                 new LambdaUpdateWrapper<LlmPromptTemplate>().set(LlmPromptTemplate::getSystem, template.getSystem())
                         .set(LlmPromptTemplate::getUser, template.getUser())
                         .set(LlmPromptTemplate::getRemark, template.getRemark())

+ 1 - 1
src/main/java/com/qmth/ops/biz/service/LlmSupplierService.java

@@ -26,7 +26,7 @@ public class LlmSupplierService extends ServiceImpl<LlmSupplierDao, LlmSupplier>
 
     @Transactional
     public void update(LlmSupplier supplier) {
-        supplierDao.update(supplier, new LambdaUpdateWrapper<LlmSupplier>()
+        supplierDao.update(null, new LambdaUpdateWrapper<LlmSupplier>()
                 .set(supplier.getName() != null, LlmSupplier::getName, supplier.getName())
                 .set(supplier.getUrl() != null, LlmSupplier::getUrl, supplier.getUrl())
                 .set(supplier.getSecret() != null, LlmSupplier::getSecret, supplier.getSecret())

+ 1 - 1
src/main/java/com/qmth/ops/biz/service/ModuleService.java

@@ -28,7 +28,7 @@ public class ModuleService extends ServiceImpl<ModuleDao, Module> {
 
     @Transactional
     public Module update(Module module) {
-        moduleDao.update(module,
+        moduleDao.update(null,
                 new LambdaUpdateWrapper<Module>().set(module.getCode() != null, Module::getCode, module.getCode())
                         .set(module.getName() != null, Module::getName, module.getName())
                         .set(module.getEnable() != null, Module::getEnable, module.getEnable())

+ 1 - 1
src/main/java/com/qmth/ops/biz/service/OcrSupplierService.java

@@ -25,7 +25,7 @@ public class OcrSupplierService extends ServiceImpl<OcrSupplierDao, OcrSupplier>
 
     @Transactional
     public void update(OcrSupplier supplier) {
-        supplierDao.update(supplier, new LambdaUpdateWrapper<OcrSupplier>()
+        supplierDao.update(null, new LambdaUpdateWrapper<OcrSupplier>()
                 .set(supplier.getName() != null, OcrSupplier::getName, supplier.getName())
                 .set(supplier.getUrl() != null, OcrSupplier::getUrl, supplier.getUrl())
                 .set(supplier.getKey() != null, OcrSupplier::getKey, supplier.getKey())

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

@@ -155,7 +155,7 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
 
     @Transactional
     public PropertyItem updateBaselineItem(PropertyItem item) {
-        propertyItemDao.update(item, new LambdaUpdateWrapper<PropertyItem>()
+        propertyItemDao.update(null, new LambdaUpdateWrapper<PropertyItem>()
                 .set(item.getMode() != null, PropertyItem::getMode, item.getMode())
                 .set(item.getComment() != null, PropertyItem::getComment, item.getComment())
                 .eq(PropertyItem::getVersionId, item.getVersionId()).eq(PropertyItem::getModuleId, item.getModuleId())
@@ -181,7 +181,7 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
             throw new ParameterException("配置值不能为空");
         }
         if (previous != null) {
-            propertyItemDao.update(previous,
+            propertyItemDao.update(null,
                     new LambdaUpdateWrapper<PropertyItem>().set(PropertyItem::getValue, item.getValue())
                             .set(item.getComment() != null, PropertyItem::getComment, item.getComment())
                             .set(PropertyItem::getUpdateTime, System.currentTimeMillis())

+ 4 - 4
src/main/java/com/qmth/ops/biz/service/UserService.java

@@ -72,10 +72,10 @@ public class UserService extends ServiceImpl<UserDao, User> {
 
     @Transactional
     public User changeAccessToken(User user) {
-        user.setAccessToken(RandomStringUtils.random(16, true, false));
-        userDao.update(user, new LambdaUpdateWrapper<User>().set(User::getAccessToken, user.getAccessToken())
-                .eq(User::getId, user.getId()));
-        return user;
+        userDao.update(null,
+                new LambdaUpdateWrapper<User>().set(User::getAccessToken, RandomStringUtils.random(16, true, false))
+                        .eq(User::getId, user.getId()));
+        return userDao.selectById(user.getId());
     }
 
     public IPage<User> query(UserQuery query) {

+ 1 - 2
src/main/java/com/qmth/ops/biz/service/VersionService.java

@@ -1,7 +1,6 @@
 package com.qmth.ops.biz.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.ops.biz.dao.VersionDao;
@@ -45,7 +44,7 @@ public class VersionService extends ServiceImpl<VersionDao, Version> {
             version.setSubNumber(versionNumber.getSub());
         }
         version.setUpdateTime(System.currentTimeMillis());
-        versionDao.update(version, new LambdaUpdateWrapper<Version>().eq(Version::getId, version.getId()));
+        versionDao.updateById(version);
         return versionDao.selectById(version.getId());
     }
 

+ 7 - 7
src/main/resources/script/init.sql

@@ -241,14 +241,14 @@ CREATE TABLE IF NOT EXISTS `llm_org_config`
 
 CREATE TABLE IF NOT EXISTS `llm_prompt_template`
 (
-    `id`       bigint(20) unsigned NOT NULL AUTO_INCREMENT,
-    `model_id` bigint(20) unsigned NOT NULL,
-    `app_type` varchar(32)         NOT NULL,
-    `system`   text                NOT NULL,
-    `user`     text                NOT NULL,
-    `remark`   varchar(32)         NOT NULL,
+    `id`          bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+    `supplier_id` bigint(20) unsigned NOT NULL,
+    `app_type`    varchar(32)         NOT NULL,
+    `system`      text                NOT NULL,
+    `user`        text                NOT NULL,
+    `remark`      varchar(32)         NOT NULL,
     PRIMARY KEY (`id`),
-    KEY `model_app_type` (`model_id`, `app_type`)
+    KEY `supplier_app_type` (`supplier_id`, `app_type`)
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8mb4;