Compare commits

...

3 Commits

Author SHA1 Message Date
f081772d40 😎增加实体类字段 2025-01-16 17:45:51 +08:00
20f3383f8f 😎新增OA问题报告回传OA接口、定时任务 2025-01-16 17:44:19 +08:00
f531b6b286 😎定时任务改为内置的方式 2025-01-15 15:14:47 +08:00
24 changed files with 1858 additions and 46 deletions

View File

@ -73,6 +73,7 @@ public class DataValidationService : IDynamicApiController, ITransient
/// <returns></returns>
public async Task<string> VerificationMaterial(long objId, string materialCode, string recordGuid)
{
await Task.Delay(0);
using var serviceScope = _scopeFactory.CreateScope();
//var sysEnumService = serviceScope.ServiceProvider.GetRequiredService<SysEnumService>();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();

View File

@ -497,4 +497,29 @@ public class Obj140
[SugarColumn(ColumnName = "fld007039_Rec", ColumnDescription = "", Length = -1)]
public string? fld007039_Rec { get; set; }
/// <summary>
/// 同步标识
/// </summary>
public string? fld007055 { get; set; }
/// <summary>
/// 同步状态
/// </summary>
public string? fld007056 { get; set; }
/// <summary>
/// 同步信息
/// </summary>
public string? fld007057 { get; set; }
/// <summary>
/// 同步时间
/// </summary>
public DateTime? fld007058 { get; set; }
/// <summary>
/// 解决方案确定
/// </summary>
public string? fld006992 { get; set; }
}

View File

@ -0,0 +1,56 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.ChangeNoticeEcn;
namespace Vistar.Application.Job.ChangeNoticeEcn;
[JobDetail("job_EcnVarianceList", Description = "生成ECN差异清单", GroupName = "default", Concurrent = false)]
[PeriodMinutes(3, TriggerId = "trigger_EcnVarianceList", Description = "生成ECN差异清单", RunOnStart = false)]
public class EcnVarianceList : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public ChangeNoticeEcnService _changeNoticeEcn;
public EcnVarianceList(IServiceScopeFactory scopeFactory, ChangeNoticeEcnService changeNoticeEcn)
{
_scopeFactory = scopeFactory;
_changeNoticeEcn = changeNoticeEcn;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
DateTime startTime = DateTime.Now;
var sapOutputs = await _changeNoticeEcn.EcnVarianceList();
var json = JsonConvert.SerializeObject(sapOutputs);
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
db.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "生成ECN差异清单",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,70 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.ChangeNoticeEcn;
namespace Vistar.Application.Job.ChangeNoticeEcn;
[JobDetail("job_SyncEcnToSap", Description = "Ecn同步到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(5, TriggerId = "trigger_SyncEcnToSap", Description = "Ecn同步到SAP", RunOnStart = false)]
public class SyncEcnToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public ChangeNoticeEcnService _changeNoticeEcn;
public SyncEcnToSap(IServiceScopeFactory scopeFactory, ChangeNoticeEcnService changeNoticeEcn)
{
_scopeFactory = scopeFactory;
_changeNoticeEcn = changeNoticeEcn;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
DateTime startTime = DateTime.Now;
using var serviceScope = _scopeFactory.CreateScope();
var sysEnumService = serviceScope.ServiceProvider.GetRequiredService<SysEnumService>();
var dbMain = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
var sapOutputs = await _changeNoticeEcn.TimingSyncToSAP();
var json = JsonConvert.SerializeObject(sapOutputs);
string output = json;
if (sapOutputs.Count == 0||sapOutputs==null)
{
output = "未查询到符合条件的记录";
}
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
//dbMain.Insertable(new SysLogOp
//{
// ControllerName = "定时任务日志",
// DisplayTitle = "Ecn同步到SAP",
// ActionName = "Ecn同步到SAP",
// LogDateTime = DateTime.Now,
// ReturnResult = output,
// Elapsed = elapsedMilliseconds.ToLong(),
// Status = "200",
//}).ExecuteCommand();
dbMain.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "Ecn同步到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,59 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.OaOpenInterface;
namespace Vistar.Application.Job.OaOpenInterface;
[JobDetail("job_SyncEcnAttachToOA", Description = "同步ECN文件到OA", GroupName = "default", Concurrent = false)]
[PeriodMinutes(10, TriggerId = "trigger_SyncEcnAttachToOAJob", Description = "同步ECN文件到OA", RunOnStart = false)]
public class SyncEcnAttachToOA : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public OaOpenInterfaceService _oaOpenInterface;
public SyncEcnAttachToOA(IServiceScopeFactory scopeFactory, OaOpenInterfaceService oaOpenInterface)
{
_scopeFactory = scopeFactory;
_oaOpenInterface = oaOpenInterface;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
DateTime startTime = DateTime.Now;
var sapOutputs = await _oaOpenInterface.SyncEcnAttach();
var json = JsonConvert.SerializeObject(sapOutputs);
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (sapOutputs.Count == 0)
{
output = "未查询到符合条件的记录";
}
db.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "同步ECN文件到OA",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,57 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.OaOpenInterface;
namespace Vistar.Application.Job.OaOpenInterface;
[JobDetail("job_SyncProblemReportingFileToOa", Description = "问题报告回传OA", GroupName = "default", Concurrent = false)]
[PeriodMinutes(10, TriggerId = "trigger_SyncProblemReportingFileToOa", Description = "问题报告回传OA", RunOnStart = false)]
public class SyncProblemReportingFileToOa : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public OaOpenInterfaceService _oaOpenInterface;
public SyncProblemReportingFileToOa(IServiceScopeFactory scopeFactory, OaOpenInterfaceService oaOpenInterface)
{
_scopeFactory = scopeFactory;
_oaOpenInterface = oaOpenInterface;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
DateTime startTime = DateTime.Now;
var sapOutputs = await _oaOpenInterface.SyncProblemReportingFileToOa();
var json = JsonConvert.SerializeObject(sapOutputs);
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (sapOutputs.Count == 0)
{
output = "未查询到符合条件的记录";
}
db.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "问题报告回传OA",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,164 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.Schedule;
using Furion.TimeCrontab;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Logging;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.ProductDesignLibrary;
using Vistar.Application.Util;
namespace Vistar.Application.Job.ProductDesignLibrary;
[JobDetail("job_SyncProductDesignBomToSap", Description = "产品设计库同步bom到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(5, TriggerId = "trigger_SyncProductDesignBomToSapJob", Description = "产品设计库同步bom到SAP", RunOnStart = false)]
public class SyncProductDesignBomToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public ProductDesignLibraryService _productDesignLibrary;
public SyncProductDesignBomToSap(IServiceScopeFactory scopeFactory, ProductDesignLibraryService productDesignLibrary)
{
_scopeFactory = scopeFactory;
_productDesignLibrary = productDesignLibrary;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
DateTime startTime = DateTime.Now;
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 syncData = await db.CopyNew().Queryable<Obj137>()
.InnerJoin<ConfigurationData>((x, y) => x.RecordGuid == y.ParentGuid && x.VersionIndex == y.ParentVersion)
//.InnerJoin<Obj118>((x, y, z) => x.fld005679_Rec == z.RecordGuid)
.Where((x, y) => x.CheckedStatus == 0 && x.deleted == false && x.IsLatestVersion == true && (x._SWPDM_1202_SW_____ != "不展开" || x._SWPDM_1202_SW_____ == null) && x.fld005530 == "N" && x.fld005529 == "成功" && (x.fld005534 == "A" || x.fld005534 == "M") && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW") && y.isDeleted == false && y.ConfigId == 8 && (y.fld005577 != "不包含" || y.fld005577 == null) && y.isSuppressed == false && y.inContext == false && !(y.ParentSwFileType == 1 && y.isAddedFromSW == false))
.Select((x, y) => new
{
x.idRecord,
x.VersionIndex,
x._System_objNBS,
x.RecordGuid,
x.fld005679_Rec,
x.fld005686,
x.fld005678,
x._SWPDM_1187_SAP___,
x.fld005680,
y.ParentGuid,
y.ParentVersion,
y.ChildGuid,
y.ChildObjID,
y.childVersion,
y.ConfigId,
y.QtyManual,
y.PartNumber,
y.fld005541,
y.fld005542,
y.fld005543,
y.fld005544,
y.fld004940,
y.fld005546,
y.fld005547,
//ecn = z._System_objNBS
})
.ToListAsync();
var syncList = syncData.GroupBy(record => record.RecordGuid)
.Select(group => new SyncBomData
{
Id = group.FirstOrDefault()?.idRecord,
MaterialCode = group.FirstOrDefault()?._System_objNBS,
RecordGuid = group.FirstOrDefault()?.RecordGuid,
SyncVersion = group.FirstOrDefault()?.fld005686,
Bmeng = group.FirstOrDefault()?.fld005678,
Werks = group.FirstOrDefault()?._SWPDM_1187_SAP___,
Datuv = group.FirstOrDefault()?.fld005680,
VersionIndex = group.FirstOrDefault()?.VersionIndex,
//Ecn = group.FirstOrDefault()?.ecn,
ecnGuid = group.FirstOrDefault()?.fld005679_Rec,
Bom = group.Select(g => new BomData
{
PartNumber = g.PartNumber,
ParentGuid = g.ParentGuid,
ChildGuid = g.ChildGuid,
ChildObjID = g.ChildObjID,
ConfigId = g.ConfigId,
childVersion = g.childVersion,
ParentVersion = g.VersionIndex,
QtyManual = g.QtyManual,
SORTF = g.fld005541,
ITISOB = g.fld005542,
ALPGR = g.fld005543,
ALPRF = g.fld005544,
ZDELETE = g.fld004940,
POSTP = g.fld005546,
ZYFMK = g.fld005547
}).ToList()
});
List<SapOutput> sapOutputs = new List<SapOutput>();
int batchSize = 20; // 每批的大小
int totalCount = syncList.ToList().Count;
for (int i = 0; i < totalCount; i += batchSize)
{
var batch = syncList.Skip(i).Take(batchSize); // 分批获取数据
// 处理当前批次的数据
var tasks = batch.Select(async item =>
{
var output = await _productDesignLibrary.SyncBomToSap(item);
return output;
}).ToList();
var bomStockInquiryOutput = await Task.WhenAll(tasks); // 等待当前批次的所有任务完成
// 合并当前批次的结果
sapOutputs.AddRange(bomStockInquiryOutput);
// 如果需要暂停或者处理频率,可以在此处插入适当的延迟。
// await Task.Delay(1000); // 如果需要等待1秒可以启用此行代码。
}
var json = JsonConvert.SerializeObject(sapOutputs);
//var tasks = syncList.Select(async item =>
//{
// var output = await _productDesignLibrary.SyncBomToSap(item);
// return output;
//});
//var bomStockInquiryOutput = await Task.WhenAll(tasks);
//var json = JsonConvert.SerializeObject(bomStockInquiryOutput.ToList());
var dbMain = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (totalCount == 0)
{
output = "未查询到符合条件的记录";
}
dbMain.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "产品设计库同步bom到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,167 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data.OscarClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.SapService.Dto;
using Vistar.Application.Util;
namespace Vistar.Application.Job.ProductDesignLibrary;
[JobDetail("job_SyncProductDesignMaterialToSap", Description = "产品设计库同步物料到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(3, TriggerId = "trigger_SyncProductDesignMaterialToSapJob", Description = "产品设计库同步物料到SAP", RunOnStart = false)]
public class SyncProductDesignMaterialToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public SapService.SapService _sapService;
private readonly SysConfigService _sysConfigService;
public SyncProductDesignMaterialToSap(IServiceScopeFactory scopeFactory, SapService.SapService sapService, SysConfigService sysConfigService)
{
_scopeFactory = scopeFactory;
_scopeFactory = scopeFactory;
_sysConfigService = sysConfigService;
_sapService = sapService;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
DateTime startTime = DateTime.Now;
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.CopyNew().Queryable<Obj137>()
.Where(x => x.CheckedStatus == 0 && x.deleted == false && x.IsLatestVersion == true && (x.fld005530 == "A" || x.fld005530 == "M") && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW"))
.ToList();
const string lengthError = "物料描述长度大于40请检查";
var SapOutputList = new List<SapOutput>();
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
int batchSize = 20;
int totalCount = input.Count;
for (int i = 0; i < totalCount; i += batchSize)
{
var batch = input.Skip(i).Take(batchSize);
var tasks = batch.Select(async item =>
{
if (item._SWPDM_1188_SAP___ != null && item._SWPDM_1188_SAP___.Length > 40)
{
db.CopyNew().Updateable<Obj137>()
.SetColumns(it => new Obj137
{
fld005532 = DateTime.Now,
fld005530 = "N",
fld005531 = lengthError,
fld005529 = "失败"
})
.Where(it => it.idRecord == item.idRecord)
.ExecuteCommand();
return new SapOutput
{
materialCode = item._System_objNBS,
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 = Requser,
Note1 = "",
Note2 = "",
Note3 = "",
Zwbid = millisecondTimestamp,
Matnr = item._System_objNBS,
Mbrsh = item._SWPDM_1185_SAP___,
Mtart = item._SWPDM_1186_SAP_____,
Maktx = item._SWPDM_1188_SAP___,
Meins = item._SWPDM_126_SW___,
Matkl = item._SWPDM_1203_SAP____,
Bismt = item._SWPDM_64_SW___,
Groes = item._SWPDM_125_SW___,
Normt = item._SWPDM_65_SW___,
Ferth = item._SWPDM_62_SW___,
Zeinr = item._SWPDM_61_SW_____,
Mstae = item._SWPDM_1209_SAP_____,
Raube = "",
Mhdrz = "",
Mhdhb = "",
Werks = item._SWPDM_1187_SAP___,
Beskz = item._SWPDM_1196_SAP_____,
Sobsl = item._SWPDM_1198_SAP_____,
Schgt = item._SWPDM_1197_SAP_____,
Rgekz = item._SWPDM_1199_SAP___,
Zbom = item._SWPDM_1208_SAP___BOM___
};
var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput);
string codeVal = sapOutput.code == "S" ? "成功" : "失败";
string msg = sapOutput.msg;
if (sapOutput.msg == "")
{
msg = "同步成功";
}
db.CopyNew().Updateable<Obj137>()
.SetColumns(it => new Obj137
{
fld005532 = DateTime.Now,
fld005529 = codeVal,
fld005530 = "N",
fld005531 = msg
})
.Where(it => it.idRecord == item.idRecord)
.ExecuteCommand();
return new SapOutput()
{
parameter = sapOutput.parameter,
materialCode = item._System_objNBS,
code = codeVal,
msg = msg,
result = sapOutput.result
};
}).ToList();
var MateriaStockInquiryOutput = await Task.WhenAll(tasks);
SapOutputList.AddRange(MateriaStockInquiryOutput);
}
var json = JsonConvert.SerializeObject(SapOutputList);
var dbMain = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (totalCount == 0)
{
output = "未查询到符合条件的记录";
}
dbMain.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "产品设计库同步物料到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,125 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.ProductDesignLibrary;
using Vistar.Application.Util;
namespace Vistar.Application.Job.ProductDesignLibrary;
[JobDetail("job_SyncProductDesignProcessRouteToSap", Description = "产品设计库同步工艺路线到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(5, TriggerId = "trigger_SyncProductDesignProcessRouteToSapJob", Description = "产品设计库同步工艺路线到SAP", RunOnStart = false)]
public class SyncProductDesignProcessRouteToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public ProductDesignLibraryService _productDesignLibrary;
public SyncProductDesignProcessRouteToSap(IServiceScopeFactory scopeFactory, ProductDesignLibraryService productDesignLibrary)
{
_scopeFactory = scopeFactory;
_productDesignLibrary = productDesignLibrary;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
DateTime startTime = DateTime.Now;
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 syncPbom = db.CopyNew().Queryable<Obj137>()
.InnerJoin<ConfigurationData>((x, y) => x.RecordGuid == y.ParentGuid && x.VersionIndex == y.ParentVersion)
.Where((x, y) => x.CheckedStatus == 0 && x.deleted == false && x.IsLatestVersion == true && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW") && (x._SWPDM_1202_SW_____ != "不展开" || x._SWPDM_1202_SW_____ == null) && x.fld005530 == "N" && x.fld005529 == "成功" && (x.fld005537 == "A" || x.fld005537 == "M") && y.ConfigId == 9 && y.isDeleted == false)
.Select((x, y) => new
{
x.idRecord,
x.VersionIndex,
x.RecordGuid,
x._System_objNBS,
x._SWPDM_1187_SAP___,
x.fld005680,
y.ParentGuid,
y.ChildGuid,
y.ChildObjID,
y.PartNumber,
y.Marker,
y.fld005571,
y.fld005572,
y.fld005573,
y.fld005575,
}).ToList();
var syncList = syncPbom.GroupBy(record => record.RecordGuid)
.Select(group => new SyncProcessRouteData
{
idRecord = group.FirstOrDefault()?.idRecord,
_System_objNBS = group.FirstOrDefault()?._System_objNBS,
VersionIndex = group.FirstOrDefault()?.VersionIndex,
Werks= group.FirstOrDefault()?._SWPDM_1187_SAP___,
Datuv = group.FirstOrDefault()?.fld005680,
ProcessRouteList = group.Select(g => new ProcessRouteList
{
ParentGuid = g.ParentGuid,
ChildGuid = g.ChildGuid,
ChildObjID = g.ChildObjID,
PartNumber = g.PartNumber,
VORNR = g.Marker,
VGW01 = g.fld005571,
VGE01 = g.fld005572,
STEUS = g.fld005573,
BMSCH = g.fld005575
}).ToList()
});
List<SapOutput> sapOutputs = new List<SapOutput>();
int batchSize = 20; // 每批的大小
int totalCount = syncList.ToList().Count;
for (int i = 0; i < totalCount; i += batchSize)
{
var batch = syncList.Skip(i).Take(batchSize); // 分批获取数据
// 处理当前批次的数据
var tasks = batch.Select(async item =>
{
var output = await _productDesignLibrary.SyncProcessRouteToSap(item);
return output;
}).ToList();
var processRouteStockInquiryOutput = await Task.WhenAll(tasks); // 等待当前批次的所有任务完成
// 合并当前批次的结果
sapOutputs.AddRange(processRouteStockInquiryOutput);
}
var json = JsonConvert.SerializeObject(sapOutputs);
var dbMain = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (totalCount == 0)
{
output = "未查询到符合条件的记录";
}
dbMain.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "产品设计库同步工艺路线到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,156 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.MaterialManagement;
using Vistar.Application.Util;
namespace Vistar.Application.Job.ProductManagement;
[JobDetail("job_SyncProductManagementBomToSap", Description = "产品管理同步bom到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(5, TriggerId = "trigger_SyncProductManagementBomToSapJob", Description = "产品管理同步bom到SAP", RunOnStart = false)]
public class SyncProductManagementBomToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public ProductManagementService _productManagement;
public SyncProductManagementBomToSap(IServiceScopeFactory scopeFactory, ProductManagementService productManagement)
{
_scopeFactory = scopeFactory;
_productManagement = productManagement;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
DateTime startTime = DateTime.Now;
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
var syncData = db.CopyNew().Queryable<Obj110>()
.InnerJoin<ConfigurationData>((x, y) => x.RecordGuid == y.ParentGuid && x.VersionIndex == y.ParentVersion)
.Where((x, y) => (x.CheckedStatus == 0 || x.CheckedStatus == 1) && x.fld005324 == "发布" && x.deleted == false && x.IsLatestVersion == true && x.fld004311 == "成功" && x.fld004312 == "N" && (x.fld004316 == "A" || x.fld004316 == "M") && y.ConfigId == 1 && y.isDeleted == false && (y.fld005586 != "不包含" || y.fld005586 == null))
.Select((x, y) => new {
x.idRecord,
x.VersionIndex,
x._System_objNBS,
x.RecordGuid,
x.fld004944_Rec,
x.fld005288,
x.fld004942,
x.fld004325,
x.fld004945,
y.ParentGuid,
y.ParentVersion,
y.ChildGuid,
y.ChildObjID,
y.childVersion,
y.ConfigId,
y.Quantity,
y.PartNumber,
y.fld004936,
y.fld004937,
y.fld004938,
y.fld004939,
y.fld004940,
y.fld004492,
y.fld004941
}).ToList();
var syncList = syncData.GroupBy(record => record.RecordGuid)
.Select(group => new SyncBomData
{
Id = group.FirstOrDefault()?.idRecord,
MaterialCode = group.FirstOrDefault()?._System_objNBS,
RecordGuid = group.FirstOrDefault()?.RecordGuid,
SyncVersion = group.FirstOrDefault()?.fld005288,
Bmeng = group.FirstOrDefault()?.fld004942 != null ? (int?)(float)group.FirstOrDefault()?.fld004942 : null,
Werks = group.FirstOrDefault()?.fld004325,
Datuv = group.FirstOrDefault()?.fld004945,
VersionIndex = group.FirstOrDefault()?.VersionIndex,
//Ecn = group.FirstOrDefault()?.ecn,
ecnGuid = group.FirstOrDefault()?.fld004944_Rec,
Bom = group.Select(g => new BomData
{
PartNumber = g.PartNumber,
ParentGuid = g.ParentGuid,
ChildGuid = g.ChildGuid,
ChildObjID = g.ChildObjID,
ConfigId = g.ConfigId,
childVersion = g.childVersion,
ParentVersion = g.VersionIndex,
Quantity = g.Quantity,
SORTF = g.fld004936,
ITISOB = g.fld004937,
ALPGR = g.fld004938,
ALPRF = g.fld004939,
ZDELETE = g.fld004940,
POSTP = g.fld004492,
ZYFMK = g.fld004941
}).ToList()
});
List<SapOutput> sapOutputs = new List<SapOutput>();
int batchSize = 20; // 每批的大小
int totalCount = syncList.ToList().Count;
for (int i = 0; i < totalCount; i += batchSize)
{
var batch = syncList.Skip(i).Take(batchSize); // 分批获取数据
// 处理当前批次的数据
var tasks = batch.Select(async item =>
{
var output = await _productManagement.SyncBomToSap(item);
return output;
}).ToList();
var bomStockInquiryOutput = await Task.WhenAll(tasks); // 等待当前批次的所有任务完成
// 合并当前批次的结果
sapOutputs.AddRange(bomStockInquiryOutput);
// 如果需要暂停或者处理频率,可以在此处插入适当的延迟。
// await Task.Delay(1000); // 如果需要等待1秒可以启用此行代码。
}
var json = JsonConvert.SerializeObject(sapOutputs);
//var tasks = syncList.Select(async item =>
//{
// var output = await _productDesignLibrary.SyncBomToSap(item);
// return output;
//});
//var bomStockInquiryOutput = await Task.WhenAll(tasks);
//var json = JsonConvert.SerializeObject(bomStockInquiryOutput.ToList());
var dbMain = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (totalCount == 0)
{
output = "未查询到符合条件的记录";
}
dbMain.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "产品管理同步bom到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,166 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.SapService.Dto;
using Vistar.Application.Util;
namespace Vistar.Application.Job.ProductManagement;
[JobDetail("job_SyncProductManagementMaterialToSap", Description = "产品管理同步物料到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(3, TriggerId = "trigger_SyncProductManagementMaterialToSapJob", Description = "产品管理同步物料到SAP", RunOnStart = false)]
public class SyncProductManagementMaterialToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public SapService.SapService _sapService;
private readonly SysConfigService _sysConfigService;
public SyncProductManagementMaterialToSap(IServiceScopeFactory scopeFactory, SapService.SapService sapService, SysConfigService sysConfigService)
{
_scopeFactory = scopeFactory;
_sysConfigService = sysConfigService;
_sapService = sapService;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
DateTime startTime = DateTime.Now;
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
var input = db.CopyNew().Queryable<Obj110>()
.Where(x => (x.CheckedStatus == 0 || x.CheckedStatus == 1) && x.fld005324 == "发布" && x.deleted == false && x.IsLatestVersion == true && (x.fld004312 == "A" || x.fld004312 == "M"))
.ToList();
var SapOutputList = new List<SapOutput>();
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
const string lengthError = "物料描述长度大于40请检查";
int batchSize = 20; // 每批的大小
int totalCount = input.Count;
for (int i = 0; i < totalCount; i += batchSize)
{
var batch = input.Skip(i).Take(batchSize); // 分批获取数据
var tasks = batch.Select(async item =>
{
if (item.fld004484.Length > 40)
{
db.CopyNew().Updateable<Obj110>()
.SetColumns(it => new Obj110
{
fld004629 = DateTime.Now,
fld004312 = "N",
fld004313 = lengthError,
fld004311 = "失败"
})
.Where(it => it.idRecord == item.idRecord)
.ExecuteCommand();
return new SapOutput
{
materialCode = item._System_objNBS,
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 = Requser,
Note1 = "",
Note2 = "",
Note3 = "",
Zwbid = millisecondTimestamp,
Matnr = item._System_objNBS,
Mbrsh = item.fld004323,
Mtart = item.fld004324,
Maktx = item.fld004484,
Meins = item.fld004861,
Matkl = item.fld004485,
Bismt = item._System_ObjDescription,
Groes = item._System_objNBS,
Normt = item.fld004887,
Ferth = item.fld004882,
Zeinr = item.fld004881,
Mstae = item.fld004699,
Raube = item.fld004877,
Mhdrz = item.fld004876.ToString(),
Mhdhb = item.fld004895.ToString(),
Werks = item.fld004325,
Beskz = item.fld004490,
Sobsl = item.fld004491,
Schgt = item.fld004873,
Rgekz = item.fld004872,
Zbom = item.fld004698
};
var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput);
string codeVal = sapOutput.code == "S" ? "成功" : "失败";
string msg = sapOutput.msg;
if (sapOutput.msg == "")
{
msg = "同步成功";
}
db.CopyNew().Updateable<Obj110>()
.SetColumns(it => new Obj110
{
fld004629 = DateTime.Now,
fld004311 = codeVal,
fld004312 = "N",
fld004313 = msg
})
.Where(it => it.idRecord == item.idRecord)
.ExecuteCommand();
return new SapOutput
{
parameter = sapOutput.parameter,
materialCode = item._System_objNBS,
code = codeVal,
msg = msg,
result = sapOutput.result
};
}).ToList();
var MateriaStockInquiryOutput = await Task.WhenAll(tasks);
SapOutputList.AddRange(MateriaStockInquiryOutput);
}
var json = JsonConvert.SerializeObject(SapOutputList);
var dbMain = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (totalCount == 0)
{
output = "未查询到符合条件的记录";
}
dbMain.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "产品管理同步物料到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,124 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.MaterialManagement;
using Vistar.Application.Util;
namespace Vistar.Application.Job.ProductManagement;
[JobDetail("job_SyncProductManagementProcessRouteToSap", Description = "产品管理同步工艺路线到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(5, TriggerId = "trigger_SyncProductManagementProcessRouteToSapJob", Description = "产品管理同步工艺路线到SAP", RunOnStart = false)]
public class SyncProductManagementProcessRouteToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public ProductManagementService _productManagement;
public SyncProductManagementProcessRouteToSap(IServiceScopeFactory scopeFactory, ProductManagementService productManagement)
{
_scopeFactory = scopeFactory;
_productManagement = productManagement;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
DateTime startTime = DateTime.Now;
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
var syncPbom = db.CopyNew().Queryable<Obj110>()
.InnerJoin<ConfigurationData>((x, y) => x.RecordGuid == y.ParentGuid && x.VersionIndex == y.ParentVersion)
.Where((x, y) => (x.CheckedStatus == 0 || x.CheckedStatus == 1) && x.fld005324 == "发布" && x.deleted == false && x.IsLatestVersion == true && x.fld004311 == "成功" && x.fld004312 == "N" && (x.fld004320 == "A" || x.fld004320 == "M") && y.ConfigId == 4 && y.isDeleted == false)
.Select((x, y) => new
{
x.idRecord,
x.VersionIndex,
x.RecordGuid,
x._System_objNBS,
x.fld004325,//工厂
x.fld004945,//有效日期
y.ParentGuid,
y.ChildGuid,
y.ChildObjID,
y.PartNumber,
y.Marker,
y.fld004994,
y.fld004995,
y.fld004996,
y.fld005296,
}).ToList();
var syncList = syncPbom.GroupBy(record => record.RecordGuid)
.Select(group => new SyncProcessRouteData
{
idRecord = group.FirstOrDefault()?.idRecord,
_System_objNBS = group.FirstOrDefault()?._System_objNBS,
VersionIndex = group.FirstOrDefault()?.VersionIndex,
Werks= group.FirstOrDefault()?.fld004325,
Datuv = group.FirstOrDefault()?.fld004945,
ProcessRouteList = group.Select(g => new ProcessRouteList
{
ParentGuid = g.ParentGuid,
ChildGuid = g.ChildGuid,
ChildObjID = g.ChildObjID,
PartNumber = g.PartNumber,
VORNR = g.Marker,
VGW01 = g.fld004994 !=null ?g.fld004994.ToString():"",
VGE01 = g.fld004995,
STEUS = g.fld004996,
BMSCH = g.fld005296 != null ? g.fld005296.ToString() : ""
}).ToList()
});
List<SapOutput> sapOutputs = new List<SapOutput>();
int batchSize = 20; // 每批的大小
int totalCount = syncList.ToList().Count;
for (int i = 0; i < totalCount; i += batchSize)
{
var batch = syncList.Skip(i).Take(batchSize); // 分批获取数据
// 处理当前批次的数据
var tasks = batch.Select(async item =>
{
var output = await _productManagement.SyncProcessRouteToSap(item);
return output;
}).ToList();
var processRouteStockInquiryOutput = await Task.WhenAll(tasks); // 等待当前批次的所有任务完成
// 合并当前批次的结果
sapOutputs.AddRange(processRouteStockInquiryOutput);
}
var json = JsonConvert.SerializeObject(sapOutputs);
var dbMain = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (totalCount == 0)
{
output = "未查询到符合条件的记录";
}
dbMain.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "产品管理同步工艺路线到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,171 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using DocumentFormat.OpenXml.Drawing;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data.OscarClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.SapService.Dto;
using Vistar.Application.Util;
namespace Vistar.Application.Job.ProductionMaterials;
[JobDetail("job_SyncProductionMaterialsToSap", Description = "生产物料同步到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(5, TriggerId = "trigger_SyncProductionMaterialsToSapJob", Description = "生产物料同步到SAP", RunOnStart = false)]
public class SyncProductionMaterialsToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public SapService.SapService _sapService;
private readonly SysConfigService _sysConfigService;
public SyncProductionMaterialsToSap(IServiceScopeFactory scopeFactory, SapService.SapService sapService, SysConfigService sysConfigService)
{
_scopeFactory = scopeFactory;
_sysConfigService = sysConfigService;
_sapService=sapService;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
DateTime startTime = DateTime.Now;
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
var input = db.CopyNew().Queryable<Obj112>()
.Where(x => (x.CheckedStatus == 7 || x.CheckedStatus == 8) && x.deleted == false && x.IsLatestVersion == true && (x.fld004607 == "A" || x.fld004607 == "M") && x.fld004973 == "发布")
.ToList();
const string lengthError = "物料描述长度大于40请检查";
var SapOutputList = new List<SapOutput>();
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
int batchSize = 20; // 每批的大小
int totalCount = input.Count;
for (int i = 0; i < totalCount; i += batchSize)
{
var batch = input.Skip(i).Take(batchSize); // 分批获取数据
var tasks = batch.Select(async item =>
{
if (item.fld004598.Length > 40)
{
db.CopyNew().Updateable<Obj112>()
.SetColumns(it => new Obj112
{
fld004606 = DateTime.Now,
fld004607 = "N",
fld004605 = lengthError,
fld004604 = "失败"
})
.Where(it => it.idRecord == item.idRecord)
.ExecuteCommand();
return new SapOutput
{
materialCode = item._System_objNBS,
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 = 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
};
var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput);
string codeVal = sapOutput.code == "S" ? "成功" : "失败";
string msg = sapOutput.msg;
if (sapOutput.msg == "")
{
msg = "同步成功";
}
db.CopyNew().Updateable<Obj112>()
.SetColumns(it => new Obj112
{
fld004606 = DateTime.Now,
fld004604 = codeVal,
fld004607 = "N",
fld004605 = msg
})
.Where(it => it.idRecord == item.idRecord)
.ExecuteCommand();
return new SapOutput()
{
parameter = sapOutput.parameter,
materialCode = item._System_objNBS,
code = codeVal,
msg = msg,
result = sapOutput.result
};
}).ToList();
var MateriaStockInquiryOutput = await Task.WhenAll(tasks);
SapOutputList.AddRange(MateriaStockInquiryOutput);
}
var json = JsonConvert.SerializeObject(SapOutputList);
var dbMain = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (totalCount == 0)
{
output = "未查询到符合条件的记录";
}
dbMain.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "生产物料同步到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,58 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using DocumentFormat.OpenXml.Drawing;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.ProjectManagement;
namespace Vistar.Application.Job.ProjectManagement;
[JobDetail("job_SyncCreateWbsToSap", Description = "创建Wbs到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(30, TriggerId = "trigger_SyncCreateWbsToSapJob", Description = "创建Wbs到SAP", RunOnStart = false)]
public class SyncCreateWbsToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public ProjectManagementService _projectManagement;
public SyncCreateWbsToSap(IServiceScopeFactory scopeFactory, ProjectManagementService projectManagement)
{
_scopeFactory = scopeFactory;
_projectManagement = projectManagement;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
DateTime startTime = DateTime.Now;
var sapOutputs = await _projectManagement.WbsInSapCreate();
var json = JsonConvert.SerializeObject(sapOutputs);
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (sapOutputs.Count==0)
{
output= "未查询到符合条件的记录";
}
db.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "创建Wbs到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,66 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.ProjectManagement;
using Vistar.Application.Util;
namespace Vistar.Application.Job.ProjectManagement;
[JobDetail("job_SyncProjectManagementBomToSap", Description = "项目管理同步Bom到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(5, TriggerId = "trigger_SyncProjectManagementBomToSap", Description = "项目管理同步Bom到SAP", RunOnStart = false)]
public class SyncProjectManagementBomToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public ProjectManagementService _projectManagement;
public SyncProjectManagementBomToSap(IServiceScopeFactory scopeFactory, ProjectManagementService projectManagement)
{
_scopeFactory = scopeFactory;
_projectManagement = projectManagement;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
DateTime startTime = DateTime.Now;
var sapOutputs = await _projectManagement.TimingSyncToSAPBom();
var json = JsonConvert.SerializeObject(sapOutputs);
string output = json;
if (sapOutputs.Count == 0 || sapOutputs == null)
{
output = "未查询到符合条件的记录";
}
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
db.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "项目管理同步Bom到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,60 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.ProjectManagement;
namespace Vistar.Application.Job.ProjectManagement;
[JobDetail("job_SyncProjectManagementMaterialToSap", Description = "项目管理同步物料到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(3, TriggerId = "trigger_SyncProjectManagementMaterialToSap", Description = "项目管理同步物料到SAP", RunOnStart = false)]
public class SyncProjectManagementMaterialToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public ProjectManagementService _projectManagement;
public SyncProjectManagementMaterialToSap(IServiceScopeFactory scopeFactory, ProjectManagementService projectManagement)
{
_scopeFactory = scopeFactory;
_projectManagement = projectManagement;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
using var serviceScope = _scopeFactory.CreateScope();
var dbMain = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
DateTime startTime = DateTime.Now;
var sapOutputs = await _projectManagement.TimingSyncToSAP();
var json = JsonConvert.SerializeObject(sapOutputs);
string output = json;
if (sapOutputs.Count == 0)
{
output = "未查询到符合条件的记录";
}
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
dbMain.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "项目管理同步物料到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,63 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.ProjectManagement;
namespace Vistar.Application.Job.ProjectManagement;
[JobDetail("job_SyncProjectManagementProcessRouteToSap", Description = "项目管理同步工艺路线到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(5, TriggerId = "trigger_SyncProjectManagementProcessRouteToSap", Description = "项目管理同步工艺路线到SAP", RunOnStart = false)]
public class SyncProjectManagementProcessRouteToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public ProjectManagementService _projectManagement;
public SyncProjectManagementProcessRouteToSap(IServiceScopeFactory scopeFactory, ProjectManagementService projectManagement)
{
_scopeFactory = scopeFactory;
_projectManagement = projectManagement;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
DateTime startTime = DateTime.Now;
using var serviceScope = _scopeFactory.CreateScope();
var dbMain = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
var sapOutputs = await _projectManagement.TimingSyncToSAPProcessRoute();
var json = JsonConvert.SerializeObject(sapOutputs);
string output = json;
if (sapOutputs.Count == 0 || sapOutputs == null)
{
output = "未查询到符合条件的记录";
}
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
dbMain.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "项目管理同步工艺路线到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,59 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.ProjectManagement;
namespace Vistar.Application.Job.ProjectManagement;
[JobDetail("job_SyncUpdateWbsToSap", Description = "更新Wbs到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(30, TriggerId = "trigger_SyncUpdateWbsJob", Description = "更新Wbs到SAP", RunOnStart = false)]
public class SyncUpdateWbsToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public ProjectManagementService _projectManagement;
public SyncUpdateWbsToSap(IServiceScopeFactory scopeFactory, ProjectManagementService projectManagement)
{
_scopeFactory = scopeFactory;
_projectManagement = projectManagement;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
DateTime startTime = DateTime.Now;
var sapOutputs = await _projectManagement.WbsInSapUpdate();
var json = JsonConvert.SerializeObject(sapOutputs);
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (sapOutputs.Count == 0)
{
output = "未查询到符合条件的记录";
}
db.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "更新Wbs到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,57 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core.Service;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.PurchasingRequisition;
namespace Vistar.Application.Job.PurchasingRequisition;
[JobDetail("job_PurchasingRequisitionToSap", Description = "采购申请同步到SAP", GroupName = "default", Concurrent = false)]
[PeriodMinutes(30, TriggerId = "trigger_PurchasingRequisitionToSap", Description = "采购申请同步到SAP", RunOnStart = false)]
public class PurchasingRequisitionToSap : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public PurchasingRequisitionService _purchasingRequisition;
public PurchasingRequisitionToSap(IServiceScopeFactory scopeFactory, PurchasingRequisitionService purchasingRequisition)
{
_scopeFactory = scopeFactory;
_purchasingRequisition = purchasingRequisition;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
DateTime startTime = DateTime.Now;
var sapOutputs = await _purchasingRequisition.TimingSyncToSAPPurchasingRequisition();
var json = JsonConvert.SerializeObject(sapOutputs);
using var serviceScope = _scopeFactory.CreateScope();
var sysEnumService = serviceScope.ServiceProvider.GetRequiredService<SysEnumService>();
var dbMain = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (sapOutputs.Count == 0)
{
output = "未查询到符合条件的记录";
}
dbMain.Insertable<ScheduledTaskLog>(new
{
TaskName = "采购申请同步到SAP",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -0,0 +1,50 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
namespace Vistar.Application.Job.SolidWorksManage;
[JobDetail("job_RefreshManageToKen", Description = "刷新ManageToKen", GroupName = "default", Concurrent = false)]
[PeriodHours(6, TriggerId = "trigger_RefreshManageToKen", Description = "刷新ManageToKen", RunOnStart = false)]
public class RefreshManageToKen : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public SolidWorksManageService.SolidWorksManageService _solidWorksManage;
public RefreshManageToKen(IServiceScopeFactory scopeFactory, SolidWorksManageService.SolidWorksManageService solidWorksManage)
{
_scopeFactory = scopeFactory;
_solidWorksManage = solidWorksManage;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
DateTime startTime = DateTime.Now;
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
var outputs = await _solidWorksManage.Authenticate();
var json = JsonConvert.SerializeObject(outputs);
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
db.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "刷新ManageToKen",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -13,6 +13,7 @@ using System.Threading.Tasks;
namespace Vistar.Application.Service.OaOpenInterface.Dto;
public class OaUploadFileOutput
{
public string EcnNum { get; set; }
public string success { get; set; }
public string message { get; set; }
public string data { get; set; }

View File

@ -65,8 +65,8 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
_solidWorksManageService = solidWorksManageService;
_objectFieldsGroupsRep = objectFieldsGroupsRep;
_fieldGroupDefaultRep = fieldGroupDefaultRep;
_obj81Rep= obj81Rep;
_obj118Rep= obj118Rep;
_obj81Rep = obj81Rep;
_obj118Rep = obj118Rep;
_scopeFactory = scopeFactory;
}
@ -200,7 +200,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
string.IsNullOrWhiteSpace(input.fld005850) ||
input.fld005852 == default(DateTime) ||
//string.IsNullOrWhiteSpace(input.fld005852.ToString("yyyy-MM-dd HH:mm:ss")) ||
string.IsNullOrWhiteSpace(input.fld005853)
string.IsNullOrWhiteSpace(input.fld005853)
)
{
response.Success = true;
@ -279,12 +279,12 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
fields = fieldList
};
response = await _solidWorksManageService.CreateProcess(data);
if (response.Success== true && response.Message== "记录 已成功保存!")
if (response.Success == true && response.Message == "记录 已成功保存!")
{
var projectData = await _obj140Rep.AsQueryable().Where(x => x._System_objNBS == input._System_objNBS && x.deleted == false).OrderByDescending(x=>x.VersionIndex).FirstAsync();
var projectData = await _obj140Rep.AsQueryable().Where(x => x._System_objNBS == input._System_objNBS && x.deleted == false).OrderByDescending(x => x.VersionIndex).FirstAsync();
long? fld005835 = null;
string fld005835_Rec = "";
var responsiblePersonOaData = await _obj81Rep.AsQueryable().Where(x => x.fld004900 == input.fld005836 && x.deleted == false).ToListAsync();
if (responsiblePersonOaData.Count != 0)
{
@ -292,7 +292,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
fld005835_Rec = responsiblePersonOaData[0].RecordGuid;
}
long? fld007039 = null;
string fld007039_Rec = "";
@ -307,7 +307,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
}
}
long? fld005848 = null;
string fld005848_Rec = "";
@ -315,7 +315,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
if (createPersonOaData.Count != 0)
{
fld005848 = 81;
fld005848_Rec= createPersonOaData[0].RecordGuid;
fld005848_Rec = createPersonOaData[0].RecordGuid;
}
long? fld005851 = null;
@ -324,7 +324,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
if (reviewerOaData.Count != 0)
{
fld005851 = 81;
fld005851_Rec= reviewerOaData[0].RecordGuid;
fld005851_Rec = reviewerOaData[0].RecordGuid;
}
long? fld005837 = null;
@ -335,7 +335,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
if (mechanicalProblemHandlerOaId.Count != 0)
{
fld005837 = 81;
fld005837_Rec= mechanicalProblemHandlerOaId[0].RecordGuid;
fld005837_Rec = mechanicalProblemHandlerOaId[0].RecordGuid;
}
}
@ -367,7 +367,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
.SetColumns(it => new Obj140
{
fld005835 = fld005835,
fld005835_Rec= fld005835_Rec,
fld005835_Rec = fld005835_Rec,
fld007039 = fld007039,
fld007039_Rec = fld007039_Rec,
fld005848 = fld005848,
@ -400,7 +400,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
response.Message = "编码已存在";
}
return response;
return response;
}
/// <summary>
@ -411,11 +411,11 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
[ApiDescriptionSettings(Name = "OaAddRelatedFiles"), HttpPost]
[DisplayName("OA创建问题报告文件")]
public async Task<ManageResponse> OaAddRelatedFiles(OaAddRelatedFilesInput input)
public async Task<ManageResponse> OaAddRelatedFiles(OaAddRelatedFilesInput input)
{
var response = new ManageResponse();
if (input.object_id == 0||string.IsNullOrEmpty(input._System_objNBS)|| input.file_structure_id ==0 || string.IsNullOrEmpty(input.file_name))
if (input.object_id == 0 || string.IsNullOrEmpty(input._System_objNBS) || input.file_structure_id == 0 || string.IsNullOrEmpty(input.file_name))
{
response.Success = true;
response.Message = "必填项不能为空";
@ -426,9 +426,9 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
//string base64String = Convert.ToBase64String(bytes);
byte[] bytes = Convert.FromBase64String(input.file);
var AddRelatedFiles=new List<AddRelatedFilesInput>();
var AddRelatedFiles = new List<AddRelatedFilesInput>();
var data=await _obj140Rep.AsQueryable().Where(x=>x._System_objNBS==input._System_objNBS && x.deleted==false).OrderByDescending(x=>x.idRecord).ToListAsync();
var data = await _obj140Rep.AsQueryable().Where(x => x._System_objNBS == input._System_objNBS && x.deleted == false).OrderByDescending(x => x.idRecord).ToListAsync();
if (data.Count > 0)
{
var CheckData = new CheckDataInput()
@ -438,7 +438,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
bom_level = 1
};
await _solidWorksManageService.CheckOut(CheckData);
var latestData = await _obj140Rep.AsQueryable().Where(x => x._System_objNBS == input._System_objNBS && x.deleted == false).OrderByDescending(x => x.idRecord).ToListAsync();
var AddRelatedFilesData = new AddRelatedFilesInput
{
@ -451,7 +451,8 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
response = await _solidWorksManageService.AddRelatedFiles(AddRelatedFilesData);
await _solidWorksManageService.CheckIn(CheckData);
}
else {
else
{
response.Success = false;
response.Message = "编码不存在";
}
@ -463,13 +464,12 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
/// <returns></returns>
[ApiDescriptionSettings(Name = "SyncEcnAttach"), HttpGet]
[DisplayName("ecn同步文件")]
[AllowAnonymous]
public async Task<List<OaUploadFileOutput>> SyncEcnAttach()
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
var data=await db.CopyNew().Queryable<Obj118>().Where(x=>x.deleted==false&&x.fld006778=="A"&&x._System_CurrentStage=="结束"&&!string.IsNullOrEmpty(x.fld006310_Rec)).ToListAsync();
var data = await db.CopyNew().Queryable<Obj118>().Where(x => x.deleted == false && x.fld006778 == "A" && x._System_CurrentStage == "结束" && !string.IsNullOrEmpty(x.fld006310_Rec)).ToListAsync();
var groupedData = data.GroupBy(item => item.RecordGuid)
.Select(group => group.OrderByDescending(item => item.idRecord).First())
@ -480,26 +480,28 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
var id = item.idRecord;
var input = new ExportRelatedFilesInput
{
record_id=id,
object_id=118
record_id = id,
object_id = 118
};
var manageOutput= await _solidWorksManageService.ExportRelatedFiles(input);
if (manageOutput.State=="成功")
var manageOutput = await _solidWorksManageService.ExportRelatedFiles(input);
if (manageOutput.State == "成功")
{
var problemReport= await db.CopyNew().Queryable<Obj140>().Where(x=>x.RecordGuid==item.fld006310_Rec&&x.deleted==false).FirstAsync();
if (problemReport != null)
var problemReport = await db.CopyNew().Queryable<Obj140>().Where(x => x.RecordGuid == item.fld006310_Rec && x.deleted == false).FirstAsync();
if (problemReport != null)
{
var oaUploadFileOutput = await OaUploadFile(problemReport._System_objNBS, manageOutput);
var oaUploadFileOutput = await OaUploadFile(problemReport._System_objNBS, manageOutput, "");
var EcnNum = problemReport._System_objNBS;
oaUploadFileOutput.EcnNum = EcnNum;
output.Add(oaUploadFileOutput);
db.CopyNew().Updateable<Obj118>()
.SetColumns(it => new Obj118
{
fld006778="N",
fld006780=DateTime.Now,
fld006779= oaUploadFileOutput.message
})
.Where(it => it.idRecord == id)
.ExecuteCommand();
db.CopyNew().Updateable<Obj118>()
.SetColumns(it => new Obj118
{
fld006778 = "N",
fld006780 = DateTime.Now,
fld006779 = oaUploadFileOutput.message
})
.Where(it => it.idRecord == id)
.ExecuteCommand();
}
}
}
@ -511,18 +513,27 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
/// </summary>
/// <param name="problemNum"></param>
/// <param name="input"></param>
/// <param name="fld006992"></param>
/// <returns></returns>
public async Task<OaUploadFileOutput> OaUploadFile(string problemNum, ExportRelatedFilesOutput input)
public async Task<OaUploadFileOutput> OaUploadFile(string problemNum, ExportRelatedFilesOutput input, string? fld006992)
{
//string url = "http://223.113.253.60:8000/papi/secondev/workflow/uploadFileByReportNo";
string url = "http://192.168.10.35:8000/papi/secondev/workflow/uploadFileByReportNo";
// 构建请求参数字典
string FileName = "";
string FileBate = "";
if (input != null)
{
FileName = input.FileName;
FileBate = input.FileBate;
}
var requestData = new
{
num = problemNum,
filename=input.FileName,
filesize="",
base64 = input.FileBate
filename = FileName,
filesize = "",
base64 = FileBate,
jjfa = fld006992
};
var output = new OaUploadFileOutput();
using (HttpClient client = new HttpClient())
@ -533,7 +544,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
string json = JsonConvert.SerializeObject(requestData);
// 创建HttpContent设置为JSON格式的内容
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(url,content);
HttpResponseMessage response = await client.PostAsync(url, content);
if (response.IsSuccessStatusCode)
{
string contentOutput = await response.Content.ReadAsStringAsync();
@ -548,4 +559,51 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
}
return output;
}
/// <summary>
/// 问题报告回传OA
/// </summary>
/// <returns></returns>
public async Task<List<OaUploadFileOutput>> SyncProblemReportingFileToOa()
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
var data = await db.CopyNew().Queryable<Obj140>().Where(x => x.CheckedStatus == false && x.IsLatestVersion == true && x._System_CurrentStage == "问题关闭" && x.fld005841 == "不需要" && x.fld007055 == "A").ToListAsync();
var output = new List<OaUploadFileOutput>();
foreach (var item in data)
{
if (!string.IsNullOrEmpty(item.fld006992))
{
var oaOutput = await OaUploadFile(item._System_objNBS, null, item.fld006992);
var EcnNum = item._System_objNBS;
oaOutput.EcnNum = EcnNum;
output.Add(oaOutput);
if (oaOutput.success == "true")
{
db.CopyNew().Updateable<Obj140>().SetColumns(it => new Obj140
{
fld007055 = "N",
fld007058 = DateTime.Now,
fld007057 = oaOutput.message,
fld007056 = "成功"
}).Where(it => it.idRecord == item.idRecord)
.ExecuteCommand();
}
else
{
db.CopyNew().Updateable<Obj140>().SetColumns(it => new Obj140
{
fld007055 = "N",
fld007058 = DateTime.Now,
fld007057 = oaOutput.message,
fld007056 = "失败"
}).Where(it => it.idRecord == item.idRecord)
.ExecuteCommand();
}
}
}
return output;
}
}

View File

@ -14,7 +14,7 @@ using System.Threading.Tasks;
namespace Vistar.Application.SolidWorksManageService.Dto;
public class ExportRelatedFilesOutput
{
public string State { get; set; }
public string FileName { get; set; }
public string FileBate { get; set; }
public string? State { get; set; }
public string? FileName { get; set; }
public string? FileBate { get; set; }
}

View File

@ -37,7 +37,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Entity\" />
<Folder Include="Service\PurchasingRequisition\Dto\" />
</ItemGroup>