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; } 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 == null || x.agvalarmstate == "") && x.agvtype == _AgvType); agvStateInfoList = base._rep.GetList(exp); } catch (Exception ex) { _logger.LogError($"��ȡ����AGV��Ϣ�쳣:{ex.Message}"); } return agvStateInfoList; } public List GetAllAGVState() { List agvStateInfoList = null; try { agvStateInfoList = base._rep.GetList(); } catch (Exception ex) { _logger.LogError($"��ȡ����AGV��Ϣ�쳣:{ex.Message}"); } return agvStateInfoList; } public async Task UpdateAsync(AGVState record) { bool result = await _rep.UpdateAsync(record); return result; } public async Task UpdateOrAddByResponse(AGVStateResponseEntity response) { AGVState record = new AGVState() { agvno = response.AGVNo, agvalarmstate = response.AGVAlarmState, agvtype = response.AGVType, agvworkstate = response.AGVWorkState, refreshtime = DateTime.Now, taskno = response.TaskNo, }; bool result = false; try { var list = GetAllAGVState(); if (list.Where(x => x.agvno == response.AGVNo).Count() == 0) { result = _rep.Insert(record); } else { record.id = list.Where(x => x.agvno == response.AGVNo).FirstOrDefault().id; result = await _rep.UpdateAsync(record); } } catch (Exception ex) { _logger.LogError($"��е��״̬��Ϣ�����쳣:{ex.Message}"); } return result; } } }