2024-10-11 08:50:20 +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;
|
2024-10-16 11:40:20 +08:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2024-10-11 08:50:20 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
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.ChangeNoticeEcn.Dto;
|
|
|
|
|
using Vistar.Application.Util;
|
|
|
|
|
|
|
|
|
|
namespace Vistar.Application.Service.ChangeNoticeEcn;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 变更通知ECN服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings(ApplicationConst.GroupName, Name = "ChangeNoticeEcn", Order = 100)]
|
|
|
|
|
public class ChangeNoticeEcnService : IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
public SqlSugarRepository<Obj118> _obj118Rep;
|
|
|
|
|
private readonly SysConfigService _sysConfigService;
|
|
|
|
|
public Common.DataValidationService _dataValidationService;
|
|
|
|
|
public SapService.SapService _sapService;
|
|
|
|
|
public ChangeNoticeEcnService(
|
|
|
|
|
SqlSugarRepository<Obj118> obj118Rep,
|
|
|
|
|
SysConfigService sysConfigService,
|
|
|
|
|
DataValidationService dataValidationService,
|
|
|
|
|
SapService.SapService sapService
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
_obj118Rep = obj118Rep;
|
|
|
|
|
_sysConfigService = sysConfigService;
|
|
|
|
|
_dataValidationService = dataValidationService;
|
|
|
|
|
_sapService = sapService;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页查询变更通知ECN
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "page", Description = "分页查询", Order = 1000), HttpPost]
|
|
|
|
|
[DisplayName("分页查询变更通知ECN")]
|
|
|
|
|
public async Task<SqlSugarPagedList<ChangeNoticeEcnOutput>> Page(PageChangeNoticeEcnInput input)
|
|
|
|
|
{
|
|
|
|
|
var query = await _obj118Rep.AsQueryable()
|
|
|
|
|
.Where(x => (x.CheckedStatus == 1 || x.CheckedStatus == 0) && x.deleted == false && x.IsLatestVersion == true)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input._System_objNBS), u => u._System_objNBS.Contains(input._System_objNBS.Trim()))
|
|
|
|
|
.WhereIF(input.fld004693Range != null && input.fld004693Range.Length == 2, u => u.fld004693 >= input.fld004693Range[0] && u.fld004693 <= input.fld004693Range[1])
|
|
|
|
|
.Select<ChangeNoticeEcnOutput>()
|
|
|
|
|
.ToPagedListAsync(input.Page, input.PageSize);
|
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 变更通知ECN-同步到 SAP
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "syncToSAP"), HttpPost]
|
|
|
|
|
[DisplayName("变更通知ECN-同步到 SAP")]
|
|
|
|
|
public async Task<SapOutput> SyncToSAP(ChangeNoticeEcnInput input)
|
|
|
|
|
{
|
|
|
|
|
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
|
|
|
|
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
|
|
|
|
var sapEcnInput = new SapEcnInput()
|
|
|
|
|
{
|
|
|
|
|
Reqkeyid = "",
|
|
|
|
|
Businessid = "",
|
|
|
|
|
Messageid = "",
|
|
|
|
|
Sndprn = "PLM",
|
|
|
|
|
Rcvprn = "SAP",
|
|
|
|
|
Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
|
|
|
|
Note1 = "",
|
|
|
|
|
Note2 = "",
|
|
|
|
|
Note3 = "",
|
|
|
|
|
|
|
|
|
|
Aennr = input._System_objNBS,
|
|
|
|
|
Aetxt = input._System_ObjDescription,
|
|
|
|
|
Datuv = input.fld004693.ToDateTime().ToString("yyyy-MM-dd"),
|
|
|
|
|
Lvorm = input.fld004694,
|
|
|
|
|
Matnr = await _dataValidationService.ChangeModuleMaterial(input.fld004638.ToLong(),input.fld004638_Rec)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var apiOutput = await _sapService.SapEcnApi(sapEcnInput);
|
|
|
|
|
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
|
|
|
|
var msg = apiOutput.msg;
|
|
|
|
|
if (apiOutput.msg == "")
|
|
|
|
|
{
|
|
|
|
|
msg = "同步成功";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await _obj118Rep.AsUpdateable()
|
|
|
|
|
.SetColumns(it => new Obj118
|
|
|
|
|
{
|
|
|
|
|
fld005293 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
|
|
fld005294 = codeVal,
|
|
|
|
|
fld005292 = "N",
|
|
|
|
|
fld005295 = msg
|
|
|
|
|
})
|
|
|
|
|
.Where(it => it.idRecord == input.idRecord)
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
var output = new SapOutput()
|
|
|
|
|
{
|
|
|
|
|
parameter = apiOutput.parameter,
|
|
|
|
|
code = codeVal,
|
|
|
|
|
msg = msg,
|
|
|
|
|
result = apiOutput.result
|
|
|
|
|
};
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-16 11:40:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 变更通知ECN-批量同步到SAP
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "BatchSyncToSAP"), HttpPost]
|
|
|
|
|
[DisplayName("变更通知ECN-批量同步到SAP")]
|
|
|
|
|
public async Task<List<SapOutput>> BatchSyncToSAP(List<ChangeNoticeEcnInput> input)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var SapOutputList = new List<SapOutput>();
|
|
|
|
|
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
|
|
|
|
|
for (int i = 0; i < input.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
|
|
|
|
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
|
|
|
|
|
|
|
|
|
var sapEcnInput = new SapEcnInput()
|
|
|
|
|
{
|
|
|
|
|
Reqkeyid = "",
|
|
|
|
|
Businessid = "",
|
|
|
|
|
Messageid = "",
|
|
|
|
|
Sndprn = "PLM",
|
|
|
|
|
Rcvprn = "SAP",
|
|
|
|
|
Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
|
|
|
|
Note1 = "",
|
|
|
|
|
Note2 = "",
|
|
|
|
|
Note3 = "",
|
|
|
|
|
|
|
|
|
|
Aennr = input[i]._System_objNBS,
|
|
|
|
|
Aetxt = input[i]._System_ObjDescription,
|
|
|
|
|
Datuv = input[i].fld004693.ToDateTime().ToString("yyyy-MM-dd"),
|
|
|
|
|
Lvorm = input[i].fld004694,
|
|
|
|
|
Matnr = await _dataValidationService.ChangeModuleMaterial(input[i].fld004638.ToLong(), input[i].fld004638_Rec)
|
|
|
|
|
};
|
|
|
|
|
var apiOutput = await _sapService.SapEcnApi(sapEcnInput);
|
|
|
|
|
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
|
|
|
|
var msg = apiOutput.msg;
|
|
|
|
|
if (apiOutput.msg == "")
|
|
|
|
|
{
|
|
|
|
|
msg = "同步成功";
|
|
|
|
|
}
|
|
|
|
|
await _obj118Rep.AsUpdateable()
|
|
|
|
|
.SetColumns(it => new Obj118
|
|
|
|
|
{
|
|
|
|
|
fld005293 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
|
|
fld005294 = codeVal,
|
|
|
|
|
fld005292 = "N",
|
|
|
|
|
fld005295 = msg
|
|
|
|
|
})
|
|
|
|
|
.Where(it => it.idRecord == input[i].idRecord)
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
var output = new SapOutput()
|
|
|
|
|
{
|
|
|
|
|
parameter = apiOutput.parameter,
|
|
|
|
|
code = codeVal,
|
|
|
|
|
msg = msg,
|
|
|
|
|
result = apiOutput.result
|
|
|
|
|
};
|
|
|
|
|
SapOutputList.Add(output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SapOutputList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 变更通知ECN-定时同步到SAP
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "TimingSyncToSAP"), HttpGet]
|
|
|
|
|
[DisplayName("变更通知ECN-定时同步到SAP")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public async Task<List<SapOutput>> TimingSyncToSAP()
|
|
|
|
|
{
|
|
|
|
|
var input = await _obj118Rep.AsQueryable()
|
|
|
|
|
.Where(x => (x.CheckedStatus == 1 || x.CheckedStatus == 0) && x.deleted == false && x.IsLatestVersion == true && (x.fld005292 == "A" || x.fld005292 == "M"))
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
var SapOutputList = new List<SapOutput>();
|
|
|
|
|
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
|
|
|
|
|
for (int i = 0; i < input.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
|
|
|
|
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
|
|
|
|
|
|
|
|
|
var sapEcnInput = new SapEcnInput()
|
|
|
|
|
{
|
|
|
|
|
Reqkeyid = "",
|
|
|
|
|
Businessid = "",
|
|
|
|
|
Messageid = "",
|
|
|
|
|
Sndprn = "PLM",
|
|
|
|
|
Rcvprn = "SAP",
|
|
|
|
|
Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
|
|
|
|
Note1 = "",
|
|
|
|
|
Note2 = "",
|
|
|
|
|
Note3 = "",
|
|
|
|
|
|
|
|
|
|
Aennr = input[i]._System_objNBS,
|
|
|
|
|
Aetxt = input[i]._System_ObjDescription,
|
|
|
|
|
Datuv = input[i].fld004693.ToDateTime().ToString("yyyy-MM-dd"),
|
|
|
|
|
Lvorm = input[i].fld004694,
|
|
|
|
|
Matnr = await _dataValidationService.ChangeModuleMaterial(input[i].fld004638.ToLong(), input[i].fld004638_Rec)
|
|
|
|
|
};
|
|
|
|
|
var apiOutput = await _sapService.SapEcnApi(sapEcnInput);
|
|
|
|
|
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
|
|
|
|
var msg = apiOutput.msg;
|
|
|
|
|
if (apiOutput.msg == "")
|
|
|
|
|
{
|
|
|
|
|
msg = "同步成功";
|
|
|
|
|
}
|
|
|
|
|
await _obj118Rep.AsUpdateable()
|
|
|
|
|
.SetColumns(it => new Obj118
|
|
|
|
|
{
|
|
|
|
|
fld005293 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
|
|
fld005294 = codeVal,
|
|
|
|
|
fld005292 = "N",
|
|
|
|
|
fld005295 = msg
|
|
|
|
|
})
|
|
|
|
|
.Where(it => it.idRecord == input[i].idRecord)
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
var output = new SapOutput()
|
|
|
|
|
{
|
|
|
|
|
parameter = apiOutput.parameter,
|
|
|
|
|
code = codeVal,
|
|
|
|
|
msg = msg,
|
|
|
|
|
result = apiOutput.result
|
|
|
|
|
};
|
|
|
|
|
SapOutputList.Add(output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SapOutputList;
|
|
|
|
|
}
|
2024-10-11 08:50:20 +08:00
|
|
|
|
|
|
|
|
|
}
|