- fixed bug in calculate max parallelCount in tasksch.RunTask
- multi-task for stores in jd.SyncStoreSkus - calculate platform price use platform price_percentage. - GoodsOrder json StoreName.
This commit is contained in:
@@ -127,3 +127,7 @@ func CaculateSkuPrice(unitPrice int, specQuality float32, specUnit string, skuNa
|
|||||||
func GetSliceLen(list interface{}) int {
|
func GetSliceLen(list interface{}) int {
|
||||||
return reflect.ValueOf(list).Len()
|
return reflect.ValueOf(list).Len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CaculateSkuVendorPrice(price int, percentage int) int {
|
||||||
|
return price * percentage / 100
|
||||||
|
}
|
||||||
|
|||||||
@@ -83,12 +83,12 @@ func RunTask(taskName string, isContinueWhenError bool, resultHandler ResultHand
|
|||||||
if parallelCount > MaxParallelCount || parallelCount == 0 {
|
if parallelCount > MaxParallelCount || parallelCount == 0 {
|
||||||
parallelCount = MaxParallelCount
|
parallelCount = MaxParallelCount
|
||||||
}
|
}
|
||||||
listLen := jxutils.GetSliceLen(itemList)
|
|
||||||
if parallelCount > listLen {
|
|
||||||
parallelCount = listLen
|
|
||||||
}
|
|
||||||
realItemList := utils.Interface2Slice(itemList)
|
realItemList := utils.Interface2Slice(itemList)
|
||||||
jobList := jxutils.SplitSlice(realItemList, batchSize)
|
jobList := jxutils.SplitSlice(realItemList, batchSize)
|
||||||
|
jobListLen := jxutils.GetSliceLen(jobList)
|
||||||
|
if parallelCount > jobListLen {
|
||||||
|
parallelCount = jobListLen
|
||||||
|
}
|
||||||
task := &Task{
|
task := &Task{
|
||||||
ID: utils.GetUUID(),
|
ID: utils.GetUUID(),
|
||||||
Name: taskName,
|
Name: taskName,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ type GoodsOrder struct {
|
|||||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"`
|
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"`
|
||||||
StoreID int `orm:"column(store_id)" json:"storeID"` // 外部系统里记录的 jxstoreid
|
StoreID int `orm:"column(store_id)" json:"storeID"` // 外部系统里记录的 jxstoreid
|
||||||
JxStoreID int `orm:"column(jx_store_id)" json:"jxStoreID"` // 根据VendorStoreID在本地系统里查询出来的 jxstoreid
|
JxStoreID int `orm:"column(jx_store_id)" json:"jxStoreID"` // 根据VendorStoreID在本地系统里查询出来的 jxstoreid
|
||||||
StoreName string `orm:"size(64)" json:"-"`
|
StoreName string `orm:"size(64)" json:"storeName"`
|
||||||
ShopPrice int64 `json:"shopPrice"` // 单位为分 门店标价
|
ShopPrice int64 `json:"shopPrice"` // 单位为分 门店标价
|
||||||
SalePrice int64 `json:"salePrice"` // 单位为分 售卖价
|
SalePrice int64 `json:"salePrice"` // 单位为分 售卖价
|
||||||
ActualPayPrice int64 `json:"actualPayPrice"` // 单位为分 顾客实际支付
|
ActualPayPrice int64 `json:"actualPayPrice"` // 单位为分 顾客实际支付
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package jd
|
|||||||
import (
|
import (
|
||||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||||
"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/tasksch"
|
"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"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
@@ -11,41 +12,53 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MaxStockQty = 100000000
|
MaxStockQty = 100000000
|
||||||
|
MaxSkuBatchSize = 50
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type tStoreSkuBindExt struct {
|
||||||
|
model.StoreSkuBind
|
||||||
|
PricePercentage int
|
||||||
|
}
|
||||||
|
|
||||||
// 京东到家,以有库存表示关注(认领)
|
// 京东到家,以有库存表示关注(认领)
|
||||||
func (p *PurchaseHandler) SyncStoreSkus(db *dao.DaoDB, storeIDs []int, skuIDs []int, isForce bool, userName string) (err error) {
|
func (p *PurchaseHandler) SyncStoreSkus(db *dao.DaoDB, storeIDs []int, skuIDs []int, isForce bool, userName string) (err error) {
|
||||||
var storeSkus []*model.StoreSkuBind
|
parallelCount := 1
|
||||||
for _, storeID := range storeIDs {
|
if len(skuIDs) < MaxSkuBatchSize {
|
||||||
|
parallelCount = 10
|
||||||
|
}
|
||||||
|
task := tasksch.RunManagedTask("SyncStoreSkus", false, nil, parallelCount, 1, userName, func(batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||||
|
storeID := batchItemList[0].(int)
|
||||||
sqlParams := []interface{}{
|
sqlParams := []interface{}{
|
||||||
utils.DefaultTimeValue,
|
utils.DefaultTimeValue,
|
||||||
storeID,
|
storeID,
|
||||||
}
|
}
|
||||||
sql := `
|
sql := `
|
||||||
SELECT *
|
SELECT t1.*, t2.price_percentage
|
||||||
FROM store_sku_bind
|
FROM store_sku_bind t1
|
||||||
WHERE (deleted_at = ? OR jd_sync_status <> 0) AND store_id = ?
|
JOIN store_map t2 ON t1.store_id = t2.store_id
|
||||||
`
|
WHERE (t1.deleted_at = ? OR t1.jd_sync_status <> 0) AND t1.store_id = ?
|
||||||
|
`
|
||||||
if skuIDs != nil && len(skuIDs) > 0 {
|
if skuIDs != nil && len(skuIDs) > 0 {
|
||||||
sql += " AND sku_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
|
sql += " AND t1.sku_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
|
||||||
sqlParams = append(sqlParams, skuIDs)
|
sqlParams = append(sqlParams, skuIDs)
|
||||||
}
|
}
|
||||||
globals.SugarLogger.Debug(sql, sqlParams)
|
var storeSkus []*tStoreSkuBindExt
|
||||||
|
// globals.SugarLogger.Debug(sql, sqlParams)
|
||||||
if err = dao.GetRows(db, &storeSkus, sql, sqlParams); err == nil {
|
if err = dao.GetRows(db, &storeSkus, sql, sqlParams); err == nil {
|
||||||
outStationNo := utils.Int2Str(storeID)
|
outStationNo := utils.Int2Str(storeID)
|
||||||
task := tasksch.RunTask("", false, nil, 10, 50, userName, func(batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
task := tasksch.RunTask("", false, nil, 0, MaxSkuBatchSize, userName, func(batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||||
var skuPriceInfoList []*jdapi.SkuPriceInfo
|
var skuPriceInfoList []*jdapi.SkuPriceInfo
|
||||||
var skuVendibilityList []*jdapi.StockVendibility
|
var skuVendibilityList []*jdapi.StockVendibility
|
||||||
var skuStockList []*jdapi.SkuStock
|
var skuStockList []*jdapi.SkuStock
|
||||||
|
|
||||||
for _, v := range batchItemList {
|
for _, v := range batchItemList {
|
||||||
storeSku := v.(*model.StoreSkuBind)
|
storeSku := v.(*tStoreSkuBindExt)
|
||||||
if storeSku.JdSyncStatus&model.SyncFlagChangedMask != 0 {
|
if storeSku.JdSyncStatus&model.SyncFlagChangedMask != 0 {
|
||||||
if storeSku.JdSyncStatus&(model.SyncFlagPriceMask|model.SyncFlagNewMask) != 0 || isForce {
|
if storeSku.JdSyncStatus&(model.SyncFlagPriceMask|model.SyncFlagNewMask) != 0 || isForce {
|
||||||
skuPriceInfoList = append(skuPriceInfoList, &jdapi.SkuPriceInfo{
|
skuPriceInfoList = append(skuPriceInfoList, &jdapi.SkuPriceInfo{
|
||||||
OutSkuId: utils.Int2Str(storeSku.SkuID),
|
OutSkuId: utils.Int2Str(storeSku.SkuID),
|
||||||
Price: storeSku.Price,
|
Price: jxutils.CaculateSkuVendorPrice(storeSku.Price, storeSku.PricePercentage),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if storeSku.JdSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 || isForce {
|
if storeSku.JdSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 || isForce {
|
||||||
@@ -85,16 +98,19 @@ func (p *PurchaseHandler) SyncStoreSkus(db *dao.DaoDB, storeIDs []int, skuIDs []
|
|||||||
}, storeSkus)
|
}, storeSkus)
|
||||||
if _, err = task.GetResult(0); err == nil {
|
if _, err = task.GetResult(0); err == nil {
|
||||||
sql := `
|
sql := `
|
||||||
UPDATE store_sku_bind
|
UPDATE store_sku_bind
|
||||||
SET jd_sync_status = 0
|
SET jd_sync_status = 0
|
||||||
WHERE store_id = ?
|
WHERE (t1.deleted_at = ? OR t1.jd_sync_status <> 0) AND t1.store_id = ?
|
||||||
`
|
`
|
||||||
if skuIDs != nil && len(skuIDs) > 0 {
|
if skuIDs != nil && len(skuIDs) > 0 {
|
||||||
sql += " AND sku_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
|
sql += " AND sku_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
|
||||||
}
|
}
|
||||||
_, err = dao.ExecuteSQL(db, sql, sqlParams)
|
_, err = dao.ExecuteSQL(db, sql, sqlParams)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return nil, err
|
||||||
|
}, storeIDs)
|
||||||
|
|
||||||
|
_, err = task.GetResult(0)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user