diff --git a/deploy/wait-for-it.sh b/deploy/wait-for-it.sh index f22da6c..d015ea7 100644 --- a/deploy/wait-for-it.sh +++ b/deploy/wait-for-it.sh @@ -7,21 +7,21 @@ hosts="" # 解析命令行参数 while [ $# -gt 0 ]; do case $1 in - -p) - shift - if [ -z "$1" ]; then - echo "No host:port provided after -p" - exit 1 - fi - hosts="$hosts $1" - ;; - -*|--*) - echo "Unknown option $1" + -p) + shift + if [ -z "$1" ]; then + echo "No host:port provided after -p" exit 1 - ;; - *) - break - ;; + fi + hosts="$hosts $1" + ;; + -* | --*) + echo "Unknown option $1" + exit 1 + ;; + *) + break + ;; esac shift done diff --git a/docs/api.md b/docs/api.md index 9e85240..a4a5649 100644 --- a/docs/api.md +++ b/docs/api.md @@ -262,7 +262,7 @@ func main() { 请注意: 1.对参数进行签名时,一定不要写死!!!,请按签名算法进行计算!! 2.所有提交参数都需要参与签名计算 为空的也需要 3.下面的参数只是示例,具体参数要根据实际接口参数进行验签 -Golang 算法 +Golang 算法 ```go package main @@ -316,7 +316,7 @@ func SortMap(m map[string]string) []string { ``` -Java 算法 +Java 算法 ```Java String appSecret = "3C569A210D1260B2"; diff --git a/internal/controllers/gateway/order_controller.go b/internal/controllers/gateway/order_controller.go index 7022824..867e680 100644 --- a/internal/controllers/gateway/order_controller.go +++ b/internal/controllers/gateway/order_controller.go @@ -6,7 +6,7 @@ import ( "gateway/internal/models/merchant" "gateway/internal/models/order" "gateway/internal/models/response" - "gateway/internal/otel" + "gateway/internal/otelTrace" "gateway/internal/schema/query" "gateway/internal/service" "gateway/internal/utils" @@ -25,7 +25,7 @@ type OrderController struct { func (c *OrderController) OrderQuery() { bankOrderId := c.GetString("bankOrderId") - otel.Logger.WithContext(c.Ctx.Request.Context()).Info(fmt.Sprintf("获取订单信息:%s", bankOrderId), zap.String("bankOrderId", bankOrderId)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info(fmt.Sprintf("获取订单信息:%s", bankOrderId), zap.String("bankOrderId", bankOrderId)) qy := query.SupplierOrderQueryResult(c.Ctx.Request.Context(), bankOrderId) c.Ctx.WriteString(qy) return @@ -40,7 +40,7 @@ func (c *OrderController) OrderUpdate() { flag := false if orderInfo.BankOrderId == "" { - otel.Logger.WithContext(c.Ctx.Request.Context()).Error(fmt.Sprintf("该订单不存在, bankOrderId", bankOrderId), zap.String("bankOrderId", bankOrderId)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error(fmt.Sprintf("该订单不存在, bankOrderId", bankOrderId), zap.String("bankOrderId", bankOrderId)) } else { switch solveType { case config.SUCCESS: @@ -62,7 +62,7 @@ func (c *OrderController) OrderUpdate() { flag = service.SolveOrderRoll(c.Ctx.Request.Context(), bankOrderId) } default: - otel.Logger.WithContext(c.Ctx.Request.Context()).Error("不存在这样的处理类型") + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error("不存在这样的处理类型") } if flag { c.Ctx.WriteString(config.SUCCESS) diff --git a/internal/controllers/gateway/scan_controller.go b/internal/controllers/gateway/scan_controller.go index 9515de5..5516da6 100644 --- a/internal/controllers/gateway/scan_controller.go +++ b/internal/controllers/gateway/scan_controller.go @@ -12,7 +12,7 @@ import ( "gateway/internal/models/merchant_deploy" "gateway/internal/models/order" "gateway/internal/models/road" - "gateway/internal/otel" + "gateway/internal/otelTrace" "gateway/internal/schema/request" "gateway/internal/schema/response" "gateway/internal/service" @@ -38,7 +38,7 @@ import ( var ( delayPool = gopool.NewPool("delayHandler", 20, gopool.NewConfig()) - idCache, _ = bigcache.New(otel.InitCtx, bigcache.DefaultConfig(10*time.Second)) + idCache, _ = bigcache.New(otelTrace.InitCtx, bigcache.DefaultConfig(10*time.Second)) ) type ScanController struct { @@ -62,7 +62,7 @@ func (c *ScanController) Scan() { "ip": strings.TrimSpace(c.GetString("ip")), "deviceId": strings.TrimSpace(c.GetString("deviceId")), }) - ctx, cancel := otel.Span(c.Ctx.Request.Context(), "页面订单", "ScanController", trace.WithAttributes( + ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "页面订单", "ScanController", trace.WithAttributes( attribute.String("exValue", p.Params["exValue"].(string)), attribute.String("orderNo", p.Params["orderNo"].(string)), attribute.String("productCode", p.Params["productCode"].(string)), @@ -73,7 +73,7 @@ func (c *ScanController) Scan() { p.ClientIP = strings.TrimSpace(c.GetString("ip")) cacheId, _ := idCache.Get(strings.TrimSpace(c.GetString("orderNo"))) if len(cacheId) != 0 { - otel.Logger.WithContext(c.Ctx.Request.Context()).Info(fmt.Sprintf("订单已经提交,订单信息:id=%s", p.Params["orderNo"]), zap.Any("orderInfo", p.Params)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info(fmt.Sprintf("订单已经提交,订单信息:id=%s", p.Params["orderNo"]), zap.Any("orderInfo", p.Params)) p.Msg = "订单已经提交!" p.Code = -1 c.SolveFailJSON(p) @@ -90,7 +90,7 @@ func (c *ScanController) Scan() { c.SolveFailJSON(p) return } - otel.Logger.WithContext(c.Ctx.Request.Context()).Info("【BaseGateway】获取商户请求过来的参数", zap.Any("params", p.Params)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info("【BaseGateway】获取商户请求过来的参数", zap.Any("params", p.Params)) // 签名验证 if !utils.Md5MFVerify(c.Ctx.Request.Context(), p.Params, p.MerchantInfo.MerchantSecret) && !utils.Md5TMPMFVerify(c.Ctx.Request.Context(), p.Params, p.MerchantInfo.MerchantSecret) && @@ -156,11 +156,11 @@ func (c *ScanController) Scan() { if hiddenCfg.Strategy == int(consts.StealRuleTypeStealBlank) { newBankOrderId, err2 := service.CreateHiddenBlankOrder(c.Ctx.Request.Context(), &orderInfo, int64(delayDuration)) if err2 != nil { - otel.Logger.WithContext(c.Ctx.Request.Context()).Error("添加订单关联失败【偷卡1】", zap.Error(err2)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error("添加订单关联失败【偷卡1】", zap.Error(err2)) } //添加订单关联 if err2 = service.CreateRelateHideOrderRecord(newBankOrderId, &orderInfo, hiddenCfg, delayDuration); err2 != nil { - otel.Logger.WithContext(c.Ctx.Request.Context()).Error("添加订单关联失败【偷卡2】", zap.Error(err2)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error("添加订单关联失败【偷卡2】", zap.Error(err2)) } //错误订单回调上游 //oldBankOrderId := orderInfo.BankOrderId @@ -174,29 +174,27 @@ func (c *ScanController) Scan() { if hiddenCfg.Strategy == int(consts.StealRuleTypeStealDelay) { newBankOrderId, err2 := service.CreateHiddenErrorOrder(c.Ctx.Request.Context(), &orderInfo, int64(delayDuration)) if err2 != nil { - otel.Logger.WithContext(c.Ctx.Request.Context()).Error("添加订单关联失败【偷卡1】", zap.Error(err2)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error("添加订单关联失败【偷卡1】", zap.Error(err2)) } //添加订单关联 if err2 = service.CreateRelateHideOrderRecord(newBankOrderId, &orderInfo, hiddenCfg, delayDuration); err2 != nil { - otel.Logger.WithContext(c.Ctx.Request.Context()).Error("添加订单关联失败【偷卡2】", zap.Error(err2)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error("添加订单关联失败【偷卡2】", zap.Error(err2)) } oldBankOrderId := orderInfo.BankOrderId //错误订单回调上游 - delayPool.CtxGo(c.Ctx.Request.Context(), func() { - time.Sleep(time.Duration(delayDuration) * time.Second) - // 创建一个5分钟超时的上下文 - timeoutCtx, cancel := context.WithTimeout(c.Ctx.Request.Context(), 5*time.Minute) - defer cancel() - service.SolvePayFail(timeoutCtx, oldBankOrderId, orderInfo.BankTransId, hiddenCfg.ExtraReturnInfo) + delayPool.CtxGo(context.Background(), func() { + ctx2, span := otelTrace.NewSchedulerTrace().Start(otelTrace.InitCtx, "Span") + defer span.End() + service.SolvePayFail(ctx2, oldBankOrderId, orderInfo.BankTransId, hiddenCfg.ExtraReturnInfo) }) orderInfo.BankOrderId = newBankOrderId } } - otel.Logger.WithContext(c.Ctx.Request.Context()).Info("【BaseGateway】生成订单记录", zap.Any("orderInfo", orderInfo)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info("【BaseGateway】生成订单记录", zap.Any("orderInfo", orderInfo)) cdata := supplier.RedeemCardInfo{} err = json.Unmarshal([]byte(orderInfo.ExValue), &cdata) if err != nil { - otel.Logger.WithContext(c.Ctx.Request.Context()).Error("格式化数据失败", zap.Error(err), zap.String("ExValue", orderInfo.ExValue)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error("格式化数据失败", zap.Error(err), zap.String("ExValue", orderInfo.ExValue)) p.Msg = fmt.Sprintf("格式化数据失败:%v", orderInfo.ExValue) c.SolveFailJSON(p) } @@ -204,16 +202,16 @@ func (c *ScanController) Scan() { isAllowed, err := backend.GetIPIsRestricted(c.Ctx.Request.Context(), p.ClientIP, mt.Id, orderInfo.BankOrderId, cdata.Data, convertor.ToString(p.Params["deviceId"])) order.UpdateIpRestricted(c.Ctx.Request.Context(), orderInfo.BankOrderId, isAllowed) - otel.Logger.WithContext(c.Ctx.Request.Context()).Info("IP是否允许", zap.Bool("isAllowed", isAllowed)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info("IP是否允许", zap.Bool("isAllowed", isAllowed)) // otel.Logger.WithContext(c.Ctx.Request.Context()).Info("IP是否允许:%v", isAllowed) if !isAllowed { - otel.Logger.WithContext(c.Ctx.Request.Context()).Info(fmt.Sprintf("IP被限制,无法兑换 %s", p.ClientIP), zap.String("ClientIP", p.ClientIP)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info(fmt.Sprintf("IP被限制,无法兑换 %s", p.ClientIP), zap.String("ClientIP", p.ClientIP)) c.Data["json"] = response.CommonErr(-1, errors.New("提交失败").Error()) service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "IP限制,无法兑换") _ = c.ServeJSON() return } - otel.Logger.WithContext(c.Ctx.Request.Context()).Info("【BaseGateway】生成订单记录", zap.Any("orderInfo", orderInfo)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info("【BaseGateway】生成订单记录", zap.Any("orderInfo", orderInfo)) if mt.AutoSettle == config.NO { params := map[string]any{ "orderNo": orderInfo.BankOrderId, @@ -239,13 +237,13 @@ func (c *ScanController) Scan() { if supplierByCode == nil { // 插入处理失败的动账通知 service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "") - otel.Logger.WithContext(c.Ctx.Request.Context()).Error("获取上游渠道失败,请联系客服", zap.String("supplierCode", supplierCode)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error("获取上游渠道失败,请联系客服", zap.String("supplierCode", supplierCode)) c.Data["json"] = response.CommonErr(-1, errors.New("获取上游渠道失败,请联系客服").Error()) _ = c.ServeJSON() c.StopRun() return } - otel.Logger.WithContext(c.Ctx.Request.Context()).Info("【BaseGateway】获取到对应的上游", zap.Any("supplierByCode", supplierByCode)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info("【BaseGateway】获取到对应的上游", zap.Any("supplierByCode", supplierByCode)) scanData := supplierByCode.Scan(c.Ctx.Request.Context(), orderInfo, p.RoadInfo, p.MerchantInfo) order.InsertCardReturnData(scanData.BankNo, scanData.ReturnData) if scanData.Status == "00" { @@ -320,7 +318,7 @@ func (c *ScanController) GetAllowedMM() { IsLinkSingle bool `json:"isLinkSingle" description:"链接是否单独放置"` LinkID string `json:"linkID" description:"链接"` } - otel.Logger.WithContext(c.Ctx.Request.Context()).Info("当前请求面额数据", zap.Any("profitMarginList", profitMarginList)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info("当前请求面额数据", zap.Any("profitMarginList", profitMarginList)) resData := make([]*profitMarginStruct, 0) for _, v := range profitMarginList { if v.ShowLabel != 0 || v.FactLabel != 0 { @@ -334,7 +332,7 @@ func (c *ScanController) GetAllowedMM() { }) } } - otel.Logger.WithContext(c.Ctx.Request.Context()).Info("当前请求面额数据", zap.Any("profitMarginList", profitMarginList)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info("当前请求面额数据", zap.Any("profitMarginList", profitMarginList)) c.Data["json"] = response.Ok(resData) _ = c.ServeJSON() } @@ -343,17 +341,17 @@ func (c *ScanController) GetAllowedMM() { func (c *ScanController) CreateOrder() { createdOrder := request.CreatedOrder{} _ = c.Bind(&createdOrder) - otel.Logger.WithContext(c.Ctx.Request.Context()).Info("创建订单:", zap.Any("createdOrder", createdOrder)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info("创建订单:", zap.Any("createdOrder", createdOrder)) valid := validation.Validation{} b, err := valid.Valid(&createdOrder) if err != nil || !b { - otel.Logger.WithContext(c.Ctx.Request.Context()).Info("创建订单错误:", zap.Error(err)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info("创建订单错误:", zap.Error(err)) res := response.CommonErr(-1, "创建订单失败,参数错误") c.Data["json"] = res _ = c.ServeJSON() return } - ctx, cancel := otel.Span(c.Ctx.Request.Context(), "API订单", "ScanController", trace.WithAttributes( + ctx, cancel := otelTrace.Span(c.Ctx.Request.Context(), "API订单", "ScanController", trace.WithAttributes( attribute.String("PayKey", createdOrder.PayKey), attribute.String("ProductCode", createdOrder.ProductCode), attribute.String("productCode", createdOrder.Sign), @@ -363,14 +361,14 @@ func (c *ScanController) CreateOrder() { merchantInfo := merchant.GetMerchantByPasskey(c.Ctx.Request.Context(), createdOrder.PayKey) if merchantInfo.Id == 0 { - otel.Logger.WithContext(c.Ctx.Request.Context()).Info("创建订单错误:", zap.Error(err)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info("创建订单错误:", zap.Error(err)) c.Data["json"] = response.CommonErr(-1, "创建订单错误,商户不存在") _ = c.ServeJSON() return } if !utils.Md5MFVerify(c.Ctx.Request.Context(), createdOrder.ToMap(), merchantInfo.MerchantSecret) && !utils.Md5Verify(createdOrder.ToMap(), merchantInfo.MerchantSecret) { - otel.Logger.WithContext(c.Ctx.Request.Context()).Info("创建订单错误,sign校验失败") + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info("创建订单错误,sign校验失败") c.Data["json"] = response.CommonErr(-1, "sign验证错误") _ = c.ServeJSON() return @@ -404,7 +402,7 @@ func (c *ScanController) CreateOrder() { supplierByCode := third_party.GetPaySupplierByCode(supplierCode) if supplierByCode == nil { // 插入处理失败的动账通知 - otel.Logger.WithContext(c.Ctx.Request.Context()).Error("获取上游渠道失败,请联系客服", zap.String("supplierCode", supplierCode)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error("获取上游渠道失败,请联系客服", zap.String("supplierCode", supplierCode)) err = errors.New("获取上游渠道失败,请联系客服") c.Data["json"] = response.CommonErr(-1, err.Error()) _ = c.ServeJSON() @@ -415,12 +413,12 @@ func (c *ScanController) CreateOrder() { orderInfo, err = service.CreateOrderInfoAndOrderProfitInfo(c.Ctx.Request.Context(), createdOrder, merchantInfo) if err != nil { res := response.CommonErr(-1, "创建订单失败,创建订单记录失败") - otel.Logger.WithContext(c.Ctx.Request.Context()).Error("创建订单错误:", zap.Error(err)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error("创建订单错误:", zap.Error(err)) c.Data["json"] = res _ = c.ServeJSON() return } - otel.Logger.WithContext(c.Ctx.Request.Context()).Info("获取供应商信息", zap.Any("supplierCode", supplierCode)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info("获取供应商信息", zap.Any("supplierCode", supplierCode)) payUrl := "" bankTransId := "" //TODO: 区分自有渠道和三方渠道 @@ -442,7 +440,7 @@ func (c *ScanController) CreateOrder() { } if err = order.UpdatePayUrlAndTime(orderInfo.BankOrderId, payUrl, bankTransId, ""); err != nil { - otel.Logger.WithContext(c.Ctx.Request.Context()).Error("更新订单支付链接失败:", zap.Error(err)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error("更新订单支付链接失败:", zap.Error(err)) c.Data["json"] = response.CommonErr(-1, "更新订单支付链接失败") return } @@ -466,7 +464,7 @@ func (c *ScanController) CreateOrder() { } respMap, err := structs.New(resp).ToMap() if err != nil { - otel.Logger.WithContext(c.Ctx.Request.Context()).Error("创建订单错误:", zap.Error(err)) + otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error("创建订单错误:", zap.Error(err)) c.Data["json"] = response.CommonErr(-1, err.Error()) _ = c.ServeJSON() return diff --git a/internal/dto/order_test.go b/internal/dto/order_test.go index 514ad67..48b4be1 100644 --- a/internal/dto/order_test.go +++ b/internal/dto/order_test.go @@ -3,7 +3,7 @@ package dto import ( "crypto/md5" "encoding/hex" - "gateway/internal/otel" + "sort" "strconv" "testing" @@ -44,7 +44,7 @@ func main() { params["amount"] = "100" result, _ := formatter.Pretty(params) - otel.Logger.WithContext(otel.InitCtx).Info(result) + otelTrace.Logger.WithContext(otelTrace.InitCtx).Info(result) strArr := SortMap(params) signStr := "" @@ -58,10 +58,10 @@ func main() { } signStr += appSecret h := md5.New() - otel.Logger.WithContext(otel.InitCtx).Info(signStr) + otelTrace.Logger.WithContext(otelTrace.InitCtx).Info(signStr) h.Write([]byte(signStr)) result = hex.EncodeToString(h.Sum(nil)) - otel.Logger.WithContext(otel.InitCtx).Info(result) + otelTrace.Logger.WithContext(otelTrace.InitCtx).Info(result) } // SortMap 对map的key值进行排序 diff --git a/internal/models/accounts/account.go b/internal/models/accounts/account.go index 3b52718..8f6842e 100644 --- a/internal/models/accounts/account.go +++ b/internal/models/accounts/account.go @@ -2,7 +2,8 @@ package accounts import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -31,7 +32,7 @@ func InsetAcount(ctx context.Context, account AccountInfo) bool { o := orm.NewOrm() _, err := o.Insert(&account) if err != nil { - otel.Logger.WithContext(ctx).Error("insert account fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert account fail: ", zap.Error(err)) return false } return true @@ -42,7 +43,7 @@ func GetAccountByUid(ctx context.Context, accountUid string) AccountInfo { var account AccountInfo _, err := o.QueryTable(ACCOUNT_INFO).Filter("account_uid", accountUid).Limit(1).All(&account) if err != nil { - otel.Logger.WithContext(ctx).Error("get account by uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get account by uid fail: ", zap.Error(err)) } return account @@ -58,7 +59,7 @@ func GetAccountLenByMap(ctx context.Context, params map[string]string) int { } cnt, err := qs.Limit(-1).OrderBy("-update_time").Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get account len by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get account len by map fail: ", zap.Error(err)) } return int(cnt) } @@ -75,7 +76,7 @@ func GetAccountByMap(ctx context.Context, params map[string]string, displayCount _, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&accountList) if err != nil { - otel.Logger.WithContext(ctx).Error("get account by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get account by map fail: ", zap.Error(err)) } return accountList } @@ -86,7 +87,7 @@ func GetAllAccount(ctx context.Context) []AccountInfo { _, err := o.QueryTable(ACCOUNT_INFO).Limit(-1).All(&accountList) if err != nil { - otel.Logger.WithContext(ctx).Error("get all account fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get all account fail: ", zap.Error(err)) } return accountList @@ -96,7 +97,7 @@ func UpdateAccount(ctx context.Context, account AccountInfo) bool { o := orm.NewOrm() _, err := o.Update(&account) if err != nil { - otel.Logger.WithContext(ctx).Error("update account fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update account fail: ", zap.Error(err)) return false } return true @@ -106,7 +107,7 @@ func DeleteAccountByUid(ctx context.Context, accountUid string) bool { o := orm.NewOrm() _, err := o.QueryTable(ACCOUNT_INFO).Filter("account_uid", accountUid).Delete() if err != nil { - otel.Logger.WithContext(ctx).Error("delete account fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("delete account fail: ", zap.Error(err)) return false } return true diff --git a/internal/models/accounts/account_history_info.go b/internal/models/accounts/account_history_info.go index 76d91e5..ee8a12d 100644 --- a/internal/models/accounts/account_history_info.go +++ b/internal/models/accounts/account_history_info.go @@ -2,7 +2,8 @@ package accounts import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -27,7 +28,7 @@ func InsertAccountHistory(ctx context.Context, accountHistory AccountHistoryInfo o := orm.NewOrm() _, err := o.Insert(accountHistory) if err != nil { - otel.Logger.WithContext(ctx).Error("insert account history fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert account history fail: ", zap.Error(err)) return false } return true @@ -43,7 +44,7 @@ func GetAccountHistoryLenByMap(ctx context.Context, params map[string]string) in } cnt, err := qs.Limit(-1).Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get account history len by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get account history len by map fail: ", zap.Error(err)) } return int(cnt) } @@ -59,7 +60,7 @@ func GetAccountHistoryByMap(ctx context.Context, params map[string]string, displ } _, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&accountHistoryList) if err != nil { - otel.Logger.WithContext(ctx).Error("get account history by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get account history by map fail: ", zap.Error(err)) } return accountHistoryList } diff --git a/internal/models/agent/agent_info.go b/internal/models/agent/agent_info.go index 24f3c59..92d4ccf 100644 --- a/internal/models/agent/agent_info.go +++ b/internal/models/agent/agent_info.go @@ -2,7 +2,8 @@ package agent import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -48,7 +49,7 @@ func InsertAgentInfo(ctx context.Context, agentInfo AgentInfo) bool { o := orm.NewOrm() _, err := o.Insert(&agentInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("insert agent info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert agent info fail: ", zap.Error(err)) return false } @@ -60,7 +61,7 @@ func GetAgentInfoByAgentUid(ctx context.Context, agentUid string) AgentInfo { var agentInfo AgentInfo _, err := o.QueryTable(AGENT_INFO).Filter("agent_uid", agentUid).Limit(1).All(&agentInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get agent info by agentUid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get agent info by agentUid fail: ", zap.Error(err)) } return agentInfo @@ -71,7 +72,7 @@ func GetAgentInfoByPhone(ctx context.Context, phone string) AgentInfo { var agentInfo AgentInfo _, err := o.QueryTable(AGENT_INFO).Filter("agent_phone", phone).Limit(1).All(&agentInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get agent info by phone fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get agent info by phone fail: ", zap.Error(err)) } return agentInfo @@ -87,7 +88,7 @@ func GetAgentInfoLenByMap(ctx context.Context, params map[string]string) int { } cnt, err := qs.Limit(-1).Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get agentinfo len by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get agentinfo len by map fail: ", zap.Error(err)) } return int(cnt) @@ -106,7 +107,7 @@ func GetAgentInfoByMap(ctx context.Context, params map[string]string, displayCou _, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&agentInfoList) if err != nil { - otel.Logger.WithContext(ctx).Error("get agentInfo by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get agentInfo by map fail: ", zap.Error(err)) } return agentInfoList @@ -125,7 +126,7 @@ func GetAllAgentByMap(ctx context.Context, parmas map[string]string) []AgentInfo _, err := qs.Limit(-1).All(&agentList) if err != nil { - otel.Logger.WithContext(ctx).Error("get all agent by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get all agent by map fail: ", zap.Error(err)) } return agentList @@ -135,7 +136,7 @@ func UpdateAgentInfo(ctx context.Context, agentInfo AgentInfo) bool { o := orm.NewOrm() _, err := o.Update(&agentInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("update agentinfo fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update agentinfo fail: ", zap.Error(err)) return false } @@ -146,7 +147,7 @@ func DeleteAgentByAgentUid(ctx context.Context, agentUid string) bool { o := orm.NewOrm() _, err := o.QueryTable(AGENT_INFO).Filter("agent_uid", agentUid).Delete() if err != nil { - otel.Logger.WithContext(ctx).Error("delete agent by agent uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("delete agent by agent uid fail: ", zap.Error(err)) return false } return true diff --git a/internal/models/merchant/merchant_info.go b/internal/models/merchant/merchant_info.go index 2f5a58a..d74e715 100644 --- a/internal/models/merchant/merchant_info.go +++ b/internal/models/merchant/merchant_info.go @@ -1,18 +1,9 @@ package merchant -/*************************************************** - ** @Desc : This file for ... - ** @Time : 2019/9/28 16:47 - ** @Author : yuebin - ** @File : merchant_info - ** @Last Modified by : yuebin - ** @Last Modified time: 2019/9/28 16:47 - ** @Software: GoLand -****************************************************/ - import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -75,7 +66,7 @@ func GetMerchantByPhone(ctx context.Context, phone string) (m MerchantInfo) { o := orm.NewOrm() _, err := o.QueryTable(MERCHANT_INFO).Filter("LoginAccount", phone).Limit(1).All(&m) if err != nil { - otel.Logger.WithContext(ctx).Error("GetMerchantByPhone merchant fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("GetMerchantByPhone merchant fail: ", zap.Error(err)) } return m } @@ -84,7 +75,7 @@ func InsertMerchantInfo(ctx context.Context, merchantInfo MerchantInfo) bool { o := orm.NewOrm() _, err := o.Insert(&merchantInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("insert merchant fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert merchant fail: ", zap.Error(err)) return false } return true @@ -100,7 +91,7 @@ func GetMerchantLenByMap(ctx context.Context, params map[string]string) int { } cnt, err := qs.Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get merchant len by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get merchant len by map fail: ", zap.Error(err)) } return int(cnt) } @@ -116,7 +107,7 @@ func GetMerchantListByMap(ctx context.Context, params map[string]string, display var merchantList []MerchantInfo _, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&merchantList) if err != nil { - otel.Logger.WithContext(ctx).Error("get merchant list by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get merchant list by map fail: ", zap.Error(err)) } return merchantList } @@ -127,7 +118,7 @@ func GetAllMerchant(ctx context.Context) []MerchantInfo { _, err := o.QueryTable(MERCHANT_INFO).Limit(-1).All(&merchantList) if err != nil { - otel.Logger.WithContext(ctx).Error("get all merchant fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get all merchant fail:", zap.Error(err)) } return merchantList @@ -159,7 +150,7 @@ func GetMerchantLenByParams(ctx context.Context, params map[string]string) int { cnt, err := qs.Limit(-1).Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get merchant len by params fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get merchant len by params fail: ", zap.Error(err)) } return int(cnt) } @@ -169,7 +160,7 @@ func GetMerchantByUid(ctx context.Context, merchantUid string) MerchantInfo { var merchantInfo MerchantInfo _, err := o.QueryTable(MERCHANT_INFO).Filter("merchant_uid", merchantUid).Limit(1).All(&merchantInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get merchant info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get merchant info fail: ", zap.Error(err)) } return merchantInfo } @@ -179,7 +170,7 @@ func GetMerchantByPasskey(ctx context.Context, payKey string) MerchantInfo { var merchantInfo MerchantInfo _, err := o.QueryTable(MERCHANT_INFO).Filter("merchant_key", payKey).Limit(1).All(&merchantInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get merchant by merchantKey fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get merchant by merchantKey fail: ", zap.Error(err)) } return merchantInfo } @@ -188,7 +179,7 @@ func UpdateMerchant(ctx context.Context, merchantInfo MerchantInfo) bool { o := orm.NewOrm() _, err := o.Update(&merchantInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("update merchant fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update merchant fail: ", zap.Error(err)) return false } @@ -199,7 +190,7 @@ func DeleteMerchantByUid(ctx context.Context, merchantUid string) bool { o := orm.NewOrm() _, err := o.QueryTable(MERCHANT_INFO).Filter("merchant_uid", merchantUid).Delete() if err != nil { - otel.Logger.WithContext(ctx).Error("delete merchant fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("delete merchant fail: ", zap.Error(err)) return false } return true diff --git a/internal/models/merchant/merchant_load_info.go b/internal/models/merchant/merchant_load_info.go index c4f5f3b..414ffb9 100644 --- a/internal/models/merchant/merchant_load_info.go +++ b/internal/models/merchant/merchant_load_info.go @@ -2,7 +2,7 @@ package merchant import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" "time" "github.com/beego/beego/v2/client/orm" @@ -33,7 +33,7 @@ func GetMerchantLoadInfoByMap(ctx context.Context, params map[string]string) []M var merchantLoadList []MerchantLoadInfo _, err := qs.Limit(-11).All(&merchantLoadList) if err != nil { - otel.Logger.WithContext(ctx).Error("get merchant load info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get merchant load info fail: ", zap.Error(err)) } return merchantLoadList } diff --git a/internal/models/merchant_deploy/merchant_deploy_info.go b/internal/models/merchant_deploy/merchant_deploy_info.go index c9c2813..94cac69 100644 --- a/internal/models/merchant_deploy/merchant_deploy_info.go +++ b/internal/models/merchant_deploy/merchant_deploy_info.go @@ -5,11 +5,11 @@ import ( "encoding/json" "errors" "fmt" - "gateway/internal/otel" - "time" + "gateway/internal/otelTrace" "github.com/beego/beego/v2/client/orm" "go.uber.org/zap" + "time" ) type MerchantDeployInfo struct { @@ -71,7 +71,7 @@ func (m *MerchantDeployInfo) GetFactMMValue(ctx context.Context, showMMValue flo // 使用json.Unmarshal函数解码JSON字符串到map中 err := json.Unmarshal([]byte(m.SingleRoadPlatformRate), &ms) if err != nil { - otel.Logger.WithContext(ctx).Error("格式化面值错误", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("格式化面值错误", zap.Error(err)) return pm, errors.New("获取面额失败") } for _, margin := range ms { @@ -88,7 +88,7 @@ func (m *MerchantDeployInfo) GetShowMMValue(ctx context.Context, factMMValue flo // 使用json.Unmarshal函数解码JSON字符串到map中 err := json.Unmarshal([]byte(m.SingleRoadPlatformRate), &ms) if err != nil { - otel.Logger.WithContext(ctx).Error("格式化面值错误", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("格式化面值错误", zap.Error(err)) return pm, errors.New("获取面额失败") } for _, margin := range ms { @@ -137,7 +137,7 @@ func GetMerchantDeployByUidAndRoadUid(ctx context.Context, uid, roadUid string) Filter("single_road_uid", roadUid). One(&innerMerchantDeployInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get merchant deploy by uid and paytype fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get merchant deploy by uid and paytype fail:", zap.Error(err)) } return &innerMerchantDeployInfo } @@ -147,7 +147,7 @@ func GetMerchantDeployByHour(ctx context.Context, hour int) []MerchantDeployInfo var merchantDeployList []MerchantDeployInfo _, err := o.QueryTable(MERCHANT_DEPLOY_INFO).Filter("unfreeze_hour", hour).Filter("status", "active").Limit(-1).All(&merchantDeployList) if err != nil { - otel.Logger.WithContext(ctx).Error("get merchant deploy list fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get merchant deploy list fail: ", zap.Error(err)) } return merchantDeployList @@ -158,7 +158,7 @@ func GetById(ctx context.Context, id int) *MerchantDeployInfo { var merchantDeploy *MerchantDeployInfo err := o.QueryTable(MERCHANT_DEPLOY_INFO).Filter("id", id).One(&merchantDeploy) if err != nil { - otel.Logger.WithContext(ctx).Error("get merchant deploy by id fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get merchant deploy by id fail: ", zap.Error(err)) } return merchantDeploy } diff --git a/internal/models/notify/notify_info.go b/internal/models/notify/notify_info.go index 3b8e12a..c2abf50 100644 --- a/internal/models/notify/notify_info.go +++ b/internal/models/notify/notify_info.go @@ -3,7 +3,8 @@ package notify import ( "context" "gateway/internal/consts" - "gateway/internal/otel" + + "gateway/internal/otelTrace" "time" "github.com/beego/beego/v2/client/orm" @@ -29,7 +30,7 @@ func InsertNotifyInfo(ctx context.Context, notifyInfo NotifyInfo) bool { o := orm.NewOrm() _, err := o.Insert(¬ifyInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("insert notify fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert notify fail:", zap.Error(err)) return false } return true @@ -46,7 +47,7 @@ func GetNotifyInfoByBankOrderId(ctx context.Context, bankOrderId string) NotifyI var notifyInfo NotifyInfo _, err := o.QueryTable(NOTIFYINFO).Filter("bank_order_id", bankOrderId).OrderBy("-create_time").All(¬ifyInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get notify info by bankOrderId fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get notify info by bankOrderId fail: ", zap.Error(err)) } return notifyInfo } @@ -61,7 +62,7 @@ func GetNotifyInfosNotSuccess(ctx context.Context, params map[string]interface{} qs = qs.Exclude("status", "success").Exclude("times", consts.LimitTimes) _, err := qs.Limit(-1).All(¬ifyInfoList) if err != nil { - otel.Logger.WithContext(ctx).Error("get notifyinfos fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get notifyinfos fail: ", zap.Error(err)) } return notifyInfoList } @@ -70,7 +71,7 @@ func UpdateNotifyInfo(ctx context.Context, notifyInfo NotifyInfo) bool { o := orm.NewOrm() _, err := o.Update(¬ifyInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("update notify info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update notify info fail: ", zap.Error(err)) return false } return true diff --git a/internal/models/order/order_info.go b/internal/models/order/order_info.go index 1dd5914..988923b 100644 --- a/internal/models/order/order_info.go +++ b/internal/models/order/order_info.go @@ -3,7 +3,8 @@ package order import ( "context" "fmt" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/utils" "strconv" "time" @@ -63,7 +64,7 @@ const ORDER_INFO = "order_info" func InsertOrder(ctx context.Context, orderInfo OrderInfo) bool { _, err := orm.NewOrm().Insert(&orderInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("insert order info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert order info fail: ", zap.Error(err)) return false } return true @@ -91,7 +92,7 @@ func HiddenOrder(ctx context.Context, info *OrderInfo) (bankOrderId string, err orderProfileInfo := OrderProfitInfo{} err = orm.NewOrm().QueryTable(ORDER_PROFIT_INFO).Filter("bank_order_id", info.BankOrderId).One(&orderProfileInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("update order profit fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update order profit fail: ", zap.Error(err)) return } //取字符串前2位 @@ -117,7 +118,7 @@ func UpdateIpRestricted(ctx context.Context, orderId string, isIpRestricted bool "update_time": time.Now(), }) if err != nil { - otel.Logger.WithContext(ctx).Error("update ip restricted fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update ip restricted fail: ", zap.Error(err)) return false } return true @@ -158,7 +159,7 @@ func GetOrderByMap(ctx context.Context, params map[string]string, display, offse } _, err := qs.Limit(display, offset).OrderBy("-update_time").All(&orderInfoList) if err != nil { - otel.Logger.WithContext(ctx).Error("get order by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get order by map fail: ", zap.Error(err)) } return orderInfoList } @@ -239,7 +240,7 @@ func GetAllAmountByMap(ctx context.Context, params map[string]string) float64 { } condition = condition + "pay_type_code = " + params["pay_type_code"] } - otel.Logger.WithContext(ctx).Info("get order amount str = ", zap.String("condition", condition)) + otelTrace.Logger.WithContext(ctx).Info("get order amount str = ", zap.String("condition", condition)) var maps []orm.Params allAmount := 0.00 num, err := o.Raw(condition).Values(&maps) @@ -254,7 +255,7 @@ func GetOrderByBankOrderId(ctx context.Context, bankOrderId string) OrderInfo { var orderInfo OrderInfo _, err := o.QueryTable(ORDER_INFO).Filter("bank_order_id", bankOrderId).Limit(1).All(&orderInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get order info by bankOrderId fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get order info by bankOrderId fail: ", zap.Error(err)) } return orderInfo } @@ -264,7 +265,7 @@ func GetOrderByBankTransId(ctx context.Context, BankTransId string) OrderInfo { var orderInfo OrderInfo _, err := o.QueryTable(ORDER_INFO).Filter("bank_trans_id", BankTransId).Limit(1).All(&orderInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get order info by bankOrderId fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get order info by bankOrderId fail: ", zap.Error(err)) } return orderInfo } @@ -273,7 +274,7 @@ func GetOrderByMerchantOrderId(ctx context.Context, merchantOrderId string) Orde var orderInfo OrderInfo err := orm.NewOrm().QueryTable(ORDER_INFO).Filter("merchant_order_id", merchantOrderId).One(&orderInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get order by merchant_order_id: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get order by merchant_order_id: ", zap.Error(err)) } return orderInfo } @@ -282,7 +283,7 @@ func GetOneOrder(ctx context.Context, bankOrderId string) OrderInfo { var orderInfo OrderInfo _, err := orm.NewOrm().QueryTable(ORDER_INFO).Filter("bank_order_id", bankOrderId).Limit(1).All(&orderInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get one order fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get one order fail: ", zap.Error(err)) } return orderInfo } diff --git a/internal/models/order/order_profit_info.go b/internal/models/order/order_profit_info.go index c6c47fc..b199387 100644 --- a/internal/models/order/order_profit_info.go +++ b/internal/models/order/order_profit_info.go @@ -2,7 +2,8 @@ package order import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -45,7 +46,7 @@ func GetOrderProfitByBankOrderId(ctx context.Context, bankOrderId string) OrderP var orderProfit OrderProfitInfo _, err := o.QueryTable(ORDER_PROFIT_INFO).Filter("bank_order_id", bankOrderId).Limit(1).AllWithCtx(ctx, &orderProfit) if err != nil { - otel.Logger.WithContext(ctx).Error("GetOrderProfitByBankOrderId fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("GetOrderProfitByBankOrderId fail:", zap.Error(err)) } return orderProfit } @@ -55,7 +56,7 @@ func GetOrderProfitByMerchantOrderId(ctx context.Context, merchantOrderId string var orderProfit OrderProfitInfo _, err := o.QueryTable(ORDER_PROFIT_INFO).Filter("merchant_order_id", merchantOrderId).Limit(1).AllWithCtx(ctx, &orderProfit) if err != nil { - otel.Logger.WithContext(ctx).Error("GetOrderProfitByBankOrderId fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("GetOrderProfitByBankOrderId fail:", zap.Error(err)) } return orderProfit } @@ -83,7 +84,7 @@ func GetOrderProfitByMap(ctx context.Context, params map[string]string, display, } _, err := qs.Limit(display, offset).OrderBy("-update_time").AllWithCtx(ctx, &orderProfitInfoList) if err != nil { - otel.Logger.WithContext(ctx).Error("get order by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get order by map fail: ", zap.Error(err)) } return orderProfitInfoList } @@ -96,11 +97,11 @@ func InsertOrderAndOrderProfit(ctx context.Context, orderInfo OrderInfo, orderPr err := orm.NewOrm().DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error { if _, err := txOrm.Insert(&orderInfo); err != nil { - otel.Logger.WithContext(ctx).Error("insert orderInfo fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert orderInfo fail: ", zap.Error(err)) return err } if _, err := txOrm.Insert(&orderProfitInfo); err != nil { - otel.Logger.WithContext(ctx).Error("insert orderProfit fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert orderProfit fail: ", zap.Error(err)) return err } return nil @@ -115,7 +116,7 @@ func InsertOrderAndOrderProfit(ctx context.Context, orderInfo OrderInfo, orderPr func InsertOrderProfit(ctx context.Context, orderProfitInfo *OrderProfitInfo) (err error) { err = orm.NewOrm().DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error { if _, err := txOrm.Insert(orderProfitInfo); err != nil { - otel.Logger.WithContext(ctx).Error("insert orderProfit fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert orderProfit fail: ", zap.Error(err)) return err } return nil @@ -129,13 +130,13 @@ func SwitchOrderAndOrderProfitStatus(ctx context.Context, merchantOrderId, statu if _, err := txOrm.QueryTable(ORDER_INFO).Filter("merchant_order_id", merchantOrderId).Update(orm.Params{ "status": status, }); err != nil { - otel.Logger.WithContext(ctx).Error("insert orderInfo fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert orderInfo fail: ", zap.Error(err)) return err } if _, err := txOrm.QueryTable(ORDER_PROFIT_INFO).Filter("merchant_order_id", merchantOrderId).Update(orm.Params{ "status": status, }); err != nil { - otel.Logger.WithContext(ctx).Error("insert orderInfo fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert orderInfo fail: ", zap.Error(err)) return err } return nil diff --git a/internal/models/order/order_settle_info.go b/internal/models/order/order_settle_info.go index b14c8b9..47eb330 100644 --- a/internal/models/order/order_settle_info.go +++ b/internal/models/order/order_settle_info.go @@ -2,7 +2,8 @@ package order import ( "context" - "gateway/internal/otel" + + "gateway/internal/otelTrace" "time" "github.com/beego/beego/v2/client/orm" @@ -39,7 +40,7 @@ func GetOrderSettleListByParams(ctx context.Context, params map[string]string) [ } var orderSettleList []OrderSettleInfo if _, err := qs.Limit(-1).All(&orderSettleList); err != nil { - otel.Logger.WithContext(ctx).Error("get order settle list fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get order settle list fail: ", zap.Error(err)) } return orderSettleList } diff --git a/internal/models/payfor/payfor_info.go b/internal/models/payfor/payfor_info.go index 82c4430..caca5d1 100644 --- a/internal/models/payfor/payfor_info.go +++ b/internal/models/payfor/payfor_info.go @@ -2,7 +2,8 @@ package payfor import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -53,7 +54,7 @@ func InsertPayFor(ctx context.Context, payFor PayforInfo) bool { o := orm.NewOrm() _, err := o.Insert(&payFor) if err != nil { - otel.Logger.WithContext(ctx).Error("insert payfor fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert payfor fail: ", zap.Error(err)) return false } return true @@ -78,7 +79,7 @@ func GetPayForByBankOrderId(ctx context.Context, bankOrderId string) PayforInfo var payFor PayforInfo _, err := o.QueryTable(PAYFORINFO).Filter("bank_order_id", bankOrderId).Limit(1).All(&payFor) if err != nil { - otel.Logger.WithContext(ctx).Error("get pay for by bank_order_id fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get pay for by bank_order_id fail: ", zap.Error(err)) } return payFor @@ -90,7 +91,7 @@ func GetPayForByMerchantOrderId(ctx context.Context, merchantOrderId string) Pay _, err := o.QueryTable(PAYFORINFO).Filter("merchant_order_id", merchantOrderId).Limit(1).All(&payFor) if err != nil { - otel.Logger.WithContext(ctx).Error("fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("fail: ", zap.Error(err)) } return payFor @@ -100,7 +101,7 @@ func UpdatePayFor(ctx context.Context, payFor PayforInfo) bool { o := orm.NewOrm() _, err := o.Update(&payFor) if err != nil { - otel.Logger.WithContext(ctx).Error("update pay for fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update pay for fail:", zap.Error(err)) return false } diff --git a/internal/models/road/road_info.go b/internal/models/road/road_info.go index d82935b..490d1e9 100644 --- a/internal/models/road/road_info.go +++ b/internal/models/road/road_info.go @@ -2,7 +2,8 @@ package road import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -54,7 +55,7 @@ func GetRoadInfoByRoadUid(ctx context.Context, roadUid string) RoadInfo { var roadInfo RoadInfo _, err := o.QueryTable(ROAD_INFO).Exclude("status", "delete").Filter("road_uid", roadUid).Limit(1).All(&roadInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get road info by road uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get road info by road uid fail: ", zap.Error(err)) } return roadInfo } @@ -66,7 +67,7 @@ func GetRoadInfoByProductCode(ctx context.Context, productCode string) RoadInfo Filter("product_code", productCode). One(&roadInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get road info by road uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get road info by road uid fail: ", zap.Error(err)) } return roadInfo } @@ -76,7 +77,7 @@ func GetRoadInfosByRoadUids(ctx context.Context, roadUids []string) []RoadInfo { var roadInfoList []RoadInfo _, err := o.QueryTable(ROAD_INFO).Filter("road_uid__in", roadUids).OrderBy("update_time").All(&roadInfoList) if err != nil { - otel.Logger.WithContext(ctx).Error("get roadInfos by roadUids fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get roadInfos by roadUids fail: ", zap.Error(err)) } return roadInfoList } @@ -86,7 +87,7 @@ func GetRoadInfoByName(ctx context.Context, roadName string) RoadInfo { var roadInfo RoadInfo _, err := o.QueryTable(ROAD_INFO).Exclude("status", "delete").Filter("road_name", roadName).Limit(1).All(&roadInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get road info by name fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get road info by name fail: ", zap.Error(err)) } return roadInfo } @@ -101,7 +102,7 @@ func GetRoadLenByMap(ctx context.Context, params map[string]string) int { } cnt, err := qs.Exclude("status", "delete").Limit(-1).Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get road len by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get road len by map fail: ", zap.Error(err)) } return int(cnt) } @@ -118,7 +119,7 @@ func GetRoadInfoByMap(ctx context.Context, params map[string]string, displayCoun _, err := qs.Exclude("status", "delete").Limit(displayCount, offset).OrderBy("-update_time").All(&roadInfoList) if err != nil { - otel.Logger.WithContext(ctx).Error("get road info by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get road info by map fail: ", zap.Error(err)) } return roadInfoList } @@ -134,7 +135,7 @@ func GetAllRoad(ctx context.Context, params map[string]string) []RoadInfo { } _, err := qs.Limit(-1).All(&roadInfoList) if err != nil { - otel.Logger.WithContext(ctx).Error("get all road fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get all road fail: ", zap.Error(err)) } return roadInfoList } @@ -143,7 +144,7 @@ func InsertRoadInfo(ctx context.Context, roadInfo RoadInfo) bool { o := orm.NewOrm() _, err := o.Insert(&roadInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("insert road info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert road info fail: ", zap.Error(err)) return false } return true @@ -160,7 +161,7 @@ func UpdateRoadInfo(ctx context.Context, roadInfo RoadInfo) bool { o := orm.NewOrm() _, err := o.Update(&roadInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("update road info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update road info fail: ", zap.Error(err)) return false } return true @@ -170,7 +171,7 @@ func DeleteRoadByRoadUid(ctx context.Context, roadUid string) bool { o := orm.NewOrm() _, err := o.QueryTable(ROAD_INFO).Filter("road_uid", roadUid).Delete() if err != nil { - otel.Logger.WithContext(ctx).Error("delete road by road uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("delete road by road uid fail: ", zap.Error(err)) return false } return true diff --git a/internal/models/road/road_pool_info.go b/internal/models/road/road_pool_info.go index c6dcdbe..117517c 100644 --- a/internal/models/road/road_pool_info.go +++ b/internal/models/road/road_pool_info.go @@ -2,7 +2,8 @@ package road import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -25,7 +26,7 @@ func InsertRoadPool(ctx context.Context, roadPool RoadPoolInfo) bool { o := orm.NewOrm() _, err := o.Insert(&roadPool) if err != nil { - otel.Logger.WithContext(ctx).Error("insert road pool fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert road pool fail: ", zap.Error(err)) return false } return true @@ -41,7 +42,7 @@ func GetRoadPoolLenByMap(ctx context.Context, params map[string]string) int { } cnt, err := qs.Limit(-1).Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get road pool len by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get road pool len by map fail: ", zap.Error(err)) } return int(cnt) } @@ -57,7 +58,7 @@ func GetRoadPoolByMap(ctx context.Context, params map[string]string, displayCoun } _, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&roadPoolList) if err != nil { - otel.Logger.WithContext(ctx).Error("get road pool by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get road pool by map fail: ", zap.Error(err)) } return roadPoolList } @@ -67,7 +68,7 @@ func GetRoadPoolByRoadPoolCode(ctx context.Context, roadPoolCode string) RoadPoo var roadPoolInfo RoadPoolInfo _, err := o.QueryTable(ROAD_POOL_INFO).Filter("road_pool_code", roadPoolCode).Limit(1).All(&roadPoolInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get road pool info by road pool code fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get road pool info by road pool code fail: ", zap.Error(err)) } return roadPoolInfo @@ -84,7 +85,7 @@ func GetAllRollPool(ctx context.Context, params map[string]string) []RoadPoolInf } _, err := qs.Limit(-1).All(&roadPoolList) if err != nil { - otel.Logger.WithContext(ctx).Error("get all roll pool fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get all roll pool fail: ", zap.Error(err)) } return roadPoolList } @@ -94,7 +95,7 @@ func GetRoadPoolByName(ctx context.Context, roadPoolName string) RoadPoolInfo { var roadPoolInfo RoadPoolInfo _, err := o.QueryTable(ROAD_POOL_INFO).Filter("road_pool_name", roadPoolName).Limit(1).All(&roadPoolInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get road pool by name fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get road pool by name fail: ", zap.Error(err)) } return roadPoolInfo } @@ -103,7 +104,7 @@ func DeleteRoadPoolByCode(ctx context.Context, roadPoolCode string) bool { o := orm.NewOrm() _, err := o.QueryTable(ROAD_POOL_INFO).Filter("road_pool_code", roadPoolCode).Delete() if err != nil { - otel.Logger.WithContext(ctx).Error("delete road pool by code fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("delete road pool by code fail: ", zap.Error(err)) return false } return true @@ -113,7 +114,7 @@ func UpdateRoadPool(ctx context.Context, roadPool RoadPoolInfo) bool { o := orm.NewOrm() _, err := o.Update(&roadPool) if err != nil { - otel.Logger.WithContext(ctx).Error("update road pool fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update road pool fail: ", zap.Error(err)) return false } return true diff --git a/internal/models/system/bank_card_info.go b/internal/models/system/bank_card_info.go index 2cf0541..55f82ad 100644 --- a/internal/models/system/bank_card_info.go +++ b/internal/models/system/bank_card_info.go @@ -2,7 +2,8 @@ package system import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -32,7 +33,7 @@ func InsertBankCardInfo(ctx context.Context, bankCardInfo BankCardInfo) bool { o := orm.NewOrm() _, err := o.Insert(&bankCardInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("insert bank card info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert bank card info fail: ", zap.Error(err)) return false } return true @@ -46,7 +47,7 @@ func GetBankCardLenByMap(ctx context.Context, params map[string]string) int { } cnt, err := qs.Limit(-1).Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get bank card len by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get bank card len by map fail: ", zap.Error(err)) } return int(cnt) } @@ -62,7 +63,7 @@ func GetBankCardByMap(ctx context.Context, params map[string]string, displayCoun } _, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&bankCardList) if err != nil { - otel.Logger.WithContext(ctx).Error("get bank card by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get bank card by map fail: ", zap.Error(err)) } return bankCardList } @@ -72,7 +73,7 @@ func GetBankCardByUid(ctx context.Context, uid string) BankCardInfo { var bankCardInfo BankCardInfo _, err := o.QueryTable(bankCardInfo).Filter("uid", uid).Limit(1).All(&bankCardInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get bank card by uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get bank card by uid fail: ", zap.Error(err)) } return bankCardInfo @@ -82,7 +83,7 @@ func DeleteBankCardByUid(ctx context.Context, uid string) bool { o := orm.NewOrm() _, err := o.QueryTable(BANK_CARD_INFO).Filter("uid", uid).Delete() if err != nil { - otel.Logger.WithContext(ctx).Error("delete bank card by uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("delete bank card by uid fail: ", zap.Error(err)) return false } return true @@ -92,7 +93,7 @@ func UpdateBankCard(ctx context.Context, bankCard BankCardInfo) bool { o := orm.NewOrm() _, err := o.Update(&bankCard) if err != nil { - otel.Logger.WithContext(ctx).Error("update bank card fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update bank card fail: ", zap.Error(err)) return false } return true diff --git a/internal/models/system/menu_info.go b/internal/models/system/menu_info.go index 6fa7440..ec876eb 100644 --- a/internal/models/system/menu_info.go +++ b/internal/models/system/menu_info.go @@ -2,7 +2,8 @@ package system import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -42,7 +43,7 @@ func InsertMenu(ctx context.Context, menuInfo MenuInfo) bool { o := orm.NewOrm() _, err := o.Insert(&menuInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("insert new menu info fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert new menu info fail:", zap.Error(err)) return false } return true @@ -70,7 +71,7 @@ func GetMenuLen(ctx context.Context) int { o := orm.NewOrm() cnt, err := o.QueryTable(MENUINFO).Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get menu info len length fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get menu info len length fail: ", zap.Error(err)) } return int(cnt) } @@ -80,7 +81,7 @@ func GetMenuInfoByMenuUid(ctx context.Context, menuUid string) MenuInfo { var menuInfo MenuInfo _, err := o.QueryTable(MENUINFO).Filter("menu_uid", menuUid).Limit(1).All(&menuInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get menu info by menuUid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get menu info by menuUid fail: ", zap.Error(err)) } return menuInfo } @@ -99,7 +100,7 @@ func GetMenuInfoByMenuOrder(ctx context.Context, menuOrder int) MenuInfo { var menuInfo MenuInfo _, err := o.QueryTable(MENUINFO).Filter("menu_order", menuOrder).Limit(1).All(&menuInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get menu info by menu order fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get menu info by menu order fail: ", zap.Error(err)) } return menuInfo } @@ -109,7 +110,7 @@ func GetMenuAll(ctx context.Context) []MenuInfo { var menuInfoList []MenuInfo _, err := o.QueryTable(MENUINFO).OrderBy("-update_time").All(&menuInfoList) if err != nil { - otel.Logger.WithContext(ctx).Error("get all menu list fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get all menu list fail:", zap.Error(err)) } return menuInfoList } @@ -119,7 +120,7 @@ func GetMenuOffset(ctx context.Context, displayCount, offset int) []MenuInfo { var menuInfoList []MenuInfo _, err := o.QueryTable(MENUINFO).Limit(displayCount, offset).All(&menuInfoList) if err != nil { - otel.Logger.WithContext(ctx).Error("get menu offset fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get menu offset fail: ", zap.Error(err)) } return menuInfoList } @@ -135,7 +136,7 @@ func GetMenuOffsetByMap(ctx context.Context, params map[string]string, displayCo } _, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&menuInfoList) if err != nil { - otel.Logger.WithContext(ctx).Error("get menu offset by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get menu offset by map fail: ", zap.Error(err)) } return menuInfoList } @@ -150,7 +151,7 @@ func GetMenuLenByMap(ctx context.Context, params map[string]string) int { } cnt, err := qs.Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get menu len by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get menu len by map fail: ", zap.Error(err)) } return int(cnt) } @@ -159,16 +160,16 @@ func UpdateMenuInfo(ctx context.Context, menuInfo MenuInfo) { o := orm.NewOrm() cnt, err := o.Update(&menuInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("update menu info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update menu info fail: ", zap.Error(err)) } - otel.Logger.WithContext(ctx).Info("update menu info success, num: ", zap.Int64("cnt", cnt)) + otelTrace.Logger.WithContext(ctx).Info("update menu info success, num: ", zap.Int64("cnt", cnt)) } func DeleteMenuInfo(ctx context.Context, menuUid string) { o := orm.NewOrm() cnt, err := o.QueryTable(MENUINFO).Filter("menu_uid", menuUid).Delete() if err != nil { - otel.Logger.WithContext(ctx).Error("delete menu info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("delete menu info fail: ", zap.Error(err)) } - otel.Logger.WithContext(ctx).Info("delete menu info num: ", zap.Int64("cnt", cnt)) + otelTrace.Logger.WithContext(ctx).Info("delete menu info num: ", zap.Int64("cnt", cnt)) } diff --git a/internal/models/system/power_info.go b/internal/models/system/power_info.go index f692eb0..f4b06f4 100644 --- a/internal/models/system/power_info.go +++ b/internal/models/system/power_info.go @@ -2,7 +2,8 @@ package system import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -48,7 +49,7 @@ func InsertPowerInfo(ctx context.Context, powerInfo PowerInfo) bool { o := orm.NewOrm() _, err := o.Insert(&powerInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("insert power info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert power info fail: ", zap.Error(err)) return false } return true @@ -59,7 +60,7 @@ func GetPower(ctx context.Context) []PowerInfo { var powerInfo []PowerInfo _, err := o.QueryTable(POWER_INFO).Limit(-1).All(&powerInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get power fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get power fail: ", zap.Error(err)) } return powerInfo } @@ -69,7 +70,7 @@ func GetPowerById(ctx context.Context, powerId string) PowerInfo { var powerInfo PowerInfo _, err := o.QueryTable(POWER_INFO).Filter("power_id", powerId).Limit(1).All(&powerInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get power by id fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get power by id fail: ", zap.Error(err)) } return powerInfo } @@ -93,7 +94,7 @@ func GetPowerItemLenByMap(ctx context.Context, params map[string]string) int { } cnt, err := qs.Limit(-1).Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get power item len by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get power item len by map fail: ", zap.Error(err)) } return int(cnt) } @@ -110,7 +111,7 @@ func GetPowerItemByMap(ctx context.Context, params map[string]string, displpay, _, err := qs.Limit(displpay, offset).OrderBy("-update_time").All(&powerItemList) if err != nil { - otel.Logger.WithContext(ctx).Error("get power item by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get power item by map fail: ", zap.Error(err)) } return powerItemList } @@ -119,7 +120,7 @@ func DeletePowerItemByPowerID(ctx context.Context, powerID string) bool { o := orm.NewOrm() _, err := o.QueryTable(POWER_INFO).Filter("power_id", powerID).Delete() if err != nil { - otel.Logger.WithContext(ctx).Error("delete power item by powerID fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("delete power item by powerID fail: ", zap.Error(err)) return false } return true @@ -129,7 +130,7 @@ func DeletePowerBySecondUid(ctx context.Context, secondUid string) bool { o := orm.NewOrm() _, err := o.QueryTable(POWER_INFO).Filter("second_menu_uid", secondUid).Delete() if err != nil { - otel.Logger.WithContext(ctx).Error("delete power by second menu uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("delete power by second menu uid fail: ", zap.Error(err)) return false } return true diff --git a/internal/models/system/role_info.go b/internal/models/system/role_info.go index c99d7f0..6c93ba6 100644 --- a/internal/models/system/role_info.go +++ b/internal/models/system/role_info.go @@ -2,7 +2,8 @@ package system import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -38,7 +39,7 @@ func GetRoleLenByMap(ctx context.Context, params map[string]string) int { } cnt, err := qs.Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get role len by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get role len by map fail: ", zap.Error(err)) } return int(cnt) } @@ -48,7 +49,7 @@ func GetRole(ctx context.Context) []RoleInfo { var roleInfo []RoleInfo _, err := o.QueryTable(ROLE_INFO).Limit(-1).OrderBy("-update_time").All(&roleInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get all role fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get all role fail: ", zap.Error(err)) } return roleInfo } @@ -64,7 +65,7 @@ func GetRoleByMap(ctx context.Context, params map[string]string, display, offset } _, err := qs.Limit(display, offset).OrderBy("-update_time").All(&roleInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get role by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get role by map fail: ", zap.Error(err)) } return roleInfo } @@ -74,7 +75,7 @@ func GetRoleByRoleUid(ctx context.Context, roleUid string) RoleInfo { var roleInfo RoleInfo _, err := o.QueryTable(ROLE_INFO).Filter("role_uid", roleUid).Limit(1).All(&roleInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get role by role uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get role by role uid fail: ", zap.Error(err)) } return roleInfo } @@ -89,7 +90,7 @@ func InsertRole(ctx context.Context, roleInfo RoleInfo) bool { o := orm.NewOrm() _, err := o.Insert(&roleInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("insert role fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert role fail: ", zap.Error(err)) return false } return true @@ -99,7 +100,7 @@ func DeleteRoleByRoleUid(ctx context.Context, roleUid string) bool { o := orm.NewOrm() _, err := o.QueryTable(ROLE_INFO).Filter("role_uid", roleUid).Delete() if err != nil { - otel.Logger.WithContext(ctx).Error("delete role by role uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("delete role by role uid fail: ", zap.Error(err)) return false } return true @@ -109,7 +110,7 @@ func UpdateRoleInfo(ctx context.Context, roleInfo RoleInfo) bool { o := orm.NewOrm() _, err := o.Update(&roleInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("update role info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update role info fail: ", zap.Error(err)) return false } return true diff --git a/internal/models/system/second_menu_info.go b/internal/models/system/second_menu_info.go index 38370d2..edf1ced 100644 --- a/internal/models/system/second_menu_info.go +++ b/internal/models/system/second_menu_info.go @@ -2,7 +2,8 @@ package system import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -47,7 +48,7 @@ func GetSecondMenuLen(ctx context.Context) int { o := orm.NewOrm() cnt, err := o.QueryTable(SECOND_MENU_INFO).Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get second meun len fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get second meun len fail: ", zap.Error(err)) } return int(cnt) } @@ -57,7 +58,7 @@ func GetSecondMenuInfoByMenuOrder(ctx context.Context, menuOrder int, firstMenuU var secondMenuInfo SecondMenuInfo _, err := o.QueryTable(SECOND_MENU_INFO).Filter("first_menu_uid", firstMenuUid).Filter("menu_order", menuOrder).Limit(1).All(&secondMenuInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get second menu info by menu order fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get second menu info by menu order fail: ", zap.Error(err)) } return secondMenuInfo } @@ -66,7 +67,7 @@ func GetSecondMenuLenByFirstMenuUid(ctx context.Context, firstMenuUid string) in o := orm.NewOrm() cnt, err := o.QueryTable(SECOND_MENU_INFO).Filter("first_menu_uid", firstMenuUid).Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get second menu len by first menu uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get second menu len by first menu uid fail: ", zap.Error(err)) } return int(cnt) } @@ -76,7 +77,7 @@ func GetSecondMenuList(ctx context.Context) []SecondMenuInfo { var secondMenuList []SecondMenuInfo _, err := o.QueryTable(SECOND_MENU_INFO).Limit(-1).OrderBy("-update_time").All(&secondMenuList) if err != nil { - otel.Logger.WithContext(ctx).Error("get second menu list fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get second menu list fail: ", zap.Error(err)) } return secondMenuList } @@ -86,7 +87,7 @@ func GetSecondMenuInfoBySecondMenuUid(ctx context.Context, secondMenuUid string) var secondMenuInfo SecondMenuInfo _, err := o.QueryTable(SECOND_MENU_INFO).Filter("second_menu_uid", secondMenuUid).Limit(1).All(&secondMenuInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get scond menu info by second menu uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get scond menu info by second menu uid fail: ", zap.Error(err)) } return secondMenuInfo } @@ -105,7 +106,7 @@ func GetSecondMenuListByFirstMenuUid(ctx context.Context, firstMenuUid string) [ var secondMenuList []SecondMenuInfo _, err := o.QueryTable(SECOND_MENU_INFO).Filter("first_menu_uid", firstMenuUid).Limit(-1).OrderBy("-update_time").All(&secondMenuList) if err != nil { - otel.Logger.WithContext(ctx).Error("get second menu list by first menu uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get second menu list by first menu uid fail: ", zap.Error(err)) } return secondMenuList } @@ -118,7 +119,7 @@ func GetSecondMenuLenByMap(ctx context.Context, params map[string]string) int { } cnt, err := qs.Limit(-1).Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get second menu len by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get second menu len by map fail: ", zap.Error(err)) } return int(cnt) } @@ -134,7 +135,7 @@ func GetSecondMenuByMap(ctx context.Context, params map[string]string, displayCo } _, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&secondMenuList) if err != nil { - otel.Logger.WithContext(ctx).Error("get second menu by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get second menu by map fail: ", zap.Error(err)) } return secondMenuList } @@ -143,7 +144,7 @@ func InsertSecondMenu(ctx context.Context, secondMenuInfo SecondMenuInfo) bool { o := orm.NewOrm() _, err := o.Insert(&secondMenuInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("insert second menu fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert second menu fail: ", zap.Error(err)) return false } return true @@ -171,10 +172,10 @@ func DeleteSecondMenuByFirstMenuUid(ctx context.Context, firstMenuUid string) bo o := orm.NewOrm() num, err := o.QueryTable(SECOND_MENU_INFO).Filter("first_menu_uid", firstMenuUid).Delete() if err != nil { - otel.Logger.WithContext(ctx).Error("delete second menu by first menu uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("delete second menu by first menu uid fail: ", zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("delete second menu by first menu uid success, num: ", zap.Int64("num", num)) + otelTrace.Logger.WithContext(ctx).Info("delete second menu by first menu uid success, num: ", zap.Int64("num", num)) return true } @@ -182,10 +183,10 @@ func DeleteSecondMenuBySecondMenuUid(ctx context.Context, secondMenuUid string) o := orm.NewOrm() num, err := o.QueryTable(SECOND_MENU_INFO).Filter("second_menu_uid", secondMenuUid).Delete() if err != nil { - otel.Logger.WithContext(ctx).Error("delete second menu by second menu uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("delete second menu by second menu uid fail: ", zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("delete second menu by second menu uid success, num: ", zap.Int64("num", num)) + otelTrace.Logger.WithContext(ctx).Info("delete second menu by second menu uid success, num: ", zap.Int64("num", num)) return true } @@ -193,7 +194,7 @@ func UpdateSecondMenuOrderBySecondUid(ctx context.Context, secondUid string, ord o := orm.NewOrm() _, err := o.QueryTable(SECOND_MENU_INFO).Filter("second_menu_uid", secondUid).Update(orm.Params{"menu_order": order}) if err != nil { - otel.Logger.WithContext(ctx).Error("update second menu order by second menu uid fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update second menu order by second menu uid fail: ", zap.Error(err)) } } @@ -201,7 +202,7 @@ func UpdateSecondMenu(ctx context.Context, secondMenu SecondMenuInfo) { o := orm.NewOrm() _, err := o.Update(&secondMenu) if err != nil { - otel.Logger.WithContext(ctx).Error("update second menu for first order fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update second menu for first order fail: ", zap.Error(err)) } } diff --git a/internal/models/user/user_info.go b/internal/models/user/user_info.go index 6d3bcb1..bef1bd9 100644 --- a/internal/models/user/user_info.go +++ b/internal/models/user/user_info.go @@ -2,7 +2,8 @@ package user import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "time" "github.com/beego/beego/v2/client/orm" @@ -32,7 +33,7 @@ func GetUserInfoByUserID(ctx context.Context, userID string) UserInfo { var userInfo UserInfo err := o.QueryTable(USERINFO).Exclude("status", "delete").Filter("user_id", userID).One(&userInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get user info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get user info fail: ", zap.Error(err)) } return userInfo } @@ -48,7 +49,7 @@ func GetOperatorByMap(ctx context.Context, params map[string]string, displayCoun } _, err := qs.Exclude("status", "delete").Limit(displayCount, offset).OrderBy("-update_time").All(&userInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("get operator by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get operator by map fail: ", zap.Error(err)) } return userInfo } @@ -61,7 +62,7 @@ func GetOperatorLenByMap(ctx context.Context, params map[string]string) int { } cnt, err := qs.Exclude("status", "delete").Count() if err != nil { - otel.Logger.WithContext(ctx).Error("get operator len by map fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("get operator len by map fail: ", zap.Error(err)) } return int(cnt) } @@ -70,9 +71,9 @@ func UpdateUserInfoIP(ctx context.Context, userInfo UserInfo) { o := orm.NewOrm() num, err := o.QueryTable(USERINFO).Exclude("status", "delete").Filter("user_id", userInfo.UserId).Update(orm.Params{"ip": userInfo.Ip}) if err != nil { - otel.Logger.WithContext(ctx).Error("%s update user info ip fail: %v", zap.String("UserId", userInfo.UserId), zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("%s update user info ip fail: %v", zap.String("UserId", userInfo.UserId), zap.Error(err)) } else { - otel.Logger.WithContext(ctx).Info("%s update user info ip success, num: %d", zap.String("UserId", userInfo.UserId), zap.Int64("num", num)) + otelTrace.Logger.WithContext(ctx).Info("%s update user info ip success, num: %d", zap.String("UserId", userInfo.UserId), zap.Int64("num", num)) } } @@ -80,18 +81,18 @@ func UpdateUserInfoPassword(ctx context.Context, userInfo UserInfo) { o := orm.NewOrm() num, err := o.QueryTable(USERINFO).Exclude("status", "delete").Filter("user_id", userInfo.UserId).Update(orm.Params{"passwd": userInfo.Passwd}) if err != nil { - otel.Logger.WithContext(ctx).Error("%s update user info password fail: %v", zap.String("UserId", userInfo.UserId), zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("%s update user info password fail: %v", zap.String("UserId", userInfo.UserId), zap.Error(err)) } else { - otel.Logger.WithContext(ctx).Info("%s update user info password success, update num: %d", zap.String("UserId", userInfo.UserId), zap.Int64("num", num)) + otelTrace.Logger.WithContext(ctx).Info("%s update user info password success, update num: %d", zap.String("UserId", userInfo.UserId), zap.Int64("num", num)) } } func UpdateUserInfo(ctx context.Context, userInfo UserInfo) { o := orm.NewOrm() if num, err := o.Update(&userInfo); err != nil { - otel.Logger.WithContext(ctx).Error("update user info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update user info fail: ", zap.Error(err)) } else { - otel.Logger.WithContext(ctx).Info("update user info success, num: ", zap.Int64("num", num)) + otelTrace.Logger.WithContext(ctx).Info("update user info success, num: ", zap.Int64("num", num)) } } @@ -99,7 +100,7 @@ func UpdateStauts(ctx context.Context, status, userId string) bool { o := orm.NewOrm() _, err := o.QueryTable(USERINFO).Filter("user_id", userId).Update(orm.Params{"status": status}) if err != nil { - otel.Logger.WithContext(ctx).Error("update status fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("update status fail: ", zap.Error(err)) return false } return true @@ -121,7 +122,7 @@ func InsertUser(ctx context.Context, userInfo UserInfo) bool { o := orm.NewOrm() _, err := o.Insert(&userInfo) if err != nil { - otel.Logger.WithContext(ctx).Error("insert user fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("insert user fail: ", zap.Error(err)) return false } return true @@ -131,7 +132,7 @@ func DeleteUserByUserId(ctx context.Context, userId string) bool { o := orm.NewOrm() _, err := o.QueryTable(USERINFO).Exclude("status", "delete").Filter("user_id", userId).Update(orm.Params{"status": "delete"}) if err != nil { - otel.Logger.WithContext(ctx).Error("delete user by userId fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("delete user by userId fail: ", zap.Error(err)) return false } return true diff --git a/internal/otel/init.go b/internal/otelTrace/init.go similarity index 98% rename from internal/otel/init.go rename to internal/otelTrace/init.go index 2b969b4..87a88d5 100644 --- a/internal/otel/init.go +++ b/internal/otelTrace/init.go @@ -1,4 +1,4 @@ -package otel +package otelTrace import ( "context" @@ -251,3 +251,7 @@ func getScheme(req *http.Request) string { } return scheme } + +func NewSchedulerTrace(opts ...trace.TracerOption) trace.Tracer { + return otel.Tracer("scheduler", opts...) +} diff --git a/internal/routers/router.go b/internal/routers/router.go index f2c35c4..f75a076 100644 --- a/internal/routers/router.go +++ b/internal/routers/router.go @@ -2,7 +2,8 @@ package routers import ( "gateway/internal/controllers/gateway" - "gateway/internal/otel" + + "gateway/internal/otelTrace" "gateway/internal/service/supplier/third_party" "github.com/beego/beego/v2/server/web" @@ -12,7 +13,7 @@ import ( func init() { web.InsertFilterChain("*", func(next web.FilterFunc) web.FilterFunc { return func(ctx *beecontext.Context) { - otel.Middleware(ctx, next) + otelTrace.Middleware(ctx, next) } }) // 网关处理 diff --git a/internal/schema/query/merchant_query.go b/internal/schema/query/merchant_query.go index 45eeea7..e4c44cd 100644 --- a/internal/schema/query/merchant_query.go +++ b/internal/schema/query/merchant_query.go @@ -6,7 +6,8 @@ import ( "fmt" "gateway/internal/models/merchant" "gateway/internal/models/order" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/utils" "strings" @@ -69,7 +70,7 @@ func (c *MerchantQueryController) OrderQuery(ctx context.Context) { p["sign"] = utils.GetMD5Sign(p, keys, paySercet) s, err := json.Marshal(p) if err != nil { - otel.Logger.WithContext(ctx).Error("json marshal fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("json marshal fail: ", zap.Error(err)) } c.Data["json"] = s } diff --git a/internal/schema/query/payfor_query.go b/internal/schema/query/payfor_query.go index 8c0fc86..9646245 100644 --- a/internal/schema/query/payfor_query.go +++ b/internal/schema/query/payfor_query.go @@ -6,7 +6,7 @@ import ( "gateway/internal/config" "gateway/internal/models/payfor" "gateway/internal/models/road" - "gateway/internal/otel" + "gateway/internal/otelTrace" "gateway/internal/service/message" "gateway/internal/service/pay_for" "gateway/internal/service/supplier/third_party" @@ -54,13 +54,13 @@ func PayForQueryTimer(ctx context.Context, task PayForQueryTask) { } func PayForSupplier(ctx context.Context, task PayForQueryTask) { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("执行代付查询任务:%+v", task)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("执行代付查询任务:%+v", task)) payFor := payfor.GetPayForByBankOrderId(ctx, task.BankOrderId) roadInfo := road.GetRoadInfoByRoadUid(ctx, payFor.RoadUid) supplier := third_party.GetPaySupplierByCode(roadInfo.ProductUid) if supplier == nil { - otel.Logger.WithContext(ctx).Error("代付查询返回supplier为空") + otelTrace.Logger.WithContext(ctx).Error("代付查询返回supplier为空") return } res, _ := supplier.PayForQuery(payFor) @@ -75,14 +75,14 @@ func PayForSupplier(ctx context.Context, task PayForQueryTask) { if task.QueryTimes <= task.LimitTimes { task.QueryTimes += 1 task.Delay = time.NewTimer(time.Duration(PayForQueryInterval) * time.Minute) - PayForQueryPool.CtxGo(ctx, func() { + PayForQueryPool.Go(func() { // 创建一个5分钟超时的上下文 - timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Minute) - defer cancel() + timeoutCtx, span := otelTrace.NewSchedulerTrace().Start(otelTrace.InitCtx, "PayForSupplier") + defer span.End() PayForQueryTimer(timeoutCtx, task) }) } else { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("该代付订单已经超过最大查询次数,bankOrderId = %s", task.BankOrderId)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("该代付订单已经超过最大查询次数,bankOrderId = %s", task.BankOrderId)) } } } @@ -90,14 +90,14 @@ func PayForSupplier(ctx context.Context, task PayForQueryTask) { func payForQueryConsumer(ctx context.Context, bankOrderId string) { exist := payfor.IsExistPayForByBankOrderId(bankOrderId) if !exist { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("代付记录不存在,bankOrderId = %s", bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("代付记录不存在,bankOrderId = %s", bankOrderId)) return } payFor := payfor.GetPayForByBankOrderId(ctx, bankOrderId) if payFor.Status != config.PAYFOR_BANKING { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("代付状态不是银行处理中,不需要去查询,bankOrderId = %s", bankOrderId)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("代付状态不是银行处理中,不需要去查询,bankOrderId = %s", bankOrderId)) return } @@ -117,17 +117,17 @@ func payForQueryConsumer(ctx context.Context, bankOrderId string) { // CreatePayForQueryConsumer 创建代付查询的消费者 func CreatePayForQueryConsumer(ctx context.Context) { - ctx, cancel := otel.Span(ctx, "CreatePayForQueryConsumer", "CreatePayForQueryConsumer") + ctx, cancel := otelTrace.Span(ctx, "CreatePayForQueryConsumer", "CreatePayForQueryConsumer") defer cancel() // 启动定时任务 conn := message.GetActiveMQConn() if conn == nil { - otel.Logger.WithContext(ctx).Error("启动消息队列消费者失败....") + otelTrace.Logger.WithContext(ctx).Error("启动消息队列消费者失败....") os.Exit(1) } payForQuery, err := conn.Subscribe(config.MqPayForQuery, stomp.AckClient) if err != nil { - otel.Logger.WithContext(ctx).Error("订阅代付查询失败......") + otelTrace.Logger.WithContext(ctx).Error("订阅代付查询失败......") os.Exit(1) } @@ -138,14 +138,14 @@ func CreatePayForQueryConsumer(ctx context.Context) { bankOrderId := string(v.Body) payForQueryConsumerPool.CtxGo(ctx, func() { // 创建一个5分钟超时的上下文 - timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Minute) - defer cancel() - payForQueryConsumer(timeoutCtx, bankOrderId) + ctx2, span := otelTrace.NewSchedulerTrace().Start(ctx, "CreatePayForQueryConsumer") + defer span.End() + payForQueryConsumer(ctx2, bankOrderId) }) // 应答,重要 err := conn.Ack(v) if err != nil { - otel.Logger.WithContext(ctx).Error("消息应答失败!") + otelTrace.Logger.WithContext(ctx).Error("消息应答失败!") } } } diff --git a/internal/schema/query/supplier_query.go b/internal/schema/query/supplier_query.go index e19d385..52d5e6b 100644 --- a/internal/schema/query/supplier_query.go +++ b/internal/schema/query/supplier_query.go @@ -7,7 +7,8 @@ import ( "gateway/internal/models/order" "gateway/internal/models/road" "gateway/internal/models/supply_model" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service/message" "gateway/internal/service/supplier/third_party" "os" @@ -32,11 +33,11 @@ func SupplierOrderQueryResult(ctx context.Context, bankOrderId string) supply_mo orderInfo := order.GetOrderByBankOrderId(ctx, bankOrderId) if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 { - otel.Logger.WithContext(ctx).Error("不存在这样的订单,订单查询结束") + otelTrace.Logger.WithContext(ctx).Error("不存在这样的订单,订单查询结束") return supply_model.OrderNotExist } if orderInfo.Status != "" && orderInfo.Status != "wait" { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("该订单=%s,已经处理完毕,", bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("该订单=%s,已经处理完毕,", bankOrderId)) return supply_model.OrderFinished } @@ -44,7 +45,7 @@ func SupplierOrderQueryResult(ctx context.Context, bankOrderId string) supply_mo supplier_ := third_party.GetPaySupplierByCode(supplierCode) if supplier_ == nil { - otel.Logger.WithContext(ctx).Error("不存在这样的订单,订单查询结束") + otelTrace.Logger.WithContext(ctx).Error("不存在这样的订单,订单查询结束") return supply_model.OrderNotExist } @@ -59,7 +60,7 @@ func solveSupplierOrderQuery(ctx context.Context, task OrderQueryTask) { flag := SupplierOrderQueryResult(ctx, bankOrderId) if flag == supply_model.RemoteSuccess || flag == supply_model.RemoteDataHealingErr { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("订单查询成功, bankOrderId:%s", bankOrderId)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("订单查询成功, bankOrderId:%s", bankOrderId)) } else { if task.Times <= LimitTimes { task.Times += 1 @@ -76,7 +77,7 @@ func DelayOrderQueryQueue(ctx context.Context, task OrderQueryTask) { for { select { case <-task.OrderQueryTimer.C: - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("订单id=%s,执行第:%d 次查询", task.BankOrderId, task.Times)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("订单id=%s,执行第:%d 次查询", task.BankOrderId, task.Times)) solveSupplierOrderQuery(ctx, task) return case <-time.After(time.Duration(2*DelayTime) * time.Minute): @@ -87,11 +88,11 @@ func DelayOrderQueryQueue(ctx context.Context, task OrderQueryTask) { // CreateSupplierOrderQueryCuConsumer 启动消息订单查询的消息队列消费者 func CreateSupplierOrderQueryCuConsumer(ctx context.Context) { - ctx, cancel := otel.Span(ctx, "CreateSupplierOrderQueryCuConsumer", "CreateSupplierOrderQueryCuConsumer") + ctx, cancel := otelTrace.Span(ctx, "CreateSupplierOrderQueryCuConsumer", "CreateSupplierOrderQueryCuConsumer") defer cancel() conn := message.GetActiveMQConn() if conn == nil { - otel.Logger.WithContext(ctx).Error("supply order query consumer fail") + otelTrace.Logger.WithContext(ctx).Error("supply order query consumer fail") os.Exit(1) } logs.Notice("启动订单查询的消费者成功.....") @@ -102,13 +103,13 @@ func CreateSupplierOrderQueryCuConsumer(ctx context.Context) { case v := <-orderQuerySub.C: if v != nil { bankOrderId := string(v.Body) - otel.Logger.WithContext(ctx).Info("消费者正在处理订单查询: " + bankOrderId) + otelTrace.Logger.WithContext(ctx).Info("消费者正在处理订单查询: " + bankOrderId) task := OrderQueryTask{BankOrderId: bankOrderId, OrderQueryTimer: time.NewTimer(time.Second * 1), Times: 1} DelayOrderQueryQueue(ctx, task) // 应答,重要 err := conn.Ack(v) if err != nil { - otel.Logger.WithContext(ctx).Error("消息应答失败!") + otelTrace.Logger.WithContext(ctx).Error("消息应答失败!") } } } diff --git a/internal/service/base_service.go b/internal/service/base_service.go index f0f304e..a37fb7c 100644 --- a/internal/service/base_service.go +++ b/internal/service/base_service.go @@ -5,7 +5,8 @@ import ( "encoding/json" "errors" "gateway/internal/config" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service/supplier" "gateway/internal/models/merchant" @@ -82,7 +83,7 @@ func ExValueIsValid(ctx context.Context, c *response.PayBaseResp) *response.PayB isRedeemValid := true exRedeemValue := supplier.RedeemCardInfo{} if err := json.Unmarshal([]byte(convertor.ToString(c.Params["exValue"])), &exRedeemValue); err != nil { - otel.Logger.WithContext(ctx).Error("提交卡密格式错误,请检查", zap.Any("exValue", c.Params["exValue"]), zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("提交卡密格式错误,请检查", zap.Any("exValue", c.Params["exValue"]), zap.Error(err)) isRedeemValid = false } if exRedeemValue.Data == "" || len(exRedeemValue.Data) == 0 { @@ -161,7 +162,7 @@ func OrderPriceIsValid(ctx context.Context, c *response.PayBaseResp) *response.P a, err := strconv.ParseFloat(convertor.ToString(c.Params["orderPrice"]), 64) if err != nil { - otel.Logger.WithContext(ctx).Error("order price is invalid: ", zap.Any("orderPrice", c.Params["orderPrice"]), zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("order price is invalid: ", zap.Any("orderPrice", c.Params["orderPrice"]), zap.Error(err)) c.Code = -1 c.Msg = "订单金额非法" } diff --git a/internal/service/merchant_hidden_config.go b/internal/service/merchant_hidden_config.go index 486930b..7701d25 100644 --- a/internal/service/merchant_hidden_config.go +++ b/internal/service/merchant_hidden_config.go @@ -9,7 +9,8 @@ import ( "gateway/internal/models/order" "gateway/internal/models/road" "gateway/internal/models/setting" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service/supplier" "strings" "sync" @@ -48,7 +49,7 @@ func GetOrderHidden(ctx context.Context, orderNo *order.OrderInfo) (cfg *hidden. var amountRule []int err = json.Unmarshal([]byte(config.AmountRule), &amountRule) if err != nil { - otel.Logger.WithContext(ctx).Error("偷卡规则查询失败:%v", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("偷卡规则查询失败:%v", zap.Error(err)) continue } //匹配条件:当前订单金额在配置金额规则中 && 当前订单面额小于等于配置面额 @@ -63,7 +64,7 @@ func GetOrderHidden(ctx context.Context, orderNo *order.OrderInfo) (cfg *hidden. record, err2 := hidden.GetLatestOneRecordByHiddenConfigId(config.Id, []int{int(consts.StealRuleStatusSuccess), int(consts.StealRuleStatusWaiting)}) if err2 != nil { - otel.Logger.WithContext(ctx).Error("偷卡规则查询失败:%v", zap.Error(err2)) + otelTrace.Logger.WithContext(ctx).Error("偷卡规则查询失败:%v", zap.Error(err2)) continue } @@ -71,7 +72,7 @@ func GetOrderHidden(ctx context.Context, orderNo *order.OrderInfo) (cfg *hidden. if record.IsFinish == 1 || record.Id == 0 { orderInfos, err := order.GetByUidAndRoadUidAndTime(config.MerchantUid, config.RoadUid, datetime.Max(record.UpdatedAt, *cardConfig.UpdatedAt)) if err != nil || len(orderInfos) == 0 { - otel.Logger.WithContext(ctx).Error("偷卡规则查询失败:%v", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("偷卡规则查询失败:%v", zap.Error(err)) continue } @@ -94,7 +95,7 @@ func GetOrderHidden(ctx context.Context, orderNo *order.OrderInfo) (cfg *hidden. // 获取最后一轮偷卡数据 records, err := hidden.GetRecordByConfigId(record.MerchantHiddenConfigId, []int{int(consts.StealRuleStatusSuccess), int(consts.StealRuleStatusWaiting)}, lastSucceedRecord.CreatedAt) if err != nil { - otel.Logger.WithContext(ctx).Error("偷卡规则查询失败:%v", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("偷卡规则查询失败:%v", zap.Error(err)) return } recordTotal := slice.ReduceBy(records, 0, func(index int, item *hidden.MerchantHiddenRecord, agg int) int { @@ -113,7 +114,7 @@ func GetOrderHidden(ctx context.Context, orderNo *order.OrderInfo) (cfg *hidden. // CreateHiddenBlankOrder 创建新的空白订单 func CreateHiddenBlankOrder(ctx context.Context, orderInfo *order.OrderInfo, duration int64) (bankOrderId string, err error) { bankOrderId, err = order.HiddenOrder(ctx, orderInfo) - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("创建新的假订单:%v", orderInfo.BankOrderId, bankOrderId), zap.String("bankOrderId", bankOrderId), zap.String("orderInfo.BankOrderId", orderInfo.BankOrderId)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("创建新的假订单:%v", orderInfo.BankOrderId, bankOrderId), zap.String("bankOrderId", bankOrderId), zap.String("orderInfo.BankOrderId", orderInfo.BankOrderId)) //复制到一个新的对象中 newOrderInfo := deepcopy.Copy(*orderInfo).(order.OrderInfo) @@ -270,7 +271,7 @@ func UpdateRelateRecordSucceedStatus(ctx context.Context, orderBankId string, am UpdateStealRecordLock.Lock() defer UpdateStealRecordLock.Unlock() - otel.Logger.WithContext(ctx).Info("【偷卡】更新偷卡记录", zap.String(orderBankId, "orderBankId"), zap.Float64("amount", amount)) + otelTrace.Logger.WithContext(ctx).Info("【偷卡】更新偷卡记录", zap.String(orderBankId, "orderBankId"), zap.Float64("amount", amount)) //查询本次偷卡记录 record, err := GetRelateRecordByTargetOrderNo(ctx, orderBankId) if err != nil || pointer.IsNil(record) || record.Id == 0 { diff --git a/internal/service/merchant_hidden_config_test.go b/internal/service/merchant_hidden_config_test.go index 681cefc..3c93672 100644 --- a/internal/service/merchant_hidden_config_test.go +++ b/internal/service/merchant_hidden_config_test.go @@ -2,11 +2,12 @@ package service import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "testing" ) func TestReplaceNumberOrLetter(t *testing.T) { result := ReplaceNumberOrLetter("1111111111", len("1111111111")) - otel.Logger.WithContext(context.Background()).Info(result) + otelTrace.Logger.WithContext(context.Background()).Info(result) } diff --git a/internal/service/message/send_message.go b/internal/service/message/send_message.go index 55def8b..7e4eed8 100644 --- a/internal/service/message/send_message.go +++ b/internal/service/message/send_message.go @@ -3,7 +3,8 @@ package message import ( "context" "fmt" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "os" "go.uber.org/zap" @@ -12,14 +13,14 @@ import ( func SendMessage(ctx context.Context, topic, message string) { conn := GetActiveMQConn() if conn == nil { - otel.Logger.WithContext(ctx).Error("send message get Active mq fail") + otelTrace.Logger.WithContext(ctx).Error("send message get Active mq fail") os.Exit(1) } err := conn.Send(topic, "text/plain", []byte(message)) if err != nil { - otel.Logger.WithContext(ctx).Error("发送消息给activeMQ失败, message=", zap.String("message", message)) + otelTrace.Logger.WithContext(ctx).Error("发送消息给activeMQ失败, message=", zap.String("message", message)) } else { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("发送消息给activeMQ成功,message="), zap.String("message", message)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("发送消息给activeMQ成功,message="), zap.String("message", message)) } } diff --git a/internal/service/notify/order_notify.go b/internal/service/notify/order_notify.go index b29474d..ba1ea42 100644 --- a/internal/service/notify/order_notify.go +++ b/internal/service/notify/order_notify.go @@ -6,7 +6,7 @@ import ( "gateway/internal/config" "gateway/internal/consts" "gateway/internal/models/notify" - "gateway/internal/otel" + "gateway/internal/otelTrace" "gateway/internal/service/message" "gateway/internal/utils" "os" @@ -39,13 +39,13 @@ var ( // SendOrderNotify 给商户发送订单结果 func SendOrderNotify(ctx context.Context, bankOrderId string) { if !notify.NotifyInfoExistByBankOrderId(bankOrderId) { - otel.Logger.WithContext(ctx).Error("该订单不存在回调内容,bankOrderId= " + bankOrderId) + otelTrace.Logger.WithContext(ctx).Error("该订单不存在回调内容,bankOrderId= " + bankOrderId) return } notifyInfo := notify.GetNotifyInfoByBankOrderId(ctx, bankOrderId) if notifyInfo.Status == "success" { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("该订单= %s,已经回调", bankOrderId)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("该订单= %s,已经回调", bankOrderId)) return } @@ -54,15 +54,15 @@ func SendOrderNotify(ctx context.Context, bankOrderId string) { req := httplib.Get(notifyInfo.Url) response, err := req.String() - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("bankOrderId = %s, 回调结果为:%s", bankOrderId, response)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("bankOrderId = %s, 回调结果为:%s", bankOrderId, response)) if err == nil && ("success" == response || "SUCCESS" == response) { if strings.Contains(strings.ToLower(response), "success") { notifyInfo.Status = "success" if notify.UpdateNotifyInfo(ctx, notifyInfo) { - otel.Logger.WithContext(ctx).Info("订单回调成功, bankOrderId=", zap.String("bankOrderId", bankOrderId)) + otelTrace.Logger.WithContext(ctx).Info("订单回调成功, bankOrderId=", zap.String("bankOrderId", bankOrderId)) } else { - otel.Logger.WithContext(ctx).Error("订单回调成功,但是更新数据库失败, bankOrderId=", zap.String("bankOrderId", bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error("订单回调成功,但是更新数据库失败, bankOrderId=", zap.String("bankOrderId", bankOrderId)) } } else { logs.Notice("订单已经回调,商户已经收到了回调通知,但是返回值错误: ", response) @@ -72,7 +72,7 @@ func SendOrderNotify(ctx context.Context, bankOrderId string) { logs.Notice(fmt.Sprintf("该订单= %s,已经超过了回调次数", bankOrderId)) } else { minute := GetOrderNotifyMinute(notifyInfo.Times) - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("bankOrderId = %s, 进行第 %d 次回调,本次延时时间为:%d", notifyInfo.BankOrderId, notifyInfo.Times, minute)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("bankOrderId = %s, 进行第 %d 次回调,本次延时时间为:%d", notifyInfo.BankOrderId, notifyInfo.Times, minute)) task := OrderNotifyTask{ Delay: time.NewTimer(time.Duration(minute) * time.Minute), MerchantOrderId: notifyInfo.MerchantOrderId, @@ -80,14 +80,14 @@ func SendOrderNotify(ctx context.Context, bankOrderId string) { FirstNotifyTime: notifyInfo.CreateTime.Format("2006-12-20 12:43:34"), NotifyTimes: notifyInfo.Times, LimitTimes: consts.LimitTimes, Status: notifyInfo.Status, } - notifyPool.CtxGo(ctx, func() { + notifyPool.Go(func() { // 创建一个5分钟超时的上下文 - timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Minute) - defer cancel() - OrderNotifyTimer(timeoutCtx, task) + ctx2, span := otelTrace.NewSchedulerTrace().Start(otelTrace.InitCtx, "sendOrderNotify") + defer span.End() + OrderNotifyTimer(ctx2, task) }) if !notify.UpdateNotifyInfo(ctx, notifyInfo) { - otel.Logger.WithContext(ctx).Error("订单回调失败,数据库更新失败:" + bankOrderId) + otelTrace.Logger.WithContext(ctx).Error("订单回调失败,数据库更新失败:" + bankOrderId) } } } @@ -159,19 +159,19 @@ func CreateOrderDelayQueue(ctx context.Context) { // CreateOrderNotifyConsumer 创建订单回调消费者 func CreateOrderNotifyConsumer(ctx context.Context) { - ctx, cancel := otel.Span(ctx, "CreateOrderNotifyConsumer", "CreateOrderNotifyConsumer") + ctx, cancel := otelTrace.Span(ctx, "CreateOrderNotifyConsumer", "CreateOrderNotifyConsumer") defer cancel() CreateOrderDelayQueue(ctx) // 启动定时任务 conn := message.GetActiveMQConn() if conn == nil { - otel.Logger.WithContext(ctx).Error("启动消息队列消费者失败....") + otelTrace.Logger.WithContext(ctx).Error("启动消息队列消费者失败....") os.Exit(1) } logs.Notice("订单回调消息队列启动成功......") orderNotify, err := conn.Subscribe(config.MqOrderNotify, stomp.AckClient) if err != nil { - otel.Logger.WithContext(ctx).Error("订阅订单回调失败......") + otelTrace.Logger.WithContext(ctx).Error("订阅订单回调失败......") os.Exit(1) } for { @@ -180,14 +180,14 @@ func CreateOrderNotifyConsumer(ctx context.Context) { if v != nil { bankOrderId := string(v.Body) sendNotifyPool.CtxGo(ctx, func() { - timeoutCtx, cancel := context.WithTimeout(ctx, time.Hour) - defer cancel() - SendOrderNotify(timeoutCtx, bankOrderId) + ctx2, span := otelTrace.NewSchedulerTrace().Start(otelTrace.InitCtx, "Span") + defer span.End() + SendOrderNotify(ctx2, bankOrderId) }) // 应答,重要 err := conn.Ack(v) if err != nil { - otel.Logger.WithContext(ctx).Error("消息应答失败!") + otelTrace.Logger.WithContext(ctx).Error("消息应答失败!") } } } diff --git a/internal/service/pay_for/payfor_service.go b/internal/service/pay_for/payfor_service.go index b6feb07..a7631b8 100644 --- a/internal/service/pay_for/payfor_service.go +++ b/internal/service/pay_for/payfor_service.go @@ -10,7 +10,7 @@ import ( "gateway/internal/models/merchant_deploy" "gateway/internal/models/payfor" "gateway/internal/models/road" - "gateway/internal/otel" + "gateway/internal/otelTrace" "gateway/internal/schema/response" "gateway/internal/service/message" "gateway/internal/service/supplier/third_party" @@ -33,7 +33,7 @@ func AutoPayFor(ctx context.Context, params map[string]any, giveType string) *re merchantInfo := merchant.GetMerchantByPasskey(ctx, convertor.ToString(params["merchantKey"])) if !utils.Md5Verify(params, merchantInfo.MerchantSecret) { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("下游商户代付请求,签名失败,商户信息: %+v", merchantInfo)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("下游商户代付请求,签名失败,商户信息: %+v", merchantInfo)) payForResponse.ResultCode = "01" payForResponse.ResultMsg = "下游商户代付请求,签名失败。" return payForResponse @@ -48,7 +48,7 @@ func AutoPayFor(ctx context.Context, params map[string]any, giveType string) *re exist := payfor.IsExistPayForByMerchantOrderId(convertor.ToString(params["merchantOrderId"])) if exist { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("代付订单号重复:merchantOrderId = %s", params["merchantOrderId"])) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("代付订单号重复:merchantOrderId = %s", params["merchantOrderId"])) payForResponse.ResultMsg = "商户订单号重复" payForResponse.ResultCode = "01" @@ -57,7 +57,7 @@ func AutoPayFor(ctx context.Context, params map[string]any, giveType string) *re settAmount, err := strconv.ParseFloat(convertor.ToString(params["amount"]), 64) if err != nil { - otel.Logger.WithContext(ctx).Error("代付的金额错误:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("代付的金额错误:", zap.Error(err)) payForResponse.ResultMsg = "代付金额错误" payForResponse.ResultCode = "01" return payForResponse @@ -134,7 +134,7 @@ func findPayForRoad(ctx context.Context, p payfor.PayforInfo) bool { roadUids := strings.Split(roadPoolInfo.RoadUidPool, "||") roadInfoList := road.GetRoadInfosByRoadUids(ctx, roadUids) if len(roadUids) == 0 || len(roadInfoList) == 0 { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("通道轮询池=%s, 没有配置通道", m.RollPayForRoadCode)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("通道轮询池=%s, 没有配置通道", m.RollPayForRoadCode)) } else { p.RoadUid = roadInfoList[0].RoadUid p.RoadName = roadInfoList[0].RoadName @@ -151,7 +151,7 @@ func findPayForRoad(ctx context.Context, p payfor.PayforInfo) bool { p.PayforTotalAmount = p.PayforFee + p.PayforAmount if m.PayforFee > config.ZERO { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("商户uid=%s,有单独的代付手续费。", m.MerchantUid)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("商户uid=%s,有单独的代付手续费。", m.MerchantUid)) p.PayforFee = m.PayforFee p.PayforTotalAmount = p.PayforFee + p.PayforAmount } @@ -209,7 +209,7 @@ func SendPayFor(ctx context.Context, p payfor.PayforInfo) bool { if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error { var account accounts.AccountInfo if err := txOrm.Raw("select * from account_info where account_uid = ? for update", p.MerchantUid).QueryRow(&account); err != nil || account.AccountUid == "" { - otel.Logger.WithContext(ctx).Error("send payfor select account fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("send payfor select account fail:", zap.Error(err)) return err } @@ -229,7 +229,7 @@ func SendPayFor(ctx context.Context, p payfor.PayforInfo) bool { account.PayforAmount = account.PayforAmount + p.PayforAmount + p.PayforFee if _, err := txOrm.Update(&account); err != nil { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=%s,在发送代付给上游的处理中,更新账户表出错, err: %s", p.MerchantUid, err)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=%s,在发送代付给上游的处理中,更新账户表出错, err: %s", p.MerchantUid, err)) return err } @@ -240,7 +240,7 @@ func SendPayFor(ctx context.Context, p payfor.PayforInfo) bool { p.UpdateTime = time.Now() if _, err := txOrm.Update(&p); err != nil { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=%s,在发送代付给上游的处理中,更代付列表出错, err:%s", p.MerchantUid, err)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=%s,在发送代付给上游的处理中,更代付列表出错, err:%s", p.MerchantUid, err)) return err } @@ -262,7 +262,7 @@ func RequestPayFor(ctx context.Context, p payfor.PayforInfo) { supplierCode := roadInfo.ProductUid supplier := third_party.GetPaySupplierByCode(supplierCode) res := supplier.PayFor(p) - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("代付uid=%s,上游处理结果为:%s", p.PayforUid, res)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("代付uid=%s,上游处理结果为:%s", p.PayforUid, res)) // 将代付订单号发送到消息队列 message.SendMessage(ctx, config.MqPayForQuery, p.BankOrderId) } @@ -308,7 +308,7 @@ func PayForResultQuery(ctx context.Context, params map[string]any) string { mJson, err := json.Marshal(query) if err != nil { - otel.Logger.WithContext(ctx).Error("PayForQuery json marshal fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("PayForQuery json marshal fail:", zap.Error(err)) return fmt.Sprintf("PayForQuery json marshal fail:%s", err.Error()) } else { return string(mJson) @@ -347,7 +347,7 @@ func BalanceQuery(ctx context.Context, params map[string]any) string { func checkSettAmount(ctx context.Context, settAmount string) (bool, string) { _, err := strconv.ParseFloat(settAmount, 64) if err != nil { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("代付金额有误,settAmount = %s", settAmount)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("代付金额有误,settAmount = %s", settAmount)) return false, "代付金额有误" } return true, "" diff --git a/internal/service/pay_for/payfor_solve.go b/internal/service/pay_for/payfor_solve.go index 8f37004..97c05d2 100644 --- a/internal/service/pay_for/payfor_solve.go +++ b/internal/service/pay_for/payfor_solve.go @@ -7,7 +7,7 @@ import ( "gateway/internal/config" "gateway/internal/models/accounts" "gateway/internal/models/payfor" - "gateway/internal/otel" + "gateway/internal/otelTrace" "time" "github.com/beego/beego/v2/client/orm" @@ -22,19 +22,19 @@ func PayForFail(ctx context.Context, p payfor.PayforInfo) bool { "select * from payfor_info where bank_order_id = ? for update", p.BankOrderId). QueryRow(&tmpForPay); err != nil || tmpForPay.PayforUid == "" { - otel.Logger.WithContext(ctx).Error("solve pay fail select fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("solve pay fail select fail:", zap.Error(err)) return err } if tmpForPay.Status == config.PAYFOR_FAIL || tmpForPay.Status == config.PAYFOR_SUCCESS { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("该代付订单uid=%s,状态已经是最终结果", tmpForPay.PayforUid)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("该代付订单uid=%s,状态已经是最终结果", tmpForPay.PayforUid)) return errors.New("状态已经是最终结果") } // 更新payfor记录的状态 tmpForPay.Status = config.PAYFOR_FAIL tmpForPay.UpdateTime = time.Now() if _, err := txOrm.Update(&tmpForPay); err != nil { - otel.Logger.WithContext(ctx).Error("PayForFail update payfor_info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("PayForFail update payfor_info fail: ", zap.Error(err)) return err } @@ -44,20 +44,20 @@ func PayForFail(ctx context.Context, p payfor.PayforInfo) bool { tmpForPay.MerchantUid). QueryRow(&account); err != nil || account.AccountUid == "" { - otel.Logger.WithContext(ctx).Error("payfor select account fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("payfor select account fail:", zap.Error(err)) return err } account.UpdateTime = time.Now() if account.PayforAmount < tmpForPay.PayforTotalAmount { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=%s,账户中待代付金额小于代付记录的金额", tmpForPay.MerchantUid)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=%s,账户中待代付金额小于代付记录的金额", tmpForPay.MerchantUid)) return errors.New("账户中待代付金额小于代付记录的金额") } // 将正在打款中的金额减去 account.PayforAmount = account.PayforAmount - tmpForPay.PayforTotalAmount if _, err := txOrm.Update(&account); err != nil { - otel.Logger.WithContext(ctx).Error("PayForFail update account fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("PayForFail update account fail: ", zap.Error(err)) return err } @@ -76,11 +76,11 @@ func PayForSuccess(ctx context.Context, p payfor.PayforInfo) bool { if err := txOrm.RawWithCtx(ctx, "select * from payfor_info where bank_order_id = ? for update", p.BankOrderId). QueryRow(&tmpPayFor); err != nil || tmpPayFor.PayforUid == "" { - otel.Logger.WithContext(ctx).Error("payfor success select payfor fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("payfor success select payfor fail:", zap.Error(err)) return err } if tmpPayFor.Status == config.PAYFOR_FAIL || tmpPayFor.Status == config.PAYFOR_SUCCESS { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("该代付订单uid=#{payFor.PayforUid},已经是最终结果,不需要处理")) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("该代付订单uid=#{payFor.PayforUid},已经是最终结果,不需要处理")) return errors.New("已经是最终结果,不需要处理") } @@ -88,7 +88,7 @@ func PayForSuccess(ctx context.Context, p payfor.PayforInfo) bool { tmpPayFor.Status = config.PAYFOR_SUCCESS _, err := txOrm.Update(&tmpPayFor) if err != nil { - otel.Logger.WithContext(ctx).Error("PayForSuccess update payfor fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("PayForSuccess update payfor fail: ", zap.Error(err)) return err } @@ -96,13 +96,13 @@ func PayForSuccess(ctx context.Context, p payfor.PayforInfo) bool { if err := txOrm.RawWithCtx(ctx, "select * from account_info where account_uid = ? for update", tmpPayFor.MerchantUid). QueryRow(&account); err != nil || account.AccountUid == "" { - otel.Logger.WithContext(ctx).Error("payfor success select account fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("payfor success select account fail:", zap.Error(err)) return err } account.UpdateTime = time.Now() if account.PayforAmount < tmpPayFor.PayforTotalAmount { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=#{payFor.MerchantUid},账户中待代付金额小于代付记录的金额")) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=#{payFor.MerchantUid},账户中待代付金额小于代付记录的金额")) return errors.New("账户中待代付金额小于代付记录的金额") } @@ -114,7 +114,7 @@ func PayForSuccess(ctx context.Context, p payfor.PayforInfo) bool { account.SettleAmount = account.SettleAmount - tmpPayFor.PayforTotalAmount if _, err := txOrm.Update(&account); err != nil { - otel.Logger.WithContext(ctx).Error("PayForSuccess update account fail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("PayForSuccess update account fail:", zap.Error(err)) return err } @@ -131,7 +131,7 @@ func PayForSuccess(ctx context.Context, p payfor.PayforInfo) bool { } if _, err := txOrm.Insert(&accountHistory); err != nil { - otel.Logger.WithContext(ctx).Error("PayForSuccess insert account history fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("PayForSuccess insert account history fail: ", zap.Error(err)) return err } diff --git a/internal/service/pay_service.go b/internal/service/pay_service.go index 26f0f98..c59a097 100644 --- a/internal/service/pay_service.go +++ b/internal/service/pay_service.go @@ -5,7 +5,8 @@ import ( "errors" "fmt" "gateway/internal/config" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service/supplier" "gateway/internal/models/merchant" @@ -87,7 +88,7 @@ func RoadIsValid(ctx context.Context, roadInfo road.RoadInfo, c *response.PayBas return "当前未处在交易区间内", false } if roadInfo.SingleMinLimit > c.OrderAmount || roadInfo.SingleMaxLimit < c.OrderAmount { - otel.Logger.WithContext(ctx).Error(FORMAT + "订单金额超限制") + otelTrace.Logger.WithContext(ctx).Error(FORMAT + "订单金额超限制") return "订单金额超过交易限制", false } todayLimit := roadInfo.TodayLimit @@ -95,11 +96,11 @@ func RoadIsValid(ctx context.Context, roadInfo road.RoadInfo, c *response.PayBas todayIncome := roadInfo.TodayIncome totalIncome := roadInfo.TotalIncome if (todayIncome + c.OrderAmount) > todayLimit { - otel.Logger.WithContext(ctx).Error(FORMAT + "达到了每天金额上限") + otelTrace.Logger.WithContext(ctx).Error(FORMAT + "达到了每天金额上限") return "订单金额超过金额限制", false } if (totalIncome + c.OrderAmount) > totalLimit { - otel.Logger.WithContext(ctx).Error(FORMAT + "达到了总量限制") + otelTrace.Logger.WithContext(ctx).Error(FORMAT + "达到了总量限制") return "订单金额达到总量限制", false } // 如果通道被选中,那么总请求数+1 @@ -199,7 +200,7 @@ func GenerateOrderProfit(ctx context.Context, orderInfo order.OrderInfo, c *resp allProfit := supplierProfit.Add(platformProfit).Add(agentProfit) if allProfit.GreaterThanOrEqual(decimal.NewFromFloat(orderInfo.OrderAmount)) { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("手续费已经超过订单金额,bankOrderId = %s", orderInfo.BankOrderId)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("手续费已经超过订单金额,bankOrderId = %s", orderInfo.BankOrderId)) c.Msg = "手续费已经超过了订单金额" c.Code = -1 } @@ -263,7 +264,7 @@ func CreateOrderProfitInfo(ctx context.Context, createdOrder request.CreatedOrde allProfit := supplierProfit.Add(platformProfit).Add(agentProfit) if allProfit.GreaterThanOrEqual(decimal.NewFromFloat(orderInfo.OrderAmount)) { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("手续费已经超过订单金额,bankOrderId = %s", orderInfo.BankOrderId)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("手续费已经超过订单金额,bankOrderId = %s", orderInfo.BankOrderId)) err = errors.New("手续费已经超过订单金额") return } @@ -314,7 +315,7 @@ func GenerateRecord(ctx context.Context, c *response.PayBaseResp) (order.OrderIn } orderInfo = order.GetOrderByMerchantOrderId(ctx, convertor.ToString(c.Params["orderNo"])) orderProfitInfo = order.GetOrderProfitByBankOrderId(ctx, orderProfitInfo.BankOrderId) - otel.Logger.WithContext(ctx).Info("插入支付订单记录和支付利润记录成功") + otelTrace.Logger.WithContext(ctx).Info("插入支付订单记录和支付利润记录成功") return orderInfo, orderProfit, nil } if orderInfo.Status != config.Created { @@ -339,7 +340,7 @@ func GenerateRecord(ctx context.Context, c *response.PayBaseResp) (order.OrderIn } orderInfo = order.GetOrderByMerchantOrderId(ctx, convertor.ToString(c.Params["orderNo"])) orderProfitInfo = order.GetOrderProfitByBankOrderId(ctx, orderProfitInfo.BankOrderId) - otel.Logger.WithContext(ctx).Info("插入支付订单记录和支付利润记录成功") + otelTrace.Logger.WithContext(ctx).Info("插入支付订单记录和支付利润记录成功") return orderInfo, orderProfitInfo, nil } diff --git a/internal/service/pay_solve.go b/internal/service/pay_solve.go index 9c4356c..e57b0f7 100644 --- a/internal/service/pay_solve.go +++ b/internal/service/pay_solve.go @@ -11,7 +11,7 @@ import ( "gateway/internal/models/notify" "gateway/internal/models/order" "gateway/internal/models/road" - "gateway/internal/otel" + "gateway/internal/otelTrace" "gateway/internal/service/message" "gateway/internal/utils" "net/url" @@ -35,7 +35,7 @@ var ( // SolvePaySuccess 处理支付成功的加款等各项操作 func SolvePaySuccess(ctx context.Context, bankOrderId string, factAmount float64, trxNo string, cardReturnData string) bool { - ctx, cancel := otel.Span(ctx, "订单处理", "SolvePayFail", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "订单处理", "SolvePayFail", trace.WithAttributes( attribute.String("bankOrderId", bankOrderId), attribute.String("cardReturnData", cardReturnData), )) @@ -46,11 +46,11 @@ func SolvePaySuccess(ctx context.Context, bankOrderId string, factAmount float64 var orderInfo order.OrderInfo if err := txOrm.RawWithCtx(ctx, "select * from order_info where bank_order_id = ? for update", bankOrderId). QueryRow(&orderInfo); err != nil || orderInfo.BankOrderId == "" { - otel.Logger.WithContext(ctx).Error("不存在该订单,或者select for update出错") + otelTrace.Logger.WithContext(ctx).Error("不存在该订单,或者select for update出错") return err } if orderInfo.Status == config.SUCCESS { - otel.Logger.WithContext(ctx).Error("该订单已经处理,订单号=", zap.String("bankOrderId", bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error("该订单已经处理,订单号=", zap.String("bankOrderId", bankOrderId)) return errors.New(fmt.Sprintf("该订单已经处理,订单号= %s", bankOrderId)) } orderInfo.FactAmount = factAmount @@ -59,7 +59,7 @@ func SolvePaySuccess(ctx context.Context, bankOrderId string, factAmount float64 orderInfo.CardReturnData = cardReturnData orderInfo.UpdateTime = time.Now() if _, err := txOrm.UpdateWithCtx(ctx, &orderInfo); err != nil || orderInfo.BankOrderId == "" { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, update order info fail: %s, bankOrderId = %s", err, bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, update order info fail: %s, bankOrderId = %s", err, bankOrderId)) return err } @@ -67,7 +67,7 @@ func SolvePaySuccess(ctx context.Context, bankOrderId string, factAmount float64 if !pointer.IsNil(record) && record.Id != 0 { // TODO: 判断是否偷卡(隐藏订单) if err2 := UpdateRelateRecordSucceedStatus(ctx, bankOrderId, factAmount); err2 != nil { - otel.Logger.WithContext(ctx).Error("【偷卡】更新偷卡记录失败", zap.Error(err2)) + otelTrace.Logger.WithContext(ctx).Error("【偷卡】更新偷卡记录失败", zap.Error(err2)) } return nil } @@ -78,11 +78,11 @@ func SolvePaySuccess(ctx context.Context, bankOrderId string, factAmount float64 "select * from order_profit_info where bank_order_id = ? for update", bankOrderId, ).QueryRow(&orderProfitInfo); err != nil || orderProfitInfo.BankOrderId == "" { - otel.Logger.WithContext(ctx).Error("select order_profit_info for update fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("select order_profit_info for update fail: ", zap.Error(err)) return err } if orderProfitInfo.BankOrderId == "" { - otel.Logger.WithContext(ctx).Error("solve pay success, get orderProfit fail, bankOrderId = ", zap.String("bankOrderId", bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error("solve pay success, get orderProfit fail, bankOrderId = ", zap.String("bankOrderId", bankOrderId)) return errors.New(fmt.Sprintf("solve pay success, get orderProfit fail, bankOrderId = %s", bankOrderId)) } @@ -103,7 +103,7 @@ func SolvePaySuccess(ctx context.Context, bankOrderId string, factAmount float64 UpdateTime: time.Now(), } if _, err := txOrm.InsertWithCtx(ctx, &orderSettleInfo); err != nil { - otel.Logger.WithContext(ctx).Error( + otelTrace.Logger.WithContext(ctx).Error( fmt.Sprintf("solve pay success,insert order settle info fail: %s, bankOrderId = %s", err, bankOrderId), ) @@ -112,7 +112,7 @@ func SolvePaySuccess(ctx context.Context, bankOrderId string, factAmount float64 // 做账户的加款操作,最重要的一步 var accountInfo accounts.AccountInfo if err := txOrm.RawWithCtx(ctx, "select * from account_info where account_uid = ? for update", orderInfo.MerchantUid).QueryRow(&accountInfo); err != nil || accountInfo.AccountUid == "" { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, raw account info fail: %s, bankOrderId = %s", err, bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, raw account info fail: %s, bankOrderId = %s", err, bankOrderId)) return err } if _, err := txOrm.QueryTable(accounts.ACCOUNT_INFO).Filter("account_uid", orderInfo.MerchantUid). @@ -120,7 +120,7 @@ func SolvePaySuccess(ctx context.Context, bankOrderId string, factAmount float64 "balance": factAmount + accountInfo.Balance, "wait_amount": factAmount + accountInfo.WaitAmount, }); err != nil { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, update account info fail: %s, bankOrderId = %s", err, bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, update account info fail: %s, bankOrderId = %s", err, bankOrderId)) return err } // 添加一条动账记录 @@ -135,7 +135,7 @@ func SolvePaySuccess(ctx context.Context, bankOrderId string, factAmount float64 UpdateTime: time.Now(), } if _, err := txOrm.InsertWithCtx(ctx, &accountHistory); err != nil { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success,insert account history fail:%s, bankOrderId = %s", err, bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success,insert account history fail:%s, bankOrderId = %s", err, bankOrderId)) return err } // 更新通道信息 @@ -149,14 +149,14 @@ func SolvePaySuccess(ctx context.Context, bankOrderId string, factAmount float64 roadInfo.TotalProfit += orderProfitInfo.PlatformProfit + orderProfitInfo.AgentProfit roadInfo.UpdateTime = time.Now() if _, err := txOrm.UpdateWithCtx(ctx, &roadInfo); err != nil { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, update road info fail: %s, bankOrderId = %s", err, bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, update road info fail: %s, bankOrderId = %s", err, bankOrderId)) return err } // 更新订单利润表 orderProfitInfo.Status = config.SUCCESS orderProfitInfo.UpdateTime = time.Now() if _, err := txOrm.UpdateWithCtx(ctx, &orderProfitInfo); err != nil { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, update order profit info fail: %s, bankOrderId = %s", err, bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, update order profit info fail: %s, bankOrderId = %s", err, bankOrderId)) return err } // 给下游发送回调通知 @@ -164,22 +164,22 @@ func SolvePaySuccess(ctx context.Context, bankOrderId string, factAmount float64 }) orderNotify.Go(func() { // 创建一个5分钟超时的上下文 - timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Minute) - defer cancel() - CreateOrderNotifyInfo(timeoutCtx, bankOrderId, config.SUCCESS) + ctx2, span := otelTrace.NewSchedulerTrace().Start(otelTrace.InitCtx, "SolvePaySuccess") + defer span.End() + CreateOrderNotifyInfo(ctx2, bankOrderId, config.SUCCESS) }) if err != nil { - otel.Logger.WithContext(ctx).Error("SolvePaySuccess失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("SolvePaySuccess失败:", zap.Error(err)) return true } - otel.Logger.WithContext(ctx).Info("SolvePaySuccess处理成功") + otelTrace.Logger.WithContext(ctx).Info("SolvePaySuccess处理成功") return true } // SolvePayFail 处理支付失败 func SolvePayFail(ctx context.Context, bankOrderId, transId string, cardReturnData string) bool { - ctx, cancel := otel.Span(ctx, "订单处理", "SolvePayFail", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "订单处理", "SolvePayFail", trace.WithAttributes( attribute.String("bankOrderId", bankOrderId), attribute.String("cardReturnData", cardReturnData), )) @@ -199,11 +199,11 @@ func SolvePayFail(ctx context.Context, bankOrderId, transId string, cardReturnDa "card_return_data": cardReturnData, "bank_trans_id": transId, }); err != nil { - otel.Logger.WithContext(ctx).Error("更改订单状态失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("更改订单状态失败:", zap.Error(err)) return err } if _, err := txOrm.QueryTable(order.ORDER_PROFIT_INFO).Filter("bank_order_id", bankOrderId).UpdateWithCtx(ctx, orm.Params{"status": config.FAIL, "bank_trans_id": transId}); err != nil { - otel.Logger.WithContext(ctx).Error("更改订单状态失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("更改订单状态失败:", zap.Error(err)) return err } @@ -218,14 +218,14 @@ func SolvePayFail(ctx context.Context, bankOrderId, transId string, cardReturnDa }) orderNotify.Go(func() { // 创建一个5分钟超时的上下文 - timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Minute) - defer cancel() - CreateOrderNotifyInfo(timeoutCtx, bankOrderId, config.FAIL) + ctx2, span := otelTrace.NewSchedulerTrace().Start(otelTrace.InitCtx, "SolvePayFail") + defer span.End() + CreateOrderNotifyInfo(ctx2, bankOrderId, config.FAIL) }) if err != nil { - otel.Logger.WithContext(ctx).Error("SolvePayFail:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("SolvePayFail:", zap.Error(err)) } - otel.Logger.WithContext(ctx).Info("SolvePayFail成功") + otelTrace.Logger.WithContext(ctx).Info("SolvePayFail成功") return true } @@ -236,13 +236,13 @@ func SolveOrderFreeze(ctx context.Context, bankOrderId string) bool { err := o.DoTxWithCtx(ctx, func(ctx context.Context, txOrm orm.TxOrmer) error { var orderInfo order.OrderInfo if err := txOrm.Raw("select * from order_info where bank_order_id = ? for update", bankOrderId).QueryRow(&orderInfo); err != nil || orderInfo.BankOrderId == "" { - otel.Logger.WithContext(ctx).Error("solve order freeze 不存在这样的订单记录,bankOrderId = ", zap.String("bankOrderId", bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error("solve order freeze 不存在这样的订单记录,bankOrderId = ", zap.String("bankOrderId", bankOrderId)) return err } // 如果订单不是失败或者成功状态,订单不能冻结 if orderInfo.Status != config.SUCCESS && orderInfo.Status != config.FAIL { - otel.Logger.WithContext(ctx).Error("非成功或失败订单不能进行冻结") + otelTrace.Logger.WithContext(ctx).Error("非成功或失败订单不能进行冻结") return errors.New("非成功或失败订单不能进行冻结") } @@ -251,7 +251,7 @@ func SolveOrderFreeze(ctx context.Context, bankOrderId string) bool { orderInfo.UpdateTime = time.Now() if _, err := txOrm.Update(&orderInfo); err != nil { - otel.Logger.WithContext(ctx).Error("solve order freeze fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("solve order freeze fail: ", zap.Error(err)) return err } @@ -260,14 +260,14 @@ func SolveOrderFreeze(ctx context.Context, bankOrderId string) bool { var accountInfo accounts.AccountInfo if err := txOrm.Raw("select * from account_info where account_uid = ? for update", orderInfo.MerchantUid).QueryRow(&accountInfo); err != nil || accountInfo.AccountUid == "" { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay fail select acount fail:%s", err)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay fail select acount fail:%s", err)) return err } accountInfo.UpdateTime = time.Now() accountInfo.FreezeAmount = orderProfitInfo.UserInAmount + accountInfo.FreezeAmount if _, err := txOrm.Update(&accountInfo); err != nil { - otel.Logger.WithContext(ctx).Error("solve order freeze fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("solve order freeze fail: ", zap.Error(err)) return err } @@ -284,18 +284,18 @@ func SolveOrderFreeze(ctx context.Context, bankOrderId string) bool { } if _, err := txOrm.Insert(&accountHistoryInfo); err != nil { - otel.Logger.WithContext(ctx).Error("solve order freeze fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("solve order freeze fail: ", zap.Error(err)) return err } return nil }) if err != nil { - otel.Logger.WithContext(ctx).Error("SolveOrderFreeze:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("SolveOrderFreeze:", zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("SolveOrderFreeze") + otelTrace.Logger.WithContext(ctx).Info("SolveOrderFreeze") return true } @@ -307,7 +307,7 @@ func SolveOrderUnfreeze(ctx context.Context, bankOrderId string) bool { if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error { orderInfo := new(order.OrderInfo) if err := txOrm.Raw("select * from order_info where bank_order_id = ? for update", bankOrderId).QueryRow(orderInfo); err != nil || orderInfo.BankOrderId == "" { - otel.Logger.WithContext(ctx).Error("solve order unfreeze 不存在这样的订单记录,bankOrderId = ", zap.String("bankOrderId", bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error("solve order unfreeze 不存在这样的订单记录,bankOrderId = ", zap.String("bankOrderId", bankOrderId)) return err } @@ -316,7 +316,7 @@ func SolveOrderUnfreeze(ctx context.Context, bankOrderId string) bool { orderInfo.UnfreezeTime = utils.GetBasicDateTime() orderInfo.UpdateTime = time.Now() if _, err := txOrm.Update(orderInfo); err != nil { - otel.Logger.WithContext(ctx).Error("solve order unfreeze fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("solve order unfreeze fail: ", zap.Error(err)) return err } @@ -324,14 +324,14 @@ func SolveOrderUnfreeze(ctx context.Context, bankOrderId string) bool { accountInfo := new(accounts.AccountInfo) if err := txOrm.Raw("select * from account_info where account_uid = ? for update", orderInfo.MerchantUid).QueryRow(accountInfo); err != nil || accountInfo.AccountUid == "" { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("unfreeze select account fail: %s", err)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("unfreeze select account fail: %s", err)) return err } accountInfo.UpdateTime = time.Now() accountInfo.FreezeAmount = accountInfo.FreezeAmount - orderProfitInfo.UserInAmount if _, err := txOrm.Update(accountInfo); err != nil { - otel.Logger.WithContext(ctx).Error("solve order unfreeze fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("solve order unfreeze fail: ", zap.Error(err)) return err } @@ -352,7 +352,7 @@ func SolveOrderUnfreeze(ctx context.Context, bankOrderId string) bool { return nil }); err != nil { - otel.Logger.WithContext(ctx).Error("SolveOrderUnfreeze失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("SolveOrderUnfreeze失败:", zap.Error(err)) return false } @@ -364,7 +364,7 @@ func SolveRefund(ctx context.Context, bankOrderId string) bool { if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error { orderInfo := new(order.OrderInfo) if err := txOrm.Raw("select * from order_info where bank_order_id = ? for update", bankOrderId).QueryRow(orderInfo); err != nil || orderInfo.BankOrderId == "" { - otel.Logger.WithContext(ctx).Error("solve refund 不存在这样的订单,bankOrderId = " + bankOrderId) + otelTrace.Logger.WithContext(ctx).Error("solve refund 不存在这样的订单,bankOrderId = " + bankOrderId) return err } @@ -391,11 +391,11 @@ func SolveRefund(ctx context.Context, bankOrderId string) bool { } if _, err := txOrm.Update(orderInfo); err != nil { - otel.Logger.WithContext(ctx).Error("solve order refund update order info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("solve order refund update order info fail: ", zap.Error(err)) return err } if _, err := txOrm.Update(account); err != nil { - otel.Logger.WithContext(ctx).Error("solve order refund update account fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("solve order refund update account fail: ", zap.Error(err)) return err } @@ -411,13 +411,13 @@ func SolveRefund(ctx context.Context, bankOrderId string) bool { } if _, err := txOrm.Insert(&accountHistoryInfo); err != nil { - otel.Logger.WithContext(ctx).Error("solve order refund insert account history fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("solve order refund insert account history fail: ", zap.Error(err)) return err } return nil }); err != nil { - otel.Logger.WithContext(ctx).Error("SolveRefund 成功:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("SolveRefund 成功:", zap.Error(err)) return false } return true @@ -429,12 +429,12 @@ func SolveOrderRoll(ctx context.Context, bankOrderId string) bool { orderInfo := new(order.OrderInfo) if err := txOrm.Raw("select * from order_info where bank_order_id = ? for update", bankOrderId).QueryRow(orderInfo); err != nil { - otel.Logger.WithContext(ctx).Error("solve order roll fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("solve order roll fail: ", zap.Error(err)) return err } if orderInfo.Status != config.SUCCESS { - otel.Logger.WithContext(ctx).Error("solve order roll 订单不存在或者订单状态不是success, bankOrderId=", zap.String("bankOrderId", bankOrderId)) + otelTrace.Logger.WithContext(ctx).Error("solve order roll 订单不存在或者订单状态不是success, bankOrderId=", zap.String("bankOrderId", bankOrderId)) return errors.New("solve order roll failed") } orderInfo.UpdateTime = time.Now() @@ -454,11 +454,11 @@ func SolveOrderRoll(ctx context.Context, bankOrderId string) bool { } if _, err := txOrm.Update(orderInfo); err != nil { - otel.Logger.WithContext(ctx).Error("solve order roll fail update order info fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("solve order roll fail update order info fail: ", zap.Error(err)) return err } if _, err := txOrm.Update(account); err != nil { - otel.Logger.WithContext(ctx).Error("solve order roll update account fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("solve order roll update account fail: ", zap.Error(err)) return err } @@ -474,13 +474,13 @@ func SolveOrderRoll(ctx context.Context, bankOrderId string) bool { } if _, err := txOrm.Insert(&accountHistoryInfo); err != nil { - otel.Logger.WithContext(ctx).Error("solve order roll insert account history fail: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("solve order roll insert account history fail: ", zap.Error(err)) return err } return nil }); err != nil { - otel.Logger.WithContext(ctx).Error("SolveOrderRoll处理失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("SolveOrderRoll处理失败:", zap.Error(err)) return false } @@ -539,15 +539,15 @@ func CreateOrderNotifyInfo(ctx context.Context, bankOrderId string, tradeStatus UpdateTime: time.Now(), Url: orderInfo.NotifyUrl + "?" + u.Encode(), }) { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("订单bankOrderId=%s,已经将回调地址插入数据库", orderInfo.BankOrderId)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("订单bankOrderId=%s,已经将回调地址插入数据库", orderInfo.BankOrderId)) } else { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("订单bankOrderId=%s,插入回调数据库失败", orderInfo.BankOrderId)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("订单bankOrderId=%s,插入回调数据库失败", orderInfo.BankOrderId)) } // 将订单发送到消息队列,给下面的商户进行回调 - sendMessageNotify.CtxGo(ctx, func() { + sendMessageNotify.Go(func() { // 创建一个5分钟超时的上下文 - timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Minute) - defer cancel() - message.SendMessage(timeoutCtx, config.MqOrderNotify, orderInfo.BankOrderId) + ctx2, span := otelTrace.NewSchedulerTrace().Start(otelTrace.InitCtx, "CreateOrderNotifyInfo") + defer span.End() + message.SendMessage(ctx2, config.MqOrderNotify, orderInfo.BankOrderId) }) } diff --git a/internal/service/settle_service.go b/internal/service/settle_service.go index c4d56ef..6fc937a 100644 --- a/internal/service/settle_service.go +++ b/internal/service/settle_service.go @@ -9,7 +9,8 @@ import ( "gateway/internal/models/merchant" "gateway/internal/models/merchant_deploy" "gateway/internal/models/order" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/utils" "time" @@ -31,9 +32,9 @@ func OrderSettle(ctx context.Context) { for _, orderSettle := range orderSettleList { orderProfitInfo := order.GetOrderProfitByBankOrderId(ctx, orderSettle.BankOrderId) if !settle(ctx, orderSettle, orderProfitInfo) { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("结算订单bankOrderId = #{orderSettle.BankOrderId}, 执行失败")) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("结算订单bankOrderId = #{orderSettle.BankOrderId}, 执行失败")) } else { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("结算订单bankOrderId= #{orderSettle.BankOrderId},执行成功")) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("结算订单bankOrderId= #{orderSettle.BankOrderId},执行成功")) } } } @@ -44,21 +45,21 @@ func settle(ctx context.Context, orderSettle order.OrderSettleInfo, orderProfit if err := o.DoTxWithCtx(ctx, func(ctx context.Context, txOrm orm.TxOrmer) error { tmpSettle := new(order.OrderSettleInfo) if err := txOrm.RawWithCtx(ctx, "select * from order_settle_info where bank_order_id=? for update", orderSettle.BankOrderId).QueryRow(tmpSettle); err != nil || tmpSettle.BankOrderId == "" { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("获取tmpSettle失败,bankOrderId=%s", orderSettle.BankOrderId), zap.String("BankOrderId", orderSettle.BankOrderId)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("获取tmpSettle失败,bankOrderId=%s", orderSettle.BankOrderId), zap.String("BankOrderId", orderSettle.BankOrderId)) return err } tmpSettle.UpdateTime = time.Now() tmpSettle.IsCompleteSettle = config.YES if _, err := txOrm.UpdateWithCtx(ctx, tmpSettle); err != nil { - otel.Logger.WithContext(ctx).Error("更新tmpSettle失败,错误:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("更新tmpSettle失败,错误:", zap.Error(err)) return err } accountInfo := new(accounts.AccountInfo) if err := txOrm.RawWithCtx(ctx, "select * from account_info where account_uid= ? for update", orderSettle.MerchantUid). QueryRow(accountInfo); err != nil || accountInfo.UpdateTime.IsZero() { - otel.Logger.WithContext(ctx).Error("结算select account info失败,错误信息:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("结算select account info失败,错误信息:", zap.Error(err)) return err } accountInfo.UpdateTime = time.Now() @@ -89,32 +90,32 @@ func settle(ctx context.Context, orderSettle order.OrderSettleInfo, orderProfit } if _, err := txOrm.Insert(&tmp); err != nil { - otel.Logger.WithContext(ctx).Error("結算插入merchantLoad失敗,失败信息:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("結算插入merchantLoad失敗,失败信息:", zap.Error(err)) return err } else { - otel.Logger.WithContext(ctx).Info("结算插入新的merchantLoad信息成功") + otelTrace.Logger.WithContext(ctx).Info("结算插入新的merchantLoad信息成功") } } else { merchantLoad := new(merchant.MerchantLoadInfo) if err := txOrm.RawWithCtx(ctx, "select * from merchant_load_info where merchant_uid=? and road_uid=? and load_date=? for update", orderSettle.MerchantUid, orderSettle.RoadUid, date). QueryRow(merchantLoad); err != nil || merchantLoad.UpdateTime.IsZero() { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("结算过程,select merchant load info失败,错误信息:%s", zap.Error(err))) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("结算过程,select merchant load info失败,错误信息:%s", zap.Error(err))) return err } else { merchantLoad.UpdateTime = time.Now() merchantLoad.LoadAmount += loadAmount if _, err := txOrm.UpdateWithCtx(ctx, merchantLoad); err != nil { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("结算过程,update merchant load info失败,失败信息:%s", zap.Error(err))) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("结算过程,update merchant load info失败,失败信息:%s", zap.Error(err))) return err } } } } else { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("结算过程中,该商户不需要押款,全款结算")) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("结算过程中,该商户不需要押款,全款结算")) } if accountInfo.WaitAmount < orderProfit.UserInAmount { - otel.Logger.WithContext(ctx).Error("系统出现严重故障,账户的带结算金额小于订单结算金额") + otelTrace.Logger.WithContext(ctx).Error("系统出现严重故障,账户的带结算金额小于订单结算金额") return errors.New("系统出现严重故障,账户的带结算金额小于订单结算金额, 账户 = " + accountInfo.AccountName + "订单id = " + orderProfit.BankOrderId) } @@ -125,7 +126,7 @@ func settle(ctx context.Context, orderSettle order.OrderSettleInfo, orderProfit accountInfo.LoanAmount = accountInfo.LoanAmount + loadAmount if _, err := txOrm.UpdateWithCtx(ctx, accountInfo); err != nil { - otel.Logger.WithContext(ctx).Error("结算update account 失败,错误信息:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("结算update account 失败,错误信息:", zap.Error(err)) return err } @@ -141,7 +142,7 @@ func MerchantLoadSolve(ctx context.Context) { hour := time.Now().Hour() merchantDeployList := merchant_deploy.GetMerchantDeployByHour(ctx, hour) for _, merchantDeploy := range merchantDeployList { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("开始执行商户uid=%s,进行解款操作", merchantDeploy.MerchantUid)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("开始执行商户uid=%s,进行解款操作", merchantDeploy.MerchantUid)) loadDate := utils.GetDateBeforeDays(merchantDeploy.LoanDays) params := make(map[string]string) @@ -152,10 +153,10 @@ func MerchantLoadSolve(ctx context.Context) { merchantLoadList := merchant.GetMerchantLoadInfoByMap(ctx, params) for _, merchantLoad := range merchantLoadList { if MerchantAbleAmount(ctx, merchantLoad) { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("商户uid=%s,押款金额=%f,押款通道= %s, 解款成功", + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("商户uid=%s,押款金额=%f,押款通道= %s, 解款成功", merchantLoad.MerchantUid, merchantLoad.LoadAmount, merchantLoad.RoadUid)) } else { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=%s,押款金额=%f,押款通道=%s, 解款失败", + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=%s,押款金额=%f,押款通道=%s, 解款失败", merchantLoad.MerchantUid, merchantLoad.LoadAmount, merchantLoad.RoadUid)) } } @@ -171,25 +172,25 @@ func MerchantAbleAmount(ctx context.Context, merchantLoad merchant.MerchantLoadI if err := txOrm.Raw("select * from merchant_load_info where merchant_uid=? and road_uid=? and load_date=? for update", merchantLoad.MerchantUid, merchantLoad.RoadUid, merchantLoad.LoadDate). QueryRow(tmpLoad); err != nil || tmpLoad.MerchantUid == "" { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("解款操作获取商户押款信息失败,fail: %s", zap.Error(err))) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("解款操作获取商户押款信息失败,fail: %s", zap.Error(err))) return err } if tmpLoad.Status != config.NO { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("押款信息merchantuid=%s,通道uid=%s, 押款日期=%s,已经解款过,不需要再进行处理了", tmpLoad.MerchantUid, tmpLoad.RoadUid, tmpLoad.LoadDate)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("押款信息merchantuid=%s,通道uid=%s, 押款日期=%s,已经解款过,不需要再进行处理了", tmpLoad.MerchantUid, tmpLoad.RoadUid, tmpLoad.LoadDate)) return errors.New("已经解款过,不需要再进行处理了") } tmpLoad.UpdateTime = time.Now() tmpLoad.Status = config.YES if _, err := txOrm.Update(tmpLoad); err != nil { - otel.Logger.WithContext(ctx).Error("解款操作更新merchant load info 失败", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("解款操作更新merchant load info 失败", zap.Error(err)) return err } accountInfo := new(accounts.AccountInfo) if err := txOrm.Raw("select * from account_info where account_uid = ? for update", merchantLoad.MerchantUid). QueryRow(accountInfo); err != nil || accountInfo.AccountUid == "" { - otel.Logger.WithContext(ctx).Error("结款操作获取账户信息失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("结款操作获取账户信息失败:", zap.Error(err)) return err } accountInfo.UpdateTime = time.Now() @@ -201,7 +202,7 @@ func MerchantAbleAmount(ctx context.Context, merchantLoad merchant.MerchantLoadI } if _, err := txOrm.Update(accountInfo); err != nil { - otel.Logger.WithContext(ctx).Error(fmt.Sprintf("解款操作更新account info 失败:%s,账户uid=%s", err, accountInfo.AccountUid)) + otelTrace.Logger.WithContext(ctx).Error(fmt.Sprintf("解款操作更新account info 失败:%s,账户uid=%s", err, accountInfo.AccountUid)) return err } @@ -213,7 +214,7 @@ func MerchantAbleAmount(ctx context.Context, merchantLoad merchant.MerchantLoadI } func OrderSettleInit(ctx context.Context) { - ctx, cancel := otel.Span(ctx, "OrderSettleInit", "OrderSettleInit") + ctx, cancel := otelTrace.Span(ctx, "OrderSettleInit", "OrderSettleInit") defer cancel() // 每隔5分钟,巡查有没有可以进行结算的订单 settleTimer := time.NewTimer(time.Duration(Interval) * time.Minute) diff --git a/internal/service/supplier/third_party/apple.go b/internal/service/supplier/third_party/apple.go index 57dbc7f..3515f6d 100644 --- a/internal/service/supplier/third_party/apple.go +++ b/internal/service/supplier/third_party/apple.go @@ -12,7 +12,8 @@ import ( "gateway/internal/models/payfor" "gateway/internal/models/road" "gateway/internal/models/supply_model" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service" "gateway/internal/service/supplier" "gateway/internal/utils" @@ -98,22 +99,22 @@ func (c *AppleCardImpl) SendCard(ctx context.Context, jsonStr string, cardInfo s req.Retries(3) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) return false, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") req.Header("tokenFrom", "iframe") response, err := req.String() - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if err != nil { - otel.Logger.WithContext(ctx).Error("Apple GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Apple GetToken 请求失败:", zap.Error(err)) return false, "" } if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return false, "" } type AutoGenerated struct { @@ -127,7 +128,7 @@ func (c *AppleCardImpl) SendCard(ctx context.Context, jsonStr string, cardInfo s var resData AutoGenerated err = json.Unmarshal([]byte(response), &resData) if err != nil { - otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response)) + otelTrace.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response)) return false, "内部数据处理失败" } @@ -150,7 +151,7 @@ func (c *AppleCardImpl) SendCard(ctx context.Context, jsonStr string, cardInfo s } func (c *AppleCardImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData { - ctx, cancel := otel.Span(ctx, "AppleCardImpl", "Scan", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "AppleCardImpl", "Scan", trace.WithAttributes( attribute.String("BankOrderId", orderInfo.BankOrderId), attribute.String("MerchantUid", orderInfo.MerchantUid), attribute.String("ExValue", orderInfo.ExValue), @@ -159,7 +160,7 @@ func (c *AppleCardImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roa cdata := supplier.RedeemCardInfo{} err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata) if err != nil { - otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) + otelTrace.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"} } ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo.BankOrderId, orderInfo.MerchantOrderId) @@ -188,7 +189,7 @@ func (c *AppleCardImpl) kMEncrypt(kf, appSecret string) (string, error) { secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥 block, err := aes.NewCipher([]byte(secret)) if err != nil { - otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher") + otelTrace.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher") return "", err } // 数据填充 @@ -204,7 +205,7 @@ func (c *AppleCardImpl) PayNotify() { attach := strings.TrimSpace(c.GetString("attach")) orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 { - otel.Logger.WithContext(ctx).Error("【APPLE】回调的订单号不存在,订单号=", zap.String("attach", attach)) + otelTrace.Logger.WithContext(ctx).Error("【APPLE】回调的订单号不存在,订单号=", zap.String("attach", attach)) c.Ctx.WriteString("FAIL") return } @@ -261,23 +262,23 @@ func (c *AppleCardImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadIn req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -326,12 +327,12 @@ func (c *AppleCardImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Road req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return supply_model.DataErr } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") @@ -341,7 +342,7 @@ func (c *AppleCardImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Road return supply_model.RemoteDataErr } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -392,25 +393,25 @@ func (c *AppleCardImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) { req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return config.PAYFOR_FAIL, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } @@ -447,7 +448,7 @@ func (c *AppleCardImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) { } } - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } diff --git a/internal/service/supplier/third_party/apple_shark.go b/internal/service/supplier/third_party/apple_shark.go index bc100df..cbe408d 100644 --- a/internal/service/supplier/third_party/apple_shark.go +++ b/internal/service/supplier/third_party/apple_shark.go @@ -7,7 +7,8 @@ import ( "encoding/base64" "encoding/json" "gateway/internal/config" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service/supplier" "net/http" @@ -102,7 +103,7 @@ func (c *AppleCardSharkImpl) SendCard(ctx context.Context, jsonStr string, cardI req.SetTransport(otelhttp.NewTransport(http.DefaultTransport)) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) return false, "内部错误请稍后再试试(01)" } req.SetTimeout(time.Second*30, time.Second*30) @@ -111,12 +112,12 @@ func (c *AppleCardSharkImpl) SendCard(ctx context.Context, jsonStr string, cardI req.Header("Accept-Charset", "utf-8") req.Header("tokenFrom", "iframe") response, err := req.String() - otel.Logger.WithContext(ctx).Info(response) + otelTrace.Logger.WithContext(ctx).Info(response) return true, "" } func (c *AppleCardSharkImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData { - ctx, cancel := otel.Span(ctx, "AppleCardSharkImpl", "Scan", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "AppleCardSharkImpl", "Scan", trace.WithAttributes( attribute.String("BankOrderId", orderInfo.BankOrderId), attribute.String("MerchantUid", orderInfo.MerchantUid), attribute.String("ExValue", orderInfo.ExValue), @@ -125,7 +126,7 @@ func (c *AppleCardSharkImpl) Scan(ctx context.Context, orderInfo order.OrderInfo cdata := supplier.RedeemCardInfo{} err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata) if err != nil { - otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) + otelTrace.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"} } ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo.BankOrderId, orderInfo.MerchantOrderId) @@ -153,7 +154,7 @@ func (c *AppleCardSharkImpl) kMEncrypt(ctx context.Context, kf, appSecret string secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥 block, err := aes.NewCipher([]byte(secret)) if err != nil { - otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher") + otelTrace.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher") return "", err } // 数据填充 @@ -169,20 +170,20 @@ func (c *AppleCardSharkImpl) PayNotify() { attach := strings.TrimSpace(c.GetString("attach")) orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 { - otel.Logger.WithContext(ctx).Error("【APPLE】回调的订单号不存在,订单号=", zap.String("attach", attach)) + otelTrace.Logger.WithContext(ctx).Error("【APPLE】回调的订单号不存在,订单号=", zap.String("attach", attach)) c.Ctx.WriteString("FAIL") return } roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid) if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 { - otel.Logger.WithContext(ctx).Error("【APPLE】支付通道已经关系或者删除,不进行回调") + otelTrace.Logger.WithContext(ctx).Error("【APPLE】支付通道已经关系或者删除,不进行回调") c.Ctx.WriteString("FAIL") return } merchantUid := orderInfo.MerchantUid merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid) if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 { - otel.Logger.WithContext(ctx).Error("【APPLE】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) + otelTrace.Logger.WithContext(ctx).Error("【APPLE】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) c.Ctx.WriteString("FAIL") return } @@ -239,23 +240,23 @@ func (c *AppleCardSharkImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.R req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n", err) return false } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -303,12 +304,12 @@ func (c *AppleCardSharkImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n", err) return supply_model.DataErr } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") @@ -318,7 +319,7 @@ func (c *AppleCardSharkImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road return supply_model.RemoteDataErr } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -370,25 +371,25 @@ func (c *AppleCardSharkImpl) PayForQuery(payFor payfor.PayforInfo) (string, stri req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n", err) return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return config.PAYFOR_FAIL, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } @@ -425,7 +426,7 @@ func (c *AppleCardSharkImpl) PayForQuery(payFor payfor.PayforInfo) (string, stri } } - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } diff --git a/internal/service/supplier/third_party/daili.go b/internal/service/supplier/third_party/daili.go index e9ed868..6fbead6 100644 --- a/internal/service/supplier/third_party/daili.go +++ b/internal/service/supplier/third_party/daili.go @@ -7,7 +7,8 @@ import ( "gateway/internal/models/payfor" "gateway/internal/models/road" "gateway/internal/models/supply_model" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service" "gateway/internal/service/supplier" "gateway/internal/utils" @@ -43,7 +44,7 @@ func (c *DaiLiImpl) HasDependencyHTML() bool { } func (c *DaiLiImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData { - ctx, cancel := otel.Span(ctx, "DaiLiImpl", "Scan", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "DaiLiImpl", "Scan", trace.WithAttributes( attribute.String("BankOrderId", orderInfo.BankOrderId), attribute.String("MerchantUid", orderInfo.MerchantUid), attribute.String("ExValue", orderInfo.ExValue), @@ -69,7 +70,7 @@ func (c *DaiLiImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInf request := URL + "?" + utils.MapToString(params) - otel.Logger.WithContext(ctx).Info("代丽请求字符串 = " + request) + otelTrace.Logger.WithContext(ctx).Info("代丽请求字符串 = " + request) var scanData supplier.ScanData scanData.Status = "00" @@ -78,7 +79,7 @@ func (c *DaiLiImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInf req.Retries(3) response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("代丽支付请求失败:" + err.Error()) + otelTrace.Logger.WithContext(ctx).Error("代丽支付请求失败:" + err.Error()) scanData.Status = "-1" scanData.Msg = "请求失败:" + err.Error() } else { @@ -106,18 +107,18 @@ func (c *DaiLiImpl) PayNotify() { orderNo := strings.TrimSpace(c.GetString("orderNo")) orderInfo := order.GetOrderByBankOrderId(ctx, orderNo) if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 { - otel.Logger.WithContext(ctx).Error("快付回调的订单号不存在,订单号=", zap.String("orderNo", orderNo)) + otelTrace.Logger.WithContext(ctx).Error("快付回调的订单号不存在,订单号=", zap.String("orderNo", orderNo)) c.StopRun() } roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid) if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 { - otel.Logger.WithContext(ctx).Error("支付通道已经关系或者删除,不进行回调") + otelTrace.Logger.WithContext(ctx).Error("支付通道已经关系或者删除,不进行回调") c.StopRun() } merchantUid := orderInfo.MerchantUid merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid) if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 { - otel.Logger.WithContext(ctx).Error("快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) + otelTrace.Logger.WithContext(ctx).Error("快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) c.StopRun() } paySecret := merchantInfo.MerchantSecret @@ -136,7 +137,7 @@ func (c *DaiLiImpl) PayNotify() { tmpSign := utils.GetMD5Sign(params, keys, paySecret) sign := strings.TrimSpace(c.GetString("sign")) if tmpSign != sign { - otel.Logger.WithContext(ctx).Error("代丽回调签名异常,回调失败") + otelTrace.Logger.WithContext(ctx).Error("代丽回调签名异常,回调失败") // c.StopRun() } // 实际支付金额 @@ -151,11 +152,11 @@ func (c *DaiLiImpl) PayNotify() { // paySolveController := new(service.PaySolveController) if tradeStatus == "FAILED" { if !service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "") { - otel.Logger.WithContext(ctx).Error("solve order fail fail") + otelTrace.Logger.WithContext(ctx).Error("solve order fail fail") } } else if tradeStatus == "CANCELED" { if !service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "") { - otel.Logger.WithContext(ctx).Error("solve order cancel fail") + otelTrace.Logger.WithContext(ctx).Error("solve order cancel fail") } } else if tradeStatus == "WAITING_PAYMENT" { logs.Notice("快付回调,该订单还处于等待支付,订单id=", orderNo) @@ -182,7 +183,7 @@ func (c *DaiLiImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) return false } } else { - otel.Logger.WithContext(ctx).Info("订单状态处于:" + tradeStatus + ";bankOrderId:" + orderInfo.BankOrderId) + otelTrace.Logger.WithContext(ctx).Info("订单状态处于:" + tradeStatus + ";bankOrderId:" + orderInfo.BankOrderId) } return true } diff --git a/internal/service/supplier/third_party/fat_six.go b/internal/service/supplier/third_party/fat_six.go index dea2288..429abc0 100644 --- a/internal/service/supplier/third_party/fat_six.go +++ b/internal/service/supplier/third_party/fat_six.go @@ -4,7 +4,8 @@ import ( "context" "encoding/json" "gateway/internal/config" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service/supplier" "time" @@ -87,7 +88,7 @@ func (f *FatSixImpl) sendCard(ctx context.Context, jsonStr string, cardInfo supp params["sign"] = sign(params, maputil.Keys(params), gojson.Json(jsonStr).Get("paySecret").Tostring()) pretty, _ := formatter.Pretty(params) - otel.Logger.WithContext(ctx).Info("请求参数:" + pretty) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + pretty) //urlParams := url.Values{} //for k, v := range params { @@ -95,7 +96,7 @@ func (f *FatSixImpl) sendCard(ctx context.Context, jsonStr string, cardInfo supp //} body, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("解析参数失败", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("解析参数失败", zap.Error(err)) return false, response } header := http.Header{} @@ -113,17 +114,17 @@ func (f *FatSixImpl) sendCard(ctx context.Context, jsonStr string, cardInfo supp resp, err := httpClient.SendRequest(request) if err != nil || resp.StatusCode != 200 { - otel.Logger.WithContext(ctx).Error("发送数据失败", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("发送数据失败", zap.Error(err)) return false, response } err = httpClient.DecodeResponse(resp, &response) if err != nil || pointer.IsNil(response) { - otel.Logger.WithContext(ctx).Error("解析分解会结构失败", zap.Error(err), zap.Any("response", response)) + otelTrace.Logger.WithContext(ctx).Error("解析分解会结构失败", zap.Error(err), zap.Any("response", response)) return false, response } pretty, _ = formatter.Pretty(response) - otel.Logger.WithContext(ctx).Info("返回参数:" + pretty) + otelTrace.Logger.WithContext(ctx).Info("返回参数:" + pretty) if response.Status == 0 { return true, response } @@ -132,7 +133,7 @@ func (f *FatSixImpl) sendCard(ctx context.Context, jsonStr string, cardInfo supp } func (f *FatSixImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, info3 merchant.MerchantInfo) supplier.ScanData { - ctx, cancel := otel.Span(ctx, "FatSixImpl", "Scan", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "FatSixImpl", "Scan", trace.WithAttributes( attribute.String("BankOrderId", orderInfo.BankOrderId), attribute.String("MerchantUid", orderInfo.MerchantUid), attribute.String("ExValue", orderInfo.ExValue), @@ -181,7 +182,7 @@ func (f *FatSixImpl) PayNotify() { }{} err := f.Bind(&resp) if err != nil { - otel.Logger.WithContext(ctx).Error("解析参数失败", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("解析参数失败", zap.Error(err)) f.Ctx.WriteString("fail") return } @@ -193,7 +194,7 @@ func (f *FatSixImpl) PayNotify() { respSign := resp.Sign tmpSign := sign(params, maputil.Keys(params), gojson.Json(roadInfo.Params).Get("paySecret").Tostring()) if tmpSign != respSign { - otel.Logger.WithContext(ctx).Error("签名错误", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("签名错误", zap.Error(err)) f.Ctx.WriteString("fail") return } @@ -201,7 +202,7 @@ func (f *FatSixImpl) PayNotify() { // TODO 订单支付成功 money, err := convertor.ToFloat(resp.Money) if err != nil { - otel.Logger.WithContext(ctx).Error("金额转换失败", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("金额转换失败", zap.Error(err)) f.Ctx.WriteString("fail") } isOk := service.SolvePaySuccess(ctx, orderInfo.BankOrderId, money, resp.Tid, "支付成功") @@ -245,7 +246,7 @@ func (f *FatSixImpl) PayQueryV2(info order.OrderInfo, roadInfo road.RoadInfo) su httpClient := netutil.NewHttpClient() resp, err := httpClient.SendRequest(request) if err != nil || resp.StatusCode != 200 { - otel.Logger.WithContext(ctx).Error("发送数据失败", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("发送数据失败", zap.Error(err)) return "发送数据失败" } response := struct { @@ -259,7 +260,7 @@ func (f *FatSixImpl) PayQueryV2(info order.OrderInfo, roadInfo road.RoadInfo) su }{} err = httpClient.DecodeResponse(resp, &response) if err != nil || pointer.IsNil(response) { - otel.Logger.WithContext(ctx).Error("解析分解会结构失败", zap.Error(err), zap.Any("response", response)) + otelTrace.Logger.WithContext(ctx).Error("解析分解会结构失败", zap.Error(err), zap.Any("response", response)) return "解析分解会结构失败" } return convertor.ToString(response.Result.Balance) diff --git a/internal/service/supplier/third_party/jd.go b/internal/service/supplier/third_party/jd.go index aac6aaa..3feb92d 100644 --- a/internal/service/supplier/third_party/jd.go +++ b/internal/service/supplier/third_party/jd.go @@ -7,7 +7,8 @@ import ( "encoding/base64" "encoding/json" "gateway/internal/config" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service/supplier" "net/http" @@ -72,22 +73,22 @@ func (c *JDCardImpl) SendCard(ctx context.Context, jsonStr string, cardInfo supp req.SetTimeout(time.Second*30, time.Second*30) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) return false, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") req.Header("tokenFrom", "iframe") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("JD请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("JD请求失败:", zap.Error(err)) return false, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return false, "" } type AutoGenerated struct { @@ -101,18 +102,18 @@ func (c *JDCardImpl) SendCard(ctx context.Context, jsonStr string, cardInfo supp var resData AutoGenerated err = json.Unmarshal([]byte(response), &resData) if err != nil { - otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response)) + otelTrace.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response)) return false, "内部数据处理失败" } if resData.Code != 0 { - otel.Logger.WithContext(ctx).Error("充值错误", zap.String("Message", resData.Message)) + otelTrace.Logger.WithContext(ctx).Error("充值错误", zap.String("Message", resData.Message)) return false, resData.Message } return true, "等待兑换" } func (c *JDCardImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData { - ctx, cancel := otel.Span(ctx, "JDCardImpl", "Scan", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "JDCardImpl", "Scan", trace.WithAttributes( attribute.String("BankOrderId", orderInfo.BankOrderId), attribute.String("MerchantUid", orderInfo.MerchantUid), attribute.String("ExValue", orderInfo.ExValue), @@ -121,7 +122,7 @@ func (c *JDCardImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadIn cdata := supplier.RedeemCardInfo{} err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata) if err != nil { - otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) + otelTrace.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"} } ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo.BankOrderId, orderInfo.MerchantOrderId) @@ -151,7 +152,7 @@ func (c *JDCardImpl) kMEncrypt(kf, appSecret string) (string, error) { secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥 block, err := aes.NewCipher([]byte(secret)) if err != nil { - otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher") + otelTrace.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher") return "", err } // 数据填充 @@ -167,20 +168,20 @@ func (c *JDCardImpl) PayNotify() { attach := strings.TrimSpace(c.GetString("merchantId")) orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 { - otel.Logger.WithContext(ctx).Error("【JD】回调的订单号不存在,订单号=", zap.String("attach", attach)) + otelTrace.Logger.WithContext(ctx).Error("【JD】回调的订单号不存在,订单号=", zap.String("attach", attach)) c.Ctx.WriteString("FAIL") return } roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid) if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 { - otel.Logger.WithContext(ctx).Error("【JD】支付通道已经关系或者删除,不进行回调") + otelTrace.Logger.WithContext(ctx).Error("【JD】支付通道已经关系或者删除,不进行回调") c.Ctx.WriteString("FAIL") return } merchantUid := orderInfo.MerchantUid merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid) if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 { - otel.Logger.WithContext(ctx).Error("【JD】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) + otelTrace.Logger.WithContext(ctx).Error("【JD】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) c.Ctx.WriteString("FAIL") return } @@ -235,23 +236,23 @@ func (c *JDCardImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -298,12 +299,12 @@ func (c *JDCardImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInf req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return supply_model.DataErr } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") @@ -313,7 +314,7 @@ func (c *JDCardImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInf return supply_model.RemoteDataErr } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -364,25 +365,25 @@ func (c *JDCardImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) { req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return config.PAYFOR_FAIL, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } @@ -419,7 +420,7 @@ func (c *JDCardImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) { } } - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } diff --git a/internal/service/supplier/third_party/kuaifu.go b/internal/service/supplier/third_party/kuaifu.go index cf2452d..2c917a7 100644 --- a/internal/service/supplier/third_party/kuaifu.go +++ b/internal/service/supplier/third_party/kuaifu.go @@ -4,7 +4,8 @@ import ( "context" "fmt" "gateway/internal/config" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service/supplier" "gateway/internal/models/merchant" @@ -53,7 +54,7 @@ func (c *KuaiFuImpl) HasDependencyHTML() bool { } func (c *KuaiFuImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData { - ctx, cancel := otel.Span(ctx, "KuaiFuImpl", "Scan", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "KuaiFuImpl", "Scan", trace.WithAttributes( attribute.String("BankOrderId", orderInfo.BankOrderId), attribute.String("MerchantUid", orderInfo.MerchantUid), attribute.String("ExValue", orderInfo.ExValue), @@ -100,14 +101,14 @@ func (c *KuaiFuImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadIn scanData.OrderPrice = convertor.ToString(params["orderPrice"]) response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("KF 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("KF 请求失败:", zap.Error(err)) scanData.Status = "01" scanData.Msg = gojson.Json(response).Get("statusMsg").Tostring() return scanData } statusCode := gojson.Json(response).Get("statusCode").Tostring() if statusCode != "00" { - otel.Logger.WithContext(ctx).Error("KF生成扫码地址失败") + otelTrace.Logger.WithContext(ctx).Error("KF生成扫码地址失败") scanData.Status = "01" scanData.Msg = "生成扫码地址失败" return scanData @@ -125,18 +126,18 @@ func (c *KuaiFuImpl) PayNotify() { orderNo := strings.TrimSpace(c.GetString("orderNo")) orderInfo := order.GetOrderByBankOrderId(ctx, orderNo) if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 { - otel.Logger.WithContext(ctx).Error("快付回调的订单号不存在,订单号=", zap.String("orderNo", orderNo)) + otelTrace.Logger.WithContext(ctx).Error("快付回调的订单号不存在,订单号=", zap.String("orderNo", orderNo)) c.StopRun() } roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid) if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 { - otel.Logger.WithContext(ctx).Error("支付通道已经关系或者删除,不进行回调") + otelTrace.Logger.WithContext(ctx).Error("支付通道已经关系或者删除,不进行回调") c.StopRun() } merchantUid := orderInfo.MerchantUid merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid) if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 { - otel.Logger.WithContext(ctx).Error("快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) + otelTrace.Logger.WithContext(ctx).Error("快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) c.StopRun() } params := make(map[string]any) @@ -154,13 +155,13 @@ func (c *KuaiFuImpl) PayNotify() { tmpSign := utils.GetMD5Sign(params, keys, paySecret) sign := strings.TrimSpace(c.GetString("sign")) if tmpSign != sign { - otel.Logger.WithContext(ctx).Error("快付回调签名异常,回调失败") + otelTrace.Logger.WithContext(ctx).Error("快付回调签名异常,回调失败") c.StopRun() } // 实际支付金额 factAmount, err := strconv.ParseFloat(convertor.ToString(params["orderPrice"]), 64) if err != nil { - otel.Logger.WithContext(ctx).Error("快付回调实际金额有误,", zap.Any("factAmount=", params["orderPrice"])) + otelTrace.Logger.WithContext(ctx).Error("快付回调实际金额有误,", zap.Any("factAmount=", params["orderPrice"])) c.StopRun() } orderInfo.FactAmount = factAmount @@ -168,11 +169,11 @@ func (c *KuaiFuImpl) PayNotify() { tradeStatus := params["tradeStatus"] if tradeStatus == "FAILED" { if !service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "") { - otel.Logger.WithContext(ctx).Error("solve order fail fail") + otelTrace.Logger.WithContext(ctx).Error("solve order fail fail") } } else if tradeStatus == "CANCELED" { if !service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "") { - otel.Logger.WithContext(ctx).Error("solve order cancel fail") + otelTrace.Logger.WithContext(ctx).Error("solve order cancel fail") } } else if tradeStatus == "WAITING_PAYMENT" { logs.Notice("快付回调,该订单还处于等待支付,订单id=", orderNo) @@ -186,7 +187,7 @@ func (c *KuaiFuImpl) PayNotify() { func (c *KuaiFuImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool { ctx := c.Ctx.Request.Context() if orderInfo.Status != "wait" && orderInfo.Status != "" { - otel.Logger.WithContext(ctx).Error("订单已经被处理,不需要查询,bankOrderId:", zap.String("BankOrderId", orderInfo.BankOrderId)) + otelTrace.Logger.WithContext(ctx).Error("订单已经被处理,不需要查询,bankOrderId:", zap.String("BankOrderId", orderInfo.BankOrderId)) return false } params := make(map[string]any) @@ -201,20 +202,20 @@ func (c *KuaiFuImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) } response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("快付订单查询失败,bankOrderId: ", zap.String("BankOrderId", orderInfo.BankOrderId)) - otel.Logger.WithContext(ctx).Error("err: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("快付订单查询失败,bankOrderId: ", zap.String("BankOrderId", orderInfo.BankOrderId)) + otelTrace.Logger.WithContext(ctx).Error("err: ", zap.Error(err)) return false } statusCode := gojson.Json(response).Get("statusCode").Tostring() if statusCode != "00" { - otel.Logger.WithContext(ctx).Error("快付订单查询返回失败,bankOrderId:", zap.String("BankOrderId", orderInfo.BankOrderId), zap.String("response", response)) + otelTrace.Logger.WithContext(ctx).Error("快付订单查询返回失败,bankOrderId:", zap.String("BankOrderId", orderInfo.BankOrderId), zap.String("response", response)) return false } // 获取用户的实际支付金额 orderPrice := gojson.Json(response).Get("orderPrice").Tostring() factAmount, err := strconv.ParseFloat(orderPrice, 64) if err != nil { - otel.Logger.WithContext(ctx).Error("快速查询得到的实际金额错误, orderPrice=", zap.Any("orderPrice", orderPrice)) + otelTrace.Logger.WithContext(ctx).Error("快速查询得到的实际金额错误, orderPrice=", zap.Any("orderPrice", orderPrice)) } // orderInfo.FactAmount = orderInfo.OrderAmount @@ -230,7 +231,7 @@ func (c *KuaiFuImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) return false } } else { - otel.Logger.WithContext(ctx).Info("订单状态处于:" + tradeStatus + ";bankOrderId:" + orderInfo.BankOrderId) + otelTrace.Logger.WithContext(ctx).Info("订单状态处于:" + tradeStatus + ";bankOrderId:" + orderInfo.BankOrderId) } return true } @@ -267,20 +268,20 @@ func (c *KuaiFuImpl) PayFor(payFor payfor.PayforInfo) string { } response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("快付代付返回错误结果: ", zap.String("response", response)) + otelTrace.Logger.WithContext(ctx).Error("快付代付返回错误结果: ", zap.String("response", response)) } else { json := gojson.Json(response) resultCode := json.Get("resultCode").Tostring() resultMsg := json.Get("resultMsg").Tostring() if resultCode != "00" { - otel.Logger.WithContext(ctx).Error("快付代付返回错误信息:", zap.String("resultMsg", resultMsg)) + otelTrace.Logger.WithContext(ctx).Error("快付代付返回错误信息:", zap.String("resultMsg", resultMsg)) return "fail" } settStatus := json.Get("settStatus").Tostring() if settStatus == "00" { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("代付uid=%s,已经成功发送给了上游处理", payFor.PayforUid)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("代付uid=%s,已经成功发送给了上游处理", payFor.PayforUid)) } else if settStatus == "01" { - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("代付uid=%s,发送失败", payFor.PayforUid)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("代付uid=%s,发送失败", payFor.PayforUid)) } } return "success" @@ -306,7 +307,7 @@ func (c *KuaiFuImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) { } response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("快付代付查询失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("快付代付查询失败:", zap.Error(err)) return config.PAYFOR_SOLVING, "查询失败" } @@ -314,22 +315,22 @@ func (c *KuaiFuImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) { payFor.ResponseTime = utils.GetBasicDateTime() payFor.UpdateTime = time.Now() if !payfor.UpdatePayFor(ctx, payFor) { - otel.Logger.WithContext(ctx).Error("更新快付代付订单状态失败") + otelTrace.Logger.WithContext(ctx).Error("更新快付代付订单状态失败") } resultCode := gojson.Json(response).Get("resultCode").Tostring() resultMsg := gojson.Json(response).Get("resultMsg").Tostring() if resultCode != "00" { - otel.Logger.WithContext(ctx).Error("快付代付查询返回错误:", zap.String("resultMsg", resultMsg)) + otelTrace.Logger.WithContext(ctx).Error("快付代付查询返回错误:", zap.String("resultMsg", resultMsg)) return config.PAYFOR_SOLVING, resultMsg } - otel.Logger.WithContext(ctx).Info("快付代付查询返回结果:", zap.String("resultMsg", resultMsg)) + otelTrace.Logger.WithContext(ctx).Info("快付代付查询返回结果:", zap.String("resultMsg", resultMsg)) merchantOrderId := gojson.Json(response).Get("merchantOrderId").Tostring() if merchantOrderId != payFor.BankOrderId { - otel.Logger.WithContext(ctx).Error("快付代付返回结果,订单id不一致: ", zap.String("resultMsg", merchantOrderId)) + otelTrace.Logger.WithContext(ctx).Error("快付代付返回结果,订单id不一致: ", zap.String("resultMsg", merchantOrderId)) return config.PAYFOR_SOLVING, "快付代付返回结果,订单id不一致" } @@ -361,7 +362,7 @@ func (c *KuaiFuImpl) BalanceQuery(roadInfo road.RoadInfo) float64 { response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("快付余额查询失败,err: ", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("快付余额查询失败,err: ", zap.Error(err)) return 0.00 } logs.Debug("快付余额查询返回:", response) @@ -377,7 +378,7 @@ func (c *KuaiFuImpl) BalanceQuery(roadInfo road.RoadInfo) float64 { balance := gojson.Json(response).Get("balance").Tostring() availableAmount := gojson.Json(response).Get("availableAmount").Tostring() - otel.Logger.WithContext(ctx).Info(fmt.Sprintf("快付余额=%s,可用金额=%s", balance, availableAmount)) + otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("快付余额=%s,可用金额=%s", balance, availableAmount)) f, err := strconv.ParseFloat(availableAmount, 64) return f diff --git a/internal/service/supplier/third_party/mf178_v2.go b/internal/service/supplier/third_party/mf178_v2.go index c600eef..4f7da5b 100644 --- a/internal/service/supplier/third_party/mf178_v2.go +++ b/internal/service/supplier/third_party/mf178_v2.go @@ -13,7 +13,8 @@ import ( "gateway/internal/models/payfor" "gateway/internal/models/road" "gateway/internal/models/supply_model" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service" "gateway/internal/service/supplier" "gateway/internal/utils" @@ -71,7 +72,7 @@ func (c *MFCardV2Impl) SendCard(ctx context.Context, jsonStr string, cardInfo su sign := utils.GetMD5SignMF(params, appSecret) params["sign"] = sign - otel.Logger.WithContext(ctx).Info("params", zap.Any("params", params)) + otelTrace.Logger.WithContext(ctx).Info("params", zap.Any("params", params)) url, err := cfg.GetMFCardSubmitUrl() if err != nil { return false, "" @@ -81,23 +82,23 @@ func (c *MFCardV2Impl) SendCard(ctx context.Context, jsonStr string, cardInfo su req.SetTimeout(time.Second*30, time.Second*30) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return false, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return false, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return false, "" } type AutoGenerated struct { @@ -126,7 +127,7 @@ func (c *MFCardV2Impl) SendCard(ctx context.Context, jsonStr string, cardInfo su } func (c *MFCardV2Impl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData { - ctx, cancel := otel.Span(ctx, "MFCardV2Impl", "Scan", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "MFCardV2Impl", "Scan", trace.WithAttributes( attribute.String("BankOrderId", orderInfo.BankOrderId), attribute.String("MerchantUid", orderInfo.MerchantUid), attribute.String("ExValue", orderInfo.ExValue), @@ -135,7 +136,7 @@ func (c *MFCardV2Impl) Scan(ctx context.Context, orderInfo order.OrderInfo, road cdata := supplier.RedeemCardInfo{} err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata) if err != nil { - otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue), zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue), zap.Error(err)) return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"} } ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo.BankOrderId) @@ -152,7 +153,7 @@ func (c *MFCardV2Impl) Scan(ctx context.Context, orderInfo order.OrderInfo, road } if err != nil { - otel.Logger.WithContext(ctx).Error("SolvePaySuccess失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("SolvePaySuccess失败:", zap.Error(err)) return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"} } var scanData supplier.ScanData @@ -174,7 +175,7 @@ func (c *MFCardV2Impl) kMEncrypt(kf, appSecret string) (string, error) { secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥 block, err := aes.NewCipher([]byte(secret)) if err != nil { - otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher") + otelTrace.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher") return "", err } // 数据填充 @@ -187,31 +188,31 @@ func (c *MFCardV2Impl) kMEncrypt(kf, appSecret string) (string, error) { func (c *MFCardV2Impl) PayNotify() { ctx := c.Ctx.Request.Context() - otel.Logger.WithContext(ctx).Info("消息回调成功!!!") + otelTrace.Logger.WithContext(ctx).Info("消息回调成功!!!") params := make(map[string]any) attach := strings.TrimSpace(c.GetString("attach")) orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 { - otel.Logger.WithContext(ctx).Error("【MF178】回调的订单号不存在,订单号=", zap.String("attach", attach)) + otelTrace.Logger.WithContext(ctx).Error("【MF178】回调的订单号不存在,订单号=", zap.String("attach", attach)) c.StopRun() return } roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid) if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 { - otel.Logger.WithContext(ctx).Error("【MF178】支付通道已经关系或者删除,不进行回调") + otelTrace.Logger.WithContext(ctx).Error("【MF178】支付通道已经关系或者删除,不进行回调") c.StopRun() return } merchantUid := orderInfo.MerchantUid merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid) if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 { - otel.Logger.WithContext(ctx).Error("【MF178】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) + otelTrace.Logger.WithContext(ctx).Error("【MF178】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) c.StopRun() return } paySecretGroup, err := sonic.GetFromString(roadInfo.Params) if err != nil { - otel.Logger.WithContext(ctx).Error("获取蜜蜂秘钥失败", zap.String("merchantUid", merchantUid)) + otelTrace.Logger.WithContext(ctx).Error("获取蜜蜂秘钥失败", zap.String("merchantUid", merchantUid)) c.StopRun() return } @@ -232,7 +233,7 @@ func (c *MFCardV2Impl) PayNotify() { sign := strings.TrimSpace(c.GetString("sign")) params["sign"] = sign // 签名 if tmpSign != sign { - otel.Logger.WithContext(ctx).Error("【MF178】回调签名异常,回调失败") + otelTrace.Logger.WithContext(ctx).Error("【MF178】回调签名异常,回调失败") c.StopRun() return } @@ -242,9 +243,9 @@ func (c *MFCardV2Impl) PayNotify() { orderInfo.FactAmount = 0 } if params["status"] == "8" { // 失败 - otel.Logger.WithContext(ctx).Info("【MF178】回调失败,订单信息", zap.Any("params", params)) + otelTrace.Logger.WithContext(ctx).Info("【MF178】回调失败,订单信息", zap.Any("params", params)) if !service.SolvePayFail(ctx, convertor.ToString(params["order_id"]), "", "") { - otel.Logger.WithContext(ctx).Error("solve order fail fail") + otelTrace.Logger.WithContext(ctx).Error("solve order fail fail") } } else if params["status"] == "9" && factAmount == orderInfo.FactAmount { // TODO 订单支付成功 @@ -278,23 +279,23 @@ func (c *MFCardV2Impl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInf req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -341,12 +342,12 @@ func (c *MFCardV2Impl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadI req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return supply_model.DataErr } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") @@ -356,7 +357,7 @@ func (c *MFCardV2Impl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadI return supply_model.RemoteDataErr } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -408,25 +409,25 @@ func (c *MFCardV2Impl) PayForQuery(payFor payfor.PayforInfo) (string, string) { req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return config.PAYFOR_FAIL, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } @@ -463,7 +464,7 @@ func (c *MFCardV2Impl) PayForQuery(payFor payfor.PayforInfo) (string, string) { } } - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } diff --git a/internal/service/supplier/third_party/self.go b/internal/service/supplier/third_party/self.go index 85d748f..9401c7f 100644 --- a/internal/service/supplier/third_party/self.go +++ b/internal/service/supplier/third_party/self.go @@ -7,7 +7,8 @@ import ( "encoding/base64" "encoding/json" "gateway/internal/config" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service/supplier" "gateway/internal/models/merchant" @@ -58,21 +59,21 @@ func (c *SelfThirdImpl) SendCard(ctx context.Context, jsonStr string, cardInfo s req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) return false, "内部错误请稍后再试试(01)" } req.SetTimeout(time.Second*30, time.Second*30) - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("【自有三方】 GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("【自有三方】 GetToken 请求失败:", zap.Error(err)) return false, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return false, "" } type AutoGenerated struct { @@ -83,7 +84,7 @@ func (c *SelfThirdImpl) SendCard(ctx context.Context, jsonStr string, cardInfo s var resData AutoGenerated err = json.Unmarshal([]byte(response), &resData) if err != nil { - otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response)) + otelTrace.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response)) return false, "内部数据处理失败" } if resData.Code == 0 { @@ -93,7 +94,7 @@ func (c *SelfThirdImpl) SendCard(ctx context.Context, jsonStr string, cardInfo s } func (c *SelfThirdImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData { - ctx, cancel := otel.Span(ctx, "SelfThirdImpl", "Scan", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "SelfThirdImpl", "Scan", trace.WithAttributes( attribute.String("BankOrderId", orderInfo.BankOrderId), attribute.String("MerchantUid", orderInfo.MerchantUid), attribute.String("ExValue", orderInfo.ExValue), @@ -102,7 +103,7 @@ func (c *SelfThirdImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roa cdata := supplier.RedeemCardInfo{} err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata) if err != nil { - otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) + otelTrace.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"} } ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo, roadInfo) @@ -132,7 +133,7 @@ func (c *SelfThirdImpl) kMEncrypt(kf, appSecret string) (string, error) { secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥 block, err := aes.NewCipher([]byte(secret)) if err != nil { - otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher") + otelTrace.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher") return "", err } // 数据填充 @@ -159,20 +160,20 @@ func (c *SelfThirdImpl) PayNotify() { } orderInfo := order.GetOrderByBankOrderId(ctx, params["orderNo"].(string)) if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 { - otel.Logger.WithContext(ctx).Error("【自有三方】回调的订单号不存在,订单号=", zap.String("orderNo", params["orderNo"].(string))) + otelTrace.Logger.WithContext(ctx).Error("【自有三方】回调的订单号不存在,订单号=", zap.String("orderNo", params["orderNo"].(string))) c.Ctx.WriteString("FAIL") return } roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid) if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 { - otel.Logger.WithContext(ctx).Error("【自有三方】支付通道已经关系或者删除,不进行回调") + otelTrace.Logger.WithContext(ctx).Error("【自有三方】支付通道已经关系或者删除,不进行回调") c.Ctx.WriteString("FAIL") return } merchantUid := orderInfo.MerchantUid merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid) if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 { - otel.Logger.WithContext(ctx).Error("【自有三方】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) + otelTrace.Logger.WithContext(ctx).Error("【自有三方】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) c.Ctx.WriteString("FAIL") return } @@ -222,23 +223,23 @@ func (c *SelfThirdImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadIn req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -287,12 +288,12 @@ func (c *SelfThirdImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Road req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return supply_model.DataErr } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") @@ -302,7 +303,7 @@ func (c *SelfThirdImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Road return supply_model.RemoteDataErr } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -353,25 +354,25 @@ func (c *SelfThirdImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) { req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return config.PAYFOR_FAIL, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } @@ -408,7 +409,7 @@ func (c *SelfThirdImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) { } } - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } diff --git a/internal/service/supplier/third_party/star_silence.go b/internal/service/supplier/third_party/star_silence.go index 026eac4..df48c07 100644 --- a/internal/service/supplier/third_party/star_silence.go +++ b/internal/service/supplier/third_party/star_silence.go @@ -11,7 +11,8 @@ import ( "gateway/internal/models/payfor" "gateway/internal/models/road" "gateway/internal/models/supply_model" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service" "gateway/internal/service/supplier" "gateway/internal/utils" @@ -67,7 +68,7 @@ func (c *StarSilenceImpl) SendCard(ctx context.Context, jsonStr string, cardInfo formData.Set(s, s2) } //req.SetTimeout(time.Second*30, time.Second*30) - otel.Logger.WithContext(ctx).Info("formData", zap.Any("formData", formData)) + otelTrace.Logger.WithContext(ctx).Info("formData", zap.Any("formData", formData)) client := netutil.NewHttpClient() client.Timeout = time.Second * 30 client.Transport = otelhttp.NewTransport(client.Transport) @@ -77,12 +78,12 @@ func (c *StarSilenceImpl) SendCard(ctx context.Context, jsonStr string, cardInfo QueryParams: formData, }) result, _ := io.ReadAll(resp.Body) - otel.Logger.WithContext(ctx).Sugar().Infof("远端请求返回数据:%s\n", string(result)) + otelTrace.Logger.WithContext(ctx).Sugar().Infof("远端请求返回数据:%s\n", string(result)) return gojson.Json(string(result)).Get("code").Tostring() == "0", gojson.Json(string(result)).Get("msg").Tostring() } func (c *StarSilenceImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData { - ctx, cancel := otel.Span(ctx, "StarSilenceImpl", "Scan", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "StarSilenceImpl", "Scan", trace.WithAttributes( attribute.String("BankOrderId", orderInfo.BankOrderId), attribute.String("MerchantUid", orderInfo.MerchantUid), attribute.String("ExValue", orderInfo.ExValue), @@ -91,7 +92,7 @@ func (c *StarSilenceImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, r cdata := supplier.RedeemCardInfo{} err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata) if err != nil { - otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) + otelTrace.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"} } ok, str := c.SendCard(ctx, roadInfo.Params, cdata, &orderInfo) @@ -109,7 +110,7 @@ func (c *StarSilenceImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, r func (c *StarSilenceImpl) PayNotify() { ctx := c.Ctx.Request.Context() - otel.Logger.WithContext(ctx).Info("消息回调成功!!!") + otelTrace.Logger.WithContext(ctx).Info("消息回调成功!!!") params := map[string]string{ "supplierOrderId": strings.TrimSpace(c.GetString("supplierOrderId")), "deservedValue": strings.TrimSpace(c.GetString("deservedValue")), @@ -119,17 +120,17 @@ func (c *StarSilenceImpl) PayNotify() { "sign": strings.TrimSpace(c.GetString("sign")), } r, _ := json.Marshal(params) - otel.Logger.WithContext(ctx).Sugar().Infof("星寂回调参数:%s", string(r)) + otelTrace.Logger.WithContext(ctx).Sugar().Infof("星寂回调参数:%s", string(r)) orderInfo := order.GetOrderByBankOrderId(ctx, params["supplierOrderId"]) // OrderId if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 { - otel.Logger.WithContext(ctx).Error("【星寂】回调的订单号不存在,订单号=", zap.String("supplierOrderId", params["supplierOrderId"])) + otelTrace.Logger.WithContext(ctx).Error("【星寂】回调的订单号不存在,订单号=", zap.String("supplierOrderId", params["supplierOrderId"])) c.Ctx.WriteString("订单不存在") return } roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid) if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 { - otel.Logger.WithContext(ctx).Error("【星寂】支付通道已经关系或者删除,不进行回调") + otelTrace.Logger.WithContext(ctx).Error("【星寂】支付通道已经关系或者删除,不进行回调") c.Ctx.WriteString("通道不存在") c.StopRun() return @@ -139,7 +140,7 @@ func (c *StarSilenceImpl) PayNotify() { params["deservedValue"], params["code"], params["msg"], gojson.Json(roadInfo.Params).Get("signKey").Tostring())), ) if tmpSign != params["sign"] { - otel.Logger.WithContext(ctx).Error("签名验证失败", zap.String(tmpSign, "tmpSign"), zap.String("sign", params["sign"])) + otelTrace.Logger.WithContext(ctx).Error("签名验证失败", zap.String(tmpSign, "tmpSign"), zap.String("sign", params["sign"])) c.Ctx.WriteString("签名验证失败") c.StopRun() } @@ -147,7 +148,7 @@ func (c *StarSilenceImpl) PayNotify() { merchantUid := orderInfo.MerchantUid merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid) if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 { - otel.Logger.WithContext(ctx).Error("【星寂】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) + otelTrace.Logger.WithContext(ctx).Error("【星寂】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) c.Ctx.WriteString("商户不存在") c.StopRun() return @@ -155,7 +156,7 @@ func (c *StarSilenceImpl) PayNotify() { // 实际支付金额 factAmount, err := strconv.ParseFloat(convertor.ToString(params["realParvalue"]), 64) if err != nil { - otel.Logger.WithContext(ctx).Error("【星寂】处理失败,%s", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("【星寂】处理失败,%s", zap.Error(err)) c.Ctx.WriteString("订单转换失败") return } @@ -166,7 +167,7 @@ func (c *StarSilenceImpl) PayNotify() { service.SolvePayFail(ctx, convertor.ToString(params["supplierOrderId"]), "", fmt.Sprintf("实付金额与订单金额不一致,实际金额%.2f,卡面金额:%.2f", factAmount, orderInfo.OrderAmount)) } else { if !service.SolvePayFail(ctx, convertor.ToString(params["supplierOrderId"]), "", params["msg"]) { - otel.Logger.WithContext(ctx).Error("【星寂】处理失败") + otelTrace.Logger.WithContext(ctx).Error("【星寂】处理失败") } } c.Ctx.WriteString("SUCCESS") @@ -196,23 +197,23 @@ func (c *StarSilenceImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.Road req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -259,12 +260,12 @@ func (c *StarSilenceImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Ro req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return supply_model.DataErr } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") @@ -274,7 +275,7 @@ func (c *StarSilenceImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Ro return supply_model.RemoteDataErr } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -326,25 +327,25 @@ func (c *StarSilenceImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return config.PAYFOR_FAIL, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } @@ -381,7 +382,7 @@ func (c *StarSilenceImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) } } - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } diff --git a/internal/service/supplier/third_party/star_silence_test.go b/internal/service/supplier/third_party/star_silence_test.go index 5049277..ab8dd05 100644 --- a/internal/service/supplier/third_party/star_silence_test.go +++ b/internal/service/supplier/third_party/star_silence_test.go @@ -2,7 +2,7 @@ package third_party import ( "fmt" - "gateway/internal/otel" + "gateway/internal/service/supplier" "gateway/internal/models/order" @@ -74,5 +74,5 @@ func TestStarSilenceImpl_PayNotify(t *testing.T) { fmt.Sprintf("%s%s%s%s%s%s", "6666cuhprmeqgjec73975600", "0", "0", "2", "销卡失败-卡密无效", "e90db0fea5be42f98a376b0049c9aa8c"), ), ) - otel.Logger.WithContext(ctx).Info(tmpSign) + otelTrace.Logger.WithContext(ctx).Info(tmpSign) } diff --git a/internal/service/supplier/third_party/t_mall_game.go b/internal/service/supplier/third_party/t_mall_game.go index 20078e9..df7dd24 100644 --- a/internal/service/supplier/third_party/t_mall_game.go +++ b/internal/service/supplier/third_party/t_mall_game.go @@ -4,7 +4,8 @@ import ( "context" "encoding/json" "gateway/internal/config" - "gateway/internal/otel" + + "gateway/internal/otelTrace" "gateway/internal/service/supplier" "net/http" @@ -48,7 +49,7 @@ func (c *TMAllGameImpl) HasDependencyHTML() bool { } func (c *TMAllGameImpl) SendCard(ctx context.Context, jsonStr string, cardInfo supplier.CardInfo, orderInfo order.OrderInfo) (bool, string) { - ctx, cancel := otel.Span(ctx, "TMAllGameImpl", "Scan", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "TMAllGameImpl", "Scan", trace.WithAttributes( attribute.String("BankOrderId", orderInfo.BankOrderId), attribute.String("MerchantUid", orderInfo.MerchantUid), attribute.String("ExValue", orderInfo.ExValue), @@ -75,7 +76,7 @@ func (c *TMAllGameImpl) SendCard(ctx context.Context, jsonStr string, cardInfo s } params["sign"] = utils.TmpEncrypt(params["merchantOrder"] + params["accountNumber"] + params["timestamp"]) url, err := cfg.GetTMallGameSubmitUrl() - otel.Logger.WithContext(ctx).Sugar().Infof("获取TMallGame地址:%s\n", url) + otelTrace.Logger.WithContext(ctx).Sugar().Infof("获取TMallGame地址:%s\n", url) if err != nil { return false, "获取天猫充值地址失败!" } @@ -83,10 +84,10 @@ func (c *TMAllGameImpl) SendCard(ctx context.Context, jsonStr string, cardInfo s req.SetTransport(otelhttp.NewTransport(http.DefaultTransport)) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) return false, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.SetTimeout(time.Second*30, time.Second*30) @@ -94,12 +95,12 @@ func (c *TMAllGameImpl) SendCard(ctx context.Context, jsonStr string, cardInfo s req.Header("tokenFrom", "iframe") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("天猫店铺请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("天猫店铺请求失败:", zap.Error(err)) return false, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return false, "" } type AutoGenerated struct { @@ -113,11 +114,11 @@ func (c *TMAllGameImpl) SendCard(ctx context.Context, jsonStr string, cardInfo s var resData AutoGenerated err = json.Unmarshal([]byte(response), &resData) if err != nil { - otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response)) + otelTrace.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response)) return false, "内部数据处理失败" } if resData.Code != 0 { - otel.Logger.WithContext(ctx).Error("充值错误", zap.String("Message", resData.Message)) + otelTrace.Logger.WithContext(ctx).Error("充值错误", zap.String("Message", resData.Message)) return false, resData.Message } switch resData.Data.Status { @@ -130,12 +131,12 @@ func (c *TMAllGameImpl) SendCard(ctx context.Context, jsonStr string, cardInfo s } func (c *TMAllGameImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData { - otel.Logger.WithContext(ctx).Info("TMallGame支付") + otelTrace.Logger.WithContext(ctx).Info("TMallGame支付") var cdata supplier.CardInfo cdata = &supplier.RedeemCardInfo{} err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata) if err != nil { - otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) + otelTrace.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"} } channel := "" @@ -169,20 +170,20 @@ func (c *TMAllGameImpl) PayNotify() { orderInfo := order.GetOrderByBankOrderId(ctx, strings.TrimSpace(c.GetString("merchantOrder"))) // OrderId if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 { - otel.Logger.WithContext(ctx).Error("【TMALLGAME】回调的订单号不存在,订单号=", zap.String("merchantOrder", strings.TrimSpace(c.GetString("merchantOrder")))) + otelTrace.Logger.WithContext(ctx).Error("【TMALLGAME】回调的订单号不存在,订单号=", zap.String("merchantOrder", strings.TrimSpace(c.GetString("merchantOrder")))) c.Ctx.WriteString("FAIL") return } roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid) if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 { - otel.Logger.WithContext(ctx).Error("【TMALLGAME】支付通道已经关系或者删除,不进行回调") + otelTrace.Logger.WithContext(ctx).Error("【TMALLGAME】支付通道已经关系或者删除,不进行回调") c.Ctx.WriteString("FAIL") return } merchantUid := orderInfo.MerchantUid merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid) if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 { - otel.Logger.WithContext(ctx).Error("【TMALLGAME】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) + otelTrace.Logger.WithContext(ctx).Error("【TMALLGAME】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) c.Ctx.WriteString("FAIL") return } @@ -197,12 +198,12 @@ func (c *TMAllGameImpl) PayNotify() { } tmpSign := utils.TmpEncrypt(strings.TrimSpace(c.GetString("merchantOrder")) + params["orderId"] + params["timestamp"]) if tmpSign != params["sign"] { - otel.Logger.WithContext(ctx).Error("【TMALLGAME】回调签名错误,签名=", zap.String("签名", params["sign"]), zap.String("计算签名", tmpSign)) + otelTrace.Logger.WithContext(ctx).Error("【TMALLGAME】回调签名错误,签名=", zap.String("签名", params["sign"]), zap.String("计算签名", tmpSign)) c.Ctx.WriteString("FAIL") return } orderInfo.BankTransId = params["orderId"] - otel.Logger.WithContext(ctx).Info("【TMALLGAME】回调参数:", zap.Any("params", params)) + otelTrace.Logger.WithContext(ctx).Info("【TMALLGAME】回调参数:", zap.Any("params", params)) if params["status"] == "finished" { // TODO 订单支付成功 isOk := service.SolvePaySuccess(ctx, orderInfo.BankOrderId, orderInfo.FactAmount, params["orderId"], "支付成功") @@ -247,23 +248,23 @@ func (c *TMAllGameImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadIn req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -311,12 +312,12 @@ func (c *TMAllGameImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Road req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return supply_model.DataErr } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") @@ -326,7 +327,7 @@ func (c *TMAllGameImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Road return supply_model.RemoteDataErr } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -378,25 +379,25 @@ func (c *TMAllGameImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) { req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return config.PAYFOR_FAIL, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } @@ -433,7 +434,7 @@ func (c *TMAllGameImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) { } } - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } diff --git a/internal/service/supplier/third_party/walmart.go b/internal/service/supplier/third_party/walmart.go index 95a7787..36fcd4a 100644 --- a/internal/service/supplier/third_party/walmart.go +++ b/internal/service/supplier/third_party/walmart.go @@ -5,7 +5,8 @@ import ( "encoding/json" "fmt" "gateway/internal/config" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service/supplier" "gateway/internal/models/merchant" @@ -129,7 +130,7 @@ func (c *WalMartImpl) SendCard(ctx context.Context, jsonStr string, cardInfo sup cfg := config.GetConfig() expectAmount, err := strconv.ParseInt(cardInfo.FaceType, 10, 64) if err != nil { - otel.Logger.WithContext(ctx).Error("金额转换失败", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("金额转换失败", zap.Error(err)) expectAmount = 0 } params := SendCardInfo{ @@ -151,20 +152,20 @@ func (c *WalMartImpl) SendCard(ctx context.Context, jsonStr string, cardInfo sup req.SetTransport(otelhttp.NewTransport(http.DefaultTransport)) marshal, err := json.Marshal(requestData) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) return false, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.SetTimeout(time.Second*30, time.Second*30) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("Apple GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Apple GetToken 请求失败:", zap.Error(err)) return false, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) type AutoGenerated struct { Code int `json:"code"` Message string `json:"message"` @@ -175,18 +176,18 @@ func (c *WalMartImpl) SendCard(ctx context.Context, jsonStr string, cardInfo sup var resData AutoGenerated err = json.Unmarshal([]byte(response), &resData) if err != nil { - otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response)) + otelTrace.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response)) return false, "内部数据处理失败" } if resData.Code != 200 { - otel.Logger.WithContext(ctx).Error("充值错误", zap.String("Message", resData.Message)) + otelTrace.Logger.WithContext(ctx).Error("充值错误", zap.String("Message", resData.Message)) return false, resData.Message } return true, response } func (c *WalMartImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData { - ctx, cancel := otel.Span(ctx, "WalMartImpl", "Scan", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "WalMartImpl", "Scan", trace.WithAttributes( attribute.String("BankOrderId", orderInfo.BankOrderId), attribute.String("MerchantUid", orderInfo.MerchantUid), attribute.String("ExValue", orderInfo.ExValue), @@ -195,7 +196,7 @@ func (c *WalMartImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadI cdata := supplier.RedeemCardInfo{} err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata) if err != nil { - otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) + otelTrace.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"} } ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo.BankOrderId) @@ -232,16 +233,16 @@ type ResponseStruct struct { func (c *WalMartImpl) PayNotify() { ctx := c.Ctx.Request.Context() - otel.Logger.WithContext(ctx).Info("【沃尔玛】快付回调开始") + otelTrace.Logger.WithContext(ctx).Info("【沃尔玛】快付回调开始") response := ResponseStruct{} err := json.Unmarshal(c.Ctx.Input.RequestBody, &response) if err != nil { - otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("RequestBody", string(c.Ctx.Input.RequestBody))) + otelTrace.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("RequestBody", string(c.Ctx.Input.RequestBody))) c.Ctx.WriteString("fail") return } if c.notifyEncrypt(response, "0468b97dfd8747f5ad57e06a17e03c365ae3269d70c14db39ddea25e70d55bbf") != response.Sign { - otel.Logger.WithContext(ctx).Sugar().Errorf("【沃尔玛】快付回调失败,签名错误,参数=%s", string(c.Ctx.Input.RequestBody)) + otelTrace.Logger.WithContext(ctx).Sugar().Errorf("【沃尔玛】快付回调失败,签名错误,参数=%s", string(c.Ctx.Input.RequestBody)) c.Ctx.WriteString("fail") return } @@ -249,7 +250,7 @@ func (c *WalMartImpl) PayNotify() { merchantUid := orderInfo.MerchantUid merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid) if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 { - otel.Logger.WithContext(ctx).Sugar().Errorf("【沃尔玛】快付回调失败,该商户不存在或者已经删除,商户uid=%s\n", merchantUid) + otelTrace.Logger.WithContext(ctx).Sugar().Errorf("【沃尔玛】快付回调失败,该商户不存在或者已经删除,商户uid=%s\n", merchantUid) c.Ctx.WriteString("fail") return } @@ -291,23 +292,23 @@ func (c *WalMartImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo req := httplib.Post(url1) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -354,12 +355,12 @@ func (c *WalMartImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadIn req := httplib.Post(url1) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return supply_model.DataErr } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") @@ -369,7 +370,7 @@ func (c *WalMartImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadIn return supply_model.RemoteDataErr } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -419,25 +420,25 @@ func (c *WalMartImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) { req := httplib.Post(url1) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return config.PAYFOR_FAIL, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } @@ -474,7 +475,7 @@ func (c *WalMartImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) { } } - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } diff --git a/internal/service/supplier/third_party/walmart_self.go b/internal/service/supplier/third_party/walmart_self.go index 622e4f0..db795b4 100644 --- a/internal/service/supplier/third_party/walmart_self.go +++ b/internal/service/supplier/third_party/walmart_self.go @@ -7,7 +7,8 @@ import ( "encoding/base64" "encoding/json" "gateway/internal/config" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "gateway/internal/service/supplier" "net/http" @@ -73,22 +74,22 @@ func (c *WalmartSelfImpl) SendCard(ctx context.Context, jsonStr string, cardInfo // req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) return false, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") req.Header("tokenFrom", "iframe") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("沃尔玛请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("沃尔玛请求失败:", zap.Error(err)) return false, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return false, "" } type AutoGenerated struct { @@ -102,18 +103,18 @@ func (c *WalmartSelfImpl) SendCard(ctx context.Context, jsonStr string, cardInfo var resData AutoGenerated err = json.Unmarshal([]byte(response), &resData) if err != nil { - otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response)) + otelTrace.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response)) return false, "内部数据处理失败" } if resData.Code != 0 { - otel.Logger.WithContext(ctx).Error("充值错误", zap.String("Message", resData.Message)) + otelTrace.Logger.WithContext(ctx).Error("充值错误", zap.String("Message", resData.Message)) return false, resData.Message } return true, "等待兑换" } func (c *WalmartSelfImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData { - ctx, cancel := otel.Span(ctx, "WalmartSelfImpl", "Scan", trace.WithAttributes( + ctx, cancel := otelTrace.Span(ctx, "WalmartSelfImpl", "Scan", trace.WithAttributes( attribute.String("BankOrderId", orderInfo.BankOrderId), attribute.String("MerchantUid", orderInfo.MerchantUid), attribute.String("ExValue", orderInfo.ExValue), @@ -122,7 +123,7 @@ func (c *WalmartSelfImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, r cdata := supplier.RedeemCardInfo{} err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata) if err != nil { - otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) + otelTrace.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue)) return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"} } ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo.BankOrderId, orderInfo.MerchantOrderId) @@ -152,7 +153,7 @@ func (c *WalmartSelfImpl) kMEncrypt(kf, appSecret string) (string, error) { secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥 block, err := aes.NewCipher([]byte(secret)) if err != nil { - otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher") + otelTrace.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher") return "", err } // 数据填充 @@ -165,24 +166,24 @@ func (c *WalmartSelfImpl) kMEncrypt(kf, appSecret string) (string, error) { func (c *WalmartSelfImpl) PayNotify() { ctx := c.Ctx.Request.Context() - otel.Logger.WithContext(ctx).Info("【沃尔玛】回调开始") + otelTrace.Logger.WithContext(ctx).Info("【沃尔玛】回调开始") attach := strings.TrimSpace(c.GetString("merchantId")) orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 { - otel.Logger.WithContext(ctx).Error("【沃尔玛】回调的订单号不存在,订单号=", zap.String("attach", attach)) + otelTrace.Logger.WithContext(ctx).Error("【沃尔玛】回调的订单号不存在,订单号=", zap.String("attach", attach)) c.Ctx.WriteString("FAIL") return } roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid) if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 { - otel.Logger.WithContext(ctx).Error("【沃尔玛】支付通道已经关系或者删除,不进行回调") + otelTrace.Logger.WithContext(ctx).Error("【沃尔玛】支付通道已经关系或者删除,不进行回调") c.Ctx.WriteString("FAIL") return } merchantUid := orderInfo.MerchantUid merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid) if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 { - otel.Logger.WithContext(ctx).Error("【沃尔玛】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) + otelTrace.Logger.WithContext(ctx).Error("【沃尔玛】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid)) c.Ctx.WriteString("FAIL") return } @@ -194,7 +195,7 @@ func (c *WalmartSelfImpl) PayNotify() { //"sign": strings.TrimSpace(c.GetString("sign")), "remark": strings.TrimSpace(c.GetString("remark")), } - otel.Logger.WithContext(ctx).Info("【沃尔玛】回调参数:", zap.Any("params", params)) + otelTrace.Logger.WithContext(ctx).Info("【沃尔玛】回调参数:", zap.Any("params", params)) orderInfo.BankTransId = params["merchantId"] if params["status"] == "1" { // TODO 订单支付成功 @@ -239,22 +240,22 @@ func (c *WalmartSelfImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.Road req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return false } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { return false @@ -297,12 +298,12 @@ func (c *WalmartSelfImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Ro req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return supply_model.DataErr } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") @@ -312,7 +313,7 @@ func (c *WalmartSelfImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Ro return supply_model.RemoteDataErr } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) resData, err := sonic.GetFromString(response) if err != nil { @@ -363,25 +364,25 @@ func (c *WalmartSelfImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) req := httplib.Post(url) marshal, err := json.Marshal(params) if err != nil { - otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err)) // fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err)) return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)" } - otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) + otelTrace.Logger.WithContext(ctx).Info("请求参数:" + string(marshal)) req.Header("Content-Type", "application/json") req.Body(marshal) req.Header("Accept-Charset", "utf-8") response, err := req.String() if err != nil { - otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err)) return config.PAYFOR_FAIL, "" } - otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) + otelTrace.Logger.WithContext(ctx).Info("远端请求返回数据:" + response) if gojson.Json(response).Get("code").Tostring() == "" { - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } @@ -418,7 +419,7 @@ func (c *WalmartSelfImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) } } - otel.Logger.WithContext(ctx).Error("远程调用失败") + otelTrace.Logger.WithContext(ctx).Error("远程调用失败") return config.PAYFOR_BANKING, "" } diff --git a/internal/service/supplier/third_party/walmart_test.go b/internal/service/supplier/third_party/walmart_test.go index 1d6d673..1a2a232 100644 --- a/internal/service/supplier/third_party/walmart_test.go +++ b/internal/service/supplier/third_party/walmart_test.go @@ -6,7 +6,7 @@ import ( "gateway/internal/models/payfor" "gateway/internal/models/road" "gateway/internal/models/supply_model" - "gateway/internal/otel" + "gateway/internal/service/supplier" "reflect" "testing" @@ -1802,6 +1802,6 @@ func TestWalMartImpl_SendCard1(t *testing.T) { Data: "123", CardNo: "123", }, "12345") - otel.Logger.WithContext(ctx).Info(isOk, response) + otelTrace.Logger.WithContext(ctx).Info(isOk, response) } diff --git a/internal/swagger/swagger.json b/internal/swagger/swagger.json index fb1a902..424754d 100644 --- a/internal/swagger/swagger.json +++ b/internal/swagger/swagger.json @@ -1,7 +1,7 @@ { - "swagger": "2.0", - "info": { - "contact": {} - }, - "paths": null + "swagger": "2.0", + "info": { + "contact": {} + }, + "paths": null } \ No newline at end of file diff --git a/internal/swagger/swagger.yml b/internal/swagger/swagger.yml index 44e767c..17ca1c6 100644 --- a/internal/swagger/swagger.yml +++ b/internal/swagger/swagger.yml @@ -1,3 +1,3 @@ swagger: "2.0" -info: {} -paths: {} +info: { } +paths: { } diff --git a/internal/utils/AES_ECB.go b/internal/utils/AES_ECB.go index 8b25e79..9a9a906 100644 --- a/internal/utils/AES_ECB.go +++ b/internal/utils/AES_ECB.go @@ -6,7 +6,7 @@ import ( "crypto/aes" "crypto/cipher" "encoding/hex" - "gateway/internal/otel" + "gateway/internal/otelTrace" "go.uber.org/zap" ) @@ -14,7 +14,7 @@ import ( func AesDecrypt(ctx context.Context, src, key []byte) []byte { block, err := aes.NewCipher(key) if err != nil { - otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher", zap.Error(err)) } blockMode := NewECBDecrypter(block) origData := make([]byte, len(src)) @@ -27,14 +27,14 @@ func AesDecrypt(ctx context.Context, src, key []byte) []byte { func AesEncrypt(ctx context.Context, src []byte, key string) []byte { decodeString, err := hex.DecodeString(key) if err != nil { - otel.Logger.WithContext(ctx).Error("Joker: AesEncrypt failed to hex key", zap.Error(err)) + otelTrace.Logger.WithContext(ctx).Error("Joker: AesEncrypt failed to hex key", zap.Error(err)) } block, err := aes.NewCipher(decodeString) if err != nil { - otel.Logger.WithContext(ctx).Error("Joker: AesEncrypt failed to NewCipher") + otelTrace.Logger.WithContext(ctx).Error("Joker: AesEncrypt failed to NewCipher") } if len(src) < 0 { - otel.Logger.WithContext(ctx).Error("Joker: AesEncrypt`s input is null ") + otelTrace.Logger.WithContext(ctx).Error("Joker: AesEncrypt`s input is null ") } ecb := NewECBEncrypter(block) src = PKCS5Padding(src, block.BlockSize()) diff --git a/internal/utils/bank.go b/internal/utils/bank.go index 8c39cb1..42dd5cc 100644 --- a/internal/utils/bank.go +++ b/internal/utils/bank.go @@ -2,7 +2,7 @@ package utils import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" "github.com/beego/beego/v2/client/httplib" "github.com/widuu/gojson" @@ -21,11 +21,11 @@ func GetBankCodeByBankCardNo(ctx context.Context, bankCardNo string) string { request := httplib.Get(bUrl) s, err := request.String() if err != nil { - otel.Logger.WithContext(ctx).Error("获取银行信息失败:" + err.Error()) + otelTrace.Logger.WithContext(ctx).Error("获取银行信息失败:" + err.Error()) return "" } - otel.Logger.WithContext(ctx).Info("获取到银行信息为:" + s) + otelTrace.Logger.WithContext(ctx).Info("获取到银行信息为:" + s) code := gojson.Json(s).Get("bank").Tostring() return code } diff --git a/internal/utils/sign_verify.go b/internal/utils/sign_verify.go index 1d05153..08dc541 100644 --- a/internal/utils/sign_verify.go +++ b/internal/utils/sign_verify.go @@ -2,7 +2,8 @@ package utils import ( "context" - "gateway/internal/otel" + "gateway/internal/otelTrace" + "sort" "strings" @@ -59,7 +60,7 @@ func Md5MFVerify(ctx context.Context, params map[string]any, paySecret string) b delete(paramsCopy, "deviceId") delete(paramsCopy, "ip") tmpSign := GetMD5SignMF(paramsCopy, paySecret) - otel.Logger.WithContext(ctx).Info("signStr=%s tmpStr=%s, %s", zap.String("signStr", tmpSign), zap.Any("tmpStr", sign), zap.Bool("sign!=tmpSign", tmpSign != sign)) + otelTrace.Logger.WithContext(ctx).Info("signStr=%s tmpStr=%s, %s", zap.String("signStr", tmpSign), zap.Any("tmpStr", sign), zap.Bool("sign!=tmpSign", tmpSign != sign)) return tmpSign == sign } @@ -77,7 +78,7 @@ func Md5TMPMFVerify(ctx context.Context, params map[string]any, paySecret string delete(paramsCopy, "sign") delete(paramsCopy, "deviceId") tmpSign := GetMD5SignMF(paramsCopy, paySecret) - otel.Logger.WithContext(ctx).Info("signStr=%s tmpStr=%s, %s", zap.String("signStr", tmpSign), zap.Any("tmpStr", sign), zap.Bool("sign!=tmpSign", tmpSign != sign)) + otelTrace.Logger.WithContext(ctx).Info("signStr=%s tmpStr=%s, %s", zap.String("signStr", tmpSign), zap.Any("tmpStr", sign), zap.Bool("sign!=tmpSign", tmpSign != sign)) return tmpSign == sign } diff --git a/main.go b/main.go index c7e953d..2f714b9 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,7 @@ package main import ( _ "gateway/internal/models" - "gateway/internal/otel" + "gateway/internal/otelTrace" _ "gateway/internal/routers" "gateway/internal/schema/query" "gateway/internal/service" @@ -16,22 +16,22 @@ import ( ) func main() { - cleanup1, cleanup2, cleanup3 := otel.InitTracer() + cleanup1, cleanup2, cleanup3 := otelTrace.InitTracer() defer func() { if cleanup1 != nil { - _ = cleanup1(otel.InitCtx) + _ = cleanup1(otelTrace.InitCtx) } if cleanup2 != nil { - _ = cleanup2(otel.InitCtx) + _ = cleanup2(otelTrace.InitCtx) } if cleanup3 != nil { - _ = cleanup3(otel.InitCtx) + _ = cleanup3(otelTrace.InitCtx) } }() - go notify.CreateOrderNotifyConsumer(otel.InitCtx) - go query.CreatePayForQueryConsumer(otel.InitCtx) - go service.OrderSettleInit(otel.InitCtx) - go query.CreateSupplierOrderQueryCuConsumer(otel.InitCtx) - otel.Logger.WithContext(otel.InitCtx).Info("gateway start") + go notify.CreateOrderNotifyConsumer(otelTrace.InitCtx) + go query.CreatePayForQueryConsumer(otelTrace.InitCtx) + go service.OrderSettleInit(otelTrace.InitCtx) + go query.CreateSupplierOrderQueryCuConsumer(otelTrace.InitCtx) + otelTrace.Logger.WithContext(otelTrace.InitCtx).Info("gateway start") web.Run() }