From 9e94808c16783e0f0148839e63beb83dd0fce0a5 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 4 Jan 2019 15:52:43 +0800 Subject: [PATCH] - sort sku in SyncSku --- business/jxstore/cms/sync.go | 2 ++ business/jxutils/jxutils_cms.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index e549d70d9..1fbdf62dd 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "reflect" + "sort" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils" @@ -245,6 +246,7 @@ func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuI } err := dao.GetEntitiesByKV(db, &skuList, cond, true) if err == nil && len(skuList) > 0 { + sort.Sort(jxutils.SkuList(skuList)) // globals.SugarLogger.Debug(utils.Format4Output(skuList, false)) // todo 这里SetParallelCount(1)的原因是京东SPU特殊类型必须要序列化同步才能正常处理, db可能会有多线程问题 task := tasksch.NewParallelTask("SyncSku loop sku", tasksch.NewParallelConfig().SetParallelCount(1), userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { diff --git a/business/jxutils/jxutils_cms.go b/business/jxutils/jxutils_cms.go index 704b8536e..bf6b70005 100644 --- a/business/jxutils/jxutils_cms.go +++ b/business/jxutils/jxutils_cms.go @@ -205,3 +205,25 @@ func FormatSkuWeight(specQuality float32, specUnit string) int { } return int(specQuality) } + +type SkuList []*model.Sku + +func (s SkuList) Len() int { + return len(s) +} + +func (s SkuList) Less(i, j int) bool { + if s[i].NameID == s[j].NameID { + if s[i].SpecUnit == s[j].SpecUnit { + return s[i].SpecQuality < s[j].SpecQuality + } + return s[i].SpecUnit < s[j].SpecUnit + } + return s[i].NameID < s[j].NameID +} + +func (s SkuList) Swap(i, j int) { + tmp := s[i] + s[i] = s[j] + s[j] = tmp +}