Merge branch 'master' into get-store

This commit is contained in:
gazebo
2019-06-24 10:17:56 +08:00
127 changed files with 9409 additions and 2126 deletions

View File

@@ -8,6 +8,7 @@ import (
"time"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
"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"
@@ -47,11 +48,10 @@ func RefreshRealMobile(ctx *jxcontext.Context, vendorID int, fromTime, toTime ti
sql := `
SELECT *
FROM goods_order
WHERE vendor_id = ? AND consignee_mobile2 = '' AND order_created_at <= ?
WHERE vendor_id = ? AND consignee_mobile2 = ''
`
sqlParams := []interface{}{
vendorID,
time.Now().Add(-4 * time.Hour), // 最近的刷新意义不大
}
if !utils.IsTimeZero(fromTime) {
sql += " AND order_created_at >= ?"
@@ -97,29 +97,6 @@ func StartGetCityStoreInfo() {
}
cityCenters = append(cityCenters, guiyang)
GetCityStoreInfo(cityCenters)
// countries, err := api.AutonaviAPI.GetDistricts(2, "")
// if err == nil {
// cityCenters := make([]*CityCenter, 0)
// country := countries[0]
// districts := country.Districts
// for _, province := range districts { // 省
// for _, city := range province.Districts { // 市
// // globals.SugarLogger.Debug(utils.Format4Output(city.Name, false))
// cityCenter := &CityCenter{
// Lng: city.Lng,
// Lat: city.Lat,
// CityName: city.Name,
// }
// // globals.SugarLogger.Debug(utils.Format4Output(cityCenter, false))
// cityCenters = append(cityCenters, cityCenter)
// }
// }
// // globals.SugarLogger.Debug(utils.Format4Output(cityCenters, false))
// GetCityStoreInfo(cityCenters)
// }
// utils.AfterFuncWithRecover(12*time.Hour, func() {
// StartGetCityStoreInfo()
// })
}
func GetCityStoreInfo(cityCenters []*CityCenter) {
@@ -233,63 +210,6 @@ func SaveEbaiStoreInfo(storeId, cityName string) {
}
}
// func GetCityStoreInfo(cityCenters []*CityCenter, i int) {
// cityCenter := cityCenters[i]
// cityPoints := GetCityPoints(cityCenter.lng, cityCenter.lat)
// GetJdCityPointsStores(jxcontext.AdminCtx, cityPoints, true, true)
// utils.AfterFuncWithRecover(10*time.Minute, func() {
// GetEbaiCityPointsStores(jxcontext.AdminCtx, cityPoints, true, true)
// utils.AfterFuncWithRecover(10*time.Minute, func() {
// i++
// if i < len(cityCenters) {
// GetCityStoreInfo(cityCenters, i)
// }
// })
// })
// }
// func GetJdCityPointsStores(ctx *jxcontext.Context, cityPoints [][]string, isAsync, isContinueWhenError bool) (hint string, err error) {
// if len(cityPoints) > 0 {
// task := tasksch.NewParallelTask("misc GetJdCityPointsStores", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
// // globals.SugarLogger.Debug(batchItemList)
// point := batchItemList[0].([]string)
// err2 := jd.OnSaveStoreListInfo(point[0], point[1])
// if err = err2; err != nil {
// globals.SugarLogger.Infof("GetJdCityPointsStores point:%s,%s failed with error:%v", point[0], point[1], err)
// }
// return nil, err
// }, cityPoints)
// // globals.SugarLogger.Debug(utils.Format4Output(task, false))
// tasksch.HandleTask(task, nil, true).Run()
// hint = task.ID
// if !isAsync {
// _, err = task.GetResult(0)
// }
// }
// return hint, err
// }
// func GetEbaiCityPointsStores(ctx *jxcontext.Context, cityPoints [][]string, isAsync, isContinueWhenError bool) (hint string, err error) {
// if len(cityPoints) > 0 {
// task := tasksch.NewParallelTask("misc GetEbaiCityPointsStores", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
// point := batchItemList[0].([]interface{})
// err2 := ebai.OnSaveStoreListInfo(point[0].(string), point[1].(string))
// if err = err2; err != nil {
// globals.SugarLogger.Infof("GetEbaiCityPointsStores point:%s,%s failed with error:%v", point[0].(string), point[1].(string), err)
// }
// return nil, err
// }, cityPoints)
// tasksch.HandleTask(task, nil, true).Run()
// hint = task.ID
// if !isAsync {
// _, err = task.GetResult(0)
// }
// }
// return hint, err
// }
func GetCityPoints(lng float64, lat float64, cityName string) (cityPoints [][]string) {
oneDu := 111319.55
for a := 0; a <= 80; a++ {
@@ -309,3 +229,25 @@ func GetCityPoints(lng float64, lat float64, cityName string) (cityPoints [][]st
}
return cityPoints
}
func StartDailyWork() {
if globals.ReallyCallPlatformAPI {
now := time.Now()
runTime := time.Date(now.Year(), now.Month(), now.Day(), 21, 0, 0, 0, time.Local) // 凌晨00:25点开始执行
waitDuration := runTime.Sub(now)
if waitDuration < 5*time.Second {
waitDuration += 24 * time.Hour
}
globals.SugarLogger.Debugf("dailyWork waitDuration:%d minutes", waitDuration/time.Minute)
utils.AfterFuncWithRecover(waitDuration, func() {
doDailyWork()
StartDailyWork()
})
}
}
func doDailyWork() {
globals.SugarLogger.Debug("doDailyWork")
cms.EnableHaveRestStores(jxcontext.AdminCtx, true, true)
// cms.CurVendorSync.FullSyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, true, true)
cms.CurVendorSync.SyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD, model.VendorIDEBAI, model.VendorIDMTWM}, nil, nil, false, true, true)
}