This commit is contained in:
赵正易 2024-06-26 17:08:37 +08:00
commit a4eee855b5

View File

@ -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<SelectTreeDto> accountList=Context.Queryable<DeviceAccount>().Where(it => it.Status == 1).OrderBy(it => it.Id)
List<SelectTreeDto> accountList = Context.Queryable<DeviceAccount>().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
/// <returns></returns>
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<DeviceType> All_device_type = null;
// DeviceType line = Context.Queryable<DeviceType>().Where(it => it.Id == devicetype_id).First();
//if (line.ParentId == 1)
//{
// Workshop = line.Name;
// All_device_type = Context.Queryable<DeviceType>().Where(it => it.ParentId == devicetype_id).ToList();
//}
//else
//{
// Workshop = Context.Queryable<DeviceType>().Where(it => it.ParentId == line.ParentId).First().Name;
// All_device_type = new List<DeviceType> { line };
//}
All_device_type = FindAllLeafNodes(devicetype_id);
// DeviceType final_parent = FindFinalParentNode(devicetype_id);
//Workshop = final_parent.Name;
List<LineDetail> LineDetailList = new List<LineDetail>();
// 停止计时
stopwatch.Stop();
// 输出执行时间
Console.WriteLine("代码段执行时间: {0} 秒", stopwatch.ElapsedMilliseconds/1000);
// 2 获取每个线下的所有设备
if (All_device_type.Count > 0)
{
List<DeviceType> all_deviceTyepe_s= Context.Queryable<DeviceType>().ToList();
List<DeviceAccount> all_account_s=Context.Queryable<DeviceAccount>().ToList();
List<DeviceRepair> all_deviceRepair_s= Context.Queryable<DeviceRepair>().ToList();
foreach (DeviceType type in All_device_type)
{
LineDetail lineDetail = new LineDetail();
lineDetail.Workshop = Context.Queryable<DeviceType>().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<DeviceAccount> accounts = Context.Queryable<DeviceAccount>()
.Where(it => it.FkDeviceType == type.Id).ToList();
List<DeviceAccount> accounts = all_account_s.Where(it => it.FkDeviceType == type.Id).ToList();
lineDetail.Total = accounts.Count;
AllTotal = AllTotal + lineDetail.Total;
List<DeviceInfo> Children = new List<DeviceInfo>();
@ -524,7 +528,7 @@ namespace ZR.Service.MES.dev
}
//0.3 判断是否报修中
bool isExist = Context.Queryable<DeviceRepair>()
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<DeviceType> FindAllLeafNodes(int targetId)
{
List<DeviceType> list_device_types= Context.Queryable<DeviceType>().ToList();
List<int> childIds = new List<int> { targetId };
List<DeviceType> result = new List<DeviceType>();
@ -615,14 +618,14 @@ namespace ZR.Service.MES.dev
int parentId = childIds.First();
childIds.RemoveAt(0);
List<int> children = Context.Queryable<DeviceType>().Where(n => n.ParentId == parentId).Select(n => n.Id).ToList();
List<int> 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<DeviceType>().First(n => n.Id == parentId));
result.Add(list_device_types.First(n => n.Id == parentId));
}
}