feat: 增加多账号并发
This commit is contained in:
parent
5264f78fb0
commit
2a312dc205
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -36,7 +37,7 @@ func (t *OrderAfterSaleResellerTool) Definition() entitys.ToolDefinition {
|
||||||
|
|
||||||
type OrderAfterSaleResellerRequest struct {
|
type OrderAfterSaleResellerRequest struct {
|
||||||
OrderNumber []string `json:"orderNumber"` // 订单号
|
OrderNumber []string `json:"orderNumber"` // 订单号
|
||||||
Account string `json:"account"` // 充值账号
|
Account []string `json:"account"` // 充值账号
|
||||||
SerialCreateTime string `json:"serialCreateTime"` // 流水创建时间
|
SerialCreateTime string `json:"serialCreateTime"` // 流水创建时间
|
||||||
AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款
|
AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款
|
||||||
AfterSalesPrice float64 `json:"afterSalesPrice"` // 售后金额
|
AfterSalesPrice float64 `json:"afterSalesPrice"` // 售后金额
|
||||||
|
|
@ -107,7 +108,7 @@ func (t *OrderAfterSaleResellerTool) Execute(ctx context.Context, requireData *e
|
||||||
if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil {
|
if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(req.OrderNumber) == 0 && req.Account == "" {
|
if len(req.OrderNumber) == 0 && len(req.Account) == 0 {
|
||||||
return fmt.Errorf("订单号 和 充值账号 不能同时为空")
|
return fmt.Errorf("订单号 和 充值账号 不能同时为空")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,41 +126,105 @@ func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleReseller(toolReq OrderAf
|
||||||
serialStartTime := serialCreateTime.Unix() - 10*60
|
serialStartTime := serialCreateTime.Unix() - 10*60
|
||||||
serialEndTime := serialCreateTime.Unix() + 10*60
|
serialEndTime := serialCreateTime.Unix() + 10*60
|
||||||
|
|
||||||
req := l_request.Request{
|
// 账号数量超过10直接截断
|
||||||
Url: t.config.BaseURL,
|
if len(toolReq.Account) > 10 {
|
||||||
Headers: map[string]string{
|
entitys.ResLog(requireData.Ch, t.Name(), "账号数量超过10已被截断")
|
||||||
|
toolReq.Account = toolReq.Account[:10]
|
||||||
|
}
|
||||||
|
|
||||||
|
headers := map[string]string{
|
||||||
"Authorization": fmt.Sprintf("Bearer %s", requireData.Auth),
|
"Authorization": fmt.Sprintf("Bearer %s", requireData.Auth),
|
||||||
},
|
}
|
||||||
Method: "POST",
|
|
||||||
Json: map[string]any{
|
// 最终输出
|
||||||
"orderNumber": toolReq.OrderNumber, // 流水号
|
var orderList []*OrderAfterSaleResellerData
|
||||||
"account": toolReq.Account, // 充值账号
|
|
||||||
|
// 多订单号
|
||||||
|
if len(toolReq.OrderNumber) > 0 {
|
||||||
|
body := map[string]any{
|
||||||
|
"orderNumber": toolReq.OrderNumber, // 订单号
|
||||||
|
}
|
||||||
|
orderList, err = t.getAfterSaleResellerList(headers, body, toolReq)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if len(toolReq.Account) > 0 {
|
||||||
|
// 多充值账号并发
|
||||||
|
orderListChan := make(chan []*OrderAfterSaleResellerData, len(toolReq.Account))
|
||||||
|
waitGroup := sync.WaitGroup{}
|
||||||
|
|
||||||
|
// 并发请求
|
||||||
|
for _, account := range toolReq.Account {
|
||||||
|
waitGroup.Add(1)
|
||||||
|
go func(account string) {
|
||||||
|
defer waitGroup.Done()
|
||||||
|
|
||||||
|
body := map[string]any{
|
||||||
|
"account": account, // 充值账号
|
||||||
"serialStartTime": serialStartTime, // 流水创建时间
|
"serialStartTime": serialStartTime, // 流水创建时间
|
||||||
"serialEndTime": serialEndTime, // 流水结束时间
|
"serialEndTime": serialEndTime, // 流水结束时间
|
||||||
},
|
}
|
||||||
|
orderListIn, errIn := t.getAfterSaleResellerList(headers, body, toolReq)
|
||||||
|
if errIn != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
orderListChan <- orderListIn
|
||||||
|
}(account)
|
||||||
|
}
|
||||||
|
|
||||||
|
waitGroup.Wait()
|
||||||
|
close(orderListChan)
|
||||||
|
|
||||||
|
// 合并结果
|
||||||
|
for orderListIn := range orderListChan {
|
||||||
|
orderList = append(orderList, orderListIn...)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("订单号 和 充值账号 不能同时为空")
|
||||||
|
}
|
||||||
|
|
||||||
|
toolResp := OrderAfterSaleResellerResponse{
|
||||||
|
Code: 0,
|
||||||
|
Msg: "Success",
|
||||||
|
Data: orderList,
|
||||||
|
}
|
||||||
|
|
||||||
|
var jsonByte []byte
|
||||||
|
jsonByte, err = json.Marshal(toolResp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成")
|
||||||
|
entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *OrderAfterSaleResellerTool) getAfterSaleResellerList(headers map[string]string, body map[string]any, originInput OrderAfterSaleResellerRequest) ([]*OrderAfterSaleResellerData, error) {
|
||||||
|
req := l_request.Request{
|
||||||
|
Url: t.config.BaseURL,
|
||||||
|
Headers: headers,
|
||||||
|
Method: "POST",
|
||||||
|
Json: body,
|
||||||
}
|
}
|
||||||
res, err := req.Send()
|
res, err := req.Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
// 解析响应
|
// 解析响应
|
||||||
var resp OrderAfterSaleResellerApiResponse
|
var resp OrderAfterSaleResellerApiResponse
|
||||||
if err = json.Unmarshal(res.Content, &resp); err != nil {
|
if err = json.Unmarshal(res.Content, &resp); err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
if resp.Code != 0 {
|
if resp.Code != 0 {
|
||||||
return fmt.Errorf("after sale supplier failed: %s", resp.Msg)
|
return nil, fmt.Errorf("after sale reseller failed: %s", resp.Msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
toolResp := OrderAfterSaleResellerResponse{
|
orderList := make([]*OrderAfterSaleResellerData, 0, len(resp.Data.Data))
|
||||||
Code: resp.Code,
|
|
||||||
Msg: resp.Msg,
|
|
||||||
Data: make([]*OrderAfterSaleResellerData, 0, len(resp.Data.Data)),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 转换数据
|
// 转换数据
|
||||||
for _, item := range resp.Data.Data {
|
for _, item := range resp.Data.Data {
|
||||||
toolResp.Data = append(toolResp.Data, &OrderAfterSaleResellerData{
|
orderList = append(orderList, &OrderAfterSaleResellerData{
|
||||||
OrderType: item.OrderType,
|
OrderType: item.OrderType,
|
||||||
OrderNumber: item.OrderNumber,
|
OrderNumber: item.OrderNumber,
|
||||||
OrderAmount: item.OrderAmount,
|
OrderAmount: item.OrderAmount,
|
||||||
|
|
@ -172,30 +237,23 @@ func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleReseller(toolReq OrderAf
|
||||||
OurProductTitle: item.OurProductTitle,
|
OurProductTitle: item.OurProductTitle,
|
||||||
Account: item.Account,
|
Account: item.Account,
|
||||||
Platforms: item.Platforms,
|
Platforms: item.Platforms,
|
||||||
AfterType: toolReq.AfterType,
|
AfterType: originInput.AfterType,
|
||||||
Remark: toolReq.AfterSalesReason,
|
Remark: originInput.AfterSalesReason,
|
||||||
AfterAmount: toolReq.AfterSalesPrice,
|
AfterAmount: originInput.AfterSalesPrice,
|
||||||
ResponsibleType: toolReq.ResponsibleType,
|
ResponsibleType: originInput.ResponsibleType,
|
||||||
ResponsiblePerson: toolReq.ResponsiblePerson,
|
ResponsiblePerson: originInput.ResponsiblePerson,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 追加扩展数据
|
// 追加扩展数据
|
||||||
for _, item := range toolResp.Data {
|
for _, item := range orderList {
|
||||||
if extItem, ok := resp.Data.ExtData[item.OrderNumber]; ok {
|
if extItem, ok := resp.Data.ExtData[item.OrderNumber]; ok {
|
||||||
item.IsExistsAfterSale = extItem.IsExistsAfterSale
|
item.IsExistsAfterSale = extItem.IsExistsAfterSale
|
||||||
item.CreateTime = extItem.SerialCreateTime
|
item.CreateTime = extItem.SerialCreateTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonByte, err := json.Marshal(toolResp)
|
return orderList, nil
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成")
|
|
||||||
entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte))
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleResellerMock(req OrderAfterSaleResellerRequest, requireData *entitys.RequireData) error {
|
func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleResellerMock(req OrderAfterSaleResellerRequest, requireData *entitys.RequireData) error {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -36,7 +37,7 @@ func (t *OrderAfterSaleSupplierTool) Definition() entitys.ToolDefinition {
|
||||||
|
|
||||||
type OrderAfterSaleSupplierRequest struct {
|
type OrderAfterSaleSupplierRequest struct {
|
||||||
SerialNumber []string `json:"serialNumber"` // 流水号
|
SerialNumber []string `json:"serialNumber"` // 流水号
|
||||||
Account string `json:"account"` // 充值账号
|
Account []string `json:"account"` // 充值账号
|
||||||
SerialCreateTime string `json:"serialCreateTime"` // 流水创建时间
|
SerialCreateTime string `json:"serialCreateTime"` // 流水创建时间
|
||||||
AfterSalesReason string `json:"afterSalesReason"` // 售后原因
|
AfterSalesReason string `json:"afterSalesReason"` // 售后原因
|
||||||
AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额
|
AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额
|
||||||
|
|
@ -103,7 +104,7 @@ func (t *OrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *e
|
||||||
if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil {
|
if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(req.SerialNumber) == 0 && req.Account == "" {
|
if len(req.SerialNumber) == 0 && len(req.Account) == 0 {
|
||||||
return fmt.Errorf("充值流水号 和 充值账号 不能同时为空")
|
return fmt.Errorf("充值流水号 和 充值账号 不能同时为空")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,41 +122,105 @@ func (t *OrderAfterSaleSupplierTool) checkOrderAfterSaleSupplier(toolReq OrderAf
|
||||||
serialStartTime := serialCreateTime.Unix() - 10*60
|
serialStartTime := serialCreateTime.Unix() - 10*60
|
||||||
serialEndTime := serialCreateTime.Unix() + 10*60
|
serialEndTime := serialCreateTime.Unix() + 10*60
|
||||||
|
|
||||||
req := l_request.Request{
|
// 账号数量超过10直接截断
|
||||||
Url: t.config.BaseURL,
|
if len(toolReq.Account) > 10 {
|
||||||
Headers: map[string]string{
|
entitys.ResLog(requireData.Ch, t.Name(), "账号数量超过10已被截断")
|
||||||
"Authorization": fmt.Sprintf("Bearer %s", requireData.Auth),
|
toolReq.Account = toolReq.Account[:10]
|
||||||
},
|
|
||||||
Method: "POST",
|
|
||||||
Json: map[string]any{
|
|
||||||
"serialNumber": toolReq.SerialNumber, // 流水号
|
|
||||||
"account": toolReq.Account, // 充值账号
|
|
||||||
"serialStartTime": serialStartTime, // 流水创建时间
|
|
||||||
"serialEndTime": serialEndTime, // 流水结束时间
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
res, err := req.Send()
|
|
||||||
|
headers := map[string]string{
|
||||||
|
"Authorization": fmt.Sprintf("Bearer %s", requireData.Auth),
|
||||||
|
}
|
||||||
|
|
||||||
|
// 最终输出
|
||||||
|
var orderList []*OrderAfterSaleSupplierData
|
||||||
|
|
||||||
|
// 多流水号
|
||||||
|
if len(toolReq.SerialNumber) > 0 {
|
||||||
|
body := map[string]any{
|
||||||
|
"serialNumber": toolReq.SerialNumber, // 流水号
|
||||||
|
}
|
||||||
|
orderList, err = t.getAfterSaleSupplierList(headers, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// 解析响应
|
} else if len(toolReq.Account) > 0 {
|
||||||
var resp OrderAfterSaleSupplierApiResponse
|
// 多充值账号并发
|
||||||
if err := json.Unmarshal(res.Content, &resp); err != nil {
|
orderListChan := make(chan []*OrderAfterSaleSupplierData, len(toolReq.Account))
|
||||||
return err
|
waitGroup := sync.WaitGroup{}
|
||||||
|
|
||||||
|
// 并发请求
|
||||||
|
for _, account := range toolReq.Account {
|
||||||
|
waitGroup.Add(1)
|
||||||
|
go func(account string) {
|
||||||
|
defer waitGroup.Done()
|
||||||
|
|
||||||
|
body := map[string]any{
|
||||||
|
"account": account, // 充值账号
|
||||||
|
"serialStartTime": serialStartTime, // 流水创建时间
|
||||||
|
"serialEndTime": serialEndTime, // 流水结束时间
|
||||||
}
|
}
|
||||||
if resp.Code != 0 {
|
orderListIn, errIn := t.getAfterSaleSupplierList(headers, body)
|
||||||
return fmt.Errorf("after sale supplier failed: %s", resp.Msg)
|
if errIn != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
orderListChan <- orderListIn
|
||||||
|
}(account)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 等待所有请求完成
|
||||||
|
waitGroup.Wait()
|
||||||
|
close(orderListChan)
|
||||||
|
|
||||||
|
for orderListIn := range orderListChan {
|
||||||
|
orderList = append(orderList, orderListIn...)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("充值流水号 和 充值账号 不能同时为空")
|
||||||
}
|
}
|
||||||
|
|
||||||
toolResp := OrderAfterSaleSupplierResponse{
|
toolResp := OrderAfterSaleSupplierResponse{
|
||||||
Code: resp.Code,
|
Code: 0,
|
||||||
Msg: resp.Msg,
|
Msg: "Success",
|
||||||
Data: make([]*OrderAfterSaleSupplierData, 0, len(resp.Data.Data)),
|
Data: orderList,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var jsonByte []byte
|
||||||
|
jsonByte, err = json.Marshal(toolResp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成")
|
||||||
|
entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *OrderAfterSaleSupplierTool) getAfterSaleSupplierList(headers map[string]string, body map[string]any) ([]*OrderAfterSaleSupplierData, error) {
|
||||||
|
req := l_request.Request{
|
||||||
|
Url: t.config.BaseURL,
|
||||||
|
Headers: headers,
|
||||||
|
Method: "POST",
|
||||||
|
Json: body,
|
||||||
|
}
|
||||||
|
res, err := req.Send()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// 解析响应
|
||||||
|
var resp OrderAfterSaleSupplierApiResponse
|
||||||
|
if err = json.Unmarshal(res.Content, &resp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if resp.Code != 0 {
|
||||||
|
return nil, fmt.Errorf("after sale supplier failed: %s", resp.Msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
orderList := make([]*OrderAfterSaleSupplierData, 0, len(resp.Data.Data))
|
||||||
|
|
||||||
// 转换数据
|
// 转换数据
|
||||||
for _, item := range resp.Data.Data {
|
for _, item := range resp.Data.Data {
|
||||||
toolResp.Data = append(toolResp.Data, &OrderAfterSaleSupplierData{
|
orderList = append(orderList, &OrderAfterSaleSupplierData{
|
||||||
SerialNumber: item.SerialNumber,
|
SerialNumber: item.SerialNumber,
|
||||||
PlatformName: item.PlatformName,
|
PlatformName: item.PlatformName,
|
||||||
SignCompany: item.SignCompany,
|
SignCompany: item.SignCompany,
|
||||||
|
|
@ -173,21 +238,14 @@ func (t *OrderAfterSaleSupplierTool) checkOrderAfterSaleSupplier(toolReq OrderAf
|
||||||
}
|
}
|
||||||
|
|
||||||
// 追加扩展数据
|
// 追加扩展数据
|
||||||
for _, item := range toolResp.Data {
|
for _, item := range orderList {
|
||||||
if extItem, ok := resp.Data.ExtData[item.SerialNumber]; ok {
|
if extItem, ok := resp.Data.ExtData[item.SerialNumber]; ok {
|
||||||
item.IsExistsAfterSale = extItem.IsExistsAfterSale
|
item.IsExistsAfterSale = extItem.IsExistsAfterSale
|
||||||
item.ExecuteTime = extItem.SerialCreateTime
|
item.ExecuteTime = extItem.SerialCreateTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonByte, err := json.Marshal(toolResp)
|
return orderList, nil
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成")
|
|
||||||
entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte))
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// mock待删除
|
// mock待删除
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue