😎定时任务改为内置的方式
This commit is contained in:
parent
e29ab3ca32
commit
f531b6b286
@ -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();
|
||||
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -37,7 +37,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Entity\" />
|
||||
<Folder Include="Service\PurchasingRequisition\Dto\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user