- 调用updateActPrice4StoreSkuName时,根据结果集限制storeID与skuIDs

This commit is contained in:
gazebo
2019-06-29 20:00:12 +08:00
parent 30afe2830d
commit a8537203c6
2 changed files with 34 additions and 17 deletions

View File

@@ -316,6 +316,9 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
return nil, err
}
pageSize = jxutils.FormalizePageSize(pageSize)
if offset < 0 {
offset = 0
}
sqlOffset := offset
sqlPageSize := pageSize
isSaleInfo := params["stFromTime"] != nil
@@ -351,7 +354,7 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
dao.Rollback(db)
return nil, err
}
globals.SugarLogger.Debug(time.Now().Sub(beginTime))
globals.SugarLogger.Debugf("GetStoresSkusNew get result1:%v", time.Now().Sub(beginTime))
skuNamesInfo.TotalCount = dao.GetLastTotalRowCount(db)
sql += " AND (1 = 0"
for _, v := range storeNameList {
@@ -394,7 +397,7 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
skuNamesInfo.TotalCount = dao.GetLastTotalRowCount(db)
}
dao.Commit(db)
globals.SugarLogger.Debug(time.Now().Sub(beginTime))
globals.SugarLogger.Debugf("GetStoresSkusNew get result2:%v", time.Now().Sub(beginTime))
storeNameMap := make(map[int64]*StoreSkuNameExt)
for _, v := range tmpList {
var storeName *StoreSkuNameExt
@@ -415,14 +418,37 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
}
storeName.Skus2 = append(storeName.Skus2, &v.StoreSkuExt)
}
err = updateActPrice4StoreSkuName(db, storeIDs, skuIDs, skuNamesInfo)
if err == nil && isSaleInfo {
err = updateSaleInfo4StoreSkuName(ctx, db, offset, pageSize, params, skuNamesInfo)
if err == nil {
if isSaleInfo {
beginTime := time.Now()
err = updateSaleInfo4StoreSkuName(ctx, db, storeIDs, skuIDs, params, skuNamesInfo, offset, pageSize)
globals.SugarLogger.Debugf("GetStoresSkusNew updateSaleInfo4StoreSkuName:%v", time.Now().Sub(beginTime))
}
if err == nil {
if !(offset == 0 && pageSize == model.UnlimitedPageSize) {
storeIDs, skuIDs = GetStoreAndSkuIDsFromInfo(skuNamesInfo)
}
beginTime := time.Now()
err = updateActPrice4StoreSkuName(db, storeIDs, skuIDs, skuNamesInfo)
globals.SugarLogger.Debugf("GetStoresSkusNew updateActPrice4StoreSkuName:%v", time.Now().Sub(beginTime))
}
}
// globals.SugarLogger.Debug(utils.Format4Output(skuNamesInfo, false))
return skuNamesInfo, err
}
func GetStoreAndSkuIDsFromInfo(skuNamesInfo *StoreSkuNamesInfo) (storeIDs, skuIDs []int) {
storeIDMap := make(map[int]int)
skuIDMap := make(map[int]int)
for _, skuName := range skuNamesInfo.SkuNames {
storeIDMap[skuName.StoreID] = 1
for _, sku := range skuName.Skus2 {
skuIDMap[sku.SkuID] = 1
}
}
return jxutils.IntMap2List(storeIDMap), jxutils.IntMap2List(skuIDMap)
}
func updateActPrice4StoreSkuName(db *dao.DaoDB, storeIDs, skuIDs []int, skuNamesInfo *StoreSkuNamesInfo) (err error) {
// 活动商品信息
jxSkuPriceMap, err := dao.GetPromotionSkuPriceMap(db, model.VendorIDJX, storeIDs, skuIDs, time.Now(), time.Now())
@@ -458,23 +484,14 @@ func updateActPrice4StoreSkuName(db *dao.DaoDB, storeIDs, skuIDs []int, skuNames
return err
}
func updateSaleInfo4StoreSkuName(ctx *jxcontext.Context, db *dao.DaoDB, offset, pageSize int, params map[string]interface{}, skuNamesInfo *StoreSkuNamesInfo) (err error) {
func updateSaleInfo4StoreSkuName(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs, skuIDs []int, params map[string]interface{}, skuNamesInfo *StoreSkuNamesInfo, offset, pageSize int) (err error) {
var (
saleInfoList []*SkuSaleInfo
timeList []time.Time
fromCount, toCount int
)
storeIDMap := make(map[int]int)
skuIDMap := make(map[int]int)
saleInfoMap := make(map[int64]*SkuSaleInfo)
for _, skuName := range skuNamesInfo.SkuNames {
storeIDMap[skuName.StoreID] = 1
for _, sku := range skuName.Skus2 {
skuIDMap[sku.SkuID] = 1
}
}
storeIDs := jxutils.IntMap2List(storeIDMap)
skuIDs := jxutils.IntMap2List(skuIDMap)
toTimeStr := ""
if params["stToTime"] != nil {
toTimeStr = params["stToTime"].(string)

View File

@@ -43,7 +43,7 @@ func GetPromotionSkuPriceMap(db *DaoDB, vendorID int, storeIDs, skuIDs []int, fr
sql += " AND t3.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
sqlParams = append(sqlParams, skuIDs)
}
sql += "ORDER BY t2.store_id, t3.sku_id, t3.price"
sql += " ORDER BY t2.store_id, t3.sku_id, t3.price"
var skuPriceList []*PromotionStoreSku
if err = GetRows(db, &skuPriceList, sql, sqlParams...); err != nil {
return nil, err