Compare commits

...

4 Commits

12 changed files with 1245 additions and 208 deletions

View File

@ -7,6 +7,7 @@
using Admin.NET.Core;
using Admin.NET.Core.Service;
using DocumentFormat.OpenXml.Bibliography;
using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Drawing.Spreadsheet;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
@ -27,6 +28,7 @@ using Vistar.Application.Entity;
using Vistar.Application.SapService.Dto;
using Vistar.Application.Util;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.CgibinAccountGetAccountBasicInfoResponse.Types;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.ScanProductAddV2Request.Types.Product.Types;
namespace Vistar.Application.Common;
public class DataValidationService : IDynamicApiController, ITransient
@ -80,10 +82,10 @@ public class DataValidationService : IDynamicApiController, ITransient
string verification = "不存在";
if (objId==110)
if (objId == 110)
{
var data = db.CopyNew().Queryable<Obj110>().Where(x => x._System_objNBS == materialCode && x.deleted == false && x.RecordGuid == recordGuid).Count();
if (data>0)
if (data > 0)
{
verification = "存在";
}
@ -194,7 +196,7 @@ public class DataValidationService : IDynamicApiController, ITransient
{
case 110:
data = await db.CopyNew().Queryable<Obj110>()
.Where(x => x.RecordGuid == recordGuid && x.deleted == false).OrderByDescending(x=>x.idRecord)
.Where(x => x.RecordGuid == recordGuid && x.deleted == false).OrderByDescending(x => x.idRecord)
.FirstAsync();
break;
case 109:
@ -395,32 +397,35 @@ public class DataValidationService : IDynamicApiController, ITransient
/// <returns></returns>
public async Task<string> ModifyInventoryInformation(string recordGuid, string code, long objectid, string Bdmng, string Labst, string ZwqslPo, string ZwqslPr, DateTime dateUpdated)
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
if (code == "S")
{
if (objectid == 137)
{
var data = _obj137Rep.AsQueryable().Where(x => x.RecordGuid == recordGuid && x.deleted == false).OrderByDescending(x => x.idRecord).First();
var data = await db.CopyNew().Queryable<Obj137>().Where(x => x.RecordGuid == recordGuid && x.deleted == false).OrderByDescending(x => x.idRecord).FirstAsync();
if (data != null)
{
await _obj137Rep.AsUpdateable().SetColumns(it => new Obj137
{
fld006530 = Bdmng,
fld005623 = Labst,
fld006531 = ZwqslPo,
fld006532 = ZwqslPr,
fld005624 = dateUpdated
})
db.CopyNew().Updateable<Obj137>()
.SetColumns(it => new Obj137
{
fld006530 = Bdmng,
fld005623 = Labst,
fld006531 = ZwqslPo,
fld006532 = ZwqslPr,
fld005624 = dateUpdated
})
.Where(it => it.idRecord == data.idRecord)
.ExecuteCommandAsync();
.ExecuteCommand();
}
}
if (objectid == 112)
{
var data = _obj112Rep.AsQueryable().Where(x => x.RecordGuid == recordGuid && x.deleted == false).First();
var data = await db.CopyNew().Queryable<Obj112>().Where(x => x.RecordGuid == recordGuid && x.deleted == false).FirstAsync();
if (data != null)
{
await _obj112Rep.AsUpdateable().SetColumns(it => new Obj112
db.CopyNew().Updateable<Obj112>().SetColumns(it => new Obj112
{
fld006750 = Bdmng,
fld006751 = Labst,
@ -429,7 +434,7 @@ public class DataValidationService : IDynamicApiController, ITransient
fld006755 = dateUpdated
})
.Where(it => it.idRecord == data.idRecord)
.ExecuteCommandAsync();
.ExecuteCommand();
}
}
}
@ -437,10 +442,10 @@ public class DataValidationService : IDynamicApiController, ITransient
{
if (objectid == 137)
{
var data = await _obj137Rep.AsQueryable().Where(x => x.RecordGuid == recordGuid && x.deleted == false).OrderByDescending(x => x.idRecord).FirstAsync();
var data = await db.CopyNew().Queryable<Obj137>().Where(x => x.RecordGuid == recordGuid && x.deleted == false).OrderByDescending(x => x.idRecord).FirstAsync();
if (data != null)
{
await _obj137Rep.AsUpdateable().SetColumns(it => new Obj137
db.CopyNew().Updateable<Obj137>().SetColumns(it => new Obj137
{
fld006530 = "",
fld005623 = "",
@ -449,31 +454,114 @@ public class DataValidationService : IDynamicApiController, ITransient
fld005624 = dateUpdated
})
.Where(it => it.idRecord == data.idRecord)
.ExecuteCommandAsync();
.ExecuteCommand();
}
}
if (objectid == 112)
{
var data = await _obj112Rep.AsQueryable().Where(x => x.RecordGuid == recordGuid && x.deleted == false).FirstAsync();
var data = await db.CopyNew().Queryable<Obj112>().Where(x => x.RecordGuid == recordGuid && x.deleted == false).FirstAsync();
if (data != null)
{
await _obj112Rep.AsUpdateable().SetColumns(it => new Obj112
{
fld006750 = "",
fld006751 = "",
fld006752 = "",
fld006753 = "",
fld006755 = dateUpdated
})
db.CopyNew().Updateable<Obj112>()
.SetColumns(it => new Obj112
{
fld006750 = "",
fld006751 = "",
fld006752 = "",
fld006753 = "",
fld006755 = dateUpdated
})
.Where(it => it.idRecord == data.idRecord)
.ExecuteCommandAsync();
.ExecuteCommand();
}
}
}
return "修改成功";
}
/// <summary>
/// 修改价格信息
/// </summary>
/// <param name="recordGuid"></param>
/// <param name="code"></param>
/// <param name="objectid"></param>
/// <param name="Verpr"></param>
/// <param name="dateUpdated"></param>
/// <returns></returns>
public async Task<string> ModifyPriceInformation(string recordGuid, string code, long objectid, string Verpr, DateTime dateUpdated)
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
if (code == "S")
{
if (objectid == 137)
{
var data = await db.CopyNew().Queryable<Obj137>().Where(x => x.RecordGuid == recordGuid && x.deleted == false).OrderByDescending(x => x.idRecord).FirstAsync();
if (data != null)
{
db.CopyNew().Updateable<Obj137>()
.SetColumns(it => new Obj137
{
fld005625 = Verpr,
fld005626 = dateUpdated
})
.Where(it => it.idRecord == data.idRecord)
.ExecuteCommand();
}
}
if (objectid == 112)
{
var data = await db.CopyNew().Queryable<Obj112>().Where(x => x.RecordGuid == recordGuid && x.deleted == false).FirstAsync();
if (data != null)
{
db.CopyNew().Updateable<Obj112>().SetColumns(it => new Obj112
{
fld006754 = Verpr,
fld006756 = dateUpdated
})
.Where(it => it.idRecord == data.idRecord)
.ExecuteCommand();
}
}
}
else
{
if (objectid == 137)
{
var data = await db.CopyNew().Queryable<Obj137>().Where(x => x.RecordGuid == recordGuid && x.deleted == false).OrderByDescending(x => x.idRecord).FirstAsync();
if (data != null)
{
db.CopyNew().Updateable<Obj137>().SetColumns(it => new Obj137
{
fld005625 = "",
fld005626 = dateUpdated
})
.Where(it => it.idRecord == data.idRecord)
.ExecuteCommand();
}
}
if (objectid == 112)
{
var data = await db.CopyNew().Queryable<Obj112>().Where(x => x.RecordGuid == recordGuid && x.deleted == false).FirstAsync();
if (data != null)
{
db.CopyNew().Updateable<Obj112>()
.SetColumns(it => new Obj112
{
fld006754 = "",
fld006756 = dateUpdated
})
.Where(it => it.idRecord == data.idRecord)
.ExecuteCommand();
}
}
}
return "修改成功";
}
/// <summary>
@ -511,6 +599,42 @@ public class DataValidationService : IDynamicApiController, ITransient
return status;
}
public async Task<decimal> ProcessNumber(decimal number)
{
if (number < 1)
{
string numStr = number.ToString();
int decimalIndex = numStr.IndexOf('.');
string decimalPart = numStr.Substring(decimalIndex + 1);
// 去除小数部分末尾的 0
decimalPart = decimalPart.TrimEnd('0');
if (decimalPart.Length == 1)
{
return number;
}
int firstNonZeroIndex = 0;
while (firstNonZeroIndex < decimalPart.Length && decimalPart[firstNonZeroIndex] == '0')
{
firstNonZeroIndex++;
}
if (firstNonZeroIndex == decimalPart.Length - 1)
{
// 若只有一位非零数字,找到合适的进位位置
string newDecimalPart = new string('0', firstNonZeroIndex - 1) + "1";
return decimal.Parse("0." + newDecimalPart);
}
return Math.Round(number, decimalPart.Length - firstNonZeroIndex - 1);
}
else
{
if (number < 10000)
{
int power = (int)Math.Floor(Math.Log10((double)number));
return (decimal)(Math.Floor((double)number / Math.Pow(10, power)) * Math.Pow(10, power));
}
return (decimal)(Math.Floor((double)number / 1000) * 1000);
}
}
///// <summary>
///// 验证是否存在bom和工艺路线

View File

@ -553,4 +553,9 @@ public class Obj112
/// </summary>
public DateTime fld006755 { get; set; }
/// <summary>
/// 成本更新日期
/// </summary>
public DateTime fld006756 { get; set; }
}

View File

@ -1407,4 +1407,9 @@ public class Obj137
/// 库存更新日期
/// </summary>
public DateTime fld005624 { get; set; }
/// <summary>
/// 成本更新日期
/// </summary>
public DateTime fld005626 { get; set; }
}

View File

@ -37,7 +37,6 @@ public class PurchasingRequisitionToSap : IJob
var sapOutputs = await _purchasingRequisition.TimingSyncToSAPPurchasingRequisition();
var json = JsonConvert.SerializeObject(sapOutputs);
using var serviceScope = _scopeFactory.CreateScope();
var sysEnumService = serviceScope.ServiceProvider.GetRequiredService<SysEnumService>();
var dbMain = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;

View File

@ -120,4 +120,8 @@ public class ItemData
/// 研发模块
/// </summary>
public string ZYFMK { get; set; }
/// <summary>
/// 子件guid
/// </summary>
public string? ChildGuid { get; set; }
}

View File

@ -0,0 +1,16 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vistar.Application.SapService.Dto;
public class SapPriceQueryInput: SapEcnQueryInput
{
}

View File

@ -11,6 +11,7 @@ using DocumentFormat.OpenXml.Spreadsheet;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using MailKit;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using OnceMi.AspNetCore.OSS;
using System;
using System.Collections.Generic;
@ -1218,4 +1219,128 @@ public class SapService : IDynamicApiController, ITransient
}
/// <summary>
/// SAP 成本查询服务
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<SapPriceQueryOutput> SapPriceQueryApi(SapPriceQueryInput input)
{
// 创建命名空间
XNamespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
XNamespace urn = "urn:sap-com:document:sap:rfc:functions";
// 创建 SOAP XML 请求
var soapEnvelope = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement(soapenv + "Envelope",
new XAttribute(XNamespace.Xmlns + "soapenv", soapenv.NamespaceName),
new XAttribute(XNamespace.Xmlns + "urn", urn.NamespaceName),
new XElement(soapenv + "Header"),
new XElement(soapenv + "Body",
new XElement(urn + "ZFIFM006",
new XElement("IS_DATA",
new XElement("IT_MATNR",
new XElement("item",
new XElement("SIGN", input.Sign),
new XElement("OPTION", input.Option),
new XElement("LOW", input.Low),
new XElement("HIGH", input.High)
)
)
),
new XElement("IS_REQ",
new XElement("REQKEYID", input.Reqkeyid),
new XElement("BUSINESSID", input.Businessid),
new XElement("MESSAGEID", input.Messageid),
new XElement("SNDPRN", input.Sndprn),
new XElement("RCVPRN", input.Rcvprn),
new XElement("REQUSER", input.Requser),
new XElement("NOTE1", input.Note1),
new XElement("NOTE2", input.Note2),
new XElement("NOTE3", input.Note3)
)
)
)
)
);
var httpClientHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true,
ClientCertificateOptions = ClientCertificateOption.Manual
};
try
{
using (var httpClient = new HttpClient(httpClientHandler))
{
// 设置基本身份验证信息
var username = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
var password = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapPassword);
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);
// 将 XML 内容转换为字符串并设置请求内容类型为 text/xml
var content = new StringContent(soapEnvelope.ToString(), Encoding.UTF8, "text/xml");
content.Headers.ContentType = new MediaTypeHeaderValue("text/xml");
httpClient.DefaultRequestHeaders.Add("Accept-Language", "zh");
// 设置 SAP Web 服务的 URL
//sap正式地址
var url = "https://vhjqeps4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/ZFIFM006/800/ZFIFM006/ZFIFM006";
//sap测试地址
//var url = "https://vhjqeds4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/ZFIFM006/130/ZFIFM006/ZFIFM006";
// 发起 POST 请求到 SAP Web 服务
var response = await httpClient.PostAsync(url, content);
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsStringAsync();
XDocument doc = XDocument.Parse(result);
var esRet = doc.Descendants("ES_RET").FirstOrDefault();
var code = esRet?.Element("CODE")?.Value;
var item = doc.Descendants("item").FirstOrDefault();
var bwkey = item?.Element("BWKEY")?.Value;
var matnr = item?.Element("MATNR")?.Value;
var verpr = item?.Element("VERPR")?.Value;
var output = new SapPriceQueryOutput()
{
Parameter = soapEnvelope.ToString(),
Code = code,
Matnr = matnr,
Bwkey = bwkey,
Verpr = verpr,
Result = result
};
return output;
}
else
{
var result = await response.Content.ReadAsStringAsync();
var output = new SapPriceQueryOutput()
{
Parameter = soapEnvelope.ToString(),
Code = "失败",
Result = result
};
return output;
}
}
}
catch (Exception ex)
{
// 记录错误日志
Console.WriteLine("发生错误: " + ex.Message);
var output = new SapPriceQueryOutput()
{
Code = "失败",
Result = "发生错误" + ex
};
return output;
}
}
}

View File

@ -16,6 +16,7 @@ using static Elastic.Clients.Elasticsearch.JoinField;
using Qiniu.CDN;
using SqlSugar;
using Microsoft.Extensions.DependencyInjection;
using System.Text.RegularExpressions;
namespace Vistar.Application.Service.MaterialManagement;
@ -26,6 +27,7 @@ namespace Vistar.Application.Service.MaterialManagement;
public class ProductManagementService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<Obj110> _obj110Rep;
private readonly SqlSugarRepository<Obj137> _obj137Rep;
private readonly SqlSugarRepository<Configurations> _configurationsRep;
private readonly SysConfigService _sysConfigService;
private readonly SqlSugarRepository<ConfigurationData> _configurationDataRep;
@ -38,6 +40,7 @@ public class ProductManagementService : IDynamicApiController, ITransient
public ProductManagementService(
SqlSugarRepository<Obj110> obj110Rep,
SqlSugarRepository<Obj137> obj137Rep,
SqlSugarRepository<Configurations> configurationsRep,
SysConfigService sysConfigService,
SqlSugarRepository<ConfigurationData> configurationDataRep,
@ -60,6 +63,7 @@ public class ProductManagementService : IDynamicApiController, ITransient
_obj122Rep = obj122Rep;
_obj121Rep = obj121Rep;
_scopeFactory = scopeFactory;
_obj137Rep = obj137Rep;
}
/// <summary>
/// 分页查询产品管理
@ -190,11 +194,30 @@ public class ProductManagementService : IDynamicApiController, ITransient
var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 110 && x.ConfigSystemName == "mBOM").FirstAsync();
var parent = await _obj110Rep.AsQueryable().Where(x => x.RecordGuid == input.ParentGuid && x.deleted == false && x.fld004311 == "成功" && x.fld004312 == "N").MaxAsync(x => x.VersionIndex);
var BomData = await _configurationDataRep.AsQueryable()
.Where(x => x.ConfigId == configid.ConfigID && x.ParentGuid == input.ParentGuid && x.isDeleted == false && x.ParentVersion == parent && (x.fld005586 != "不包含" || x.fld005586 == null))
.WhereIF(!string.IsNullOrWhiteSpace(input.Description), u => u.Description.Contains(input.Description.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.PartNumber), u => u.PartNumber.Contains(input.PartNumber.Trim()))
.Select<ProductManagementBomOutput>().ToPagedListAsync(input.Page, input.PageSize);
return BomData;
.Where(x => x.ConfigId == configid.ConfigID && x.ParentGuid == input.ParentGuid && x.isDeleted == false && x.ParentVersion == parent && (x.fld005586 != "不包含" || x.fld005586 == null)).Select<ProductManagementBomOutput>().ToListAsync();
//.WhereIF(!string.IsNullOrWhiteSpace(input.Description), u => u.Description.Contains(input.Description.Trim()))
//.WhereIF(!string.IsNullOrWhiteSpace(input.PartNumber), u => u.PartNumber.Contains(input.PartNumber.Trim()))
//.Select<ProductManagementBomOutput>().ToPagedListAsync(input.Page, input.PageSize);
foreach (var item in BomData)
{
if (item.ChildObjID == 137)
{
if (item.PartNumber != null && Regex.IsMatch(item.PartNumber, "默认"))
{
var data137 = await _obj137Rep.AsQueryable().Where(x => x.RecordGuid == item.ChildGuid && x.deleted == false && x._system_objConfigurationName == "默认").OrderByDescending(x => x.idRecord).FirstAsync();
if (data137 != null)
{
item.PartNumber = data137._System_objNBS;
item.Description = data137._System_ObjDescription;
}
}
}
}
var data = BomData.ToPagedList(input.Page, input.PageSize);
return data;
}
/// <summary>
/// 产品管理-Bom同步到SAP
@ -217,8 +240,28 @@ public class ProductManagementService : IDynamicApiController, ITransient
for (int i = 0; i < input.Count; i++)
{
var Verification = await _dataValidationService.VerificationMaterial(input[i].ChildObjID, input[i].PartNumber, input[i].ChildGuid);
if (Verification == "不存在")
//var Verification = await _dataValidationService.VerificationMaterial(input[i].ChildObjID, input[i].PartNumber, input[i].ChildGuid);
string verification = "不存在";
if (input[i].ChildObjID == 137)
{
var data137 = await _obj137Rep.AsQueryable().Where(x => x._System_objNBS == input[i].PartNumber && x.deleted == false && x.RecordGuid == input[i].ChildGuid && x._system_objConfigurationName == "默认").OrderByDescending(x => x.idRecord).FirstAsync();
if (data137 == null)
{
verification = "不存在";
}
else
{
input[i].PartNumber = data137._System_objNBS;
verification = "存在";
}
}
else
{
verification = await _dataValidationService.VerificationMaterial(input[i].ChildObjID, input[i].PartNumber, input[i].ChildGuid);
}
if (verification == "不存在")
{
continue;
}
@ -234,7 +277,8 @@ public class ProductManagementService : IDynamicApiController, ITransient
ALPRF = input[i].fld004939,
ZDELETE = input[i].fld004940,
POSTP = input[i].fld004492,
ZYFMK = input[i].fld004941
ZYFMK = input[i].fld004941,
ChildGuid= input[i].ChildGuid
};
itemDataList.Add(itemData);
}
@ -246,7 +290,8 @@ public class ProductManagementService : IDynamicApiController, ITransient
for (int i = 0; i < BomData.Count; i++)
{
var itemList = itemDataList.Where(x => x.IDNRK == BomData[i].PartNumber).ToList();
//var itemList = itemDataList.Where(x => x.IDNRK == BomData[i].PartNumber).ToList();
var itemList = itemDataList.Where(x => x.ChildGuid == BomData[i].ChildGuid).ToList();
if (itemList.Count == 0)
{
var Verification = await _dataValidationService.VerificationMaterial(BomData[i].ChildObjID, BomData[i].PartNumber, BomData[i].ChildGuid);
@ -964,10 +1009,47 @@ public class ProductManagementService : IDynamicApiController, ITransient
var itemDataList = new List<ItemData>();
foreach (var item in data.Bom)
{
var verification = await _dataValidationService.VerificationMaterial(item.ChildObjID, item.PartNumber, item.ChildGuid);
string verification = "不存在";
if (item.ChildObjID == 137)
{
var data137 = await db.CopyNew().Queryable<Obj137>().Where(x => x._System_objNBS == item.PartNumber && x.deleted == false && x.RecordGuid == item.ChildGuid && x._system_objConfigurationName == "默认").OrderByDescending(x=>x.idRecord).FirstAsync();
if (data137 == null)
{
verification = "不存在";
}
else {
item.PartNumber = data137._System_objNBS;
verification = "存在";
}
}
else {
verification = await _dataValidationService.VerificationMaterial(item.ChildObjID, item.PartNumber, item.ChildGuid);
}
if (verification == "不存在")
{
continue;
if (item.ChildObjID == 137)
{
string partNumber = item.PartNumber.Replace("默认 ", "");//过滤BOM表PartNumber字段存在“默认 ”
if (partNumber == item.PartNumber)//判断过滤后,物料编码是否和原料相同,相同的话跳出循环
{
continue;
}
var data137 = db.CopyNew().Queryable<Obj137>().Where(x => x._System_objNBS == item.ChildGuid && x.deleted == false && x._system_objConfigurationName == "默认").OrderByDescending(x => x.idRecord).First();
if (data137 != null)
{
item.PartNumber = data137._System_objNBS;
}
else
{
continue;
}
}
else
{
continue;
}
}
var itemData = new ItemData
{
@ -980,7 +1062,8 @@ public class ProductManagementService : IDynamicApiController, ITransient
ALPRF = item.ALPRF,
ZDELETE = item.ZDELETE,
POSTP = item.POSTP,
ZYFMK = item.ZYFMK
ZYFMK = item.ZYFMK,
ChildGuid=item.ChildGuid
};
itemDataList.Add(itemData);
}
@ -989,13 +1072,35 @@ public class ProductManagementService : IDynamicApiController, ITransient
var BomData = db.CopyNew().Queryable<ConfigurationData>().Where(x => x.ConfigId == 1 && x.ParentGuid == data.RecordGuid && x.isDeleted == false && x.ParentVersion == Convert.ToInt32(data.SyncVersion) && (x.fld005586 != "不包含" || x.fld005586 == null)).ToList();
foreach (var item in BomData)
{
var itemList = itemDataList.Where(x => x.IDNRK == item.PartNumber).ToList();
//var itemList = itemDataList.Where(x => x.IDNRK == item.PartNumber).ToList();
var itemList = itemDataList.Where(x => x.ChildGuid == item.ChildGuid).ToList();
if (itemList.Count == 0)
{
var Verification = await _dataValidationService.VerificationMaterial(item.ChildObjID, item.PartNumber, item.ChildGuid);
if (Verification == "不存在")
{
continue;
if (item.ChildObjID == 137)
{
string partNumber = item.PartNumber.Replace("默认 ", "");//过滤BOM表PartNumber字段存在“默认 ”
if (partNumber == item.PartNumber)//判断过滤后,物料编码是否和原料相同,相同的话跳出循环
{
continue;
}
var data137 = db.CopyNew().Queryable<Obj137>().Where(x => x._System_objNBS == partNumber && x.deleted == false).OrderByDescending(x => x.idRecord).First();
if (data137 != null)
{
item.PartNumber = data137._System_objNBS;
}
else
{
continue;
}
}
else
{
continue;
}
}
var itemData = new ItemData()
{

View File

@ -120,7 +120,7 @@ public class PurchasingRequisitionService : IDynamicApiController, ITransient
//查询BOM
var bomData = await db.CopyNew().Queryable<ConfigurationData>().Where(x => x.ConfigId == configid && x.ParentGuid == item.RecordGuid && x.isDeleted == false && x.ParentVersion == item.VersionIndex).ToListAsync();
var project = await db.CopyNew().Queryable<Obj119>().Where(x => x.RecordGuid == item.fld004639_Rec && x.deleted == false).OrderByDescending(x => x.VersionIndex).FirstAsync();
var project = await db.CopyNew().Queryable<Obj109>().Where(x => x.RecordGuid == item.fld004639_Rec && x.deleted == false).OrderByDescending(x => x.VersionIndex).FirstAsync();
foreach (var bomItem in bomData)
{
var unit = await _dataValidationService.GetUnit(bomItem.ChildObjID, bomItem.ChildGuid);

View File

@ -0,0 +1,79 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vistar.Application.Service.StockInquiry.Dto;
public class BomPriceInquiryOutput
{
/// <summary>
/// 物料编码
/// </summary>
public string materialCode { get; set; }
/// <summary>
/// 物料描述
/// </summary>
public string materialName { get; set; }
/// <summary>
/// sap入参
/// </summary>
public string Parameter { get; set; }
/// <summary>
/// 消息类型
/// </summary>
public string Code { get; set; }
/// <summary>
/// 物料编码
/// </summary>
public string Matnr { get; set; }
/// <summary>
/// 工厂
/// </summary>
public string Bwkey { get; set; }
/// <summary>
/// 价格
/// </summary>
public string Verpr { get; set; }
/// <summary>
/// sap出参
/// </summary>
public string Result { get; set; }
/// <summary>
/// 更新日期
/// </summary>
public DateTime DateUpdated { get; set; }
/// <summary>
/// 查询状态
/// </summary>
public string State { get; set; }
}
public class BomPriceInquiryUpdateable
{
public long Objectid { get; set; }
public string RecordGuid { get; set; }
public string Code { get; set; }
/// <summary>
/// 价格
/// </summary>
public string Verpr { get; set; }
public DateTime DateUpdated { get; set; }
}

View File

@ -6,15 +6,18 @@
using Admin.NET.Core;
using Admin.NET.Core.Service;
using DocumentFormat.OpenXml.VariantTypes;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.OscarClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -37,6 +40,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
public SolidWorksManageService.SolidWorksManageService _solidWorksManageService;
private readonly SysConfigService _sysConfigService;
public SapService.SapService _sapService;
private readonly IServiceScopeFactory _scopeFactory;
public StockInquiryService
(
DataValidationService dataValidationService,
@ -45,7 +49,8 @@ public class StockInquiryService : IDynamicApiController, ITransient
SqlSugarRepository<ConfigurationData> configurationDataRep,
SolidWorksManageService.SolidWorksManageService solidWorksManageService,
SysConfigService sysConfigService,
SapService.SapService sapService
SapService.SapService sapService,
IServiceScopeFactory scopeFactory
)
{
_obj137Rep = obj137Rep;
@ -55,6 +60,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
_sysConfigService = sysConfigService;
_sapService = sapService;
_dataValidationService = dataValidationService;
_scopeFactory = scopeFactory;
}
/// <summary>
@ -137,14 +143,17 @@ public class StockInquiryService : IDynamicApiController, ITransient
[AllowAnonymous]
public async Task<List<BomStockInquiryOutput>> GetBomProductInventory(string materialCode)
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
var materialData = await _obj137Rep.AsQueryable()
var materialData = await db.CopyNew().Queryable<Obj137>()
.Where(x => x._System_objNBS == materialCode && x.deleted == false)
.OrderByDescending(x => x.idRecord)
.FirstAsync();
var bomList = await _configurationDataRep.AsQueryable()
var bomList = await db.CopyNew().Queryable<ConfigurationData>()
.Where(x => x.ParentGuid == materialData.RecordGuid && x.isDeleted == false
&& x.ParentVersion == materialData.VersionIndex
&& (x.fld005577 != "不包含" || x.fld005577 == null)
@ -152,95 +161,191 @@ public class StockInquiryService : IDynamicApiController, ITransient
.ToListAsync();
var UpdateableList = new List<BomStockInquiryUpdateable>();
var UpdateableOutput = new List<BomStockInquiryOutput>();
var tasks = bomList.Select(async item =>
int batchSize = 20; // 每批的大小
int totalCount = bomList.ToList().Count;
for (int i = 0; i < totalCount; i += batchSize)
{
var code = item.PartNumber;
var name = item.Description;
var objectid = item.ChildObjID;
var childGuid = item.ChildGuid;
var batch = bomList.Skip(i).Take(batchSize); // 分批获取数据
var SapEcnQueryData = new SapEcnQueryInput
// 处理当前批次的数据
var tasks = batch.Select(async item =>
{
Reqkeyid = "",
Businessid = "",
Messageid = "",
Sndprn = "PLM",
Rcvprn = "SAP",
Requser = Requser,
Note1 = "",
Note2 = "",
Note3 = "",
Sign = "I",
Option = "EQ",
Low = code,
High = ""
};
var code = item.PartNumber;
var name = item.Description;
var objectid = item.ChildObjID;
var childGuid = item.ChildGuid;
var apiOutput = await _sapService.SapEcnQueryApi(SapEcnQueryData);
var dateUpdated = DateTime.Now;
if (apiOutput.Code == "S")
{
var UpdateableData = new BomStockInquiryUpdateable
var SapEcnQueryData = new SapEcnQueryInput
{
Objectid = objectid,
Code = apiOutput.Code,
RecordGuid = childGuid,
Bdmng = apiOutput.Bdmng,
Labst = apiOutput.Labst,
ZwqslPo = apiOutput.ZwqslPo,
ZwqslPr = apiOutput.ZwqslPr,
DateUpdated = dateUpdated
Reqkeyid = "",
Businessid = "",
Messageid = "",
Sndprn = "PLM",
Rcvprn = "SAP",
Requser = Requser,
Note1 = "",
Note2 = "",
Note3 = "",
Sign = "I",
Option = "EQ",
Low = code,
High = ""
};
UpdateableList.Add(UpdateableData);
}
else
{
var UpdateableData = new BomStockInquiryUpdateable
{
Code = "",
RecordGuid = "",
Bdmng = "",
Labst = "",
ZwqslPo = "",
ZwqslPr = "",
DateUpdated = dateUpdated
};
UpdateableList.Add(UpdateableData);
}
if (apiOutput.Code == "S")
{
return new BomStockInquiryOutput
{
materialCode = code,
materialName = name,
Labst = apiOutput.Labst,
Bdmng = apiOutput.Bdmng,
ZwqslPr = apiOutput.ZwqslPr,
ZwqslPo = apiOutput.ZwqslPo,
DateUpdated = dateUpdated,
State = "查询成功"
};
}
else
{
return new BomStockInquiryOutput
{
materialCode = code,
materialName = name,
State = "SAP未查询库存信息"
};
}
});
var bomStockInquiryOutput = await Task.WhenAll(tasks);
var apiOutput = await _sapService.SapEcnQueryApi(SapEcnQueryData);
var dateUpdated = DateTime.Now;
if (apiOutput.Code == "S")
{
var UpdateableData = new BomStockInquiryUpdateable
{
Objectid = objectid,
Code = apiOutput.Code,
RecordGuid = childGuid,
Bdmng = apiOutput.Bdmng,
Labst = apiOutput.Labst,
ZwqslPo = apiOutput.ZwqslPo,
ZwqslPr = apiOutput.ZwqslPr,
DateUpdated = dateUpdated
};
//UpdateableList.Add(UpdateableData);
_dataValidationService.ModifyInventoryInformation(UpdateableData.RecordGuid, UpdateableData.Code, UpdateableData.Objectid, UpdateableData.Bdmng, UpdateableData.Labst, UpdateableData.ZwqslPo, UpdateableData.ZwqslPr, UpdateableData.DateUpdated);
}
else
{
var UpdateableData = new BomStockInquiryUpdateable
{
Code = "",
RecordGuid = "",
Bdmng = "",
Labst = "",
ZwqslPo = "",
ZwqslPr = "",
DateUpdated = dateUpdated
};
//UpdateableList.Add(UpdateableData);
_dataValidationService.ModifyInventoryInformation(UpdateableData.RecordGuid, UpdateableData.Code, UpdateableData.Objectid, UpdateableData.Bdmng, UpdateableData.Labst, UpdateableData.ZwqslPo, UpdateableData.ZwqslPr, UpdateableData.DateUpdated);
}
if (apiOutput.Code == "S")
{
return new BomStockInquiryOutput
{
materialCode = code,
materialName = name,
Labst = apiOutput.Labst,
Bdmng = apiOutput.Bdmng,
ZwqslPr = apiOutput.ZwqslPr,
ZwqslPo = apiOutput.ZwqslPo,
DateUpdated = dateUpdated,
State = "查询成功"
};
}
else
{
return new BomStockInquiryOutput
{
materialCode = code,
materialName = name,
State = "SAP未查询到库存信息"
};
}
}).ToList();
var bomStockInquiryOutput = await Task.WhenAll(tasks); // 等待当前批次的所有任务完成
foreach (var item in UpdateableList)
{
await _dataValidationService.ModifyInventoryInformation(item.RecordGuid, item.Code, item.Objectid, item.Bdmng, item.Labst, item.ZwqslPo, item.ZwqslPr, item.DateUpdated);
// 合并当前批次的结果
UpdateableOutput.AddRange(bomStockInquiryOutput);
}
return bomStockInquiryOutput.ToList();
// var tasks = bomList.Select(async item =>
//{
// var code = item.PartNumber;
// var name = item.Description;
// var objectid = item.ChildObjID;
// var childGuid = item.ChildGuid;
// 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 = childGuid,
// Bdmng = apiOutput.Bdmng,
// Labst = apiOutput.Labst,
// ZwqslPo = apiOutput.ZwqslPo,
// ZwqslPr = apiOutput.ZwqslPr,
// DateUpdated = dateUpdated
// };
// UpdateableList.Add(UpdateableData);
// }
// else
// {
// var UpdateableData = new BomStockInquiryUpdateable
// {
// Code = "",
// RecordGuid = "",
// Bdmng = "",
// Labst = "",
// ZwqslPo = "",
// ZwqslPr = "",
// DateUpdated = dateUpdated
// };
// UpdateableList.Add(UpdateableData);
// }
// if (apiOutput.Code == "S")
// {
// return new BomStockInquiryOutput
// {
// materialCode = code,
// materialName = name,
// Labst = apiOutput.Labst,
// Bdmng = apiOutput.Bdmng,
// ZwqslPr = apiOutput.ZwqslPr,
// ZwqslPo = apiOutput.ZwqslPo,
// DateUpdated = dateUpdated,
// State = "查询成功"
// };
// }
// else
// {
// return new BomStockInquiryOutput
// {
// materialCode = code,
// materialName = name,
// State = "SAP未查询到库存信息"
// };
// }
//});
//var bomStockInquiryOutput = await Task.WhenAll(tasks);
//foreach (var item in UpdateableList)
//{
// await _dataValidationService.ModifyInventoryInformation(item.RecordGuid, item.Code, item.Objectid, item.Bdmng, item.Labst, item.ZwqslPo, item.ZwqslPr, item.DateUpdated);
//}
return UpdateableOutput.ToList();
}
/// <summary>
@ -270,97 +375,194 @@ public class StockInquiryService : IDynamicApiController, ITransient
[AllowAnonymous]
public async Task<List<BomStockInquiryOutput>> RawMaterialStockInquiry()
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
var data = await _obj112Rep.AsQueryable()
var data = await db.CopyNew().Queryable<Obj112>()
.Where(x => x.deleted == false)
.Select<RawMaterialOutput>()
.ToListAsync();
var UpdateableList = new List<BomStockInquiryUpdateable>();
var UpdateableOutput = new List<BomStockInquiryOutput>();
var tasks = data.Select(async item =>
int batchSize = 20; // 每批的大小
int totalCount = data.ToList().Count;
for (int i = 0; i < totalCount; i += batchSize)
{
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 batch = data.Skip(i).Take(batchSize); // 分批获取数据
var apiOutput = await _sapService.SapEcnQueryApi(SapEcnQueryData);
var dateUpdated = DateTime.Now;
if (apiOutput.Code == "S")
// 处理当前批次的数据
var tasks = batch.Select(async item =>
{
var UpdateableData = new BomStockInquiryUpdateable
var code = item._System_objNBS;
var name = item._System_objDescription;
var objectid = 112;
var id = item.idRecord;
var SapEcnQueryData = new SapEcnQueryInput
{
Objectid = objectid,
Code = apiOutput.Code,
RecordGuid = id.ToString(),//在这个方法中使用RecordGuid字段作为id字段
Bdmng = apiOutput.Bdmng,
Labst = apiOutput.Labst,
ZwqslPo = apiOutput.ZwqslPo,
ZwqslPr = apiOutput.ZwqslPr,
DateUpdated = dateUpdated
Reqkeyid = "",
Businessid = "",
Messageid = "",
Sndprn = "PLM",
Rcvprn = "SAP",
Requser = Requser,
Note1 = "",
Note2 = "",
Note3 = "",
Sign = "I",
Option = "EQ",
Low = code,
High = ""
};
UpdateableList.Add(UpdateableData);
}
else
{
var UpdateableData = new BomStockInquiryUpdateable
{
Code = "",
RecordGuid = "",
Bdmng = "",
Labst = "",
ZwqslPo = "",
ZwqslPr = "",
DateUpdated = dateUpdated
};
UpdateableList.Add(UpdateableData);
}
if (apiOutput.Code == "S")
{
return new BomStockInquiryOutput
{
materialCode = code,
materialName = name,
Labst = apiOutput.Labst,
Bdmng = apiOutput.Bdmng,
ZwqslPr = apiOutput.ZwqslPr,
ZwqslPo = apiOutput.ZwqslPo,
DateUpdated = dateUpdated,
State = "查询成功"
};
}
else
{
return new BomStockInquiryOutput
{
materialCode = code,
materialName = name,
State = "SAP未查询库存信息"
};
}
});
var bomStockInquiryOutput = await Task.WhenAll(tasks);
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);
}
else
{
var UpdateableData = new BomStockInquiryUpdateable
{
Code = "",
RecordGuid = "",
Bdmng = "",
Labst = "",
ZwqslPo = "",
ZwqslPr = "",
DateUpdated = dateUpdated
};
UpdateableList.Add(UpdateableData);
}
if (apiOutput.Code == "S")
{
return new BomStockInquiryOutput
{
materialCode = code,
materialName = name,
Labst = apiOutput.Labst,
Bdmng = apiOutput.Bdmng,
ZwqslPr = apiOutput.ZwqslPr,
ZwqslPo = apiOutput.ZwqslPo,
DateUpdated = dateUpdated,
State = "查询成功"
};
}
else
{
return new BomStockInquiryOutput
{
materialCode = code,
materialName = name,
State = "SAP未查询到库存信息"
};
}
}).ToList();
var bomStockInquiryOutput = await Task.WhenAll(tasks); // 等待当前批次的所有任务完成
// 合并当前批次的结果
UpdateableOutput.AddRange(bomStockInquiryOutput);
}
// var tasks = data.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);
// }
// else
// {
// var UpdateableData = new BomStockInquiryUpdateable
// {
// Code = "",
// RecordGuid = "",
// Bdmng = "",
// Labst = "",
// ZwqslPo = "",
// ZwqslPr = "",
// DateUpdated = dateUpdated
// };
// UpdateableList.Add(UpdateableData);
// }
// if (apiOutput.Code == "S")
// {
// return new BomStockInquiryOutput
// {
// materialCode = code,
// materialName = name,
// Labst = apiOutput.Labst,
// Bdmng = apiOutput.Bdmng,
// ZwqslPr = apiOutput.ZwqslPr,
// ZwqslPo = apiOutput.ZwqslPo,
// DateUpdated = dateUpdated,
// State = "查询成功"
// };
// }
// else
// {
// return new BomStockInquiryOutput
// {
// materialCode = code,
// materialName = name,
// State = "SAP未查询到库存信息"
// };
// }
//});
//var bomStockInquiryOutput = await Task.WhenAll(tasks);
foreach (var item in UpdateableList)
{
var dateUpdated = DateTime.Now;
await _obj112Rep.AsUpdateable().SetColumns(it => new Obj112
db.CopyNew().Updateable<Obj112>().SetColumns(it => new Obj112
{
fld006750 = item.Bdmng,
fld006751 = item.Labst,
@ -368,11 +570,349 @@ public class StockInquiryService : IDynamicApiController, ITransient
fld006753 = item.ZwqslPr,
fld006755 = dateUpdated
})
.Where(it => it.idRecord == Convert.ToInt32(item.RecordGuid))//在这个方法中使用RecordGuid字段作为id字段
.ExecuteCommandAsync();
.Where(it => it.idRecord == Convert.ToInt32(item.RecordGuid))//在这个方法中使用RecordGuid字段作为id字段
.ExecuteCommand();
}
return bomStockInquiryOutput.ToList();
return UpdateableOutput.ToList();
}
/// <summary>
/// 产品管理库-价格查询
/// </summary>
/// <param name="materialCode"></param>
/// <returns></returns>
[ApiDescriptionSettings(Name = "GetPriceInquiry", Description = "产品管理库-价格查询", Order = 1000), HttpGet]
[DisplayName("产品管理库-价格查询")]
[AllowAnonymous]
public async Task<SapPriceQueryOutput> GetPriceInquiry(string materialCode)
{
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
var SapPriceQueryData = new SapPriceQueryInput
{
Reqkeyid = "",
Businessid = "",
Messageid = "",
Sndprn = "PLM",
Rcvprn = "SAP",
Requser = Requser,
Note1 = "",
Note2 = "",
Note3 = "",
Sign = "I",
Option = "EQ",
Low = materialCode,
High = ""
};
var apiOutput = await _sapService.SapPriceQueryApi(SapPriceQueryData);
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());
priceValue = Verpr == 0 ? "9999.99" : Verpr.ToString();
}
else {
priceValue = "9999.99";
}
var data = await _obj137Rep.AsQueryable().Where(x => x._System_objNBS == materialCode && x.deleted == false).OrderByDescending(x => x.idRecord).FirstAsync();
if (data != null)
{
apiOutput.DateUpdated = DateTime.Now;
await _obj137Rep.AsUpdateable().SetColumns(it => new Obj137
{
fld005625 = priceValue,
fld005626 = apiOutput.DateUpdated
})
.Where(it => it.idRecord == data.idRecord)
.ExecuteCommandAsync();
apiOutput.Verpr = priceValue;
return apiOutput;
}
var RawMaterialData = await _obj112Rep.AsQueryable().Where(x => x._System_objNBS == materialCode && x.deleted == false).FirstAsync();
if (RawMaterialData != null)
{
apiOutput.DateUpdated = DateTime.Now;
await _obj112Rep.AsUpdateable().SetColumns(it => new Obj112
{
fld006754 = priceValue,
fld006756 = apiOutput.DateUpdated
})
.Where(it => it.idRecord == RawMaterialData.idRecord)
.ExecuteCommandAsync();
apiOutput.Verpr = priceValue;
return apiOutput;
}
}
return apiOutput;
}
/// <summary>
/// 产品管理库-Bom成本查询
/// </summary>
/// <param name="materialCode"></param>
/// <returns></returns>
[ApiDescriptionSettings(Name = "GetBomPriceInquiry", Description = "产品管理库-Bom成本查询", Order = 1000), HttpGet]
[DisplayName("产品管理库-Bom成本查询")]
[AllowAnonymous]
public async Task<List<BomPriceInquiryOutput>> GetBomPriceInquiry(string materialCode)
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
var materialData = await db.CopyNew().Queryable<Obj137>()
.Where(x => x._System_objNBS == materialCode && x.deleted == false)
.OrderByDescending(x => x.idRecord)
.FirstAsync();
var bomList = await db.CopyNew().Queryable<ConfigurationData>()
.Where(x => x.ParentGuid == materialData.RecordGuid && x.isDeleted == false
&& x.ParentVersion == materialData.VersionIndex
&& (x.fld005577 != "不包含" || x.fld005577 == null)
&& x.isSuppressed == false && x.inContext == false)
.ToListAsync();
var UpdateableList = new List<BomPriceInquiryUpdateable>();
var UpdateableOutput = new List<BomPriceInquiryOutput>();
int batchSize = 20; // 每批的大小
int totalCount = bomList.ToList().Count;
for (int i = 0; i < totalCount; i += batchSize)
{
var batch = bomList.Skip(i).Take(batchSize); // 分批获取数据
// 处理当前批次的数据
var tasks = batch.Select(async item =>
{
var code = item.PartNumber;
var name = item.Description;
var objectid = item.ChildObjID;
var childGuid = item.ChildGuid;
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";
}
var UpdateableData = new BomPriceInquiryUpdateable
{
Objectid = objectid,
Code = apiOutput.Code,
RecordGuid = childGuid,
Verpr = priceValue,
DateUpdated = dateUpdated
};
//UpdateableList.Add(UpdateableData);
_dataValidationService.ModifyPriceInformation(UpdateableData.RecordGuid, UpdateableData.Code, UpdateableData.Objectid, UpdateableData.Verpr, UpdateableData.DateUpdated);
return new BomPriceInquiryOutput
{
materialCode = code,
materialName = name,
Verpr = priceValue,
DateUpdated = dateUpdated,
State = "查询成功"
};
}
else
{
var UpdateableData = new BomPriceInquiryUpdateable
{
Code = "",
RecordGuid = "",
Verpr = "",
DateUpdated = dateUpdated
};
//UpdateableList.Add(UpdateableData);
_dataValidationService.ModifyPriceInformation(UpdateableData.RecordGuid, UpdateableData.Code, UpdateableData.Objectid, UpdateableData.Verpr, UpdateableData.DateUpdated);
return new BomPriceInquiryOutput
{
materialCode = code,
materialName = name,
State = "查询失败"
};
}
//if (apiOutput.Code == "S")
//{
// return new BomPriceInquiryOutput
// {
// materialCode = code,
// materialName = name,
// Verpr = apiOutput.Verpr,
// DateUpdated = dateUpdated,
// State = "查询成功"
// };
//}
//else
//{
// return new BomPriceInquiryOutput
// {
// materialCode = code,
// materialName = name,
// State = "SAP未查询到价格信息"
// };
//}
}).ToList();
var bomStockInquiryOutput = await Task.WhenAll(tasks); // 等待当前批次的所有任务完成
// 合并当前批次的结果
UpdateableOutput.AddRange(bomStockInquiryOutput);
}
return UpdateableOutput.ToList();
}
/// <summary>
/// 原材料成本查询
/// </summary>
/// <returns></returns>
[ApiDescriptionSettings(Name = "RawMaterialPriceInquiry", Description = "原材料成本查询", Order = 1000), HttpGet]
[DisplayName("原材料成本查询")]
[AllowAnonymous]
public async Task<List<BomPriceInquiryOutput>> RawMaterialPriceInquiry()
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
var data = await db.CopyNew().Queryable<Obj112>()
.Where(x => x.deleted == false)
.Select<RawMaterialOutput>()
.ToListAsync();
var UpdateableList = new List<BomPriceInquiryUpdateable>();
var UpdateableOutput = new List<BomPriceInquiryOutput>();
int batchSize = 20; // 每批的大小
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 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<Obj112>().SetColumns(it => new Obj112
{
fld006754 = priceValue,
fld006755 = 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<Obj112>().SetColumns(it => new Obj112
{
fld006754 = "",
fld006755 = 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);
}
return UpdateableOutput.ToList();
}
}

View File

@ -79,7 +79,42 @@ public class SapEcnQueryOutput
/// 更新日期
/// </summary>
public DateTime DateUpdated { get; set; }
}
public class SapPriceQueryOutput
{
/// <summary>
/// sap入参
/// </summary>
public string Parameter { get; set; }
/// <summary>
/// 消息类型
/// </summary>
public string Code { get; set; }
/// <summary>
/// 物料编码
/// </summary>
public string Matnr { get; set; }
/// <summary>
/// 工厂
/// </summary>
public string Bwkey { get; set; }
/// <summary>
/// 价格
/// </summary>
public string Verpr { get; set; }
/// <summary>
/// sap出参
/// </summary>
public string Result { get; set; }
/// <summary>
/// 更新日期
/// </summary>
public DateTime DateUpdated { get; set; }
}