|
|
using Microsoft.Extensions.Logging;
|
|
|
using SlnMesnac.Model.domain;
|
|
|
using SlnMesnac.Repository.service.@base;
|
|
|
using SqlSugar;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
|
|
|
namespace SlnMesnac.Repository.service.Impl
|
|
|
{
|
|
|
public class AGVMapPointServiceImpl : BaseServiceImpl<AGVMapPoint>, IAGVMapPointService
|
|
|
{
|
|
|
private ILogger<AGVMapPointServiceImpl> _logger;
|
|
|
public AGVMapPointServiceImpl(Repository<AGVMapPoint> repository, ILogger<AGVMapPointServiceImpl> logger) : base(repository)
|
|
|
{
|
|
|
_logger = logger;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取所有AGV地图点位
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public List<AGVMapPoint> GetAllMapPoint()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
List<AGVMapPoint> aGVMapPoints = _rep.GetList();
|
|
|
return aGVMapPoints;
|
|
|
}
|
|
|
catch(Exception ex)
|
|
|
{
|
|
|
_logger.LogError("获取所有AGV点位错误:" + ex.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新或添加地图点位列表
|
|
|
/// </summary>
|
|
|
/// <param name="records"></param>
|
|
|
/// <returns></returns>
|
|
|
public bool RefreshOrAddAGVMapPoint(List<AGVMapPoint> records)
|
|
|
{
|
|
|
bool result = true;
|
|
|
try
|
|
|
{
|
|
|
var list = GetAllMapPoint();
|
|
|
if(list == null)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
foreach (var r in records)
|
|
|
{
|
|
|
if (list.Where(x => x.PointGuid == r.PointGuid).Count() == 0)
|
|
|
{
|
|
|
if (!_rep.Insert(r))
|
|
|
{
|
|
|
result = false;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
r.ID = list.Where(x => x.PointGuid == r.PointGuid).First().ID;
|
|
|
result = _rep.Update(r);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
_logger.LogError("更新或添加地图点位列表:" + ex.Message);
|
|
|
return false;
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除所有AGV点位
|
|
|
/// </summary>
|
|
|
/// <param name="aGVMapPoint"></param>
|
|
|
/// <returns></returns>
|
|
|
public bool DeleteAllAGVMapPoint()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var list = GetAllMapPoint();
|
|
|
return _rep.Delete(list);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
_logger.LogError("删除所有AGV点位:" + ex.Message);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除旧的点位,添加新的点位
|
|
|
/// </summary>
|
|
|
/// <param name="aGVMapPoint"></param>
|
|
|
/// <returns></returns>
|
|
|
public bool DeleteAndAddAgvMapPoint(List<AGVMapPoint> aGVMapPoint)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var list = GetAllMapPoint();
|
|
|
if (!DeleteAllAGVMapPoint())
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
return _rep.InsertRange(aGVMapPoint);
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
_logger.LogError("删除旧的点位,添加新的点位:" + ex.Message);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|