Compare commits

..

No commits in common. "f9e32e30231861fb6c37b46efec429e4f0dc9372" and "2edea5f0fbc51b633f51cf1ca67f0785866b3ede" have entirely different histories.

13 changed files with 147 additions and 192 deletions

View File

@ -1,21 +0,0 @@
# 创建最终镜像用于运行编译后的Go程序
FROM alpine
RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/main' > /etc/apk/repositories \
&& echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/community' >>/etc/apk/repositories \
&& apk update && apk add tzdata \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
# 设置工作目录
WORKDIR /app
# 将编译好的二进制文件从构建阶段复制到运行阶段
COPY ./ /app
ENV TZ=Asia/Shanghai
# 设置容器启动时运行的命令
CMD ["./bin/server"]

View File

@ -21,10 +21,3 @@ endif
# generate wire # generate wire
wire: wire:
cd ./cmd/server && wire cd ./cmd/server && wire
.PHONY: build
# build
build:
# make config;
make wire;
mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./...

View File

@ -1,18 +0,0 @@
export GO111MODULE=on
export GOPROXY=https://goproxy.cn,direct
export GOPATH=/root/go
export GOCACHE=/root/.cache/go-build
export CONTAINER_NAME=ai_scheduler
export CGO_ENABLED='0'
go mod tidy
make build
docker build -t ${CONTAINER_NAME} .
docker stop ${CONTAINER_NAME}
docker rm -f ${CONTAINER_NAME}
docker run -itd \
--name "${CONTAINER_NAME}" \
--restart=always \
-e "OLLAMA_BASE_URL=${OLLAMA_BASE_URL:-http://host.docker.internal:11434}" \
-p 8090:8090 \
"${CONTAINER_NAME}"

View File

@ -75,6 +75,50 @@ func (r *AiRouterBiz) Route(ctx context.Context, req *entitys.ChatRequest) (*ent
func (r *AiRouterBiz) RouteWithSocket(c *websocket.Conn, req *entitys.ChatSockRequest) (err error) { func (r *AiRouterBiz) RouteWithSocket(c *websocket.Conn, req *entitys.ChatSockRequest) (err error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
//ch := r.channelPool.Get()
ch := make(chan entitys.ResponseData)
done := make(chan struct{})
go func() {
defer close(done)
for {
select {
case v, ok := <-ch:
if !ok {
return
}
// 带超时的发送,避免阻塞
if err := sendWithTimeout(c, v, 2*time.Second); err != nil {
log.Errorf("Send error: %v", err)
cancel() // 通知主流程退出
return
}
case <-ctx.Done():
return
}
}
}()
defer func() {
if err != nil {
_ = entitys.MsgSend(c, entitys.ResponseData{
Done: false,
Content: err.Error(),
Type: entitys.ResponseErr,
})
}
_ = entitys.MsgSend(c, entitys.ResponseData{
Done: true,
Content: "",
Type: entitys.ResponseEnd,
})
//r.channelPool.Put(ch)
close(ch)
}()
session := c.Headers("X-Session", "") session := c.Headers("X-Session", "")
if len(session) == 0 { if len(session) == 0 {
return errors.SessionNotFound return errors.SessionNotFound
@ -88,77 +132,6 @@ func (r *AiRouterBiz) RouteWithSocket(c *websocket.Conn, req *entitys.ChatSockRe
return errors.KeyNotFound return errors.KeyNotFound
} }
var chat = make([]string, 0)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
//ch := r.channelPool.Get()
ch := make(chan entitys.Response)
done := make(chan struct{})
go func() {
defer func() {
close(done)
if len(chat) > 0 {
}
var his = []*model.AiChatHi{
{
SessionID: session,
Role: "user",
Content: req.Text,
},
}
if len(chat) > 0 {
his = append(his, &model.AiChatHi{
SessionID: session,
Role: "assistant",
Content: strings.Join(chat, ""),
})
}
for _, hi := range his {
r.hisImpl.Add(hi)
}
}()
for {
select {
case v, ok := <-ch:
if !ok {
return
}
// 带超时的发送,避免阻塞
if err = sendWithTimeout(c, v, 2*time.Second); err != nil {
log.Errorf("Send error: %v", err)
cancel() // 通知主流程退出
return
}
if v.Type == entitys.ResponseText || v.Type == entitys.ResponseStream {
chat = append(chat, v.Content)
}
case <-ctx.Done():
return
}
}
}()
defer func() {
if err != nil {
_ = entitys.MsgSend(c, entitys.Response{
Content: err.Error(),
Type: entitys.ResponseErr,
})
}
_ = entitys.MsgSend(c, entitys.Response{
Content: "",
Type: entitys.ResponseEnd,
})
//r.channelPool.Put(ch)
close(ch)
}()
sysInfo, err := r.getSysInfo(key) sysInfo, err := r.getSysInfo(key)
if err != nil { if err != nil {
return errors.SysNotFound return errors.SysNotFound
@ -178,8 +151,8 @@ func (r *AiRouterBiz) RouteWithSocket(c *websocket.Conn, req *entitys.ChatSockRe
AgentClient := r.utilAgent.Get() AgentClient := r.utilAgent.Get()
ch <- entitys.Response{ ch <- entitys.ResponseData{
Index: "", Done: false,
Content: "准备意图识别", Content: "准备意图识别",
Type: entitys.ResponseLog, Type: entitys.ResponseLog,
} }
@ -192,21 +165,46 @@ func (r *AiRouterBiz) RouteWithSocket(c *websocket.Conn, req *entitys.ChatSockRe
resMsg := match.Choices[0].Content resMsg := match.Choices[0].Content
r.utilAgent.Put(AgentClient) r.utilAgent.Put(AgentClient)
ch <- entitys.Response{ ch <- entitys.ResponseData{
Index: "", Done: false,
Content: resMsg, Content: resMsg,
Type: entitys.ResponseLog, Type: entitys.ResponseLog,
} }
ch <- entitys.Response{ ch <- entitys.ResponseData{
Index: "", Done: false,
Content: "意图识别结束", Content: "意图识别结束",
Type: entitys.ResponseLog, Type: entitys.ResponseLog,
} }
//for i := 1; i < 10; i++ {
// ch <- entitys.ResponseData{
// Done: false,
// Content: fmt.Sprintf("%d", i),
// Type: entitys.ResponseLog,
// }
// time.Sleep(1 * time.Second)
//}
//return
if err != nil { if err != nil {
log.Errorf("LLM error: %v", err) log.Errorf("LLM error: %v", err)
return errors.SystemError return errors.SystemError
} }
//msg, err := r.ollama.ToolSelect(ctx, r.getPromptOllama(sysInfo, history, req.Text), []api.Tool{})
//if err != nil {
// return
//}
//resMsg := msg.Message.Content
select {
case ch <- entitys.ResponseData{
Done: false,
Content: resMsg,
Type: entitys.ResponseLog,
}:
case <-ctx.Done():
return ctx.Err()
}
var matchJson entitys.Match var matchJson entitys.Match
if err := json.Unmarshal([]byte(resMsg), &matchJson); err != nil { if err := json.Unmarshal([]byte(resMsg), &matchJson); err != nil {
return errors.SystemError return errors.SystemError
@ -220,7 +218,7 @@ func (r *AiRouterBiz) RouteWithSocket(c *websocket.Conn, req *entitys.ChatSockRe
} }
// 辅助函数:带超时的 WebSocket 发送 // 辅助函数:带超时的 WebSocket 发送
func sendWithTimeout(c *websocket.Conn, data entitys.Response, timeout time.Duration) error { func sendWithTimeout(c *websocket.Conn, data entitys.ResponseData, timeout time.Duration) error {
sendCtx, cancel := context.WithTimeout(context.Background(), timeout) sendCtx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
@ -236,9 +234,9 @@ func sendWithTimeout(c *websocket.Conn, data entitys.Response, timeout time.Dura
return sendCtx.Err() return sendCtx.Err()
} }
} }
func (r *AiRouterBiz) handleOtherTask(c *websocket.Conn, ch chan entitys.Response, matchJson *entitys.Match) (err error) { func (r *AiRouterBiz) handleOtherTask(c *websocket.Conn, ch chan entitys.ResponseData, matchJson *entitys.Match) (err error) {
ch <- entitys.Response{ ch <- entitys.ResponseData{
Index: "", Done: false,
Content: matchJson.Reasoning, Content: matchJson.Reasoning,
Type: entitys.ResponseText, Type: entitys.ResponseText,
} }
@ -246,11 +244,11 @@ func (r *AiRouterBiz) handleOtherTask(c *websocket.Conn, ch chan entitys.Respons
return return
} }
func (r *AiRouterBiz) handleMatch(ctx context.Context, c *websocket.Conn, ch chan entitys.Response, matchJson *entitys.Match, tasks []model.AiTask, sysInfo model.AiSy) (err error) { func (r *AiRouterBiz) handleMatch(ctx context.Context, c *websocket.Conn, ch chan entitys.ResponseData, matchJson *entitys.Match, tasks []model.AiTask, sysInfo model.AiSy) (err error) {
if !matchJson.IsMatch { if !matchJson.IsMatch {
ch <- entitys.Response{ ch <- entitys.ResponseData{
Index: "", Done: false,
Content: matchJson.Reasoning, Content: matchJson.Reasoning,
Type: entitys.ResponseText, Type: entitys.ResponseText,
} }
@ -279,7 +277,7 @@ func (r *AiRouterBiz) handleMatch(ctx context.Context, c *websocket.Conn, ch cha
} }
} }
func (r *AiRouterBiz) handleTask(channel chan entitys.Response, c *websocket.Conn, matchJson *entitys.Match, task *model.AiTask) (err error) { func (r *AiRouterBiz) handleTask(channel chan entitys.ResponseData, c *websocket.Conn, matchJson *entitys.Match, task *model.AiTask) (err error) {
var configData entitys.ConfigDataTool var configData entitys.ConfigDataTool
err = json.Unmarshal([]byte(task.Config), &configData) err = json.Unmarshal([]byte(task.Config), &configData)
@ -295,7 +293,7 @@ func (r *AiRouterBiz) handleTask(channel chan entitys.Response, c *websocket.Con
} }
// 知识库 // 知识库
func (r *AiRouterBiz) handleKnowle(channel chan entitys.Response, c *websocket.Conn, matchJson *entitys.Match, task *model.AiTask, sysInfo model.AiSy) (err error) { func (r *AiRouterBiz) handleKnowle(channel chan entitys.ResponseData, c *websocket.Conn, matchJson *entitys.Match, task *model.AiTask, sysInfo model.AiSy) (err error) {
var ( var (
configData entitys.ConfigDataTool configData entitys.ConfigDataTool
@ -378,7 +376,7 @@ func (r *AiRouterBiz) handleKnowle(channel chan entitys.Response, c *websocket.C
return return
} }
func (r *AiRouterBiz) handleApiTask(channels chan entitys.Response, c *websocket.Conn, matchJson *entitys.Match, task *model.AiTask) (err error) { func (r *AiRouterBiz) handleApiTask(channels chan entitys.ResponseData, c *websocket.Conn, matchJson *entitys.Match, task *model.AiTask) (err error) {
var ( var (
request l_request.Request request l_request.Request
auth = c.Headers("X-Authorization", "") auth = c.Headers("X-Authorization", "")

View File

@ -6,33 +6,27 @@ import (
"github.com/gofiber/websocket/v2" "github.com/gofiber/websocket/v2"
) )
type ResponseType string type Response string
const ( const (
ResponseJson ResponseType = "json" ResponseJson Response = "json"
ResponseLoading ResponseType = "loading" ResponseLoading Response = "loading"
ResponseEnd ResponseType = "end" ResponseEnd Response = "end"
ResponseStream ResponseType = "stream" ResponseStream Response = "stream"
ResponseText ResponseType = "txt" ResponseText Response = "txt"
ResponseImg ResponseType = "img" ResponseImg Response = "img"
ResponseFile ResponseType = "file" ResponseFile Response = "file"
ResponseErr ResponseType = "error" ResponseErr Response = "error"
ResponseLog ResponseType = "log" ResponseLog Response = "log"
) )
type ResponseData struct { type ResponseData struct {
Done bool Done bool
Content string Content string
Type ResponseType Type Response
} }
type Response struct { func MsgSet(msgType Response, msg string, done bool) []byte {
Content string
Type ResponseType
Index string
}
func MsgSet(msgType ResponseType, msg string, done bool) []byte {
jsonByte, err := json.Marshal(ResponseData{ jsonByte, err := json.Marshal(ResponseData{
Done: done, Done: done,
Content: msg, Content: msg,
@ -45,7 +39,7 @@ func MsgSet(msgType ResponseType, msg string, done bool) []byte {
return jsonByte return jsonByte
} }
func MsgSend(c *websocket.Conn, msg Response) error { func MsgSend(c *websocket.Conn, msg ResponseData) error {
jsonByte, _ := json.Marshal(msg) jsonByte, _ := json.Marshal(msg)
return c.WriteMessage(websocket.TextMessage, jsonByte) return c.WriteMessage(websocket.TextMessage, jsonByte)

View File

@ -67,7 +67,7 @@ type Tool interface {
Name() string Name() string
Description() string Description() string
Definition() ToolDefinition Definition() ToolDefinition
Execute(channel chan Response, c *websocket.Conn, args json.RawMessage) error Execute(channel chan ResponseData, c *websocket.Conn, args json.RawMessage) error
} }
type ConfigDataHttp struct { type ConfigDataHttp struct {

View File

@ -60,7 +60,7 @@ func (c *Client) ToolSelect(ctx context.Context, messages []api.Message, tools [
return return
} }
func (c *Client) ChatStream(ctx context.Context, ch chan entitys.Response, messages []api.Message, index string) (err error) { func (c *Client) ChatStream(ctx context.Context, ch chan entitys.ResponseData, messages []api.Message) (err error) {
// 构建聊天请求 // 构建聊天请求
req := &api.ChatRequest{ req := &api.ChatRequest{
Model: c.config.Model, Model: c.config.Model,
@ -74,8 +74,8 @@ func (c *Client) ChatStream(ctx context.Context, ch chan entitys.Response, messa
defer w.Done() defer w.Done()
err = c.client.Chat(ctx, req, func(resp api.ChatResponse) error { err = c.client.Chat(ctx, req, func(resp api.ChatResponse) error {
if resp.Message.Content != "" { if resp.Message.Content != "" {
ch <- entitys.Response{ ch <- entitys.ResponseData{
Index: index, Done: false,
Content: resp.Message.Content, Content: resp.Message.Content,
Type: entitys.ResponseStream, Type: entitys.ResponseStream,
} }

View File

@ -7,11 +7,10 @@ import (
"bufio" "bufio"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http"
"strings"
"github.com/gofiber/fiber/v2/log" "github.com/gofiber/fiber/v2/log"
"github.com/gofiber/websocket/v2" "github.com/gofiber/websocket/v2"
"net/http"
"strings"
) )
// 知识库工具 // 知识库工具
@ -60,7 +59,7 @@ func (k *KnowledgeBaseTool) Definition() entitys.ToolDefinition {
} }
// Execute 执行知识库查询 // Execute 执行知识库查询
func (k *KnowledgeBaseTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage) error { func (k *KnowledgeBaseTool) Execute(channel chan entitys.ResponseData, c *websocket.Conn, args json.RawMessage) error {
var params KnowledgeBaseRequest var params KnowledgeBaseRequest
if err := json.Unmarshal(args, &params); err != nil { if err := json.Unmarshal(args, &params); err != nil {
@ -94,14 +93,14 @@ type MsgContent struct {
} }
// 解析知识库响应内容,并把通过channel结果返回 // 解析知识库响应内容,并把通过channel结果返回
func (this *KnowledgeBaseTool) msgContentParse(input string, channel chan entitys.Response) (msgContent MsgContent, err error) { func msgContentParse(input string, channel chan entitys.ResponseData) (msgContent MsgContent, err error) {
err = json.Unmarshal([]byte(input), &msgContent) err = json.Unmarshal([]byte(input), &msgContent)
if err != nil { if err != nil {
err = fmt.Errorf("unmarshal input failed: %w", err) err = fmt.Errorf("unmarshal input failed: %w", err)
} }
channel <- entitys.Response{ channel <- entitys.ResponseData{
Index: this.Name(), Done: msgContent.Done,
Content: msgContent.Content, Content: msgContent.Content,
Type: entitys.ResponseStream, Type: entitys.ResponseStream,
} }
@ -110,7 +109,7 @@ func (this *KnowledgeBaseTool) msgContentParse(input string, channel chan entity
} }
// 请求知识库聊天 // 请求知识库聊天
func (this *KnowledgeBaseTool) chat(channel chan entitys.Response, c *websocket.Conn, param KnowledgeBaseRequest) (err error) { func (this *KnowledgeBaseTool) chat(channel chan entitys.ResponseData, c *websocket.Conn, param KnowledgeBaseRequest) (err error) {
req := l_request.Request{ req := l_request.Request{
Method: "post", Method: "post",
@ -137,7 +136,7 @@ func (this *KnowledgeBaseTool) chat(channel chan entitys.Response, c *websocket.
} }
defer rsp.Body.Close() defer rsp.Body.Close()
err = this.connectAndReadSSE(rsp, channel) err = connectAndReadSSE(rsp, channel)
if err != nil { if err != nil {
return return
} }
@ -146,7 +145,7 @@ func (this *KnowledgeBaseTool) chat(channel chan entitys.Response, c *websocket.
} }
// 连接 SSE 并读取数据 // 连接 SSE 并读取数据
func (this *KnowledgeBaseTool) connectAndReadSSE(resp *http.Response, channel chan entitys.Response) error { func connectAndReadSSE(resp *http.Response, channel chan entitys.ResponseData) error {
// 验证响应状态和格式 // 验证响应状态和格式
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
@ -166,7 +165,7 @@ func (this *KnowledgeBaseTool) connectAndReadSSE(resp *http.Response, channel ch
if line == "" { if line == "" {
// 空行表示一条消息结束,处理当前消息 // 空行表示一条消息结束,处理当前消息
if currentMsg.Data != "" || currentMsg.Event != "" || currentMsg.ID != "" { if currentMsg.Data != "" || currentMsg.Event != "" || currentMsg.ID != "" {
_, err := this.msgContentParse(currentMsg.Data, channel) _, err := msgContentParse(currentMsg.Data, channel)
if err != nil { if err != nil {
return fmt.Errorf("msgContentParse failed: %w", err) return fmt.Errorf("msgContentParse failed: %w", err)
} }
@ -201,7 +200,7 @@ func (this *KnowledgeBaseTool) connectAndReadSSE(resp *http.Response, channel ch
// 处理最后一条未结束的消息(无结尾空行) // 处理最后一条未结束的消息(无结尾空行)
if currentMsg.Data != "" || currentMsg.Event != "" || currentMsg.ID != "" { if currentMsg.Data != "" || currentMsg.Event != "" || currentMsg.ID != "" {
_, err := this.msgContentParse(currentMsg.Data, channel) _, err := msgContentParse(currentMsg.Data, channel)
if err != nil { if err != nil {
return fmt.Errorf("msgContentParse failed: %w", err) return fmt.Errorf("msgContentParse failed: %w", err)
} }

View File

@ -100,7 +100,7 @@ func (m *Manager) GetToolDefinitions(caller constants.Caller) []entitys.ToolDefi
} }
// ExecuteTool 执行工具 // ExecuteTool 执行工具
func (m *Manager) ExecuteTool(channel chan entitys.Response, c *websocket.Conn, name string, args json.RawMessage) error { func (m *Manager) ExecuteTool(channel chan entitys.ResponseData, c *websocket.Conn, name string, args json.RawMessage) error {
tool, exists := m.GetTool(name) tool, exists := m.GetTool(name)
if !exists { if !exists {
return fmt.Errorf("tool not found: %s", name) return fmt.Errorf("tool not found: %s", name)

View File

@ -81,7 +81,7 @@ type ZltxOrderDetailData struct {
} }
// Execute 执行直连天下订单详情查询 // Execute 执行直连天下订单详情查询
func (w *ZltxOrderDetailTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage) error { func (w *ZltxOrderDetailTool) Execute(channel chan entitys.ResponseData, c *websocket.Conn, args json.RawMessage) error {
var req ZltxOrderDetailRequest var req ZltxOrderDetailRequest
if err := json.Unmarshal(args, &req); err != nil { if err := json.Unmarshal(args, &req); err != nil {
return fmt.Errorf("invalid zltxOrderDetail request: %w", err) return fmt.Errorf("invalid zltxOrderDetail request: %w", err)
@ -96,7 +96,7 @@ func (w *ZltxOrderDetailTool) Execute(channel chan entitys.Response, c *websocke
} }
// getMockZltxOrderDetail 获取模拟直连天下订单详情数据 // getMockZltxOrderDetail 获取模拟直连天下订单详情数据
func (w *ZltxOrderDetailTool) getZltxOrderDetail(ch chan entitys.Response, c *websocket.Conn, number string) (err error) { func (w *ZltxOrderDetailTool) getZltxOrderDetail(ch chan entitys.ResponseData, c *websocket.Conn, number string) (err error) {
//查询订单详情 //查询订单详情
var auth string var auth string
if c != nil { if c != nil {
@ -129,14 +129,14 @@ func (w *ZltxOrderDetailTool) getZltxOrderDetail(ch chan entitys.Response, c *we
if err = json.Unmarshal(res.Content, &resData); err != nil { if err = json.Unmarshal(res.Content, &resData); err != nil {
return return
} }
ch <- entitys.Response{ ch <- entitys.ResponseData{
Index: w.Name(), Done: false,
Content: res.Text, Content: res.Text,
Type: entitys.ResponseJson, Type: entitys.ResponseJson,
} }
if resData.Data.Direct != nil && resData.Data.Direct["needAi"].(bool) { if resData.Data.Direct != nil && resData.Data.Direct["needAi"].(bool) {
ch <- entitys.Response{ ch <- entitys.ResponseData{
Index: w.Name(), Done: false,
Content: "正在分析订单日志", Content: "正在分析订单日志",
Type: entitys.ResponseLoading, Type: entitys.ResponseLoading,
} }
@ -173,7 +173,7 @@ func (w *ZltxOrderDetailTool) getZltxOrderDetail(ch chan entitys.Response, c *we
Role: "user", Role: "user",
Content: fmt.Sprintf("订单日志:%s", string(dataJson)), Content: fmt.Sprintf("订单日志:%s", string(dataJson)),
}, },
}, w.Name()) })
if err != nil { if err != nil {
return fmt.Errorf("订单日志解析失败:%s", err) return fmt.Errorf("订单日志解析失败:%s", err)
} }

View File

@ -67,7 +67,7 @@ type ZltxOrderDirectLogData struct {
Data map[string]interface{} `json:"data"` Data map[string]interface{} `json:"data"`
} }
func (t *ZltxOrderLogTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage) error { func (t *ZltxOrderLogTool) Execute(channel chan entitys.ResponseData, c *websocket.Conn, args json.RawMessage) error {
var req ZltxOrderLogRequest var req ZltxOrderLogRequest
if err := json.Unmarshal(args, &req); err != nil { if err := json.Unmarshal(args, &req); err != nil {
return fmt.Errorf("invalid zltxOrderLog request: %w", err) return fmt.Errorf("invalid zltxOrderLog request: %w", err)
@ -78,7 +78,7 @@ func (t *ZltxOrderLogTool) Execute(channel chan entitys.Response, c *websocket.C
return t.getZltxOrderLog(channel, c, req.OrderNumber, req.SerialNumber) return t.getZltxOrderLog(channel, c, req.OrderNumber, req.SerialNumber)
} }
func (t *ZltxOrderLogTool) getZltxOrderLog(channel chan entitys.Response, c *websocket.Conn, orderNumber, serialNumber string) (err error) { func (t *ZltxOrderLogTool) getZltxOrderLog(channel chan entitys.ResponseData, c *websocket.Conn, orderNumber, serialNumber string) (err error) {
//查询订单详情 //查询订单详情
var auth string var auth string
if c != nil { if c != nil {
@ -106,10 +106,15 @@ func (t *ZltxOrderLogTool) getZltxOrderLog(channel chan entitys.Response, c *web
if err = json.Unmarshal(res.Content, &resData); err != nil { if err = json.Unmarshal(res.Content, &resData); err != nil {
return return
} }
channel <- entitys.Response{ if c != nil {
Index: t.Name(), _ = c.WriteMessage(websocket.TextMessage, res.Content)
Content: res.Text, return
Type: entitys.ResponseJson, } else {
channel <- entitys.ResponseData{
Done: false,
Content: res.Text,
Type: entitys.ResponseJson,
}
} }
return return
} }

View File

@ -52,7 +52,7 @@ type ZltxProductRequest struct {
Name string `json:"name"` Name string `json:"name"`
} }
func (z ZltxProductTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage) error { func (z ZltxProductTool) Execute(channel chan entitys.ResponseData, c *websocket.Conn, args json.RawMessage) error {
var req ZltxProductRequest var req ZltxProductRequest
if err := json.Unmarshal(args, &req); err != nil { if err := json.Unmarshal(args, &req); err != nil {
return fmt.Errorf("invalid zltxProduct request: %w", err) return fmt.Errorf("invalid zltxProduct request: %w", err)
@ -132,7 +132,7 @@ type ZltxProductData struct {
PlatformProductList interface{} `json:"platform_product_list"` PlatformProductList interface{} `json:"platform_product_list"`
} }
func (z ZltxProductTool) getZltxProduct(channel chan entitys.Response, c *websocket.Conn, id string, name string) error { func (z ZltxProductTool) getZltxProduct(channel chan entitys.ResponseData, c *websocket.Conn, id string, name string) error {
var auth string var auth string
if c != nil { if c != nil {
auth = c.Headers("X-Authorization", "") auth = c.Headers("X-Authorization", "")
@ -196,8 +196,8 @@ func (z ZltxProductTool) getZltxProduct(channel chan entitys.Response, c *websoc
if err != nil { if err != nil {
return err return err
} }
channel <- entitys.Response{ channel <- entitys.ResponseData{
Index: z.Name(), Done: false,
Content: string(marshal), Content: string(marshal),
Type: entitys.ResponseJson, Type: entitys.ResponseJson,
} }

View File

@ -46,7 +46,7 @@ type ZltxOrderStatisticsRequest struct {
Number string `json:"number"` Number string `json:"number"`
} }
func (z ZltxOrderStatisticsTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage) error { func (z ZltxOrderStatisticsTool) Execute(channel chan entitys.ResponseData, c *websocket.Conn, args json.RawMessage) error {
var req ZltxOrderStatisticsRequest var req ZltxOrderStatisticsRequest
if err := json.Unmarshal(args, &req); err != nil { if err := json.Unmarshal(args, &req); err != nil {
return err return err
@ -74,7 +74,7 @@ type ZltxOrderStatisticsData struct {
Total int `json:"total"` Total int `json:"total"`
} }
func (z ZltxOrderStatisticsTool) getZltxOrderStatistics(channel chan entitys.Response, c *websocket.Conn, number string) error { func (z ZltxOrderStatisticsTool) getZltxOrderStatistics(channel chan entitys.ResponseData, c *websocket.Conn, number string) error {
//查询订单详情 //查询订单详情
var auth string var auth string
if c != nil { if c != nil {
@ -102,10 +102,15 @@ func (z ZltxOrderStatisticsTool) getZltxOrderStatistics(channel chan entitys.Res
if resData.Code != 200 { if resData.Code != 200 {
return fmt.Errorf("zltx order statistics error: %s", resData.Error) return fmt.Errorf("zltx order statistics error: %s", resData.Error)
} }
channel <- entitys.Response{ if c != nil {
Index: z.Name(), _ = c.WriteMessage(websocket.TextMessage, res.Content)
Content: res.Text, return nil
Type: entitys.ResponseJson, } else {
channel <- entitys.ResponseData{
Done: false,
Content: res.Text,
Type: entitys.ResponseJson,
}
} }
return nil return nil
} }