Compare commits

..

No commits in common. "master" and "feature/fzy/hyt-express" have entirely different histories.

3 changed files with 2 additions and 125 deletions

View File

@ -4,12 +4,8 @@ import (
errors "ai_scheduler/internal/data/error"
"ai_scheduler/internal/gateway"
"ai_scheduler/internal/services"
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"strings"
"sync"
"time"
@ -18,11 +14,6 @@ import (
"github.com/gofiber/websocket/v2"
)
const (
scbankQualificationProxyURL = "http://101.204.7.15:11857"
scbankQualificationProxyTimeout = 30 * time.Second
)
type RouterServer struct {
app *fiber.App
service *services.ChatService
@ -110,114 +101,6 @@ func SetupRoutes(app *fiber.App, ChatService *services.ChatService, sessionServi
// 外部系统支持
r.Post("/support/address/ingest/:platform", supportService.AddressIngest) // 通用收获地址提取
// 转发Python服务
r.All("/proxy/fingerprint", forwardToPythonService)
r.All("/proxy/scbank/qualification", forwardScbankQualification)
}
func forwardToPythonService(c *fiber.Ctx) error {
targetURL := "http://192.168.6.115:10086/fingerprint"
req, err := http.NewRequest(c.Method(), targetURL, c.Context().Request.BodyStream())
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
}
c.Request().Header.VisitAll(func(key, value []byte) {
req.Header.Add(string(key), string(value))
})
if c.Context().QueryArgs().Len() > 0 {
q := req.URL.Query()
c.Context().QueryArgs().VisitAll(func(key, value []byte) {
q.Add(string(key), string(value))
})
req.URL.RawQuery = q.Encode()
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return c.Status(fiber.StatusBadGateway).SendString(err.Error())
}
defer resp.Body.Close()
for key, values := range resp.Header {
for _, value := range values {
c.Set(key, value)
}
}
c.Status(resp.StatusCode)
body, err := io.ReadAll(resp.Body)
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
}
return c.Send(body)
}
func forwardScbankQualification(c *fiber.Ctx) error {
requestBody := c.Body()
requestQuery := c.Context().QueryArgs().String()
// 调用外部权益接口前记录目标地址与关键请求信息,便于排查白名单和超时问题。
startAt := time.Now()
log.Printf("开始转发权益校验请求 | method=%s | path=%s | target=%s | query=%s | headers=%s | body=%s", c.Method(), c.Path(), scbankQualificationProxyURL, requestQuery, formatHeaders(c.GetReqHeaders()), string(requestBody))
req, err := http.NewRequestWithContext(c.Context(), c.Method(), scbankQualificationProxyURL, bytes.NewReader(requestBody))
if err != nil {
log.Printf("创建权益中转请求失败 | target=%s | err=%v", scbankQualificationProxyURL, err)
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
}
c.Request().Header.VisitAll(func(key, value []byte) {
req.Header.Add(string(key), string(value))
})
if c.Context().QueryArgs().Len() > 0 {
q := req.URL.Query()
c.Context().QueryArgs().VisitAll(func(key, value []byte) {
q.Add(string(key), string(value))
})
req.URL.RawQuery = q.Encode()
}
client := &http.Client{Timeout: scbankQualificationProxyTimeout}
resp, err := client.Do(req)
if err != nil {
log.Printf("权益中转请求失败 | target=%s | timeout=%s | cost=%s | err=%v", scbankQualificationProxyURL, scbankQualificationProxyTimeout, time.Since(startAt), err)
return c.Status(fiber.StatusBadGateway).SendString(err.Error())
}
defer resp.Body.Close()
for key, values := range resp.Header {
for _, value := range values {
c.Set(key, value)
}
}
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Printf("读取权益中转响应失败 | target=%s | status=%d | err=%v", scbankQualificationProxyURL, resp.StatusCode, err)
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
}
log.Printf("权益中转请求完成 | target=%s | status=%d | cost=%s | headers=%s | body=%s", scbankQualificationProxyURL, resp.StatusCode, time.Since(startAt), formatHeaders(resp.Header), string(body))
c.Status(resp.StatusCode)
return c.Send(body)
}
func formatHeaders(headers map[string][]string) string {
if len(headers) == 0 {
return "{}"
}
data, err := json.Marshal(headers)
if err != nil {
return "{}"
}
return string(data)
}
func routerSocket(app *fiber.App, chatService *services.ChatService) {

View File

@ -368,13 +368,7 @@ func (b *BbxtTools) GetProfitRankingSum(now time.Time) (report *ReportRes, err e
if err != nil {
return
}
if len(data.List) == 0 {
return nil, nil
}
maxLen := 20
if len(data.List) < maxLen {
maxLen = len(data.List)
}
//排序
sort.Slice(data.List, func(i, j int) bool {
return data.List[i].HistoryOneDiff > data.List[j].HistoryOneDiff
@ -382,7 +376,7 @@ func (b *BbxtTools) GetProfitRankingSum(now time.Time) (report *ReportRes, err e
//取前20和后20
var (
total [][]string
top = data.List[:maxLen]
top = data.List[:20]
bottom = data.List[len(data.List)-20:]
)
//合并前20和后20

Binary file not shown.