- sort sku in SyncSku
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"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)
|
err := dao.GetEntitiesByKV(db, &skuList, cond, true)
|
||||||
if err == nil && len(skuList) > 0 {
|
if err == nil && len(skuList) > 0 {
|
||||||
|
sort.Sort(jxutils.SkuList(skuList))
|
||||||
// globals.SugarLogger.Debug(utils.Format4Output(skuList, false))
|
// globals.SugarLogger.Debug(utils.Format4Output(skuList, false))
|
||||||
// todo 这里SetParallelCount(1)的原因是京东SPU特殊类型必须要序列化同步才能正常处理, db可能会有多线程问题
|
// 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) {
|
task := tasksch.NewParallelTask("SyncSku loop sku", tasksch.NewParallelConfig().SetParallelCount(1), userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||||
|
|||||||
@@ -205,3 +205,25 @@ func FormatSkuWeight(specQuality float32, specUnit string) int {
|
|||||||
}
|
}
|
||||||
return int(specQuality)
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user