|
@ -2,6 +2,7 @@ |
|
|
using BBWYB.Common.Models; |
|
|
using BBWYB.Common.Models; |
|
|
using BBWYB.Server.Model; |
|
|
using BBWYB.Server.Model; |
|
|
using BBWYB.Server.Model.Db; |
|
|
using BBWYB.Server.Model.Db; |
|
|
|
|
|
using BBWYB.Server.Model.Db.BBWY; |
|
|
using BBWYB.Server.Model.Dto; |
|
|
using BBWYB.Server.Model.Dto; |
|
|
using FreeSql; |
|
|
using FreeSql; |
|
|
using Newtonsoft.Json.Linq; |
|
|
using Newtonsoft.Json.Linq; |
|
@ -19,6 +20,7 @@ namespace BBWYB.Server.Business.Sync |
|
|
private TaskSchedulerManager taskSchedulerManager; |
|
|
private TaskSchedulerManager taskSchedulerManager; |
|
|
private List<Enums.TimeLimitTaskType> timeLimitTaskTypes; |
|
|
private List<Enums.TimeLimitTaskType> timeLimitTaskTypes; |
|
|
private TimeLimitRules timeLimitRules; |
|
|
private TimeLimitRules timeLimitRules; |
|
|
|
|
|
private FreeSqlMultiDBManager fsqlManager; |
|
|
|
|
|
|
|
|
public OrderSyncBusiness(IFreeSql fsql, |
|
|
public OrderSyncBusiness(IFreeSql fsql, |
|
|
NLogManager nLogManager, |
|
|
NLogManager nLogManager, |
|
@ -26,7 +28,8 @@ namespace BBWYB.Server.Business.Sync |
|
|
OP_PlatformClientFactory opPlatformClientFactory, |
|
|
OP_PlatformClientFactory opPlatformClientFactory, |
|
|
VenderBusiness venderBusiness, |
|
|
VenderBusiness venderBusiness, |
|
|
TaskSchedulerManager taskSchedulerManager, |
|
|
TaskSchedulerManager taskSchedulerManager, |
|
|
TimeLimitRules timeLimitRules) : base(fsql, nLogManager, idGenerator) |
|
|
TimeLimitRules timeLimitRules, |
|
|
|
|
|
FreeSqlMultiDBManager fsqlManager) : base(fsql, nLogManager, idGenerator) |
|
|
{ |
|
|
{ |
|
|
this.opPlatformClientFactory = opPlatformClientFactory; |
|
|
this.opPlatformClientFactory = opPlatformClientFactory; |
|
|
this.venderBusiness = venderBusiness; |
|
|
this.venderBusiness = venderBusiness; |
|
@ -37,6 +40,7 @@ namespace BBWYB.Server.Business.Sync |
|
|
Enums.TimeLimitTaskType.待议价任务 |
|
|
Enums.TimeLimitTaskType.待议价任务 |
|
|
}; |
|
|
}; |
|
|
this.timeLimitRules = timeLimitRules; |
|
|
this.timeLimitRules = timeLimitRules; |
|
|
|
|
|
this.fsqlManager = fsqlManager; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void AutoOrderSync() |
|
|
public void AutoOrderSync() |
|
@ -145,8 +149,8 @@ namespace BBWYB.Server.Business.Sync |
|
|
|
|
|
|
|
|
List<SpuOptimizationTask> insertSpuOptimizationTaskList = new List<SpuOptimizationTask>(); |
|
|
List<SpuOptimizationTask> insertSpuOptimizationTaskList = new List<SpuOptimizationTask>(); |
|
|
List<SkuOptimizationTask> insertSkuOptimizationTaskList = new List<SkuOptimizationTask>(); |
|
|
List<SkuOptimizationTask> insertSkuOptimizationTaskList = new List<SkuOptimizationTask>(); |
|
|
List<SpuOptimizationBargainTeamTask> insertSkuOptimizationBargainTeamTaskList = new List<SpuOptimizationBargainTeamTask>(); |
|
|
List<SpuOptimizationBargainTeamTask> insertSpuOptimizationBargainTeamTaskList = new List<SpuOptimizationBargainTeamTask>(); |
|
|
List<SpuOptimizationCompetitiveTenderTask> insertSkuOptimizationCompetitiveTenderTaskList = new List<SpuOptimizationCompetitiveTenderTask>(); |
|
|
List<SpuOptimizationCompetitiveTenderTask> insertSpuOptimizationCompetitiveTenderTaskList = new List<SpuOptimizationCompetitiveTenderTask>(); |
|
|
|
|
|
|
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
@ -424,7 +428,7 @@ namespace BBWYB.Server.Business.Sync |
|
|
var includeSpuOrderList = waitToCheckSkuSaleOrderList.Where(o => o.OrderSkuList.Any(osku => osku.ProductId == spuGroup.Key)); |
|
|
var includeSpuOrderList = waitToCheckSkuSaleOrderList.Where(o => o.OrderSkuList.Any(osku => osku.ProductId == spuGroup.Key)); |
|
|
|
|
|
|
|
|
var sourceShopName = string.Empty; |
|
|
var sourceShopName = string.Empty; |
|
|
//京东sku-拳探sku下单关系映射表
|
|
|
//拳探sku-京东sku下单关系映射表
|
|
|
var mappingQT_JDSKUDictionary = new Dictionary<string, string>(); |
|
|
var mappingQT_JDSKUDictionary = new Dictionary<string, string>(); |
|
|
|
|
|
|
|
|
#region 解析来源店铺数据
|
|
|
#region 解析来源店铺数据
|
|
@ -456,72 +460,118 @@ namespace BBWYB.Server.Business.Sync |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
#endregion
|
|
|
#endregion
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (var waitCheckOrder in waitToCheckSkuSaleOrderList) |
|
|
#region 读取JDSKU预估金额
|
|
|
{ |
|
|
var jdskus = mappingQT_JDSKUDictionary.Values.ToList(); |
|
|
|
|
|
var jdskuRecentCostList = fsqlManager.BBWYCfsql.Select<SkuRecentCost>(jdskus).ToList(); |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
foreach (var waitCheckOrderSku in waitCheckOrder.OrderSkuList) |
|
|
#region 处理SKU分组
|
|
|
{ |
|
|
var skuGroups = spuGroup.GroupBy(osku => osku.SkuId).ToList(); |
|
|
if (noFisrstPurchasedSpuList.Contains(waitCheckOrderSku.ProductId) && |
|
|
var skuIdList = skuGroups.Select(g => g.Key).ToList(); |
|
|
!dbSpuOptimizationTaskList.Any(t => t.ProductId == waitCheckOrderSku.ProductId) && |
|
|
#endregion
|
|
|
!insertSpuOptimizationTaskList.Any(t => t.SkuId == waitCheckOrderSku.SkuId)) |
|
|
|
|
|
|
|
|
#region 创建SPU优化任务
|
|
|
|
|
|
var spuOptimizationTask = new SpuOptimizationTask() |
|
|
|
|
|
{ |
|
|
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
|
|
BelongShopName = sourceShopName, |
|
|
|
|
|
CompletionTime = null, |
|
|
|
|
|
CreateTime = DateTime.Now, |
|
|
|
|
|
IsOptimizationCompleted = false, |
|
|
|
|
|
LastOptimizationTime = null, |
|
|
|
|
|
ProductId = spuGroup.Key, |
|
|
|
|
|
ShopId = shopId, |
|
|
|
|
|
ProductTitle = spuGroup.FirstOrDefault()?.ProductTitle, |
|
|
|
|
|
TriggerOptimizationReason = Enums.TriggerOptimizationReason.首次采购, |
|
|
|
|
|
PreSkuCount = skuGroups.Count(), |
|
|
|
|
|
PreItemCount = 0, |
|
|
|
|
|
PrePurchaseAmount = 0M |
|
|
|
|
|
}; |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 创建SKU优化任务
|
|
|
|
|
|
foreach (var skuGroup in skuGroups) |
|
|
{ |
|
|
{ |
|
|
#region 创建待优化任务
|
|
|
mappingQT_JDSKUDictionary.TryGetValue(skuGroup.Key, out string jdSkuId); |
|
|
|
|
|
var preItemCount = skuGroup.Sum(osku => osku.Quantity); |
|
|
|
|
|
var prePurchaseAmount = 0M; |
|
|
|
|
|
if (!string.IsNullOrEmpty(jdSkuId)) |
|
|
|
|
|
{ |
|
|
|
|
|
var jdSkuRecentCost = jdskuRecentCostList.FirstOrDefault(x => x.SkuId == jdSkuId); |
|
|
|
|
|
if (jdSkuRecentCost != null) |
|
|
|
|
|
{ |
|
|
|
|
|
prePurchaseAmount = (jdSkuRecentCost.SingleSkuAmount ?? 0M + |
|
|
|
|
|
jdSkuRecentCost.SingleFirstFreight ?? 0M + |
|
|
|
|
|
jdSkuRecentCost.SingleFreight ?? 0M + |
|
|
|
|
|
jdSkuRecentCost.SingleDeliveryFreight ?? 0M + |
|
|
|
|
|
jdSkuRecentCost.SingleConsumableAmount ?? 0M + |
|
|
|
|
|
jdSkuRecentCost.SingleInStorageAmount ?? 0M + |
|
|
|
|
|
jdSkuRecentCost.SingleOutStorageAmount ?? 0M + |
|
|
|
|
|
jdSkuRecentCost.SinglePackagingLaborAmount ?? 0M + |
|
|
|
|
|
jdSkuRecentCost.SingleOperationAmount ?? 0M) * preItemCount; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
var skuOptimizationTask = new SkuOptimizationTask() |
|
|
var skuOptimizationTask = new SkuOptimizationTask() |
|
|
{ |
|
|
{ |
|
|
Id = idGenerator.NewLong(), |
|
|
Id = idGenerator.NewLong(), |
|
|
PreItemCount = 0, |
|
|
|
|
|
PrePurchasedAmount = 0, |
|
|
|
|
|
IsOptimizationCompleted = false, |
|
|
|
|
|
IsPurchasementCompleted = false, |
|
|
|
|
|
CreateTime = DateTime.Now, |
|
|
CreateTime = DateTime.Now, |
|
|
SafeWarningRemainingDay = 0, |
|
|
JDSkuId = jdSkuId, |
|
|
TriggerOptimizationReason = Enums.TriggerOptimizationReason.首次采购, |
|
|
PreItemCount = preItemCount, |
|
|
SkuId = waitCheckOrderSku.SkuId, |
|
|
SkuId = skuGroup.Key, |
|
|
ShopId = shopId, |
|
|
SpuOptimizationTaskId = spuOptimizationTask.Id, |
|
|
ProductId = waitCheckOrderSku.ProductId, |
|
|
PrePurchaseAmount = prePurchaseAmount |
|
|
BelongShopName = sourceShopName, |
|
|
|
|
|
CompletionTime = null, |
|
|
|
|
|
JDSkuId = belongSkus?.FirstOrDefault(j => j.Value<string>("SkuId") == waitCheckOrderSku.SkuId)?.Value<string>("BelongSkuId") ?? string.Empty, |
|
|
|
|
|
LastOptimizationRatio = 0, |
|
|
|
|
|
LastPurchasePrice = 0, |
|
|
|
|
|
LastOptimizationTime = null |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
insertSkuOptimizationTaskList.Add(skuOptimizationTask); |
|
|
insertSkuOptimizationTaskList.Add(skuOptimizationTask); |
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 创建待优化子任务
|
|
|
//累计spu优化任务信息
|
|
|
|
|
|
spuOptimizationTask.PreItemCount += preItemCount; |
|
|
|
|
|
spuOptimizationTask.PrePurchaseAmount += prePurchaseAmount; |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 创建SPU优化议价组任务
|
|
|
|
|
|
foreach (var department in bargainTeamList) |
|
|
|
|
|
{ |
|
|
|
|
|
var spuOptimizationBargainTeamTask = new SpuOptimizationBargainTeamTask() |
|
|
{ |
|
|
{ |
|
|
foreach (var department in bargainTeamList) |
|
|
Id = idGenerator.NewLong(), |
|
|
{ |
|
|
BelongTeamId = department.Id, |
|
|
var skuOptimizationChildTask = new SkuOptimizationChildTask() |
|
|
BelongTeamName = department.DepartmentName, |
|
|
{ |
|
|
CompletionTime = null, |
|
|
Id = idGenerator.NewLong(), |
|
|
IsOptimizationCompleted = false, |
|
|
BelongTeamId = department.Id, |
|
|
SpuOptimizationTaskId = spuOptimizationTask.Id |
|
|
BelongTeamName = department.DepartmentName, |
|
|
}; |
|
|
CompletionTime = null, |
|
|
insertSpuOptimizationBargainTeamTaskList.Add(spuOptimizationBargainTeamTask); |
|
|
IsOptimizationCompleted = false, |
|
|
|
|
|
OptimizationTaskId = skuOptimizationTask.Id |
|
|
|
|
|
}; |
|
|
|
|
|
insertSkuOptimizationChildTaskList.Add(skuOptimizationChildTask); |
|
|
|
|
|
|
|
|
|
|
|
#region 创建竞标任务
|
|
|
|
|
|
var schemeList = waitToCompetitiveTenderSchemeList.Where(ps => ps.SkuId == waitCheckOrderSku.SkuId && |
|
|
|
|
|
ps.BelongBargainTeamId == department.Id) |
|
|
|
|
|
.ToList(); |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
#region 创建采购方案竞标任务
|
|
|
} |
|
|
var waitJoinSchemeList = waitToCompetitiveTenderSchemeList.Where(ps => ps.BelongBargainTeamId == department.Id && |
|
|
|
|
|
skuIdList.Contains(ps.SkuId)) |
|
|
|
|
|
.ToList(); |
|
|
|
|
|
if (waitJoinSchemeList.Count() > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
insertSpuOptimizationCompetitiveTenderTaskList.AddRange(waitJoinSchemeList.Select(ps => new SpuOptimizationCompetitiveTenderTask() |
|
|
|
|
|
{ |
|
|
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
|
|
BargainTeamId = ps.BelongBargainTeamId, |
|
|
|
|
|
CreateTime = DateTime.Now, |
|
|
|
|
|
IsUpdateQuotedPrice = false, |
|
|
|
|
|
SchemeGroupId = ps.SchemeGroupId, |
|
|
|
|
|
SchemeId = ps.Id, |
|
|
|
|
|
SkuId = ps.SkuId, |
|
|
|
|
|
SpuOptimizationBargainTeamTaskId = spuOptimizationBargainTeamTask.Id, |
|
|
|
|
|
SpuOptimizationTaskId = spuOptimizationTask.Id |
|
|
|
|
|
})); |
|
|
} |
|
|
} |
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
#region 创建待优化限时任务
|
|
|
#region 创建优化限时任务
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
//判断sku是否首次采购
|
|
|
//判断sku是否首次采购
|
|
|
var isFirst = !dbSkuTotalSaleInfoList.Any(s => s.SkuId == waitCheckOrderSku.SkuId); |
|
|
var isFirst = !dbSpuTotalSaleInfoList.Any(s => s.ProductId == spuGroup.Key); |
|
|
|
|
|
|
|
|
insertTimeLimitTaskList.Add(new TimeLimitTask() |
|
|
insertTimeLimitTaskList.Add(new TimeLimitTask() |
|
|
{ |
|
|
{ |
|
@ -532,13 +582,13 @@ namespace BBWYB.Server.Business.Sync |
|
|
//OrderId = o.OrderId,
|
|
|
//OrderId = o.OrderId,
|
|
|
//OrderSn = o.OrderSn,
|
|
|
//OrderSn = o.OrderSn,
|
|
|
ShopId = shopId, |
|
|
ShopId = shopId, |
|
|
SkuId = waitCheckOrderSku.SkuId, |
|
|
//SkuId = waitCheckOrderSku.SkuId,
|
|
|
TaskType = Enums.TimeLimitTaskType.待议价任务, |
|
|
TaskType = Enums.TimeLimitTaskType.待议价任务, |
|
|
TaskId = skuOptimizationTask.Id, |
|
|
TaskId = spuOptimizationTask.Id, |
|
|
Remark = "首次采购限时任务" |
|
|
Remark = "首次采购限时任务" |
|
|
}); |
|
|
}); |
|
|
#endregion
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
#endregion
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -564,14 +614,14 @@ namespace BBWYB.Server.Business.Sync |
|
|
if (insertTimeLimitTaskList.Count() > 0) |
|
|
if (insertTimeLimitTaskList.Count() > 0) |
|
|
fsql.Insert(insertTimeLimitTaskList).ExecuteAffrows(); |
|
|
fsql.Insert(insertTimeLimitTaskList).ExecuteAffrows(); |
|
|
|
|
|
|
|
|
//if (insertSkuOptimizationTaskList.Count() > 0)
|
|
|
if (insertSpuOptimizationTaskList.Count() > 0) |
|
|
// fsql.Insert(insertSkuOptimizationTaskList).ExecuteAffrows();
|
|
|
fsql.Insert(insertSpuOptimizationTaskList).ExecuteAffrows(); |
|
|
|
|
|
if (insertSkuOptimizationTaskList.Count() > 0) |
|
|
//if (insertSkuOptimizationChildTaskList.Count() > 0)
|
|
|
fsql.Insert(insertSkuOptimizationTaskList).ExecuteAffrows(); |
|
|
// fsql.Insert(insertSkuOptimizationChildTaskList).ExecuteAffrows();
|
|
|
if (insertSpuOptimizationBargainTeamTaskList.Count() > 0) |
|
|
|
|
|
fsql.Insert(insertSpuOptimizationBargainTeamTaskList).ExecuteAffrows(); |
|
|
//if (insertCompetitiveTenderList.Count() > 0)
|
|
|
if (insertSpuOptimizationCompetitiveTenderTaskList.Count() > 0) |
|
|
// fsql.Insert(insertCompetitiveTenderList).ExecuteAffrows();
|
|
|
fsql.Insert(insertSpuOptimizationCompetitiveTenderTaskList).ExecuteAffrows(); |
|
|
|
|
|
|
|
|
if (updateOrderList.Count() > 0) |
|
|
if (updateOrderList.Count() > 0) |
|
|
foreach (var update in updateOrderList) |
|
|
foreach (var update in updateOrderList) |
|
|