diff --git a/SlnMesnac.Business/base/AirPortAGVMapPointBusiness.cs b/SlnMesnac.Business/base/AirPortAGVMapPointBusiness.cs new file mode 100644 index 0000000..16e0fe0 --- /dev/null +++ b/SlnMesnac.Business/base/AirPortAGVMapPointBusiness.cs @@ -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 _logger; + private static BaseStateRefreshBusiness instance; + + public BaseStateRefreshBusiness(ILogger logger) + { + _logger = logger; + + } + + public static BaseStateRefreshBusiness GetInstance(ILogger logger) + { + if (instance == null) + { + instance = new BaseStateRefreshBusiness(logger); + } + return instance; + } + + + } + } +} diff --git a/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs b/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs index e31ff74..2937d39 100644 --- a/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs +++ b/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs @@ -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 _logger; private static BaseStateRefreshBusiness instance; private AirPorthttpClient _airPorthttpClient; - public BaseStateRefreshBusiness(ILogger logger, IAGVStateService agvService, AirPorthttpClient airPorthttpClient) + public BaseStateRefreshBusiness(ILogger logger, IAGVStateService agvService, AirPorthttpClient airPorthttpClient, IAGVSettingService aGVSettingService) { _logger = logger; _AGVStateService = agvService; _airPorthttpClient = airPorthttpClient; + _aGVSettingService = aGVSettingService; } - public static BaseStateRefreshBusiness GetInstance(ILogger logger, IAGVStateService agvService, AirPorthttpClient airPorthttpClient) + public static BaseStateRefreshBusiness GetInstance(ILogger 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的状态 /// /// - public bool UpdateALLAGVStateByResposne() + public async Task UpdateALLAGVStateByResposne() { try { @@ -43,14 +47,28 @@ namespace SlnMesnac.Business.@base { return false; } - _AGVStateService.UpdateOrAddByResponse(response); + + List records = new List(); + 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; } - } } diff --git a/SlnMesnac.Repository/service/IAGVMapPointService.cs b/SlnMesnac.Repository/service/IAGVMapPointService.cs new file mode 100644 index 0000000..0332892 --- /dev/null +++ b/SlnMesnac.Repository/service/IAGVMapPointService.cs @@ -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 + { + /// + /// 获取所有AGV地图点位 + /// + /// + List GetAllMapPoint(); + + /// + /// 更新或添加地图点位列表 + /// + /// + /// + bool RefreshOrAddAGVMapPoint(List records); + + /// + /// 删除所有AGV点位 + /// + /// + /// + bool DeleteAllAGVMapPoint(); + + /// + /// 删除旧的点位,添加新的点位 + /// + /// + /// + bool DeleteAndAddAgvMapPoint(List aGVMapPoint); + } +} diff --git a/SlnMesnac.Repository/service/IAGVSettingService.cs b/SlnMesnac.Repository/service/IAGVSettingService.cs index d974188..22cd5fe 100644 --- a/SlnMesnac.Repository/service/IAGVSettingService.cs +++ b/SlnMesnac.Repository/service/IAGVSettingService.cs @@ -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 /// /// List GetAllAgvSetting(); + + /// + /// 根据AGVID获取AGV类型 + /// + /// + /// + string GetAgvSettingByID(string id); + + /// + /// 插入AGV设置 + /// + /// + /// + bool InsertAgvSetting(AGVSetting agvSetting); + + /// + /// 根据ID删除AGV设置 + /// + /// + /// + bool DeleteAgvSettingByID(int id); } } diff --git a/SlnMesnac.Repository/service/IAGVStateService.cs b/SlnMesnac.Repository/service/IAGVStateService.cs index a037ca9..ba49b15 100644 --- a/SlnMesnac.Repository/service/IAGVStateService.cs +++ b/SlnMesnac.Repository/service/IAGVStateService.cs @@ -12,7 +12,7 @@ namespace SlnMesnac.Repository.service public interface IAGVStateService: IBaseService { /// - /// ѯAGV״̬ + /// ѯָAGV״̬ /// /// List GetAgvState(AgvType AgvType); @@ -31,11 +31,18 @@ namespace SlnMesnac.Repository.service List GetAllAGVState(); /// - /// Ӧݲ + /// м¼£޼¼Ϣ /// /// /// - Task UpdateOrAddByResponse(AGVResponseEntity> response); + Task UpdateOrAddRecords(List records); + + /// + /// ɾAGV״̬Ϣ + /// + /// + /// + bool DeleteAGVStateByID(int id); } } \ No newline at end of file diff --git a/SlnMesnac.Repository/service/Impl/AGVMapPointServiceImpl.cs b/SlnMesnac.Repository/service/Impl/AGVMapPointServiceImpl.cs new file mode 100644 index 0000000..a5f29c2 --- /dev/null +++ b/SlnMesnac.Repository/service/Impl/AGVMapPointServiceImpl.cs @@ -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, IAGVMapPointService + { + private ILogger _logger; + public AGVMapPointServiceImpl(Repository repository, ILogger logger) : base(repository) + { + _logger = logger; + } + + /// + /// 获取所有AGV地图点位 + /// + /// + public List GetAllMapPoint() + { + try + { + List aGVMapPoints = _rep.GetList(); + return aGVMapPoints; + } + catch(Exception ex) + { + _logger.LogError("获取所有AGV点位错误:" + ex.Message); + return null; + } + } + + /// + /// 更新或添加地图点位列表 + /// + /// + /// + public bool RefreshOrAddAGVMapPoint(List 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; + } + + /// + /// 删除所有AGV点位 + /// + /// + /// + public bool DeleteAllAGVMapPoint() + { + try + { + var list = GetAllMapPoint(); + return _rep.Delete(list); + } + catch (Exception ex) + { + _logger.LogError("删除所有AGV点位:" + ex.Message); + return false; + } + } + + /// + /// 删除旧的点位,添加新的点位 + /// + /// + /// + public bool DeleteAndAddAgvMapPoint(List aGVMapPoint) + { + try + { + var list = GetAllMapPoint(); + if (!DeleteAllAGVMapPoint()) + { + return false; + } + return _rep.InsertRange(aGVMapPoint); + + } + catch (Exception ex) + { + _logger.LogError("删除旧的点位,添加新的点位:" + ex.Message); + return false; + } + } + } +} diff --git a/SlnMesnac.Repository/service/Impl/AGVSettingServiceImpl.cs b/SlnMesnac.Repository/service/Impl/AGVSettingServiceImpl.cs index 88b2d26..1975eef 100644 --- a/SlnMesnac.Repository/service/Impl/AGVSettingServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/AGVSettingServiceImpl.cs @@ -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; } + /// + /// 获取所有AGV设置 + /// + /// public List GetAllAgvSetting() { List agvSettingList = null; try { - agvSettingList = base._rep.GetList(); + agvSettingList = _rep.GetList(); } catch (Exception ex) { @@ -28,5 +34,60 @@ namespace SlnMesnac.Repository.service.Impl } return agvSettingList; } + + /// + /// 根据AGVID获取AGV类型 + /// + /// + /// + public string GetAgvSettingByID(string id) + { + try + { + List list = _rep.GetList(); + return list.Where(x => x.AGVNo == id).First().AGVType; + } + catch(Exception ex) + { + _logger.LogError("根据AGVID获取AGV类型异常" + ex.Message); + return ""; + } + } + + /// + /// 插入AGV设置 + /// + /// + /// + public bool InsertAgvSetting(AGVSetting agvSetting) + { + try + { + return _rep.Insert(agvSetting); + } + catch(Exception ex) + { + _logger.LogError("插入新的AGV设置异常" + ex.Message); + return false; + } + } + + /// + /// 根据ID删除AGV设置 + /// + /// + /// + public bool DeleteAgvSettingByID(int id) + { + try + { + return _rep.DeleteById(id); + } + catch (Exception ex) + { + _logger.LogError("插入新的AGV设置"); + return false; + } + } } } diff --git a/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs b/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs index c69eace..032dbf7 100644 --- a/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs @@ -20,6 +20,11 @@ namespace SlnMesnac.Repository.service.Impl _logger = logger; } + /// + /// 查询指定类型AGV状态 + /// + /// + /// public List GetAgvState(AgvType AgvType) { string _AgvType = Convert.ToString(((int)AgvType).ToString()); @@ -43,6 +48,10 @@ namespace SlnMesnac.Repository.service.Impl return agvStateInfoList; } + /// + /// 查询所有AGV状态信息 + /// + /// public List GetAllAGVState() { List agvStateInfoList = null; @@ -57,6 +66,11 @@ namespace SlnMesnac.Repository.service.Impl return agvStateInfoList; } + /// + /// 更新AGV设备状态信息 + /// + /// + /// public async Task UpdateAsync(AGVState record) { bool result = await _rep.UpdateAsync(record); @@ -64,28 +78,13 @@ namespace SlnMesnac.Repository.service.Impl } /// - /// 根据响应数据更新AGV状态 + /// 如有记录则更新,无记录则添加信息 /// - /// + /// /// - public async Task UpdateOrAddByResponse(AGVResponseEntity> response) + public async Task UpdateOrAddRecords(List records) { - List records = new List(); - 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; } + + /// + /// 删除AGV状态信息 + /// + /// + /// + public bool DeleteAGVStateByID(int id) + { + try + { + return _rep.DeleteById(id); + } + catch(Exception ex) + { + _logger.LogError("AGV状态删除错误:" + ex.Message); + return false; + } + } } } \ No newline at end of file