diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 7e49921c7..ebfd2534d 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -381,36 +381,55 @@ func DeleteStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor } func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, payload map[string]interface{}, userName string) (num int64, err error) { + storeHandler := CurVendorSync.GetStoreHandler(vendorID) + if storeHandler == nil { + return 0, ErrCanNotFindVendor + } if db == nil { db = dao.GetDB() } if vendorStoreID := utils.Interface2String(payload["vendorStoreID"]); vendorStoreID != "" { - if handler := CurVendorSync.GetStoreHandler(vendorID); handler != nil { - vendorStoreInfo, err2 := handler.ReadStore(vendorStoreID) - if err = err2; err == nil { - payload["deliveryType"] = vendorStoreInfo.DeliveryType - } - err = nil // todo 忽略读不到DeliveryType的错误 - } else { - err = ErrCanNotFindVendor + vendorStoreInfo, err2 := storeHandler.ReadStore(vendorStoreID) + if err = err2; err == nil { + payload["deliveryType"] = vendorStoreInfo.DeliveryType } + err = nil // todo 忽略读不到DeliveryType的错误 } if err == nil { - dummyStoreMap := &model.StoreMap{} - valid := dao.NormalMakeMapByStructObject(payload, dummyStoreMap, userName) + storeMap := &model.StoreMap{ + StoreID: storeID, + VendorID: vendorID, + } + storeMap.DeletedAt = utils.DefaultTimeValue + if err = dao.GetEntity(db, storeMap, model.FieldStoreID, model.FieldVendorID, model.FieldDeletedAt); err != nil { + return 0, err + } + valid := dao.StrictMakeMapByStructObject(payload, storeMap, userName) + // globals.SugarLogger.Debug(utils.Format4Output(valid, false)) if len(valid) > 0 { + dao.Begin(db) + defer func() { + dao.Rollback(db) + }() if valid["status"] != nil { // 对于store vendor map,只有Status改变才需要同步到厂商 - num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, dummyStoreMap, valid, userName, map[string]interface{}{ + num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, storeMap, valid, userName, map[string]interface{}{ model.FieldStoreID: storeID, model.FieldVendorID: vendorID, }, model.FieldSyncStatus) } else { - num, err = dao.UpdateEntityLogically(db, dummyStoreMap, valid, userName, map[string]interface{}{ + num, err = dao.UpdateEntityLogically(db, storeMap, valid, userName, map[string]interface{}{ model.FieldStoreID: storeID, model.FieldVendorID: vendorID, }) } if err == nil && num > 0 { + storeSkuBind := &model.StoreSkuBind{} + if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, storeSkuBind, nil, userName, map[string]interface{}{ + model.FieldStoreID: storeID, + }, storeHandler.GetFieldSyncStatusName()); err != nil { + return 0, err + } + dao.Commit(db) if valid["status"] != nil { _, err = CurVendorSync.SyncStore(ctx, db, vendorID, storeID, false, userName) } diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index 330cb12b8..4dd14dab4 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -301,7 +301,7 @@ func Struct2FlatMap(obj interface{}) map[string]interface{} { } // todo 这里看是否需要将key值转换成标准格式(即字母大写),因为beego orm不区分,不转换也可以 -func FilterMapByStructObject(mapData map[string]interface{}, obj interface{}, excludedFields []string) (valid map[string]interface{}, invalid map[string]interface{}) { +func FilterMapByStructObject(mapData map[string]interface{}, obj interface{}, excludedFields []string, isCheckValue bool) (valid map[string]interface{}, invalid map[string]interface{}) { excludedMap := make(map[string]int) for _, v := range excludedFields { excludedMap[v] = 1 @@ -310,7 +310,7 @@ func FilterMapByStructObject(mapData map[string]interface{}, obj interface{}, ex valid = make(map[string]interface{}) invalid = make(map[string]interface{}) for k, v := range mapData { - if m[k] != nil && excludedMap[k] == 0 && v != nil { + if m[k] != nil && excludedMap[k] == 0 && v != nil && (!isCheckValue || m[k] != v) { valid[k] = v } else { invalid[k] = v diff --git a/business/model/dao/dao_utils.go b/business/model/dao/dao_utils.go index 65d7abf87..189de6ebd 100644 --- a/business/model/dao/dao_utils.go +++ b/business/model/dao/dao_utils.go @@ -9,24 +9,23 @@ import ( "git.rosy.net.cn/jx-callback/business/model" ) -func NormalFilterMapByStructObject(mapData map[string]interface{}, obj interface{}) (valid map[string]interface{}, invalid map[string]interface{}) { +func IDCULDFilterMapByStructObject(mapData map[string]interface{}, obj interface{}, isCheckValue bool) (valid map[string]interface{}, invalid map[string]interface{}) { // 这里必须用首字母小写,因为是用于访问map,是用于访问map,是需要完全匹配的 - return jxutils.FilterMapByStructObject(mapData, obj, []string{"id", "createdAt", "updatedAt", "finishedAt", "deletedAt", "syncStatus", "lastOperator"}) + return jxutils.FilterMapByStructObject(mapData, obj, []string{"id", "createdAt", "updatedAt", "finishedAt", "deletedAt", "syncStatus", "lastOperator"}, isCheckValue) } func NormalMakeMapByStructObject(mapData map[string]interface{}, obj interface{}, userName string) (retVal map[string]interface{}) { - retVal, _ = NormalFilterMapByStructObject(mapData, obj) - // if len(retVal) > 0 { - // WrapUpdateULEntity(retVal, userName) - // } + retVal, _ = IDCULDFilterMapByStructObject(mapData, obj, false) + return retVal +} + +func StrictMakeMapByStructObject(mapData map[string]interface{}, obj interface{}, userName string) (retVal map[string]interface{}) { + retVal, _ = IDCULDFilterMapByStructObject(mapData, obj, true) return retVal } func NormalMakeMapByFieldList(mapData map[string]interface{}, fields []string, userName string) (retVal map[string]interface{}) { retVal, _ = jxutils.FilterMapByFieldList(mapData, fields) - // if len(retVal) > 0 { - // WrapUpdateULEntity(retVal, userName) - // } return retVal } diff --git a/controllers/cms_store.go b/controllers/cms_store.go index 9b8be94dc..331efc035 100644 --- a/controllers/cms_store.go +++ b/controllers/cms_store.go @@ -127,8 +127,9 @@ func (c *StoreController) GetStoreVendorMaps() { // @router /UpdateStoreVendorMap [put] func (c *StoreController) UpdateStoreVendorMap() { c.callUpdateStoreVendorMap(func(params *tStoreUpdateStoreVendorMapParams) (retVal interface{}, errCode string, err error) { - storeMap := make(map[string]interface{}) - if err = utils.UnmarshalUseNumber([]byte(params.Payload), &storeMap); err == nil { + var storeMap map[string]interface{} + var storeMapStruct model.StoreMap + if storeMap, err = utils.Unmarshal2Map([]byte(params.Payload), &storeMapStruct); err == nil { retVal, err = cms.UpdateStoreVendorMap(params.Ctx, nil, params.StoreID, params.VendorID, storeMap, params.Ctx.GetUserName()) } return retVal, "", err