wxw
2024-09-02 54da8a22c438e1495b9c5fbae75ca9d4b5ca7335
Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs
@@ -1,4 +1,6 @@

using Admin.NET.Core.Service;
namespace WCS.Application;
/// <summary>
@@ -8,9 +10,11 @@
public class WcsDeviceService : IDynamicApiController, ITransient
{
    private readonly SqlSugarRepository<WcsDevice> _wcsDeviceRep;
    public WcsDeviceService(SqlSugarRepository<WcsDevice> wcsDeviceRep)
    private readonly SysCacheService _sysCacheService;
    public WcsDeviceService(SqlSugarRepository<WcsDevice> wcsDeviceRep, SysCacheService sysCacheService)
    {
        _wcsDeviceRep = wcsDeviceRep;
        _sysCacheService = sysCacheService;
    }
    /// <summary>
@@ -41,6 +45,7 @@
            {
                Id = u.Id,
                PlcId = u.PlcId,
                DeviceType = (DeviceTypeEnum)u.DeviceType,
                PlcIdIP = plcid.IP,
                Level = (DeviceLevelEnum)u.Level,
                DbNumber = u.DbNumber,
@@ -121,19 +126,6 @@
    }
    /// <summary>
    /// 获取设备信息列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "List")]
    [DisplayName("获取设备信息列表")]
    public async Task<List<WcsDeviceOutput>> List([FromQuery] PageWcsDeviceInput input)
    {
        return await _wcsDeviceRep.AsQueryable().Select<WcsDeviceOutput>().ToListAsync();
    }
    /// <summary>
    /// 获取PlcId列表
    /// </summary>
    /// <returns></returns>
@@ -199,5 +191,34 @@
        await _wcsDeviceRep.Context.Insertable(listPosition).ExecuteCommandAsync();
    }
    /// <summary>
    /// 获取设备信息列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "List")]
    [DisplayName("获取设备信息列表")]
    public async Task<List<WcsDeviceOutput>> List([FromQuery] PageWcsDeviceInput input)
    {
        var list = await _wcsDeviceRep.AsQueryable()
                                    .LeftJoin<WcsPlc>((a, b) => a.PlcId == b.Id)
                                    .Select<WcsDeviceOutput>((a, b) => new WcsDeviceOutput() { Type = b.Type }, true)
                                    .ToListAsync();
        //获取跺机的状态
        foreach (var modDevice in list)
        {
            if (_sysCacheService.ExistKey("PlcConn" + modDevice.PlcId))
            {
                var cachePlc = _sysCacheService.Get<WcsPlc>("PlcConn" + modDevice.PlcId);
                modDevice.Status = cachePlc.IsConn;
            }
            else
            {
                modDevice.Status = false;
            }
        }
        return list;
    }
}