Browse Source

临时提交

boweniac 1 week ago
parent
commit
b3e4397643

+ 1 - 1
crontask/init.go

@@ -44,7 +44,7 @@ func ScheduleRun(c *cron.Cron, serverCtx *svc.ServiceContext) {
 	})
 
 	syncWx := NewCronTask(context.Background(), serverCtx)
-	c.AddFunc("* * * * *", func() {
+	c.AddFunc("*/30 * * * *", func() {
 		syncWx.syncWx()
 	})
 }

+ 37 - 0
desc/wechat/fastgpt.api

@@ -8,6 +8,32 @@ type (
         // Name | 部门名称
         Title *string `json:"title"`
     }
+
+    AppsListReq {
+        Type string `json:"type"`
+
+        Keyword *string `json:"keyword,optional"`
+    }
+
+    AppsListResp {
+        BaseDataInfo
+
+        Data []*AppsListRespInfo `json:"data"`
+    }
+
+    AppsListRespInfo {
+        Id string `json:"_id"`
+
+        TeamId string `json:"teamId"`
+
+        TmbId string `json:"tmbId"`
+
+        Avatar string `json:"avatar"`
+
+        Name string `json:"name"`
+
+        Intro string `json:"intro"`
+    }
 )
 
 @server(
@@ -22,3 +48,14 @@ service Wechat {
     @handler CreateFastgpt
     post /api/fastgpt/create (CreateInfo) returns (BaseMsgResp)
 }
+
+@server(
+    jwt: Auth
+    group: fastgpt
+    middleware: Authority
+)
+
+service Wechat {
+    @handler GetAppsList
+    post /api/fastgpt/apps_list (AppsListReq) returns (AppsListResp)
+}

+ 44 - 0
internal/handler/fastgpt/get_apps_list_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/apps_list fastgpt GetAppsList
+//
+
+//
+
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: AppsListReq
+//
+// Responses:
+//  200: AppsListResp
+
+func GetAppsListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.AppsListReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := fastgpt.NewGetAppsListLogic(r.Context(), svcCtx)
+		resp, err := l.GetAppsList(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 14 - 0
internal/handler/routes.go

@@ -2146,4 +2146,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 			},
 		},
 	)
+
+	server.AddRoutes(
+		rest.WithMiddlewares(
+			[]rest.Middleware{serverCtx.Authority},
+			[]rest.Route{
+				{
+					Method:  http.MethodPost,
+					Path:    "/api/fastgpt/apps_list",
+					Handler: fastgpt.GetAppsListHandler(serverCtx),
+				},
+			}...,
+		),
+		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+	)
 }

+ 207 - 5
internal/logic/department/create_department_logic.go

@@ -96,6 +96,7 @@ func (l *CreateDepartmentLogic) CreateDepartment(req *types.DepartmentInfo) (res
 
 	// 创建默认智能体
 	apps_info := &apps.Apps{
+		ParentID: nil,
 		TeamID:   teams_info.ID,
 		TmbID:    team_members_info.ID,
 		Name:     "默认智能体",
@@ -104,7 +105,193 @@ func (l *CreateDepartmentLogic) CreateDepartment(req *types.DepartmentInfo) (res
 		Avatar:   "/imgs/app/avatar/simple.svg",
 		Intro:    "",
 		TeamTags: []string{},
-		Modules:  []apps.AppModule{},
+		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",
@@ -114,7 +301,7 @@ func (l *CreateDepartmentLogic) CreateDepartment(req *types.DepartmentInfo) (res
 			},
 		},
 		PluginData: apps.PluginData{
-			ID:          primitive.NewObjectID(),
+			ID:          mustParseObjectID("67da46b29667c5bf21203554"),
 			NodeVersion: "67da46d29667c5bf2120361a",
 		},
 		InheritPermission: true,
@@ -138,15 +325,30 @@ func (l *CreateDepartmentLogic) CreateDepartment(req *types.DepartmentInfo) (res
 				CustomUrl: "",
 			},
 			Instruction: "",
-			ID:          primitive.NewObjectID(),
+			ID:          mustParseObjectID("67da46d29667c5bf2120361d"),
 		},
-		UpdateTime: time.Date(2024, 7, 10, 12, 0, 18, 197000000, time.UTC),
+		UpdateTime:               time.Date(2025, 3, 19, 4, 24, 4, 394000000, time.UTC),
+		ScheduledTriggerConfig:   nil,
+		ScheduledTriggerNextTime: nil,
 	}
 
-	err = l.svcCtx.MongoModel.TeamMembersModel.Insert(context.TODO(), team_members_info)
+	err = l.svcCtx.MongoModel.AppsModel.Insert(context.TODO(), apps_info)
 	if err != nil {
 		return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
 	}
 
 	return &types.BaseMsgResp{Msg: errormsg.Success}, nil
 }
+
+func mustParseObjectID(hex string) primitive.ObjectID {
+	id, err := primitive.ObjectIDFromHex(hex)
+	if err != nil {
+		panic(err) // 或者根据需要处理错误
+	}
+	return id
+}
+
+func getInt32(n int32) *int32 {
+	num := int32(n)
+	return &num
+}

+ 50 - 0
internal/logic/fastgpt/get_apps_list_logic.go

@@ -0,0 +1,50 @@
+package fastgpt
+
+import (
+	"context"
+	"github.com/zeromicro/go-zero/core/errorx"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetAppsListLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetAppsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAppsListLogic {
+	return &GetAppsListLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetAppsListLogic) GetAppsList(req *types.AppsListReq) (resp *types.AppsListResp, err error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+
+	data, err := l.svcCtx.MongoModel.AppsModel.FindAll(context.TODO(), req.Type, req.Keyword)
+	if err != nil {
+		return nil, errorx.NewInvalidArgumentError("fastgpt get list failed " + err.Error())
+	}
+
+	var appList []*types.AppsListRespInfo
+
+	if data != nil {
+		for _, app := range data {
+			appList = append(appList, &types.AppsListRespInfo{
+				Id:     app.ID.String(),
+				TeamId: app.TeamID.String(),
+				TmbId:  app.TmbID.String(),
+				Avatar: app.Avatar,
+				Name:   app.Name,
+				Intro:  app.Intro,
+			})
+		}
+	}
+
+	return &types.AppsListResp{Data: appList}, nil
+}

+ 23 - 0
internal/types/types.go

@@ -4295,6 +4295,7 @@ type DepartmentInfoResp struct {
 	// Department information | 部门数据
 	Data DepartmentInfo `json:"data"`
 }
+
 // swagger:model CreateInfo
 type CreateInfo struct {
 	// Translated Name | 展示名称
@@ -4302,3 +4303,25 @@ type CreateInfo struct {
 	// Name | 部门名称
 	Title *string `json:"title"`
 }
+
+// swagger:model AppsListReq
+type AppsListReq struct {
+	Type    string  `json:"type"`
+	Keyword *string `json:"keyword,optional"`
+}
+
+// swagger:model AppsListResp
+type AppsListResp struct {
+	BaseDataInfo
+	Data []*AppsListRespInfo `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"`
+}

+ 21 - 0
mongo_model/apps/appsmodelgen.go

@@ -18,6 +18,7 @@ type appsModel interface {
 	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)
+	FindAll(ctx context.Context, apptype string, keyword *string) ([]*Apps, error)
 }
 
 type defaultAppsModel struct {
@@ -73,3 +74,23 @@ func (m *defaultAppsModel) Delete(ctx context.Context, id string) (int64, error)
 	res, err := m.conn.DeleteOne(ctx, bson.M{"_id": oid})
 	return res, err
 }
+
+func (m *defaultAppsModel) FindAll(ctx context.Context, apptype string, keyword *string) ([]*Apps, error) {
+	var data []*Apps
+
+	err := m.conn.Find(ctx, &data, bson.M{
+		"type": apptype,
+		"name": bson.M{
+			"$regex":   keyword, // 用你想要匹配的模式替换 searchPattern
+			"$options": "i",              // 可选:i 表示不区分大小写
+		},
+	})
+	switch err {
+	case nil:
+		return data, nil
+	case mon.ErrNotFound:
+		return nil, ErrNotFound
+	default:
+		return nil, err
+	}
+}