| | |
| | | using AutoMapper; |
| | | using WIDESEAWCS_BasicInfoService; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO.BasicInfo; |
| | | 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; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IContainerItemRepository _containerItemRepository; |
| | | private readonly IOrderContainerRepository _orderContainerRepository; |
| | | |
| | | public ContainerService(IContainerRepository BaseDal, IMapper mapper) : base(BaseDal) |
| | | public ContainerService(IContainerRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IContainerItemRepository containerItemRepository, IOrderContainerRepository orderContainerRepository) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _containerItemRepository = containerItemRepository; |
| | | _orderContainerRepository = orderContainerRepository; |
| | | } |
| | | |
| | | public void GetPosition(string orderNo, int length, int width, int height) |
| | | public SuctionInfo GetPlacementResult(Block block, List<Block> blocks) |
| | | { |
| | | 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) |
| | | ContainerPlacer containerPlacer = new ContainerPlacer(); |
| | | |
| | | |
| | | return containerPlacer.CalculatePlacement(block, blocks); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åæ¾ç½®ä½ç½® |
| | | /// </summary> |
| | | /// <param name="length"></param> |
| | | /// <param name="width"></param> |
| | | /// <param name="height"></param> |
| | | /// <param name="containerSize"></param> |
| | | /// <param name="placedBlocks"></param> |
| | | /// <param name="edge">è¾¹</param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public TaskPosition? GetTaskPosition(int length, int width, int height, ContainerSize containerSize, List<PlacedBlock> placedBlocks, int edge) |
| | | { |
| | | try |
| | | { |
| | | containerInfos = orderContainers; |
| | | if (containerInfos.Count == 1) |
| | | { |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | PlaceBlockService placeBlockService = new PlaceBlockService(containerSize, placedBlocks); |
| | | |
| | | TaskPosition? taskPosition = placeBlockService.PlaceBlock(length, width, height, edge); |
| | | return taskPosition; |
| | | } |
| | | else |
| | | catch (Exception ex) |
| | | { |
| | | Dt_Container container = Db.Queryable<Dt_Container>().OrderBy(x => x.ContainerSort).First(x => x.ContainerStatus == ContainerStatusEnum.Empty.ObjToInt()); |
| | | if (container != null) |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public (bool, TaskPosition?, string) GetPosition(int orderId, string orderNo, int length, int width, int height) |
| | | { |
| | | TaskPosition? taskPosition = GetPositionByOrder(orderId, orderNo, length, width, height); |
| | | if (taskPosition != null) |
| | | { |
| | | return (true, taskPosition, ""); |
| | | } |
| | | taskPosition = GetPosition(length, width, height); |
| | | if (taskPosition != null) |
| | | { |
| | | return (true, taskPosition, ""); |
| | | } |
| | | return (true, taskPosition, "10001"); |
| | | } |
| | | |
| | | public TaskPosition? GetPosition(int length, int width, int height) |
| | | { |
| | | List<Dt_Container> containers = Db.Queryable<Dt_Container>().Where(x => x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt()).Includes(x => x.Items).ToList(); |
| | | |
| | | Dt_Container? container = containers.OrderBy(x => x.ContainerSort).FirstOrDefault(x => x.ContainerStatus == ContainerStatusEnum.Empty.ObjToInt() && x.ContainerEnable); |
| | | List<PlacedBlock> placedBlocks = new List<PlacedBlock>(); |
| | | if (container != null && (containers.Any(x => (x.Items.Any(v => v.ItemLength > 1600 || v.ItemWidth > 1600)) && x.DeviceCode == container.DeviceCode) || containers.Where(x => x.ContainerStatus == ContainerStatusEnum.Empty.ObjToInt() && x.ContainerEnable && x.DeviceCode == container.DeviceCode).Count() > 1 || length > 1600 || width > 1600)) |
| | | { |
| | | int edge = 0; |
| | | if (container.ContainerNo == containers.Where(x => x.DeviceCode == container.DeviceCode && x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt()).Min(x => x.ContainerNo)) |
| | | { |
| | | containerInfos = _mapper.Map<List<Dt_OrderContainer>>(container); |
| | | edge = 1; |
| | | } |
| | | |
| | | ContainerSize containerSize = new ContainerSize(container.ContainerLength, container.ContainerWidth, container.ContainerHeight); |
| | | TaskPosition? taskPosition = GetTaskPosition(length, width, height, containerSize, placedBlocks, edge); |
| | | if (taskPosition != null) |
| | | { |
| | | taskPosition.PutPosition = container.ContainerCode; |
| | | return taskPosition; |
| | | } |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | public TaskPosition? GetPositionByOrder(int orderId, string orderNo, int length, int width, int height) |
| | | { |
| | | List<Dt_OrderContainer> orderContainers = Db.Queryable<Dt_OrderContainer>().Where(it => it.OrderNo == orderNo && it.OrderId == orderId).ToList(); |
| | | if (orderContainers != null && orderContainers.Count > 0) |
| | | { |
| | | 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(); |
| | | List<Dt_Container> dt_Containers = Db.Queryable<Dt_Container>().ToList(); |
| | | |
| | | List<Dt_Container> containers = dt_Containers.Where(it => orderContainers.Any(x => x.ContainerId == it.Id && x.ContainerCode == it.ContainerCode) && it.ContainerEnable && it.ContainerStatus != ContainerStatusEnum.ReadyRelease.ObjToInt()).ToList().OrderBy(x => x.ContainerSort).ToList(); |
| | | |
| | | for (int i = 0; i < containers.Count; i++) |
| | | { |
| | | containers[i].Items = Db.Queryable<Dt_ContainerItem>().Where(x => x.ContainerId == containers[i].Id).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) |
| | | int tempLength = item.ItemLength; |
| | | int tempWidth = item.ItemWidth; |
| | | |
| | | if (item.ItemLength < item.ItemWidth) |
| | | { |
| | | Point3D point3D = new Point3D(item.ItemPositionX, item.ItemPositionY, item.ItemPositionZ); |
| | | placedBlocks.Add(new PlacedBlock(point3D, item.ItemLength, item.ItemWidth, item.ItemHeight)); |
| | | tempLength = item.ItemWidth; |
| | | tempWidth = item.ItemLength; |
| | | } |
| | | |
| | | 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.ItemPositionX, item.ItemPositionY, item.ItemPositionZ); |
| | | placedBlocks.Add(new PlacedBlock(point3D, tempLength, tempWidth, item.ItemHeight)); |
| | | } |
| | | Dt_OrderContainer? orderContainer = orderContainers.FirstOrDefault(x => x.ContainerId == x.Id && x.ContainerCode == x.ContainerCode); |
| | | |
| | | int edge = 0; |
| | | if (container.ContainerNo == dt_Containers.Where(x => x.DeviceCode == container.DeviceCode && x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt()).Min(x => x.ContainerNo)) |
| | | { |
| | | edge = 1; |
| | | } |
| | | |
| | | ContainerSize containerSize = new ContainerSize(container.ContainerLength, container.ContainerWidth, container.ContainerHeight); |
| | | TaskPosition? taskPosition = GetTaskPosition(length, width, height, containerSize, placedBlocks, edge); |
| | | if (taskPosition != null) |
| | | { |
| | | taskPosition.PutPosition = container.ContainerCode; |
| | | return taskPosition; |
| | | } |
| | | //else |
| | | //{ |
| | | // if (LightStatusStorage.LightStatusDic.ContainsKey(container.ContainerCode))//LightStatusEnum |
| | | // { |
| | | // LightStatusStorage.LightStatusDic[container.ContainerCode] = LightStatusEnum.ReadyRelease; |
| | | |
| | | // if (container.Items.Count > 10) |
| | | // { |
| | | // container.ContainerStatus = ContainerStatusEnum.ReadyRelease.ObjToInt(); |
| | | // BaseDal.UpdateData(container); |
| | | // } |
| | | |
| | | // } |
| | | //} |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public WebResponseContent ReleaseContainer(int[] keys) |
| | | { |
| | | try |
| | | { |
| | | List<Dt_Container> containers = Db.Queryable<Dt_Container>().Where(x => keys.Contains(x.Id)).Includes(x => x.Items).ToList(); |
| | | List<Dt_ContainerItem> containerItems = new List<Dt_ContainerItem>(); |
| | | List<Dt_OrderContainer> orderContainers = Db.Queryable<Dt_OrderContainer>().Where(x => containers.Select(x => x.Id).ToList().Contains(x.ContainerId)).ToList(); |
| | | |
| | | for (int i = 0; i < containers.Count; i++) |
| | | { |
| | | containers[i].ContainerStatus = ContainerStatusEnum.Empty.ObjToInt(); |
| | | containerItems.AddRange(containers[i].Items); |
| | | } |
| | | |
| | | _unitOfWorkManage.BeginTran(); |
| | | _containerItemRepository.DeleteAndMoveIntoHty(containerItems, App.User?.UserId > 0 ? WIDESEAWCS_Core.Enums.OperateTypeEnum.人工å é¤ : WIDESEAWCS_Core.Enums.OperateTypeEnum.èªå¨å é¤); |
| | | _orderContainerRepository.DeleteAndMoveIntoHty(orderContainers, App.User?.UserId > 0 ? WIDESEAWCS_Core.Enums.OperateTypeEnum.人工å é¤ : WIDESEAWCS_Core.Enums.OperateTypeEnum.èªå¨å é¤); |
| | | Db.Updateable(containers).ExecuteCommand(); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | |