Exemplo n.º 1
0
        public Result PostSmartOperator([FromBody] IEnumerable <SmartOperator> operators)
        {
            if (operators == null || !operators.Any())
            {
                return(Result.GenError <Result>(Error.ParamError));
            }
            if (operators.Any(x => x.UserId == 0))
            {
                return(Result.GenError <Result>(Error.SmartOperatorNotEmpty));
            }

            var wId  = operators.FirstOrDefault()?.WorkshopId ?? 0;
            var uIds = operators.Select(x => x.UserId.ToString());

            if (SmartOperatorHelper.GetHaveSame(wId, uIds))
            {
                return(Result.GenError <Result>(Error.SmartOperatorDuplicate));
            }

            var userId         = Request.GetIdentityInformation();
            var markedDateTime = DateTime.Now;

            foreach (var op in operators)
            {
                op.CreateUserId   = userId;
                op.MarkedDateTime = markedDateTime;
                op.Remark         = op.Remark ?? "";
            }

            SmartOperatorHelper.Instance.Add(operators);
            OldWorkFlowHelper.Instance.OnSmartOperatorChanged(operators);
            return(Result.GenError <Result>(Error.Success));
        }
Exemplo n.º 2
0
        public DataResult GetSmartOperator([FromQuery] bool menu, bool add, int qId, int wId, int levelId = -1,
                                           int processId = -1, string number = "", string name = "", SmartOperatorState state = SmartOperatorState.全部, int condition = 0)
        {
            var result = new DataResult();

            result.datas.AddRange(menu
                ? SmartOperatorHelper.GetMenu(add, qId, wId, levelId, processId, number, name, state, condition)
                : SmartOperatorHelper.GetDetail(add, qId, wId, levelId, processId, number, name, state, condition));
            if (qId != 0 && !result.datas.Any())
            {
                result.errno = Error.SmartOperatorNotExist;
                return(result);
            }
            return(result);
        }
        public object PostSmartSchedulePreview([FromBody] IEnumerable <SmartTaskOrderCapacity> taskOrders)
        {
            if (taskOrders == null)
            {
                return(Result.GenError <Result>(Error.ParamError));
            }
            var taskIds = taskOrders.GroupBy(x => x.Id).Select(y => y.Key);

            if (taskIds.Count() != taskOrders.Count())
            {
                return(Result.GenError <Result>(Error.SmartTaskOrderDuplicate));
            }
            var result = new SmartTaskOrderNeedWithOrderPreviewResult();
            var wId    = taskOrders.FirstOrDefault()?.WorkshopId ?? 0;

            if (taskOrders.Any())
            {
                var tOrders = SmartTaskOrderHelper.Instance.GetByIds <SmartTaskOrderCapacity>(taskIds);
                if (taskIds.Count() != tOrders.Count())
                {
                    result.errno = Error.SmartTaskOrderNotExist;
                    result.datas.AddRange(taskOrders.Where(x => tOrders.All(y => y.Id != x.Id)).Select(x => x.TaskOrder.IsNullOrEmpty() ? x.Id.ToString() : x.TaskOrder));
                    return(result);
                }

                foreach (var task in taskOrders)
                {
                    var t = tOrders.FirstOrDefault(x => x.Id == task.Id);
                    if (t == null)
                    {
                        result.errno = Error.SmartTaskOrderNotExist;
                        result.datas.Add(task.TaskOrder);
                    }
                    else
                    {
                        task.TaskOrder    = t.TaskOrder;
                        task.Target       = t.Target;
                        task.DeliveryTime = t.DeliveryTime;
                        task.ProductId    = t.ProductId;
                        task.CapacityId   = t.CapacityId;
                    }
                }
            }

            if (result.errno != Error.Success)
            {
                return(result);
            }
            var productIds = taskOrders.GroupBy(x => x.ProductId).Select(y => y.Key);

            if (!productIds.Any())
            {
                return(Result.GenError <Result>(Error.SmartProductNotExist));
            }

            var products = SmartProductHelper.Instance.GetByIds <SmartProduct>(productIds);

            if (products.Count() != productIds.Count())
            {
                return(Result.GenError <Result>(Error.SmartProductNotExist));
            }

            var productCapacities = SmartProductCapacityHelper.GetSmartProductCapacities(productIds);

            if (!productCapacities.Any())
            {
                return(Result.GenError <Result>(Error.SmartProductCapacityNotExist));
            }

            var capacityIds = products.GroupBy(x => x.CapacityId).Select(y => y.Key);

            if (!capacityIds.Any())
            {
                return(Result.GenError <Result>(Error.SmartCapacityNotExist));
            }
            var capacityLists = SmartCapacityListHelper.GetSmartCapacityListsWithOrder(capacityIds);

            foreach (var productId in productIds)
            {
                var tasks       = taskOrders.Where(x => x.ProductId == productId);
                var product     = products.FirstOrDefault(x => x.Id == productId);
                var pCapacities = productCapacities.Where(x => x.ProductId == productId);
                var cLists      = capacityLists.Where(x => x.CapacityId == product.CapacityId);
                if (cLists.Count() != pCapacities.Count())
                {
                    result.errno = Error.SmartProductCapacityNotExist;
                    result.datas.AddRange(tasks.Select(x => x.TaskOrder));
                }
            }

            if (result.errno != Error.Success)
            {
                return(result);
            }
            //设备型号
            var deviceModels = SmartDeviceModelHelper.Instance.GetAll <SmartDeviceModel>();
            //设备型号数量
            var deviceList  = SmartDeviceHelper.GetNormalSmartDevices(wId);
            var modelCounts = deviceList.GroupBy(x => new { x.CategoryId, x.ModelId }).Select(y => new SmartDeviceModelCount
            {
                CategoryId = y.Key.CategoryId,
                ModelId    = y.Key.ModelId,
                Count      = y.Count()
            });
            //人员等级
            var operatorLevels = SmartOperatorLevelHelper.Instance.GetAll <SmartOperatorLevel>();
            //人员等级数量
            var operatorList   = SmartOperatorHelper.GetNormalSmartOperators(wId);
            var operatorCounts = operatorList.GroupBy(x => new { x.ProcessId, x.LevelId }).Select(y => new SmartOperatorCount
            {
                ProcessId = y.Key.ProcessId,
                LevelId   = y.Key.LevelId,
                Count     = y.Count()
            });
            var taskNeeds = SmartTaskOrderNeedHelper.GetSmartTaskOrderNeedsByTaskOrderIds(wId, taskIds);

            foreach (var task in taskOrders)
            {
                var needs = taskNeeds.Where(need => need.TaskOrderId == task.Id);
                if (task.Needs.Any())
                {
                    task.Needs = task.Needs.Select(x =>
                    {
                        var need = needs.FirstOrDefault(y => y.TaskOrderId == x.TaskOrderId && y.PId == x.PId);
                        if (need != null)
                        {
                            x.DoneTarget = need.DoneTarget;
                            x.HavePut    = need.HavePut;
                        }

                        return(x);
                    }).ToList();
                }
                var oldNeeds = task.Needs.ToList();
                task.Needs.Clear();
                var productId = task.ProductId;
                var product   = products.FirstOrDefault(x => x.Id == productId);
                task.Product = product.Product;
                var pCapacities = productCapacities.Where(x => x.ProductId == productId);
                var cLists      = capacityLists.Where(x => x.CapacityId == product.CapacityId);
                var target      = task.Target;
                foreach (var cList in cLists.Reverse())
                {
                    var need       = oldNeeds.FirstOrDefault(x => x.Id == cList.Id);
                    var stock      = need?.Stock ?? 0;
                    var doneTarget = need?.DoneTarget ?? 0;
                    var havePut    = need?.HavePut ?? 0;
                    if (target < stock)
                    {
                        stock  = target;
                        target = 0;
                    }
                    else
                    {
                        target -= stock;
                    }

                    if (!task.All)
                    {
                        target = target > doneTarget ? target - doneTarget : 0;
                    }
                    var pCapacity = pCapacities.FirstOrDefault(x => x.ProcessId == cList.ProcessId);
                    var rate      = 0m;
                    var y         = pCapacity;
                    if (y.DeviceList.Any())
                    {
                        rate = y.DeviceList.First().Rate;
                    }
                    else if (y.OperatorList.Any())
                    {
                        rate = y.OperatorList.First().Rate;
                    }
                    var put     = rate != 0 ? (int)Math.Ceiling((target) * 100 / rate) : 0;
                    var newNeed = new SmartTaskOrderCapacityNeed
                    {
                        Id          = cList.Id,
                        TaskOrderId = task.Id,
                        ProductId   = productId,
                        ProcessId   = cList.ProcessId,
                        CategoryId  = cList.CategoryId,
                        PId         = cList.PId,
                        Target      = target,
                        DoneTarget  = doneTarget,
                        Stock       = stock,
                        Rate        = rate,
                        Put         = put,
                        HavePut     = havePut,
                        Process     = cList.Process,
                        Order       = cList.Order
                    };
                    if (need != null)
                    {
                        newNeed.Devices       = need.Devices;
                        newNeed.NeedDCapacity = newNeed.DCapacity != 0 ? ((decimal)put / newNeed.DCapacity).ToRound() : 0;
                        foreach (var device in need.DeviceList)
                        {
                            var modelCount = modelCounts.FirstOrDefault(x => x.ModelId == device.Key)?.Count ?? 0;
                            newNeed.TotalDCapacity += modelCount * device.Value.Item1 * device.Value.Item2;
                        }
                        newNeed.HaveDCapacity = newNeed.DCapacity != 0 ? ((decimal)newNeed.TotalDCapacity / newNeed.DCapacity).ToRound() : 0;

                        newNeed.Operators     = need.Operators;
                        newNeed.NeedOCapacity = newNeed.OCapacity != 0 ? ((decimal)put / newNeed.OCapacity).ToRound() : 0;
                        foreach (var op in need.OperatorsList)
                        {
                            var operatorCount = operatorCounts.FirstOrDefault(x => x.LevelId == op.Key)?.Count ?? 0;
                            newNeed.TotalOCapacity += operatorCount * op.Value.Item1 * op.Value.Item2;
                        }
                        newNeed.HaveOCapacity = newNeed.OCapacity != 0 ? ((decimal)newNeed.TotalOCapacity / newNeed.OCapacity).ToRound() : 0;
                    }
                    task.Needs.Insert(0, newNeed);
                    target = put;
                }
            }
            result.datas.AddRange(taskOrders);
            var orders = taskOrders.SelectMany(x => x.Needs).GroupBy(y => new { y.PId, y.Order, y.Process }).Select(z => new SmartTaskOrderNeedWithOrderPreview
            {
                Id      = z.Key.PId,
                Process = z.Key.Process,
                Order   = z.Key.Order
            }).ToList();

            foreach (var task in taskOrders)
            {
                foreach (var newNeed in task.Needs)
                {
                    var order = orders.FirstOrDefault(x => x.Id == newNeed.PId);
                    if (order != null)
                    {
                        order.Stock  += newNeed.Stock;
                        order.Put    += newNeed.Put;
                        order.Target += newNeed.Target;
                        if (newNeed.DeviceList.Any())
                        {
                            foreach (var device in newNeed.DeviceList)
                            {
                                var modelDevice = order.Devices.FirstOrDefault(x => x.Id == device.Key);
                                if (modelDevice == null)
                                {
                                    order.Devices.Add(new SmartTaskOrderNeedCapacityPreview
                                    {
                                        Id   = device.Key,
                                        Name = deviceModels.FirstOrDefault(x => x.Id == device.Key)?.Model ?? "",
                                    });
                                }
                                modelDevice = order.Devices.FirstOrDefault(x => x.Id == device.Key);
                                modelDevice.NeedCapacity += newNeed.NeedDCapacity;

                                var modelCount = modelCounts.FirstOrDefault(x => x.ModelId == device.Key)?.Count ?? 0;
                                modelDevice.HaveCapacity = modelCount;
                            }
                        }

                        if (newNeed.OperatorsList.Any())
                        {
                            foreach (var op in newNeed.OperatorsList)
                            {
                                var levelOp = order.Operators.FirstOrDefault(x => x.Id == op.Key);
                                if (levelOp == null)
                                {
                                    order.Operators.Add(new SmartTaskOrderNeedCapacityPreview
                                    {
                                        Id   = op.Key,
                                        Name = operatorLevels.FirstOrDefault(x => x.Id == op.Key)?.Level ?? "",
                                    });
                                }
                                levelOp = order.Operators.FirstOrDefault(x => x.Id == op.Key);
                                levelOp.NeedCapacity += newNeed.NeedOCapacity;

                                var operatorCount = operatorCounts.FirstOrDefault(x => newNeed.PId == x.ProcessId && x.LevelId == op.Key)?.Count ?? 0;
                                levelOp.HaveCapacity = operatorCount;
                            }
                        }
                    }
                }
            }
            result.Orders.AddRange(orders.OrderBy(z => z.Order).Select(x =>
            {
                x.Devices   = x.Devices.OrderBy(y => y.Id).ToList();
                x.Operators = x.Operators.OrderBy(y => y.Id).ToList();
                return(x);
            }));
            return(result);
        }
Exemplo n.º 4
0
        public object PostSmartScheduleCostDay([FromBody] SmartTaskOrderArrangeParam arrange)
        {
            var taskOrders = arrange.Confirms;
            var wId        = arrange.WorkshopId;

            if (taskOrders == null || !taskOrders.Any())
            {
                return(Result.GenError <Result>(Error.ParamError));
            }
            if (taskOrders.Any(x => !x.Needs.Any()))
            {
                return(Result.GenError <Result>(Error.SmartScheduleNeedLost));
            }

            var today      = DateTime.Today;
            var schedules  = new List <SmartTaskOrderScheduleDetail>();
            var costDays   = HScheduleHelper.ArrangeSchedule(wId, ref taskOrders, ref schedules, out var indexes);
            var eStartTime = costDays.Any() ? costDays.Min(x => x.EstimatedStartTime) : today;

            if (eStartTime == default(DateTime))
            {
                eStartTime = today;
            }
            var eEndTime = costDays.Any() ? costDays.Max(x => x.EstimatedEndTime) : today;

            if (eEndTime == default(DateTime))
            {
                eEndTime = today;
            }
            var put    = new List <object>();
            var orders = new List <SmartTaskOrderNeedWithOrder>();
            //设备型号数量
            var deviceList = SmartDeviceHelper.Instance.GetAll <SmartDevice>();
            //人员等级数量
            var operatorList = SmartOperatorHelper.GetAllSmartOperators();
            //按工序排
            var processes = schedules.GroupBy(x => new { x.PId, x.Process, x.Order }).Select(y => y.Key);
            var ts        = costDays.SelectMany(costDay =>
            {
                var taskNeeds = taskOrders.First(x => x.Id == costDay.Id).Needs;
                return(taskNeeds.Where(n => taskOrders.Any(task => task.Id == n.TaskOrderId)).Select(x =>
                {
                    var task = taskOrders.First(t => t.Id == x.TaskOrderId);
                    var schedule = schedules.Where(sc =>
                                                   sc.TaskOrderId == x.TaskOrderId && sc.ProcessId == x.ProcessId && sc.PId == x.PId).ToList();
                    var totalDays = (eEndTime - eStartTime).TotalDays + 1;
                    if (schedule.Count < totalDays)
                    {
                        for (var i = 0; i < (eEndTime - eStartTime).TotalDays + 1; i++)
                        {
                            var t = eStartTime.AddDays(i);
                            if (schedule.All(p => p.ProcessTime != t))
                            {
                                schedule.Add(new SmartTaskOrderScheduleDetail()
                                {
                                    ProcessTime = t
                                });
                            }
                        }

                        schedule = schedule.OrderBy(sc => sc.ProcessTime).ToList();
                    }

                    var scs = schedule.Select(y =>
                    {
                        var d = new SmartTaskOrderSchedulePutAndWarehouseInfoResult
                        {
                            ProcessTime = y.ProcessTime,
                            TaskOrderId = y.TaskOrderId,
                            TaskOrder = y.TaskOrder,
                            Target = y.Target,
                            DoneTarget = y.DoneTarget,
                            Put = y.Put,
                            HavePut = y.HavePut,
                        };

                        if (y.ProductType == 0)
                        {
                            d.Arranges = y.DeviceList.ToDictionary(de => de.Key,
                                                                   de =>
                            {
                                var ope = deviceList.FirstOrDefault(dl => dl.Id == de.Key);
                                return new Tuple <string, int>(ope?.Code ?? "", de.Value);
                            });
                        }
                        else if (d.ProductType == 1)
                        {
                            d.Arranges = y.OperatorsList.ToDictionary(op => op.Key,
                                                                      op =>
                            {
                                var ope = operatorList.FirstOrDefault(dl => dl.Id == op.Key);
                                return new Tuple <string, int>(ope?.Name ?? "", op.Value);
                            });
                        }
                        ;
                        var s = new
                        {
                            Id = y.Id,
                            ProductType = y.ProductType,
                            ProcessTime = y.ProcessTime,
                            Put = y.Put,
                            HavePut = y.HavePut,
                            Target = y.Target,
                            DoneTarget = y.DoneTarget,
                            Data = d
                        };
                        return s;
                    });
                    var need = new
                    {
                        Id = x.Id,
                        TaskOrderId = x.TaskOrderId,
                        TaskOrder = task.TaskOrder,
                        ProductId = x.ProductId,
                        Product = task.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,
                        Schedules = scs
                    };
                    return need;
                }));
            });

            put.AddRange(ts);

            orders.AddRange(costDays.SelectMany(x => x.CostDays).GroupBy(y => new { y.PId, y.Process, y.Order }).Select(z => new SmartTaskOrderNeedWithOrder
            {
                Id      = z.Key.PId,
                Process = z.Key.Process,
                Order   = z.Key.Order
            }).OrderBy(z => z.Order));

            var arrangeIndexes = new List <SmartTaskOrderScheduleIndex>();

            foreach (var order in orders)
            {
                for (var i = 0; i < (eEndTime - eStartTime).TotalDays + 1; i++)
                {
                    var t = eStartTime.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);
                        arrangeIndexes.Add(new SmartTaskOrderScheduleIndex
                        {
                            ProcessTime = t,
                            PId         = order.Id,
                            Index       = !ins.Any() ? 0 : (ins.Sum(index => index.Index) / ins.Count()).ToRound(2)
                        });
                    }
                }
            }

            var indexs = arrangeIndexes.OrderBy(x => orders.FirstOrDefault(y => y.Id == x.PId)?.Order ?? 0)
                         .ThenBy(z => z.ProcessTime);

            return(new
            {
                errno = 0,
                errmsg = "成功",
                StartTime = eStartTime,
                EndTime = eEndTime,
                Orders = orders,
                Cost = costDays,
                //Schedule = schedules,
                Schedule = schedules.Select(x =>
                                            new
                {
                    x.ProcessTime,
                    x.PId,
                    x.TaskOrder,
                    x.TaskOrderId,
                    x.ProcessId,
                    x.ProductId,
                    x.Target,
                    x.Put,
                    x.Have,
                    x.HavePut,
                    x.LeftPut,
                    x.Rate,
                    x.Stock,
                    x.LeftTarget,
                    x.DoneTarget,
                    x.Done
                }),
                Put = put,
                Indexes = indexs
            });
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public object GetArrangedTaskOrderPutDetail([FromQuery] int wId, int id, int taskOrderId, int pId)
        {
            var result = new DataResult();
            IEnumerable <SmartTaskOrderSchedulePutInfoResult> data = null;

            if (id != 0)
            {
                var sql = $"SELECT a.ProcessTime, a.TaskOrderId, b.TaskOrder, a.ProductId, a.ProductType, a.Put, a.HavePut, a.Devices, a.Operators " +
                          $"FROM `t_task_order_schedule` a " +
                          $"JOIN `t_task_order` b ON a.TaskOrderId = b.Id " +
                          $"WHERE a.Id = @id AND a.WorkshopId = @wId;";
                data = ServerConfig.ApiDb.Query <SmartTaskOrderSchedulePutInfoResult>(sql, new
                {
                    wId,
                    id,
                    taskOrderId
                });
            }
            else if (taskOrderId != 0 && pId != 0)
            {
                data = SmartTaskOrderScheduleHelper.GetSmartTaskOrderSchedule(wId, taskOrderId, pId).Select(x => new SmartTaskOrderSchedulePutInfoResult
                {
                    ProcessTime = x.ProcessTime,
                    ProductType = x.ProductType,
                    TaskOrderId = x.TaskOrderId,
                    TaskOrder   = x.TaskOrder,
                    ProductId   = x.ProductId,
                    Put         = x.Target,
                    HavePut     = x.DoneTarget
                });
            }

            if (data == null)
            {
                return(result);
            }
            data = data.Where(x => x.Put > 0);
            if (!data.Any())
            {
                return(result);
            }
            //设备型号数量
            var deviceList = SmartDeviceHelper.Instance.GetAll <SmartDevice>();
            //人员等级数量
            var operatorList = SmartOperatorHelper.GetAllSmartOperators();

            //// 任务单计划号
            //var productIds = data.Select(x => x.ProductId);
            //// 任务单计划号
            //var products = SmartProductHelper.Instance.GetByIds<SmartProduct>(productIds);
            //// 计划号产能
            //var productCapacities = SmartProductCapacityHelper.Instance.GetAllSmartProductCapacities(productIds);
            //var capacityIds = products.Select(x => x.CapacityId);
            //// 产能设置
            //var smartCapacityLists = SmartCapacityListHelper.Instance.GetAllSmartCapacityListsWithOrder(capacityIds);
            foreach (var d in data)
            {
                if (d.ProductType == 0)
                {
                    d.Arranges = d.DeviceList.ToDictionary(de => de.Key,
                                                           de =>
                    {
                        var ope = deviceList.FirstOrDefault(dl => dl.Id == de.Key);
                        //var processId = d.ProcessId;
                        //var productId = d.ProductId;
                        ////计划号工序单日产能
                        //var pCapacity = productCapacities.FirstOrDefault(x => x.ProductId == productId && x.ProcessId == processId);
                        //var capacityId = pCapacity?.CapacityId ?? 0;
                        //var capacityList = smartCapacityLists.FirstOrDefault(x => x.CapacityId == capacityId && x.ProcessId == processId);
                        //var single = capacityList != null ? capacityList.OperatorList.FirstOrDefault(x => x.LevelId == (ope?.ModelId ?? 0))?.Single ?? 0 : 0;
                        //return new Tuple<string, int, int>(ope?.Code ?? "", de.Value, de.Value * single);
                        //return new Tuple<string, int, int>(ope?.Code ?? "", de.Value.Item1, de.Value.Item2);
                        return(new Tuple <string, int>(ope?.Code ?? "", de.Value));
                    });
                }
                else if (d.ProductType == 1)
                {
                    d.Arranges = d.OperatorsList.ToDictionary(op => op.Key,
                                                              op =>
                    {
                        var ope = operatorList.FirstOrDefault(dl => dl.Id == op.Key);
                        //var processId = d.ProcessId;
                        //var productId = d.ProductId;
                        ////计划号工序单日产能
                        //var pCapacity = productCapacities.FirstOrDefault(x => x.ProductId == productId && x.ProcessId == processId);
                        //var capacityId = pCapacity?.CapacityId ?? 0;
                        //var capacityList = smartCapacityLists.FirstOrDefault(x => x.CapacityId == capacityId && x.ProcessId == processId);
                        //var single = capacityList != null ? capacityList.OperatorList.FirstOrDefault(x => x.LevelId == (ope?.LevelId ?? 0))?.Single ?? 0 : 0;
                        //return new Tuple<string, int, int>(ope?.Name ?? "", op.Value, op.Value * single);
                        return(new Tuple <string, int>(ope?.Name ?? "", op.Value));
                    });
                }
                ;
            }
            result.datas.AddRange(data);
            return(result);
        }
        public object GetSmartCapacityListInfo([FromQuery] int qId, int processId)
        {
            var result           = new DataResult();
            var deviceCategoryId = 0;
            SmartCapacityListDetail capacityList = null;

            if (qId != 0)
            {
                capacityList = SmartCapacityListHelper.GetDetail(qId);
                if (capacityList == null)
                {
                    return(Result.GenError <Result>(Error.SmartCapacityListNotExist));
                }
                var capacity = SmartCapacityHelper.Instance.Get <SmartCapacity>(capacityList.CapacityId);
                if (capacity == null)
                {
                    return(Result.GenError <Result>(Error.SmartCapacityNotExist));
                }

                deviceCategoryId = capacityList.CategoryId;
            }
            else if (processId != 0)
            {
                var process = SmartProcessCodeCategoryProcessHelper.GetDetailByProcessId(processId);
                if (process == null)
                {
                    return(Result.GenError <Result>(Error.SmartProcessCodeCategoryProcessNotExist));
                }

                capacityList = new SmartCapacityListDetail
                {
                    ProcessId = process.Id
                };
                deviceCategoryId = process.CategoryId;
            }
            else
            {
                return(Result.GenError <Result>(Error.ParamError));
            }

            capacityList.PId = SmartProcessCodeCategoryProcessHelper.Instance.Get <SmartProcessCodeCategoryProcess>(capacityList.ProcessId)?.ProcessId ?? 0;
            var actDevices = new List <SmartDeviceCapacity>();

            if (deviceCategoryId != 0)
            {
                var models  = SmartDeviceModelHelper.GetDetail(0, deviceCategoryId);
                var devices = capacityList.DeviceList;
                if (models.Any())
                {
                    var modelCount = SmartDeviceHelper.GetNormalDeviceModelCount(models.Select(x => x.Id));
                    foreach (var model in models)
                    {
                        var device = devices.FirstOrDefault(x => x.ModelId == model.Id) ?? new SmartDeviceCapacity();
                        device.Category   = model.Category;
                        device.CategoryId = model.CategoryId;
                        device.ModelId    = model.Id;
                        device.Model      = model.Model;
                        device.Count      = modelCount.FirstOrDefault(x => x.ModelId == model.Id) != null
                            ? modelCount.FirstOrDefault(x => x.ModelId == model.Id).Count : 0;

                        actDevices.Add(device);
                    }
                }
            }

            var actOperators = new List <SmartOperatorCapacity>();
            var levels       = SmartOperatorLevelHelper.Instance.GetAll <SmartOperatorLevel>().OrderBy(x => x.Order);

            if (levels.Any())
            {
                var operatorCount = SmartOperatorHelper.GetNormalOperatorCount(capacityList.ProcessId);
                var operators     = capacityList.OperatorList;
                if (levels.Any())
                {
                    foreach (var level in levels)
                    {
                        var op = operators.FirstOrDefault(x => x.LevelId == level.Id) ?? new SmartOperatorCapacity();
                        op.Level   = level.Level;
                        op.LevelId = level.Id;
                        op.Count   = operatorCount.FirstOrDefault(x => x.ProcessId == capacityList.PId && x.LevelId == op.LevelId) != null
                            ? operatorCount.FirstOrDefault(x => x.ProcessId == capacityList.PId && x.LevelId == level.Id).Count : 0;

                        actOperators.Add(op);
                    }
                }
            }

            result.datas.Add(capacityList);
            return(new
            {
                errno = 0,
                errmsg = "成功",
                Devices = actDevices,
                Operators = actOperators
            });
        }