using Microsoft.Extensions.Logging; using SlnMesnac.Common; using SlnMesnac.Model.AirportApiEntity; using SlnMesnac.Model.domain; using SlnMesnac.Model.Enum; using SlnMesnac.Repository.service.@base; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; namespace SlnMesnac.Repository.service.Impl { public class AGVStateServiceImpl : BaseServiceImpl, IAGVStateService { private ILogger _logger; public AGVStateServiceImpl(Repository repository, ILogger logger) : base(repository) { _logger = logger; } /// /// 查询指定类型AGV状态 /// /// /// public List GetAgvState(AgvType AgvType) { string _AgvType = Convert.ToString(((int)AgvType).ToString()); List agvStateInfoList = null; try { Expression> exp = x => true; exp = exp.And(x => (x.agvno != null || x.agvno != "") && (x.taskno == null || x.taskno == "") && x.agvworkstate == "空闲" && x.agvalarmstate == "正常" && x.agvtype == _AgvType); agvStateInfoList = base._rep.GetList(exp); } catch (Exception ex) { _logger.LogError($"AGV状态获取错误:{ex.Message}"); } return agvStateInfoList; } /// /// 查询所有AGV状态信息 /// /// public List GetAllAGVState() { List agvStateInfoList = null; try { agvStateInfoList = base._rep.GetList(); } catch (Exception ex) { _logger.LogError($"所有AGV状态获取错误:{ex.Message}"); } return agvStateInfoList; } /// /// 更新AGV设备状态信息 /// /// /// public async Task UpdateAsync(AGVState record) { bool result = await _rep.UpdateAsync(record); return result; } /// /// 如有记录则更新,无记录则添加信息 /// /// /// public async Task UpdateOrAddRecords(List records) { bool result = true; try { var list = GetAllAGVState(); foreach (var r in records) { if (list.Where(x => x.agvno == r.agvno).Count() == 0) { if (!_rep.Insert(r)) { result = false; } } else { r.id = list.Where(x => x.agvno == r.agvno).First().id; result = await _rep.UpdateAsync(r); } } } catch (Exception ex) { _logger.LogError($"AGV状态更新错误:{ex.Message}"); return false; } return result; } /// /// 删除AGV状态信息 /// /// /// public bool DeleteAGVStateByID(int id) { try { return _rep.DeleteById(id); } catch(Exception ex) { _logger.LogError("AGV状态删除错误:" + ex.Message); return false; } } /// /// 查询指定AGV信息 /// /// /// public AGVState GetSingleAGVState(string AGVguid) { try { return _rep.GetList(x => x.agvno == AGVguid).First(); } catch (Exception ex) { _logger.LogError("AGV状态查询错误:" + ex.Message); return null; } } } }