From 788755c2a366253f2aa71d37d2a96408fc95083c Mon Sep 17 00:00:00 2001 From: "807875765@qq.com" <807875765@qq.com> Date: Tue, 15 Mar 2022 11:47:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=85=A5ants=EF=BC=88=E6=AD=A3?= =?UTF-8?q?=E5=BC=8F=E6=9C=8D=E5=B7=B2go=20get=EF=BC=89=E6=90=BA=E7=A8=8B?= =?UTF-8?q?=E6=B1=A0=20=E5=B7=B2=E6=94=AF=E6=8C=81=E5=A4=9A=E5=BA=97?= =?UTF-8?q?=E9=93=BA=E6=89=B9=E9=87=8F=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 20 +++++++++-------- controllers/cms_sync.go | 37 ++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 4a879c407..34ca09d22 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -2992,7 +2992,7 @@ func GetVendorStoreSkusToStruct(ctx *jxcontext.Context, storeID, vendorID int) ( if len(tmpList) == 0 { //数据库中无匹配项 直接将第三方数据进行导出 goto creatExec } else { //进行比较 - if result := ComPareLocalWithVendors(tmpList, vendorStoreSkus); result != nil { + if result := ComPareLocalWithVendors(tmpList, vendorStoreSkus, vendorID); result != nil { // 将返回的切片进行覆盖 vendorStoreSkus = result goto creatExec @@ -3064,7 +3064,7 @@ func GetLocalStoreSkusByStoreID(storeID int) (tmp []*tGetStoresSkusInfoContainCa } // 比较本地和第三方平台的差异 返回一个Excel 可接收实体 -func ComPareLocalWithVendors(localSku []*tGetStoresSkusInfoContainCategoryName, vendorSkus []*VendorStoreSkus) (result []*VendorStoreSkus) { +func ComPareLocalWithVendors(localSku []*tGetStoresSkusInfoContainCategoryName, vendorSkus []*VendorStoreSkus, vendorID int) (result []*VendorStoreSkus) { // 进行取参比较 var localStoreSkus []*VendorStoreSkus var updateStoreSkus []*VendorStoreSkus @@ -3074,8 +3074,8 @@ func ComPareLocalWithVendors(localSku []*tGetStoresSkusInfoContainCategoryName, SkuID: sku.StoreSkuExt.SkuID, SkuName: sku.SkuName.Name, Status: sku.Status, - CategoryList: jxStatusTransForm(sku.CategoryName), //此处需要使用函数进行转换 进行查询根据类别ID去sku_category查询返回一个子类别放入List中 - Price: vendorPriceTransForm(&sku.StoreSkuExt, 1), //此处需要使用函数转换传入一个VendorID进行比较根据ID的不同返回对应不同的字段 + CategoryList: jxStatusTransForm(sku.CategoryName), //此处需要使用函数进行转换 进行查询根据类别ID去sku_category查询返回一个子类别放入List中 + Price: vendorPriceTransForm(&sku.StoreSkuExt, vendorID), //此处需要使用函数转换传入一个VendorID进行比较根据ID的不同返回对应不同的字段 Reason: defaultReason, } localStoreSkus = append(localStoreSkus, skus) @@ -3108,11 +3108,13 @@ func ComPareLocalWithVendors(localSku []*tGetStoresSkusInfoContainCategoryName, buffer.WriteString("商品上下架状态不一致") count++ } - if value.CategoryList[0] != vendorSku.CategoryList[len(vendorSku.CategoryList)-1] { - buffer.WriteString(strconv.Itoa(count)) - buffer.WriteString(".") - buffer.WriteString("类别不一致:平台类别为" + vendorSku.CategoryList[len(vendorSku.CategoryList)-1]) - count++ + if vendorSku.CategoryList != nil { // Ebai 同步过得商品中的类别中都是nil + if value.CategoryList[0] != vendorSku.CategoryList[len(vendorSku.CategoryList)-1] { + buffer.WriteString(strconv.Itoa(count)) + buffer.WriteString(".") + buffer.WriteString("类别不一致:平台类别为" + vendorSku.CategoryList[len(vendorSku.CategoryList)-1]) + count++ + } } value.Reason = buffer.String() } diff --git a/controllers/cms_sync.go b/controllers/cms_sync.go index 2fe89b0f1..4edcdb18e 100644 --- a/controllers/cms_sync.go +++ b/controllers/cms_sync.go @@ -2,8 +2,11 @@ package controllers import ( "fmt" + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/globals" + "github.com/panjf2000/ants" "io" + "sync" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxstore/cms" @@ -142,11 +145,43 @@ func (c *SyncController) CompareStoreWithOperator() { return retVal, "", err } 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 }) } +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 删除门店平台商品信息(包括分类) // @Description 删除门店平台商品信息(包括分类)(!!!此操作会先清除平台上已有的商品及分类信息),此操作只适用于单门店模式平台 // @Param token header string true "认证token"