41 lines
931 B
Go
41 lines
931 B
Go
package impl
|
|
|
|
import (
|
|
"ai_scheduler/internal/data/model"
|
|
"ai_scheduler/internal/entitys"
|
|
"ai_scheduler/tmpl/dataTemp"
|
|
"ai_scheduler/utils"
|
|
"encoding/json"
|
|
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
type BotConfigImpl struct {
|
|
dataTemp.DataTemp
|
|
}
|
|
|
|
func NewBotConfigImpl(db *utils.Db) *BotConfigImpl {
|
|
return &BotConfigImpl{
|
|
DataTemp: *dataTemp.NewDataTemp(db, new(model.AiBotConfig)),
|
|
}
|
|
}
|
|
|
|
// GetRobotConfig 获取机器人配置
|
|
func (b *BotConfigImpl) GetRobotConfig(robotCode string) (entitys.DingTalkBot, error) {
|
|
// 获取机器人配置
|
|
var botConfig model.AiBotConfig
|
|
cond := builder.NewCond().And(builder.Eq{"robot_code": robotCode})
|
|
err := b.GetOneBySearchToStrut(&cond, &botConfig)
|
|
if err != nil {
|
|
return entitys.DingTalkBot{}, err
|
|
}
|
|
// 解出 config
|
|
var config entitys.DingTalkBot
|
|
err = json.Unmarshal([]byte(botConfig.BotConfig), &config)
|
|
if err != nil {
|
|
return entitys.DingTalkBot{}, err
|
|
}
|
|
|
|
return config, nil
|
|
}
|