// 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.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;
///
/// 变更通知ECN服务
///
[ApiDescriptionSettings(ApplicationConst.GroupName, Name = "ChangeNoticeEcn", Order = 100)]
public class ChangeNoticeEcnService : IDynamicApiController, ITransient
{
public SqlSugarRepository _obj118Rep;
private readonly SysConfigService _sysConfigService;
public Common.DataValidationService _dataValidationService;
public SapService.SapService _sapService;
public ChangeNoticeEcnService(
SqlSugarRepository obj118Rep,
SysConfigService sysConfigService,
DataValidationService dataValidationService,
SapService.SapService sapService
)
{
_obj118Rep = obj118Rep;
_sysConfigService = sysConfigService;
_dataValidationService = dataValidationService;
_sapService = sapService;
}
///
/// 分页查询变更通知ECN
///
///
///
[ApiDescriptionSettings(Name = "page", Description = "分页查询", Order = 1000), HttpPost]
[DisplayName("分页查询变更通知ECN")]
public async Task> 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()
.ToPagedListAsync(input.Page, input.PageSize);
return query;
}
///
/// 变更通知ECN-同步到 SAP
///
///
///
[ApiDescriptionSettings(Name = "syncToSAP"), HttpPost]
[DisplayName("变更通知ECN-同步到 SAP")]
public async Task 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(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;
}
}