From ce6a232b55646e8d39cb0b4861ee363608b6f9aa Mon Sep 17 00:00:00 2001 From: hwh <332078369@qq.com> Date: 星期五, 06 九月 2024 10:48:26 +0800 Subject: [PATCH] 服务状态读数据库;报警复位功能 --- Admin.NET/WCS.Application/Service/WcsAlarmInfo/Dto/WcsAlarmInfoInput.cs | 6 ++ Admin.NET/WCS.Application/PLC/PLCUtil.cs | 63 ++++++++++++++------- Admin.NET/WCS.Application/Service/Config/SysConfigService.cs | 17 +++++ Web/src/views/device/alarmManage/index.vue | 23 ++----- Admin.NET/WCS.Application/PLC/PLCTaskAction.cs | 18 ++++-- Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs | 35 ++++++++++- Admin.NET/WCS.Application/Hub/PlcHub.cs | 12 +++ 7 files changed, 123 insertions(+), 51 deletions(-) diff --git a/Admin.NET/WCS.Application/Hub/PlcHub.cs b/Admin.NET/WCS.Application/Hub/PlcHub.cs index de41681..2cf316f 100644 --- a/Admin.NET/WCS.Application/Hub/PlcHub.cs +++ b/Admin.NET/WCS.Application/Hub/PlcHub.cs @@ -10,10 +10,11 @@ public class PlcHub : Hub<IPlcHub> { private readonly IHubContext<PlcHub, IPlcHub> _plcHubContext; - - public PlcHub(IHubContext<PlcHub, IPlcHub> plcHubContext) + private readonly SysConfigService _sysConfigService; + public PlcHub(IHubContext<PlcHub, IPlcHub> plcHubContext, SysConfigService sysConfigService) { _plcHubContext = plcHubContext; + _sysConfigService = sysConfigService; } /// <summary> /// 涓嬪彂PLC杩炴帴鐘舵�� @@ -48,13 +49,20 @@ PLCTaskAction.Init(); else PLCTaskAction.Stop(); + await _sysConfigService.UpdateConfigValue("sys_RunningState", context.BoRunningState.Value); } //鑴辨満妯″紡 if (context.BoOffline.HasValue) + { PLCTaskAction.boOffline = context.BoOffline.Value; + await _sysConfigService.UpdateConfigValue("sys_Offline", context.BoOffline.Value); + } //鑷埛鏂� if (context.BoRefresh.HasValue) + { PLCTaskAction.boRefresh = context.BoRefresh.Value; + await _sysConfigService.UpdateConfigValue("sys_Refresh", context.BoRefresh.Value); + } await _plcHubContext.Clients.All.UpdateService(new PLCServiceModel() { BoRunningState = PLCTaskAction.boRunningState, BoRefresh = PLCTaskAction.boRefresh, BoOffline = PLCTaskAction.boOffline }); } } diff --git a/Admin.NET/WCS.Application/PLC/PLCTaskAction.cs b/Admin.NET/WCS.Application/PLC/PLCTaskAction.cs index 69e9e93..a7eff8f 100644 --- a/Admin.NET/WCS.Application/PLC/PLCTaskAction.cs +++ b/Admin.NET/WCS.Application/PLC/PLCTaskAction.cs @@ -19,6 +19,7 @@ private static readonly ISqlSugarClient _db = SqlSugarSetup.ITenant.GetConnectionScope(SqlSugarConst.MainConfigId); private static readonly SysCacheService sysCacheService = App.GetRequiredService<SysCacheService>(); private static readonly IHubContext<PlcHub, IPlcHub> _plcHubContext = App.GetService<IHubContext<PlcHub, IPlcHub>>(); + private static readonly SysConfigService _sysConfigService = App.GetService<SysConfigService>(); private static List<WcsPlc> listPlc = new List<WcsPlc>(); private static List<WcsDevice> listPlcDevice = new List<WcsDevice>(); @@ -37,6 +38,9 @@ { //璁㈤槄浜嬩欢 DeviceValueChangeEvent += PLCService.OnChangeEvent; + boRunningState = _sysConfigService.GetConfigValue<bool>("sys_RunningState").Result; + boOffline = _sysConfigService.GetConfigValue<bool>("sys_Offline").Result; + boRefresh = _sysConfigService.GetConfigValue<bool>("sys_Refresh").Result; } /// <summary> /// 鍒濆鍖朠LC杩炴帴 @@ -60,18 +64,20 @@ var plc = new PLCUtil(modPlc); listPlcUtil.Add(plc); } - cts = new CancellationTokenSource(); - boRunningState = true; _plcHubContext.Clients.All.UpdateService(new PLCServiceModel() { BoRunningState = boRunningState, BoOffline = boOffline, BoRefresh = boRefresh }); - StartRead(); - ConnectionStatus(); - StartWatchAlarm(); - StartWatchPosition(); + if (boRunningState) + { + cts = new CancellationTokenSource(); + StartRead(); + ConnectionStatus(); + StartWatchAlarm(); + StartWatchPosition(); + } } /// <summary> /// 寮�鍚鍙杙lc绾跨▼ diff --git a/Admin.NET/WCS.Application/PLC/PLCUtil.cs b/Admin.NET/WCS.Application/PLC/PLCUtil.cs index 27e6c55..0caf17a 100644 --- a/Admin.NET/WCS.Application/PLC/PLCUtil.cs +++ b/Admin.NET/WCS.Application/PLC/PLCUtil.cs @@ -53,41 +53,55 @@ address = DbNumber + "." + Pos; else address = DbNumber + Pos; + return this.GetPlcDBValue(PosType, address, Length); + } + } + /// <summary> + /// 璇诲彇PLC鍊� + /// </summary> + /// <param name="PosType">瀛楃绫诲瀷</param> + /// <param name="Pos">鍋忕Щ閲�/鍦板潃</param> + /// <param name="Length">闀垮害锛堝瓧绗︿覆锛�</param> + /// <returns></returns> + public (IoTClient.Result, dynamic value) GetPlcDBValue(PLCDataTypeEnum PosType, string Pos, int? Length = 0) + { + lock (OLock) + { dynamic result = null; switch (PosType) { case PLCDataTypeEnum.Bit: - result = _client.ReadBoolean(address); + result = _client.ReadBoolean(Pos); break; case PLCDataTypeEnum.Byte: - result = _client.ReadByte(address); + result = _client.ReadByte(Pos); break; case PLCDataTypeEnum.Short: - result = _client.ReadInt16(address); + result = _client.ReadInt16(Pos); break; case PLCDataTypeEnum.UShort: - result = _client.ReadUInt16(address); + result = _client.ReadUInt16(Pos); break; case PLCDataTypeEnum.Int: - result = _client.ReadInt32(address); + result = _client.ReadInt32(Pos); break; case PLCDataTypeEnum.UInt: - result = _client.ReadUInt32(address); + result = _client.ReadUInt32(Pos); break; case PLCDataTypeEnum.Long: - result = _client.ReadInt64(address); + result = _client.ReadInt64(Pos); break; case PLCDataTypeEnum.ULong: - result = _client.ReadUInt64(address); + result = _client.ReadUInt64(Pos); break; case PLCDataTypeEnum.Float: - result = _client.ReadFloat(address); + result = _client.ReadFloat(Pos); break; case PLCDataTypeEnum.Double: - result = _client.ReadDouble(address); + result = _client.ReadDouble(Pos); break; case PLCDataTypeEnum.String: - result = _client.ReadString(address, Convert.ToUInt16(Length)); + result = _client.ReadString(Pos, Convert.ToUInt16(Length)); break; default: result = new IoTClient.Result<object>(); @@ -159,6 +173,13 @@ address = DbNumber + "." + Pos; else address = DbNumber + Pos; + return this.SetPlcDBValue(PosType, address, Pos, Value); + } + /// <summary> + /// 鍐欏叆PLC鍊� + /// </summary> + public IoTClient.Result SetPlcDBValue(PLCDataTypeEnum PosType, string Pos, string Value) + { switch (PosType) { case PLCDataTypeEnum.Bit: @@ -173,25 +194,25 @@ throw new Exception("鍐欏叆鍊奸敊璇�"); } } - return _client.Write(address, bit); + return _client.Write(Pos, bit); case PLCDataTypeEnum.Byte: - return _client.Write(address, byte.Parse(Value)); + return _client.Write(Pos, byte.Parse(Value)); case PLCDataTypeEnum.Short: - return _client.Write(address, short.Parse(Value)); + return _client.Write(Pos, short.Parse(Value)); case PLCDataTypeEnum.UShort: - return _client.Write(address, ushort.Parse(Value)); + return _client.Write(Pos, ushort.Parse(Value)); case PLCDataTypeEnum.Int: - return _client.Write(address, int.Parse(Value)); + return _client.Write(Pos, int.Parse(Value)); case PLCDataTypeEnum.UInt: - return _client.Write(address, uint.Parse(Value)); + return _client.Write(Pos, uint.Parse(Value)); case PLCDataTypeEnum.Long: - return _client.Write(address, long.Parse(Value)); + return _client.Write(Pos, long.Parse(Value)); case PLCDataTypeEnum.ULong: - return _client.Write(address, ulong.Parse(Value)); + return _client.Write(Pos, ulong.Parse(Value)); case PLCDataTypeEnum.Float: - return _client.Write(address, float.Parse(Value)); + return _client.Write(Pos, float.Parse(Value)); case PLCDataTypeEnum.Double: - return _client.Write(address, float.Parse(Value)); + return _client.Write(Pos, float.Parse(Value)); default: return new IoTClient.Result(); } diff --git a/Admin.NET/WCS.Application/Service/Config/SysConfigService.cs b/Admin.NET/WCS.Application/Service/Config/SysConfigService.cs index 2c691a9..ea1ddc9 100644 --- a/Admin.NET/WCS.Application/Service/Config/SysConfigService.cs +++ b/Admin.NET/WCS.Application/Service/Config/SysConfigService.cs @@ -107,4 +107,21 @@ _sysCacheService.Remove($"{CacheConst.KeyConfig}{config.Code}"); } + /// <summary> + /// 鏇存柊鍙傛暟閰嶇疆鍊� + /// </summary> + /// <param name="code"></param> + /// <param name="value"></param> + /// <returns></returns> + [NonAction] + public async Task UpdateConfigValue(string code, bool value) + { + var config = await _sysConfigRep.GetFirstAsync(u => u.Code == code); + if (config == null) return; + + config.Value = value?"True":"False"; + await _sysConfigRep.AsUpdateable(config).ExecuteCommandAsync(); + + _sysCacheService.Remove($"{CacheConst.KeyConfig}{config.Code}"); + } } diff --git a/Admin.NET/WCS.Application/Service/WcsAlarmInfo/Dto/WcsAlarmInfoInput.cs b/Admin.NET/WCS.Application/Service/WcsAlarmInfo/Dto/WcsAlarmInfoInput.cs index 11f5067..25b843b 100644 --- a/Admin.NET/WCS.Application/Service/WcsAlarmInfo/Dto/WcsAlarmInfoInput.cs +++ b/Admin.NET/WCS.Application/Service/WcsAlarmInfo/Dto/WcsAlarmInfoInput.cs @@ -200,3 +200,9 @@ { } + +public class ResetInput +{ + [Required(ErrorMessage = "妤煎眰涓嶈兘涓虹┖")] + public int layer { get; set; } +} \ No newline at end of file diff --git a/Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs b/Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs index e2eef27..27f6373 100644 --- a/Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs +++ b/Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs @@ -1,4 +1,5 @@ -锘縰sing Microsoft.AspNetCore.SignalR; +锘縰sing Admin.NET.Core.Service; +using Microsoft.AspNetCore.SignalR; namespace WCS.Application; @@ -10,10 +11,12 @@ { private readonly SqlSugarRepository<WcsAlarmInfo> _wcsAlarmInfoRep; private readonly IHubContext<PlcHub, IPlcHub> _plcHubContext; - public WcsAlarmInfoService(SqlSugarRepository<WcsAlarmInfo> wcsAlarmInfoRep, IHubContext<PlcHub, IPlcHub> plcHubContext) + private readonly SysDictDataService _dictDataService; + public WcsAlarmInfoService(SqlSugarRepository<WcsAlarmInfo> wcsAlarmInfoRep, IHubContext<PlcHub, IPlcHub> plcHubContext, SysDictDataService dictDataService) { _wcsAlarmInfoRep = wcsAlarmInfoRep; _plcHubContext = plcHubContext; + _dictDataService = dictDataService; } /// <summary> @@ -121,13 +124,35 @@ [HttpPost] [ApiDescriptionSettings(Name = "Reset")] [DisplayName("澶嶄綅鎶ヨ")] - public async Task Reset() + public async Task Reset(ResetInput input) { //娴嬭瘯鎺ㄦ暟鎹敤鐨� - await _plcHubContext.Clients.All.PublicAlarm(new List<WcsAlarmInfo>() { new WcsAlarmInfo() { Id = 100, StationNum = "260", AlarmCode = "MB102", AlarmName = "鏈夌墿鍝侀伄鎸�", AlarmTime = DateTime.Now, Status = YesNoEnum.N } }); + //await _plcHubContext.Clients.All.PublicAlarm(new List<WcsAlarmInfo>() { new WcsAlarmInfo() { Id = 100, StationNum = "260", AlarmCode = "MB102", AlarmName = "鏈夌墿鍝侀伄鎸�", AlarmTime = DateTime.Now, Status = YesNoEnum.Y } }); //await _plcHubContext.Clients.All.PublicAlarm(new WcsAlarmInfo() { Id = 100, StationNum = "260", AlarmCode = "MB102", AlarmName = "鏈夌墿鍝侀伄鎸�", AlarmTime = DateTime.Now, Status = YesNoEnum.Y }); + var modPlc = await _wcsAlarmInfoRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine && s.Text == (input.layer.ToString() + "灞傛墭鐩樿緭閫佺嚎")).FirstAsync(); + if (modPlc == null) + throw Oops.Bah("鏈壘鍒拌緭閫佺嚎PLC"); + var listDict = await _dictDataService.GetDataList("reset_alarm"); + var value = listDict.FirstOrDefault(s => s.Code == input.layer.ToString()); + if (value == null) + throw Oops.Bah("鏈壘鍒板浣嶅湴鍧�锛岃鍦ㄥ瓧鍏哥鐞嗕腑璁剧疆"); + PLCUtil modUtil = new PLCUtil(modPlc); + switch (input.layer) + { + case 1: + break; + case 2: + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, value.Value, "1"); + } + break; + case 3: + break; + default: + break; + } + modUtil.Close(); - //throw Oops.Bah("寮�鍙戜腑"); } diff --git a/Web/src/views/device/alarmManage/index.vue b/Web/src/views/device/alarmManage/index.vue index 4013f0a..3d1de64 100644 --- a/Web/src/views/device/alarmManage/index.vue +++ b/Web/src/views/device/alarmManage/index.vue @@ -18,9 +18,9 @@ </el-col> <el-col :span="19"> <div class="card-page"> - <el-button type="primary" :plain="isPlain1" @click="floorTogglePlain(1)">涓�灞傚钩闈�</el-button> - <el-button type="primary" :plain="isPlain2" @click="floorTogglePlain(2)">浜屽眰骞抽潰</el-button> - <el-button type="primary" :plain="isPlain3" @click="floorTogglePlain(3)">涓夊眰骞抽潰</el-button> + <el-button type="primary" :plain="layer != 1" @click="floorTogglePlain(1)">涓�灞傚钩闈�</el-button> + <el-button type="primary" :plain="layer != 2" @click="floorTogglePlain(2)">浜屽眰骞抽潰</el-button> + <el-button type="primary" :plain="layer != 3" @click="floorTogglePlain(3)">涓夊眰骞抽潰</el-button> </div> <div style="margin: 40px; height: 50%;"> <div class="grid-container-line"> @@ -1950,32 +1950,21 @@ //澶嶄綅鎶ヨ const reset = async () => { - await resetWcsAlarmInfo(); + await resetWcsAlarmInfo({ layer: layer.value }); // await handleQuery(); } - -const isPlain1 = ref(false);//涓�灞� -const isPlain2 = ref(true);//浜屽眰 -const isPlain3 = ref(true);//涓夊眰 +const layer = ref(1); //鍒囨崲灞傚钩闈� function floorTogglePlain(buttonNumber) { + layer.value = buttonNumber; if (buttonNumber === 1) { - isPlain1.value = false; - isPlain2.value = true; - isPlain3.value = true; //鍒囨崲杈撻�佺嚎鏁版嵁 cellsData.value = cellsDataOne.value; } else if (buttonNumber === 2) { - isPlain2.value = false; - isPlain1.value = true; - isPlain3.value = true; //鍒囨崲杈撻�佺嚎鏁版嵁 cellsData.value = cellsDataTwo.value; } else if (buttonNumber === 3) { - isPlain3.value = false; - isPlain1.value = true; - isPlain2.value = true; //鍒囨崲杈撻�佺嚎鏁版嵁 cellsData.value = cellsDataThree.value; } -- Gitblit v1.8.0