😎新增pdm查询价格接口,PDM库存查询接口改为分批查询,新增价格信息修改数据库方法,新增处理价格方法

This commit is contained in:
bairubing 2025-02-14 16:49:37 +08:00
parent 9202fa9e56
commit eca2138c6a
5 changed files with 942 additions and 189 deletions

View File

@ -7,6 +7,7 @@
using Admin.NET.Core; using Admin.NET.Core;
using Admin.NET.Core.Service; using Admin.NET.Core.Service;
using DocumentFormat.OpenXml.Bibliography; using DocumentFormat.OpenXml.Bibliography;
using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Drawing.Spreadsheet; using DocumentFormat.OpenXml.Drawing.Spreadsheet;
using Furion.DependencyInjection; using Furion.DependencyInjection;
using Furion.DynamicApiController; using Furion.DynamicApiController;
@ -27,6 +28,7 @@ using Vistar.Application.Entity;
using Vistar.Application.SapService.Dto; using Vistar.Application.SapService.Dto;
using Vistar.Application.Util; using Vistar.Application.Util;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.CgibinAccountGetAccountBasicInfoResponse.Types; using static SKIT.FlurlHttpClient.Wechat.Api.Models.CgibinAccountGetAccountBasicInfoResponse.Types;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.ScanProductAddV2Request.Types.Product.Types;
namespace Vistar.Application.Common; namespace Vistar.Application.Common;
public class DataValidationService : IDynamicApiController, ITransient public class DataValidationService : IDynamicApiController, ITransient
@ -80,10 +82,10 @@ public class DataValidationService : IDynamicApiController, ITransient
string verification = "不存在"; 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(); 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 = "存在"; verification = "存在";
} }
@ -194,7 +196,7 @@ public class DataValidationService : IDynamicApiController, ITransient
{ {
case 110: case 110:
data = await db.CopyNew().Queryable<Obj110>() 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(); .FirstAsync();
break; break;
case 109: case 109:
@ -395,32 +397,35 @@ public class DataValidationService : IDynamicApiController, ITransient
/// <returns></returns> /// <returns></returns>
public async Task<string> ModifyInventoryInformation(string recordGuid, string code, long objectid, string Bdmng, string Labst, string ZwqslPo, string ZwqslPr, DateTime dateUpdated) 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 (code == "S")
{ {
if (objectid == 137) 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) if (data != null)
{ {
await _obj137Rep.AsUpdateable().SetColumns(it => new Obj137 db.CopyNew().Updateable<Obj137>()
{ .SetColumns(it => new Obj137
fld006530 = Bdmng, {
fld005623 = Labst, fld006530 = Bdmng,
fld006531 = ZwqslPo, fld005623 = Labst,
fld006532 = ZwqslPr, fld006531 = ZwqslPo,
fld005624 = dateUpdated fld006532 = ZwqslPr,
}) fld005624 = dateUpdated
})
.Where(it => it.idRecord == data.idRecord) .Where(it => it.idRecord == data.idRecord)
.ExecuteCommandAsync(); .ExecuteCommand();
} }
} }
if (objectid == 112) 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) if (data != null)
{ {
await _obj112Rep.AsUpdateable().SetColumns(it => new Obj112 db.CopyNew().Updateable<Obj112>().SetColumns(it => new Obj112
{ {
fld006750 = Bdmng, fld006750 = Bdmng,
fld006751 = Labst, fld006751 = Labst,
@ -429,7 +434,7 @@ public class DataValidationService : IDynamicApiController, ITransient
fld006755 = dateUpdated fld006755 = dateUpdated
}) })
.Where(it => it.idRecord == data.idRecord) .Where(it => it.idRecord == data.idRecord)
.ExecuteCommandAsync(); .ExecuteCommand();
} }
} }
} }
@ -437,10 +442,10 @@ public class DataValidationService : IDynamicApiController, ITransient
{ {
if (objectid == 137) 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) if (data != null)
{ {
await _obj137Rep.AsUpdateable().SetColumns(it => new Obj137 db.CopyNew().Updateable<Obj137>().SetColumns(it => new Obj137
{ {
fld006530 = "", fld006530 = "",
fld005623 = "", fld005623 = "",
@ -449,31 +454,114 @@ public class DataValidationService : IDynamicApiController, ITransient
fld005624 = dateUpdated fld005624 = dateUpdated
}) })
.Where(it => it.idRecord == data.idRecord) .Where(it => it.idRecord == data.idRecord)
.ExecuteCommandAsync(); .ExecuteCommand();
} }
} }
if (objectid == 112) 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) if (data != null)
{ {
await _obj112Rep.AsUpdateable().SetColumns(it => new Obj112 db.CopyNew().Updateable<Obj112>()
{ .SetColumns(it => new Obj112
fld006750 = "", {
fld006751 = "", fld006750 = "",
fld006752 = "", fld006751 = "",
fld006753 = "", fld006752 = "",
fld006755 = dateUpdated fld006753 = "",
}) fld006755 = dateUpdated
})
.Where(it => it.idRecord == data.idRecord) .Where(it => it.idRecord == data.idRecord)
.ExecuteCommandAsync(); .ExecuteCommand();
} }
} }
} }
return "修改成功"; 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> /// <summary>
@ -511,6 +599,42 @@ public class DataValidationService : IDynamicApiController, ITransient
return status; 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> ///// <summary>
///// 验证是否存在bom和工艺路线 ///// 验证是否存在bom和工艺路线

View File

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

View File

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

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;
using Admin.NET.Core.Service; using Admin.NET.Core.Service;
using DocumentFormat.OpenXml.VariantTypes;
using Furion.DependencyInjection; using Furion.DependencyInjection;
using Furion.DynamicApiController; using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using SqlSugar; using SqlSugar;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data.OscarClient;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -37,6 +40,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
public SolidWorksManageService.SolidWorksManageService _solidWorksManageService; public SolidWorksManageService.SolidWorksManageService _solidWorksManageService;
private readonly SysConfigService _sysConfigService; private readonly SysConfigService _sysConfigService;
public SapService.SapService _sapService; public SapService.SapService _sapService;
private readonly IServiceScopeFactory _scopeFactory;
public StockInquiryService public StockInquiryService
( (
DataValidationService dataValidationService, DataValidationService dataValidationService,
@ -45,7 +49,8 @@ public class StockInquiryService : IDynamicApiController, ITransient
SqlSugarRepository<ConfigurationData> configurationDataRep, SqlSugarRepository<ConfigurationData> configurationDataRep,
SolidWorksManageService.SolidWorksManageService solidWorksManageService, SolidWorksManageService.SolidWorksManageService solidWorksManageService,
SysConfigService sysConfigService, SysConfigService sysConfigService,
SapService.SapService sapService SapService.SapService sapService,
IServiceScopeFactory scopeFactory
) )
{ {
_obj137Rep = obj137Rep; _obj137Rep = obj137Rep;
@ -55,6 +60,7 @@ public class StockInquiryService : IDynamicApiController, ITransient
_sysConfigService = sysConfigService; _sysConfigService = sysConfigService;
_sapService = sapService; _sapService = sapService;
_dataValidationService = dataValidationService; _dataValidationService = dataValidationService;
_scopeFactory = scopeFactory;
} }
/// <summary> /// <summary>
@ -137,14 +143,17 @@ public class StockInquiryService : IDynamicApiController, ITransient
[AllowAnonymous] [AllowAnonymous]
public async Task<List<BomStockInquiryOutput>> GetBomProductInventory(string materialCode) 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 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) .Where(x => x._System_objNBS == materialCode && x.deleted == false)
.OrderByDescending(x => x.idRecord) .OrderByDescending(x => x.idRecord)
.FirstAsync(); .FirstAsync();
var bomList = await _configurationDataRep.AsQueryable() var bomList = await db.CopyNew().Queryable<ConfigurationData>()
.Where(x => x.ParentGuid == materialData.RecordGuid && x.isDeleted == false .Where(x => x.ParentGuid == materialData.RecordGuid && x.isDeleted == false
&& x.ParentVersion == materialData.VersionIndex && x.ParentVersion == materialData.VersionIndex
&& (x.fld005577 != "不包含" || x.fld005577 == null) && (x.fld005577 != "不包含" || x.fld005577 == null)
@ -152,95 +161,191 @@ public class StockInquiryService : IDynamicApiController, ITransient
.ToListAsync(); .ToListAsync();
var UpdateableList = new List<BomStockInquiryUpdateable>(); 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 batch = bomList.Skip(i).Take(batchSize); // 分批获取数据
var name = item.Description;
var objectid = item.ChildObjID;
var childGuid = item.ChildGuid;
var SapEcnQueryData = new SapEcnQueryInput // 处理当前批次的数据
var tasks = batch.Select(async item =>
{ {
Reqkeyid = "", var code = item.PartNumber;
Businessid = "", var name = item.Description;
Messageid = "", var objectid = item.ChildObjID;
Sndprn = "PLM", var childGuid = item.ChildGuid;
Rcvprn = "SAP",
Requser = Requser,
Note1 = "",
Note2 = "",
Note3 = "",
Sign = "I",
Option = "EQ",
Low = code,
High = ""
};
var apiOutput = await _sapService.SapEcnQueryApi(SapEcnQueryData); var SapEcnQueryData = new SapEcnQueryInput
var dateUpdated = DateTime.Now;
if (apiOutput.Code == "S")
{
var UpdateableData = new BomStockInquiryUpdateable
{ {
Objectid = objectid, Reqkeyid = "",
Code = apiOutput.Code, Businessid = "",
RecordGuid = childGuid, Messageid = "",
Bdmng = apiOutput.Bdmng, Sndprn = "PLM",
Labst = apiOutput.Labst, Rcvprn = "SAP",
ZwqslPo = apiOutput.ZwqslPo, Requser = Requser,
ZwqslPr = apiOutput.ZwqslPr, Note1 = "",
DateUpdated = dateUpdated 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) // 合并当前批次的结果
{ UpdateableOutput.AddRange(bomStockInquiryOutput);
await _dataValidationService.ModifyInventoryInformation(item.RecordGuid, item.Code, item.Objectid, item.Bdmng, item.Labst, item.ZwqslPo, item.ZwqslPr, item.DateUpdated);
} }
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> /// <summary>
@ -270,97 +375,194 @@ public class StockInquiryService : IDynamicApiController, ITransient
[AllowAnonymous] [AllowAnonymous]
public async Task<List<BomStockInquiryOutput>> RawMaterialStockInquiry() 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 Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
var data = await _obj112Rep.AsQueryable() var data = await db.CopyNew().Queryable<Obj112>()
.Where(x => x.deleted == false) .Where(x => x.deleted == false)
.Select<RawMaterialOutput>() .Select<RawMaterialOutput>()
.ToListAsync(); .ToListAsync();
var UpdateableList = new List<BomStockInquiryUpdateable>(); 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 batch = data.Skip(i).Take(batchSize); // 分批获取数据
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; var tasks = batch.Select(async item =>
if (apiOutput.Code == "S")
{ {
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, Reqkeyid = "",
Code = apiOutput.Code, Businessid = "",
RecordGuid = id.ToString(),//在这个方法中使用RecordGuid字段作为id字段 Messageid = "",
Bdmng = apiOutput.Bdmng, Sndprn = "PLM",
Labst = apiOutput.Labst, Rcvprn = "SAP",
ZwqslPo = apiOutput.ZwqslPo, Requser = Requser,
ZwqslPr = apiOutput.ZwqslPr, Note1 = "",
DateUpdated = dateUpdated 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) foreach (var item in UpdateableList)
{ {
var dateUpdated = DateTime.Now; var dateUpdated = DateTime.Now;
await _obj112Rep.AsUpdateable().SetColumns(it => new Obj112 db.CopyNew().Updateable<Obj112>().SetColumns(it => new Obj112
{ {
fld006750 = item.Bdmng, fld006750 = item.Bdmng,
fld006751 = item.Labst, fld006751 = item.Labst,
@ -368,11 +570,349 @@ public class StockInquiryService : IDynamicApiController, ITransient
fld006753 = item.ZwqslPr, fld006753 = item.ZwqslPr,
fld006755 = dateUpdated fld006755 = dateUpdated
}) })
.Where(it => it.idRecord == Convert.ToInt32(item.RecordGuid))//在这个方法中使用RecordGuid字段作为id字段 .Where(it => it.idRecord == Convert.ToInt32(item.RecordGuid))//在这个方法中使用RecordGuid字段作为id字段
.ExecuteCommandAsync(); .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();
} }
} }