public object PostSmartScheduleConfirm([FromBody] SmartTaskOrderArrangeParam arrange) { var taskOrders = arrange.Confirms; 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 userId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; var schedules = new List <SmartTaskOrderScheduleDetail>(); var costDays = HScheduleHelper.ArrangeSchedule(arrange.WorkshopId, ref taskOrders, ref schedules, out _, true, userId, markedDateTime); OldWorkFlowHelper.Instance.OnTaskOrderArrangeChanged(); return(Result.GenError <Result>(Error.Success)); }
public static void Init(IConfiguration configuration) { RedisHelper.Init(configuration); RedisHelper.CloseWrite = _close; ServerId = configuration.GetAppSettings <int>("ServerId"); IsAnalysis = configuration.GetAppSettings <bool>("Analysis"); ApiDb = new DataBase(configuration.GetConnectionString("ApiDb")) { CloseWrite = _close }; _loads = new Dictionary <string, Action> { //{PermissionHelper.TableName, PermissionHelper.LoadConfig}, { "ReadDB", LoadDateBase }, { PermissionHelper.TableName, PermissionHelper.LoadConfig }, { PermissionGroupHelper.TableName, PermissionGroupHelper.LoadConfig }, { NpcProxyLinkServerHelper.TableName, NpcProxyLinkServerHelper.LoadConfig }, }; foreach (var action in _loads.Values) { action(); } GateUrl = configuration.GetAppSettings <string>("GateUrl"); ErpUrl = configuration.GetAppSettings <string>("ErpUrl"); GlobalConfig.LoadGlobalConfig(); AccountInfoHelper.Init(configuration); WorkFlowHelper.Init(); OldWorkFlowHelper.Init(); //HMaterialHelper.MaterialChange3(); //return; if (ServerId == 1) { HKanBanHelper.Init(); } else if (ServerId == 2) { HNotifyHelper.Init(); HWarningHelper.Init(); HOpScheduleHelper.Init(); //HFlowCardHelper.Init(); //SimulateHelper.Init(); HScheduleHelper.Init(); TimerHelper.Init(); //HMaterialHelper.Init(); } else if (ServerId == 3) { AnalysisHelper.Init(); HKanBanHelper.Init(); } if (!RedisHelper.Exists(IsSetProcessDataKey)) { RedisHelper.SetForever(IsSetProcessDataKey, 1); } if (!RedisHelper.Exists(IsSetDataIgnoreKey)) { RedisHelper.SetForever(IsSetDataIgnoreKey, 0); } _loads.Add(HWarningHelper.RedisReloadKey, HWarningHelper.NeedReload); _loads.Add(HOpScheduleHelper.RedisReloadKey, HOpScheduleHelper.NeedReload); Log.InfoFormat("ServerConfig Done"); }
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 }); }