- 重构RefreshOrderRealMobile

This commit is contained in:
gazebo
2019-03-28 15:09:23 +08:00
parent cd99fc3e14
commit 24af4bc330
8 changed files with 78 additions and 63 deletions

View File

@@ -2,7 +2,6 @@ package ebai
import (
"math"
"strings"
"time"
"git.rosy.net.cn/baseapi/platformapi/autonavi"
@@ -11,7 +10,6 @@ import (
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/partner"
@@ -339,46 +337,7 @@ func getTimeFromInterface(timeValue interface{}) time.Time {
return utils.Timestamp2Time(timeStamp)
}
func (c *PurchaseHandler) RefreshRealMobile(ctx *jxcontext.Context, fromTime, toTime time.Time, isAsync, isContinueWhenError bool) (hint string, err error) {
sql := `
SELECT *
FROM goods_order
WHERE vendor_id = ? AND consignee_mobile2 = '' AND order_created_at <= ?
`
sqlParams := []interface{}{
model.VendorIDEBAI,
time.Now().Add(-4 * time.Hour),
}
if !utils.IsTimeZero(fromTime) {
sql += " AND order_created_at >= ?"
sqlParams = append(sqlParams, fromTime)
}
if !utils.IsTimeZero(toTime) {
sql += " AND order_created_at <= ?"
sqlParams = append(sqlParams, toTime)
}
var orderList []*model.GoodsOrder
db := dao.GetDB()
if err = dao.GetRows(db, &orderList, sql, sqlParams...); err == nil && len(orderList) > 0 {
task := tasksch.NewParallelTask("ebai RefreshRealMobile", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
order := batchItemList[0].(*model.GoodsOrder)
mobile, err2 := api.EbaiAPI.GetRealMobile4Order(order.VendorOrderID)
if err = err2; err == nil {
if !jxutils.IsMobileFake(mobile) && strings.Index(order.ConsigneeMobile, mobile) == -1 {
order.ConsigneeMobile2 = mobile
_, err = dao.UpdateEntity(db, order, "ConsigneeMobile2")
}
} else {
globals.SugarLogger.Infof("RefreshRealMobile orderID:%s failed with error:%v", order.VendorOrderID, err)
}
return nil, err
}, orderList)
tasksch.HandleTask(task, nil, true).Run()
hint = task.ID
if !isAsync {
_, err = task.GetResult(0)
}
}
return hint, err
func (c *PurchaseHandler) GetOrderRealMobile(ctx *jxcontext.Context, order *model.GoodsOrder) (mobile string, err error) {
mobile, err = api.EbaiAPI.GetRealMobile4Order(order.VendorOrderID)
return mobile, err
}