| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Xml.Linq; |
| | | using WIDESEA_Comm.Http; |
| | | using WIDESEA_Common.Log; |
| | | 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 |
| | | { |
| | | public class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService |
| | | { |
| | | private readonly IRouterService _routerService; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly ITaskExecuteDetailRepository _taskExecuteDetailRepository; |
| | | private readonly ITask_HtyService _task_HtyService; |
| | | private readonly IMapper _mapper; |
| | | private readonly IContainerRepository _containerRepository; |
| | | private readonly IContainerItemRepository _containerItemRepository; |
| | | private readonly IDeviceInfoRepository _deviceInfoRepository; |
| | | |
| | | public TaskService(ITaskRepository BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IMapper mapper, ITask_HtyService task_HtyService) : base(BaseDal) |
| | | public TaskService(ITaskRepository BaseDal, IMapper mapper, IContainerRepository containerRepository, IContainerItemRepository containerItemRepository, IDeviceInfoRepository deviceInfoRepository) : base(BaseDal) |
| | | { |
| | | _routerService = routerService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _taskExecuteDetailRepository = taskExecuteDetailRepository; |
| | | _task_HtyService = task_HtyService; |
| | | _mapper = mapper; |
| | | _containerRepository = containerRepository; |
| | | _containerItemRepository = containerItemRepository; |
| | | _deviceInfoRepository = deviceInfoRepository; |
| | | } |
| | | |
| | | public Dt_Task? QueryAGantryUnExecuteTask(string gantryDeviceNo) |
| | |
| | | return BaseDal.QueryFirst(x => x.TaskState == (int)TaskStatusEnum.Gantry_New && x.DeviceCode == gantryDeviceNo); |
| | | } |
| | | |
| | | public WebResponseContent CreateTask(string takePosition, string putPosition, string deviceCode) |
| | | public WebResponseContent CreateTask(string takePosition, string putPosition, string deviceCode, int length, int width, int height) |
| | | { |
| | | return WebResponseContent.Instance.OK(); |
| | | try |
| | | { |
| | | Dt_Container takeContainer = _containerRepository.QueryFirst(x => x.ContainerCode == takePosition && x.ContainerType == ContainerTypeEnum.TakeContainer.ObjToInt()); |
| | | if (takeContainer == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("åè´§ä½ç½®ä¸åå¨"); |
| | | } |
| | | |
| | | Dt_Container putContainer = _containerRepository.QueryFirst(x => x.ContainerCode == putPosition && x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt()); |
| | | if (putContainer == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æ¾è´§ä½ç½®ä¸åå¨"); |
| | | } |
| | | |
| | | ContainerSize containerSize = new ContainerSize(putContainer.ContainerLength, putContainer.ContainerWidth, putContainer.ContainerHeight); |
| | | List<Dt_ContainerItem> containerItems = _containerItemRepository.QueryData(x => x.ContainerId == putContainer.Id); |
| | | |
| | | 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) |
| | | { |
| | | return WebResponseContent.Instance.Error("æ¾è´§ä½ç½®å·²æ»¡"); |
| | | } |
| | | string code = DateTime.Now.ToString("yyyyMMddHHmmss"); |
| | | |
| | | Dt_ContainerItem dt_ContainerItem = new Dt_ContainerItem() |
| | | { |
| | | ContainerId = putContainer.Id, |
| | | ItemCode = code, |
| | | ItemLength = length, |
| | | ItemWidth = width, |
| | | ItemHeight = height, |
| | | ItemPositionX = point3D.Value.X, |
| | | ItemPositionY = point3D.Value.Y, |
| | | ItemPositionZ = point3D.Value.Z, |
| | | 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() |
| | | { |
| | | TaskNum = 1, |
| | | PalletCode = code, |
| | | 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}", |
| | | Grade = 0, |
| | | }; |
| | | |
| | | _containerItemRepository.AddData(dt_ContainerItem); |
| | | base.AddData(dt_Task); |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | } |