| | |
| | | // Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。 |
| | | // |
| | | // 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。 |
| | | // |
| | | // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! |
| | | |
| | | |
| | | using Admin.NET.Core.Service; |
| | | using Microsoft.AspNetCore.Http; |
| | | |
| | | namespace WCS.Application; |
| | | |
| | | /// <summary> |
| | |
| | | public class WcsPlcService : IDynamicApiController, ITransient |
| | | { |
| | | private readonly SqlSugarRepository<WcsPlc> _wcsPlcRep; |
| | | public WcsPlcService(SqlSugarRepository<WcsPlc> wcsPlcRep) |
| | | private readonly SysCacheService _sysCacheService; |
| | | public WcsPlcService(SqlSugarRepository<WcsPlc> wcsPlcRep, SysCacheService sysCacheService) |
| | | { |
| | | _wcsPlcRep = wcsPlcRep; |
| | | _sysCacheService = sysCacheService; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | [DisplayName("分页查询PLC")] |
| | | public async Task<SqlSugarPagedList<WcsPlcOutput>> Page(PageWcsPlcInput input) |
| | | { |
| | | input.SearchKey = input.SearchKey?.Trim(); |
| | | input.SearchKey = input.SearchKey?.Trim(); |
| | | var query = _wcsPlcRep.AsQueryable() |
| | | .WhereIF(!string.IsNullOrEmpty(input.SearchKey), u => |
| | | u.IP.Contains(input.SearchKey) |
| | | ) |
| | | .WhereIF(input.PLCType.HasValue, u => u.PLCType == input.PLCType) |
| | | .WhereIF(!string.IsNullOrWhiteSpace(input.IP), u => u.IP.Contains(input.IP.Trim())) |
| | | .WhereIF(input.Type.HasValue, u => u.Type == input.Type) |
| | | .Select<WcsPlcOutput>(); |
| | | return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize); |
| | | return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | return await _wcsPlcRep.AsQueryable().Select<WcsPlcOutput>().ToListAsync(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取PLC连接状态和服务状态 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | [HttpGet] |
| | | [ApiDescriptionSettings(Name = "ListStatus")] |
| | | [DisplayName("获取PLC连接状态")] |
| | | public async Task<dynamic> ListStatus([FromQuery] PageWcsPlcInput input) |
| | | { |
| | | var listPlc = await _wcsPlcRep.AsQueryable() |
| | | .Where(s => s.Type == PLCTypeEnum.StackingMachine || s.Type == PLCTypeEnum.ConveyorLine || s.Type == PLCTypeEnum.BoxConveyorLine) |
| | | .ToListAsync(); |
| | | foreach (var modPlc in listPlc) |
| | | { |
| | | if (_sysCacheService.ExistKey("PLCCONN:" + modPlc.Id)) |
| | | { |
| | | var cachePlc = _sysCacheService.Get<WcsPlc>("PLCCONN:" + modPlc.Id); |
| | | modPlc.IsConn = cachePlc.IsConn; |
| | | } |
| | | else |
| | | { |
| | | modPlc.IsConn = false; |
| | | } |
| | | } |
| | | //服务状态 |
| | | var modService = new { PLCTaskAction.boRunningState, PLCTaskAction.boOffline, PLCTaskAction.boRefresh }; |
| | | return new { listPlc, modService }; |
| | | } |
| | | /// <summary> |
| | | /// 获取位置信息 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpGet] |
| | | [ApiDescriptionSettings(Name = "ListPosition")] |
| | | [DisplayName("获取位置信息")] |
| | | public List<PlcPositionInfo> ListPosition() |
| | | { |
| | | //测试用 |
| | | //return new List<PlcPositionInfo>() |
| | | //{ |
| | | // new PlcPositionInfo(){ Type=PLCTypeEnum.ConveyorLine, StationNum="147", BoHaveItem=true }, |
| | | // new PlcPositionInfo(){ Type=PLCTypeEnum.ConveyorLine, StationNum="143", BoHaveItem=true }, |
| | | |
| | | // new PlcPositionInfo(){ Type=PLCTypeEnum.StackingMachine, StationNum="002", BoxHeight=30 }, |
| | | //}; |
| | | |
| | | |
| | | |
| | | var list = PLCTaskAction.listPositionInfo.ToList(); |
| | | return list; |
| | | } |
| | | } |