IPC-610
2025-01-15 b4083a6b047fc9e0964133c87227213c5154e37a
Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.SignalR;
using 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>
@@ -29,7 +32,7 @@
        input.SearchKey = input.SearchKey?.Trim();
        var query = _wcsAlarmInfoRep.AsQueryable()
            .WhereIF(!string.IsNullOrEmpty(input.SearchKey), u =>
                u.PlcIP.Contains(input.SearchKey)
                u.StationNum.Contains(input.SearchKey)
            )
            .WhereIF(!string.IsNullOrWhiteSpace(input.PlcIP), u => u.PlcIP.Contains(input.PlcIP.Trim()))
            .WhereIF(input.Status.HasValue, u => u.Status == input.Status)
@@ -121,13 +124,39 @@
    [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:
        //        modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, value.Value, "1");
        //        break;
        //    case 2:
        //        {
        //            modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, value.Value, "1");
        //        }
        //        break;
        //    case 3:
        //        modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, value.Value, "1");
        //        break;
        //    default:
        //        break;
        //}
        //throw Oops.Bah("开发中");
        modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, value.Value, "1");
        modUtil.Close();
    }