From 13922ead6063d67e5bf7d54bdd83e454a18bc25c Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 3 Jan 2020 17:29:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=AC=E4=B8=9C=E6=B4=BB=E5=8A=A8=E9=87=8D?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E5=88=A0=E9=99=A4=E4=B8=8E=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=97=B6=E9=81=87=E9=94=99=E7=BB=A7=E7=BB=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/jd/act.go | 62 ++++++++++++++++++----------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/business/partner/purchase/jd/act.go b/business/partner/purchase/jd/act.go index ba2ee46e8..28ec7333e 100644 --- a/business/partner/purchase/jd/act.go +++ b/business/partner/purchase/jd/act.go @@ -13,6 +13,7 @@ import ( "git.rosy.net.cn/baseapi/platformapi/jdapi" "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/baseapi/utils/errlist" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/jxutils/tasksch" "git.rosy.net.cn/jx-callback/business/model" @@ -242,67 +243,80 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa var updateItems []*dao.KVUpdateItem actStoreSkuMap := partner.SplitActStoreSku(actStoreSkuList) + actSkuCount := 0 + toDelActSkuCount := 0 for storeID := range actStoreSkuMap { for _, actStoreSku := range actStoreSkuMap[storeID] { - vendorActInfoMap[actStoreSku.VendorActID] = append(vendorActInfoMap[actStoreSku.VendorActID], actStoreSku) + vendorActID := actStoreSku.VendorActID + if vendorActID == "" { + vendorActID = act.VendorActID + } + actSkuCount++ + vendorActInfoMap[vendorActID] = append(vendorActInfoMap[vendorActID], actStoreSku) if model.IsSyncStatusDelete(actStoreSku.SyncStatus) { - vendorActID := actStoreSku.VendorActID - if vendorActID == "" { - vendorActID = act.VendorActID - } + toDelActSkuCount++ deleteActInfoMap[vendorActID] = append(deleteActInfoMap[vendorActID], actStoreSku) } else if model.IsSyncStatusNew(actStoreSku.SyncStatus) { actStoreSkuList4Create = append(actStoreSkuList4Create, actStoreSku) } } } + // 如果是全删,直接添加删除(即取消)标志 + if actSkuCount == toDelActSkuCount { + act.SyncStatus |= model.SyncFlagDeletedMask + } db := dao.GetDB() err = func() (err error) { if model.IsSyncStatusDelete(act.SyncStatus) { + errList := errlist.New() for vendorActID := range vendorActInfoMap { if vendorActID != "" { - if err = cancelSkuAct(ctx, act, vendorActID); err != nil { - return err + if err = cancelSkuAct(ctx, act, vendorActID); err == nil { + updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, vendorActInfoMap[vendorActID], model.SyncFlagModifiedMask)...) + } else { + errList.AddErr(err) } } } - for _, actStoreSkuList := range vendorActInfoMap { - updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, actStoreSkuList, model.SyncFlagModifiedMask)...) + if err = errList.GetErrListAsOne(); err == nil { + updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask)) } - updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask)) } else if model.IsSyncStatusNew(act.SyncStatus) { - if act.VendorActID, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil { + if act.VendorActID, err = createSkuAct(ctx, act, actStoreSkuList4Create); err == nil { + updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, actStoreSkuList4Create, model.SyncFlagNewMask)...) + updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagNewMask)) + } else { if act.VendorActID != "" { actMap := partner.Act2ActMap(act) - dao.UpdateEntity(db, actMap, "VendorActID") + dao.UpdateEntity(db, actMap, model.FieldVendorActID) } - return err } - updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, actStoreSkuList4Create, model.SyncFlagNewMask)...) - updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagNewMask)) } else if model.IsSyncStatusUpdate(act.SyncStatus) { - // globals.SugarLogger.Debug(utils.Format4Output(updateItems, false)) + errList := errlist.New() if len(actStoreSkuList4Create) > 0 { - if _, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil { - return err + if _, err = createSkuAct(ctx, act, actStoreSkuList4Create); err == nil { + updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, actStoreSkuList4Create, model.SyncFlagNewMask)...) + } else { + errList.AddErr(err) } - updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, actStoreSkuList4Create, model.SyncFlagNewMask)...) } for vendorActID := range deleteActInfoMap { if vendorActID != "" { if len(vendorActInfoMap[vendorActID]) == len(deleteActInfoMap[vendorActID]) { - // todo 如果这个取消导致了整活动被取消的话,怎么设置京西活动的状态 err = cancelSkuAct(ctx, act, vendorActID) } else { err = cancelSkuActSkus(ctx, act, vendorActID, deleteActInfoMap[vendorActID]) } - if err != nil { - return err + if err == nil { + updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, deleteActInfoMap[vendorActID], model.SyncFlagDeletedMask)...) + } else { + errList.AddErr(err) } + } else { + updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, deleteActInfoMap[vendorActID], model.SyncFlagDeletedMask)...) } - updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, deleteActInfoMap[vendorActID], model.SyncFlagDeletedMask)...) } - if err == nil { + if err = errList.GetErrListAsOne(); err == nil { updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask)) } }