Browse Source

问题功能添加

WH01243 5 tháng trước cách đây
mục cha
commit
82876591fa

+ 5 - 0
api/aiChat/v1/aiChatApi.go

@@ -65,3 +65,8 @@ type UsuallyProblemReq struct {
 	g.Meta `path:"/usuallyProblem" tags:"AiChat" method:"post" summary:"获取场景下的常见问题"`
 	Href   string `json:"href" v:"url"`
 }
+type UsuallyProblemRes struct {
+	ErrorMsg  string   `json:"error_msg"`
+	ErrorCode int64    `json:"error_code"`
+	Data      []string `json:"data" dc:"true:成功 false:失败"`
+}

+ 31 - 4
internal/controller/aiChat/aiChat_v1_chat_history.go

@@ -1,14 +1,41 @@
 package aiChat
 
 import (
+	"aiChat/internal/model"
+	"app.yhyue.com/moapp/jybase/encrypt"
 	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
+	"fmt"
+	"github.com/gogf/gf/v2/frame/g"
 
 	"aiChat/api/aiChat/v1"
 )
 
 func (c *ControllerV1) ChatHistory(ctx context.Context, req *v1.ChatHistoryReq) (res *v1.ChatHistoryRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
+	session := model.SessionCtx.Get(ctx).JSession
+	if session.PositionId <= 0 {
+		return nil, fmt.Errorf("请登录")
+	}
+	res = &v1.ChatHistoryRes{}
+	if req.PrevId != "" {
+		req.PrevId = encrypt.SE.Decode4Hex(req.PrevId) //id解密
+	}
+	history, hasNext, err := model.ChatHistory.GetMessage(session.PositionId, req.PageNum, req.PageSize, req.PrevId)
+	if err != nil {
+		g.Log().Error(ctx, "%d查询聊天记录异常,error:%s", session.PositionId, err)
+		res.ErrorCode = -1
+		res.ErrorMsg = "数据查询异常"
+		return
+	}
+	res.Data.HasMore = hasNext
+	for _, v := range history {
+		res.Data.List = append(res.Data.List, v1.History{
+			Id:         encrypt.SE.Encode2Hex(v.Id),
+			Content:    v.Content,
+			Type:       v.Type,
+			Useful:     v.Useful,
+			Actions:    v.Actions,
+			CreateTime: v.CreateTime.Unix(),
+		})
+	}
+	return
 }

+ 18 - 4
internal/controller/aiChat/aiChat_v1_evaluate.go

@@ -1,14 +1,28 @@
 package aiChat
 
 import (
+	"aiChat/internal/model"
+	"app.yhyue.com/moapp/jybase/encrypt"
 	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
+	"fmt"
 
 	"aiChat/api/aiChat/v1"
 )
 
 func (c *ControllerV1) Evaluate(ctx context.Context, req *v1.EvaluateReq) (res *v1.EvaluateRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
+	res = &v1.EvaluateRes{}
+	id := encrypt.SE.Decode4Hex(req.MessageId)
+	session := model.SessionCtx.Get(ctx).JSession
+	if session.PositionId <= 0 {
+		return nil, fmt.Errorf("请登录")
+	}
+
+	err = model.ChatHistory.Evaluate(session.PositionId, id, req.Evaluate)
+	if err != nil {
+		res.Data = false
+		return
+	} else {
+		res.Data = true
+	}
+	return
 }

+ 10 - 4
internal/controller/aiChat/aiChat_v1_find_answer.go

@@ -1,14 +1,20 @@
 package aiChat
 
 import (
+	"aiChat/internal/model"
 	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
+	"fmt"
 
 	"aiChat/api/aiChat/v1"
 )
 
 func (c *ControllerV1) FindAnswer(ctx context.Context, req *v1.FindAnswerReq) (res *v1.FindAnswerRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
+	res = &v1.FindAnswerRes{}
+	session := model.SessionCtx.Get(ctx).JSession
+	if session.PositionId <= 0 {
+		return nil, fmt.Errorf("请登录")
+	}
+
+	res, _ = model.Answer.FindAnswer(ctx, req)
+	return
 }

+ 11 - 4
internal/controller/aiChat/aiChat_v1_usually_problem.go

@@ -1,14 +1,21 @@
 package aiChat
 
 import (
+	"aiChat/internal/model"
 	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
+	"fmt"
+	"github.com/gogf/gf/v2/frame/g"
 
 	"aiChat/api/aiChat/v1"
 )
 
 func (c *ControllerV1) UsuallyProblem(ctx context.Context, req *v1.UsuallyProblemReq) (res *v1.UsuallyProblemRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
+	session := model.SessionCtx.Get(ctx).JSession
+	if session.PersonId <= 0 {
+		return nil, fmt.Errorf("请登录")
+	}
+	var list []string
+	list, err = model.Question.GetUsuallyProblem(ctx, req.Href, g.Config().MustGet(ctx, "chat.usuallyProblem", 5).Int())
+	return &v1.UsuallyProblemRes{Data: list}, nil
+
 }

+ 0 - 5
internal/controller/v1/v1.go

@@ -1,5 +0,0 @@
-// =================================================================================
-// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
-// =================================================================================
-
-package v1

+ 0 - 14
internal/controller/v1/v1_aiChat_chat_history.go

@@ -1,14 +0,0 @@
-package v1
-
-import (
-	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
-
-	"aiChat/api/v1/aiChat"
-)
-
-func (c *ControllerAiChat) ChatHistory(ctx context.Context, req *aiChat.ChatHistoryReq) (res *aiChat.ChatHistoryRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
-}

+ 0 - 14
internal/controller/v1/v1_aiChat_evaluate.go

@@ -1,14 +0,0 @@
-package v1
-
-import (
-	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
-
-	"aiChat/api/v1/aiChat"
-)
-
-func (c *ControllerAiChat) Evaluate(ctx context.Context, req *aiChat.EvaluateReq) (res *aiChat.EvaluateRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
-}

+ 0 - 14
internal/controller/v1/v1_aiChat_find_answer.go

@@ -1,14 +0,0 @@
-package v1
-
-import (
-	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
-
-	"aiChat/api/v1/aiChat"
-)
-
-func (c *ControllerAiChat) FindAnswer(ctx context.Context, req *aiChat.FindAnswerReq) (res *aiChat.FindAnswerRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
-}

+ 0 - 14
internal/controller/v1/v1_aiChat_usually_problem.go

@@ -1,14 +0,0 @@
-package v1
-
-import (
-	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
-
-	"aiChat/api/v1/aiChat"
-)
-
-func (c *ControllerAiChat) UsuallyProblem(ctx context.Context, req *aiChat.UsuallyProblemReq) (res *aiChat.UsuallyProblemRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
-}

+ 0 - 14
internal/controller/v1/v1_aiSearchApi_create_new_session.go

@@ -1,14 +0,0 @@
-package v1
-
-import (
-	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
-
-	"aiChat/api/v1/aiSearchApi"
-)
-
-func (c *ControllerAiSearchApi) CreateNewSession(ctx context.Context, req *aiSearchApi.CreateNewSessionReq) (res *aiSearchApi.CreateNewSessionRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
-}

+ 0 - 14
internal/controller/v1/v1_aiSearchApi_history_ss_list.go

@@ -1,14 +0,0 @@
-package v1
-
-import (
-	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
-
-	"aiChat/api/v1/aiSearchApi"
-)
-
-func (c *ControllerAiSearchApi) HistorySsList(ctx context.Context, req *aiSearchApi.HistorySsListReq) (res *aiSearchApi.HistorySsListRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
-}

+ 0 - 14
internal/controller/v1/v1_aiSearchApi_like_session.go

@@ -1,14 +0,0 @@
-package v1
-
-import (
-	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
-
-	"aiChat/api/v1/aiSearchApi"
-)
-
-func (c *ControllerAiSearchApi) LikeSession(ctx context.Context, req *aiSearchApi.LikeSessionReq) (res *aiSearchApi.LikeSessionRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
-}

+ 0 - 14
internal/controller/v1/v1_aiSearchApi_problem_collect.go

@@ -1,14 +0,0 @@
-package v1
-
-import (
-	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
-
-	"aiChat/api/v1/aiSearchApi"
-)
-
-func (c *ControllerAiSearchApi) ProblemCollect(ctx context.Context, req *aiSearchApi.ProblemCollectReq) (res *aiSearchApi.ProblemCollectRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
-}

+ 0 - 14
internal/controller/v1/v1_aiSearchApi_problem_configuration.go

@@ -1,14 +0,0 @@
-package v1
-
-import (
-	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
-
-	"aiChat/api/v1/aiSearchApi"
-)
-
-func (c *ControllerAiSearchApi) ProblemConfiguration(ctx context.Context, req *aiSearchApi.ProblemConfigurationReq) (res *aiSearchApi.ProblemConfigurationRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
-}

+ 0 - 14
internal/controller/v1/v1_aiSearchApi_problem_delete.go

@@ -1,14 +0,0 @@
-package v1
-
-import (
-	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
-
-	"aiChat/api/v1/aiSearchApi"
-)
-
-func (c *ControllerAiSearchApi) ProblemDelete(ctx context.Context, req *aiSearchApi.ProblemDeleteReq) (res *aiSearchApi.ProblemDeleteRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
-}

+ 0 - 14
internal/controller/v1/v1_aiSearchApi_problem_list.go

@@ -1,14 +0,0 @@
-package v1
-
-import (
-	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
-
-	"aiChat/api/v1/aiSearchApi"
-)
-
-func (c *ControllerAiSearchApi) ProblemList(ctx context.Context, req *aiSearchApi.ProblemListReq) (res *aiSearchApi.ProblemListRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
-}

+ 0 - 14
internal/controller/v1/v1_aiSearchApi_session_detail.go

@@ -1,14 +0,0 @@
-package v1
-
-import (
-	"context"
-
-	"github.com/gogf/gf/v2/errors/gcode"
-	"github.com/gogf/gf/v2/errors/gerror"
-
-	"aiChat/api/v1/aiSearchApi"
-)
-
-func (c *ControllerAiSearchApi) SessionDetail(ctx context.Context, req *aiSearchApi.SessionDetailReq) (res *aiSearchApi.SessionDetailRes, err error) {
-	return nil, gerror.NewCode(gcode.CodeNotImplemented)
-}

+ 0 - 17
internal/controller/v1/v1_new.go

@@ -1,17 +0,0 @@
-// =================================================================================
-// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
-// =================================================================================
-
-package v1
-
-type ControllerAiSearchApi struct{}
-
-func NewAiSearchApi() aiChat.IV1AiSearchApi {
-	return &ControllerAiSearchApi{}
-}
-
-type ControllerAiChat struct{}
-
-func NewAiChat() aiChat.IV1AiChat {
-	return &ControllerAiChat{}
-}