|
|
@ -9,6 +9,8 @@ using FreeSql; |
|
|
|
using SDKAdapter; |
|
|
|
using SDKAdapter.OperationPlatform.Client; |
|
|
|
using SDKAdapter.OperationPlatform.Models; |
|
|
|
using SDKAdapter.PurchasePlatform.Client; |
|
|
|
using SDKAdapter.PurchasePlatform.Models; |
|
|
|
using System.Data; |
|
|
|
using System.Net.Http.Headers; |
|
|
|
using Yitter.IdGenerator; |
|
|
@ -23,8 +25,9 @@ namespace BBWYB.Server.Business |
|
|
|
private FreeSqlMultiDBManager freeSqlMultiDBManager; |
|
|
|
private VenderBusiness venderBusiness; |
|
|
|
private OP_PlatformClientFactory opPlatformClientFactory; |
|
|
|
private PP_PlatformClientFactory pp_PlatformClientFactory; |
|
|
|
private RestApiService restApiService; |
|
|
|
public DataRepairBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator, KuaiDi100Manager kuaiDi100Manager, PurchaseSchemeBusiness purchaseSchemeBusiness, PurchaseOrderBusiness purchaseOrderBusiness, FreeSqlMultiDBManager freeSqlMultiDBManager, VenderBusiness venderBusiness, OP_PlatformClientFactory opPlatformClientFactory, RestApiService restApiService) : base(fsql, nLogManager, idGenerator) |
|
|
|
public DataRepairBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator, KuaiDi100Manager kuaiDi100Manager, PurchaseSchemeBusiness purchaseSchemeBusiness, PurchaseOrderBusiness purchaseOrderBusiness, FreeSqlMultiDBManager freeSqlMultiDBManager, VenderBusiness venderBusiness, OP_PlatformClientFactory opPlatformClientFactory, PP_PlatformClientFactory pp_PlatformClientFactory, RestApiService restApiService) : base(fsql, nLogManager, idGenerator) |
|
|
|
{ |
|
|
|
this.kuaiDi100Manager = kuaiDi100Manager; |
|
|
|
this.purchaseSchemeBusiness = purchaseSchemeBusiness; |
|
|
@ -32,6 +35,7 @@ namespace BBWYB.Server.Business |
|
|
|
this.freeSqlMultiDBManager = freeSqlMultiDBManager; |
|
|
|
this.venderBusiness = venderBusiness; |
|
|
|
this.opPlatformClientFactory = opPlatformClientFactory; |
|
|
|
this.pp_PlatformClientFactory = pp_PlatformClientFactory; |
|
|
|
this.restApiService = restApiService; |
|
|
|
} |
|
|
|
|
|
|
@ -653,6 +657,10 @@ namespace BBWYB.Server.Business |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 采购配件最近采购价
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 采购商累计信息
|
|
|
@ -773,5 +781,85 @@ namespace BBWYB.Server.Business |
|
|
|
fsql.Insert(insertSkuHistoryPurchaserRelationList).ExecuteAffrows(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public void RepairPurchaseSkuLastPurchasePriceCost() |
|
|
|
{ |
|
|
|
//IDictionary<string, IUpdate<PurchaseSchemeProductSku>> updatePssDictionary = new Dictionary<string, IUpdate<PurchaseSchemeProductSku>>();
|
|
|
|
List<string> updatePssKeyList = new List<string>(); |
|
|
|
|
|
|
|
var oriList = fsql.Select<OrderPurchaseRelationInfo, PurchaseScheme, PurchaseSchemeProduct, Purchaser>() |
|
|
|
.InnerJoin((ori, ps, psp, pr) => ori.SchemeId == ps.Id) |
|
|
|
.InnerJoin((ori, ps, psp, pr) => ps.Id == psp.SkuPurchaseSchemeId) |
|
|
|
.InnerJoin((ori, ps, psp, pr) => pr.Id == psp.PurchaserId) |
|
|
|
.Where((ori, ps, psp, pr) => pr.Platform == Enums.Platform.阿里巴巴 && fsql.Select<PurchaseSchemeProductSku>().Where(pss => pss.PurchaseSkuId == ori.PurchaseSkuId && pss.LastPurchasePriceCost == null).Any()) |
|
|
|
.OrderByDescending((ori, ps, psp, pr) => ori.CreateTime) |
|
|
|
.ToList((ori, ps, psp, pr) => new |
|
|
|
{ |
|
|
|
ori.OrderId, |
|
|
|
ori.PurchaseOrderId, |
|
|
|
ori.PurchaseSkuId, |
|
|
|
ori.SchemeId, |
|
|
|
ps.ShopId |
|
|
|
}); |
|
|
|
|
|
|
|
var a = oriList.Any(x => x.SchemeId == 459761181151301); |
|
|
|
|
|
|
|
var purchaseAccountList = freeSqlMultiDBManager.MDSfsql.Select<Model.Db.MDS.Purchaseaccount, Model.Db.Mds.Shops>() |
|
|
|
.InnerJoin((pa, s) => pa.ShopId == s.Id) |
|
|
|
.Where((pa, s) => s.PlatformId == 10 && pa.PurchasePlatformId == "2") |
|
|
|
.ToList((pa, s) => new |
|
|
|
{ |
|
|
|
s.ShopId, |
|
|
|
pa.AppKey, |
|
|
|
pa.AppSecret, |
|
|
|
pa.AppToken |
|
|
|
}); |
|
|
|
|
|
|
|
var client = pp_PlatformClientFactory.GetClient(AdapterEnums.PlatformType.阿里巴巴); |
|
|
|
|
|
|
|
var puchaseOrderGroups = oriList.GroupBy(ori => ori.PurchaseOrderId); |
|
|
|
var poIndex = 0; |
|
|
|
foreach (var poGroup in puchaseOrderGroups) |
|
|
|
{ |
|
|
|
var poId = poGroup.Key; |
|
|
|
poIndex++; |
|
|
|
Console.WriteLine($"查询采购单 {poId}, {poIndex}/{puchaseOrderGroups.Count()}"); |
|
|
|
try |
|
|
|
{ |
|
|
|
var shopId = poGroup.FirstOrDefault().ShopId.ToString(); |
|
|
|
var purchaseAccount = purchaseAccountList.FirstOrDefault(s => s.ShopId == shopId); |
|
|
|
Thread.Sleep(1500); |
|
|
|
var purchaseOrderSimpleInfo = client.QueryOrderDetail(new PP_QueryOrderDetailRequest() |
|
|
|
{ |
|
|
|
AppKey = purchaseAccount.AppKey, |
|
|
|
AppSecret = purchaseAccount.AppSecret, |
|
|
|
AppToken = purchaseAccount.AppToken, |
|
|
|
OrderId = poId |
|
|
|
}); |
|
|
|
|
|
|
|
foreach (var ori in poGroup) |
|
|
|
{ |
|
|
|
var key = $"{ori.PurchaseSkuId}_{ori.SchemeId}"; |
|
|
|
if (updatePssKeyList.Contains(key)) |
|
|
|
continue; |
|
|
|
|
|
|
|
var purchaseSku = purchaseOrderSimpleInfo.ItemList.FirstOrDefault(x => x.SkuId == ori.PurchaseSkuId); |
|
|
|
if (purchaseSku != null) |
|
|
|
{ |
|
|
|
Console.WriteLine($"更新 {key}"); |
|
|
|
var update = fsql.Update<PurchaseSchemeProductSku>().Set(pss => pss.LastPurchasePriceCost, purchaseSku.Price) |
|
|
|
.Where(pss => pss.PurchaseSkuId == ori.PurchaseSkuId && pss.SkuPurchaseSchemeId == ori.SchemeId); |
|
|
|
update.ExecuteAffrows(); |
|
|
|
updatePssKeyList.Add(key); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
Console.WriteLine($"{poId},{ex.Message}"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|