添加API SyncStoresCourierInfo

This commit is contained in:
gazebo
2019-10-11 16:12:09 +08:00
parent 7946ab6207
commit 470f54f705
9 changed files with 124 additions and 7 deletions

View File

@@ -273,7 +273,7 @@ func setStoreMapInfo(ctx *jxcontext.Context, db *dao.DaoDB, storesInfo *StoresIn
if err != nil {
return err
}
storeCourierList, err := dao.GetStoreCourierList(db, storeIDs, model.StoreStatusAll)
storeCourierList, err := dao.GetStoreCourierList(db, storeIDs, model.StoreStatusAll, model.StoreAuditStatusAll)
if err != nil {
return err
}
@@ -1873,6 +1873,85 @@ func SaveAndSendAlarmVendorSnapshot(ctx *jxcontext.Context, vendorIDs, storeIDs
return err
}
func SyncStoresCourierInfo(ctx *jxcontext.Context, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
db := dao.GetDB()
storeList2, err := dao.GetStoreList(db, storeIDs, nil, "")
var storeList []*model.Store
for _, v := range storeList2 {
if v.Status != model.StoreStatusDisabled {
storeList = append(storeList, v)
}
}
if err == nil && len(storeList) > 0 {
task := tasksch.NewParallelTask(fmt.Sprintf("同步门店快递信息1:%v", storeIDs),
tasksch.NewParallelConfig().SetParallelCount(2).SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
store := batchItemList[0].(*model.Store)
subTask := tasksch.NewParallelTask(fmt.Sprintf("同步门店快递信息2:%d", store.ID),
tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
vendorID := batchItemList[0].(int)
storeDetail2, err := dao.GetStoreDetail2(db, store.ID, "", vendorID)
if err == nil && storeDetail2.VendorStoreID != "" && storeDetail2.CourierStatus != model.StoreStatusDisabled {
if handler := partner.GetDeliveryPlatformFromVendorID(vendorID); handler != nil {
if updateHandler, ok := handler.Handler.(partner.IDeliveryUpdateStoreHandler); ok {
updateHandler.UpdateStore(ctx, storeDetail2)
}
storeCourier, err2 := handler.Handler.GetStore(ctx, store.ID, storeDetail2.VendorStoreID)
if err = err2; err == nil {
if storeDetail2.AuditStatus == model.StoreAuditStatusCreated { // 如果已经通过审核,更新本地状态
partner.CurStoreManager.OnCourierStoreStatusChanged(ctx, storeCourier.VendorStoreID, vendorID, storeCourier.AuditStatus)
}
distance := jxutils.EarthDistance(jxutils.IntCoordinate2Standard(store.Lng), jxutils.IntCoordinate2Standard(store.Lat), jxutils.IntCoordinate2Standard(storeCourier.Lng), jxutils.IntCoordinate2Standard(storeCourier.Lat))
params := map[string]interface{}{
"Lng": storeCourier.Lng,
"Lat": storeCourier.Lat,
"Remark": fmt.Sprintf("%d", int(distance*1000)),
}
_, err = dao.UpdateEntityLogically(dao.GetDB(), &model.StoreCourierMap{}, params, ctx.GetUserName(), map[string]interface{}{
"StoreID": store.ID,
"VendorID": vendorID,
})
if distance > 0.2 {
globals.SugarLogger.Infof("SyncStoresCourierInfo [运营2]门店:%s-%d的%s配送门店坐标不一致,京西:%d,%d,平台:%d,%d,距离:%f公里", store.Name, store.ID, model.VendorChineseNames[vendorID], store.Lng, store.Lat, storeCourier.Lng, storeCourier.Lat, distance)
retVal = [][]interface{}{
[]interface{}{
store,
storeDetail2,
},
}
}
} else if handler.Handler.IsErrStoreNotExist(err) {
if storeDetail2.AuditStatus == model.StoreAuditStatusCreated {
err = nil
} else {
globals.SugarLogger.Infof("SyncStoresCourierInfo [运营2]门店:%s-%d的%s配送门店%s获取出错:%v", store.Name, store.ID, model.VendorChineseNames[vendorID], storeDetail2.VendorStoreID, err)
}
}
}
} else if dao.IsNoRowsError(err) {
err = nil
}
return retVal, err
}, partner.UseableDeliveryVendorIDs)
tasksch.HandleTask(subTask, task, true).Run()
retVal, err = subTask.GetResult(0)
return retVal, err
}, storeList)
tasksch.HandleTask(task, nil, true).Run()
if isAsync {
hint = task.GetID()
} else {
resultList, err2 := task.GetResult(0)
if err = err2; err == nil {
hint = utils.Int2Str(len(resultList))
}
}
}
return hint, err
}
func SyncStoresQualify(ctx *jxcontext.Context, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
if len(storeIDs) > 0 {
db := dao.GetDB()