From 386ac29ad777f11332fdc181c8e7f4461e99442c Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 2 Nov 2018 14:11:32 +0800 Subject: [PATCH] - TrimBlanChar to TrimBlankChar - error_code.go --- business/jxcallback/auth/auth.go | 3 ++- business/jxutils/jxcontext/jxcontext.go | 9 ++++----- business/jxutils/jxutils_cms.go | 4 ++-- business/model/error_code.go | 15 +++++++++++++++ business/partner/purchase/ebai/order.go | 2 +- business/partner/purchase/ebai/store_sku.go | 2 +- business/partner/purchase/elm/order.go | 2 +- business/partner/purchase/jd/order.go | 2 +- controllers/financial.go | 3 ++- controllers/jx_order.go | 3 ++- 10 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 business/model/error_code.go diff --git a/business/jxcallback/auth/auth.go b/business/jxcallback/auth/auth.go index f0bfad663..6e18d40de 100644 --- a/business/jxcallback/auth/auth.go +++ b/business/jxcallback/auth/auth.go @@ -5,6 +5,7 @@ import ( "time" "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/globals" ) @@ -76,5 +77,5 @@ func GetUserInfo(token string) (loginInfo *LoginInfo, err error) { if err = globals.Cacher.GetAs(token, loginInfo); err == nil { return loginInfo, nil } - return nil, errors.New("token过期或无效,请重新登录") + return nil, model.ErrTokenIsInvalid } diff --git a/business/jxutils/jxcontext/jxcontext.go b/business/jxutils/jxcontext/jxcontext.go index c7f171bd9..f8ad250a8 100644 --- a/business/jxutils/jxcontext/jxcontext.go +++ b/business/jxutils/jxcontext/jxcontext.go @@ -6,8 +6,7 @@ import ( "git.rosy.net.cn/jx-callback/business/jxcallback/auth" "git.rosy.net.cn/jx-callback/business/jxutils/tasksch" - "git.rosy.net.cn/jx-callback/globals" - "github.com/astaxie/beego" + "git.rosy.net.cn/jx-callback/business/model" ) type Context struct { @@ -52,9 +51,9 @@ func New(rootTask tasksch.ITask, token string, w http.ResponseWriter, r *http.Re mapData: make(map[interface{}]interface{}), } ctx.userInfo, err = auth.GetUserInfo(token) - if err != nil && beego.BConfig.RunMode == "prod" { - globals.SugarLogger.Warnf("token is invalid, token:%s", token) - // return nil, "", err + if err != nil { + // globals.SugarLogger.Warnf("token is invalid, token:%s", token) + return nil, model.ErrCodeTokenIsInvalid, err } return ctx, "", nil } diff --git a/business/jxutils/jxutils_cms.go b/business/jxutils/jxutils_cms.go index 4832690cf..1f2fb00c5 100644 --- a/business/jxutils/jxutils_cms.go +++ b/business/jxutils/jxutils_cms.go @@ -62,11 +62,11 @@ func SplitStoreName(fullName, separator, defaultPrefix string) (prefix, bareName bareName = strings.Trim(strings.Trim(fullName, defaultPrefix), separator) } - return utils.TrimBlanChar(defaultPrefix), utils.TrimBlanChar(bareName) + return utils.TrimBlankChar(defaultPrefix), utils.TrimBlankChar(bareName) } func ComposeStoreName(bareName, separator, prefix string) (fullName string) { - return prefix + separator + utils.TrimBlanChar(strings.Trim(bareName, separator)) + return prefix + separator + utils.TrimBlankChar(strings.Trim(bareName, separator)) } func StrTime2JxOperationTime(strTime string, defValue int16) int16 { diff --git a/business/model/error_code.go b/business/model/error_code.go new file mode 100644 index 000000000..1b2f89cab --- /dev/null +++ b/business/model/error_code.go @@ -0,0 +1,15 @@ +package model + +import "errors" + +const ( + ErrorCodeIgnore = "ignore" + + ErrCodeSuccess = "0" + ErrCodeGeneralFailed = "-1" + ErrCodeTokenIsInvalid = "-2" +) + +var ( + ErrTokenIsInvalid = errors.New("token过期或无效,请重新登录") +) diff --git a/business/partner/purchase/ebai/order.go b/business/partner/purchase/ebai/order.go index e26bb982e..20d1f433f 100644 --- a/business/partner/purchase/ebai/order.go +++ b/business/partner/purchase/ebai/order.go @@ -47,7 +47,7 @@ func (p *PurchaseHandler) GetOrder(vendorOrderID string) (order *model.GoodsOrde ConsigneeMobile: userMap["phone"].(string), ConsigneeAddress: userMap["address"].(string), CoordinateType: model.CoordinateTypeBaiDu, - BuyerComment: utils.TrimBlanChar(utils.Interface2String(orderMap["remark"])), + BuyerComment: utils.TrimBlankChar(utils.Interface2String(orderMap["remark"])), ExpectedDeliveredTime: getTimeFromTimestampStr(utils.Interface2String(orderMap["send_time"])), VendorStatus: utils.Int64ToStr(utils.MustInterface2Int64(orderMap["status"])), OrderSeq: int(utils.Str2Int64(utils.Interface2String(orderMap["order_index"]))), diff --git a/business/partner/purchase/ebai/store_sku.go b/business/partner/purchase/ebai/store_sku.go index 1f2977110..9ad4d1853 100644 --- a/business/partner/purchase/ebai/store_sku.go +++ b/business/partner/purchase/ebai/store_sku.go @@ -477,7 +477,7 @@ func (p *PurchaseHandler) updateLocalCatAsNew(db *dao.DaoDB, localCatMap map[str } func formatName(name string) string { - return utils.TrimBlanChar(utils.FilterMb4(name)) + return utils.TrimBlankChar(utils.FilterMb4(name)) } // 饿百的排序是从大到小 diff --git a/business/partner/purchase/elm/order.go b/business/partner/purchase/elm/order.go index e4eb221a8..21ac0a876 100644 --- a/business/partner/purchase/elm/order.go +++ b/business/partner/purchase/elm/order.go @@ -139,7 +139,7 @@ func (c *PurchaseHandler) GetOrder(orderID string) (order *model.GoodsOrder, err ConsigneeName: result["consignee"].(string), ConsigneeMobile: consigneeMobile, ConsigneeAddress: result["address"].(string), - BuyerComment: utils.TrimBlanChar(utils.Interface2String(result["description"])), + BuyerComment: utils.TrimBlankChar(utils.Interface2String(result["description"])), ExpectedDeliveredTime: utils.Str2TimeWithDefault(utils.Interface2String(result["deliverTime"]), utils.DefaultTimeValue), VendorStatus: utils.Interface2String(result["status"]), // 取订单的原始status,不合并消息类型(因为当前消息类型没有意义) OrderSeq: int(utils.MustInterface2Int64(result["daySn"])), diff --git a/business/partner/purchase/jd/order.go b/business/partner/purchase/jd/order.go index 369b3b93a..2580c197a 100644 --- a/business/partner/purchase/jd/order.go +++ b/business/partner/purchase/jd/order.go @@ -72,7 +72,7 @@ func (c *PurchaseHandler) GetOrder(orderID string) (order *model.GoodsOrder, err ConsigneeMobile: result["buyerMobile"].(string), ConsigneeAddress: result["buyerFullAddress"].(string), CoordinateType: model.CoordinateTypeMars, - BuyerComment: utils.TrimBlanChar(utils.Interface2String(result["orderBuyerRemark"])), + BuyerComment: utils.TrimBlankChar(utils.Interface2String(result["orderBuyerRemark"])), ExpectedDeliveredTime: utils.Str2TimeWithDefault(utils.Interface2String(result["orderPreEndDeliveryTime"]), utils.DefaultTimeValue), VendorStatus: utils.Int64ToStr(utils.MustInterface2Int64(result["orderStatus"])), OrderSeq: int(utils.MustInterface2Int64(result["orderNum"])), diff --git a/controllers/financial.go b/controllers/financial.go index 4f3dcce21..2f5077644 100644 --- a/controllers/financial.go +++ b/controllers/financial.go @@ -7,6 +7,7 @@ import ( "github.com/astaxie/beego" "git.rosy.net.cn/jx-callback/business/jxstore/financial" + "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model/legacymodel" ) @@ -85,7 +86,7 @@ func (c *FinancialController) ShowStoreLatestBill() { htmlResult = fmt.Sprintf(html, bills[0].Url) } err2 = err - return retVal, ignoreCode, err + return retVal, model.ErrorCodeIgnore, err }) if htmlResult != "" { io.WriteString(w, htmlResult) diff --git a/controllers/jx_order.go b/controllers/jx_order.go index 671a11be8..1a0b58073 100644 --- a/controllers/jx_order.go +++ b/controllers/jx_order.go @@ -8,6 +8,7 @@ import ( "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxcallback/orderman" "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch" + "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/globals" "github.com/astaxie/beego" ) @@ -186,7 +187,7 @@ func (c *OrderController) ExportMTWaybills() { } content, err = orderman.FixedOrderManager.ExportMTWaybills(params.Ctx, params.FromDate, params.ToDate) globals.SugarLogger.Debug(err) - return retVal, ignoreCode, err + return retVal, model.ErrorCodeIgnore, err }) if content != nil { c.Ctx.ResponseWriter.Header().Set("Content-Type", "application/vnd.ms-excel")