From 1530c85855f4e269fe443a4ce218d72ea8c59915 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 6 Jun 2019 10:33:04 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E6=94=B9genFakeID1=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E4=BC=9A=E7=94=9F=E6=88=90=E9=87=8D=E5=A4=8D=E7=9A=84?= =?UTF-8?q?ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxutils/jxutils_cms.go | 19 ++++++++++++++++++- business/model/dao/store_sku.go | 21 +++++++++++++++++++++ business/model/model.go | 26 ++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/business/jxutils/jxutils_cms.go b/business/jxutils/jxutils_cms.go index 849255137..7f089dfa6 100644 --- a/business/jxutils/jxutils_cms.go +++ b/business/jxutils/jxutils_cms.go @@ -9,6 +9,7 @@ import ( "reflect" "regexp" "strings" + "sync" "time" "git.rosy.net.cn/baseapi/platformapi" @@ -235,9 +236,25 @@ func IsSkuSpecial(specQuality float32, specUnit string) bool { return int(specQuality) == model.SpecialSpecQuality && (specUnit == model.SpecialSpecUnit || specUnit == model.SpecialSpecUnit2) } +var lastFakeID int64 +var lastFakeIDMutex sync.RWMutex + // 生成一个不重复的临时ID func genFakeID1() int64 { - return time.Now().UnixNano() / 1000000 + for { + fakeID := time.Now().UnixNano() / 1000 + lastFakeIDMutex.RLock() + if fakeID == lastFakeID { + lastFakeIDMutex.RUnlock() + time.Sleep(1 * time.Microsecond) + } else { + lastFakeIDMutex.RUnlock() + lastFakeIDMutex.Lock() + defer lastFakeIDMutex.Unlock() + lastFakeID = fakeID + return fakeID + } + } } // 这个用于没有打开远程同步时的假同步,生成ID使用 diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 8ddc2f494..05ea5016b 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -360,3 +360,24 @@ func GetDescImgFieldName(vendorID int) (fieldName string) { } return fieldName } + +func GetStoresSkusInfo(db *DaoDB, storeIDs, skuIDs []int) (storeSkuList []*model.StoreSkuBind, err error) { + sql := ` + SELECT * + FROM store_sku_bind t1 + WHERE t1.deleted_at = ? + ` + sqlParams := []interface{}{ + utils.DefaultTimeValue, + } + if len(storeIDs) > 0 { + sql += " AND t1.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")" + sqlParams = append(sqlParams, storeIDs) + } + if len(skuIDs) > 0 { + sql += " AND t1.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")" + sqlParams = append(sqlParams, skuIDs) + } + err = GetRows(db, &storeSkuList, sql, sqlParams...) + return storeSkuList, err +} diff --git a/business/model/model.go b/business/model/model.go index 3404b69da..62f654827 100644 --- a/business/model/model.go +++ b/business/model/model.go @@ -45,6 +45,8 @@ const ( FieldVendorOrderID = "VendorOrderID" FieldVendorOrderID2 = "VendorOrderID2" + + FieldVendorActID = "VendorActID" ) type ModelIDCUL struct { @@ -80,6 +82,30 @@ const ( SyncFlagStoreAddress = 16 ) +func IsSyncStatusNew(syncStatus int) bool { + return (syncStatus & SyncFlagNewMask) != 0 +} + +func IsSyncStatusDelete(syncStatus int) bool { + return (syncStatus & SyncFlagDeletedMask) != 0 +} + +func IsSyncStatusUpdate(syncStatus int) bool { + return (syncStatus & SyncFlagModifiedMask) != 0 +} + +func IsSyncStatusNeedCreate(syncStatus int) bool { + return IsSyncStatusNew(syncStatus) && !IsSyncStatusDelete(syncStatus) +} + +func IsSyncStatusNeedDelete(syncStatus int) bool { + return !IsSyncStatusNew(syncStatus) && IsSyncStatusDelete(syncStatus) +} + +func IsSyncStatusNeedUpdate(syncStatus int) bool { + return !IsSyncStatusNew(syncStatus) && !IsSyncStatusDelete(syncStatus) && IsSyncStatusUpdate(syncStatus) +} + // const ( // KeyJdFlag = "jdFlag" // KeyJdSyncedAt = "jdSyncedAt"