update:修复默认模型没有修改到模版配置的bug

This commit is contained in:
hrz 2025-04-15 11:44:28 +08:00
parent 4bf950574c
commit 5823804dff
6 changed files with 85 additions and 95 deletions

View file

@ -3,6 +3,7 @@ package xiaozhi.modules.agent.service.impl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import xiaozhi.modules.agent.dao.AgentTemplateDao; import xiaozhi.modules.agent.dao.AgentTemplateDao;
@ -39,29 +40,30 @@ public class AgentTemplateServiceImpl extends ServiceImpl<AgentTemplateDao, Agen
@Override @Override
public void updateDefaultTemplateModelId(String modelType, String modelId) { public void updateDefaultTemplateModelId(String modelType, String modelId) {
modelType = modelType.toUpperCase(); modelType = modelType.toUpperCase();
AgentTemplateEntity defaultTemplate = getDefaultTemplate();
if (defaultTemplate != null) { UpdateWrapper<AgentTemplateEntity> wrapper = new UpdateWrapper<>();
switch (modelType) { switch (modelType) {
case "ASR": case "ASR":
defaultTemplate.setAsrModelId(modelId); wrapper.set("asr_model_id", modelId);
break; break;
case "VAD": case "VAD":
defaultTemplate.setVadModelId(modelId); wrapper.set("vad_model_id", modelId);
break; break;
case "LLM": case "LLM":
defaultTemplate.setLlmModelId(modelId); wrapper.set("llm_model_id", modelId);
break; break;
case "TTS": case "TTS":
defaultTemplate.setTtsModelId(modelId); wrapper.set("tts_model_id", modelId);
break; wrapper.set("tts_voice_id", null);
case "Memory": break;
defaultTemplate.setMemModelId(modelId); case "MEMORY":
break; wrapper.set("mem_model_id", modelId);
case "Intent": break;
defaultTemplate.setIntentModelId(modelId); case "INTENT":
break; wrapper.set("intent_model_id", modelId);
} break;
this.updateById(defaultTemplate);
} }
wrapper.ge("sort", 0);
update(wrapper);
} }
} }

View file

@ -135,6 +135,7 @@ public class ModelController {
} }
// 将其他模型设置为非默认 // 将其他模型设置为非默认
modelConfigService.setDefaultModel(entity.getModelType(), 0); modelConfigService.setDefaultModel(entity.getModelType(), 0);
entity.setIsEnabled(1);
entity.setIsDefault(1); entity.setIsDefault(1);
modelConfigService.updateById(entity); modelConfigService.updateById(entity);

View file

@ -42,6 +42,7 @@ public class ModelConfigServiceImpl extends BaseServiceImpl<ModelConfigDao, Mode
List<ModelConfigEntity> entities = modelConfigDao.selectList( List<ModelConfigEntity> entities = modelConfigDao.selectList(
new QueryWrapper<ModelConfigEntity>() new QueryWrapper<ModelConfigEntity>()
.eq("model_type", modelType) .eq("model_type", modelType)
.eq("is_enabled", 1)
.like(StringUtils.isNotBlank(modelName), "model_name", "%" + modelName + "%") .like(StringUtils.isNotBlank(modelName), "model_name", "%" + modelName + "%")
.select("id", "model_name")); .select("id", "model_name"));
return ConvertUtils.sourceToTarget(entities, ModelBasicInfoDTO.class); return ConvertUtils.sourceToTarget(entities, ModelBasicInfoDTO.class);

View file

@ -27,6 +27,7 @@ import xiaozhi.common.validator.ValidatorUtils;
import xiaozhi.common.validator.group.AddGroup; import xiaozhi.common.validator.group.AddGroup;
import xiaozhi.common.validator.group.DefaultGroup; import xiaozhi.common.validator.group.DefaultGroup;
import xiaozhi.common.validator.group.UpdateGroup; import xiaozhi.common.validator.group.UpdateGroup;
import xiaozhi.modules.config.service.ConfigService;
import xiaozhi.modules.sys.dto.SysParamsDTO; import xiaozhi.modules.sys.dto.SysParamsDTO;
import xiaozhi.modules.sys.service.SysParamsService; import xiaozhi.modules.sys.service.SysParamsService;
@ -42,6 +43,7 @@ import xiaozhi.modules.sys.service.SysParamsService;
@AllArgsConstructor @AllArgsConstructor
public class SysParamsController { public class SysParamsController {
private final SysParamsService sysParamsService; private final SysParamsService sysParamsService;
private final ConfigService configService;
@GetMapping("page") @GetMapping("page")
@Operation(summary = "分页") @Operation(summary = "分页")
@ -77,7 +79,7 @@ public class SysParamsController {
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
sysParamsService.save(dto); sysParamsService.save(dto);
configService.getConfig(false);
return new Result<Void>(); return new Result<Void>();
} }
@ -90,7 +92,7 @@ public class SysParamsController {
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
sysParamsService.update(dto); sysParamsService.update(dto);
configService.getConfig(false);
return new Result<Void>(); return new Result<Void>();
} }
@ -103,7 +105,7 @@ public class SysParamsController {
AssertUtils.isArrayEmpty(ids, "id"); AssertUtils.isArrayEmpty(ids, "id");
sysParamsService.delete(ids); sysParamsService.delete(ids);
configService.getConfig(false);
return new Result<Void>(); return new Result<Void>();
} }
} }

View file

@ -1,6 +1,6 @@
<template> <template>
<el-dialog :visible="dialogVisible" @update:visible="handleVisibleChange" width="975px" center custom-class="custom-dialog" :show-close="false" <el-dialog :visible="dialogVisible" @update:visible="handleVisibleChange" width="975px" center
class="center-dialog"> custom-class="custom-dialog" :show-close="false" class="center-dialog">
<div style="margin: 0 18px; text-align: left; padding: 10px; border-radius: 10px;"> <div style="margin: 0 18px; text-align: left; padding: 10px; border-radius: 10px;">
<div style="font-size: 30px; color: #3d4566; margin-top: -10px; margin-bottom: 10px; text-align: center;"> <div style="font-size: 30px; color: #3d4566; margin-top: -10px; margin-bottom: 10px; text-align: center;">
添加模型 添加模型
@ -18,7 +18,7 @@
<span style="margin-right: 8px;">是否启用</span> <span style="margin-right: 8px;">是否启用</span>
<el-switch v-model="formData.isEnabled" class="custom-switch"></el-switch> <el-switch v-model="formData.isEnabled" class="custom-switch"></el-switch>
</div> </div>
<div style="display: flex; align-items: center;"> <div style="display: none; align-items: center;">
<span style="margin-right: 8px;">设为默认</span> <span style="margin-right: 8px;">设为默认</span>
<el-switch v-model="formData.isDefault" class="custom-switch"></el-switch> <el-switch v-model="formData.isDefault" class="custom-switch"></el-switch>
</div> </div>
@ -65,18 +65,10 @@
<el-form :model="formData.configJson" label-width="auto" label-position="left" class="custom-form"> <el-form :model="formData.configJson" label-width="auto" label-position="left" class="custom-form">
<template v-for="(row, rowIndex) in chunkedCallInfoFields"> <template v-for="(row, rowIndex) in chunkedCallInfoFields">
<div :key="rowIndex" style="display: flex; gap: 20px; margin-bottom: 0;"> <div :key="rowIndex" style="display: flex; gap: 20px; margin-bottom: 0;">
<el-form-item <el-form-item v-for="field in row" :key="field.prop" :label="field.label" :prop="field.prop"
v-for="field in row"
:key="field.prop"
:label="field.label"
:prop="field.prop"
style="flex: 1;"> style="flex: 1;">
<el-input <el-input v-model="formData.configJson[field.prop]" :placeholder="field.placeholder"
v-model="formData.configJson[field.prop]" :type="field.type || 'text'" class="custom-input-bg" :show-password="field.type === 'password'">
:placeholder="field.placeholder"
:type="field.type || 'text'"
class="custom-input-bg"
:show-password="field.type === 'password'">
</el-input> </el-input>
</el-form-item> </el-form-item>
</div> </div>
@ -123,7 +115,7 @@ export default {
watch: { watch: {
visible(val) { visible(val) {
this.dialogVisible = val; this.dialogVisible = val;
if(val) { if (val) {
this.initConfigJson(); this.initConfigJson();
} else { } else {
this.resetForm(); this.resetForm();

View file

@ -17,7 +17,7 @@
<span style="margin-right: 8px;">是否启用</span> <span style="margin-right: 8px;">是否启用</span>
<el-switch v-model="form.isEnabled" :active-value="1" :inactive-value="0" class="custom-switch"></el-switch> <el-switch v-model="form.isEnabled" :active-value="1" :inactive-value="0" class="custom-switch"></el-switch>
</div> </div>
<div style="display: flex; align-items: center;"> <div style="display: none; align-items: center;">
<span style="margin-right: 8px;">设为默认</span> <span style="margin-right: 8px;">设为默认</span>
<el-switch v-model="form.isDefault" :active-value="1" :inactive-value="0" class="custom-switch"></el-switch> <el-switch v-model="form.isDefault" :active-value="1" :inactive-value="0" class="custom-switch"></el-switch>
</div> </div>
@ -64,18 +64,10 @@
<el-form :model="form.configJson" ref="callInfoForm" label-width="auto" class="custom-form"> <el-form :model="form.configJson" ref="callInfoForm" label-width="auto" class="custom-form">
<template v-for="(row, rowIndex) in chunkedCallInfoFields"> <template v-for="(row, rowIndex) in chunkedCallInfoFields">
<div :key="rowIndex" style="display: flex; gap: 20px; margin-bottom: 0;"> <div :key="rowIndex" style="display: flex; gap: 20px; margin-bottom: 0;">
<el-form-item <el-form-item v-for="field in row" :key="field.prop" :label="field.label" :prop="field.prop"
v-for="field in row"
:key="field.prop"
:label="field.label"
:prop="field.prop"
style="flex: 1;"> style="flex: 1;">
<el-input <el-input v-model="form.configJson[field.prop]" :placeholder="field.placeholder" :type="field.type"
v-model="form.configJson[field.prop]" class="custom-input-bg" :show-password="field.type === 'password'">
:placeholder="field.placeholder"
:type="field.type"
class="custom-input-bg"
:show-password="field.type === 'password'">
</el-input> </el-input>
</el-form-item> </el-form-item>
</div> </div>
@ -165,57 +157,57 @@ export default {
}, },
methods: { methods: {
resetForm() { resetForm() {
this.form = { this.form = {
id: "", id: "",
modelType: "", modelType: "",
modelCode: "", modelCode: "",
modelName: "", modelName: "",
isDefault: false, isDefault: false,
isEnabled: false, isEnabled: false,
docLink: "", docLink: "",
remark: "", remark: "",
sort: 0, sort: 0,
configJson: {} configJson: {}
}; };
this.dynamicCallInfoFields.forEach(field => { this.dynamicCallInfoFields.forEach(field => {
this.$set(this.form.configJson, field.prop, ''); this.$set(this.form.configJson, field.prop, '');
}); });
}, },
resetProviders() { resetProviders() {
this.providers = []; this.providers = [];
this.providersLoaded = false; this.providersLoaded = false;
}, },
loadModelData() { loadModelData() {
if (this.modelData.id) { if (this.modelData.id) {
Api.model.getModelConfig(this.modelData.id, ({ data }) => { Api.model.getModelConfig(this.modelData.id, ({ data }) => {
if (data.code === 0 && data.data) { if (data.code === 0 && data.data) {
const model = data.data; const model = data.data;
this.pendingProviderType = model.configJson.type; this.pendingProviderType = model.configJson.type;
this.pendingModelData = model; this.pendingModelData = model;
if (this.providersLoaded) { if (this.providersLoaded) {
this.loadProviderFields(model.configJson.type); this.loadProviderFields(model.configJson.type);
} else { } else {
this.loadProviders(); this.loadProviders();
} }
} }
}); });
} }
}, },
handleSave() { handleSave() {
const provideCode = this.form.configJson.type; const provideCode = this.form.configJson.type;
const formData = { const formData = {
id: this.modelData.id, id: this.modelData.id,
modelCode: this.form.modelCode, modelCode: this.form.modelCode,
modelName: this.form.modelName, modelName: this.form.modelName,
isDefault: this.form.isDefault ? 1 : 0, isDefault: this.form.isDefault ? 1 : 0,
isEnabled: this.form.isEnabled ? 1 : 0, isEnabled: this.form.isEnabled ? 1 : 0,
docLink: this.form.docLink, docLink: this.form.docLink,
remark: this.form.remark, remark: this.form.remark,
sort: this.form.sort || 0, sort: this.form.sort || 0,
configJson: { configJson: {
...this.form.configJson, ...this.form.configJson,
} }
}; };
this.$emit("save", { provideCode, formData }); this.$emit("save", { provideCode, formData });
this.dialogVisible = false; this.dialogVisible = false;