You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
4.5 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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<AGVState>, IAGVStateService
{
private ILogger<AGVStateServiceImpl> _logger;
public AGVStateServiceImpl(Repository<AGVState> repository, ILogger<AGVStateServiceImpl> logger) : base(repository)
{
_logger = logger;
}
/// <summary>
/// 查询指定类型AGV状态
/// </summary>
/// <param name="AgvType"></param>
/// <returns></returns>
public List<AGVState> GetAgvState(AgvType AgvType)
{
string _AgvType = Convert.ToString(((int)AgvType).ToString());
List<AGVState> agvStateInfoList = null;
try
{
Expression<Func<AGVState, bool>> 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;
}
/// <summary>
/// 查询所有AGV状态信息
/// </summary>
/// <returns></returns>
public List<AGVState> GetAllAGVState()
{
List<AGVState> agvStateInfoList = null;
try
{
agvStateInfoList = base._rep.GetList();
}
catch (Exception ex)
{
_logger.LogError($"所有AGV状态获取错误:{ex.Message}");
}
return agvStateInfoList;
}
/// <summary>
/// 更新AGV设备状态信息
/// </summary>
/// <param name="record"></param>
/// <returns></returns>
public async Task<bool> UpdateAsync(AGVState record)
{
bool result = await _rep.UpdateAsync(record);
return result;
}
/// <summary>
/// 如有记录则更新,无记录则添加信息
/// </summary>
/// <param name="records"></param>
/// <returns></returns>
public async Task<bool> UpdateOrAddRecords(List<AGVState> 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;
}
/// <summary>
/// 删除AGV状态信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool DeleteAGVStateByID(int id)
{
try
{
return _rep.DeleteById(id);
}
catch(Exception ex)
{
_logger.LogError("AGV状态删除错误" + ex.Message);
return false;
}
}
/// <summary>
/// 查询指定AGV信息
/// </summary>
/// <param name="AGVguid"></param>
/// <returns></returns>
public AGVState GetSingleAGVState(string AGVguid)
{
try
{
return _rep.GetList(x => x.agvno == AGVguid).First();
}
catch (Exception ex)
{
_logger.LogError("AGV状态查询错误" + ex.Message);
return null;
}
}
}
}