using Microsoft.Extensions.Logging; using SlnMesnac.Common; using SlnMesnac.Model.AirportApiEntity; using SlnMesnac.Model.domain; using SlnMesnac.Repository.service.@base; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; namespace SlnMesnac.Repository.service.Impl { public class ManipulatorStateServiceImpl : BaseServiceImpl, IManipulatorStateService { private ILogger _logger; public ManipulatorStateServiceImpl(Repository rep, ILogger logger) : base(rep) { _logger = logger; } public List GetAllManipulatorState() { var list = new List(); try { list = base._rep.GetList(); } catch (Exception ex) { _logger.LogError($"所有机械臂状态信息获取异常:{ex.Message}"); } return list; } public List GetFreeManipulatorState() { var list = new List(); try { list = base._rep.GetList() .Where(x => x.ManipulatorNo != "" && (x.TaskNo == null || x.TaskNo == "") && x.ManipulatorWorkState == "任务空闲") .ToList(); } catch (Exception ex) { _logger.LogError($"空闲机械臂状态信息获取异常:{ex.Message}"); } return list; } public async Task UpdateAsync(ManipulatorState record) { bool result = await _rep.UpdateAsync(record); return result; } public async Task UpdateOrAddByResponse(ManipulatorStateResponseEntity response) { ManipulatorState record = new ManipulatorState() { ManipulatorNo = response.ManipulatorNo, ManipulatorAlarmState = response.ManipulatorAlarmState, ManipulatorWorkState = response.ManipulatorWorkState, TaskNo = response.TaskNo, RefreshTime = DateTime.Now, }; bool result = false; try { var list = GetAllManipulatorState(); if (list.Where(x => x.ManipulatorNo == response.ManipulatorNo).Count() == 0) { result = _rep.Insert(record); } else { record.ID = list.Where(x => x.ManipulatorNo == response.ManipulatorNo).FirstOrDefault().ID; result = await _rep.UpdateAsync(record); } } catch(Exception ex) { _logger.LogError($"机械臂状态信息更新异常:{ex.Message}"); } return result; } } }