change - 状态刷新调度任务

dev
liuwf 1 year ago
parent e0a6d10540
commit 2e5c112322

@ -13,6 +13,7 @@
<ProjectReference Include="..\Admin.Core.Model\Admin.Core.Model.csproj" /> <ProjectReference Include="..\Admin.Core.Model\Admin.Core.Model.csproj" />
<ProjectReference Include="..\Admin.Core.Service\Admin.Core.Service.csproj" /> <ProjectReference Include="..\Admin.Core.Service\Admin.Core.Service.csproj" />
<ProjectReference Include="..\Aucma.Core.PLc\Aucma.Core.PLc.csproj" /> <ProjectReference Include="..\Aucma.Core.PLc\Aucma.Core.PLc.csproj" />
<ProjectReference Include="..\Aucma.Core.Scanner\Aucma.Core.Scanner.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -0,0 +1,67 @@
using Admin.Core.Common;
using Admin.Core.IService;
using Admin.Core.IService.ISys;
using Admin.Core.Model;
using Admin.Core.Service;
using Aucma.Core.PLc;
using Aucma.Core.Scanner;
using log4net;
using NetTaste;
using NPOI.SS.Formula.Functions;
using Quartz;
using System;
using System.Linq;
using System.Threading.Tasks;
/// <summary>
///plc数据库扫码器状态刷新
/// </summary>
namespace Admin.Core.Tasks
{
public class Job_AllState_Quartz : JobBase, IJob
{
public delegate Task RefreshCodeBindingState(bool mesState, bool plcState, bool scanner1, bool scanner2);
public static event RefreshCodeBindingState RefreshCodeBindingStateEvent;
private readonly IBaseServices<BaseBomInfo> baseServices;
public Job_AllState_Quartz(ISysTasksQzService SysTasksQzService, ISysJobLogService sysJobLogService,IBaseBomInfoServices baseBomInfoServices)
{
_SysTasksQzService = SysTasksQzService;
_sysJobLogService = sysJobLogService;
baseServices = baseBomInfoServices;
}
public async Task Execute(IJobExecutionContext context)
{
await ExecuteJob(context, async () => await Run());
}
#region plc数据库扫码器状态刷新
public Task Run()
{
bool mesState;
bool plcState;
bool scanner1;
bool scanner2;
mesState = baseServices.GetConnectionState();
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc"));
if (obj != null && obj.plc.IsConnected)
{
plcState = true;
}
else
{
plcState = false;
}
string ip1 = Appsettings.app("Middleware", "Scanner1", "Ip");
string ip2 = Appsettings.app("Middleware", "Scanner2", "Ip");
scanner1 = MvCodeHelper.ConnectionStatus(ip1);
scanner2 = MvCodeHelper.ConnectionStatus(ip2);
//条码绑定上位机状态刷新
RefreshCodeBindingStateEvent(mesState,plcState,scanner1,scanner2);
return Task.FromResult(0);
#endregion
}
}
}

@ -66,7 +66,7 @@ namespace Aucma.Core.CodeBinding
services.AddScannerSetup(); services.AddScannerSetup();
//任务调度 //任务调度
// services.AddJobSetup(); services.AddJobSetup();
//PLC //PLC
services.AddPlcSetup(); services.AddPlcSetup();
//支持编码大全 例如:支持 System.Text.Encoding.GetEncoding("GB2312") System.Text.Encoding.GetEncoding("GB18030") //支持编码大全 例如:支持 System.Text.Encoding.GetEncoding("GB2312") System.Text.Encoding.GetEncoding("GB18030")
@ -89,7 +89,7 @@ namespace Aucma.Core.CodeBinding
/// </summary> /// </summary>
/// <param name="app"></param> /// <param name="app"></param>
/// <param name="env"></param> /// <param name="env"></param>
public void Configure(IApplicationBuilder app, IScannerService scannerService, IRunPlcService runPlcService) // ISysTasksQzService tasksQzService, ISchedulerCenter schedulerCenter public void Configure(IApplicationBuilder app, IScannerService scannerService, IRunPlcService runPlcService, ISysTasksQzService tasksQzService, ISchedulerCenter schedulerCenter) // ISysTasksQzService tasksQzService, ISchedulerCenter schedulerCenter
{ {
// 使用静态文件 // 使用静态文件
app.UseStaticFiles(); app.UseStaticFiles();
@ -98,9 +98,10 @@ namespace Aucma.Core.CodeBinding
//开启扫码服务 //开启扫码服务
app.UseScannerMildd(scannerService); app.UseScannerMildd(scannerService);
// 开启QuartzNetJob调度服务 // 开启QuartzNetJob调度服务
// app.UseQuartzJobMildd(tasksQzService, schedulerCenter); app.UseQuartzJobMildd(tasksQzService, schedulerCenter);
//PLC //PLC
app.UsePlcMildd(runPlcService); app.UsePlcMildd(runPlcService);
} }
#region 注册服务 #region 注册服务

@ -18,6 +18,8 @@ using Admin.Core.IService;
using Admin.Core.Service; using Admin.Core.Service;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Admin.Core.Model; using Admin.Core.Model;
using Admin.Core.Tasks;
using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
namespace Aucma.Core.CodeBinding.ViewModels namespace Aucma.Core.CodeBinding.ViewModels
{ {
@ -38,23 +40,10 @@ namespace Aucma.Core.CodeBinding.ViewModels
{ {
UserContent = firstPage; UserContent = firstPage;
Job_AllState_Quartz.RefreshCodeBindingStateEvent += RefreshStatus;
MesDbState(false);
PlcState(true);
Scanner1State(true);
Scanner2State(true);
init();
} }
public void init()
{
// 设备状态刷新定时器
System.Timers.Timer timer = new System.Timers.Timer(1000 * 5);
timer.Elapsed += new System.Timers.ElapsedEventHandler(RefreshStatus);
timer.AutoReset = true;
timer.Enabled = true;
timer.Start();
}
#region 设备状态刷新 #region 设备状态刷新
/// <summary> /// <summary>
@ -62,48 +51,15 @@ namespace Aucma.Core.CodeBinding.ViewModels
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
public void RefreshStatus(object sender, System.Timers.ElapsedEventArgs e) public Task RefreshStatus(bool mesState,bool plcState,bool scanner1,bool scanner2)
{
RefreshMesDb();
RefreshPlc();
RefreshScanner();
}
/// <summary>
/// 数据库状态刷新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void RefreshMesDb()
{
MesDbState(true);
}
/// <summary>
/// plc状态刷新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void RefreshPlc()
{ {
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc")); MesDbState(mesState);
if (obj != null) PlcState(plcState);
{ Scanner1State(scanner1);
if (obj.plc.IsConnected) Scanner2State(scanner2);
{ return Task.CompletedTask;
PlcState(true);
}
else
{
PlcState(false);
}
}
else
{
PlcState(false);
}
} }
/// <summary> /// <summary>
/// 扫码器状态刷新 /// 扫码器状态刷新
/// </summary> /// </summary>
@ -264,13 +220,13 @@ namespace Aucma.Core.CodeBinding.ViewModels
{ {
if (type) if (type)
{ {
MesDbUIStatusWb = "MES数据库连接成功"; MesDbUIStatusWb = "MES数据库";
MesDbUIColor = "Green"; MesDbUIColor = "Green";
MesUIIcon = "Assets/Images/Green.png"; MesUIIcon = "Assets/Images/Green.png";
} }
else else
{ {
MesDbUIStatusWb = "MES数据库异常"; MesDbUIStatusWb = "MES数据库";
MesDbUIColor = "Red"; MesDbUIColor = "Red";
MesUIIcon = "Assets/Images/Red.png"; MesUIIcon = "Assets/Images/Red.png";
} }
@ -317,13 +273,13 @@ namespace Aucma.Core.CodeBinding.ViewModels
{ {
if (type) if (type)
{ {
PlcUIStatusWb = "PLC连接成功"; PlcUIStatusWb = "PLC状态";
PlcUIColor = "Green"; PlcUIColor = "Green";
PlcUIIcon = "Assets/Images/Green.png"; PlcUIIcon = "Assets/Images/Green.png";
} }
else else
{ {
PlcUIStatusWb = "PLC状态异常"; PlcUIStatusWb = "PLC状态";
PlcUIColor = "Red"; PlcUIColor = "Red";
PlcUIIcon = "Assets/Images/Red.png"; PlcUIIcon = "Assets/Images/Red.png";
} }
@ -376,13 +332,13 @@ namespace Aucma.Core.CodeBinding.ViewModels
{ {
if (type) if (type)
{ {
Scanner1UIStatusWb = "扫码器1连接成功"; Scanner1UIStatusWb = "扫码器1状态";
Scanner1UIColor = "Green"; Scanner1UIColor = "Green";
Scanner1UIIcon = "Assets/Images/Green.png"; Scanner1UIIcon = "Assets/Images/Green.png";
} }
else else
{ {
Scanner1UIStatusWb = "扫码器1状态异常"; Scanner1UIStatusWb = "扫码器1状态";
Scanner1UIColor = "Red"; Scanner1UIColor = "Red";
Scanner1UIIcon = "Assets/Images/Red.png"; Scanner1UIIcon = "Assets/Images/Red.png";
} }
@ -435,13 +391,13 @@ namespace Aucma.Core.CodeBinding.ViewModels
{ {
if (type) if (type)
{ {
Scanner2UIStatusWb = "扫码器2连接成功"; Scanner2UIStatusWb = "扫码器2状态";
Scanner2UIColor = "Green"; Scanner2UIColor = "Green";
Scanner2UIIcon = "Assets/Images/Green.png"; Scanner2UIIcon = "Assets/Images/Green.png";
} }
else else
{ {
Scanner2UIStatusWb = "扫码器2状态异常"; Scanner2UIStatusWb = "扫码器2状态";
Scanner2UIColor = "Red"; Scanner2UIColor = "Red";
Scanner2UIIcon = "Assets/Images/Red.png"; Scanner2UIIcon = "Assets/Images/Red.png";
} }

@ -101,13 +101,13 @@
"JobGroup": "DEFAULT", "JobGroup": "DEFAULT",
"Cron": "*/1 * * * * ?", "Cron": "*/1 * * * * ?",
"AssemblyName": "Admin.Core.Tasks", "AssemblyName": "Admin.Core.Tasks",
"ClassName": "Job_Admin_Quartz", "ClassName": "Job_AllState_Quartz",
"Remark": "执行任务调度系统", "Remark": "执行任务调度系统",
"RunTimes": 3881, "RunTimes": 3881,
"BeginTime": "2023-04-23 11:08:50.000", "BeginTime": "2023-04-23 11:08:50.000",
"EndTime": "2023-08-06 16:45:30.000", "EndTime": "2080-12-01 16:45:30.000",
"TriggerType": 1, "TriggerType": 1,
"IntervalSecond": 1, "IntervalSecond": 5,
"CycleRunTimes": 1, "CycleRunTimes": 1,
"IsStart": true, "IsStart": true,
"JobParams": null, "JobParams": null,

Loading…
Cancel
Save