Browse Source

Merge branch 'fixbug/task-603-0516-lcd' into debug

lichangdong 16 hours ago
parent
commit
b3355399f5

+ 18 - 0
desc/wechat/sop_task.api

@@ -150,6 +150,20 @@ type (
 		BaseDataInfo
 		Data string `json:"data"`
 	}
+
+	GetBotByTaskIdReq {
+    	TaskId int `json:"sourceId" validate:"required,number,gt=0"`
+    }
+
+    BotList {
+        Wxid string `json:"wxid"`
+        Nickname string `json:"nickname"`
+    }
+
+    GetBotByTaskIdResp {
+        BaseDataInfo
+        Data []BotList `json:"data"`
+    }
 )
 
 @server(
@@ -227,4 +241,8 @@ service Wechat {
 	// 根据内容生成AI回答
 	@handler generateAiAnswer
 	post /sop_task/generate_ai_answer (GenerateAiAnswerReq) returns (GenerateAiAnswerResp)
+
+
+	@handler getBotByTaskId
+    post /sop_task/get_bot_by_task_id (GetBotByTaskIdReq) returns (GetBotByTaskIdResp)
 }

+ 5 - 0
internal/handler/routes.go

@@ -674,6 +674,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 					Path:    "/sop_task/generate_ai_answer",
 					Handler: sop_task.GenerateAiAnswerHandler(serverCtx),
 				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/sop_task/get_bot_by_task_id",
+					Handler: sop_task.GetBotByTaskIdHandler(serverCtx),
+				},
 			}...,
 		),
 		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),

+ 44 - 0
internal/handler/sop_task/get_bot_by_task_id_handler.go

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

+ 52 - 0
internal/logic/sop_task/get_bot_by_task_id_logic.go

@@ -0,0 +1,52 @@
+package sop_task
+
+import (
+	"context"
+	"wechat-api/ent/soptask"
+	"wechat-api/ent/wx"
+	"wechat-api/internal/utils/dberrorhandler"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetBotByTaskIdLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetBotByTaskIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBotByTaskIdLogic {
+	return &GetBotByTaskIdLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetBotByTaskIdLogic) GetBotByTaskId(req *types.GetBotByTaskIdReq) (resp *types.GetBotByTaskIdResp, err error) {
+	taskId := req.TaskId
+	task, err := l.svcCtx.DB.SopTask.Query().
+		Where(soptask.ID(uint64(taskId))).
+		First(l.ctx)
+	if err != nil {
+		l.Error("查询任务失败", err)
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+	if len(task.BotWxidList) == 0 {
+		return &types.GetBotByTaskIdResp{Data: []types.BotList{}}, nil
+	}
+	var list []types.BotList
+	err = l.svcCtx.DB.Wx.Query().
+		Where(wx.WxidIn(task.BotWxidList...)).
+		Select(wx.FieldWxid, wx.FieldNickname).
+		Scan(l.ctx, &list)
+	if err != nil {
+		l.Error("查询机器人信息失败", err)
+		return nil, err
+	}
+	return &types.GetBotByTaskIdResp{Data: list}, nil
+
+}

+ 18 - 0
internal/types/types.go

@@ -1504,6 +1504,24 @@ type GenerateAiAnswerResp struct {
 	Data string `json:"data"`
 }
 
+// swagger:model GetBotByTaskIdReq
+type GetBotByTaskIdReq struct {
+	// required : true
+	// min : 0
+	TaskId int `json:"sourceId" validate:"required,number,gt=0"`
+}
+
+type BotList struct {
+	Wxid     string `json:"wxid"`
+	Nickname string `json:"nickname"`
+}
+
+// swagger:model GetBotByTaskIdResp
+type GetBotByTaskIdResp struct {
+	BaseDataInfo
+	Data []BotList `json:"data"`
+}
+
 // The response data of sop stage information | SopStage信息
 // swagger:model SopStageInfo
 type SopStageInfo struct {