aa
This commit is contained in:
@@ -177,7 +177,7 @@ func AddCategory(ctx *jxcontext.Context, cat *model.SkuCategory, userName string
|
||||
return nil, err
|
||||
}
|
||||
if cat.IsExdSpec == model.NO {
|
||||
if err = OnCreateThing(ctx, db, nil, int64(cat.ID), model.ThingTypeCategory); err != nil {
|
||||
if err = OnCreateThing(ctx, db, nil, int64(cat.ID), model.ThingTypeCategory, model.SyncFlagNewMask); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
@@ -884,7 +884,7 @@ func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName s
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
if err = OnCreateThing(ctx, db, nil, int64(skuNameExt.SkuName.ID), model.ThingTypeSkuName); err != nil {
|
||||
if err = OnCreateThing(ctx, db, nil, int64(skuNameExt.SkuName.ID), model.ThingTypeSkuName, model.SyncFlagNewMask); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
@@ -903,7 +903,7 @@ func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName s
|
||||
return nil, err
|
||||
}
|
||||
if sku.EclpID == "" {
|
||||
if err = OnCreateThing(ctx, db, nil, int64(sku.ID), model.ThingTypeSku); err != nil {
|
||||
if err = OnCreateThing(ctx, db, nil, int64(sku.ID), model.ThingTypeSku, model.SyncFlagNewMask); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
@@ -1248,7 +1248,7 @@ func AddSku(ctx *jxcontext.Context, nameID int, sku *model.Sku, userName string)
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
if err = OnCreateThing(ctx, db, nil, int64(sku.ID), model.ThingTypeSku); err != nil {
|
||||
if err = OnCreateThing(ctx, db, nil, int64(sku.ID), model.ThingTypeSku, model.SyncFlagNewMask); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ func getThingMap(db *dao.DaoDB, thingMap *model.ThingMap) (err error) {
|
||||
return dao.GetEntity(db, thingMap, "ThingID", "ThingType", "VendorID", "VendorOrgCode", model.FieldDeletedAt)
|
||||
}
|
||||
|
||||
func OnCreateThing(ctx *jxcontext.Context, db *dao.DaoDB, vendorInfoList []*MultiStoreVendorInfo, thingID int64, thingType int8) (err error) {
|
||||
func OnCreateThing(ctx *jxcontext.Context, db *dao.DaoDB, vendorInfoList []*MultiStoreVendorInfo, thingID int64, thingType, syncFlag int8) (err error) {
|
||||
if thingType == model.ThingTypeSkuName {
|
||||
return nil
|
||||
}
|
||||
@@ -278,7 +278,7 @@ func OnCreateThing(ctx *jxcontext.Context, db *dao.DaoDB, vendorInfoList []*Mult
|
||||
ThingType: thingType,
|
||||
VendorID: v.VendorID,
|
||||
VendorOrgCode: v.OrgCode,
|
||||
SyncStatus: model.SyncFlagNewMask,
|
||||
SyncStatus: syncFlag,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(thingMap, ctx.GetUserName())
|
||||
if err2 := dao.CreateEntity(db, thingMap); err2 != nil {
|
||||
@@ -445,7 +445,7 @@ func updateThingMapEntity(db *dao.DaoDB, thingMap *model.ThingMap) {
|
||||
// }
|
||||
}
|
||||
|
||||
func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, vendorOrgCode string, isAsync, isContinueWhenError bool, opType int, isForceUpdate bool) (hint string, err error) {
|
||||
func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID, vendorID int, vendorOrgCode string, isAsync, isContinueWhenError bool, opType int, isForceUpdate bool) (hint string, err error) {
|
||||
handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler)
|
||||
if handler == nil {
|
||||
return "", fmt.Errorf("平台:%s不支持此操作", model.VendorChineseNames[vendorID])
|
||||
@@ -496,7 +496,21 @@ func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
StoreSkuMap := make(map[int]*dao.StoreSkuSyncInfo)
|
||||
if storeID != 0 {
|
||||
skuList2, _ := dao.GetStoreSkuListWithVendor(db, storeID, vendorID, vendorOrgCode)
|
||||
for _, v := range skuList2 {
|
||||
if _, ok := StoreSkuMap[v.ID]; !ok {
|
||||
StoreSkuMap[v.ID] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
getSyncFlag := func(skuID int) int8 {
|
||||
if StoreSkuMap[skuID] != nil {
|
||||
return model.SyncFlagNewMask
|
||||
}
|
||||
return 0
|
||||
}
|
||||
if opType == AmendPruneOnlyAmend || opType == AmendPruneAll {
|
||||
for _, v := range localSkuList {
|
||||
if v.ExdSkuID == "" {
|
||||
@@ -504,14 +518,17 @@ func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
if !model.IsSyncStatusDelete(v.SkuSyncStatus) {
|
||||
if remoteSkuMap[v.VendorSkuID] == 0 {
|
||||
if !model.IsSyncStatusNew(v.SkuSyncStatus) {
|
||||
OnCreateThing(ctx, db, vendorInfo, int64(v.SkuID), model.ThingTypeSku)
|
||||
OnCreateThing(ctx, db, vendorInfo, int64(v.SkuID), model.ThingTypeSku, getSyncFlag(v.SkuID))
|
||||
}
|
||||
} else if isForceUpdate {
|
||||
OnUpdateThing(ctx, db, vendorInfo, int64(v.SkuID), model.ThingTypeSku)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
OnCreateThing(ctx, db, vendorInfo, int64(v.SkuID), model.ThingTypeSku)
|
||||
//表示根据某门店的门店商品同步京东商品库中,这个门店关注并可售了这个商品,插到thingmap里同步标志是待创建(SyncFlagNewMask)才会创建
|
||||
//若该门店没关注可售,那插到thingmap里的话就该同步标志为0,就不会创建
|
||||
//getSyncFlag
|
||||
OnCreateThing(ctx, db, vendorInfo, int64(v.SkuID), model.ThingTypeSku, getSyncFlag(v.SkuID))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -550,14 +567,14 @@ func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
if !model.IsSyncStatusDelete(v.CatSyncStatus) {
|
||||
if remoteCatMap[v.VendorCatID] == 0 {
|
||||
if !model.IsSyncStatusNew(v.CatSyncStatus) {
|
||||
OnCreateThing(ctx, db, vendorInfo, int64(v.ID), model.ThingTypeCategory)
|
||||
OnCreateThing(ctx, db, vendorInfo, int64(v.ID), model.ThingTypeCategory, model.SyncFlagNewMask)
|
||||
}
|
||||
} else if isForceUpdate && !model.IsSyncStatusUpdate(v.CatSyncStatus) {
|
||||
OnUpdateThing(ctx, db, vendorInfo, int64(v.ID), model.ThingTypeCategory)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
OnCreateThing(ctx, db, vendorInfo, int64(v.ID), model.ThingTypeCategory)
|
||||
OnCreateThing(ctx, db, vendorInfo, int64(v.ID), model.ThingTypeCategory, model.SyncFlagNewMask)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -598,7 +615,7 @@ func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func FullSyncVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, vendorOrgCode string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
func FullSyncVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID, vendorID int, vendorOrgCode string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
multiStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler)
|
||||
if multiStoreHandler == nil {
|
||||
return "", fmt.Errorf("vendorID:%d不是多门店平台", vendorID)
|
||||
@@ -608,7 +625,7 @@ func FullSyncVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo
|
||||
step := batchItemList[0].(int)
|
||||
switch step {
|
||||
case 0:
|
||||
_, err = amendAndPruneVendorStuff(ctx, task, vendorID, vendorOrgCode, false, isContinueWhenError, AmendPruneAll, false)
|
||||
_, err = amendAndPruneVendorStuff(ctx, task, storeID, vendorID, vendorOrgCode, false, isContinueWhenError, AmendPruneAll, false)
|
||||
case 1:
|
||||
_, err = SyncCategories(ctx, task, []int{vendorID}, []string{vendorOrgCode}, nil, false)
|
||||
case 2:
|
||||
|
||||
@@ -388,7 +388,7 @@ func syncStoreSku() {
|
||||
_, err = cms.CurVendorSync.LoopMultiStoresVendors(jxcontext.AdminCtx, db, "同步多门店平台商品库", false, true,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorInfo := batchItemList[0].(*cms.MultiStoreVendorInfo)
|
||||
_, err = cms.FullSyncVendorStuff(jxcontext.AdminCtx, task, vendorInfo.VendorID, vendorInfo.OrgCode, false, true)
|
||||
_, err = cms.FullSyncVendorStuff(jxcontext.AdminCtx, task, 0, vendorInfo.VendorID, vendorInfo.OrgCode, false, true)
|
||||
return retVal, err
|
||||
})
|
||||
errList.AddErr(err)
|
||||
|
||||
@@ -1770,3 +1770,20 @@ func GetStoreSkuCategoryMap(db *DaoDB, categoryID, storeID int) (storeSkuCategor
|
||||
GetRow(db, &storeSkuCategoryMap, sql, sqlParams)
|
||||
return storeSkuCategoryMap, err
|
||||
}
|
||||
|
||||
func GetStoreSkuListWithVendor(db *DaoDB, storeID, vendorID int, vendorOrgCode string) (skuList []*StoreSkuSyncInfo, err error) {
|
||||
sql := `
|
||||
SELECT DISTINCT b.*, c.vendor_thing_id vendor_sku_id
|
||||
FROM store_sku_bind a
|
||||
JOIN sku b ON a.sku_id = b.id AND b.deleted_at = ? AND b.status = ?
|
||||
LEFT JOIN thing_map c ON c.thing_id = b.id AND c.thing_type = ? AND c.vendor_id = ? AND c.vendor_org_code = ? AND c.deleted_at = ?
|
||||
WHERE a.deleted_at = ? AND a.status = ? AND a.store_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue, model.SkuStatusNormal,
|
||||
model.ThingTypeSku, vendorID, vendorOrgCode, utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue, model.StoreSkuBindStatusNormal, storeID,
|
||||
}
|
||||
err = GetRows(db, &skuList, sql, sqlParams)
|
||||
return skuList, err
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ type ThingMap struct {
|
||||
VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空
|
||||
|
||||
VendorThingID string `orm:"size(32);column(vendor_thing_id);index" json:"vendorThingID"`
|
||||
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
|
||||
SyncStatus int8 `orm:"default(0)" json:"syncStatus"`
|
||||
|
||||
Remark string `orm:"size(255)" json:"remark"`
|
||||
}
|
||||
|
||||
@@ -296,6 +296,7 @@ func (c *SyncController) AmendAndPruneStoreStuff() {
|
||||
// @Param token header string true "认证token"
|
||||
// @Param vendorID formData int true "平台ID(京东0 美团1 饿百3)"
|
||||
// @Param vendorOrgCode formData string true "平台账号"
|
||||
// @Param storeID formData int false "门店ID"
|
||||
// @Param isAsync formData bool false "是否异步操作"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
@@ -303,7 +304,7 @@ func (c *SyncController) AmendAndPruneStoreStuff() {
|
||||
// @router /FullSyncVendorStuff [post]
|
||||
func (c *SyncController) FullSyncVendorStuff() {
|
||||
c.callFullSyncVendorStuff(func(params *tSyncFullSyncVendorStuffParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.FullSyncVendorStuff(params.Ctx, nil, params.VendorID, params.VendorOrgCode, params.IsAsync, params.IsContinueWhenError)
|
||||
retVal, err = cms.FullSyncVendorStuff(params.Ctx, nil, params.StoreID, params.VendorID, params.VendorOrgCode, params.IsAsync, params.IsContinueWhenError)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user