fix
This commit is contained in:
parent
62dd14a627
commit
075f89df49
|
@ -27,11 +27,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/api/collection/get_collect_product_list",
|
Path: "/api/collection/get_collect_product_list",
|
||||||
Handler: GetCollectProductListHandler(serverCtx),
|
Handler: GetCollectProductListHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/api/collection/test_ai",
|
|
||||||
Handler: TestAiHandler(serverCtx),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/collection/internal/logic"
|
|
||||||
"fusenapi/server/collection/internal/svc"
|
|
||||||
"fusenapi/server/collection/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestAiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
var req types.TestAiReq
|
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewTestAiLogic(r.Context(), svcCtx)
|
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
|
||||||
basic.BeforeLogic(w, r, rl)
|
|
||||||
|
|
||||||
resp := l.TestAi(&req, userinfo, w)
|
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/constants"
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
"fusenapi/utils/curl"
|
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/collection/internal/svc"
|
|
||||||
"fusenapi/server/collection/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TestAiLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewTestAiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TestAiLogic {
|
|
||||||
return &TestAiLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *TestAiLogic) TestAi(req *types.TestAiReq, userinfo *auth.UserInfo, w http.ResponseWriter) (resp *basic.Response) {
|
|
||||||
lenAiHost := len(l.svcCtx.Config.BLMService.Urls)
|
|
||||||
if lenAiHost == 0 {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "ai host list is 0")
|
|
||||||
}
|
|
||||||
hostIndex := rand.Intn(lenAiHost)
|
|
||||||
var resultBLM constants.BLMServiceUrlResult
|
|
||||||
logx.Info("正在请求:" + l.svcCtx.Config.BLMService.Urls[hostIndex])
|
|
||||||
err := curl.NewClient(l.ctx, &curl.Config{
|
|
||||||
BaseUrl: l.svcCtx.Config.BLMService.Urls[hostIndex],
|
|
||||||
Url: constants.BLMServiceUrlLogoCombine,
|
|
||||||
RequireTimeout: time.Second * 15,
|
|
||||||
}).PostJson(req.Data, &resultBLM)
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "request failed")
|
|
||||||
}
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
||||||
// func (l *TestAiLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
||||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
// }
|
|
|
@ -40,10 +40,6 @@ type GetCollectProductListRspItem struct {
|
||||||
IsDeleted int64 `json:"is_deleted"`
|
IsDeleted int64 `json:"is_deleted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestAiReq struct {
|
|
||||||
Data map[string]interface{} `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,6 @@ service collection {
|
||||||
//获取收藏列表
|
//获取收藏列表
|
||||||
@handler GetCollectProductListHandler
|
@handler GetCollectProductListHandler
|
||||||
get /api/collection/get_collect_product_list(GetCollectProductListReq) returns (response);
|
get /api/collection/get_collect_product_list(GetCollectProductListReq) returns (response);
|
||||||
//测试算法合图并发
|
|
||||||
@handler TestAiHandler
|
|
||||||
post /api/collection/test_ai(TestAiReq) returns (response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//收藏产品
|
//收藏产品
|
||||||
|
@ -55,8 +52,4 @@ type GetCollectProductListRspItem {
|
||||||
MinPrice string `json:"min_price"`
|
MinPrice string `json:"min_price"`
|
||||||
IsShelf int64 `json:"is_shelf"`
|
IsShelf int64 `json:"is_shelf"`
|
||||||
IsDeleted int64 `json:"is_deleted"`
|
IsDeleted int64 `json:"is_deleted"`
|
||||||
}
|
|
||||||
//测试算法
|
|
||||||
type TestAiReq {
|
|
||||||
Data map[string]interface{} `json:"data"`
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user