// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。 // // 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。 // // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! using Admin.NET.Core; using Admin.NET.Core.Service; using Furion.DependencyInjection; using Furion.DynamicApiController; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using SqlSugar; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using Vistar.Application.Common; using Vistar.Application.Const; using Vistar.Application.Entity; using Vistar.Application.SapService.Dto; using Vistar.Application.Service.StockInquiry.Dto; using Vistar.Application.Util; namespace Vistar.Application.Service.StockInquiry; [ApiDescriptionSettings(ApplicationConst.GroupName, Name = "StockInquiry", Order = 100)] public class StockInquiryService : IDynamicApiController, ITransient { public Common.DataValidationService _dataValidationService; public SqlSugarRepository _obj137Rep; public SqlSugarRepository _obj112Rep; public SqlSugarRepository _configurationDataRep; public SolidWorksManageService.SolidWorksManageService _solidWorksManageService; private readonly SysConfigService _sysConfigService; public SapService.SapService _sapService; public StockInquiryService ( DataValidationService dataValidationService, SqlSugarRepository obj137Rep, SqlSugarRepository obj112Rep, SqlSugarRepository configurationDataRep, SolidWorksManageService.SolidWorksManageService solidWorksManageService, SysConfigService sysConfigService, SapService.SapService sapService ) { _obj137Rep = obj137Rep; _obj112Rep = obj112Rep; _configurationDataRep = configurationDataRep; _solidWorksManageService = solidWorksManageService; _sysConfigService = sysConfigService; _sapService = sapService; _dataValidationService = dataValidationService; } /// /// 产品管理库-库存查询 /// /// /// [ApiDescriptionSettings(Name = "GetProductInventory", Description = "产品管理库-库存查询", Order = 1000), HttpGet] [DisplayName("产品管理库-库存查询")] [AllowAnonymous] public async Task GetProductInventory(string materialCode) { var Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName); var SapEcnQueryData = new SapEcnQueryInput { Reqkeyid = "", Businessid = "", Messageid = "", Sndprn = "PLM", Rcvprn = "SAP", Requser = Requser, Note1 = "", Note2 = "", Note3 = "", Sign = "I", Option = "EQ", Low = materialCode, High = "" }; var apiOutput = await _sapService.SapEcnQueryApi(SapEcnQueryData); if (apiOutput.Code == "S") { 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 { fld006530 = apiOutput.Bdmng, fld005623 = apiOutput.Labst, fld006531 = apiOutput.ZwqslPo, fld006532 = apiOutput.ZwqslPr, fld005624 = apiOutput.DateUpdated }) .Where(it => it.idRecord == data.idRecord) .ExecuteCommandAsync(); 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 { fld006750 = apiOutput.Bdmng, fld006751 = apiOutput.Labst, fld006752 = apiOutput.ZwqslPo, fld006753 = apiOutput.ZwqslPr, fld006755 = apiOutput.DateUpdated }) .Where(it => it.idRecord == RawMaterialData.idRecord) .ExecuteCommandAsync(); return apiOutput; } } return apiOutput; } /// /// 产品管理库-Bom库存查询 /// /// /// [ApiDescriptionSettings(Name = "GetBomProductInventory", Description = "产品管理库-Bom库存查询", Order = 1000), HttpGet] [DisplayName("产品管理库-库存查询")] [AllowAnonymous] public async Task> GetBomProductInventory(string materialCode) { var Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName); var materialData = await _obj137Rep.AsQueryable() .Where(x => x._System_objNBS == materialCode && x.deleted == false) .OrderByDescending(x => x.idRecord) .FirstAsync(); var bomList = await _configurationDataRep.AsQueryable() .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(); 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 bomStockInquiryOutput.ToList(); } /// /// 获取原材料 /// /// /// [ApiDescriptionSettings(Name = "GetRawMaterial", Description = "获取原材料", Order = 1000), HttpPost] [DisplayName("获取原材料")] [AllowAnonymous] public async Task> GetRawMaterial(RawMaterialInput input) { var data = await _obj112Rep.AsQueryable() .Where(x => x.deleted == false) .WhereIF(!string.IsNullOrWhiteSpace(input.materialCode), u => u._System_objNBS.Contains(input.materialCode.Trim())) .Select() .ToListAsync(); return data; } /// /// 原材料库存查询 /// /// [ApiDescriptionSettings(Name = "RawMaterialStockInquiry", Description = "原材料库存查询", Order = 1000), HttpGet] [DisplayName("原材料库存查询")] [AllowAnonymous] public async Task> RawMaterialStockInquiry() { var Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName); var data = await _obj112Rep.AsQueryable() .Where(x => x.deleted == false) .Select() .ToListAsync(); var UpdateableList = new List(); 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(), 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 { fld006750 = item.Bdmng, fld006751 = item.Labst, fld006752 = item.ZwqslPo, fld006753 = item.ZwqslPr, fld006755 = dateUpdated }) .Where(it => it.idRecord == Convert.ToInt32(item.RecordGuid)) .ExecuteCommandAsync(); } return bomStockInquiryOutput.ToList(); } }