| | |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using AutoMapper; |
| | | using Magicodes.ExporterAndImporter.Core; |
| | | using Microsoft.AspNetCore.Mvc.RazorPages; |
| | | using NetTaste; |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using HslCommunication.WebSocket; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Diagnostics; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.Linq; |
| | | using System.Linq.Expressions; |
| | | using System.Reflection; |
| | | using System.Reflection.Metadata; |
| | | using System.Security.Policy; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Xml.Linq; |
| | | using WIDESEA_Common.Log; |
| | | using WIDESEAWCS_BasicInfoRepository; |
| | | using WIDESEAWCS_BasicInfoService; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.Utilities; |
| | | using WIDESEAWCS_DTO.Enum; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Repository; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | |
| | | namespace WIDESEAWCS_TaskInfoService |
| | | { |
| | |
| | | private readonly IMapper _mapper; |
| | | private readonly IContainerRepository _containerRepository; |
| | | private readonly IContainerItemRepository _containerItemRepository; |
| | | private readonly IDeviceInfoRepository _deviceInfoRepository; |
| | | private readonly WebSocketServer _webSocketServer; |
| | | private readonly IOrderDetailsRepository _orderDetailsRepository; |
| | | |
| | | public TaskService(ITaskRepository BaseDal, IMapper mapper, IContainerRepository containerRepository, IContainerItemRepository containerItemRepository, IDeviceInfoRepository deviceInfoRepository) : base(BaseDal) |
| | | public TaskService(ITaskRepository BaseDal, IMapper mapper, IContainerRepository containerRepository, IContainerItemRepository containerItemRepository, WebSocketServer webSocketServer, IOrderDetailsRepository orderDetailsRepository) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _containerRepository = containerRepository; |
| | | _containerItemRepository = containerItemRepository; |
| | | _deviceInfoRepository = deviceInfoRepository; |
| | | _webSocketServer = webSocketServer; |
| | | _orderDetailsRepository = orderDetailsRepository; |
| | | } |
| | | |
| | | public Dt_Task? QueryAGantryUnExecuteTask(string gantryDeviceNo) |
| | | { |
| | | return BaseDal.QueryFirst(x => x.TaskState == (int)TaskStatusEnum.Gantry_New && x.DeviceCode == gantryDeviceNo); |
| | | } |
| | | |
| | | public WebResponseContent PlaceBlockTest(int orderRowId) |
| | | { |
| | | try |
| | | { |
| | | List<OrderDetails> orderDetails = _orderDetailsRepository.QueryData(x => x.Orderrowsid == orderRowId); |
| | | if (orderDetails == null || orderDetails.Count == 0) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°è®¢åæç»ä¿¡æ¯"); |
| | | } |
| | | |
| | | Dt_Container putContainer = _containerRepository.QueryFirst(x => x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt()); |
| | | if (putContainer == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æ¾è´§ä½ç½®ä¸åå¨"); |
| | | } |
| | | |
| | | ContainerSize containerSize = new ContainerSize(1500, putContainer.ContainerWidth, putContainer.ContainerHeight); |
| | | List<PlacedBlock> placedBlocks = new List<PlacedBlock>(); |
| | | |
| | | for (int i = 0; i < orderDetails.Count; i++) |
| | | { |
| | | try |
| | | { |
| | | lock (placedBlocks) |
| | | { |
| | | int length = Convert.ToInt32(orderDetails[i].Orderdetails_length); |
| | | int width = Convert.ToInt32(orderDetails[i].Orderdetails_width); |
| | | int height = Convert.ToInt32(orderDetails[i].Orderdetails_thickness); |
| | | |
| | | TaskPosition taskPosition = new TaskPosition(); |
| | | taskPosition = GetTakePutPosition(length, width, height, containerSize, placedBlocks); |
| | | |
| | | PlacedBlock placedBlock = new PlacedBlock(new Point3D(taskPosition.PositionX, taskPosition.PositionY, taskPosition.PositionZ), length, width, height); |
| | | placedBlocks.Add(placedBlock); |
| | | |
| | | object obj = new |
| | | { |
| | | x = taskPosition.PutCenterPositionX - containerSize.Length / 2, |
| | | y = taskPosition.PutCenterPositionY - containerSize.Width / 2, |
| | | z = taskPosition.PutCenterPositionZ, |
| | | length, |
| | | width, |
| | | height, |
| | | }; |
| | | |
| | | _webSocketServer.PublishAllClientPayload(obj.Serialize()); |
| | | |
| | | Thread.Sleep(100); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | } |
| | | } |
| | | return WebResponseContent.Instance.OK(data: placedBlocks); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public TaskPosition GetTakePutPosition(int length, int width, int height, ContainerSize containerSize, List<PlacedBlock> placedBlocks) |
| | | { |
| | | try |
| | | { |
| | | PlaceBlockService placeBlockService = new PlaceBlockService(containerSize, placedBlocks); |
| | | |
| | | Point3D? point3D = placeBlockService.PlaceBlock(length, width, height); |
| | | if (point3D == null) |
| | | { |
| | | throw new Exception("æ¾è´§ä½ç½®å·²æ»¡"); |
| | | } |
| | | |
| | | //æ¾è´§ä½ç½®æ¿æä¸å¿ç¹ |
| | | Point3D putCenter = new Point3D(point3D.Value.X + length / 2, point3D.Value.Y + width / 2, point3D.Value.Z + height / 2); |
| | | |
| | | //åè´§ä½ç½®æ¿æä¸å¿ç¹ |
| | | Point3D takeCenter = new Point3D(length / 2, width / 2, height / 2); |
| | | |
| | | //å¸çé¿530 é´é660 æå¤§920 å¸ç宽130 |
| | | |
| | | int positionR = 1; |
| | | |
| | | int takePositionX = 0; |
| | | int takePositionY = 0; |
| | | int takePositionZ = 0; |
| | | int putPositionX = 0; |
| | | int putPositionY = 0; |
| | | int putPositionZ = 0; |
| | | |
| | | //1.妿é¿åº¦å¤§äº920ï¼å®½åº¦å¤§äºçäº300ï¼åå¯ä»¥ä½¿ç¨åå¸ç横åå¸å |
| | | if (length > 920 && width >= 300) |
| | | { |
| | | // |
| | | Point3D deviceCenter = new Point3D(530 / 2, 920 / 2, 0); |
| | | |
| | | positionR = 1; |
| | | takePositionX = takeCenter.Y - deviceCenter.X; |
| | | takePositionY = takeCenter.X - deviceCenter.Y; |
| | | takePositionZ = 10; |
| | | |
| | | putPositionX = putCenter.Y - deviceCenter.X; |
| | | putPositionY = putCenter.X - deviceCenter.Y; |
| | | putPositionZ = point3D.Value.Z; // putCenter.Z /*+ 10*/; |
| | | } |
| | | else |
| | | { |
| | | positionR = 0; |
| | | Point3D deviceCenter = new Point3D(130 / 2, 530 / 2, 0); |
| | | takePositionX = takeCenter.Y - deviceCenter.X; |
| | | takePositionY = takeCenter.X - deviceCenter.Y; |
| | | takePositionZ = 10; |
| | | |
| | | putPositionX = putCenter.Y - deviceCenter.X; |
| | | putPositionY = putCenter.X - deviceCenter.Y; |
| | | putPositionZ = point3D.Value.Z; //putCenter.Z /*+ 10*/; |
| | | } |
| | | |
| | | TaskPosition taskPosition = new TaskPosition() |
| | | { |
| | | PositionR = positionR, |
| | | TakePositionX = takePositionX, |
| | | TakePositionY = takePositionY, |
| | | TakePositionZ = takePositionZ, |
| | | PutPositionX = putPositionX, |
| | | PutPositionY = putPositionY, |
| | | PutPositionZ = putPositionZ, |
| | | TakeCenterPositionX = takeCenter.X, |
| | | TakeCenterPositionY = takeCenter.Y, |
| | | TakeCenterPositionZ = takeCenter.Z, |
| | | PutCenterPositionX = putCenter.X, |
| | | PutCenterPositionY = putCenter.Y, |
| | | PutCenterPositionZ = putCenter.Z, |
| | | PositionX = point3D.Value.X, |
| | | PositionY = point3D.Value.Y, |
| | | PositionZ = point3D.Value.Z |
| | | }; |
| | | |
| | | return taskPosition; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent CreateTask(string takePosition, string putPosition, string deviceCode, int length, int width, int height) |
| | |
| | | |
| | | List<PlacedBlock> placedBlocks = containerItems.Select(x => new PlacedBlock(new Point3D(x.ItemPositionX, x.ItemPositionY, x.ItemPositionZ), x.ItemLength, x.ItemWidth, x.ItemHeight)).ToList(); |
| | | |
| | | PlaceBlockService placeBlockService = new PlaceBlockService(containerSize, placedBlocks); |
| | | |
| | | Point3D? point3D = placeBlockService.PlaceBlock(length, width, height); |
| | | if (point3D == null) |
| | | TaskPosition taskPosition = GetTakePutPosition(length, width, height, containerSize, placedBlocks); |
| | | |
| | | object obj = new |
| | | { |
| | | return WebResponseContent.Instance.Error("æ¾è´§ä½ç½®å·²æ»¡"); |
| | | } |
| | | x = taskPosition.PutCenterPositionX - putContainer.ContainerLength / 2, |
| | | y = taskPosition.PutCenterPositionY - putContainer.ContainerWidth / 2, |
| | | z = taskPosition.PutCenterPositionZ, |
| | | length, |
| | | width, |
| | | height, |
| | | }; |
| | | |
| | | _webSocketServer.PublishAllClientPayload(obj.Serialize()); |
| | | |
| | | string code = DateTime.Now.ToString("yyyyMMddHHmmss"); |
| | | |
| | | Dt_ContainerItem dt_ContainerItem = new Dt_ContainerItem() |
| | |
| | | ItemLength = length, |
| | | ItemWidth = width, |
| | | ItemHeight = height, |
| | | ItemPositionX = point3D.Value.X, |
| | | ItemPositionY = point3D.Value.Y, |
| | | ItemPositionZ = point3D.Value.Z, |
| | | ItemPositionX = taskPosition.PutPositionX, |
| | | ItemPositionY = taskPosition.PutPositionY, |
| | | ItemPositionZ = taskPosition.PutPositionZ, |
| | | ItemStatus = (int)ItemStatusEnum.Assigned, |
| | | ItemName = code |
| | | }; |
| | | |
| | | int positionR = 1; |
| | | |
| | | int takePositionX = 0; |
| | | int takePositionY = 0; |
| | | |
| | | int putPositionX = 0; |
| | | int putPositionY = 0; |
| | | |
| | | int takeContainerPositionX = 0; |
| | | int takeContainerPositionY = 0; |
| | | int takeContainerPositionZ = 0; |
| | | |
| | | int putContainerPositionX = 0; |
| | | int putContainerPositionY = 0; |
| | | int putContainerPositionZ = 0; |
| | | |
| | | int deviceHalfLength = 0; |
| | | int deviceHalfWidth = 0; |
| | | |
| | | if (length > 920 && width >= 300) |
| | | { |
| | | positionR = 1; |
| | | if (OPositions.ZPositions.TryGetValue(takeContainer.ContainerCode, out Position? takeOPosition)) |
| | | { |
| | | takeContainerPositionX = takeOPosition.PositionX; |
| | | takeContainerPositionY = takeOPosition.PositionY; |
| | | takeContainerPositionZ = takeOPosition.PositionZ; |
| | | } |
| | | |
| | | if (OPositions.ZPositions.TryGetValue(putContainer.ContainerCode, out Position? putOPosition)) |
| | | { |
| | | putContainerPositionX = putOPosition.PositionX; |
| | | putContainerPositionY = putOPosition.PositionY; |
| | | putContainerPositionZ = putOPosition.PositionZ; |
| | | } |
| | | |
| | | deviceHalfLength = 460; |
| | | deviceHalfWidth = 265; |
| | | } |
| | | else |
| | | { |
| | | positionR = 0; |
| | | |
| | | if (OPositions.HPositions.TryGetValue(takeContainer.ContainerCode, out Position? takeOPosition)) |
| | | { |
| | | takeContainerPositionX = takeOPosition.PositionX; |
| | | takeContainerPositionY = takeOPosition.PositionY; |
| | | takeContainerPositionZ = takeOPosition.PositionZ; |
| | | } |
| | | |
| | | if (OPositions.HPositions.TryGetValue(putContainer.ContainerCode, out Position? putOPosition)) |
| | | { |
| | | putContainerPositionX = putOPosition.PositionX; |
| | | putContainerPositionY = putOPosition.PositionY; |
| | | putContainerPositionZ = putOPosition.PositionZ; |
| | | } |
| | | |
| | | deviceHalfLength = 265; |
| | | deviceHalfWidth = 460; |
| | | } |
| | | |
| | | //å¸çé¿530 300 é´é660 æå¤§920 å¸ç宽130 |
| | | |
| | | int sourceTakePositionX = 0; |
| | | int sourceTakePositionY = 0; |
| | | |
| | | int sourcePutPositionX = 0; |
| | | int sourceTPutPositionY = 0; |
| | | |
| | | if (length / 2 + point3D.Value.X > 1000) |
| | | { |
| | | takePositionY = 1000; |
| | | putPositionY = putContainerPositionY + 1000; |
| | | |
| | | sourceTakePositionY = 1000; |
| | | sourceTPutPositionY = 1000; |
| | | } |
| | | else |
| | | { |
| | | takePositionY = takeContainerPositionY - length / 2 + deviceHalfLength; |
| | | putPositionY = putContainerPositionY + length / 2 + point3D.Value.X - deviceHalfLength; |
| | | |
| | | sourceTakePositionY = length / 2 + point3D.Value.X + deviceHalfLength; |
| | | sourceTPutPositionY = length / 2 + point3D.Value.X - deviceHalfLength; |
| | | } |
| | | |
| | | |
| | | if (width >= 530) |
| | | { |
| | | takePositionX = takeContainerPositionX + Math.Abs( width / 2 - deviceHalfWidth); |
| | | putPositionX = point3D.Value.Y + putContainerPositionX + Math.Abs(width / 2 - deviceHalfWidth); |
| | | |
| | | sourceTakePositionX = Math.Abs(width / 2 - deviceHalfWidth); |
| | | sourcePutPositionX = point3D.Value.Y + Math.Abs(width / 2 - deviceHalfWidth); |
| | | } |
| | | else |
| | | { |
| | | takePositionX = takeContainerPositionX; |
| | | putPositionX = point3D.Value.Y + takeContainerPositionX; |
| | | |
| | | sourceTakePositionX = 0; |
| | | sourcePutPositionX = point3D.Value.Y; |
| | | } |
| | | |
| | | int takePositionZ = takeContainerPositionZ - (height - (height - 10)); |
| | | int putPositionZ = (putContainerPositionZ - (height - (height - 10))) - point3D.Value.Z; |
| | | |
| | | int sourceTakePositionZ = height - (height - 10); |
| | | int sourcePutPositionZ = height - (height - 10) + point3D.Value.Z; |
| | | |
| | | Dt_Task dt_Task = new Dt_Task() |
| | | { |
| | |
| | | DeviceCode = deviceCode, |
| | | TaskState = (int)TaskStatusEnum.Gantry_New, |
| | | TaskType = 0, |
| | | SourceAddress = $"{takePosition}-{sourceTakePositionX}-{sourceTakePositionY}-{sourceTakePositionZ}-{positionR}", |
| | | TargetAddress = $"{putPosition}-{sourcePutPositionX}-{sourceTPutPositionY}-{sourcePutPositionZ}-{positionR}", |
| | | CurrentAddress = $"{takePosition}-{takePositionX}-{takePositionY}-{takePositionZ}-{positionR}", |
| | | NextAddress = $"{putPosition}-{putPositionX}-{putPositionY}-{putPositionZ}-{positionR}", |
| | | SourceAddress = $"{takePosition}*{taskPosition.TakePositionX}*{taskPosition.TakePositionY}*{taskPosition.TakePositionZ}*{taskPosition.PositionR}", |
| | | TargetAddress = $"{putPosition}*{taskPosition.PutPositionX}*{taskPosition.PutPositionX}*{taskPosition.PutPositionZ}*{taskPosition.PositionR}", |
| | | CurrentAddress = $"{takePosition}*{taskPosition.TakePositionX}*{taskPosition.TakePositionY}*{taskPosition.TakePositionZ}*{taskPosition.PositionR}", |
| | | NextAddress = $"{putPosition}*{taskPosition.PutPositionX}*{taskPosition.PutPositionX}*{taskPosition.PutPositionZ}*{taskPosition.PositionR}", |
| | | Grade = 0, |
| | | }; |
| | | |