add - 新增地图点位,AGV设置数据库匹配数据库实体类,操作类,优化业务类结构

master
SoulStar 4 months ago
parent 44881027dc
commit 2ac2a9ed83

@ -0,0 +1,35 @@
using Microsoft.Extensions.Logging;
using SlnMesnac.Repository.service;
using SlnMesnac.TouchSocket;
using System;
using System.Collections.Generic;
using System.Text;
namespace SlnMesnac.Business.@base
{
public class AirPortAGVMapPointBusiness
{
public class BaseStateRefreshBusiness
{
private ILogger<BaseStateRefreshBusiness> _logger;
private static BaseStateRefreshBusiness instance;
public BaseStateRefreshBusiness(ILogger<BaseStateRefreshBusiness> logger)
{
_logger = logger;
}
public static BaseStateRefreshBusiness GetInstance(ILogger<BaseStateRefreshBusiness> logger)
{
if (instance == null)
{
instance = new BaseStateRefreshBusiness(logger);
}
return instance;
}
}
}
}

@ -1,31 +1,35 @@
using Microsoft.Extensions.Logging;
using SlnMesnac.Model.AirportApiEntity;
using SlnMesnac.Repository;
using SlnMesnac.Repository.service;
using SlnMesnac.TouchSocket;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.Business.@base
{
public class BaseStateRefreshBusiness
{
private IAGVStateService _AGVStateService;
private IAGVSettingService _aGVSettingService;
private ILogger<BaseStateRefreshBusiness> _logger;
private static BaseStateRefreshBusiness instance;
private AirPorthttpClient _airPorthttpClient;
public BaseStateRefreshBusiness(ILogger<BaseStateRefreshBusiness> logger, IAGVStateService agvService, AirPorthttpClient airPorthttpClient)
public BaseStateRefreshBusiness(ILogger<BaseStateRefreshBusiness> logger, IAGVStateService agvService, AirPorthttpClient airPorthttpClient, IAGVSettingService aGVSettingService)
{
_logger = logger;
_AGVStateService = agvService;
_airPorthttpClient = airPorthttpClient;
_aGVSettingService = aGVSettingService;
}
public static BaseStateRefreshBusiness GetInstance(ILogger<BaseStateRefreshBusiness> logger, IAGVStateService agvService, AirPorthttpClient airPorthttpClient)
public static BaseStateRefreshBusiness GetInstance(ILogger<BaseStateRefreshBusiness> logger, IAGVStateService agvService, AirPorthttpClient airPorthttpClient, IAGVSettingService aGVSettingService)
{
if (instance == null)
{
instance = new BaseStateRefreshBusiness(logger, agvService, airPorthttpClient);
instance = new BaseStateRefreshBusiness(logger, agvService, airPorthttpClient, aGVSettingService);
}
return instance;
}
@ -34,7 +38,7 @@ namespace SlnMesnac.Business.@base
/// 调用接口更新所有AGV的状态
/// </summary>
/// <returns></returns>
public bool UpdateALLAGVStateByResposne()
public async Task<bool> UpdateALLAGVStateByResposne()
{
try
{
@ -43,14 +47,28 @@ namespace SlnMesnac.Business.@base
{
return false;
}
_AGVStateService.UpdateOrAddByResponse(response);
List<AGVState> records = new List<AGVState>();
foreach (var entity in response.Data)
{
AGVState record = new AGVState()
{
agvno = entity.Guid,
agvalarmstate = entity.AgvMoveStatus != 6 ? "正常" : "异常",
agvtype = _aGVSettingService.GetAgvSettingByID(entity.Guid),
agvworkstate = entity.AgvMoveStatus == 1 ? "空闲" : "忙碌",
refreshtime = DateTime.Now,
taskno = entity.TaskID,
};
records.Add(record);
}
return await _AGVStateService.UpdateOrAddRecords(records);
}
catch (Exception e)
{
_logger.LogError("Error:" + e);
return false;
}
return true;
}
}
}

@ -0,0 +1,38 @@
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
using System.Text;
namespace SlnMesnac.Repository.service
{
public interface IAGVMapPointService : IBaseService<AGVMapPoint>
{
/// <summary>
/// 获取所有AGV地图点位
/// </summary>
/// <returns></returns>
List<AGVMapPoint> GetAllMapPoint();
/// <summary>
/// 更新或添加地图点位列表
/// </summary>
/// <param name="records"></param>
/// <returns></returns>
bool RefreshOrAddAGVMapPoint(List<AGVMapPoint> records);
/// <summary>
/// 删除所有AGV点位
/// </summary>
/// <param name="aGVMapPoint"></param>
/// <returns></returns>
bool DeleteAllAGVMapPoint();
/// <summary>
/// 删除旧的点位,添加新的点位
/// </summary>
/// <param name="aGVMapPoint"></param>
/// <returns></returns>
bool DeleteAndAddAgvMapPoint(List<AGVMapPoint> aGVMapPoint);
}
}

@ -4,6 +4,7 @@ using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.Repository.service
{
@ -14,5 +15,26 @@ namespace SlnMesnac.Repository.service
/// </summary>
/// <returns></returns>
List<AGVSetting> GetAllAgvSetting();
/// <summary>
/// 根据AGVID获取AGV类型
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
string GetAgvSettingByID(string id);
/// <summary>
/// 插入AGV设置
/// </summary>
/// <param name="agvSetting"></param>
/// <returns></returns>
bool InsertAgvSetting(AGVSetting agvSetting);
/// <summary>
/// 根据ID删除AGV设置
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
bool DeleteAgvSettingByID(int id);
}
}

@ -12,7 +12,7 @@ namespace SlnMesnac.Repository.service
public interface IAGVStateService: IBaseService<AGVState>
{
/// <summary>
/// 查询AGV状态
/// 查询指定类型AGV状态
/// </summary>
/// <returns></returns>
List<AGVState> GetAgvState(AgvType AgvType);
@ -31,11 +31,18 @@ namespace SlnMesnac.Repository.service
List<AGVState> GetAllAGVState();
/// <summary>
/// 根据响应数据插入或更新数据
/// 如有记录则更新,无记录则添加信息
/// </summary>
/// <param name="response"></param>
/// <returns></returns>
Task<bool> UpdateOrAddByResponse(AGVResponseEntity<List<ResponseRobotAtrributeDataEntity>> response);
Task<bool> UpdateOrAddRecords(List<AGVState> records);
/// <summary>
/// 删除AGV状态信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
bool DeleteAGVStateByID(int id);
}
}

@ -0,0 +1,120 @@
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;
}
}
}
}

@ -3,7 +3,9 @@ using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.Repository.service.Impl
{
@ -15,12 +17,16 @@ namespace SlnMesnac.Repository.service.Impl
_logger = logger;
}
/// <summary>
/// 获取所有AGV设置
/// </summary>
/// <returns></returns>
public List<AGVSetting> GetAllAgvSetting()
{
List<AGVSetting> agvSettingList = null;
try
{
agvSettingList = base._rep.GetList();
agvSettingList = _rep.GetList();
}
catch (Exception ex)
{
@ -28,5 +34,60 @@ namespace SlnMesnac.Repository.service.Impl
}
return agvSettingList;
}
/// <summary>
/// 根据AGVID获取AGV类型
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public string GetAgvSettingByID(string id)
{
try
{
List<AGVSetting> list = _rep.GetList();
return list.Where(x => x.AGVNo == id).First().AGVType;
}
catch(Exception ex)
{
_logger.LogError("根据AGVID获取AGV类型异常" + ex.Message);
return "";
}
}
/// <summary>
/// 插入AGV设置
/// </summary>
/// <param name="agvSetting"></param>
/// <returns></returns>
public bool InsertAgvSetting(AGVSetting agvSetting)
{
try
{
return _rep.Insert(agvSetting);
}
catch(Exception ex)
{
_logger.LogError("插入新的AGV设置异常" + ex.Message);
return false;
}
}
/// <summary>
/// 根据ID删除AGV设置
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool DeleteAgvSettingByID(int id)
{
try
{
return _rep.DeleteById(id);
}
catch (Exception ex)
{
_logger.LogError("插入新的AGV设置");
return false;
}
}
}
}

@ -20,6 +20,11 @@ namespace SlnMesnac.Repository.service.Impl
_logger = logger;
}
/// <summary>
/// 查询指定类型AGV状态
/// </summary>
/// <param name="AgvType"></param>
/// <returns></returns>
public List<AGVState> GetAgvState(AgvType AgvType)
{
string _AgvType = Convert.ToString(((int)AgvType).ToString());
@ -43,6 +48,10 @@ namespace SlnMesnac.Repository.service.Impl
return agvStateInfoList;
}
/// <summary>
/// 查询所有AGV状态信息
/// </summary>
/// <returns></returns>
public List<AGVState> GetAllAGVState()
{
List<AGVState> agvStateInfoList = null;
@ -57,6 +66,11 @@ namespace SlnMesnac.Repository.service.Impl
return agvStateInfoList;
}
/// <summary>
/// 更新AGV设备状态信息
/// </summary>
/// <param name="record"></param>
/// <returns></returns>
public async Task<bool> UpdateAsync(AGVState record)
{
bool result = await _rep.UpdateAsync(record);
@ -64,28 +78,13 @@ namespace SlnMesnac.Repository.service.Impl
}
/// <summary>
/// 根据响应数据更新AGV状态
/// 如有记录则更新,无记录则添加信息
/// </summary>
/// <param name="response"></param>
/// <param name="records"></param>
/// <returns></returns>
public async Task<bool> UpdateOrAddByResponse(AGVResponseEntity<List<ResponseRobotAtrributeDataEntity>> response)
public async Task<bool> UpdateOrAddRecords(List<AGVState> records)
{
List<AGVState> records = new List<AGVState>();
foreach (var entity in response.Data)
{
AGVState record = new AGVState()
{
agvno = entity.Guid,
agvalarmstate = entity.AgvMoveStatus != 6 ? "正常" : "异常",
agvtype = entity.Name,
agvworkstate = entity.AgvMoveStatus == 1 ? "空闲" : "忙碌",
refreshtime = DateTime.Now,
taskno = entity.TaskID,
};
records.Add(record);
}
bool result = false;
bool result = true;
try
{
var list = GetAllAGVState();
@ -93,11 +92,14 @@ namespace SlnMesnac.Repository.service.Impl
{
if (list.Where(x => x.agvno == r.agvno).Count() == 0)
{
result = _rep.Insert(r);
if (!_rep.Insert(r))
{
result = false;
}
}
else
{
r.id = list.Where(x => x.agvno == r.agvno).FirstOrDefault().id;
r.id = list.Where(x => x.agvno == r.agvno).First().id;
result = await _rep.UpdateAsync(r);
}
}
@ -105,8 +107,27 @@ namespace SlnMesnac.Repository.service.Impl
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;
}
}
}
}
Loading…
Cancel
Save