123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- package fastgpt
- import (
- "context"
- "github.com/suyuan32/simple-admin-common/msg/errormsg"
- "github.com/zeromicro/go-zero/core/errorx"
- "go.mongodb.org/mongo-driver/bson/primitive"
- "time"
- 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"
- "wechat-api/internal/svc"
- "wechat-api/internal/types"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type CreateFastgptLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewCreateFastgptLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateFastgptLogic {
- return &CreateFastgptLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx}
- }
- func (l *CreateFastgptLogic) CreateFastgpt(req *types.CreateInfo) (resp *types.BaseMsgResp, err error) {
- //创建 fastgpt 用户
- user_info := &users.Users{
- Status: "active",
- Username: req.UserName,
- Password: "838b0ad79fa89e8b3a0cfdc6eab90ac24d20e30ca862855b93a4c736f8cdfedf",
- Avatar: "/icon/human.svg",
- Balance: int32(200000),
- PromotionRate: int32(15),
- Timezone: "Asia/Shanghai",
- }
- err = l.svcCtx.MongoModel.UsersModel.Insert(context.TODO(), user_info)
- if err != nil {
- return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
- }
- // 创建团队
- teams_info := &teams.Teams{
- Name: *req.Title,
- OwnerID: user_info.ID,
- DefaultPermission: int32(0),
- Avatar: "/icon/logo.svg",
- CreateTime: time.Date(2024, 7, 10, 12, 0, 18, 197000000, time.UTC),
- Balance: int32(999900000),
- }
- err = l.svcCtx.MongoModel.TeamsModel.Insert(context.TODO(), teams_info)
- if err != nil {
- return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
- }
- // 创建团队关系
- team_members_info := &team_members.TeamMembers{
- TeamID: teams_info.ID,
- UserID: user_info.ID,
- Name: "Owner",
- Role: "owner",
- Status: "active",
- CreateTime: time.Date(2024, 7, 10, 12, 0, 18, 197000000, time.UTC),
- DefaultTeam: true,
- Version: int32(0),
- }
- err = l.svcCtx.MongoModel.TeamMembersModel.Insert(context.TODO(), team_members_info)
- if err != nil {
- return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
- }
- // 创建app
- apps_info := &apps.Apps{
- ParentID: nil,
- TeamID: teams_info.ID,
- TmbID: team_members_info.ID,
- Name: "默认智能体",
- Type: "simple",
- Version: "v2",
- Avatar: "/imgs/app/avatar/simple.svg",
- Intro: "",
- Modules: []apps.AppModule{
- {
- NodeID: "userGuide",
- Name: "系统配置",
- Position: Position{
- X: 531.24,
- Y: -486.76,
- },
- Inputs: [],
- Outputs: []Output{},
- },
- },
- Edges: []Edge{
- {
- Source: "workflowStartNodeId",
- Target: "7BdojPlukIQw",
- },
- },
- PluginData: PluginData{
- ID: primitive.NewObjectID(),
- NodeVersion: "67da46d29667c5bf2120361a",
- },
- UpdateTime: time.Date(2025, 3, 19, 4, 24, 4, 0, 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
- }
|