diff --git a/ZR.Service/MES/dev/DeviceAccountService.cs b/ZR.Service/MES/dev/DeviceAccountService.cs index b243879..8fb7c30 100644 --- a/ZR.Service/MES/dev/DeviceAccountService.cs +++ b/ZR.Service/MES/dev/DeviceAccountService.cs @@ -11,6 +11,7 @@ using ZR.Model.MES.dev; using ZR.Model.MES.dev.Dto; using ZR.Service.MES.dev.IService; using System.ComponentModel; +using System.Diagnostics; namespace ZR.Service.MES.dev { @@ -332,16 +333,16 @@ namespace ZR.Service.MES.dev }).ToList(); // 获取 类型表 绑定的设备 父子节点 - List accountList=Context.Queryable().Where(it => it.Status == 1).OrderBy(it => it.Id) + List accountList = Context.Queryable().Where(it => it.Status == 1).OrderBy(it => it.Id) .Select(it => new SelectTreeDto { - Id = it.Id.ToString()+it.FkDeviceType.ToString() ,//解决合并后id重复 + Id = it.Id.ToString() + it.FkDeviceType.ToString(),//解决合并后id重复 ParentId = it.FkDeviceType.ToString(), Label = (it.DeviceName + '-' + it.DeviceCode), Value = it.Id.ToString() }).ToList(); - return deviceTypeList.Concat(accountList).OrderBy(it=>int.Parse(it.Id)).ToList(); + return deviceTypeList.Concat(accountList).OrderBy(it => int.Parse(it.Id)).ToList(); @@ -453,6 +454,7 @@ namespace ZR.Service.MES.dev /// public DeviceStatusAnalysisDto GetDeviceStatus(int devicetype_id) { + DeviceStatusAnalysisDto analysis = new DeviceStatusAnalysisDto(); // 设备总数 @@ -466,38 +468,40 @@ namespace ZR.Service.MES.dev // 停用总数 int NoUseTotal = 0; + Stopwatch stopwatch = new Stopwatch(); + // 开始计时 + stopwatch.Start(); // 1 获取设备类型下面所有的线 List All_device_type = null; - // DeviceType line = Context.Queryable().Where(it => it.Id == devicetype_id).First(); - //if (line.ParentId == 1) - //{ - // Workshop = line.Name; - // All_device_type = Context.Queryable().Where(it => it.ParentId == devicetype_id).ToList(); - //} - //else - //{ - // Workshop = Context.Queryable().Where(it => it.ParentId == line.ParentId).First().Name; - // All_device_type = new List { line }; - //} + All_device_type = FindAllLeafNodes(devicetype_id); - // DeviceType final_parent = FindFinalParentNode(devicetype_id); - //Workshop = final_parent.Name; + List LineDetailList = new List(); + // 停止计时 + stopwatch.Stop(); + + // 输出执行时间 + Console.WriteLine("代码段执行时间: {0} 秒", stopwatch.ElapsedMilliseconds/1000); // 2 获取每个线下的所有设备 if (All_device_type.Count > 0) { + List all_deviceTyepe_s= Context.Queryable().ToList(); + List all_account_s=Context.Queryable().ToList(); + List all_deviceRepair_s= Context.Queryable().ToList(); + foreach (DeviceType type in All_device_type) { LineDetail lineDetail = new LineDetail(); - lineDetail.Workshop = Context.Queryable().Where(n => n.Id == type.ParentId).Select(n => n.Name).First(); + lineDetail.Workshop = all_deviceTyepe_s.Where(n => n.Id == type.ParentId).Select(n => n.Name).First(); lineDetail.Workline = type.Name; - List accounts = Context.Queryable() - .Where(it => it.FkDeviceType == type.Id).ToList(); + List accounts = all_account_s.Where(it => it.FkDeviceType == type.Id).ToList(); + + lineDetail.Total = accounts.Count; AllTotal = AllTotal + lineDetail.Total; List Children = new List(); @@ -524,7 +528,7 @@ namespace ZR.Service.MES.dev } //0.3 判断是否报修中 - bool isExist = Context.Queryable() + bool isExist = all_deviceRepair_s .Where(it => it.FkDeviceId == item.Id) .Where(it => it.Status == 0 || it.Status == 1 || it.Status == 3).Any(); if (isExist) @@ -564,16 +568,13 @@ namespace ZR.Service.MES.dev .Where((e, p, r) => e.Status == 0 || e.Status == 1 || e.Status == 3) .Count(); - // UnmaintainedTotal = UnmaintainedTotal + isExist_route; if (isExist_route > 0) { - deviceInfo.DeviceStatus = 2; UnmaintainedTotal++; Children.Add(deviceInfo); continue; - } deviceInfo.DeviceStatus = 1; NormalTotal++; @@ -588,6 +589,7 @@ namespace ZR.Service.MES.dev } + } analysis.AllTotal = AllTotal; analysis.UnmaintainedTotal = UnmaintainedTotal; @@ -595,7 +597,7 @@ namespace ZR.Service.MES.dev analysis.DamageTotal = DamageTotal; analysis.NormalTotal = NormalTotal; analysis.NoUseTotal = NoUseTotal; - + return analysis; } @@ -607,6 +609,7 @@ namespace ZR.Service.MES.dev public List FindAllLeafNodes(int targetId) { + List list_device_types= Context.Queryable().ToList(); List childIds = new List { targetId }; List result = new List(); @@ -615,14 +618,14 @@ namespace ZR.Service.MES.dev int parentId = childIds.First(); childIds.RemoveAt(0); - List children = Context.Queryable().Where(n => n.ParentId == parentId).Select(n => n.Id).ToList(); + List children = list_device_types.Where(n => n.ParentId == parentId).Select(n => n.Id).ToList(); if (children.Any()) { childIds.AddRange(children); } else { - result.Add(Context.Queryable().First(n => n.Id == parentId)); + result.Add(list_device_types.First(n => n.Id == parentId)); } }