引入ants(正式服已go get)携程池 已支持多店铺批量操作
This commit is contained in:
@@ -2992,7 +2992,7 @@ func GetVendorStoreSkusToStruct(ctx *jxcontext.Context, storeID, vendorID int) (
|
|||||||
if len(tmpList) == 0 { //数据库中无匹配项 直接将第三方数据进行导出
|
if len(tmpList) == 0 { //数据库中无匹配项 直接将第三方数据进行导出
|
||||||
goto creatExec
|
goto creatExec
|
||||||
} else { //进行比较
|
} else { //进行比较
|
||||||
if result := ComPareLocalWithVendors(tmpList, vendorStoreSkus); result != nil {
|
if result := ComPareLocalWithVendors(tmpList, vendorStoreSkus, vendorID); result != nil {
|
||||||
// 将返回的切片进行覆盖
|
// 将返回的切片进行覆盖
|
||||||
vendorStoreSkus = result
|
vendorStoreSkus = result
|
||||||
goto creatExec
|
goto creatExec
|
||||||
@@ -3064,7 +3064,7 @@ func GetLocalStoreSkusByStoreID(storeID int) (tmp []*tGetStoresSkusInfoContainCa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 比较本地和第三方平台的差异 返回一个Excel 可接收实体
|
// 比较本地和第三方平台的差异 返回一个Excel 可接收实体
|
||||||
func ComPareLocalWithVendors(localSku []*tGetStoresSkusInfoContainCategoryName, vendorSkus []*VendorStoreSkus) (result []*VendorStoreSkus) {
|
func ComPareLocalWithVendors(localSku []*tGetStoresSkusInfoContainCategoryName, vendorSkus []*VendorStoreSkus, vendorID int) (result []*VendorStoreSkus) {
|
||||||
// 进行取参比较
|
// 进行取参比较
|
||||||
var localStoreSkus []*VendorStoreSkus
|
var localStoreSkus []*VendorStoreSkus
|
||||||
var updateStoreSkus []*VendorStoreSkus
|
var updateStoreSkus []*VendorStoreSkus
|
||||||
@@ -3074,8 +3074,8 @@ func ComPareLocalWithVendors(localSku []*tGetStoresSkusInfoContainCategoryName,
|
|||||||
SkuID: sku.StoreSkuExt.SkuID,
|
SkuID: sku.StoreSkuExt.SkuID,
|
||||||
SkuName: sku.SkuName.Name,
|
SkuName: sku.SkuName.Name,
|
||||||
Status: sku.Status,
|
Status: sku.Status,
|
||||||
CategoryList: jxStatusTransForm(sku.CategoryName), //此处需要使用函数进行转换 进行查询根据类别ID去sku_category查询返回一个子类别放入List中
|
CategoryList: jxStatusTransForm(sku.CategoryName), //此处需要使用函数进行转换 进行查询根据类别ID去sku_category查询返回一个子类别放入List中
|
||||||
Price: vendorPriceTransForm(&sku.StoreSkuExt, 1), //此处需要使用函数转换传入一个VendorID进行比较根据ID的不同返回对应不同的字段
|
Price: vendorPriceTransForm(&sku.StoreSkuExt, vendorID), //此处需要使用函数转换传入一个VendorID进行比较根据ID的不同返回对应不同的字段
|
||||||
Reason: defaultReason,
|
Reason: defaultReason,
|
||||||
}
|
}
|
||||||
localStoreSkus = append(localStoreSkus, skus)
|
localStoreSkus = append(localStoreSkus, skus)
|
||||||
@@ -3108,11 +3108,13 @@ func ComPareLocalWithVendors(localSku []*tGetStoresSkusInfoContainCategoryName,
|
|||||||
buffer.WriteString("商品上下架状态不一致")
|
buffer.WriteString("商品上下架状态不一致")
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
if value.CategoryList[0] != vendorSku.CategoryList[len(vendorSku.CategoryList)-1] {
|
if vendorSku.CategoryList != nil { // Ebai 同步过得商品中的类别中都是nil
|
||||||
buffer.WriteString(strconv.Itoa(count))
|
if value.CategoryList[0] != vendorSku.CategoryList[len(vendorSku.CategoryList)-1] {
|
||||||
buffer.WriteString(".")
|
buffer.WriteString(strconv.Itoa(count))
|
||||||
buffer.WriteString("类别不一致:平台类别为" + vendorSku.CategoryList[len(vendorSku.CategoryList)-1])
|
buffer.WriteString(".")
|
||||||
count++
|
buffer.WriteString("类别不一致:平台类别为" + vendorSku.CategoryList[len(vendorSku.CategoryList)-1])
|
||||||
|
count++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
value.Reason = buffer.String()
|
value.Reason = buffer.String()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
"github.com/panjf2000/ants"
|
||||||
"io"
|
"io"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||||
@@ -142,11 +145,43 @@ func (c *SyncController) CompareStoreWithOperator() {
|
|||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
}
|
}
|
||||||
globals.SugarLogger.Debug(params.StoreIDs, params.VendorIDs)
|
globals.SugarLogger.Debug(params.StoreIDs, params.VendorIDs)
|
||||||
err = cms.GetVendorStoreSkusToStruct(params.Ctx, storeIDs[0], vendorIDs[0])
|
p, _ := ants.NewPoolWithFunc(10, func(data interface{}) {
|
||||||
|
task := data.(*CompareTask)
|
||||||
|
task.Do()
|
||||||
|
})
|
||||||
|
defer p.Release()
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(len(storeIDs))
|
||||||
|
tasks := make([]*CompareTask, 0, len(storeIDs))
|
||||||
|
for i := 0; i < len(storeIDs); i++ {
|
||||||
|
task := &CompareTask{
|
||||||
|
StoreId: storeIDs[i],
|
||||||
|
VendorId: vendorIDs[0],
|
||||||
|
Ctx: params.Ctx,
|
||||||
|
Wg: &wg,
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks = append(tasks, task)
|
||||||
|
p.Invoke(task)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
// err = cms.GetVendorStoreSkusToStruct(params.Ctx, storeIDs[0], vendorIDs[0])
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CompareTask struct {
|
||||||
|
StoreId int
|
||||||
|
VendorId int
|
||||||
|
Ctx *jxcontext.Context
|
||||||
|
Wg *sync.WaitGroup
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *CompareTask) Do() {
|
||||||
|
cms.GetVendorStoreSkusToStruct(t.Ctx, t.StoreId, t.VendorId)
|
||||||
|
t.Wg.Done()
|
||||||
|
}
|
||||||
|
|
||||||
// @Title 删除门店平台商品信息(包括分类)
|
// @Title 删除门店平台商品信息(包括分类)
|
||||||
// @Description 删除门店平台商品信息(包括分类)(!!!此操作会先清除平台上已有的商品及分类信息),此操作只适用于单门店模式平台
|
// @Description 删除门店平台商品信息(包括分类)(!!!此操作会先清除平台上已有的商品及分类信息),此操作只适用于单门店模式平台
|
||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
|
|||||||
Reference in New Issue
Block a user