Browse Source

临时提交

boweniac 2 tuần trước cách đây
mục cha
commit
e55d933d6c

+ 56 - 0
internal/logic/department/create_department_logic.go

@@ -6,9 +6,11 @@ import (
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/suyuan32/simple-admin-core/rpc/types/core"
 	"github.com/zeromicro/go-zero/core/errorx"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 	"time"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
+	apps "wechat-api/mongo_model/apps"
 	team_members "wechat-api/mongo_model/team_members"
 	teams "wechat-api/mongo_model/teams"
 	users "wechat-api/mongo_model/users"
@@ -92,5 +94,59 @@ func (l *CreateDepartmentLogic) CreateDepartment(req *types.DepartmentInfo) (res
 		return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
 	}
 
+	// 创建默认智能体
+	apps_info := &apps.Apps{
+		TeamID:   teams_info.ID,
+		TmbID:    team_members_info.ID,
+		Name:     "默认智能体",
+		Type:     "simple",
+		Version:  "v2",
+		Avatar:   "/imgs/app/avatar/simple.svg",
+		Intro:    "",
+		TeamTags: []string{},
+		Modules:  []apps.AppModule{},
+		Edges: []apps.Edge{
+			{
+				Source:       "workflowStartNodeId",
+				Target:       "7BdojPlukIQw",
+				SourceHandle: "workflowStartNodeId-source-right",
+				TargetHandle: "7BdojPlukIQw-target-left",
+			},
+		},
+		PluginData: apps.PluginData{
+			ID:          primitive.NewObjectID(),
+			NodeVersion: "67da46d29667c5bf2120361a",
+		},
+		InheritPermission: true,
+		VersionNumber:     int32(0),
+		ChatConfig: apps.ChatConfig{
+			WelcomeText:   "",
+			Variables:     []interface{}{},
+			QuestionGuide: false,
+			TTSConfig: apps.TTSConfig{
+				Type: "web",
+			},
+			WhisperConfig: apps.WhisperConfig{
+				Open:            false,
+				AutoSend:        false,
+				AutoTTSResponse: false,
+			},
+			ScheduledTriggerConfig: nil,
+			ChatInputGuide: apps.ChatInputGuide{
+				Open:      false,
+				TextList:  []string{},
+				CustomUrl: "",
+			},
+			Instruction: "",
+			ID:          primitive.NewObjectID(),
+		},
+		UpdateTime: time.Date(2024, 7, 10, 12, 0, 18, 197000000, time.UTC),
+	}
+
+	err = l.svcCtx.MongoModel.TeamMembersModel.Insert(context.TODO(), team_members_info)
+	if err != nil {
+		return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
+	}
+
 	return &types.BaseMsgResp{Msg: errormsg.Success}, nil
 }

+ 25 - 0
mongo_model/apps/appsmodel.go

@@ -0,0 +1,25 @@
+package model
+
+import "github.com/zeromicro/go-zero/core/stores/mon"
+
+var _ AppsModel = (*customAppsModel)(nil)
+
+type (
+	// AppsModel is an interface to be customized, add more methods here,
+	// and implement the added methods in customAppsModel.
+	AppsModel interface {
+		appsModel
+	}
+
+	customAppsModel struct {
+		*defaultAppsModel
+	}
+)
+
+// NewAppsModel returns a model for the mongo.
+func NewAppsModel(url, db, collection string) AppsModel {
+	conn := mon.MustNewModel(url, db, collection)
+	return &customAppsModel{
+		defaultAppsModel: newDefaultAppsModel(conn),
+	}
+}

+ 75 - 0
mongo_model/apps/appsmodelgen.go

@@ -0,0 +1,75 @@
+// Code generated by goctl. DO NOT EDIT.
+// goctl 1.8.1
+
+package model
+
+import (
+	"context"
+	"time"
+
+	"github.com/zeromicro/go-zero/core/stores/mon"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
+	"go.mongodb.org/mongo-driver/mongo"
+)
+
+type appsModel interface {
+	Insert(ctx context.Context, data *Apps) error
+	FindOne(ctx context.Context, id string) (*Apps, error)
+	Update(ctx context.Context, data *Apps) (*mongo.UpdateResult, error)
+	Delete(ctx context.Context, id string) (int64, error)
+}
+
+type defaultAppsModel struct {
+	conn *mon.Model
+}
+
+func newDefaultAppsModel(conn *mon.Model) *defaultAppsModel {
+	return &defaultAppsModel{conn: conn}
+}
+
+func (m *defaultAppsModel) Insert(ctx context.Context, data *Apps) error {
+	if data.ID.IsZero() {
+		data.ID = primitive.NewObjectID()
+		data.UpdateTime = time.Now()
+	}
+
+	_, err := m.conn.InsertOne(ctx, data)
+	return err
+}
+
+func (m *defaultAppsModel) FindOne(ctx context.Context, id string) (*Apps, error) {
+	oid, err := primitive.ObjectIDFromHex(id)
+	if err != nil {
+		return nil, ErrInvalidObjectId
+	}
+
+	var data Apps
+
+	err = m.conn.FindOne(ctx, &data, bson.M{"_id": oid})
+	switch err {
+	case nil:
+		return &data, nil
+	case mon.ErrNotFound:
+		return nil, ErrNotFound
+	default:
+		return nil, err
+	}
+}
+
+func (m *defaultAppsModel) Update(ctx context.Context, data *Apps) (*mongo.UpdateResult, error) {
+	data.UpdateTime = time.Now()
+
+	res, err := m.conn.UpdateOne(ctx, bson.M{"_id": data.ID}, bson.M{"$set": data})
+	return res, err
+}
+
+func (m *defaultAppsModel) Delete(ctx context.Context, id string) (int64, error) {
+	oid, err := primitive.ObjectIDFromHex(id)
+	if err != nil {
+		return 0, ErrInvalidObjectId
+	}
+
+	res, err := m.conn.DeleteOne(ctx, bson.M{"_id": oid})
+	return res, err
+}

+ 114 - 0
mongo_model/apps/appstypes.go

@@ -0,0 +1,114 @@
+package model
+
+import (
+	"time"
+
+	"go.mongodb.org/mongo-driver/bson/primitive"
+)
+
+type AppModule struct {
+	NodeID       string      `bson:"nodeId" json:"nodeId"`
+	Name         string      `bson:"name" json:"name"`
+	Intro        string      `bson:"intro" json:"intro"`
+	Avatar       string      `bson:"avatar,omitempty" json:"avatar,omitempty"`
+	FlowNodeType string      `bson:"flowNodeType" json:"flowNodeType"`
+	ShowStatus   bool        `bson:"showStatus,omitempty" json:"showStatus,omitempty"`
+	Position     Position    `bson:"position" json:"position"`
+	Version      string      `bson:"version" json:"version"`
+	Inputs       []AppInput  `bson:"inputs" json:"inputs"`
+	Outputs      []AppOutput `bson:"outputs" json:"outputs"`
+}
+
+type Position struct {
+	X float64 `bson:"x" json:"x"`
+	Y float64 `bson:"y" json:"y"`
+}
+
+type AppInput struct {
+	Key             string      `bson:"key" json:"key"`
+	RenderTypeList  []string    `bson:"renderTypeList" json:"renderTypeList"`
+	ValueType       string      `bson:"valueType" json:"valueType"`
+	Label           string      `bson:"label" json:"label"`
+	ToolDescription string      `bson:"toolDescription,omitempty" json:"toolDescription,omitempty"`
+	Required        bool        `bson:"required,omitempty" json:"required,omitempty"`
+	Value           interface{} `bson:"value,omitempty" json:"value,omitempty"`
+	Min             *int32      `bson:"min,omitempty" json:"min,omitempty"`
+	Max             *int32      `bson:"max,omitempty" json:"max,omitempty"`
+	Step            *int32      `bson:"step,omitempty" json:"step,omitempty"`
+	Description     string      `bson:"description,omitempty" json:"description,omitempty"`
+	DebugLabel      string      `bson:"debugLabel,omitempty" json:"debugLabel,omitempty"`
+	Placeholder     string      `bson:"placeholder,omitempty" json:"placeholder,omitempty"`
+}
+
+type AppOutput struct {
+	ID          string `bson:"id" json:"id"`
+	Key         string `bson:"key" json:"key"`
+	Label       string `bson:"label" json:"label"`
+	Required    bool   `bson:"required,omitempty" json:"required,omitempty"`
+	Description string `bson:"description,omitempty" json:"description,omitempty"`
+	ValueType   string `bson:"valueType" json:"valueType"`
+	ValueDesc   string `bson:"valueDesc,omitempty" json:"valueDesc,omitempty"`
+	Type        string `bson:"type" json:"type"`
+}
+
+type Edge struct {
+	Source       string `bson:"source" json:"source"`
+	Target       string `bson:"target" json:"target"`
+	SourceHandle string `bson:"sourceHandle" json:"sourceHandle"`
+	TargetHandle string `bson:"targetHandle" json:"targetHandle"`
+}
+
+type PluginData struct {
+	ID          primitive.ObjectID `bson:"_id" json:"id"`
+	NodeVersion string             `bson:"nodeVersion" json:"nodeVersion"`
+}
+
+type TTSConfig struct {
+	Type string `bson:"type" json:"type"`
+}
+
+type WhisperConfig struct {
+	Open            bool `bson:"open" json:"open"`
+	AutoSend        bool `bson:"autoSend" json:"autoSend"`
+	AutoTTSResponse bool `bson:"autoTTSResponse" json:"autoTTSResponse"`
+}
+
+type ChatInputGuide struct {
+	Open      bool     `bson:"open" json:"open"`
+	TextList  []string `bson:"textList" json:"textList"`
+	CustomUrl string   `bson:"customUrl" json:"customUrl"`
+}
+
+type ChatConfig struct {
+	WelcomeText            string             `bson:"welcomeText" json:"welcomeText"`
+	Variables              []interface{}      `bson:"variables" json:"variables"`
+	QuestionGuide          bool               `bson:"questionGuide" json:"questionGuide"`
+	TTSConfig              TTSConfig          `bson:"ttsConfig" json:"ttsConfig"`
+	WhisperConfig          WhisperConfig      `bson:"whisperConfig" json:"whisperConfig"`
+	ScheduledTriggerConfig interface{}        `bson:"scheduledTriggerConfig" json:"scheduledTriggerConfig"`
+	ChatInputGuide         ChatInputGuide     `bson:"chatInputGuide" json:"chatInputGuide"`
+	Instruction            string             `bson:"instruction" json:"instruction"`
+	ID                     primitive.ObjectID `bson:"_id" json:"id"`
+}
+
+type Apps struct {
+	ID                       primitive.ObjectID  `bson:"_id,omitempty" json:"id,omitempty"`
+	ParentID                 *primitive.ObjectID `bson:"parentId,omitempty" json:"parentId,omitempty"`
+	TeamID                   primitive.ObjectID  `bson:"teamId" json:"teamId"`
+	TmbID                    primitive.ObjectID  `bson:"tmbId" json:"tmbId"`
+	Name                     string              `bson:"name" json:"name"`
+	Type                     string              `bson:"type" json:"type"`
+	Version                  string              `bson:"version" json:"version"`
+	Avatar                   string              `bson:"avatar" json:"avatar"`
+	Intro                    string              `bson:"intro" json:"intro"`
+	TeamTags                 []string            `bson:"teamTags" json:"teamTags"`
+	Modules                  []AppModule         `bson:"modules" json:"modules"`
+	Edges                    []Edge              `bson:"edges" json:"edges"`
+	PluginData               PluginData          `bson:"pluginData" json:"pluginData"`
+	InheritPermission        bool                `bson:"inheritPermission" json:"inheritPermission"`
+	UpdateTime               time.Time           `bson:"updateTime" json:"updateTime"`
+	VersionNumber            int32               `bson:"__v" json:"versionNumber"`
+	ChatConfig               ChatConfig          `bson:"chatConfig" json:"chatConfig"`
+	ScheduledTriggerConfig   interface{}         `bson:"scheduledTriggerConfig" json:"scheduledTriggerConfig"`
+	ScheduledTriggerNextTime interface{}         `bson:"scheduledTriggerNextTime" json:"scheduledTriggerNextTime"`
+}

+ 12 - 0
mongo_model/apps/error.go

@@ -0,0 +1,12 @@
+package model
+
+import (
+	"errors"
+
+	"github.com/zeromicro/go-zero/core/stores/mon"
+)
+
+var (
+	ErrNotFound        = mon.ErrNotFound
+	ErrInvalidObjectId = errors.New("invalid objectId")
+)