diff --git a/admin.net.pro/Admin.NET/Vistar.Application/Service/StockInquiry/StockInquiryService.cs b/admin.net.pro/Admin.NET/Vistar.Application/Service/StockInquiry/StockInquiryService.cs
index 7b04dca..dcdce98 100644
--- a/admin.net.pro/Admin.NET/Vistar.Application/Service/StockInquiry/StockInquiryService.cs
+++ b/admin.net.pro/Admin.NET/Vistar.Application/Service/StockInquiry/StockInquiryService.cs
@@ -96,7 +96,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
if (apiOutput.Code == "S")
{
- var data = await _obj137Rep.AsQueryable().Where(x => x._System_objNBS == materialCode && x.deleted == false).OrderByDescending(x => x.idRecord).FirstAsync();
+ var data = await _obj137Rep.AsQueryable().Where(x => x._System_objNBS == materialCode && x.deleted == false && x.SWPDMConfigurationName == "默认").OrderByDescending(x => x.idRecord).FirstAsync();
if (data != null)
{
apiOutput.DateUpdated = DateTime.Now;
@@ -139,7 +139,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
///
///
[ApiDescriptionSettings(Name = "GetBomProductInventory", Description = "产品管理库-Bom库存查询", Order = 1000), HttpGet]
- [DisplayName("产品管理库-库存查询")]
+ [DisplayName("产品管理库-Bom库存查询")]
[AllowAnonymous]
public async Task> GetBomProductInventory(string materialCode)
{
@@ -149,7 +149,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
var Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName);
var materialData = await db.CopyNew().Queryable()
- .Where(x => x._System_objNBS == materialCode && x.deleted == false)
+ .Where(x => x._System_objNBS == materialCode && x.deleted == false && x.SWPDMConfigurationName == "默认")
.OrderByDescending(x => x.idRecord)
.FirstAsync();
@@ -163,7 +163,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
var UpdateableList = new List();
var UpdateableOutput = new List();
- int batchSize = 20; // 每批的大小
+ int batchSize = 50; // 每批的大小
int totalCount = bomList.ToList().Count;
for (int i = 0; i < totalCount; i += batchSize)
@@ -256,6 +256,8 @@ public class StockInquiryService : IDynamicApiController, ITransient
// 合并当前批次的结果
UpdateableOutput.AddRange(bomStockInquiryOutput);
+ // 如果需要暂停或者处理频率,可以在此处插入适当的延迟。
+ await Task.Delay(1000); // 如果需要等待1秒,可以启用此行代码。
}
// var tasks = bomList.Select(async item =>
@@ -386,7 +388,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
var UpdateableList = new List();
var UpdateableOutput = new List();
- int batchSize = 20; // 每批的大小
+ int batchSize = 100; // 每批的大小
int totalCount = data.ToList().Count;
for (int i = 0; i < totalCount; i += batchSize)
@@ -477,6 +479,9 @@ public class StockInquiryService : IDynamicApiController, ITransient
// 合并当前批次的结果
UpdateableOutput.AddRange(bomStockInquiryOutput);
+
+ // 如果需要暂停或者处理频率,可以在此处插入适当的延迟。
+ await Task.Delay(1000); // 如果需要等待1秒,可以启用此行代码。
}
// var tasks = data.Select(async item =>
@@ -611,9 +616,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
if (apiOutput.Code == "S")
{
string priceValue = apiOutput.Verpr;
- var Verpr2 = await _dataValidationService.ProcessNumber(0);
- var Verpr3 = await _dataValidationService.ProcessNumber(apiOutput.Verpr.ToDecimal());
- var priceValue3 = Verpr3 == 0 ? "9999.99" : Verpr3.ToString();
+
if (apiOutput.Verpr != "0.0")
{
var Verpr = await _dataValidationService.ProcessNumber(apiOutput.Verpr.ToDecimal());
@@ -623,7 +626,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
priceValue = "9999.99";
}
- var data = await _obj137Rep.AsQueryable().Where(x => x._System_objNBS == materialCode && x.deleted == false).OrderByDescending(x => x.idRecord).FirstAsync();
+ var data = await _obj137Rep.AsQueryable().Where(x => x._System_objNBS == materialCode && x.deleted == false && x.SWPDMConfigurationName == "默认").OrderByDescending(x => x.idRecord).FirstAsync();
if (data != null)
{
apiOutput.DateUpdated = DateTime.Now;
@@ -674,7 +677,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
var Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName);
var materialData = await db.CopyNew().Queryable()
- .Where(x => x._System_objNBS == materialCode && x.deleted == false)
+ .Where(x => x._System_objNBS == materialCode && x.deleted == false && x.SWPDMConfigurationName == "默认")
.OrderByDescending(x => x.idRecord)
.FirstAsync();
@@ -688,7 +691,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
var UpdateableList = new List();
var UpdateableOutput = new List();
- int batchSize = 20; // 每批的大小
+ int batchSize = 50; // 每批的大小
int totalCount = bomList.ToList().Count;
for (int i = 0; i < totalCount; i += batchSize)
@@ -800,6 +803,8 @@ public class StockInquiryService : IDynamicApiController, ITransient
// 合并当前批次的结果
UpdateableOutput.AddRange(bomStockInquiryOutput);
+ // 如果需要暂停或者处理频率,可以在此处插入适当的延迟。
+ await Task.Delay(1000); // 如果需要等待1秒,可以启用此行代码。
}
return UpdateableOutput.ToList();
}
@@ -824,7 +829,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
var UpdateableList = new List();
var UpdateableOutput = new List();
- int batchSize = 20; // 每批的大小
+ int batchSize = 100; // 每批的大小
int totalCount = data.ToList().Count;
for (int i = 0; i < totalCount; i += batchSize)
@@ -911,6 +916,298 @@ public class StockInquiryService : IDynamicApiController, ITransient
// 合并当前批次的结果
UpdateableOutput.AddRange(bomStockInquiryOutput);
+
+ // 如果需要暂停或者处理频率,可以在此处插入适当的延迟。
+ await Task.Delay(1000); // 如果需要等待1秒,可以启用此行代码。
+ }
+ return UpdateableOutput.ToList();
+ }
+
+ ///
+ /// 获取PDM库物料
+ ///
+ ///
+ ///
+ [ApiDescriptionSettings(Name = "GetPdmMaterial", Description = "获取PDM库物料", Order = 1000), HttpPost]
+ [DisplayName("获取PDM库物料")]
+ [AllowAnonymous]
+ public async Task> GetPdmMaterial(RawMaterialInput input)
+ {
+ var data = await _obj137Rep.AsQueryable().PartitionBy(it => it.RecordGuid)
+ .OrderBy(it => it.idRecord, OrderByType.Desc)
+ .Take(1)
+ .WhereIF(!string.IsNullOrWhiteSpace(input.materialCode), u => u._System_objNBS.Contains(input.materialCode.Trim()))
+ .Where(it => it.deleted == false && it.SWPDMConfigurationName == "默认" && it.IsLatestVersion == true && !SqlFunc.IsNullOrEmpty(it._System_objNBS) && !it._System_objNBS.Contains("默认"))
+ .Select()
+ .ToListAsync();
+ return data;
+ }
+
+ ///
+ /// PDM库存查询
+ ///
+ ///
+ [ApiDescriptionSettings(Name = "PdmMaterialStockInquiry", Description = "PDM库存查询", Order = 1000), HttpGet]
+ [DisplayName("PDM库存查询")]
+ [AllowAnonymous]
+ public async Task> PdmMaterialStockInquiry()
+ {
+ using var serviceScope = _scopeFactory.CreateScope();
+ var db = serviceScope.ServiceProvider.GetRequiredService().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
+
+ var Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName);
+ var data = await _obj137Rep.AsQueryable().PartitionBy(it => it.RecordGuid)
+ .OrderBy(it => it.idRecord, OrderByType.Desc)
+ .Take(1)
+ .Where(it => it.deleted == false && it.SWPDMConfigurationName == "默认" && it.IsLatestVersion == true && !SqlFunc.IsNullOrEmpty(it._System_objNBS) && !it._System_objNBS.Contains("默认"))
+ .Select()
+ .ToListAsync();
+ var UpdateableList = new List();
+ var UpdateableOutput = new List();
+
+ int batchSize = 100; // 每批的大小
+ int totalCount = data.ToList().Count;
+
+ for (int i = 0; i < totalCount; i += batchSize)
+ {
+ var batch = data.Skip(i).Take(batchSize); // 分批获取数据
+
+ // 处理当前批次的数据
+ var tasks = batch.Select(async item =>
+ {
+ var code = item._System_objNBS;
+ var name = item._System_objDescription;
+ var objectid = 112;
+ var id = item.idRecord;
+ var SapEcnQueryData = new SapEcnQueryInput
+ {
+ Reqkeyid = "",
+ Businessid = "",
+ Messageid = "",
+ Sndprn = "PLM",
+ Rcvprn = "SAP",
+ Requser = Requser,
+ Note1 = "",
+ Note2 = "",
+ Note3 = "",
+ Sign = "I",
+ Option = "EQ",
+ Low = code,
+ High = ""
+ };
+
+ var apiOutput = await _sapService.SapEcnQueryApi(SapEcnQueryData);
+ var dateUpdated = DateTime.Now;
+ if (apiOutput.Code == "S")
+ {
+ var UpdateableData = new BomStockInquiryUpdateable
+ {
+ Objectid = objectid,
+ Code = apiOutput.Code,
+ RecordGuid = id.ToString(),//在这个方法中使用RecordGuid字段作为id字段
+ Bdmng = apiOutput.Bdmng,
+ Labst = apiOutput.Labst,
+ ZwqslPo = apiOutput.ZwqslPo,
+ ZwqslPr = apiOutput.ZwqslPr,
+ DateUpdated = dateUpdated
+ };
+ UpdateableList.Add(UpdateableData);
+
+
+ db.CopyNew().Updateable().SetColumns(it => new Obj137
+ {
+ fld006530 = UpdateableData.Bdmng,
+ fld005623 = UpdateableData.Labst,
+ fld006531 = UpdateableData.ZwqslPo,
+ fld006532 = UpdateableData.ZwqslPr,
+ fld005624 = dateUpdated
+ })
+ .Where(it => it.idRecord == Convert.ToInt32(UpdateableData.RecordGuid))//在这个方法中使用RecordGuid字段作为id字段
+ .ExecuteCommand();
+
+ return new BomStockInquiryOutput
+ {
+ materialCode = code,
+ materialName = name,
+ Labst = apiOutput.Labst,
+ Bdmng = apiOutput.Bdmng,
+ ZwqslPr = apiOutput.ZwqslPr,
+ ZwqslPo = apiOutput.ZwqslPo,
+ DateUpdated = dateUpdated,
+ State = "查询成功"
+ };
+ }
+ else
+ {
+ var UpdateableData = new BomStockInquiryUpdateable
+ {
+ Code = "",
+ RecordGuid = "",
+ Bdmng = "",
+ Labst = "",
+ ZwqslPo = "",
+ ZwqslPr = "",
+ DateUpdated = dateUpdated
+ };
+ UpdateableList.Add(UpdateableData);
+ db.CopyNew().Updateable().SetColumns(it => new Obj137
+ {
+ fld006530 = "",
+ fld005623 = "",
+ fld006531 = "",
+ fld006532 = "",
+ fld005624 = dateUpdated
+ })
+ .Where(it => it.idRecord == Convert.ToInt32(UpdateableData.RecordGuid))//在这个方法中使用RecordGuid字段作为id字段
+ .ExecuteCommand();
+
+ return new BomStockInquiryOutput
+ {
+ materialCode = code,
+ materialName = name,
+ State = "SAP未查询到库存信息"
+ };
+
+ }
+
+ }).ToList();
+
+ var bomStockInquiryOutput = await Task.WhenAll(tasks); // 等待当前批次的所有任务完成
+
+ // 合并当前批次的结果
+ UpdateableOutput.AddRange(bomStockInquiryOutput);
+
+ // 如果需要暂停或者处理频率,可以在此处插入适当的延迟。
+ await Task.Delay(1000); // 如果需要等待1秒,可以启用此行代码。
+ }
+ //foreach (var item in UpdateableList)
+ //{
+ // var dateUpdated = DateTime.Now;
+ // db.CopyNew().Updateable().SetColumns(it => new Obj112
+ // {
+ // fld006750 = item.Bdmng,
+ // fld006751 = item.Labst,
+ // fld006752 = item.ZwqslPo,
+ // fld006753 = item.ZwqslPr,
+ // fld006755 = dateUpdated
+ // })
+ // .Where(it => it.idRecord == Convert.ToInt32(item.RecordGuid))//在这个方法中使用RecordGuid字段作为id字段
+ // .ExecuteCommand();
+ //}
+
+ return UpdateableOutput.ToList();
+ }
+
+ ///
+ /// PDM成本查询
+ ///
+ ///
+ [ApiDescriptionSettings(Name = "PDMMaterialPriceInquiry", Description = "PDM成本查询", Order = 1000), HttpGet]
+ [DisplayName("PDM成本查询")]
+ [AllowAnonymous]
+ public async Task> PdmMaterialPriceInquiry()
+ {
+ using var serviceScope = _scopeFactory.CreateScope();
+ var db = serviceScope.ServiceProvider.GetRequiredService().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
+
+ var Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName);
+ var data = await _obj137Rep.AsQueryable().PartitionBy(it => it.RecordGuid)
+ .OrderBy(it => it.idRecord, OrderByType.Desc)
+ .Take(1)
+ .Where(it => it.deleted == false && it.SWPDMConfigurationName == "默认" && it.IsLatestVersion == true && !SqlFunc.IsNullOrEmpty(it._System_objNBS) && !it._System_objNBS.Contains("默认"))
+ .Select()
+ .ToListAsync();
+ var UpdateableList = new List();
+ var UpdateableOutput = new List();
+
+ int batchSize = 100; // 每批的大小
+ int totalCount = data.ToList().Count;
+
+ for (int i = 0; i < totalCount; i += batchSize)
+ {
+ var batch = data.Skip(i).Take(batchSize); // 分批获取数据
+
+ // 处理当前批次的数据
+ var tasks = batch.Select(async item =>
+ {
+ var code = item._System_objNBS;
+ var name = item._System_objDescription;
+ var id = item.idRecord;
+ var SapPriceQueryData = new SapPriceQueryInput
+ {
+ Reqkeyid = "",
+ Businessid = "",
+ Messageid = "",
+ Sndprn = "PLM",
+ Rcvprn = "SAP",
+ Requser = Requser,
+ Note1 = "",
+ Note2 = "",
+ Note3 = "",
+ Sign = "I",
+ Option = "EQ",
+ Low = code,
+ High = ""
+ };
+
+ var apiOutput = await _sapService.SapPriceQueryApi(SapPriceQueryData);
+ var dateUpdated = DateTime.Now;
+ if (apiOutput.Code == "S")
+ {
+ string priceValue = apiOutput.Verpr;
+
+ if (apiOutput.Verpr != "0.0")
+ {
+ var Verpr = await _dataValidationService.ProcessNumber(apiOutput.Verpr.ToDecimal());
+ priceValue = Verpr == 0 ? "9999.99" : Verpr.ToString();
+ }
+ else
+ {
+ priceValue = "9999.99";
+ }
+
+ db.CopyNew().Updateable().SetColumns(it => new Obj137
+ {
+ fld005625 = priceValue,
+ fld005626 = dateUpdated
+ })
+ .Where(it => it.idRecord == id)//在这个方法中使用RecordGuid字段作为id字段
+ .ExecuteCommand();
+
+ return new BomPriceInquiryOutput
+ {
+ materialCode = code,
+ materialName = name,
+ Verpr = priceValue,
+ DateUpdated = dateUpdated,
+ State = "查询成功"
+ };
+ }
+ else
+ {
+ db.CopyNew().Updateable().SetColumns(it => new Obj137
+ {
+ fld005625 = "",
+ fld005626 = dateUpdated
+ }).Where(it => it.idRecord == id)
+ .ExecuteCommand();
+
+ return new BomPriceInquiryOutput
+ {
+ materialCode = code,
+ materialName = name,
+ State = "查询失败"
+ };
+ }
+ }).ToList();
+
+ var bomStockInquiryOutput = await Task.WhenAll(tasks); // 等待当前批次的所有任务完成
+
+ // 合并当前批次的结果
+ UpdateableOutput.AddRange(bomStockInquiryOutput);
+
+ // 如果需要暂停或者处理频率,可以在此处插入适当的延迟。
+ await Task.Delay(1000); // 如果需要等待1秒,可以启用此行代码。
}
return UpdateableOutput.ToList();
}