陈勇
2 天以前 6b74e1dcf5642c8f56975471e27780d695953989
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_StoragIntegrationServices/WCS/Partial/RequestInboundRoadWayNo.cs
@@ -6,6 +6,7 @@
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_DTO;
@@ -28,6 +29,13 @@
            WebResponseContent response = new WebResponseContent();
            try
            {
                //如任务已存在则 è¿”回此任务
                var checkTask = _taskRepository.QueryFirst(x => x.PalletCode == json.PalletCode && x.PVI == json.PVI);
                if (checkTask != null)
                {
                    return response.OK("申请入库成功", data: checkTask);
                }
                //屏蔽MES
                if (json.Position == "EL01RB")
                {
@@ -41,17 +49,7 @@
                }
                var carInfo = _carBodyInfoRepository.QueryFirst(x => x.RFID == json.PVI && x.PalletCode == json.PalletCode);
                if (carInfo == null) throw new Exception("未知车身信息,无法入库");
                //{
                //    Dt_CarBodyInfo _CarBodyInfo = new Dt_CarBodyInfo  //测试
                //    {
                //        PVI = "J25000660",
                //        RFID = json.PVI,
                //        BodyStatus = 0,
                //        CarType = 1,
                //    };
                //}
                List<Dt_RoadWay> roadWays = new List<Dt_RoadWay>();
                if (carInfo.CarType == 1)
@@ -60,34 +58,55 @@
                }
                else if (carInfo.CarType == 2)
                {
                    roadWays = _roadWayRepository.QueryData(x => x.WirteCar == 2);
                    roadWays = _roadWayRepository.QueryData(x => x.ColorCar == 2);
                }
                var maxGroup = _locationRepository.QueryData(x => (x.LocationType == carInfo.CarType || x.LocationType == 3) && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == (int)EnableEnum.Enable)
                                .GroupBy(x => x.RoadwayNo)
                                .OrderByDescending(g => g.Count()) // æ ¹æ®æ¯ä¸ªç»„的元素数量排序
                                .ToList(); // å–出数量最多的组
                string maxRoadwayNo = GetInboundRoadWayNo(carInfo.CarType);
                Dictionary<string, int> result = new Dictionary<string, int>();
                foreach (var item in maxGroup)
                if (string.IsNullOrEmpty(maxRoadwayNo))
                {
                    var number = _taskRepository.QueryData(x => x.TargetAddress == item.Key).Count();
                    if (item.Count() - number <= 0)
                    {
                        continue;
                    }
                    result.Add(item.Key, item.Count() - number);
                    maxRoadwayNo = GetInboundRoadWayNo(3);
                }
                string maxRoadwayNo = result.OrderByDescending(x => x.Value).FirstOrDefault().Key; // æ•°é‡æœ€å¤šçš„组的Key
                if (string.IsNullOrEmpty(maxRoadwayNo)) return response.Error(12, "无可用库位");
                var stationList = _stationManagerRepository.QueryData(x => x.RoadwayNo == maxRoadwayNo && x.stationArea == json.area && x.stationType == 1);
                #region åŽŸåº“ä½åˆ†é…
                //var maxGroup = _locationRepository.QueryData(x => x.LocationType == carInfo.CarType && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == (int)EnableEnum.Enable)
                //                .GroupBy(x => x.RoadwayNo)
                //                .OrderByDescending(g => g.Count()) // æ ¹æ®æ¯ä¸ªç»„的元素数量排序
                //                .ToList(); // å–出数量最多的组
                //if (maxGroup.Count == 0)
                //{
                //    maxGroup = _locationRepository.QueryData(x => x.LocationType == (int)BodyType.Empty && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == (int)EnableEnum.Enable)
                //   .GroupBy(x => x.RoadwayNo)
                //   .OrderByDescending(g => g.Count()) // æ ¹æ®æ¯ä¸ªç»„的元素数量排序
                //   .ToList(); // å–出数量最多的组
                //}
                //if (maxGroup.Count == 0) return response.Error(12, "无可用库位");
                //Dictionary<string, int> result = new Dictionary<string, int>();
                //foreach (var item in maxGroup)
                //{
                //    var number = _taskRepository.QueryData(x => x.RoadwayNo == item.Key && x.CarType == carInfo.CarType && (x.TaskType == (int)TaskInboundTypeEnum.Inbound || x.TaskType == (int)TaskInboundTypeEnum.InTray)).Count();
                //    if (item.Count() - number <= 0)
                //    {
                //        continue;
                //    }
                //    result.Add(item.Key, item.Count() - number);
                //}
                //string maxRoadwayNo = result.OrderByDescending(x => x.Value).FirstOrDefault().Key; // æ•°é‡æœ€å¤šçš„组的Key
                #endregion
                var stationList = _stationManagerRepository.QueryData(x => x.RoadwayNo == maxRoadwayNo && x.stationArea == json.area && x.stationType == 1 && x.stationStatus == "1");
                Dt_StationManager station = null;
                if (stationList.Count > 1)
                {
                    var task = _taskRepository.QueryData(x => x.Roadway == stationList.FirstOrDefault().Roadway).OrderByDescending(x => x.CreateDate).FirstOrDefault();
                    var task = _taskRepository.QueryData(x => x.Roadway == stationList.FirstOrDefault().Roadway && x.TaskType == (int)TaskInboundTypeEnum.Inbound).OrderByDescending(x => x.CreateDate).FirstOrDefault();
                    if (task != null) station = stationList.Where(x => x.stationChildCode != task.NextAddress && x.stationChildCode != task.CurrentAddress).FirstOrDefault();
                    else station = stationList.FirstOrDefault();
                }
@@ -118,7 +137,8 @@
                    TaskNum = _taskRepository.GetTaskNo().Result,
                    Creater = "Systeam",
                    PVI = json.PVI,
                    CarType = carInfo.CarType
                    CarType = carInfo.CarType,
                    RoadwayNo = station.RoadwayNo
                };
                _unitOfWorkManage.BeginTran();
@@ -137,5 +157,34 @@
            }
            return response;
        }
        private string GetInboundRoadWayNo(int CarType)
        {
            var maxGroup = _locationRepository.QueryData(x => x.LocationType == CarType && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == (int)EnableEnum.Enable)
                                .GroupBy(x => x.RoadwayNo)
                                .OrderByDescending(g => g.Count()) // æ ¹æ®æ¯ä¸ªç»„的元素数量排序
                                .ToList(); // å–出数量最多的组
            Dictionary<string, int> result = new Dictionary<string, int>();
            foreach (var item in maxGroup)
            {
                int number = 0;
                if (CarType == 3)
                {
                    number = _taskRepository.QueryData(x => x.RoadwayNo == item.Key && (x.TaskType == (int)TaskInboundTypeEnum.Inbound || x.TaskType == (int)TaskInboundTypeEnum.InTray) && x.TaskState <= (int)TaskInStatusEnum.Line_InFinish).Count();
                }
                else
                {
                    number = _taskRepository.QueryData(x => x.RoadwayNo == item.Key && x.CarType == CarType && (x.TaskType == (int)TaskInboundTypeEnum.Inbound || x.TaskType == (int)TaskInboundTypeEnum.InTray) && x.TaskState <= (int)TaskInStatusEnum.Line_InFinish).Count();
                }
                if (item.Count() - number <= 0)
                {
                    continue;
                }
                result.Add(item.Key, item.Count() - number);
            }
            return result.OrderByDescending(x => x.Value).FirstOrDefault().Key; // æ•°é‡æœ€å¤šçš„组的Key
        }
    }
}