From 517ae5245ece3eb546fb9b56286bc35f9846c3a4 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 10 Dec 2019 18:15:01 +0800 Subject: [PATCH 01/10] =?UTF-8?q?CreateAct=E4=B8=8EAddStoreVendorMap?= =?UTF-8?q?=E5=BF=85=E9=A1=BB=E8=A6=81=E6=B1=82vendorOrgCode=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DUpdateStoreVendorMap=E4=B8=AD=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/act/act.go | 4 +++ business/jxstore/cms/store.go | 49 ++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index 058f83fc7..4de287908 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -407,6 +407,10 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, vendorOr return "", err } act.VendorMask = model.GetVendorMask(vendorIDs...) + if act.VendorMask&(^model.GetVendorMask(model.VendorIDJX)) != 0 && + vendorOrgCode == "" { + return "", fmt.Errorf("必须指定平台分账号信息") + } setActDefault(act) db := dao.GetDB() diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 1b6cbdbc1..20d575c4e 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -1037,7 +1037,13 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend userName := ctx.GetUserName() storeMap.StoreID = storeID storeMap.VendorID = vendorID + storeMap.Status = model.StoreStatusOpened + storeMap.DeliveryType = model.StoreDeliveryTypeByStore + storeMap.SyncStatus = 0 if vendorID != model.VendorIDJX { + if storeMap.VendorOrgCode == "" { + return nil, fmt.Errorf("必须指定平台分账号信息") + } if handler := CurVendorSync.GetStoreHandler(vendorID); handler != nil { store, err2 := handler.ReadStore(ctx, vendorOrgCode, storeMap.VendorStoreID) if err = err2; err == nil || storeMap.IsSync == 0 { @@ -1052,8 +1058,8 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend err = ErrCanNotFindVendor } } - dao.WrapAddIDCULDEntity(storeMap, userName) if err == nil { + dao.WrapAddIDCULDEntity(storeMap, userName) if db == nil { db = dao.GetDB() } @@ -1101,9 +1107,12 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor return 0, fmt.Errorf("非京东平台要求必须自动拣货") } } - storeHandler := CurVendorSync.GetStoreHandler(vendorID) - if storeHandler == nil { - return 0, ErrCanNotFindVendor + var storeHandler partner.IPurchasePlatformHandler + if vendorID != model.VendorIDJX { + storeHandler = CurVendorSync.GetStoreHandler(vendorID) + if storeHandler == nil { + return 0, ErrCanNotFindVendor + } } if db == nil { db = dao.GetDB() @@ -1141,19 +1150,24 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor } } - if vendorStoreID := utils.Interface2String(valid["vendorStoreID"]); vendorStoreID != "" { - vendorStoreInfo, err2 := storeHandler.ReadStore(ctx, storeMap.VendorOrgCode, vendorStoreID) - if err = err2; err == nil { - valid["deliveryType"] = vendorStoreInfo.DeliveryType + if vendorID != model.VendorIDJX { + if vendorStoreID := utils.Interface2String(valid["vendorStoreID"]); vendorStoreID != "" { + vendorStoreInfo, err2 := storeHandler.ReadStore(ctx, storeMap.VendorOrgCode, vendorStoreID) + if err = err2; err == nil { + valid["deliveryType"] = vendorStoreInfo.DeliveryType + } + err = nil // todo 忽略读不到DeliveryType的错误 } - err = nil // todo 忽略读不到DeliveryType的错误 } if err == nil { // globals.SugarLogger.Debug(utils.Format4Output(valid, false)) if len(valid) > 0 { dao.Begin(db) defer func() { - dao.Rollback(db) + if r := recover(); r != nil { + dao.Rollback(db) + panic(r) + } }() if valid["status"] != nil { // 对于store vendor map,只有Status改变才需要同步到厂商 num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, storeMap, valid, userName, map[string]interface{}{ @@ -1166,19 +1180,24 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor model.FieldVendorID: vendorID, }) } - if err == nil && num > 0 { + if err != nil { + dao.Rollback(db) + return 0, err + } + if num > 0 { if valid["pricePercentage"] != nil || valid["pricePercentagePack"] != nil { storeSkuBind := &model.StoreSkuBind{} if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, storeSkuBind, nil, userName, map[string]interface{}{ model.FieldStoreID: storeID, }, dao.GetSyncStatusStructField(model.VendorNames[vendorID]), model.SyncFlagPriceMask); err != nil { + dao.Rollback(db) return 0, err } } - dao.Commit(db) - if valid["status"] != nil || valid["freightDeductionPack"] != nil { - _, err = CurVendorSync.SyncStore(ctx, db, vendorID, storeID, false, userName) - } + } + dao.Commit(db) + if vendorID != model.VendorIDJX && (valid["status"] != nil || valid["freightDeductionPack"] != nil) { + _, err = CurVendorSync.SyncStore(ctx, db, vendorID, storeID, false, userName) } } } From 77218936927e266d373b381e7d7337614daa9994 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 10 Dec 2019 18:34:58 +0800 Subject: [PATCH 02/10] fk --- business/jxstore/cms/store.go | 17 ++++++++++------- business/jxstore/cms/sync.go | 1 + 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 20d575c4e..d47c26cb5 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -1185,13 +1185,16 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor return 0, err } if num > 0 { - if valid["pricePercentage"] != nil || valid["pricePercentagePack"] != nil { - storeSkuBind := &model.StoreSkuBind{} - if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, storeSkuBind, nil, userName, map[string]interface{}{ - model.FieldStoreID: storeID, - }, dao.GetSyncStatusStructField(model.VendorNames[vendorID]), model.SyncFlagPriceMask); err != nil { - dao.Rollback(db) - return 0, err + // TODO 重算京西商城价 + if vendorID != model.VendorIDJX { + if valid["pricePercentage"] != nil || valid["pricePercentagePack"] != nil { + storeSkuBind := &model.StoreSkuBind{} + if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, storeSkuBind, nil, userName, map[string]interface{}{ + model.FieldStoreID: storeID, + }, dao.GetSyncStatusStructField(model.VendorNames[vendorID]), model.SyncFlagPriceMask); err != nil { + dao.Rollback(db) + return 0, err + } } } } diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 8f6a55058..8a1b6fb37 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -561,6 +561,7 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN if len(loopInfoList) == 1 { taskName = fmt.Sprintf("%s,处理平台%s", taskName, model.VendorChineseNames[loopInfoList[0].VendorID]) } + globals.SugarLogger.Debugf("LoopStoresMap2 loopInfoList:%s", utils.Format4Output(loopInfoList, false)) task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList) tasksch.HandleTask(task, nil, isManageIt).Run() if !isAsync { From 794f4f084aa80fb62d0e920cf329dc5e239702c8 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 10 Dec 2019 18:39:32 +0800 Subject: [PATCH 03/10] up --- business/jxstore/cms/sync.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 8a1b6fb37..73217bec0 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -188,7 +188,9 @@ func (v *VendorSync) oldSyncReorderCategories(ctx *jxcontext.Context, db *dao.Da func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID, storeID int, isAsync bool, userName string) (hint string, err error) { globals.SugarLogger.Debugf("SyncStore, storeID:%d", storeID) - + if vendorID == model.VendorIDJX { + return "1", nil + } var vendorIDs []int if vendorID != -1 { vendorIDs = []int{ From 7ef2f0c23d0bc638f6b060409f093483c3373dac Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 11 Dec 2019 08:49:15 +0800 Subject: [PATCH 04/10] =?UTF-8?q?1000007223=E7=9A=84=E9=85=8D=E9=80=81?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E9=97=AE=E9=A2=98=E3=80=82=E6=9A=82=E6=97=B6?= =?UTF-8?q?=E5=85=88=E6=8A=8ASelfDeliverDelivered=E7=9A=84=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E9=99=90=E5=88=B6=E6=94=BE=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/scheduler/basesch/basesch.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/business/jxcallback/scheduler/basesch/basesch.go b/business/jxcallback/scheduler/basesch/basesch.go index 0d7716a12..72a09852d 100644 --- a/business/jxcallback/scheduler/basesch/basesch.go +++ b/business/jxcallback/scheduler/basesch/basesch.go @@ -124,7 +124,8 @@ func (c *BaseScheduler) SelfDeliverDelivering(order *model.GoodsOrder, userName func (c *BaseScheduler) SelfDeliverDelivered(order *model.GoodsOrder, userName string) (err error) { globals.SugarLogger.Infof("SelfDeliverDelivered orderID:%s", order.VendorOrderID) - if /*order.LockStatus == model.OrderStatusUnknown && */ order.Status == model.OrderStatusDelivering { + if /*order.LockStatus == model.OrderStatusUnknown && */ order.Status >= model.OrderStatusFinishedPickup && + order.Status <= model.OrderStatusDelivering { if c.IsReallyCallPlatformAPI { err = utils.CallFuncLogError(func() error { return partner.GetPurchaseOrderHandlerFromVendorID(order.VendorID).SelfDeliverDelivered(order, userName) From d566ee38e3a3304043b1863610ee469fc13fbaff Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 11 Dec 2019 08:53:32 +0800 Subject: [PATCH 05/10] =?UTF-8?q?OnXXThing=E4=BE=9D=E8=B5=96mdoel.IsUseThi?= =?UTF-8?q?ngMap=E8=BF=94=E5=9B=9E=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync2.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/business/jxstore/cms/sync2.go b/business/jxstore/cms/sync2.go index f84310780..bc51053da 100644 --- a/business/jxstore/cms/sync2.go +++ b/business/jxstore/cms/sync2.go @@ -168,8 +168,10 @@ func OnCreateThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingTy dao.WrapAddIDCULDEntity(thingMap, ctx.GetUserName()) errList.AddErr(dao.CreateEntity(db, thingMap)) } - // return errList.GetErrListAsOne() - return nil + if model.IsUseThingMap { + err = errList.GetErrListAsOne() + } + return err } func OnUpdateThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingType int8) (err error) { @@ -194,8 +196,10 @@ func OnUpdateThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingTy errList.AddErr(err2) } } - // return errList.GetErrListAsOne() - return nil + if model.IsUseThingMap { + err = errList.GetErrListAsOne() + } + return err } func OnDeleteThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingType int8) (err error) { @@ -225,8 +229,10 @@ func OnDeleteThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingTy errList.AddErr(err2) } } - // return errList.GetErrListAsOne() - return nil + if model.IsUseThingMap { + err = errList.GetErrListAsOne() + } + return err } func SkuCategoryVendor2ThingMap(cat *dao.SkuStoreCatInfo) (thingMap *model.ThingMap) { From 31704041a8bee92de7352c11b0a59c34902ba8ec Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 11 Dec 2019 09:07:32 +0800 Subject: [PATCH 06/10] =?UTF-8?q?alpha=E7=8E=AF=E5=A2=83=E5=90=AF=E7=94=A8?= =?UTF-8?q?isUseThingMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 8 ++++---- business/jxstore/cms/sync2.go | 6 +++--- business/model/dao/store_sku.go | 6 +++--- business/model/sync_map.go | 4 ---- conf/app.conf | 4 ++++ globals/globals.go | 4 ++++ 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 73217bec0..0fed8bc08 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -129,7 +129,7 @@ func (v *VendorSync) syncCategories(ctx *jxcontext.Context, parentTask tasksch.I } func (v *VendorSync) SyncCategory(ctx *jxcontext.Context, db *dao.DaoDB, categoryID int, isAsync bool, userName string) (hint string, err error) { - if !model.IsUseThingMap { + if !globals.IsUseThingMap { return v.oldSyncCategory(ctx, db, categoryID, isAsync, userName) } return SyncCategories(ctx, nil, nil, nil, []int{categoryID}, isAsync) @@ -165,7 +165,7 @@ func (v *VendorSync) oldSyncCategory(ctx *jxcontext.Context, db *dao.DaoDB, cate } func (v *VendorSync) SyncReorderCategories(ctx *jxcontext.Context, db *dao.DaoDB, categoryID int, isAsync bool, userName string) (hint string, err error) { - if !model.IsUseThingMap { + if !globals.IsUseThingMap { return v.oldSyncReorderCategories(ctx, db, categoryID, isAsync, userName) } return SyncReorderCategories(ctx, -1, isAsync) @@ -248,7 +248,7 @@ func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuI } func (v *VendorSync) SyncSkus(ctx *jxcontext.Context, db *dao.DaoDB, nameIDs []int, skuIDs []int, isAsync, isContinueWhenError bool, userName string) (hint string, err error) { - if !model.IsUseThingMap { + if !globals.IsUseThingMap { return v.oldSyncSkus(ctx, db, nameIDs, skuIDs, isAsync, isContinueWhenError, userName) } return SyncSkus(ctx, nil, nil, nil, nameIDs, skuIDs, isAsync) @@ -563,7 +563,7 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN if len(loopInfoList) == 1 { taskName = fmt.Sprintf("%s,处理平台%s", taskName, model.VendorChineseNames[loopInfoList[0].VendorID]) } - globals.SugarLogger.Debugf("LoopStoresMap2 loopInfoList:%s", utils.Format4Output(loopInfoList, false)) + // globals.SugarLogger.Debugf("LoopStoresMap2 loopInfoList:%s", utils.Format4Output(loopInfoList, false)) task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList) tasksch.HandleTask(task, nil, isManageIt).Run() if !isAsync { diff --git a/business/jxstore/cms/sync2.go b/business/jxstore/cms/sync2.go index bc51053da..06508a7fc 100644 --- a/business/jxstore/cms/sync2.go +++ b/business/jxstore/cms/sync2.go @@ -168,7 +168,7 @@ func OnCreateThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingTy dao.WrapAddIDCULDEntity(thingMap, ctx.GetUserName()) errList.AddErr(dao.CreateEntity(db, thingMap)) } - if model.IsUseThingMap { + if globals.IsUseThingMap { err = errList.GetErrListAsOne() } return err @@ -196,7 +196,7 @@ func OnUpdateThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingTy errList.AddErr(err2) } } - if model.IsUseThingMap { + if globals.IsUseThingMap { err = errList.GetErrListAsOne() } return err @@ -229,7 +229,7 @@ func OnDeleteThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingTy errList.AddErr(err2) } } - if model.IsUseThingMap { + if globals.IsUseThingMap { err = errList.GetErrListAsOne() } return err diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 2005fca28..3ffa82eba 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -282,7 +282,7 @@ func GetDirtyStoreCategories(db *DaoDB, vendorID, storeID int, level int) (cats // 以store_sku_bind为基础来做同步,正常情况下使用 // 单多门店模式厂商通用 func GetStoreSkus2(db *DaoDB, vendorID, storeID int, skuIDs []int, mustDirty bool) (skus []*StoreSkuSyncInfo, err error) { - if !model.IsUseThingMap { + if !globals.IsUseThingMap { return oldGetStoreSkus2(db, vendorID, storeID, skuIDs, mustDirty) } return newGetStoreSkus2(db, vendorID, storeID, skuIDs, mustDirty) @@ -495,7 +495,7 @@ func GetStoreSkus(db *DaoDB, vendorID, storeID int, skuIDs []int) (skus []*Store // 以sku为基础来做全同步, // 多门店模式厂商适用 func GetFullStoreSkus(db *DaoDB, vendorID, storeID int) (skus []*StoreSkuSyncInfo, err error) { - if !model.IsUseThingMap { + if !globals.IsUseThingMap { return oldGetFullStoreSkus(db, vendorID, storeID) } return newGetFullStoreSkus(db, vendorID, storeID) @@ -1061,7 +1061,7 @@ func GetStoreSkuNamePrice(db *DaoDB) (storeSkuNamePriceList []*model.StoreSkuNam } err = GetRows(db, &storeSkuNamePriceList, sql, sqlParams...) if err != nil { - return nil,err + return nil, err } return storeSkuNamePriceList, err } diff --git a/business/model/sync_map.go b/business/model/sync_map.go index 3de1b6fae..5ca1dcbae 100644 --- a/business/model/sync_map.go +++ b/business/model/sync_map.go @@ -6,10 +6,6 @@ const ( ThingTypeSku = 3 ) -const ( - IsUseThingMap = false -) - type ThingMap struct { ModelIDCULD diff --git a/conf/app.conf b/conf/app.conf index 752b09a24..7bf68d28d 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -97,6 +97,8 @@ zhongwuAppSecret = "29435497822f52f3cf659c65da548a79" getWeixinTokenKey = "c928ed0d-87a3-441a-8517-f92f0167296f" storeName = "京西菜市" +useThingMap = false + [dev] jdOrgCode = "320406" jdToken = "77e703b7-7997-441b-a12a-2e522efb117a" @@ -292,6 +294,8 @@ enableEbaiStoreWrite = true enableMtwmStoreWrite = true enableWscStoreWrite = false +useThingMap = true + [beta] enableStoreWrite = false enableJdStoreWrite = false diff --git a/globals/globals.go b/globals/globals.go index 5c51c004a..b0909ff04 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -51,6 +51,8 @@ var ( WxpayNotifyURL string JdOrgCode string + + IsUseThingMap bool ) func init() { @@ -99,6 +101,8 @@ func Init() { WxpayNotifyURL = beego.AppConfig.DefaultString("wxpayNotifyURL", "") JdOrgCode = beego.AppConfig.DefaultString("jdOrgCode", "") + + IsUseThingMap = beego.AppConfig.DefaultBool("useThingMap", false) } func IsCallbackAlwaysReturnSuccess() bool { From 3e6fdb0de1fa21a36eaf1cdbc8b14f8117816a29 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 11 Dec 2019 09:11:15 +0800 Subject: [PATCH 07/10] up --- business/jxstore/cms/sku.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxstore/cms/sku.go b/business/jxstore/cms/sku.go index cdedfa20e..578c5b46f 100644 --- a/business/jxstore/cms/sku.go +++ b/business/jxstore/cms/sku.go @@ -61,7 +61,7 @@ func GetCategories(ctx *jxcontext.Context, parentID int) (catList []*dao.SkuCate ids = append(ids, v.ID) } thingMapMap, err2 := dao.GetThingMapMap(db, model.ThingTypeCategory, nil, ids) - globals.SugarLogger.Debug(utils.Format4Output(thingMapMap, false)) + // globals.SugarLogger.Debug(utils.Format4Output(thingMapMap, false)) if err = err2; err == nil { for _, v := range cats { catList = append(catList, &dao.SkuCategoryWithVendor{ From 6c98fecca60ffccef3b321d84c0b8e0bb0702015 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 11 Dec 2019 09:22:17 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8DGetSkuCategoryWithVendo?= =?UTF-8?q?r=E4=B8=AD=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/dao/sku.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/model/dao/sku.go b/business/model/dao/sku.go index b9d2d5cf1..6c2180333 100644 --- a/business/model/dao/sku.go +++ b/business/model/dao/sku.go @@ -186,7 +186,7 @@ func GetSkuCategoryWithVendor(db *DaoDB, vendorIDs []int, appOrgCodes []string, t1m.sync_status cat_sync_status, t1pm.id parent_map_id, - t1pm.t1p.name parent_cat_name + t1p.name parent_cat_name, t1pm.vendor_thing_id parent_vendor_cat_id, t1pm.sync_status parent_cat_sync_status /* From a3e1521bb49b4c1b9d7134adcee82fdbda0d442b Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 11 Dec 2019 10:13:35 +0800 Subject: [PATCH 09/10] updateThingMapEntity --- business/jxstore/cms/store_sku.go | 1 + business/jxstore/cms/sync2.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 9506e94c0..6e9702138 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -315,6 +315,7 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool return "", nil, err } sql += " AND ( 1 = 0" + // TODO if params["jdSyncStatus"] != nil && realVendorMap[model.VendorIDJD] == 1 { sql += " OR (t4.jd_sync_status & ? <> 0 AND t2.jd_id <> 0 AND t1.status = ? AND t2.status = ?)" sqlParams = append(sqlParams, params["jdSyncStatus"], model.SkuStatusNormal, model.SkuStatusNormal) diff --git a/business/jxstore/cms/sync2.go b/business/jxstore/cms/sync2.go index 06508a7fc..2cdb89960 100644 --- a/business/jxstore/cms/sync2.go +++ b/business/jxstore/cms/sync2.go @@ -167,6 +167,8 @@ func OnCreateThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingTy } dao.WrapAddIDCULDEntity(thingMap, ctx.GetUserName()) errList.AddErr(dao.CreateEntity(db, thingMap)) + + updateThingMapEntity(db, thingMap) } if globals.IsUseThingMap { err = errList.GetErrListAsOne() @@ -192,6 +194,8 @@ func OnUpdateThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingTy thingMap.LastOperator = ctx.GetUserName() _, err2 = dao.UpdateEntity(db, thingMap) errList.AddErr(err2) + + updateThingMapEntity(db, thingMap) } else if !dao.IsNoRowsError(err2) { errList.AddErr(err2) } @@ -225,6 +229,8 @@ func OnDeleteThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingTy thingMap.LastOperator = ctx.GetUserName() _, err2 = dao.UpdateEntity(db, thingMap) errList.AddErr(err2) + + updateThingMapEntity(db, thingMap) } else if !dao.IsNoRowsError(err2) { errList.AddErr(err2) } @@ -259,6 +265,7 @@ func SkuVendor2ThingMap(sku *dao.StoreSkuSyncInfo) (thingMap *model.ThingMap) { SyncStatus: sku.SkuSyncStatus, VendorThingID: sku.VendorSkuID, } + thingMap.DeletedAt = utils.DefaultTimeValue thingMap.ID = sku.BindID // 一定要赋值 return thingMap } @@ -288,6 +295,26 @@ func OnThingSync(ctx *jxcontext.Context, db *dao.DaoDB, thingMap *model.ThingMap thingMap.UpdatedAt = time.Now() thingMap.Remark = "" _, err = dao.UpdateEntity(db, thingMap, updateFields...) + + updateThingMapEntity(db, thingMap) } return err } + +func updateThingMapEntity(db *dao.DaoDB, thingMap *model.ThingMap) { + if thingMap.ThingType == model.ThingTypeCategory { + cat := &model.SkuCategory{ + JdID: utils.Str2Int64WithDefault(thingMap.VendorThingID, 0), + JdSyncStatus: thingMap.SyncStatus, + } + cat.ID = int(thingMap.ThingID) + dao.UpdateEntity(db, cat, "JdID", "JdSyncStatus") + } else if thingMap.ThingType == model.ThingTypeSku { + sku := &model.Sku{ + JdID: utils.Str2Int64WithDefault(thingMap.VendorThingID, 0), + JdSyncStatus: thingMap.SyncStatus, + } + sku.ID = int(thingMap.ThingID) + dao.UpdateEntity(db, sku, "JdID", "JdSyncStatus") + } +} From 73811a7bc650bee99c6703992aac369a01f76ef4 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 11 Dec 2019 10:28:38 +0800 Subject: [PATCH 10/10] fk --- business/jxstore/cms/store_sku.go | 9 +++-- business/jxstore/cms/sync.go | 60 +++++++++++++++---------------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 6e9702138..a05685086 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -268,10 +268,10 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool } sql += ")" } - if params["jdID"] != nil { - sql += " AND t1.jd_id = ?" - sqlParams = append(sqlParams, params["jdID"].(int)) - } + // if params["jdID"] != nil { + // sql += " AND t1.jd_id = ?" + // sqlParams = append(sqlParams, params["jdID"].(int)) + // } if params["name"] != nil { sql += " AND t1.name LIKE ?" sqlParams = append(sqlParams, "%"+params["name"].(string)+"%") @@ -315,7 +315,6 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool return "", nil, err } sql += " AND ( 1 = 0" - // TODO if params["jdSyncStatus"] != nil && realVendorMap[model.VendorIDJD] == 1 { sql += " OR (t4.jd_sync_status & ? <> 0 AND t2.jd_id <> 0 AND t1.status = ? AND t2.status = ?)" sqlParams = append(sqlParams, params["jdSyncStatus"], model.SkuStatusNormal, model.SkuStatusNormal) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 0fed8bc08..29a4cf774 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -188,9 +188,6 @@ func (v *VendorSync) oldSyncReorderCategories(ctx *jxcontext.Context, db *dao.Da func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID, storeID int, isAsync bool, userName string) (hint string, err error) { globals.SugarLogger.Debugf("SyncStore, storeID:%d", storeID) - if vendorID == model.VendorIDJX { - return "1", nil - } var vendorIDs []int if vendorID != -1 { vendorIDs = []int{ @@ -200,35 +197,38 @@ func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID, hint, err = v.LoopStoresMap(ctx, db, fmt.Sprintf("同步门店信息:%d", storeID), isAsync, false, vendorIDs, []int{storeID}, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (resultList interface{}, err error) { loopMapInfo := batchItemList[0].(*LoopStoreMapInfo) handler := v.GetStoreHandler(loopMapInfo.VendorID) - if len(loopMapInfo.StoreMapList) > 1 { - loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), nil, ctx, - func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - var resultList []interface{} - storeMap := batchItemList[0].(*model.StoreMap) - db2 := db - if len(loopMapInfo.StoreMapList) > 1 { - db2 = dao.GetDB() - } - if err = handler.UpdateStore(db2, storeMap.StoreID, userName); err == nil { - storeMap.SyncStatus = 0 - _, err = dao.UpdateEntity(db2, storeMap, model.FieldSyncStatus) - resultList = append(resultList, 1) - } - return resultList, err - }, loopMapInfo.StoreMapList) - t.AddChild(loopStoreTask).Run() - resultList, err = loopStoreTask.GetResult(0) - } else { - storeMap := loopMapInfo.StoreMapList[0] - if err = handler.UpdateStore(db, storeMap.StoreID, userName); err == nil { - storeMap.SyncStatus = 0 - _, err = dao.UpdateEntity(db, storeMap, model.FieldSyncStatus) - } - if err == nil { - resultList = []interface{}{1} + if handler != nil { + if len(loopMapInfo.StoreMapList) > 1 { + loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), nil, ctx, + func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + var resultList []interface{} + storeMap := batchItemList[0].(*model.StoreMap) + db2 := db + if len(loopMapInfo.StoreMapList) > 1 { + db2 = dao.GetDB() + } + if err = handler.UpdateStore(db2, storeMap.StoreID, userName); err == nil { + storeMap.SyncStatus = 0 + _, err = dao.UpdateEntity(db2, storeMap, model.FieldSyncStatus) + resultList = append(resultList, 1) + } + return resultList, err + }, loopMapInfo.StoreMapList) + t.AddChild(loopStoreTask).Run() + resultList, err = loopStoreTask.GetResult(0) + } else { + storeMap := loopMapInfo.StoreMapList[0] + if err = handler.UpdateStore(db, storeMap.StoreID, userName); err == nil { + storeMap.SyncStatus = 0 + _, err = dao.UpdateEntity(db, storeMap, model.FieldSyncStatus) + } + if err == nil { + resultList = []interface{}{1} + } } + err = partner.AddVendorInfo2Err(err, loopMapInfo.VendorID) } - return resultList, partner.AddVendorInfo2Err(err, loopMapInfo.VendorID) + return resultList, err }, true) return hint, makeSyncError(err) }