2024-09-26 11:23:07 +08:00
|
|
|
|
// 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;
|
2025-01-15 15:12:26 +08:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using SqlSugar;
|
2024-09-26 11:23:07 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Vistar.Application.Const;
|
|
|
|
|
using Vistar.Application.Entity;
|
|
|
|
|
using Vistar.Application.SapService.Dto;
|
|
|
|
|
using Vistar.Application.Service.ProductionMaterialsManagement.Dto;
|
|
|
|
|
using Vistar.Application.Util;
|
|
|
|
|
|
|
|
|
|
namespace Vistar.Application.Service.ProductionMaterialsManagement;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生产物料管理服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings(ApplicationConst.GroupName, Name = "ProductionMaterialsManagement", Order = 100)]
|
|
|
|
|
public class ProductionMaterialsManagementService : IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<Obj112> _obj112Rep;
|
|
|
|
|
private readonly SysConfigService _sysConfigService;
|
|
|
|
|
public SapService.SapService _sapService;
|
|
|
|
|
private readonly SqlSugarRepository<Configurations> _configurationsRep;
|
|
|
|
|
private readonly SqlSugarRepository<ConfigurationData> _configurationDataRep;
|
2025-01-15 15:12:26 +08:00
|
|
|
|
private readonly IServiceScopeFactory _scopeFactory;
|
2024-09-26 11:23:07 +08:00
|
|
|
|
|
|
|
|
|
public ProductionMaterialsManagementService(
|
|
|
|
|
SqlSugarRepository<Obj112> obj112Rep,
|
|
|
|
|
SysConfigService sysConfigService,
|
|
|
|
|
SapService.SapService sapService,
|
|
|
|
|
SqlSugarRepository<Configurations> configurationsRep,
|
2025-01-15 15:12:26 +08:00
|
|
|
|
SqlSugarRepository<ConfigurationData> configurationDataRep,
|
|
|
|
|
IServiceScopeFactory scopeFactory
|
2024-09-26 11:23:07 +08:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
_obj112Rep = obj112Rep;
|
|
|
|
|
_sysConfigService = sysConfigService;
|
|
|
|
|
_sapService = sapService;
|
|
|
|
|
_configurationsRep = configurationsRep;
|
|
|
|
|
_configurationDataRep = configurationDataRep;
|
2025-01-15 15:12:26 +08:00
|
|
|
|
_scopeFactory = scopeFactory;
|
2024-09-26 11:23:07 +08:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页查询生产物料管理
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "page", Description = "分页查询生产物料管理", Order = 1000), HttpPost]
|
|
|
|
|
[DisplayName("分页查询生产物料管理")]
|
|
|
|
|
public async Task<SqlSugarPagedList<ProductionMaterialsManagementOutput>> Page(PageProductionMaterialsManagementInput input)
|
|
|
|
|
{
|
|
|
|
|
var query = await _obj112Rep.AsQueryable()
|
2024-10-28 10:09:12 +08:00
|
|
|
|
.Where(x => (x.CheckedStatus == 7 || x.CheckedStatus == 8) && x.deleted == false && x.IsLatestVersion == true && x.fld004973 == "发布")
|
2024-09-26 11:23:07 +08:00
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input._System_objNBS), u => u._System_objNBS.Contains(input._System_objNBS.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.fld004598), u => u.fld004598.Contains(input.fld004598.Trim()))
|
|
|
|
|
.WhereIF(input.fld004609Range != null && input.fld004609Range.Length == 2, u => u.fld004609 >= input.fld004609Range[0] && u.fld004609 <= input.fld004609Range[1])
|
|
|
|
|
.Select<ProductionMaterialsManagementOutput>()
|
|
|
|
|
.ToPagedListAsync(input.Page, input.PageSize);
|
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生产物料管理-同步到 SAP
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "syncToSAP"), HttpPost]
|
|
|
|
|
[DisplayName("生产物料管理-同步到 SAP")]
|
|
|
|
|
public async Task<SapOutput> SyncToSAP(ProductionMaterialsManagementInput input)
|
|
|
|
|
{
|
|
|
|
|
const string lengthError = "项目描述长度大于40,请检查!";
|
|
|
|
|
|
|
|
|
|
// 验证物料描述长度
|
|
|
|
|
if (input.fld004598.Length > 40)
|
|
|
|
|
{
|
|
|
|
|
await _obj112Rep.AsUpdateable()
|
|
|
|
|
.SetColumns(it => new Obj112
|
|
|
|
|
{
|
|
|
|
|
fld004606 = DateTime.Now,
|
|
|
|
|
fld004607 = "N",
|
|
|
|
|
fld004605 = lengthError,
|
|
|
|
|
fld004604 = "失败"
|
|
|
|
|
})
|
|
|
|
|
.Where(it => it.idRecord == input.idRecord)
|
|
|
|
|
.ExecuteCommandAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return new SapOutput
|
|
|
|
|
{
|
|
|
|
|
code = "失败",
|
|
|
|
|
msg = lengthError,
|
|
|
|
|
result = lengthError
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
|
|
|
|
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
|
|
|
|
|
|
|
|
|
var sapMaterialInput = new SapMaterialInput()
|
|
|
|
|
{
|
|
|
|
|
Reqkeyid = "",
|
|
|
|
|
Businessid = "",
|
|
|
|
|
Messageid = "",
|
|
|
|
|
Sndprn = "PLM",
|
|
|
|
|
Rcvprn = "SAP",
|
|
|
|
|
Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
|
|
|
|
Note1 = "",
|
|
|
|
|
Note2 = "",
|
|
|
|
|
Note3 = "",
|
|
|
|
|
Zwbid = millisecondTimestamp,
|
|
|
|
|
Matnr = input._System_objNBS,
|
|
|
|
|
Mbrsh = input.fld004595,
|
|
|
|
|
Mtart = input.fld004596,
|
|
|
|
|
Maktx = input.fld004598,
|
|
|
|
|
Meins = input.fld004594,
|
|
|
|
|
Matkl = input.fld004599,
|
2024-10-29 10:07:05 +08:00
|
|
|
|
Bismt = input._System_ObjDescription,
|
|
|
|
|
Groes = input.fld005323,
|
2024-09-26 11:23:07 +08:00
|
|
|
|
Normt = input.fld004592,
|
|
|
|
|
Ferth = input.fld004593,
|
|
|
|
|
Zeinr = input.fld004903,
|
|
|
|
|
Mstae = input.fld004696,
|
|
|
|
|
Raube = input.fld004904,
|
|
|
|
|
Mhdrz = input.fld004905.ToString(),
|
|
|
|
|
Mhdhb = input.fld004907.ToString(),
|
|
|
|
|
Werks = input.fld004597,
|
|
|
|
|
Beskz = input.fld004600,
|
|
|
|
|
Sobsl = input.fld004601,
|
|
|
|
|
Schgt = input.fld004602,
|
|
|
|
|
Rgekz = input.fld004603,
|
|
|
|
|
Zbom = input.fld004695
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var apiOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
|
|
|
|
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
|
|
|
|
var msg = apiOutput.msg;
|
|
|
|
|
if (apiOutput.msg == "")
|
|
|
|
|
{
|
|
|
|
|
msg = "同步成功";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await _obj112Rep.AsUpdateable()
|
|
|
|
|
.SetColumns(it => new Obj112
|
|
|
|
|
{
|
|
|
|
|
fld004606 = DateTime.Now,
|
|
|
|
|
fld004604 = codeVal,
|
|
|
|
|
fld004607 = "N",
|
|
|
|
|
fld004605 = msg
|
|
|
|
|
})
|
|
|
|
|
.Where(it => it.idRecord == input.idRecord)
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
var output = new SapOutput()
|
|
|
|
|
{
|
|
|
|
|
parameter = apiOutput.parameter,
|
|
|
|
|
code = codeVal,
|
|
|
|
|
msg = msg,
|
|
|
|
|
result = apiOutput.result
|
|
|
|
|
};
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生产物料管理-批量同步到SAP
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "BatchSyncToSAP"), HttpPost]
|
|
|
|
|
[DisplayName("生产物料管理-批量同步到SAP")]
|
|
|
|
|
public async Task<List<SapOutput>> BatchSyncToSAP(List<ProductionMaterialsManagementInput> input)
|
|
|
|
|
{
|
2025-01-15 15:12:26 +08:00
|
|
|
|
using var serviceScope = _scopeFactory.CreateScope();
|
|
|
|
|
var sysEnumService = serviceScope.ServiceProvider.GetRequiredService<SysEnumService>();
|
|
|
|
|
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
|
|
|
|
|
|
2024-09-26 11:23:07 +08:00
|
|
|
|
const string lengthError = "物料描述长度大于40,请检查!";
|
2024-10-30 15:59:19 +08:00
|
|
|
|
const string synchronized = "该项目编号已同步或已停用!";
|
2024-09-26 11:23:07 +08:00
|
|
|
|
var SapOutputList = new List<SapOutput>();
|
|
|
|
|
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
|
2025-01-15 15:12:26 +08:00
|
|
|
|
|
|
|
|
|
var tasks = input.Select(async item =>
|
2024-09-26 11:23:07 +08:00
|
|
|
|
{
|
2025-01-15 15:12:26 +08:00
|
|
|
|
if (item.fld004598.Length > 40)
|
2024-09-26 11:23:07 +08:00
|
|
|
|
{
|
2025-01-15 15:12:26 +08:00
|
|
|
|
db.CopyNew().Updateable<Obj112>()
|
2024-09-26 11:23:07 +08:00
|
|
|
|
.SetColumns(it => new Obj112
|
|
|
|
|
{
|
|
|
|
|
fld004606 = DateTime.Now,
|
|
|
|
|
fld004607 = "N",
|
|
|
|
|
fld004605 = lengthError,
|
|
|
|
|
fld004604 = "失败"
|
|
|
|
|
})
|
2025-01-15 15:12:26 +08:00
|
|
|
|
.Where(it => it.idRecord == item.idRecord)
|
|
|
|
|
.ExecuteCommand();
|
2024-09-26 11:23:07 +08:00
|
|
|
|
|
2025-01-15 15:12:26 +08:00
|
|
|
|
return new SapOutput
|
2024-09-26 11:23:07 +08:00
|
|
|
|
{
|
2025-01-15 15:12:26 +08:00
|
|
|
|
materialCode = item._System_objNBS,
|
2024-09-26 11:23:07 +08:00
|
|
|
|
code = "失败",
|
|
|
|
|
msg = lengthError,
|
|
|
|
|
result = lengthError
|
2025-01-15 15:12:26 +08:00
|
|
|
|
};
|
2024-09-26 11:23:07 +08:00
|
|
|
|
}
|
2025-01-15 15:12:26 +08:00
|
|
|
|
|
|
|
|
|
if (item.fld004607 == "N" || item.fld004607 == "D" || item.fld004607 == null)
|
2024-09-26 11:23:07 +08:00
|
|
|
|
{
|
2025-01-15 15:12:26 +08:00
|
|
|
|
return new SapOutput
|
2024-09-26 11:23:07 +08:00
|
|
|
|
{
|
2025-01-15 15:12:26 +08:00
|
|
|
|
materialCode = item._System_objNBS,
|
2024-09-26 11:23:07 +08:00
|
|
|
|
code = "失败",
|
|
|
|
|
msg = synchronized,
|
|
|
|
|
result = synchronized
|
2025-01-15 15:12:26 +08:00
|
|
|
|
};
|
2024-09-26 11:23:07 +08:00
|
|
|
|
}
|
2025-01-15 15:12:26 +08:00
|
|
|
|
|
2024-09-26 11:23:07 +08:00
|
|
|
|
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
|
|
|
|
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
|
|
|
|
var sapMaterialInput = new SapMaterialInput()
|
|
|
|
|
{
|
|
|
|
|
Reqkeyid = "",
|
|
|
|
|
Businessid = "",
|
|
|
|
|
Messageid = "",
|
|
|
|
|
Sndprn = "PLM",
|
|
|
|
|
Rcvprn = "SAP",
|
|
|
|
|
Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
|
|
|
|
Note1 = "",
|
|
|
|
|
Note2 = "",
|
|
|
|
|
Note3 = "",
|
|
|
|
|
Zwbid = millisecondTimestamp,
|
2025-01-15 15:12:26 +08:00
|
|
|
|
Matnr = item._System_objNBS,
|
|
|
|
|
Mbrsh = item.fld004595,
|
|
|
|
|
Mtart = item.fld004596,
|
|
|
|
|
Maktx = item.fld004598,
|
|
|
|
|
Meins = item.fld004594,
|
|
|
|
|
Matkl = item.fld004599,
|
|
|
|
|
Bismt = item._System_ObjDescription,
|
|
|
|
|
Groes = item.fld005323,
|
|
|
|
|
Normt = item.fld004592,
|
|
|
|
|
Ferth = item.fld004593,
|
|
|
|
|
Zeinr = item.fld004903,
|
|
|
|
|
Mstae = item.fld004696,
|
|
|
|
|
Raube = item.fld004904,
|
|
|
|
|
Mhdrz = item.fld004905.ToString(),
|
|
|
|
|
Mhdhb = item.fld004907.ToString(),
|
|
|
|
|
Werks = item.fld004597,
|
|
|
|
|
Beskz = item.fld004600,
|
|
|
|
|
Sobsl = item.fld004601,
|
|
|
|
|
Schgt = item.fld004602,
|
|
|
|
|
Rgekz = item.fld004603,
|
|
|
|
|
Zbom = item.fld004695
|
2024-09-26 11:23:07 +08:00
|
|
|
|
};
|
|
|
|
|
var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
|
|
|
|
string codeVal = sapOutput.code == "S" ? "成功" : "失败";
|
|
|
|
|
string msg = sapOutput.msg;
|
|
|
|
|
|
|
|
|
|
if (sapOutput.msg == "")
|
|
|
|
|
{
|
|
|
|
|
msg = "同步成功";
|
|
|
|
|
}
|
2025-01-15 15:12:26 +08:00
|
|
|
|
db.CopyNew().Updateable<Obj112>()
|
2024-09-26 11:23:07 +08:00
|
|
|
|
.SetColumns(it => new Obj112
|
2025-01-15 15:12:26 +08:00
|
|
|
|
{
|
|
|
|
|
fld004606 = DateTime.Now,
|
|
|
|
|
fld004604 = codeVal,
|
|
|
|
|
fld004607 = "N",
|
|
|
|
|
fld004605 = msg
|
|
|
|
|
})
|
|
|
|
|
.Where(it => it.idRecord == item.idRecord)
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
return new SapOutput()
|
2024-09-26 11:23:07 +08:00
|
|
|
|
{
|
|
|
|
|
parameter = sapOutput.parameter,
|
2025-01-15 15:12:26 +08:00
|
|
|
|
materialCode = item._System_objNBS,
|
2024-09-26 11:23:07 +08:00
|
|
|
|
code = codeVal,
|
|
|
|
|
msg = msg,
|
|
|
|
|
result = sapOutput.result
|
|
|
|
|
};
|
2025-01-15 15:12:26 +08:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
var materialOutput = await Task.WhenAll(tasks);
|
|
|
|
|
return materialOutput.ToList();
|
|
|
|
|
//for (int i = 0; i < input.Count; i++)
|
|
|
|
|
//{
|
|
|
|
|
// // 验证物料描述长度
|
|
|
|
|
// if (input[i].fld004598.Length > 40)
|
|
|
|
|
// {
|
|
|
|
|
// await _obj112Rep.AsUpdateable()
|
|
|
|
|
// .SetColumns(it => new Obj112
|
|
|
|
|
// {
|
|
|
|
|
// fld004606 = DateTime.Now,
|
|
|
|
|
// fld004607 = "N",
|
|
|
|
|
// fld004605 = lengthError,
|
|
|
|
|
// fld004604 = "失败"
|
|
|
|
|
// })
|
|
|
|
|
// .Where(it => it.idRecord == input[i].idRecord)
|
|
|
|
|
// .ExecuteCommandAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
// SapOutputList.Add(new SapOutput()
|
|
|
|
|
// {
|
|
|
|
|
// materialCode = input[i]._System_objNBS,
|
|
|
|
|
// code = "失败",
|
|
|
|
|
// msg = lengthError,
|
|
|
|
|
// result = lengthError
|
|
|
|
|
// });
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// if (input[i].fld004607 == "N" || input[i].fld004607 == "D" || input[i].fld004607 == null)
|
|
|
|
|
// {
|
|
|
|
|
// SapOutputList.Add(new SapOutput()
|
|
|
|
|
// {
|
|
|
|
|
// materialCode = input[i]._System_objNBS,
|
|
|
|
|
// code = "失败",
|
|
|
|
|
// msg = synchronized,
|
|
|
|
|
// result = synchronized
|
|
|
|
|
// });
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// //获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
|
|
|
|
// string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
|
|
|
|
// var sapMaterialInput = new SapMaterialInput()
|
|
|
|
|
// {
|
|
|
|
|
// Reqkeyid = "",
|
|
|
|
|
// Businessid = "",
|
|
|
|
|
// Messageid = "",
|
|
|
|
|
// Sndprn = "PLM",
|
|
|
|
|
// Rcvprn = "SAP",
|
|
|
|
|
// Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
|
|
|
|
// Note1 = "",
|
|
|
|
|
// Note2 = "",
|
|
|
|
|
// Note3 = "",
|
|
|
|
|
// Zwbid = millisecondTimestamp,
|
|
|
|
|
// Matnr = input[i]._System_objNBS,
|
|
|
|
|
// Mbrsh = input[i].fld004595,
|
|
|
|
|
// Mtart = input[i].fld004596,
|
|
|
|
|
// Maktx = input[i].fld004598,
|
|
|
|
|
// Meins = input[i].fld004594,
|
|
|
|
|
// Matkl = input[i].fld004599,
|
|
|
|
|
// Bismt = input[i]._System_ObjDescription,
|
|
|
|
|
// Groes = input[i].fld005323,
|
|
|
|
|
// Normt = input[i].fld004592,
|
|
|
|
|
// Ferth = input[i].fld004593,
|
|
|
|
|
// Zeinr = input[i].fld004903,
|
|
|
|
|
// Mstae = input[i].fld004696,
|
|
|
|
|
// Raube = input[i].fld004904,
|
|
|
|
|
// Mhdrz = input[i].fld004905.ToString(),
|
|
|
|
|
// Mhdhb = input[i].fld004907.ToString(),
|
|
|
|
|
// Werks = input[i].fld004597,
|
|
|
|
|
// Beskz = input[i].fld004600,
|
|
|
|
|
// Sobsl = input[i].fld004601,
|
|
|
|
|
// Schgt = input[i].fld004602,
|
|
|
|
|
// Rgekz = input[i].fld004603,
|
|
|
|
|
// Zbom = input[i].fld004695
|
|
|
|
|
// };
|
|
|
|
|
// var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
|
|
|
|
// string codeVal = sapOutput.code == "S" ? "成功" : "失败";
|
|
|
|
|
// string msg = sapOutput.msg;
|
|
|
|
|
|
|
|
|
|
// if (sapOutput.msg == "")
|
|
|
|
|
// {
|
|
|
|
|
// msg = "同步成功";
|
|
|
|
|
// }
|
|
|
|
|
// await _obj112Rep.AsUpdateable()
|
|
|
|
|
// .SetColumns(it => new Obj112
|
|
|
|
|
// {
|
|
|
|
|
// fld004606 = DateTime.Now,
|
|
|
|
|
// fld004604 = codeVal,
|
|
|
|
|
// fld004607 = "N",
|
|
|
|
|
// fld004605 = msg
|
|
|
|
|
// })
|
|
|
|
|
// .Where(it => it.idRecord == input[i].idRecord)
|
|
|
|
|
// .ExecuteCommandAsync();
|
|
|
|
|
// var output = new SapOutput()
|
|
|
|
|
// {
|
|
|
|
|
// parameter = sapOutput.parameter,
|
|
|
|
|
// materialCode = input[0]._System_objNBS,
|
|
|
|
|
// code = codeVal,
|
|
|
|
|
// msg = msg,
|
|
|
|
|
// result = sapOutput.result
|
|
|
|
|
// };
|
|
|
|
|
// SapOutputList.Add(output);
|
|
|
|
|
//}
|
|
|
|
|
//return SapOutputList;
|
2024-09-26 11:23:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生产物料管理-定时同步到SAP
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "TimingSyncToSAP"), HttpGet]
|
|
|
|
|
[DisplayName("生产物料管理-定时同步到SAP")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public async Task<List<SapOutput>> TimingSyncToSAP()
|
|
|
|
|
{
|
2025-01-15 15:12:26 +08:00
|
|
|
|
using var serviceScope = _scopeFactory.CreateScope();
|
|
|
|
|
var sysEnumService = serviceScope.ServiceProvider.GetRequiredService<SysEnumService>();
|
|
|
|
|
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
|
|
|
|
|
|
|
|
|
|
var input = db.Queryable<Obj112>()
|
2024-10-28 10:09:12 +08:00
|
|
|
|
.Where(x => (x.CheckedStatus == 7 || x.CheckedStatus == 8) && x.deleted == false && x.IsLatestVersion == true && (x.fld004607 == "A" || x.fld004607 == "M") && x.fld004973 == "发布")
|
2025-01-15 15:12:26 +08:00
|
|
|
|
.ToList();
|
2024-09-26 11:23:07 +08:00
|
|
|
|
const string lengthError = "物料描述长度大于40,请检查!";
|
|
|
|
|
var SapOutputList = new List<SapOutput>();
|
|
|
|
|
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
|
2025-01-15 15:12:26 +08:00
|
|
|
|
|
|
|
|
|
var tasks = input.Select(async item =>
|
2024-09-26 11:23:07 +08:00
|
|
|
|
{
|
2025-01-15 15:12:26 +08:00
|
|
|
|
if (item.fld004598.Length > 40)
|
2024-09-26 11:23:07 +08:00
|
|
|
|
{
|
2025-01-15 15:12:26 +08:00
|
|
|
|
db.CopyNew().Updateable<Obj112>()
|
2024-09-26 11:23:07 +08:00
|
|
|
|
.SetColumns(it => new Obj112
|
|
|
|
|
{
|
|
|
|
|
fld004606 = DateTime.Now,
|
|
|
|
|
fld004607 = "N",
|
|
|
|
|
fld004605 = lengthError,
|
|
|
|
|
fld004604 = "失败"
|
|
|
|
|
})
|
2025-01-15 15:12:26 +08:00
|
|
|
|
.Where(it => it.idRecord == item.idRecord)
|
|
|
|
|
.ExecuteCommand();
|
2024-09-26 11:23:07 +08:00
|
|
|
|
|
2025-01-15 15:12:26 +08:00
|
|
|
|
return new SapOutput
|
2024-09-26 11:23:07 +08:00
|
|
|
|
{
|
2025-01-15 15:12:26 +08:00
|
|
|
|
materialCode = item._System_objNBS,
|
2024-09-26 11:23:07 +08:00
|
|
|
|
code = "失败",
|
|
|
|
|
msg = lengthError,
|
|
|
|
|
result = lengthError
|
2025-01-15 15:12:26 +08:00
|
|
|
|
};
|
2024-09-26 11:23:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
|
|
|
|
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
|
|
|
|
var sapMaterialInput = new SapMaterialInput()
|
|
|
|
|
{
|
|
|
|
|
Reqkeyid = "",
|
|
|
|
|
Businessid = "",
|
|
|
|
|
Messageid = "",
|
|
|
|
|
Sndprn = "PLM",
|
|
|
|
|
Rcvprn = "SAP",
|
|
|
|
|
Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
|
|
|
|
Note1 = "",
|
|
|
|
|
Note2 = "",
|
|
|
|
|
Note3 = "",
|
|
|
|
|
Zwbid = millisecondTimestamp,
|
2025-01-15 15:12:26 +08:00
|
|
|
|
Matnr = item._System_objNBS,
|
|
|
|
|
Mbrsh = item.fld004595,
|
|
|
|
|
Mtart = item.fld004596,
|
|
|
|
|
Maktx = item.fld004598,
|
|
|
|
|
Meins = item.fld004594,
|
|
|
|
|
Matkl = item.fld004599,
|
|
|
|
|
Bismt = item._System_ObjDescription,
|
|
|
|
|
Groes = item.fld005323,
|
|
|
|
|
Normt = item.fld004592,
|
|
|
|
|
Ferth = item.fld004593,
|
|
|
|
|
Zeinr = item.fld004903,
|
|
|
|
|
Mstae = item.fld004696,
|
|
|
|
|
Raube = item.fld004904,
|
|
|
|
|
Mhdrz = item.fld004905.ToString(),
|
|
|
|
|
Mhdhb = item.fld004907.ToString(),
|
|
|
|
|
Werks = item.fld004597,
|
|
|
|
|
Beskz = item.fld004600,
|
|
|
|
|
Sobsl = item.fld004601,
|
|
|
|
|
Schgt = item.fld004602,
|
|
|
|
|
Rgekz = item.fld004603,
|
|
|
|
|
Zbom = item.fld004695
|
2024-09-26 11:23:07 +08:00
|
|
|
|
};
|
|
|
|
|
var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
|
|
|
|
string codeVal = sapOutput.code == "S" ? "成功" : "失败";
|
|
|
|
|
string msg = sapOutput.msg;
|
|
|
|
|
|
|
|
|
|
if (sapOutput.msg == "")
|
|
|
|
|
{
|
|
|
|
|
msg = "同步成功";
|
|
|
|
|
}
|
2025-01-15 15:12:26 +08:00
|
|
|
|
db.CopyNew().Updateable<Obj112>()
|
2024-09-26 11:23:07 +08:00
|
|
|
|
.SetColumns(it => new Obj112
|
|
|
|
|
{
|
|
|
|
|
fld004606 = DateTime.Now,
|
|
|
|
|
fld004604 = codeVal,
|
|
|
|
|
fld004607 = "N",
|
|
|
|
|
fld004605 = msg
|
|
|
|
|
})
|
2025-01-15 15:12:26 +08:00
|
|
|
|
.Where(it => it.idRecord == item.idRecord)
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
return new SapOutput()
|
2024-09-26 11:23:07 +08:00
|
|
|
|
{
|
|
|
|
|
parameter = sapOutput.parameter,
|
2025-01-15 15:12:26 +08:00
|
|
|
|
materialCode = item._System_objNBS,
|
2024-09-26 11:23:07 +08:00
|
|
|
|
code = codeVal,
|
|
|
|
|
msg = msg,
|
|
|
|
|
result = sapOutput.result
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-15 15:12:26 +08:00
|
|
|
|
});
|
|
|
|
|
var materialOutput = await Task.WhenAll(tasks);
|
|
|
|
|
return materialOutput.ToList();
|
|
|
|
|
|
|
|
|
|
//for (int i = 0; i < input.Count; i++)
|
|
|
|
|
//{
|
|
|
|
|
// // 验证物料描述长度
|
|
|
|
|
// if (input[i].fld004598.Length > 40)
|
|
|
|
|
// {
|
|
|
|
|
// await _obj112Rep.AsUpdateable()
|
|
|
|
|
// .SetColumns(it => new Obj112
|
|
|
|
|
// {
|
|
|
|
|
// fld004606 = DateTime.Now,
|
|
|
|
|
// fld004607 = "N",
|
|
|
|
|
// fld004605 = lengthError,
|
|
|
|
|
// fld004604 = "失败"
|
|
|
|
|
// })
|
|
|
|
|
// .Where(it => it.idRecord == input[i].idRecord)
|
|
|
|
|
// .ExecuteCommandAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
// SapOutputList.Add(new SapOutput()
|
|
|
|
|
// {
|
|
|
|
|
// materialCode = input[i]._System_objNBS,
|
|
|
|
|
// code = "失败",
|
|
|
|
|
// msg = lengthError,
|
|
|
|
|
// result = lengthError
|
|
|
|
|
// });
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// //获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
|
|
|
|
// string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
|
|
|
|
// var sapMaterialInput = new SapMaterialInput()
|
|
|
|
|
// {
|
|
|
|
|
// Reqkeyid = "",
|
|
|
|
|
// Businessid = "",
|
|
|
|
|
// Messageid = "",
|
|
|
|
|
// Sndprn = "PLM",
|
|
|
|
|
// Rcvprn = "SAP",
|
|
|
|
|
// Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
|
|
|
|
// Note1 = "",
|
|
|
|
|
// Note2 = "",
|
|
|
|
|
// Note3 = "",
|
|
|
|
|
// Zwbid = millisecondTimestamp,
|
|
|
|
|
// Matnr = input[i]._System_objNBS,
|
|
|
|
|
// Mbrsh = input[i].fld004595,
|
|
|
|
|
// Mtart = input[i].fld004596,
|
|
|
|
|
// Maktx = input[i].fld004598,
|
|
|
|
|
// Meins = input[i].fld004594,
|
|
|
|
|
// Matkl = input[i].fld004599,
|
|
|
|
|
// Bismt = input[i]._System_ObjDescription,
|
|
|
|
|
// Groes = input[i].fld005323,
|
|
|
|
|
// Normt = input[i].fld004592,
|
|
|
|
|
// Ferth = input[i].fld004593,
|
|
|
|
|
// Zeinr = input[i].fld004903,
|
|
|
|
|
// Mstae = input[i].fld004696,
|
|
|
|
|
// Raube = input[i].fld004904,
|
|
|
|
|
// Mhdrz = input[i].fld004905.ToString(),
|
|
|
|
|
// Mhdhb = input[i].fld004907.ToString(),
|
|
|
|
|
// Werks = input[i].fld004597,
|
|
|
|
|
// Beskz = input[i].fld004600,
|
|
|
|
|
// Sobsl = input[i].fld004601,
|
|
|
|
|
// Schgt = input[i].fld004602,
|
|
|
|
|
// Rgekz = input[i].fld004603,
|
|
|
|
|
// Zbom = input[i].fld004695
|
|
|
|
|
// };
|
|
|
|
|
// var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
|
|
|
|
// string codeVal = sapOutput.code == "S" ? "成功" : "失败";
|
|
|
|
|
// string msg = sapOutput.msg;
|
|
|
|
|
|
|
|
|
|
// if (sapOutput.msg == "")
|
|
|
|
|
// {
|
|
|
|
|
// msg = "同步成功";
|
|
|
|
|
// }
|
|
|
|
|
// await _obj112Rep.AsUpdateable()
|
|
|
|
|
// .SetColumns(it => new Obj112
|
|
|
|
|
// {
|
|
|
|
|
// fld004606 = DateTime.Now,
|
|
|
|
|
// fld004604 = codeVal,
|
|
|
|
|
// fld004607 = "N",
|
|
|
|
|
// fld004605 = msg
|
|
|
|
|
// })
|
|
|
|
|
// .Where(it => it.idRecord == input[i].idRecord)
|
|
|
|
|
// .ExecuteCommandAsync();
|
|
|
|
|
// var output = new SapOutput()
|
|
|
|
|
// {
|
|
|
|
|
// parameter = sapOutput.parameter,
|
|
|
|
|
// materialCode = input[0]._System_objNBS,
|
|
|
|
|
// code = codeVal,
|
|
|
|
|
// msg = msg,
|
|
|
|
|
// result = sapOutput.result
|
|
|
|
|
// };
|
|
|
|
|
// SapOutputList.Add(output);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//return SapOutputList;
|
2024-09-26 11:23:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|