| | |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO.PlacedBlockDTO; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_IBasicInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | |
| | | public class ContainerService : ServiceBase<Dt_Container, IContainerRepository>, IContainerService |
| | | { |
| | | private readonly IMapper _mapper; |
| | | int lengthThreshold = AppSettings.Get("LengthThreshold").ObjToInt(); |
| | | |
| | | public ContainerService(IContainerRepository BaseDal, IMapper mapper) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | } |
| | | |
| | | public void GetPosition(string orderNo, int length, int width, int height) |
| | | public TaskPosition? GetTaskPosition(int length, int width, int height, ContainerSize containerSize, List<PlacedBlock> placedBlocks) |
| | | { |
| | | List<Dt_OrderContainer> containerInfos = new List<Dt_OrderContainer>(); |
| | | List<Dt_OrderContainer> orderContainers = Db.Queryable<Dt_OrderContainer>().Where(it => it.OrderNo == orderNo).ToList(); |
| | | if (orderContainers != null) |
| | | try |
| | | { |
| | | containerInfos = orderContainers; |
| | | if (containerInfos.Count == 1) |
| | | PlaceBlockService placeBlockService = new PlaceBlockService(containerSize, placedBlocks); |
| | | |
| | | Point3D? point3D = placeBlockService.PlaceBlock(length, width, height); |
| | | if (point3D == null) |
| | | { |
| | | Dt_Container container = Db.Queryable<Dt_Container>().OrderBy(x => x.ContainerSort).First(x => x.ContainerStatus == ContainerStatusEnum.Empty.ObjToInt()); |
| | | if (container != null) |
| | | { |
| | | Dt_OrderContainer containerInfo = _mapper.Map<Dt_OrderContainer>(container); |
| | | containerInfos.Add(containerInfo); |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Dt_Container container = Db.Queryable<Dt_Container>().OrderBy(x => x.ContainerSort).First(x => x.ContainerStatus == ContainerStatusEnum.Empty.ObjToInt()); |
| | | if (container != null) |
| | | |
| | | //æ¾è´§ä½ç½®æ¿æä¸å¿ç¹ |
| | | 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 >= 100) |
| | | { |
| | | containerInfos = _mapper.Map<List<Dt_OrderContainer>>(container); |
| | | // |
| | | 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 if (length < 450) |
| | | { |
| | | Point3D deviceCenter = new Point3D(530 / 2, 130 / 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*/; |
| | | } |
| | | |
| | | if (positionR == 1 && takePositionY < 155) |
| | | { |
| | | takePositionY = 0; |
| | | |
| | | putPositionY = point3D.Value.X + 155; |
| | | } |
| | | else if (positionR == 1 && takePositionY >= 880) |
| | | { |
| | | takePositionY = 880 - 155; |
| | | putPositionY = 880; |
| | | } |
| | | else |
| | | { |
| | | takePositionY -= 155; |
| | | } |
| | | |
| | | if (positionR == 0 && takePositionY < 350) |
| | | { |
| | | takePositionY = 0; |
| | | |
| | | putPositionY = point3D.Value.X + 350; |
| | | } |
| | | else if (positionR == 0 && takePositionY >= 350 && takePositionY <= 880) |
| | | { |
| | | takePositionY -= 350; |
| | | } |
| | | else if (positionR == 0 && takePositionY >= 880) |
| | | { |
| | | takePositionY = 880 - 350; |
| | | putPositionY = 880; |
| | | } |
| | | |
| | | if (putPositionX < -20) |
| | | { |
| | | takePositionX = -40; |
| | | //point3D.X += -20; |
| | | putPositionX = point3D.Value.Y - 40; |
| | | } |
| | | |
| | | 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 TaskPosition? GetPosition(string orderNo, int length, int width, int height) |
| | | //{ |
| | | // List<Dt_OrderContainer> containerInfos = new List<Dt_OrderContainer>(); |
| | | // List<Dt_OrderContainer> orderContainers = Db.Queryable<Dt_OrderContainer>().Where(it => it.OrderNo == orderNo).ToList(); |
| | | // if (orderContainers != null && orderContainers.Count > 0) |
| | | // { |
| | | // containerInfos = orderContainers; |
| | | // if (containerInfos.Count == 1) |
| | | // { |
| | | // Dt_Container container = Db.Queryable<Dt_Container>().OrderBy(x => x.ContainerSort).First(x => x.ContainerStatus == ContainerStatusEnum.Empty.ObjToInt() && x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt() && x.ContainerEnable); |
| | | // if (container != null) |
| | | // { |
| | | // Dt_OrderContainer containerInfo = _mapper.Map<Dt_OrderContainer>(container); |
| | | // containerInfos.Add(containerInfo); |
| | | // } |
| | | // else |
| | | // { |
| | | // Dt_Container containerItem = Db.Queryable<Dt_Container>().Where(x => x.ContainerStatus == ContainerStatusEnum.NonEmpty.ObjToInt() && x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt() && x.ContainerEnable).Includes(x => x.Items).OrderByDescending(x => x.Items.Count).First(); |
| | | // if (containerItem != null) |
| | | // { |
| | | // if (LightStatusStorage.LightStatusDic.TryGetValue(containerItem.ContainerCode, out LightStatusEnum lightStatus)) |
| | | // { |
| | | // if (lightStatus != LightStatusEnum.ReadyRelease) |
| | | // { |
| | | // LightStatusStorage.LightStatusDic[containerItem.ContainerCode] = LightStatusEnum.ReadyRelease; |
| | | |
| | | // Dt_OrderContainer containerInfo = _mapper.Map<Dt_OrderContainer>(containerItem); |
| | | // containerInfos.Add(containerInfo); |
| | | // } |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // throw new Exception($"æªæ¾å°å¯æ¾è´§ä½ç½®,è¯·æ£æ¥æ°æ®æ¯å¦å·²æ·»å æè
å·¥ä½è¢«ç¦ç¨"); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // Dt_Container container = Db.Queryable<Dt_Container>().OrderBy(x => x.ContainerSort).First(x => x.ContainerStatus == ContainerStatusEnum.Empty.ObjToInt() && x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt() && x.ContainerEnable); |
| | | // if (container != null) |
| | | // { |
| | | // containerInfos.Add(_mapper.Map<Dt_OrderContainer>(container)); |
| | | // } |
| | | // else |
| | | // { |
| | | // Dt_Container containerItem = Db.Queryable<Dt_Container>().Where(x => x.ContainerStatus == ContainerStatusEnum.NonEmpty.ObjToInt() && x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt() && x.ContainerEnable).Includes(x => x.Items).OrderByDescending(x => x.Items.Count()).First(); |
| | | // if (containerItem != null) |
| | | // { |
| | | // if (LightStatusStorage.LightStatusDic.TryGetValue(containerItem.ContainerCode, out LightStatusEnum lightStatus)) |
| | | // { |
| | | // if (lightStatus != LightStatusEnum.ReadyRelease) |
| | | // { |
| | | // LightStatusStorage.LightStatusDic[containerItem.ContainerCode] = LightStatusEnum.ReadyRelease; |
| | | |
| | | // Dt_OrderContainer containerInfo = _mapper.Map<Dt_OrderContainer>(containerItem); |
| | | // containerInfos.Add(containerInfo); |
| | | // } |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // throw new Exception($"æªæ¾å°å¯æ¾è´§ä½ç½®,è¯·æ£æ¥æ°æ®æ¯å¦å·²æ·»å æè
å·¥ä½è¢«ç¦ç¨"); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | // { |
| | | // List<Dt_Container> containers = Db.Queryable<Dt_Container>().Where(it => containerInfos.Any(x => x.ContainerId == it.Id && x.ContainerCode == it.ContainerCode) && it.ContainerEnable).Includes(x => x.Items).ToList().OrderBy(x => x.ContainerSort).ToList(); |
| | | |
| | | // foreach (var container in containers) |
| | | // { |
| | | // List<PlacedBlock> placedBlocks = new List<PlacedBlock>(); |
| | | |
| | | // foreach (var item in container.Items) |
| | | // { |
| | | // Point3D point3D = new Point3D(item.ItemRelaPositionX, item.ItemRelaPositionY, item.ItemRelaPositionZ); |
| | | // placedBlocks.Add(new PlacedBlock(point3D, item.ItemLength, item.ItemWidth, item.ItemHeight)); |
| | | // } |
| | | // Dt_OrderContainer? orderContainer = containerInfos.FirstOrDefault(x => x.ContainerId == x.Id && x.ContainerCode == x.ContainerCode); |
| | | // int containerLength = container.ContainerLength; |
| | | // if (length < lengthThreshold) |
| | | // { |
| | | // containerLength = lengthThreshold; |
| | | // } |
| | | // ContainerSize containerSize = new ContainerSize(containerLength, container.ContainerWidth, container.ContainerHeight); |
| | | // TaskPosition? taskPosition = GetTaskPosition(length, width, height, containerSize, placedBlocks); |
| | | // if (taskPosition != null) |
| | | // { |
| | | // taskPosition.PutPosition = container.ContainerCode; |
| | | // return taskPosition; |
| | | // } |
| | | // throw new Exception("10001"); |
| | | |
| | | // } |
| | | // } |
| | | // return null; |
| | | //} |
| | | |
| | | public TaskPosition? GetPosition(string orderNo, int length, int width, int height) |
| | | { |
| | | TaskPosition? taskPosition = GetPositionByOrder(orderNo, length, width, height); |
| | | if (taskPosition != null) |
| | | { |
| | | return taskPosition; |
| | | } |
| | | taskPosition = GetPosition(length, width, height); |
| | | if (taskPosition != null) |
| | | { |
| | | return taskPosition; |
| | | } |
| | | throw new Exception("10001"); |
| | | } |
| | | |
| | | public TaskPosition? GetPosition(int length, int width, int height) |
| | | { |
| | | Dt_Container container = Db.Queryable<Dt_Container>().OrderBy(x => x.ContainerSort).First(x => x.ContainerStatus == ContainerStatusEnum.Empty.ObjToInt() && x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt() && x.ContainerEnable); |
| | | List<PlacedBlock> placedBlocks = new List<PlacedBlock>(); |
| | | |
| | | if (container.Items != null && container.Items.Count > 0) |
| | | { |
| | | foreach (var item in container.Items) |
| | | { |
| | | Point3D point3D = new Point3D(item.ItemRelaPositionX, item.ItemRelaPositionY, item.ItemRelaPositionZ); |
| | | placedBlocks.Add(new PlacedBlock(point3D, item.ItemLength, item.ItemWidth, item.ItemHeight)); |
| | | } |
| | | } |
| | | |
| | | int containerLength = container.ContainerLength; |
| | | if (length < lengthThreshold) |
| | | { |
| | | List<Dt_Container> containers = Db.Queryable<Dt_Container>().Where(it => containerInfos.Any(x => x.ContainerId == it.Id && x.ContainerCode == it.ContainerCode)).Includes(x => x.Items).ToList(); |
| | | containerLength = lengthThreshold; |
| | | } |
| | | ContainerSize containerSize = new ContainerSize(containerLength, container.ContainerWidth, container.ContainerHeight); |
| | | TaskPosition? taskPosition = GetTaskPosition(length, width, height, containerSize, placedBlocks); |
| | | if (taskPosition != null) |
| | | { |
| | | taskPosition.PutPosition = container.ContainerCode; |
| | | return taskPosition; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public TaskPosition? GetPositionByOrder(string orderNo, int length, int width, int height) |
| | | { |
| | | List<Dt_OrderContainer> orderContainers = Db.Queryable<Dt_OrderContainer>().Where(it => it.OrderNo == orderNo).ToList(); |
| | | if (orderContainers != null && orderContainers.Count > 0) |
| | | { |
| | | List<Dt_Container> containers = Db.Queryable<Dt_Container>().Where(it => orderContainers.Any(x => x.ContainerId == it.Id && x.ContainerCode == it.ContainerCode) && it.ContainerEnable).Includes(x => x.Items).ToList().OrderBy(x => x.ContainerSort).ToList(); ; |
| | | |
| | | foreach (var container in containers) |
| | | { |
| | | List<PlacedBlock> placedBlocks = new List<PlacedBlock>(); |
| | | |
| | | if (container.Items != null && container.Items.Count > 0) |
| | | foreach (var item in container.Items) |
| | | { |
| | | foreach (var item in container.Items) |
| | | { |
| | | Point3D point3D = new Point3D(item.ItemPositionX, item.ItemPositionY, item.ItemPositionZ); |
| | | placedBlocks.Add(new PlacedBlock(point3D, item.ItemLength, item.ItemWidth, item.ItemHeight)); |
| | | } |
| | | |
| | | ContainerSize containerSize = new ContainerSize(container.ContainerLength, container.ContainerWidth, container.ContainerHeight); |
| | | PlaceBlockService placeBlockService = new PlaceBlockService(containerSize, placedBlocks); |
| | | Point3D? axis = placeBlockService.PlaceBlock(length, width, height); |
| | | if (axis != null) |
| | | { |
| | | Dt_ContainerItem containerItem = new Dt_ContainerItem() |
| | | { |
| | | ContainerId = container.Id, |
| | | ItemCode = "ItemCode", |
| | | ItemHeight = height, |
| | | ItemLength = length, |
| | | ItemName = "ItemName", |
| | | ItemPositionX = axis.Value.X, |
| | | ItemPositionY = axis.Value.Y, |
| | | ItemPositionZ = axis.Value.Z, |
| | | ItemWidth = width, |
| | | ItemStatus = ItemStatusEnum.Assigned.ObjToInt() |
| | | }; |
| | | Db.Insertable(containerItem).ExecuteCommand(); |
| | | } |
| | | Point3D point3D = new Point3D(item.ItemRelaPositionX, item.ItemRelaPositionY, item.ItemRelaPositionZ); |
| | | placedBlocks.Add(new PlacedBlock(point3D, item.ItemLength, item.ItemWidth, item.ItemHeight)); |
| | | } |
| | | Dt_OrderContainer? orderContainer = orderContainers.FirstOrDefault(x => x.ContainerId == x.Id && x.ContainerCode == x.ContainerCode); |
| | | int containerLength = container.ContainerLength; |
| | | if (length < lengthThreshold) |
| | | { |
| | | containerLength = lengthThreshold; |
| | | } |
| | | else |
| | | { |
| | | if (orderContainer != null) |
| | | containerLength = orderContainer.MaxLength; |
| | | } |
| | | ContainerSize containerSize = new ContainerSize(containerLength, container.ContainerWidth, container.ContainerHeight); |
| | | TaskPosition? taskPosition = GetTaskPosition(length, width, height, containerSize, placedBlocks); |
| | | if (taskPosition != null) |
| | | { |
| | | taskPosition.PutPosition = container.ContainerCode; |
| | | return taskPosition; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | |