Пример #1
0
        public object GetArrangedTaskOrderPutAndWarehouse([FromQuery] int wId, DateTime startTime, DateTime endTime, DateTime deliveryTime, bool all)
        {
            var result = new SmartTaskOrderNeedOrderTimeResult();

            if (startTime == default(DateTime) || endTime == default(DateTime))
            {
                return(result);
            }
            var schedules = SmartTaskOrderScheduleHelper.GetSmartTaskOrderSchedule(wId, startTime, endTime);
            var tasks     = SmartTaskOrderHelper.GetAllArrangedButNotDoneSmartTaskOrderDetails(wId, deliveryTime, all);
            var taskIds   = tasks.Select(x => x.Id).Concat(schedules.Select(y => y.TaskOrderId)).Distinct();

            if (!taskIds.Any())
            {
                return(result);
            }

            tasks = SmartTaskOrderHelper.GetAllArrangedButNotDoneSmartTaskOrderDetails(wId, taskIds);
            var taskNeeds = SmartTaskOrderNeedHelper.GetSmartTaskOrderNeedsByTaskOrderIds(wId, taskIds, true);
            var orders    = taskNeeds.GroupBy(y => new { y.PId, y.Order, y.Process, y.CategoryId }).Select(z => new SmartTaskOrderNeedWithOrder
            {
                Id         = z.Key.PId,
                Process    = z.Key.Process,
                CategoryId = z.Key.CategoryId,
                Order      = z.Key.Order
            });

            result.StartTime = startTime;
            result.EndTime   = endTime;
            result.Orders.AddRange(orders.OrderBy(z => z.Order));

            //设备型号数量
            var deviceList = SmartDeviceHelper.GetNormalSmartDevices(wId);
            //人员等级数量
            var operatorList = SmartOperatorHelper.GetNormalSmartOperators(wId);
            var modelCount   = deviceList.GroupBy(x => new { x.CategoryId }).Select(y => new SmartDeviceModelCount
            {
                CategoryId = y.Key.CategoryId,
                Count      = y.Count()
            });
            var operatorCount = operatorList.GroupBy(x => new { x.ProcessId }).Select(y => new SmartOperatorCount
            {
                ProcessId = y.Key.ProcessId,
                Count     = y.Count()
            });
            //if (schedules.Any())
            //{
            //    var productIds = schedules.Select(x => x.ProductId);
            //    // 任务单计划号
            //    var products = SmartProductHelper.Instance.GetByIds<SmartProduct>(productIds);
            //    var capacityIds = products.Select(x => x.CapacityId);
            //    // 产能设置
            //    var smartCapacityLists = SmartCapacityListHelper.Instance.GetAllSmartCapacityListsWithOrder(capacityIds);
            //    //if ()
            //    //{

            //    //}
            //    ////产能配置
            //    //var capacityList = smartCapacityLists.Where(x => x.CapacityId == task.CapacityId);
            //    ////工序单日产能配置
            //    //var cList = capacityList.FirstOrDefault(x => x.ProcessId == y.ProcessId);
            //    //sc.Index
            //}
            var ts = taskNeeds.Where(n => tasks.Any(task => task.Id == n.TaskOrderId)).Select(x =>
            {
                var task = tasks.First(t => t.Id == x.TaskOrderId);
                var need = new SmartTaskOrderScheduleSumInfoResult
                {
                    Id           = x.Id,
                    TaskOrderId  = x.TaskOrderId,
                    TaskOrder    = x.TaskOrder,
                    ProductId    = x.ProductId,
                    Product      = x.Product,
                    DeliveryTime = task.DeliveryTime,
                    ArrangedTime = task.ArrangedTime,
                    PId          = x.PId,
                    ProcessId    = x.ProcessId,
                    Process      = x.Process,
                    Order        = x.Order,
                    Put          = x.Put,
                    HavePut      = x.HavePut,
                    Target       = x.Target,
                    DoneTarget   = x.DoneTarget,
                };
                var schedule = schedules.Where(sc => sc.TaskOrderId == need.TaskOrderId && sc.ProcessId == need.ProcessId && sc.PId == need.PId).ToList();
                for (var i = 0; i < (result.EndTime - result.StartTime).TotalDays + 1; i++)
                {
                    var t = result.StartTime.AddDays(i);
                    if (schedule.All(p => p.ProcessTime != t))
                    {
                        schedule.Add(new SmartTaskOrderScheduleDetail()
                        {
                            ProcessTime = t
                        });
                    }
                }

                schedule = schedule.OrderBy(sc => sc.ProcessTime).ToList();
                need.Schedules.AddRange(schedule.Select(y => new SmartTaskOrderScheduleInfoResult
                {
                    Id          = y.Id,
                    ProductType = y.ProductType,
                    ProcessTime = y.ProcessTime,
                    Put         = y.Put,
                    HavePut     = y.HavePut,
                    Target      = y.Target,
                    DoneTarget  = y.DoneTarget,
                }));
                return(need);
            });

            result.datas.AddRange(ts.OrderBy(x => x.DeliveryTime).ThenBy(x => x.ArrangedTime));

            var indexes        = SmartTaskOrderScheduleIndexHelper.GetSmartTaskOrderScheduleIndex(wId, startTime, endTime).ToList();
            var arrangeIndexes = new List <SmartTaskOrderScheduleIndex>();

            foreach (var order in result.Orders)
            {
                for (var i = 0; i < (result.EndTime - result.StartTime).TotalDays + 1; i++)
                {
                    var t = result.StartTime.AddDays(i);
                    if (!indexes.Any(p => p.ProcessTime == t && p.PId == order.Id))
                    {
                        arrangeIndexes.Add(new SmartTaskOrderScheduleIndex
                        {
                            ProcessTime = t,
                            PId         = order.Id,
                        });
                    }
                    else
                    {
                        var     ins   = indexes.Where(p => p.ProcessTime == t && p.PId == order.Id);
                        decimal index = 0;
                        if (ins.Any())
                        {
                            var cnt = ins.First().ProductType == 0
                                ? (modelCount.FirstOrDefault(x => x.CategoryId == order.CategoryId)?.Count ?? 0)
                                : (operatorCount.FirstOrDefault(x => x.ProcessId == order.Id)?.Count ?? 0);
                            index = cnt == 0 ? 0 : (ins.Sum(x => x.Index) / cnt).ToRound(2);
                        }
                        arrangeIndexes.Add(new SmartTaskOrderScheduleIndex
                        {
                            ProcessTime = t,
                            PId         = order.Id,
                            Index       = index
                        });
                    }
                }
            }
            result.Indexes.AddRange(arrangeIndexes.OrderBy(x => result.Orders.FirstOrDefault(y => y.Id == x.PId)?.Order ?? 0).ThenBy(z => z.ProcessTime));
            return(result);
        }
Пример #2
0
        public object GetArrangedTaskOrderPutIndex([FromQuery] int wId, DateTime time, int pId)
        {
            var result = new DataResult();
            var data   =
                SmartTaskOrderScheduleIndexHelper.GetSmartTaskOrderScheduleIndex(wId, time, default(DateTime), pId)
                .Select(ClassExtension.ParentCopyToChild <SmartTaskOrderScheduleIndex, SmartTaskOrderScheduleIndexDetail>).Where(x => x.Index > 0).ToList();

            if (!data.Any())
            {
                return(result);
            }
            //设备型号数量
            var deviceList = SmartDeviceHelper.GetNormalSmartDevices(wId);
            //人员等级数量
            var operatorList = SmartOperatorHelper.GetNormalSmartOperators(wId);
            var modelCount   = deviceList.GroupBy(x => new { x.CategoryId, x.ModelId }).Select(y => new SmartDeviceModelCount
            {
                CategoryId = y.Key.CategoryId,
                ModelId    = y.Key.ModelId,
                Count      = y.Count()
            });
            var operatorCount = operatorList.GroupBy(x => new { x.ProcessId, x.LevelId }).Select(y => new SmartOperatorCount
            {
                ProcessId = y.Key.ProcessId,
                LevelId   = y.Key.LevelId,
                Count     = y.Count()
            });
            var order       = SmartProcessHelper.Instance.Get <SmartProcess>(pId);
            var productType = data.First().ProductType;

            if (productType == 0)
            {
                var devices = deviceList.Where(x => x.CategoryId == order.CategoryId);
                foreach (var device in devices)
                {
                    if (data.All(p => p.DealId != device.Id))
                    {
                        data.Add(new SmartTaskOrderScheduleIndexDetail
                        {
                            WorkshopId  = wId,
                            ProductType = productType,
                            ProcessTime = time,
                            PId         = pId,
                            DealId      = device.Id
                        });
                    }
                }
            }
            else if (productType == 1)
            {
                var operators = operatorList.Where(x => x.ProcessId == order.Id);
                foreach (var op in operators)
                {
                    if (data.All(p => p.DealId != op.Id))
                    {
                        data.Add(new SmartTaskOrderScheduleIndexDetail
                        {
                            WorkshopId  = wId,
                            ProductType = productType,
                            ProcessTime = time,
                            PId         = pId,
                            DealId      = op.Id
                        });
                    }
                }
            }

            foreach (var x in data)
            {
                if (x.ProductType == 0)
                {
                    x.Code = deviceList.FirstOrDefault(z => z.Id == x.DealId)?.Code ?? "";
                }
                else if (x.ProductType == 1)
                {
                    x.Name = operatorList.FirstOrDefault(z => z.Id == x.DealId)?.Name ?? "";
                }
            }
            result.datas.AddRange(data);
            return(result);
        }