- UpdateStore中,如果只是本地属性变更,不需要同步

This commit is contained in:
gazebo
2019-06-12 17:38:49 +08:00
parent 2bf8e2fab9
commit 4e2d2321a9

View File

@@ -73,6 +73,24 @@ var (
"虞山街道": "虞山镇", "虞山街道": "虞山镇",
"常福街道": "虞山镇", "常福街道": "虞山镇",
} }
storeKeyPropertyMap = map[string]int{
"name": 1,
"cityCode": 1,
"districtCode": 1,
"address": 1,
"tel1": 1,
"tel2": 1,
"openTime1": 1,
"closeTime1": 1,
"openTime2": 1,
"closeTime2": 1,
"lng": 1,
"lat": 1,
"deliveryRangeType": 1,
"deliveryRange": 1,
"status": 1,
}
) )
// todo 门店绑定信息可以考虑以数组形式返回,而不是现在这样 // todo 门店绑定信息可以考虑以数组形式返回,而不是现在这样
@@ -412,6 +430,15 @@ func GetVendorStore(ctx *jxcontext.Context, vendorStoreID string, vendorID int)
return nil, ErrCanNotFindVendor return nil, ErrCanNotFindVendor
} }
func isUpdateStoreNeedSync(valid map[string]interface{}) bool {
for k := range valid {
if storeKeyPropertyMap[k] == 1 {
return true
}
}
return false
}
func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interface{}, userName string) (num int64, err error) { func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interface{}, userName string) (num int64, err error) {
globals.SugarLogger.Debugf("UpdateStore storeID:%d, payload:%s", storeID, utils.Format4Output(payload, false)) globals.SugarLogger.Debugf("UpdateStore storeID:%d, payload:%s", storeID, utils.Format4Output(payload, false))
@@ -505,6 +532,7 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
dao.Rollback(db) dao.Rollback(db)
}() }()
if num, err = dao.UpdateEntityLogically(db, store, valid, userName, nil); err == nil && num == 1 { if num, err = dao.UpdateEntityLogically(db, store, valid, userName, nil); err == nil && num == 1 {
if isUpdateStoreNeedSync(valid) {
dummy := &model.StoreMap{} dummy := &model.StoreMap{}
_, err2 := dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, dummy, nil, userName, map[string]interface{}{ _, err2 := dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, dummy, nil, userName, map[string]interface{}{
model.FieldStoreID: store.ID, model.FieldStoreID: store.ID,
@@ -514,6 +542,9 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
globals.SugarLogger.Debugf("UpdateStore track:%s, before call SyncStore", ctx.GetTrackInfo()) globals.SugarLogger.Debugf("UpdateStore track:%s, before call SyncStore", ctx.GetTrackInfo())
_, err = CurVendorSync.SyncStore(ctx, db, -1, store.ID, false, userName) _, err = CurVendorSync.SyncStore(ctx, db, -1, store.ID, false, userName)
} }
} else {
dao.Commit(db)
}
} }
} else { } else {
globals.SugarLogger.Debugf("UpdateStore track:%s, store:%s", ctx.GetTrackInfo(), utils.Format4Output(store, true)) globals.SugarLogger.Debugf("UpdateStore track:%s, store:%s", ctx.GetTrackInfo(), utils.Format4Output(store, true))