go-wxhelper/service/aiassistant/save.go

33 lines
716 B
Go
Raw Normal View History

2024-02-02 17:30:11 +08:00
package aiassistant
import (
"wechat-robot/internal/database"
"wechat-robot/model/entity"
"wechat-robot/model/param/aiassistant"
)
// Save
// @description: 保存AI助手
// @param p
// @return err
func Save(p aiassistant.Save) (err error) {
if p.Id == "" {
// 新增
var ent entity.AiAssistant
ent.Name = p.Name
ent.Personality = p.Personality
ent.Model = p.Model
ent.Enable = p.Enable
err = database.Client.Create(&ent).Error
} else {
// 修改
var pm = make(map[string]any)
pm["name"] = p.Name
pm["personality"] = p.Personality
pm["model"] = p.Model
pm["enable"] = p.Enable
err = database.Client.Model(&entity.AiAssistant{}).Where("id = ?", p.Id).Updates(pm).Error
}
return
}