create_fastgpt_logic.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package fastgpt
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  5. "github.com/zeromicro/go-zero/core/errorx"
  6. "go.mongodb.org/mongo-driver/bson/primitive"
  7. "time"
  8. apps "wechat-api/mongo_model/apps"
  9. team_members "wechat-api/mongo_model/team_members"
  10. teams "wechat-api/mongo_model/teams"
  11. users "wechat-api/mongo_model/users"
  12. "wechat-api/internal/svc"
  13. "wechat-api/internal/types"
  14. "github.com/zeromicro/go-zero/core/logx"
  15. )
  16. type CreateFastgptLogic struct {
  17. logx.Logger
  18. ctx context.Context
  19. svcCtx *svc.ServiceContext
  20. }
  21. func NewCreateFastgptLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateFastgptLogic {
  22. return &CreateFastgptLogic{
  23. Logger: logx.WithContext(ctx),
  24. ctx: ctx,
  25. svcCtx: svcCtx}
  26. }
  27. func (l *CreateFastgptLogic) CreateFastgpt(req *types.CreateInfo) (resp *types.BaseMsgResp, err error) {
  28. //创建 fastgpt 用户
  29. user_info := &users.Users{
  30. Status: "active",
  31. Username: req.UserName,
  32. Password: "838b0ad79fa89e8b3a0cfdc6eab90ac24d20e30ca862855b93a4c736f8cdfedf",
  33. Avatar: "/icon/human.svg",
  34. Balance: int32(200000),
  35. PromotionRate: int32(15),
  36. Timezone: "Asia/Shanghai",
  37. }
  38. err = l.svcCtx.MongoModel.UsersModel.Insert(context.TODO(), user_info)
  39. if err != nil {
  40. return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
  41. }
  42. // 创建团队
  43. teams_info := &teams.Teams{
  44. Name: *req.Title,
  45. OwnerID: user_info.ID,
  46. DefaultPermission: int32(0),
  47. Avatar: "/icon/logo.svg",
  48. CreateTime: time.Date(2024, 7, 10, 12, 0, 18, 197000000, time.UTC),
  49. Balance: int32(999900000),
  50. }
  51. err = l.svcCtx.MongoModel.TeamsModel.Insert(context.TODO(), teams_info)
  52. if err != nil {
  53. return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
  54. }
  55. // 创建团队关系
  56. team_members_info := &team_members.TeamMembers{
  57. TeamID: teams_info.ID,
  58. UserID: user_info.ID,
  59. Name: "Owner",
  60. Role: "owner",
  61. Status: "active",
  62. CreateTime: time.Date(2024, 7, 10, 12, 0, 18, 197000000, time.UTC),
  63. DefaultTeam: true,
  64. Version: int32(0),
  65. }
  66. err = l.svcCtx.MongoModel.TeamMembersModel.Insert(context.TODO(), team_members_info)
  67. if err != nil {
  68. return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
  69. }
  70. // 创建app
  71. apps_info := &apps.Apps{
  72. ParentID: nil,
  73. TeamID: teams_info.ID,
  74. TmbID: team_members_info.ID,
  75. Name: "默认智能体",
  76. Type: "simple",
  77. Version: "v2",
  78. Avatar: "/imgs/app/avatar/simple.svg",
  79. Intro: "",
  80. Modules: []apps.AppModule{
  81. {
  82. NodeID: "userGuide",
  83. Name: "系统配置",
  84. Position: Position{
  85. X: 531.24,
  86. Y: -486.76,
  87. },
  88. Inputs: [],
  89. Outputs: []Output{},
  90. },
  91. },
  92. Edges: []Edge{
  93. {
  94. Source: "workflowStartNodeId",
  95. Target: "7BdojPlukIQw",
  96. },
  97. },
  98. PluginData: PluginData{
  99. ID: primitive.NewObjectID(),
  100. NodeVersion: "67da46d29667c5bf2120361a",
  101. },
  102. UpdateTime: time.Date(2025, 3, 19, 4, 24, 4, 0, time.UTC),
  103. }
  104. err = l.svcCtx.MongoModel.TeamMembersModel.Insert(context.TODO(), team_members_info)
  105. if err != nil {
  106. return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
  107. }
  108. return &types.BaseMsgResp{Msg: errormsg.Success}, nil
  109. }