wxw
2024-09-06 d89bbfdd748109020f3255c80918d0f60b6e842c
Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs
@@ -1,4 +1,7 @@
namespace WCS.Application;
using Admin.NET.Core.Service;
using Microsoft.AspNetCore.SignalR;
namespace WCS.Application;
/// <summary>
/// 报警信息表服务
@@ -7,9 +10,13 @@
public class WcsAlarmInfoService : IDynamicApiController, ITransient
{
    private readonly SqlSugarRepository<WcsAlarmInfo> _wcsAlarmInfoRep;
    public WcsAlarmInfoService(SqlSugarRepository<WcsAlarmInfo> wcsAlarmInfoRep)
    private readonly 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>
@@ -46,6 +53,7 @@
    public async Task<long> Add(AddWcsAlarmInfoInput input)
    {
        var entity = input.Adapt<WcsAlarmInfo>();
        entity.Status = YesNoEnum.N;
        await _wcsAlarmInfoRep.InsertAsync(entity);
        return entity.Id;
    }
@@ -103,7 +111,7 @@
    public async Task<List<WcsAlarmInfoOutput>> List([FromQuery] PageWcsAlarmInfoInput input)
    {
        return await _wcsAlarmInfoRep.AsQueryable()
            //.WhereIF(!input.Status.IsNullOrEmpty(), s => s.Status == input.Status)
            .WhereIF(!input.Status.IsNullOrEmpty(), s => s.Status == input.Status)
            .Select<WcsAlarmInfoOutput>().ToListAsync();
    }
@@ -116,9 +124,35 @@
    [HttpPost]
    [ApiDescriptionSettings(Name = "Reset")]
    [DisplayName("复位报警")]
    public async Task Reset()
    public async Task Reset(ResetInput input)
    {
        throw Oops.Bah("开发中");
        //测试推数据用的
        //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();
    }