Merge remote-tracking branch 'origin/mark' into yonghui

This commit is contained in:
苏尹岚
2019-12-06 09:05:16 +08:00
17 changed files with 478 additions and 256 deletions

View File

@@ -604,6 +604,7 @@ func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName s
}
skuNameExt.SkuName.Status = model.SkuStatusNormal
if skuNameExt.IsSpu == 1 {
return nil, fmt.Errorf("不允许创建多规格商品")
skuNameExt.SkuName.JdSyncStatus = model.SyncFlagNewMask
}
if skuNameExt.Unit == model.SpecialUnit {
@@ -1044,7 +1045,7 @@ func refreshStoreSkuPrice(ctx *jxcontext.Context, db *dao.DaoDB, skuID int) (err
storeSku.ID = v.BindID
if _, err = dao.UpdateEntityLogically(db, storeSku, map[string]interface{}{
"Price": v.Price,
dao.GetSyncStatusStructField(model.VendorNames[vendorID]): v.StoreSkuSyncStatus | model.SyncFlagPriceMask,
dao.GetSyncStatusStructField(model.VendorNames[vendorID]): v.SkuSyncStatus | model.SyncFlagPriceMask,
}, ctx.GetUserName(), nil); err != nil {
return err
}

View File

@@ -38,11 +38,6 @@ type SingleStoreHandlerWrapper struct {
partner.ISingleStoreHandler
}
type tMultiStoreVendorInfo struct {
VendorID int
OrgCode string
}
var (
CurVendorSync VendorSync
)
@@ -101,20 +96,6 @@ func (v *VendorSync) GetSingleStoreHandler(vendorID int) partner.ISingleStoreHan
return nil
}
func getMultiStoreVendorInfoList() (list []*tMultiStoreVendorInfo) {
vendorIDs := partner.GetMultiStoreVendorIDs()
for _, vendorID := range vendorIDs {
orgCodeList := partner.CurAPIManager.GetAppOrgCodeList(vendorID)
for _, v := range orgCodeList {
list = append(list, &tMultiStoreVendorInfo{
VendorID: vendorID,
OrgCode: v,
})
}
}
return list
}
func (v *VendorSync) syncCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, db *dao.DaoDB, cats []*model.SkuCategory, userName string) (err error) {
multiStoresHandler := v.GetMultiStoreHandler(vendorID)
syncStatusFieldName := dao.GetSyncStatusStructField(model.VendorNames[vendorID])
@@ -430,11 +411,11 @@ func (v *VendorSync) proxySyncStoreSku(ctx *jxcontext.Context, parentTask tasksc
return SyncStoreSkuNew(ctx, parentTask, storeMap.VendorID, storeMap.StoreID, storeMap.VendorStoreID, nil, skuIDs, excludeSkuIDs, isAsync, isContinueWhenError)
}
func (v *VendorSync) proxyFullSyncStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeMap *model.StoreMap, isAsync, isContinueWhenError bool) (hint string, err error) {
return FullSyncStoreSkuNew(ctx, parentTask, storeMap.VendorID, storeMap.StoreID, storeMap.VendorStoreID, isAsync, isContinueWhenError)
func (v *VendorSync) proxyFullSyncStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeMap *model.StoreMap, excludeSkuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
return FullSyncStoreSkuNew(ctx, parentTask, storeMap.VendorID, storeMap.StoreID, storeMap.VendorStoreID, excludeSkuIDs, isAsync, isContinueWhenError)
}
func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled, isAsync, isContinueWhenError bool) (hint string, err error) {
func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled bool, excludeSkuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
globals.SugarLogger.Debug("FullSyncStoresSkus")
hint, err = v.LoopStoresMap(ctx, db, fmt.Sprintf("初始化门店商品信息:%v", storeIDs), isAsync, true, vendorIDs, storeIDs,
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
@@ -449,7 +430,7 @@ func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, v
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeMap := batchItemList[0].(*model.StoreMap)
if syncDisabled || storeMap.Status > model.StoreStatusDisabled {
if _, err = v.proxyFullSyncStoreSku(ctx, task, storeMap, false, isContinueWhenError); err != nil {
if _, err = v.proxyFullSyncStoreSku(ctx, task, storeMap, excludeSkuIDs, false, isContinueWhenError); err != nil {
globals.SugarLogger.Debugf("FullSyncStoresSkus failed2 store:%d failed with error:%v", storeMap.StoreID, err)
}
}
@@ -715,59 +696,3 @@ func GetTimeMixByInt(begin1, end1, begin2, end2 int16) (beginAt, endAt int16) {
}
return beginAt, endAt
}
func OnCreateThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingType int8) (err error) {
for _, v := range getMultiStoreVendorInfoList() {
thingMap := &model.ThingMap{
ThingID: thingID,
ThingType: thingType,
VendorID: v.VendorID,
VendorOrgCode: v.OrgCode,
SyncStatus: model.SyncFlagNewMask,
}
dao.WrapAddIDCULDEntity(thingMap, ctx.GetUserName())
err = dao.CreateEntity(db, thingMap)
}
return nil
}
func OnUpdateThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingType int8) (err error) {
for _, v := range getMultiStoreVendorInfoList() {
thingMap := &model.ThingMap{
ThingID: thingID,
ThingType: thingType,
VendorID: v.VendorID,
VendorOrgCode: v.OrgCode,
}
thingMap.DeletedAt = utils.DefaultTimeValue
if err = dao.GetEntity(db, thingMap, "ThingID", "ThingType", "VendorID", "VendorOrgCode", model.FieldDeletedAt); err == nil {
thingMap.SyncStatus |= model.SyncFlagModifiedMask
thingMap.LastOperator = ctx.GetUserName()
_, err = dao.UpdateEntity(db, thingMap)
}
}
return nil
}
func OnDeleteThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingType int8) (err error) {
for _, v := range getMultiStoreVendorInfoList() {
thingMap := &model.ThingMap{
ThingID: thingID,
ThingType: thingType,
VendorID: v.VendorID,
VendorOrgCode: v.OrgCode,
}
thingMap.DeletedAt = utils.DefaultTimeValue
if err = dao.GetEntity(db, thingMap, "ThingID", "ThingType", "VendorID", "VendorOrgCode", model.FieldDeletedAt); err == nil {
if model.IsSyncStatusNew(thingMap.SyncStatus) {
thingMap.SyncStatus = 0
} else {
thingMap.SyncStatus |= model.SyncFlagDeletedMask
}
_, err = dao.DeleteEntityLogically(db, thingMap, map[string]interface{}{
model.FieldSyncStatus: thingMap.SyncStatus,
}, ctx.GetUserName(), nil)
}
}
return nil
}

View File

@@ -1,30 +1,206 @@
package cms
import (
"fmt"
"time"
"git.rosy.net.cn/baseapi/utils"
"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"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
)
type tMultiStoreVendorInfo struct {
VendorID int
OrgCode string
}
func CombineVendorIDAndOrgCode(vendorID int, orgCode string) string {
return fmt.Sprintf("%d-%s", vendorID, orgCode)
}
func getMultiStoreVendorInfoList() (list []*tMultiStoreVendorInfo) {
vendorIDs := partner.GetMultiStoreVendorIDs()
for _, vendorID := range vendorIDs {
orgCodeList := partner.CurAPIManager.GetAppOrgCodeList(vendorID)
for _, v := range orgCodeList {
list = append(list, &tMultiStoreVendorInfo{
VendorID: vendorID,
OrgCode: v,
})
}
}
return list
}
func SyncCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs []int, appOrgCodes []string, catIDs []int, isAsync bool) (hint string, err error) {
// if len(vendorIDs) == 0 {
// vendorIDs = partner.GetMultiStoreVendorIDs()
// }
// vendorOrgCodeList := apimanager.CurAPIManager.GetVendorOrgCodeList(vendorIDs, appOrgCodes)
// task := tasksch.NewParallelTask("同步商家分类", nil, ctx,
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
// vendorOrgCodePair := batchItemList[0].(*apimanager.VendorOrgCodePair)
// if handler := partner.GetPurchasePlatformFromVendorID(vendorOrgCodePair.VendorID); handler != nil {
// }
// return retVal, err
// }, vendorOrgCodeList)
// tasksch.HandleTask(task, parentTask, len(catIDs) > 0).Run()
// if isAsync {
// hint = task.GetID()
// } else {
// resultList, err2 := task.GetResult(0)
// if err = err2; err == nil {
// hint = utils.Int2Str(len(resultList))
// }
// }
globals.SugarLogger.Debugf("SyncCategories catIDs:%v", catIDs)
db := dao.GetDB()
catList, err := dao.GetSkuCategoryWithVendor(db, nil, nil, -1, catIDs, true)
if err == nil {
// todo 按vendorID orgCode合并操作
task := tasksch.NewParallelTask(fmt.Sprintf("同步分类:%v", catIDs), nil, ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
catVendorInfo := batchItemList[0].(*dao.SkuCategoryWithVendor)
if multiStoresHandler, ok := partner.GetPurchasePlatformFromVendorID(catVendorInfo.VendorID).(partner.IMultipleStoresHandler); ok {
if model.IsSyncStatusDelete(catVendorInfo.SyncStatus) { //删除
if !dao.IsVendorThingIDEmpty(catVendorInfo.VendorCatID) &&
model.IsSyncStatusNeedDelete(catVendorInfo.SyncStatus) {
err = multiStoresHandler.DeleteCategory2(ctx, catVendorInfo)
}
} else if model.IsSyncStatusNew(catVendorInfo.SyncStatus) { // 新增
err = multiStoresHandler.CreateCategory2(ctx, catVendorInfo)
} else if model.IsSyncStatusUpdate(catVendorInfo.SyncStatus) { // 修改
err = multiStoresHandler.UpdateCategory2(ctx, catVendorInfo)
}
} else {
err = fmt.Errorf("平台:%d不合法", catVendorInfo.VendorID)
}
if err = OnThingSync(ctx, dao.GetDB(), SkuCategoryVendor2ThingMap(catVendorInfo), err); err == nil {
retVal = []int{catVendorInfo.ID}
}
return retVal, err
}, catList)
tasksch.HandleTask(task, parentTask, len(catIDs) > 0).Run()
if isAsync {
hint = task.GetID()
} else {
resultList, err2 := task.GetResult(0)
if err = err2; err == nil {
hint = utils.Int2Str(len(resultList))
}
}
}
return hint, err
}
func SyncReorderCategories(ctx *jxcontext.Context, parentCatID int, isAsync bool) (hint string, err error) {
globals.SugarLogger.Debugf("SyncReorderCategories parentCatID:%d", parentCatID)
db := dao.GetDB()
hint, err = CurVendorSync.LoopMultiStoresVendors(ctx, db, fmt.Sprintf("分类重排序:%d", parentCatID), isAsync, false,
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
vendorInfo := batchItemList[0].(*tMultiStoreVendorInfo)
multiStoresHandler := CurVendorSync.GetMultiStoreHandler(vendorInfo.VendorID)
if multiStoresHandler != nil {
catList, err2 := dao.GetSkuCategoryWithVendor(db, []int{vendorInfo.VendorID}, []string{vendorInfo.OrgCode}, parentCatID, nil, false)
if err = err2; err == nil {
var vendorCatIDList []string
for _, v := range catList {
if v.VendorCatID != "" {
vendorCatIDList = append(vendorCatIDList, v.VendorCatID)
}
}
if len(vendorCatIDList) > 0 {
if err = multiStoresHandler.ReorderCategories2(ctx, vendorInfo.OrgCode, catList[0].VendorParentCatID, vendorCatIDList); err == nil {
retVal = []int{len(vendorCatIDList)}
}
}
}
} else {
err = fmt.Errorf("非法平台:%d", vendorInfo.VendorID)
}
return retVal, err
})
return hint, err
}
func OnCreateThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingType int8) (err error) {
for _, v := range getMultiStoreVendorInfoList() {
thingMap := &model.ThingMap{
ThingID: thingID,
ThingType: thingType,
VendorID: v.VendorID,
VendorOrgCode: v.OrgCode,
SyncStatus: model.SyncFlagNewMask,
}
dao.WrapAddIDCULDEntity(thingMap, ctx.GetUserName())
err = dao.CreateEntity(db, thingMap)
}
return nil
}
func OnUpdateThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingType int8) (err error) {
for _, v := range getMultiStoreVendorInfoList() {
thingMap := &model.ThingMap{
ThingID: thingID,
ThingType: thingType,
VendorID: v.VendorID,
VendorOrgCode: v.OrgCode,
}
thingMap.DeletedAt = utils.DefaultTimeValue
if err = dao.GetEntity(db, thingMap, "ThingID", "ThingType", "VendorID", "VendorOrgCode", model.FieldDeletedAt); err == nil {
thingMap.SyncStatus |= model.SyncFlagModifiedMask
thingMap.LastOperator = ctx.GetUserName()
_, err = dao.UpdateEntity(db, thingMap)
}
}
return nil
}
func OnDeleteThing(ctx *jxcontext.Context, db *dao.DaoDB, thingID int64, thingType int8) (err error) {
for _, v := range getMultiStoreVendorInfoList() {
thingMap := &model.ThingMap{
ThingID: thingID,
ThingType: thingType,
VendorID: v.VendorID,
VendorOrgCode: v.OrgCode,
}
thingMap.DeletedAt = utils.DefaultTimeValue
if err = dao.GetEntity(db, thingMap, "ThingID", "ThingType", "VendorID", "VendorOrgCode", model.FieldDeletedAt); err == nil {
if model.IsSyncStatusNew(thingMap.SyncStatus) {
thingMap.SyncStatus = 0
thingMap.DeletedAt = time.Now()
} else {
thingMap.SyncStatus |= model.SyncFlagDeletedMask
}
thingMap.LastOperator = ctx.GetUserName()
_, err = dao.UpdateEntity(db, thingMap)
}
}
return nil
}
func SkuCategoryVendor2ThingMap(cat *dao.SkuCategoryWithVendor) (thingMap *model.ThingMap) {
thingMap = &model.ThingMap{
ThingID: int64(cat.ID),
ThingType: model.ThingTypeCategory,
VendorID: cat.VendorID,
VendorOrgCode: cat.VendorOrgCode,
SyncStatus: cat.SyncStatus,
VendorThingID: cat.VendorCatID,
}
thingMap.ID = cat.MapID // 一定要赋值
return thingMap
}
func OnThingSync(ctx *jxcontext.Context, db *dao.DaoDB, thingMap *model.ThingMap, syncErr error) (err error) {
if syncErr != nil {
err = syncErr
thingMap.Remark = utils.LimitUTF8StringLen(err.Error(), 255)
dao.UpdateEntity(db, thingMap, "Remark")
} else {
updateFields := []string{
model.FieldSyncStatus,
model.FieldUpdatedAt,
model.FieldLastOperator,
"Remark",
}
if model.IsSyncStatusDelete(thingMap.SyncStatus) { //删除
thingMap.DeletedAt = time.Now()
thingMap.VendorThingID = ""
updateFields = append(updateFields, "VendorThingID", model.FieldDeletedAt)
} else if model.IsSyncStatusNew(thingMap.SyncStatus) { // 新增
updateFields = append(updateFields, "VendorThingID")
}
thingMap.SyncStatus = 0
thingMap.LastOperator = ctx.GetUserName()
thingMap.UpdatedAt = time.Now()
thingMap.Remark = ""
_, err = dao.UpdateEntity(db, thingMap, updateFields...)
}
return err
}

View File

@@ -80,14 +80,14 @@ func SyncStoreCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo
catInfo := batchItemList[0].(*dao.SkuStoreCatInfo)
storeCatMap := &model.StoreSkuCategoryMap{}
storeCatMap.ID = catInfo.MapID
if model.IsSyncStatusDelete(catInfo.StoreCatSyncStatus) { // 删除
if model.IsSyncStatusDelete(catInfo.StoreCatSyncStatus) && !dao.IsVendorThingIDEmpty(catInfo.VendorCatID) {
if model.IsSyncStatusDelete(catInfo.CatSyncStatus) { // 删除
if model.IsSyncStatusDelete(catInfo.CatSyncStatus) && !dao.IsVendorThingIDEmpty(catInfo.VendorCatID) {
err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, catInfo.VendorCatID, level)
if err != nil && handler.IsErrCategoryNotExist(err) {
err = nil
}
}
} else if model.IsSyncStatusNew(catInfo.StoreCatSyncStatus) { // 新增
} else if model.IsSyncStatusNew(catInfo.CatSyncStatus) { // 新增
err = handler.CreateStoreCategory(ctx, storeID, vendorStoreID, catInfo)
if err != nil && handler.IsErrCategoryExist(err) {
if cat, err2 := handler.GetStoreCategory(ctx, storeID, vendorStoreID, catInfo.Name); err2 == nil {
@@ -102,7 +102,7 @@ func SyncStoreCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo
updateFields = append(updateFields, model.FieldLastOperator)
}
}
} else if model.IsSyncStatusUpdate(catInfo.StoreCatSyncStatus) { // 修改
} else if model.IsSyncStatusUpdate(catInfo.CatSyncStatus) { // 修改
if err = handler.UpdateStoreCategory(ctx, storeID, vendorStoreID, catInfo); err == nil {
updateFields = append(updateFields, idFieldName)
}
@@ -163,7 +163,7 @@ func SyncStoreSkuNew2(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID
return hint, err
}
func FullSyncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) {
func FullSyncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, excludeSkuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
task := tasksch.NewParallelTask("FullSyncStoreSkuNew", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
@@ -178,9 +178,9 @@ func FullSyncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo
}
case 1:
if singleStoreHandler != nil {
_, err = SyncStoreSkuNew(ctx, task, vendorID, storeID, vendorStoreID, nil, nil, nil, false, isContinueWhenError)
_, err = SyncStoreSkuNew(ctx, task, vendorID, storeID, vendorStoreID, nil, nil, excludeSkuIDs, false, isContinueWhenError)
} else {
err = syncStoreSkuNew(ctx, task, true, vendorID, storeID, nil, nil, nil, false, isContinueWhenError)
err = syncStoreSkuNew(ctx, task, true, vendorID, storeID, nil, nil, excludeSkuIDs, false, isContinueWhenError)
}
}
return retVal, err
@@ -195,7 +195,7 @@ func FullSyncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo
}
func isStoreSkuSyncNeedDelete(storeSku *dao.StoreSkuSyncInfo) bool {
return model.IsSyncStatusDelete(storeSku.StoreSkuSyncStatus) || storeSku.BindDeletedAt != utils.DefaultTimeValue || storeSku.BindID == 0 || storeSku.NameID == 0
return model.IsSyncStatusDelete(storeSku.SkuSyncStatus) || storeSku.BindDeletedAt != utils.DefaultTimeValue || storeSku.BindID == 0 || storeSku.NameID == 0
}
func storeSkuSyncInfo2Bare(inSku *dao.StoreSkuSyncInfo) (outSku *partner.StoreSkuInfo) {
@@ -237,10 +237,10 @@ func sku2Update(vendorID int, sku *dao.StoreSkuSyncInfo, syncStatus int8) (item
kvs := map[string]interface{}{}
if syncStatus&(model.SyncFlagDeletedMask|model.SyncFlagNewMask|model.SyncFlagModifiedMask) != 0 {
if model.IsSyncStatusNew(syncStatus) {
sku.StoreSkuSyncStatus = 0
sku.SkuSyncStatus = 0
kvs[dao.GetVendorThingIDStructField(model.VendorNames[vendorID])] = utils.Str2Int64WithDefault(sku.VendorSkuID, 0)
} else if model.IsSyncStatusDelete(syncStatus) {
sku.StoreSkuSyncStatus = 0
sku.SkuSyncStatus = 0
if utils.IsTimeZero(sku.BindDeletedAt) && (sku.ID == 0 || sku.NameID == 0) {
kvs[model.FieldDeletedAt] = time.Now()
}
@@ -248,18 +248,18 @@ func sku2Update(vendorID int, sku *dao.StoreSkuSyncInfo, syncStatus int8) (item
kvs[dao.GetVendorThingIDStructField(model.VendorNames[vendorID])] = 0
}
} else {
sku.StoreSkuSyncStatus = sku.StoreSkuSyncStatus & model.SyncFlagPriceMask
sku.SkuSyncStatus = sku.SkuSyncStatus & model.SyncFlagPriceMask
}
} else if syncStatus&model.SyncFlagStockMask != 0 {
if isStoreSkuSyncNeedDelete(sku) {
sku.StoreSkuSyncStatus = 0
sku.SkuSyncStatus = 0
} else {
sku.StoreSkuSyncStatus = sku.StoreSkuSyncStatus & (model.SyncFlagPriceMask | model.SyncFlagSaleMask)
sku.SkuSyncStatus = sku.SkuSyncStatus & (model.SyncFlagPriceMask | model.SyncFlagSaleMask)
}
} else {
sku.StoreSkuSyncStatus = sku.StoreSkuSyncStatus & ^syncStatus
sku.SkuSyncStatus = sku.SkuSyncStatus & ^syncStatus
}
kvs[dao.GetSyncStatusStructField(model.VendorNames[vendorID])] = sku.StoreSkuSyncStatus
kvs[dao.GetSyncStatusStructField(model.VendorNames[vendorID])] = sku.SkuSyncStatus
if sku.VendorPrice > 0 {
kvs[dao.GetVendorPriceStructField(model.VendorNames[vendorID])] = sku.VendorPrice
}
@@ -352,10 +352,10 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
} else {
updateItems = append(updateItems, sku2Update(vendorID, sku, model.SyncFlagDeletedMask))
}
} else if model.IsSyncStatusNew(sku.StoreSkuSyncStatus) {
} else if model.IsSyncStatusNew(sku.SkuSyncStatus) {
calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage))
if singleStoreHandler == nil {
sku.StoreSkuSyncStatus |= model.SyncFlagSaleMask | model.SyncFlagPriceMask
sku.SkuSyncStatus |= model.SyncFlagSaleMask | model.SyncFlagPriceMask
bareSku = storeSkuSyncInfo2Bare(sku)
stockList = append(stockList, bareSku)
priceList = append(priceList, bareSku)
@@ -367,7 +367,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
} else {
if sku.MergedStatus == model.SkuStatusNormal {
if dao.IsVendorThingIDEmpty(sku.VendorCatID) {
globals.SugarLogger.Warnf("syncStoreSkuNew 创建门店:%d商品:%d但没有平台分类ID", sku.StoreID, sku.SkuID)
globals.SugarLogger.Warnf("syncStoreSkuNew 创建门店:%d商品:%d但没有平台分类ID", storeID, sku.SkuID)
} else {
createList = append(createList, sku)
}
@@ -384,26 +384,26 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
} else {
isAdded2Update := false
// 修改商品信息时不改价(以免活动引起的失败),而用单独的改价来改
if (model.IsSyncStatusUpdate(sku.StoreSkuSyncStatus) || (model.IsSyncStatusSeq(sku.StoreSkuSyncStatus) && reorderHandler == nil)) && singleStoreHandler != nil {
if (model.IsSyncStatusUpdate(sku.SkuSyncStatus) || (model.IsSyncStatusSeq(sku.SkuSyncStatus) && reorderHandler == nil)) && singleStoreHandler != nil {
if dao.IsVendorThingIDEmpty(sku.VendorCatID) {
globals.SugarLogger.Warnf("syncStoreSkuNew 修改门店:%d商品:%d但没有平台分类ID", sku.StoreID, sku.SkuID)
globals.SugarLogger.Warnf("syncStoreSkuNew 修改门店:%d商品:%d但没有平台分类ID", storeID, sku.SkuID)
} else {
isAdded2Update = true
updateList = append(updateList, calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)))
}
}
if model.IsSyncStatusPrice(sku.StoreSkuSyncStatus) {
if model.IsSyncStatusPrice(sku.SkuSyncStatus) {
bareSku = storeSkuSyncInfo2Bare(calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)))
priceList = append(priceList, bareSku)
}
if !isAdded2Update {
if model.IsSyncStatusUpdate(sku.StoreSkuSyncStatus) && singleStoreHandler == nil { // 正常就不应该进到这里
if model.IsSyncStatusUpdate(sku.SkuSyncStatus) && singleStoreHandler == nil { // 正常就不应该进到这里
if bareSku == nil {
bareSku = storeSkuSyncInfo2Bare(sku)
}
updateItems = append(updateItems, sku2Update(vendorID, sku, model.SyncFlagStockMask))
}
if model.IsSyncStatusSale(sku.StoreSkuSyncStatus) {
if model.IsSyncStatusSale(sku.SkuSyncStatus) {
if bareSku == nil {
bareSku = storeSkuSyncInfo2Bare(sku)
}
@@ -419,7 +419,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
}
}
}
isNeedReorder = model.IsSyncStatusSeq(sku.StoreSkuSyncStatus)
isNeedReorder = model.IsSyncStatusSeq(sku.SkuSyncStatus)
}
}
if isNeedReorder && reorderHandler != nil && sku.VendorCatID != "" {
@@ -660,10 +660,10 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v
if opType == AmendPruneOnlyAmend || opType == AmendPruneAll {
for _, v := range localSkuList {
if !model.IsSyncStatusDelete(v.StoreSkuSyncStatus) && v.BindID != 0 {
if !model.IsSyncStatusDelete(v.SkuSyncStatus) && v.BindID != 0 {
syncStatus := int8(0)
if remoteSkuMap[v.VendorSkuID] == 0 {
if !model.IsSyncStatusNew(v.StoreSkuSyncStatus) {
if !model.IsSyncStatusNew(v.SkuSyncStatus) {
syncStatus = model.SyncFlagNewMask
}
} else if isForceUpdate {
@@ -674,7 +674,7 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v
skuBind.ID = v.BindID
skuBind.LastOperator = ctx.GetUserName()
skuBind.UpdatedAt = time.Now()
dao.SetStoreSkuBindSyncStatus(skuBind, vendorID, syncStatus|v.StoreSkuSyncStatus)
dao.SetStoreSkuBindSyncStatus(skuBind, vendorID, syncStatus|v.SkuSyncStatus)
dao.UpdateEntity(db, skuBind, dao.GetSyncStatusStructField(model.VendorNames[vendorID]), model.FieldLastOperator, model.FieldUpdatedAt)
}
}
@@ -710,13 +710,13 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v
cat2Delete = checkRemoteCatExist(remoteCatMap, localCatMap, remoteCatList)
for _, v := range localCatList {
if !model.IsSyncStatusDelete(v.StoreCatSyncStatus) && v.MapID != 0 {
if !model.IsSyncStatusDelete(v.CatSyncStatus) && v.MapID != 0 {
syncStatus := int8(0)
if remoteCatMap[v.VendorCatID] == 0 {
if !model.IsSyncStatusNew(v.StoreCatSyncStatus) {
if !model.IsSyncStatusNew(v.CatSyncStatus) {
syncStatus = model.SyncFlagNewMask
}
} else if isForceUpdate && !model.IsSyncStatusUpdate(v.StoreCatSyncStatus) {
} else if isForceUpdate && !model.IsSyncStatusUpdate(v.CatSyncStatus) {
syncStatus = model.SyncFlagModifiedMask
}
if syncStatus != 0 {
@@ -724,7 +724,7 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v
catBind.ID = v.MapID
catBind.LastOperator = ctx.GetUserName()
catBind.UpdatedAt = time.Now()
dao.SetStoreCatMapSyncStatus(catBind, vendorID, syncStatus|v.StoreCatSyncStatus)
dao.SetStoreCatMapSyncStatus(catBind, vendorID, syncStatus|v.CatSyncStatus)
dao.UpdateEntity(db, catBind, dao.GetSyncStatusStructField(model.VendorNames[vendorID]), model.FieldLastOperator, model.FieldUpdatedAt)
}
}

View File

@@ -144,12 +144,12 @@ func doDailyWork() {
globals.SugarLogger.Debug("doDailyWork")
cms.SyncStoresCourierInfo(jxcontext.AdminCtx, nil, false, true)
netprinter.RebindAllPrinters(jxcontext.AdminCtx, false, true)
// cms.CurVendorSync.FullSyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, false, true, true)
syncFlag := model.SyncFlagPriceMask
if (time.Now().Unix()/24*3600)%10 == 0 {
syncFlag |= model.SyncFlagSaleMask
}
cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, false, nil, []int{27379}, syncFlag, true, true)
// cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, false, nil, []int{27379}, syncFlag, true, true)
cms.CurVendorSync.FullSyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, false, []int{27379}, true, true)
SaveImportantTaskID(TaskNameSyncStoreSku, SpecialTaskID)
taskID, _ := cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDEBAI, model.VendorIDMTWM}, nil, false, nil, nil, syncFlag, true, true)

View File

@@ -631,7 +631,7 @@ func TransformJdSpu2Sku(ctx *jxcontext.Context, skuNameIDs []int, count int, isA
return "", fmt.Errorf("待转换的skuName为空")
}
batchSize := 40
rootTask := tasksch.NewSeqTask("TransformJdSpu2Sku", ctx,
rootTask := tasksch.NewSeqTask2("TransformJdSpu2Sku", ctx, isContinueWhenError,
func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
var (
locker sync.Mutex