|
|
@ -7,6 +7,8 @@ using BBWYB.Server.Model.Db; |
|
|
|
using BBWYB.Server.Model.Db.HY; |
|
|
|
using BBWYB.Server.Model.Dto; |
|
|
|
using FreeSql; |
|
|
|
using MySqlX.XDevAPI; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
using SDKAdapter; |
|
|
|
using SDKAdapter.OperationPlatform.Client; |
|
|
@ -15,6 +17,7 @@ using SDKAdapter.PurchasePlatform.Client; |
|
|
|
using SDKAdapter.PurchasePlatform.Models; |
|
|
|
using System.Data; |
|
|
|
using System.Reflection; |
|
|
|
using System.Text; |
|
|
|
using Yitter.IdGenerator; |
|
|
|
|
|
|
|
namespace BBWYB.Server.Business |
|
|
@ -1440,6 +1443,255 @@ namespace BBWYB.Server.Business |
|
|
|
var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ExportQTSpuAndJDSku.csv"); |
|
|
|
System.IO.File.WriteAllLines(path, result, System.Text.Encoding.UTF8); |
|
|
|
} |
|
|
|
|
|
|
|
public void BelongBarginTeam() |
|
|
|
{ |
|
|
|
var lines = System.IO.File.ReadAllLines("C:\\Users\\pengcong\\Desktop\\供应商.csv", Encoding.UTF8).ToList(); |
|
|
|
lines.RemoveAt(0); |
|
|
|
|
|
|
|
var purchaseRelations = lines.Select(x => |
|
|
|
{ |
|
|
|
var array = x.Split(",", StringSplitOptions.RemoveEmptyEntries); |
|
|
|
var teamId = string.Empty; |
|
|
|
var teamName = string.Empty; |
|
|
|
if (array[3] == "陈默") |
|
|
|
{ |
|
|
|
teamId = "1760971589383360512"; |
|
|
|
teamName = "1组"; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
teamId = "1760971688964526080"; |
|
|
|
teamName = "2组"; |
|
|
|
} |
|
|
|
return new |
|
|
|
{ |
|
|
|
PurchaserName = array[0], |
|
|
|
TeamId = teamId, |
|
|
|
TeamName = teamName |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
var errorPurchaserList = new List<string>(); |
|
|
|
var errorSchemeList = new List<string>(); |
|
|
|
var errorSchemeGroupList = new List<string>(); |
|
|
|
|
|
|
|
var dbPurchaserList = fsql.Select<Purchaser>().ToList(); |
|
|
|
var dbPurchaseGroupList = fsql.Select<PurchaseSchemeGroup>().ToList(); |
|
|
|
var dbSchemeList = fsql.Select<PurchaseScheme>().ToList(); |
|
|
|
var dbSchemeProductList = fsql.Select<PurchaseSchemeProduct>().ToList(); |
|
|
|
|
|
|
|
var updatePurchaserList = new List<Purchaser>(); |
|
|
|
var updateSchemeList = new List<PurchaseScheme>(); |
|
|
|
var updateSchemeGroupList = new List<PurchaseSchemeGroup>(); |
|
|
|
var deletePsgIdList = new List<long>(); |
|
|
|
|
|
|
|
foreach (var purchaseRelation in purchaseRelations) |
|
|
|
{ |
|
|
|
var dbPurchaser = dbPurchaserList.FirstOrDefault(p => p.Name == purchaseRelation.PurchaserName); |
|
|
|
if (dbPurchaser == null) |
|
|
|
{ |
|
|
|
errorPurchaserList.Add($"未从数据表中找到供应商 {purchaseRelation}"); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (dbPurchaser.BelongBargainTeamId != purchaseRelation.TeamId) |
|
|
|
{ |
|
|
|
dbPurchaser.BelongBargainTeamId = purchaseRelation.TeamId; |
|
|
|
dbPurchaser.BelongBargainTeamName = purchaseRelation.TeamName; |
|
|
|
dbPurchaser.BelongType = Enums.PurchaserBelongType.临时; |
|
|
|
updatePurchaserList.Add(dbPurchaser); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var purchaseRelation in purchaseRelations) |
|
|
|
{ |
|
|
|
var dbPurchaser = dbPurchaserList.FirstOrDefault(p => p.Name == purchaseRelation.PurchaserName); |
|
|
|
if (dbPurchaser == null) |
|
|
|
continue; |
|
|
|
|
|
|
|
//查询使用了该采购商的采购方案
|
|
|
|
var usePurchaserSchemeIdList = dbSchemeProductList.Where(psp => psp.PurchaserId == dbPurchaser.Id) |
|
|
|
.Select(psp => psp.SkuPurchaseSchemeId) |
|
|
|
.Distinct() |
|
|
|
.ToList(); |
|
|
|
var usePurchaserSchemeList = dbSchemeList.Where(ps => usePurchaserSchemeIdList.Contains(ps.Id)).ToList(); |
|
|
|
|
|
|
|
foreach (var scheme in usePurchaserSchemeList) |
|
|
|
{ |
|
|
|
var pspList = dbSchemeProductList.Where(psp => psp.SkuPurchaseSchemeId == scheme.Id).ToList(); |
|
|
|
if (pspList.Count() == 0) |
|
|
|
continue; |
|
|
|
var usePurchaserIdList = pspList.Select(psp => psp.PurchaserId).Distinct().ToList(); |
|
|
|
var currentSchemePurchaserList = dbPurchaserList.Where(p => usePurchaserIdList.Contains(p.Id)).ToList(); |
|
|
|
var currentSchemePurchaserBelongGroups = currentSchemePurchaserList.GroupBy(p => p.BelongBargainTeamId); |
|
|
|
if (currentSchemePurchaserBelongGroups.Count() > 1) |
|
|
|
{ |
|
|
|
var sb = new StringBuilder($"采购方案{scheme.Id}使用了{currentSchemePurchaserBelongGroups.Count()}个不同归属的采购商 "); |
|
|
|
foreach (var belongGroup in currentSchemePurchaserBelongGroups) |
|
|
|
{ |
|
|
|
var teamName = belongGroup.FirstOrDefault()?.BelongBargainTeamName; |
|
|
|
sb.Append($"{teamName}:{string.Join(",", belongGroup.Select(x => x.Name))},"); |
|
|
|
} |
|
|
|
|
|
|
|
errorSchemeList.Add(sb.ToString()); |
|
|
|
} |
|
|
|
else if (currentSchemePurchaserBelongGroups.Count() == 1) |
|
|
|
{ |
|
|
|
var firstPurchaser = currentSchemePurchaserBelongGroups.FirstOrDefault()?.FirstOrDefault(); |
|
|
|
if (scheme.BelongBargainTeamId != firstPurchaser.BelongBargainTeamId) |
|
|
|
{ |
|
|
|
scheme.BelongBargainTeamId = firstPurchaser?.BelongBargainTeamId; |
|
|
|
scheme.BelongBargainTeamName = firstPurchaser?.BelongBargainTeamName; |
|
|
|
updateSchemeList.Add(scheme); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var psg in dbPurchaseGroupList) |
|
|
|
{ |
|
|
|
var schemeList = dbSchemeList.Where(ps => ps.SchemeGroupId == psg.Id).ToList(); |
|
|
|
if (schemeList.Count() == 0) |
|
|
|
{ |
|
|
|
deletePsgIdList.Add(psg.Id); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
var currentPsgPurchaserBelongGroups = schemeList.GroupBy(ps => ps.BelongBargainTeamId); |
|
|
|
if (currentPsgPurchaserBelongGroups.Count() > 1) |
|
|
|
{ |
|
|
|
var sb = new StringBuilder($"采购分组{psg.GroupName}使用了{currentPsgPurchaserBelongGroups.Count()}个不同归属的采购方案 "); |
|
|
|
foreach (var belongGroup in currentPsgPurchaserBelongGroups) |
|
|
|
{ |
|
|
|
var teamName = belongGroup.FirstOrDefault()?.BelongBargainTeamName; |
|
|
|
sb.Append($"{teamName}:{string.Join(",", belongGroup.Select(x => x.Id))},"); |
|
|
|
} |
|
|
|
errorSchemeGroupList.Add(sb.ToString()); |
|
|
|
} |
|
|
|
else if (currentPsgPurchaserBelongGroups.Count() == 1) |
|
|
|
{ |
|
|
|
var firstScheme = schemeList[0]; |
|
|
|
if (psg.BelongBargainTeamId != firstScheme.BelongBargainTeamId) |
|
|
|
{ |
|
|
|
psg.BelongBargainTeamId = firstScheme.BelongBargainTeamId; |
|
|
|
updateSchemeGroupList.Add(psg); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (errorPurchaserList.Count() > 0 || |
|
|
|
errorSchemeList.Count() > 0 || |
|
|
|
errorSchemeGroupList.Count() > 0) |
|
|
|
{ |
|
|
|
var msg = JsonConvert.SerializeObject(errorPurchaserList.Union(errorSchemeList).Union(errorSchemeGroupList)); |
|
|
|
throw new BusinessException(msg); |
|
|
|
} |
|
|
|
|
|
|
|
#region 更新采购商
|
|
|
|
{ |
|
|
|
var updateList = new List<IUpdate<Purchaser>>(); |
|
|
|
for (var i = 0; i < updatePurchaserList.Count(); i++) |
|
|
|
{ |
|
|
|
var purchaser = updatePurchaserList[i]; |
|
|
|
var update = fsql.Update<Purchaser>(purchaser.Id) |
|
|
|
.Set(p => p.BelongBargainTeamId, purchaser.BelongBargainTeamId) |
|
|
|
.Set(p => p.BelongBargainTeamName, purchaser.BelongBargainTeamName); |
|
|
|
updateList.Add(update); |
|
|
|
if (updateList.Count() == 10) |
|
|
|
{ |
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
foreach (var _u in updateList) |
|
|
|
_u.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
updateList.Clear(); |
|
|
|
Console.WriteLine($"UpdatePurchaser {i + 1}/{updatePurchaserList.Count()}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (updateList.Count() > 0) |
|
|
|
{ |
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
foreach (var _u in updateList) |
|
|
|
_u.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
updateList.Clear(); |
|
|
|
Console.WriteLine($"LastUpdatePurchaser"); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 更新采购方案
|
|
|
|
{ |
|
|
|
var updateList = new List<IUpdate<PurchaseScheme>>(); |
|
|
|
for (var i = 0; i < updateSchemeList.Count(); i++) |
|
|
|
{ |
|
|
|
var scheme = updateSchemeList[i]; |
|
|
|
var update = fsql.Update<PurchaseScheme>(scheme.Id) |
|
|
|
.Set(ps => ps.BelongBargainTeamId, scheme.BelongBargainTeamId) |
|
|
|
.Set(ps => ps.BelongBargainTeamName, scheme.BelongBargainTeamName); |
|
|
|
updateList.Add(update); |
|
|
|
if (updateList.Count() == 10) |
|
|
|
{ |
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
foreach (var _u in updateList) |
|
|
|
_u.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
updateList.Clear(); |
|
|
|
Console.WriteLine($"UpdateScheme {i + 1}/{updateSchemeList.Count()}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (updateList.Count() > 0) |
|
|
|
{ |
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
foreach (var _u in updateList) |
|
|
|
_u.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
updateList.Clear(); |
|
|
|
Console.WriteLine($"LastUpdateScheme"); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 更新采购分组
|
|
|
|
{ |
|
|
|
var updateList = new List<IUpdate<PurchaseSchemeGroup>>(); |
|
|
|
for (var i = 0; i < updateSchemeGroupList.Count(); i++) |
|
|
|
{ |
|
|
|
var psg = updateSchemeGroupList[i]; |
|
|
|
var update = fsql.Update<PurchaseSchemeGroup>(psg.Id) |
|
|
|
.Set(g => g.BelongBargainTeamId, psg.BelongBargainTeamId); |
|
|
|
updateList.Add(update); |
|
|
|
if (updateList.Count() == 10) |
|
|
|
{ |
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
foreach (var _u in updateList) |
|
|
|
_u.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
updateList.Clear(); |
|
|
|
Console.WriteLine($"UpdateSchemeGroup {i + 1}/{updateSchemeGroupList.Count()}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (updateList.Count() > 0) |
|
|
|
{ |
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
foreach (var _u in updateList) |
|
|
|
_u.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
updateList.Clear(); |
|
|
|
Console.WriteLine($"LastUpdateSchemeGroup"); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|