- refactor jxcontent and tasksch (remove dependency from jxcontent to tasksch)
- send dingding msg to user when async task finished
This commit is contained in:
@@ -750,40 +750,40 @@ func RefreshMissingDadaStores(ctx *jxcontext.Context, storeID int, isAsync, isCo
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
task := tasksch.NewParallelTask("RefreshMissingDadaStores", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx.GetUserName(), func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeDetail := batchItemList[0].(*dao.StoreDetail2)
|
||||
_, err = api.DadaAPI.ShopDetail(utils.Int2Str(storeDetail.ID))
|
||||
if err != nil {
|
||||
if codeErr, ok := err.(*utils.ErrorWithCode); ok && codeErr.IntCode() == dadaapi.ResponseCodeShopNotExist {
|
||||
_, err = api.DadaAPI.ShopAdd(utils.Int2Str(storeDetail.ID), composeDadaStoreName(storeDetail), dadaapi.BusinessTypeConvStore, storeDetail.CityName,
|
||||
storeDetail.DistrictName, storeDetail.Address, jxutils.IntCoordinate2Standard(storeDetail.Lng), jxutils.IntCoordinate2Standard(storeDetail.Lat),
|
||||
storeDetail.Tel1, storeDetail.Tel1, nil)
|
||||
task := tasksch.NewParallelTask("RefreshMissingDadaStores", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeDetail := batchItemList[0].(*dao.StoreDetail2)
|
||||
_, err = api.DadaAPI.ShopDetail(utils.Int2Str(storeDetail.ID))
|
||||
if err != nil {
|
||||
if codeErr, ok := err.(*utils.ErrorWithCode); ok && codeErr.IntCode() == dadaapi.ResponseCodeShopNotExist {
|
||||
_, err = api.DadaAPI.ShopAdd(utils.Int2Str(storeDetail.ID), composeDadaStoreName(storeDetail), dadaapi.BusinessTypeConvStore, storeDetail.CityName,
|
||||
storeDetail.DistrictName, storeDetail.Address, jxutils.IntCoordinate2Standard(storeDetail.Lng), jxutils.IntCoordinate2Standard(storeDetail.Lat),
|
||||
storeDetail.Tel1, storeDetail.Tel1, nil)
|
||||
}
|
||||
} else {
|
||||
params := map[string]interface{}{
|
||||
"station_name": composeDadaStoreName(storeDetail),
|
||||
"business": dadaapi.BusinessTypeConvStore,
|
||||
"city_name": storeDetail.CityName,
|
||||
"area_name": storeDetail.DistrictName,
|
||||
"station_address": storeDetail.Address,
|
||||
"lng": jxutils.IntCoordinate2Standard(storeDetail.Lng),
|
||||
"lat": jxutils.IntCoordinate2Standard(storeDetail.Lat),
|
||||
"contact_name": storeDetail.Tel1,
|
||||
"phone": storeDetail.Tel1,
|
||||
}
|
||||
err = api.DadaAPI.ShopUpdate(utils.Int2Str(storeDetail.ID), params)
|
||||
}
|
||||
} else {
|
||||
params := map[string]interface{}{
|
||||
"station_name": composeDadaStoreName(storeDetail),
|
||||
"business": dadaapi.BusinessTypeConvStore,
|
||||
"city_name": storeDetail.CityName,
|
||||
"area_name": storeDetail.DistrictName,
|
||||
"station_address": storeDetail.Address,
|
||||
"lng": jxutils.IntCoordinate2Standard(storeDetail.Lng),
|
||||
"lat": jxutils.IntCoordinate2Standard(storeDetail.Lat),
|
||||
"contact_name": storeDetail.Tel1,
|
||||
"phone": storeDetail.Tel1,
|
||||
if err == nil {
|
||||
db := dao.GetDB()
|
||||
_, err = AddStoreCourierMap(ctx, db, storeDetail.ID, model.VendorIDDada, &model.StoreCourierMap{
|
||||
VendorStoreID: utils.Int2Str(storeDetail.ID),
|
||||
Status: model.StoreStatusOpened,
|
||||
})
|
||||
}
|
||||
err = api.DadaAPI.ShopUpdate(utils.Int2Str(storeDetail.ID), params)
|
||||
}
|
||||
if err == nil {
|
||||
db := dao.GetDB()
|
||||
_, err = AddStoreCourierMap(ctx, db, storeDetail.ID, model.VendorIDDada, &model.StoreCourierMap{
|
||||
VendorStoreID: utils.Int2Str(storeDetail.ID),
|
||||
Status: model.StoreStatusOpened,
|
||||
})
|
||||
}
|
||||
return nil, err
|
||||
}, storeList)
|
||||
ctx.SetTaskOrAddChild(task, nil)
|
||||
tasksch.ManageTask(task).Run()
|
||||
return nil, err
|
||||
}, storeList)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
hint = task.ID
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
|
||||
Reference in New Issue
Block a user