- 重构新京西活动,平台接口定为笼统的SyncAct,京平台支持添加,删除商品,暂不支持修改
This commit is contained in:
@@ -3,6 +3,7 @@ package jd
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
@@ -132,7 +133,7 @@ func storeSku2Jd(actStoreSku []*model.ActStoreSku2, handler func(syncStatus int)
|
||||
return jdActStoreSku
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) CreateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
func (c *PurchaseHandler) CreateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
if act.Type < model.ActOrderBegin {
|
||||
act.VendorActID, err = createSkuAct(ctx, act, actStoreSku)
|
||||
} else {
|
||||
@@ -152,7 +153,11 @@ func createSkuAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model.
|
||||
vendorActID = utils.Int64ToStr(infoID)
|
||||
if err = CreatePromotionRules(act.Type, infoID, "", act.LimitDevice, act.LimitPin, act.LimitCount, act.LimitDaily, traceID); err == nil {
|
||||
if _, err = CreatePromotionSku(act.Type, infoID, "", storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceID); err == nil {
|
||||
err = ConfirmPromotion(act.Type, infoID, "", traceID)
|
||||
if err = ConfirmPromotion(act.Type, infoID, "", traceID); err == nil {
|
||||
for _, v := range actStoreSku {
|
||||
v.VendorActID = vendorActID
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,114 +171,93 @@ func cancelSkuActSkus(ctx *jxcontext.Context, actType int, vendorActID string, a
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
func cancelSkuAct(ctx *jxcontext.Context, actType int, vendorActID string) (err error) {
|
||||
err = CancelPromotion(actType, utils.Str2Int64(vendorActID), "", getTraceID(ctx))
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) CancelAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
traceID := getTraceID(ctx)
|
||||
func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) CancelAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
if act.Type < model.ActOrderBegin {
|
||||
outInfoID := utils.Int2Str(act.ID)
|
||||
err = CancelPromotion(act.Type, 0, outInfoID, traceID)
|
||||
err = CancelPromotion(act.Type, 0, outInfoID, getTraceID(ctx))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreList []*model.ActStore2, actStoreSkuList []*model.ActStoreSku2) (err error) {
|
||||
traceID := getTraceID(ctx)
|
||||
func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreSkuList []*model.ActStoreSku2) (err error) {
|
||||
globals.SugarLogger.Debugf("jd SyncAct, actID:%d", act.ID)
|
||||
vendorActInfoMap := make(map[string][]*model.ActStoreSku2)
|
||||
deleteActInfoMap := make(map[string][]*model.ActStoreSku2)
|
||||
var actStoreSkuList4Create []*model.ActStoreSku2
|
||||
var updateItems []*dao.KVUpdateItem
|
||||
|
||||
actStoreMap := partner.SplitActStore(actStoreList)
|
||||
actStoreSkuMap := partner.SplitActStoreSku(actStoreSkuList)
|
||||
var actStoreSkuList4Create, actStoreSkuList4Delete []*model.ActStoreSku2
|
||||
var okList []*LogicUpdateInfo
|
||||
for _, actStore := range actStoreMap {
|
||||
for _, actStoreSku := range actStoreSkuMap[actStore.StoreID] {
|
||||
for storeID := range actStoreSkuMap {
|
||||
for _, actStoreSku := range actStoreSkuMap[storeID] {
|
||||
vendorActInfoMap[actStoreSku.VendorActID] = append(vendorActInfoMap[actStoreSku.VendorActID], actStoreSku)
|
||||
if model.IsSyncStatusNeedCreate(actStoreSku.SyncStatus) {
|
||||
if actStore.VendorActID == "" {
|
||||
actStoreSkuList4Create = append(actStoreSkuList4Create, actStoreSku)
|
||||
} else {
|
||||
if actStoreSku.VendorActID, err = createSkuAct(ctx, act, []*model.ActStoreSku2{actStoreSku}); err != nil {
|
||||
return err
|
||||
}
|
||||
okList = append(okList, &LogicUpdateInfo{
|
||||
Item: partner.ActStoreSku2ActStoreSkuMap(actStoreSku),
|
||||
KVs: map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldVendorActID: actStoreSku.VendorActID,
|
||||
},
|
||||
})
|
||||
}
|
||||
actStoreSkuList4Create = append(actStoreSkuList4Create, actStoreSku)
|
||||
} else if model.IsSyncStatusNeedDelete(actStoreSku.SyncStatus) {
|
||||
if actStoreSku.VendorActID == "" {
|
||||
actStoreSkuList4Delete = append(actStoreSkuList4Delete, actStoreSku)
|
||||
} else {
|
||||
if err = CancelPromotion(act.Type, utils.Str2Int64(actStoreSku.VendorActID), "", traceID); err != nil {
|
||||
return err
|
||||
}
|
||||
okList = append(okList, &LogicUpdateInfo{
|
||||
Item: partner.ActStoreSku2ActStoreSkuMap(actStoreSku),
|
||||
KVs: map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldDeletedAt: time.Now(),
|
||||
},
|
||||
})
|
||||
vendorActID := actStoreSku.VendorActID
|
||||
if vendorActID == "" {
|
||||
vendorActID = act.VendorActID
|
||||
}
|
||||
}
|
||||
}
|
||||
if actStore.VendorActID != "" {
|
||||
if model.IsSyncStatusDelete(actStore.SyncStatus) {
|
||||
if err = CancelPromotion(act.Type, utils.Str2Int64(actStore.VendorActID), "", traceID); err != nil {
|
||||
return err
|
||||
}
|
||||
okList = append(okList, &LogicUpdateInfo{
|
||||
Item: partner.ActStore2ActStoreMap(actStore),
|
||||
KVs: map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldDeletedAt: time.Now(),
|
||||
},
|
||||
})
|
||||
|
||||
} else if len(actStoreSkuList4Delete) > 0 {
|
||||
if err = cancelSkuActSkus(ctx, act.Type, actStore.VendorActID, actStoreSkuList4Delete); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, v := range actStoreSkuList4Delete {
|
||||
okList = append(okList, &LogicUpdateInfo{
|
||||
Item: partner.ActStoreSku2ActStoreSkuMap(v),
|
||||
KVs: map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldDeletedAt: time.Now(),
|
||||
},
|
||||
})
|
||||
}
|
||||
actStoreSkuList4Delete = nil
|
||||
}
|
||||
|
||||
if act.VendorActID != "" {
|
||||
if len(actStoreSkuList4Create) > 0 {
|
||||
if actStore.VendorActID, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil {
|
||||
return err
|
||||
}
|
||||
okList = append(okList, &LogicUpdateInfo{
|
||||
Item: partner.ActStore2ActStoreMap(actStore),
|
||||
KVs: map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
},
|
||||
})
|
||||
for _, v := range actStoreSkuList4Create {
|
||||
okList = append(okList, &LogicUpdateInfo{
|
||||
Item: partner.ActStoreSku2ActStoreSkuMap(v),
|
||||
KVs: map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
actStoreSkuList4Create = nil
|
||||
deleteActInfoMap[vendorActID] = append(deleteActInfoMap[vendorActID], actStoreSku)
|
||||
}
|
||||
}
|
||||
}
|
||||
// db := dao.GetDB()
|
||||
|
||||
err = func() (err error) {
|
||||
if model.IsSyncStatusNeedCreate(act.SyncStatus) {
|
||||
if act.VendorActID, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil {
|
||||
return err
|
||||
}
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(actStoreSkuList4Create, model.SyncFlagNewMask)...)
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagNewMask))
|
||||
} else if model.IsSyncStatusNeedDelete(act.SyncStatus) {
|
||||
for vendorActID := range vendorActInfoMap {
|
||||
if vendorActID != "" {
|
||||
if err = cancelSkuAct(ctx, act.Type, vendorActID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, actStoreSkuList := range vendorActInfoMap {
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(actStoreSkuList, model.SyncFlagDeletedMask)...)
|
||||
}
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagDeletedMask))
|
||||
} else if model.IsSyncStatusNeedUpdate(act.SyncStatus) {
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(updateItems, false))
|
||||
for vendorActID := range deleteActInfoMap {
|
||||
if vendorActID != "" {
|
||||
if len(vendorActInfoMap[vendorActID]) == len(deleteActInfoMap[vendorActID]) {
|
||||
err = cancelSkuAct(ctx, act.Type, vendorActID)
|
||||
} else {
|
||||
err = cancelSkuActSkus(ctx, act.Type, vendorActID, deleteActInfoMap[vendorActID])
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(deleteActInfoMap[vendorActID], model.SyncFlagDeletedMask)...)
|
||||
}
|
||||
if len(actStoreSkuList4Create) > 0 {
|
||||
if _, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil {
|
||||
return err
|
||||
}
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(actStoreSkuList4Create, model.SyncFlagNewMask)...)
|
||||
}
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
db := dao.GetDB()
|
||||
_, err2 := dao.BatchUpdateEntityByKV(db, updateItems)
|
||||
if err == nil {
|
||||
err = err2
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user