Forráskód Böngészése

Merge branch 'feature/fastgpt'

* feature/fastgpt:
  增加增删改接口
  list 接口输出 object id 转字符串
  fixbug
boweniac 1 hónapja
szülő
commit
7ec534caee

+ 2 - 2
desc/all.api

@@ -43,6 +43,6 @@ import "./wechat/credit_usage.api"
 import "./wechat/pay_recharge.api"
 import "./wechat/whatsapp.api"
 import "./wechat/whatsapp_channel.api"
-import "./wechat/api_key.api"
+import "./wechat/fastgpt.api"
 import "./wechat/department.api"
-import "./wechat/fastgpt.api"
+import "./wechat/api_key.api"

+ 25 - 0
desc/wechat/fastgpt.api

@@ -34,6 +34,22 @@ type (
 
         Intro string `json:"intro"`
     }
+
+    CreateAppsReq {
+        Type string `json:"type"`
+        Name string `json:"name"`
+        Intro *string `json:"intro,optional"`
+    }
+
+    UpdateAppsReq {
+        Id string `json:"id"`
+        Name string `json:"name"`
+        Intro *string `json:"intro,optional"`
+    }
+
+    DeleteAppsReq {
+        Id string `json:"id"`
+    }
 )
 
 @server(
@@ -58,4 +74,13 @@ service Wechat {
 service Wechat {
     @handler GetAppsList
     post /api/fastgpt/apps_list (AppsListReq) returns (AppsListResp)
+
+    @handler CreateApp
+    post /api/fastgpt/create_app (CreateAppsReq) returns (BaseMsgResp)
+
+    @handler UpdateApp
+    post /api/fastgpt/update_app (UpdateAppsReq) returns (BaseMsgResp)
+
+    @handler DeleteApp
+    post /api/fastgpt/delete_app (DeleteAppsReq) returns (BaseMsgResp)
 }

+ 44 - 0
internal/handler/fastgpt/create_app_handler.go

@@ -0,0 +1,44 @@
+package fastgpt
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/fastgpt"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /api/fastgpt/create_app fastgpt CreateApp
+//
+
+//
+
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: CreateAppsReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func CreateAppHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.CreateAppsReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := fastgpt.NewCreateAppLogic(r.Context(), svcCtx)
+		resp, err := l.CreateApp(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/fastgpt/delete_app_handler.go

@@ -0,0 +1,44 @@
+package fastgpt
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/fastgpt"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /api/fastgpt/delete_app fastgpt DeleteApp
+//
+
+//
+
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: DeleteAppsReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func DeleteAppHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.DeleteAppsReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := fastgpt.NewDeleteAppLogic(r.Context(), svcCtx)
+		resp, err := l.DeleteApp(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/fastgpt/update_app_handler.go

@@ -0,0 +1,44 @@
+package fastgpt
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/fastgpt"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /api/fastgpt/update_app fastgpt UpdateApp
+//
+
+//
+
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: UpdateAppsReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func UpdateAppHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.UpdateAppsReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := fastgpt.NewUpdateAppLogic(r.Context(), svcCtx)
+		resp, err := l.UpdateApp(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 40 - 25
internal/handler/routes.go

@@ -2070,28 +2070,43 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
+		[]rest.Route{
+			{
+				Method:  http.MethodGet,
+				Path:    "/api/fastgpt/set_token",
+				Handler: fastgpt.SetTokenHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/fastgpt/create",
+				Handler: fastgpt.CreateFastgptHandler(serverCtx),
+			},
+		},
+	)
+
+	server.AddRoutes(
 		rest.WithMiddlewares(
 			[]rest.Middleware{serverCtx.Authority},
 			[]rest.Route{
 				{
 					Method:  http.MethodPost,
-					Path:    "/api_key/create",
-					Handler: api_key.CreateApiKeyHandler(serverCtx),
+					Path:    "/api/fastgpt/apps_list",
+					Handler: fastgpt.GetAppsListHandler(serverCtx),
 				},
 				{
 					Method:  http.MethodPost,
-					Path:    "/api_key/update",
-					Handler: api_key.UpdateApiKeyHandler(serverCtx),
+					Path:    "/api/fastgpt/create_app",
+					Handler: fastgpt.CreateAppHandler(serverCtx),
 				},
 				{
 					Method:  http.MethodPost,
-					Path:    "/api_key/delete",
-					Handler: api_key.DeleteApiKeyHandler(serverCtx),
+					Path:    "/api/fastgpt/update_app",
+					Handler: fastgpt.UpdateAppHandler(serverCtx),
 				},
 				{
 					Method:  http.MethodPost,
-					Path:    "/api_key/list",
-					Handler: api_key.GetApiKeyListHandler(serverCtx),
+					Path:    "/api/fastgpt/delete_app",
+					Handler: fastgpt.DeleteAppHandler(serverCtx),
 				},
 			}...,
 		),
@@ -2133,28 +2148,28 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		[]rest.Route{
-			{
-				Method:  http.MethodGet,
-				Path:    "/api/fastgpt/set_token",
-				Handler: fastgpt.SetTokenHandler(serverCtx),
-			},
-			{
-				Method:  http.MethodPost,
-				Path:    "/api/fastgpt/create",
-				Handler: fastgpt.CreateFastgptHandler(serverCtx),
-			},
-		},
-	)
-
-	server.AddRoutes(
 		rest.WithMiddlewares(
 			[]rest.Middleware{serverCtx.Authority},
 			[]rest.Route{
 				{
 					Method:  http.MethodPost,
-					Path:    "/api/fastgpt/apps_list",
-					Handler: fastgpt.GetAppsListHandler(serverCtx),
+					Path:    "/api_key/create",
+					Handler: api_key.CreateApiKeyHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/api_key/update",
+					Handler: api_key.UpdateApiKeyHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/api_key/delete",
+					Handler: api_key.DeleteApiKeyHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/api_key/list",
+					Handler: api_key.GetApiKeyListHandler(serverCtx),
 				},
 			}...,
 		),

+ 410 - 0
internal/logic/fastgpt/create_app_logic.go

@@ -0,0 +1,410 @@
+package fastgpt
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"strconv"
+	"time"
+	apps "wechat-api/mongo_model/apps"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type CreateAppLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewCreateAppLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAppLogic {
+	return &CreateAppLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *CreateAppLogic) CreateApp(req *types.CreateAppsReq) (resp *types.BaseMsgResp, err error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+
+	organizationIdStr := strconv.FormatUint(organizationId, 10)
+
+	user, err := l.svcCtx.MongoModel.UsersModel.FindOneByUsername(context.TODO(), organizationIdStr)
+	if err != nil {
+		return nil, errorx.NewInvalidArgumentError("fastgpt get list failed " + err.Error())
+	}
+
+	teamMember, err := l.svcCtx.MongoModel.TeamMembersModel.FindOneByUserId(context.TODO(), user.ID)
+	if err != nil {
+		return nil, errorx.NewInvalidArgumentError("fastgpt get list failed " + err.Error())
+	}
+
+	intro := ""
+	if req.Intro != nil {
+		intro = *req.Intro
+	}
+	var apps_info *apps.Apps
+	if req.Type == "simple" {
+		// 创建默认智能体
+		apps_info = &apps.Apps{
+			ParentID: nil,
+			TeamID:   teamMember.TeamID,
+			TmbID:    teamMember.ID,
+			Name:     req.Name,
+			Type:     "simple",
+			Version:  "v2",
+			Avatar:   "/imgs/app/avatar/simple.svg",
+			Intro:    intro,
+			TeamTags: []string{},
+			Modules: []apps.AppModule{
+				{
+					NodeID:       "userGuide",
+					Name:         "系统配置",
+					Intro:        "",
+					FlowNodeType: "userGuide",
+					Position: apps.Position{
+						X: 531.242273606555,
+						Y: -486.761172954975,
+					},
+					Version: "481",
+					Inputs:  []apps.AppInput{},
+					Outputs: []apps.AppOutput{},
+				},
+				{
+					NodeID:       "workflowStartNodeId",
+					Name:         "流程开始",
+					Intro:        "",
+					Avatar:       "core/workflow/template/workflowStart",
+					FlowNodeType: "workflowStart",
+					Position: apps.Position{
+						X: 558.40823764155,
+						Y: 123.723874291941,
+					},
+					Version: "481",
+					Inputs: []apps.AppInput{
+						{
+							Key:             "userChatInput",
+							RenderTypeList:  []string{"reference", "textarea"},
+							ValueType:       "string",
+							Label:           "workflow:user_question",
+							ToolDescription: "workflow:user_question",
+							Required:        true,
+						},
+					},
+					Outputs: []apps.AppOutput{
+						{
+							ID:        "userChatInput",
+							Key:       "userChatInput",
+							Label:     "common:core.module.input.label.user question",
+							Type:      "static",
+							ValueType: "string",
+						},
+						{
+							ID:          "userFiles",
+							Key:         "userFiles",
+							Label:       "app:workflow.user_file_input",
+							Description: "app:workflow.user_file_input_desc",
+							Type:        "static",
+							ValueType:   "arrayString",
+						},
+					},
+				},
+				{
+					NodeID:       "7BdojPlukIQw",
+					Name:         "AI 对话",
+					Intro:        "AI 大模型对话",
+					Avatar:       "core/workflow/template/aiChat",
+					FlowNodeType: "chatNode",
+					ShowStatus:   true,
+					Position: apps.Position{
+						X: 1106.32383879608,
+						Y: -350.603067468347,
+					},
+					Version: "4813",
+					Inputs: []apps.AppInput{
+						{
+							Key:            "model",
+							RenderTypeList: []string{"settingLLMModel", "reference"},
+							ValueType:      "string",
+							Value:          "DeepSeek-V3",
+						},
+						{
+							Key:            "temperature",
+							RenderTypeList: []string{"hidden"},
+							ValueType:      "number",
+							Value:          int32(0),
+							Min:            getInt32(0),
+							Max:            getInt32(10),
+							Step:           getInt32(1),
+						},
+						{
+							Key:            "maxToken",
+							RenderTypeList: []string{"hidden"},
+							ValueType:      "number",
+							Value:          int32(2000),
+							Min:            getInt32(100),
+							Max:            getInt32(4000),
+							Step:           getInt32(50),
+						},
+						{
+							Key:            "isResponseAnswerText",
+							RenderTypeList: []string{"hidden"},
+							ValueType:      "boolean",
+							Value:          true,
+						},
+						{
+							Key:            "aiChatQuoteRole",
+							RenderTypeList: []string{"hidden"},
+							ValueType:      "string",
+							Value:          "system",
+						},
+						{
+							Key:            "quoteTemplate",
+							RenderTypeList: []string{"hidden"},
+							ValueType:      "string",
+						},
+						{
+							Key:            "quotePrompt",
+							RenderTypeList: []string{"hidden"},
+							ValueType:      "string",
+						},
+						{
+							Key:            "systemPrompt",
+							RenderTypeList: []string{"textarea", "reference"},
+							Max:            getInt32(3000),
+							ValueType:      "string",
+							Label:          "core.ai.Prompt",
+							Description:    "core.app.tip.systemPromptTip",
+							Placeholder:    "core.app.tip.chatNodeSystemPromptTip",
+							Value:          "",
+						},
+						{
+							Key:            "history",
+							RenderTypeList: []string{"numberInput", "reference"},
+							ValueType:      "chatHistory",
+							Label:          "core.module.input.label.chat history",
+							Required:       true,
+							Min:            getInt32(0),
+							Max:            getInt32(30),
+							Value:          int32(6),
+						},
+						{
+							Key:             "userChatInput",
+							RenderTypeList:  []string{"reference", "textarea"},
+							ValueType:       "string",
+							Label:           "common:core.module.input.label.user question",
+							Required:        true,
+							ToolDescription: "common:core.module.input.label.user question",
+							Value:           []interface{}{"workflowStartNodeId", "userChatInput"},
+						},
+						{
+							Key:            "quoteQA",
+							RenderTypeList: []string{"settingDatasetQuotePrompt"},
+							Label:          "",
+							DebugLabel:     "common:core.module.Dataset quote.label",
+							Description:    "",
+							ValueType:      "datasetQuote",
+						},
+						{
+							Key:            "fileUrlList",
+							RenderTypeList: []string{"reference", "input"},
+							Label:          "app:file_quote_link",
+							DebugLabel:     "app:file_quote_link",
+							ValueType:      "arrayString",
+							Value:          [][]interface{}{{"workflowStartNodeId", "userFiles"}},
+						},
+						{
+							Key:            "aiChatVision",
+							RenderTypeList: []string{"hidden"},
+							ValueType:      "boolean",
+							Value:          true,
+						},
+					},
+					Outputs: []apps.AppOutput{
+						{
+							ID:          "history",
+							Key:         "history",
+							Required:    true,
+							Label:       "common:core.module.output.label.New context",
+							Description: "common:core.module.output.description.New context",
+							ValueType:   "chatHistory",
+							ValueDesc:   "{\n  obj: System | Human | AI;\n  value: string;\n}[]",
+							Type:        "static",
+						},
+						{
+							ID:          "answerText",
+							Key:         "answerText",
+							Required:    true,
+							Label:       "common:core.module.output.label.Ai response content",
+							Description: "common:core.module.output.description.Ai response content",
+							ValueType:   "string",
+							Type:        "static",
+						},
+					},
+				},
+			},
+			Edges: []apps.Edge{
+				{
+					Source:       "workflowStartNodeId",
+					Target:       "7BdojPlukIQw",
+					SourceHandle: "workflowStartNodeId-source-right",
+					TargetHandle: "7BdojPlukIQw-target-left",
+				},
+			},
+			PluginData: apps.PluginData{
+				ID:          mustParseObjectID("67da46b29667c5bf21203554"),
+				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:          mustParseObjectID("67da46d29667c5bf2120361d"),
+			},
+			UpdateTime:               time.Date(2025, 3, 19, 4, 24, 4, 394000000, time.UTC),
+			ScheduledTriggerConfig:   nil,
+			ScheduledTriggerNextTime: nil,
+		}
+	} else {
+		apps_info = &apps.Apps{
+			ParentID: nil,
+			TeamID:   teamMember.TeamID,
+			TmbID:    teamMember.ID,
+			Name:     req.Name,
+			Type:     "advanced",
+			Version:  "v2",
+			Avatar:   "/imgs/app/avatar/workflow.svg",
+			Intro:    intro,
+			TeamTags: []string{},
+			Modules: []apps.AppModule{
+				{
+					NodeID:       "userGuide",
+					Name:         "common:core.module.template.system_config",
+					Intro:        "common:core.module.template.system_config_info",
+					Avatar:       "core/workflow/template/systemConfig",
+					FlowNodeType: "userGuide",
+					Position: apps.Position{
+						X: 262.273233881709,
+						Y: -476.002411365981,
+					},
+					Version: "481",
+					Inputs: []apps.AppInput{
+						{
+							Key:            "welcomeText",
+							RenderTypeList: []string{"hidden"},
+							ValueType:      "string",
+							Label:          "core.app.Welcome Text",
+							Value:          "",
+						}, {
+							Key:            "variables",
+							RenderTypeList: []string{"hidden"},
+							ValueType:      "any",
+							Label:          "core.app.Chat Variable",
+							Value:          []string{},
+						}, {
+							Key:            "questionGuide",
+							RenderTypeList: []string{"hidden"},
+							ValueType:      "boolean",
+							Label:          "core.app.Question Guide",
+							Value:          false,
+						}, {
+							Key:            "tts",
+							RenderTypeList: []string{"hidden"},
+							ValueType:      "any",
+							Label:          "",
+							Value: apps.AppInputValue{
+								Type: "web",
+							},
+						}, {
+							Key:            "whisper",
+							RenderTypeList: []string{"hidden"},
+							ValueType:      "any",
+							Label:          "",
+							Value: apps.AppInputValue{
+								Open:            false,
+								AutoSend:        false,
+								AutoTTSResponse: false,
+							},
+						}, {
+							Key:            "scheduleTrigger",
+							RenderTypeList: []string{"hidden"},
+							ValueType:      "any",
+							Label:          "",
+						},
+					},
+					Outputs: []apps.AppOutput{},
+				},
+				{
+					NodeID:       "448745",
+					Name:         "common:core.module.template.work_start",
+					Intro:        "",
+					Avatar:       "core/workflow/template/workflowStart",
+					FlowNodeType: "workflowStart",
+					Position: apps.Position{
+						X: 632.368838596004,
+						Y: -347.744649294401,
+					},
+					Version: "481",
+					Inputs: []apps.AppInput{
+						{
+							Key:             "userChatInput",
+							RenderTypeList:  []string{"reference", "textarea"},
+							ValueType:       "string",
+							Label:           "common:core.module.input.label.user question",
+							ToolDescription: "common:core.module.input.label.user question",
+							Required:        true,
+						},
+					},
+					Outputs: []apps.AppOutput{
+						{
+							ID:        "userChatInput",
+							Key:       "userChatInput",
+							Label:     "common:core.module.input.label.user question",
+							Type:      "static",
+							ValueType: "string",
+						},
+					},
+				},
+			},
+			Edges: []apps.Edge{},
+			PluginData: apps.PluginData{
+				ID:          mustParseObjectID("67dce247bd93cb6e085a6bda"),
+				NodeVersion: "481",
+			},
+			InheritPermission: true,
+			VersionNumber:     int32(0),
+			UpdateTime:        time.Date(2025, 3, 19, 4, 24, 4, 394000000, time.UTC),
+		}
+	}
+
+	if apps_info != nil {
+		err = l.svcCtx.MongoModel.AppsModel.Insert(context.TODO(), apps_info)
+		if err != nil {
+			return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
+		}
+	} else {
+		return nil, errorx.NewInvalidArgumentError("fastgpt create failed ")
+	}
+
+	return &types.BaseMsgResp{Msg: errormsg.Success}, nil
+}

+ 34 - 0
internal/logic/fastgpt/delete_app_logic.go

@@ -0,0 +1,34 @@
+package fastgpt
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type DeleteAppLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewDeleteAppLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteAppLogic {
+	return &DeleteAppLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *DeleteAppLogic) DeleteApp(req *types.DeleteAppsReq) (resp *types.BaseMsgResp, err error) {
+
+	_, err = l.svcCtx.MongoModel.AppsModel.Delete(context.TODO(), req.Id)
+	if err != nil {
+		return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
+	}
+
+	return &types.BaseMsgResp{Msg: errormsg.Success}, nil
+}

+ 3 - 3
internal/logic/fastgpt/get_apps_list_logic.go

@@ -49,9 +49,9 @@ func (l *GetAppsListLogic) GetAppsList(req *types.AppsListReq) (resp *types.Apps
 	if data != nil {
 		for _, app := range data {
 			appList = append(appList, &types.AppsListRespInfo{
-				Id:     app.ID.String(),
-				TeamId: app.TeamID.String(),
-				TmbId:  app.TmbID.String(),
+				Id:     app.ID.Hex(),
+				TeamId: app.TeamID.Hex(),
+				TmbId:  app.TmbID.Hex(),
 				Avatar: app.Avatar,
 				Name:   app.Name,
 				Intro:  app.Intro,

+ 43 - 0
internal/logic/fastgpt/update_app_logic.go

@@ -0,0 +1,43 @@
+package fastgpt
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	apps "wechat-api/mongo_model/apps"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type UpdateAppLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewUpdateAppLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateAppLogic {
+	return &UpdateAppLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *UpdateAppLogic) UpdateApp(req *types.UpdateAppsReq) (resp *types.BaseMsgResp, err error) {
+	intro := ""
+	if req.Intro != nil {
+		intro = *req.Intro
+	}
+	apps_info := &apps.Apps{
+		ID:    mustParseObjectID(req.Id),
+		Name:  req.Name,
+		Intro: intro,
+	}
+	_, err = l.svcCtx.MongoModel.AppsModel.UpdateInfo(context.TODO(), apps_info)
+	if err != nil {
+		return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
+	}
+
+	return &types.BaseMsgResp{Msg: errormsg.Success}, nil
+}

+ 75 - 56
internal/types/types.go

@@ -4184,47 +4184,53 @@ type WhatsappChannelInfoResp struct {
 	Data WhatsappChannelInfo `json:"data"`
 }
 
-// The data of api_key information | ApiKey信息
-// swagger:model ApiKeyInfo
-type ApiKeyInfo struct {
-	BaseIDInfo
-	// Title
-	Title *string `json:"title,optional"`
-	// Key
-	Key *string `json:"key,optional"`
-	// 租户ID
-	OrganizationId  *uint64    `json:"organization_id,optional"`
-	AgentId         *uint64    `json:"agent_id,optional"`
-	AgentInfo       *AgentInfo `json:"agent_info,optional"`
-	CustomAgentBase *string    `json:"custom_agent_base,optional"`
-	CustomAgentKey  *string    `json:"custom_agent_key,optional"`
-	OpenaiBase      *string    `json:"openai_base,optional"`
-	OpenaiKey       *string    `json:"openai_key,optional"`
+// swagger:model CreateInfo
+type CreateInfo struct {
+	// Translated Name | 展示名称
+	UserName string `json:"username"`
+	// Name | 部门名称
+	Title *string `json:"title"`
 }
 
-// The response data of api_key list | ApiKey列表数据
-// swagger:model ApiKeyListResp
-type ApiKeyListResp struct {
+// swagger:model AppsListReq
+type AppsListReq struct {
+	Type    string  `json:"type"`
+	Keyword *string `json:"keyword,optional"`
+}
+
+// swagger:model AppsListResp
+type AppsListResp struct {
 	BaseDataInfo
-	// ApiKey list data | ApiKey列表数据
-	Data ApiKeyListInfo `json:"data"`
+	Data []*AppsListRespInfo `json:"data"`
 }
 
-// ApiKey list data | ApiKey列表数据
-// swagger:model ApiKeyListInfo
-type ApiKeyListInfo struct {
-	BaseListInfo
-	// The API list data | ApiKey列表数据
-	Data []ApiKeyInfo `json:"data"`
+// swagger:model AppsListRespInfo
+type AppsListRespInfo struct {
+	Id     string `json:"_id"`
+	TeamId string `json:"teamId"`
+	TmbId  string `json:"tmbId"`
+	Avatar string `json:"avatar"`
+	Name   string `json:"name"`
+	Intro  string `json:"intro"`
 }
 
-// Get ApiKey list request params | ApiKey列表请求参数
-// swagger:model ApiKeyListReq
-type ApiKeyListReq struct {
-	PageInfo
-	// Key
-	Key            *string `json:"key,optional"`
-	OrganizationId *uint64 `json:"organization_id,optional"`
+// swagger:model CreateAppsReq
+type CreateAppsReq struct {
+	Type  string  `json:"type"`
+	Name  string  `json:"name"`
+	Intro *string `json:"intro,optional"`
+}
+
+// swagger:model UpdateAppsReq
+type UpdateAppsReq struct {
+	Id    string  `json:"id"`
+	Name  string  `json:"name"`
+	Intro *string `json:"intro,optional"`
+}
+
+// swagger:model DeleteAppsReq
+type DeleteAppsReq struct {
+	Id string `json:"id"`
 }
 
 // The response data of department information | 部门信息
@@ -4298,32 +4304,45 @@ type DepartmentInfoResp struct {
 	Data DepartmentInfo `json:"data"`
 }
 
-// swagger:model CreateInfo
-type CreateInfo struct {
-	// Translated Name | 展示名称
-	UserName string `json:"username"`
-	// Name | 部门名称
-	Title *string `json:"title"`
+// The data of api_key information | ApiKey信息
+// swagger:model ApiKeyInfo
+type ApiKeyInfo struct {
+	BaseIDInfo
+	// Title
+	Title *string `json:"title,optional"`
+	// Key
+	Key *string `json:"key,optional"`
+	// 租户ID
+	OrganizationId  *uint64    `json:"organization_id,optional"`
+	AgentId         *uint64    `json:"agent_id,optional"`
+	AgentInfo       *AgentInfo `json:"agent_info,optional"`
+	CustomAgentBase *string    `json:"custom_agent_base,optional"`
+	CustomAgentKey  *string    `json:"custom_agent_key,optional"`
+	OpenaiBase      *string    `json:"openai_base,optional"`
+	OpenaiKey       *string    `json:"openai_key,optional"`
 }
 
-// swagger:model AppsListReq
-type AppsListReq struct {
-	Type    string  `json:"type"`
-	Keyword *string `json:"keyword,optional"`
+// The response data of api_key list | ApiKey列表数据
+// swagger:model ApiKeyListResp
+type ApiKeyListResp struct {
+	BaseDataInfo
+	// ApiKey list data | ApiKey列表数据
+	Data ApiKeyListInfo `json:"data"`
 }
 
-// swagger:model AppsListResp
-type AppsListResp struct {
-	BaseDataInfo
-	Data []*AppsListRespInfo `json:"data"`
+// ApiKey list data | ApiKey列表数据
+// swagger:model ApiKeyListInfo
+type ApiKeyListInfo struct {
+	BaseListInfo
+	// The API list data | ApiKey列表数据
+	Data []ApiKeyInfo `json:"data"`
 }
 
-// swagger:model AppsListRespInfo
-type AppsListRespInfo struct {
-	Id     string `json:"_id"`
-	TeamId string `json:"teamId"`
-	TmbId  string `json:"tmbId"`
-	Avatar string `json:"avatar"`
-	Name   string `json:"name"`
-	Intro  string `json:"intro"`
+// Get ApiKey list request params | ApiKey列表请求参数
+// swagger:model ApiKeyListReq
+type ApiKeyListReq struct {
+	PageInfo
+	// Key
+	Key            *string `json:"key,optional"`
+	OrganizationId *uint64 `json:"organization_id,optional"`
 }

+ 19 - 1
mongo_model/apps/appsmodelgen.go

@@ -17,6 +17,7 @@ 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)
+	UpdateInfo(ctx context.Context, data *Apps) (*mongo.UpdateResult, error)
 	Delete(ctx context.Context, id string) (int64, error)
 	FindAll(ctx context.Context, teamId primitive. ObjectID, apptype string, keyword *string) ([]*Apps, error)
 }
@@ -65,6 +66,18 @@ func (m *defaultAppsModel) Update(ctx context.Context, data *Apps) (*mongo.Updat
 	return res, err
 }
 
+func (m *defaultAppsModel) UpdateInfo(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": bson.M{
+			"name":  data.Name,
+			"intro": data.Intro,
+		},
+	})
+	return res, err
+}
+
 func (m *defaultAppsModel) Delete(ctx context.Context, id string) (int64, error) {
 	oid, err := primitive.ObjectIDFromHex(id)
 	if err != nil {
@@ -78,11 +91,16 @@ func (m *defaultAppsModel) Delete(ctx context.Context, id string) (int64, error)
 func (m *defaultAppsModel) FindAll(ctx context.Context, teamId primitive. ObjectID, apptype string, keyword *string) ([]*Apps, error) {
 	var data []*Apps
 
+	k := ""
+	if keyword != nil {
+		k = *keyword
+	}
+
 	err := m.conn.Find(ctx, &data, bson.M{
 		"teamId": teamId,
 		"type": apptype,
 		"name": bson.M{
-			"$regex":   keyword, // 用你想要匹配的模式替换 searchPattern
+			"$regex":   k, // 用你想要匹配的模式替换 searchPattern
 			"$options": "i",              // 可选:i 表示不区分大小写
 		},
 	})

+ 7 - 0
mongo_model/apps/appstypes.go

@@ -40,6 +40,13 @@ type AppInput struct {
 	Placeholder     string      `bson:"placeholder,omitempty" json:"placeholder,omitempty"`
 }
 
+type AppInputValue struct {
+	Type            string `bson:"type" json:"type"`
+	Open            bool   `bson:"open" json:"open"`
+	AutoSend        bool   `bson:"autoSend" json:"autoSend"`
+	AutoTTSResponse bool   `bson:"autoTTSResponse" json:"autoTTSResponse"`
+}
+
 type AppOutput struct {
 	ID          string `bson:"id" json:"id"`
 	Key         string `bson:"key" json:"key"`