From a50b59f0985a2f8ce2372737b58732c73b28fa96 Mon Sep 17 00:00:00 2001 From: "qianhao.xu" Date: Wed, 12 Jun 2024 17:41:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MES/dev/DeviceAccountController.cs | 15 ++ ZR.Model/MES/dev/DeviceRepair.cs | 2 +- ZR.Model/MES/dev/Dto/DeviceRepairDto.cs | 2 +- .../MES/dev/Dto/DeviceStatusAnalysisDto.cs | 101 ++++++++++ ZR.Service/MES/dev/DeviceAccountService.cs | 178 +++++++++++++++++- ZR.Service/MES/dev/DeviceRepairService.cs | 4 +- .../MES/dev/IService/IDeviceAccountService.cs | 2 +- 7 files changed, 295 insertions(+), 9 deletions(-) create mode 100644 ZR.Model/MES/dev/Dto/DeviceStatusAnalysisDto.cs diff --git a/ZR.Admin.WebApi/Controllers/MES/dev/DeviceAccountController.cs b/ZR.Admin.WebApi/Controllers/MES/dev/DeviceAccountController.cs index 8292659..67bed56 100644 --- a/ZR.Admin.WebApi/Controllers/MES/dev/DeviceAccountController.cs +++ b/ZR.Admin.WebApi/Controllers/MES/dev/DeviceAccountController.cs @@ -214,5 +214,20 @@ namespace ZR.Admin.WebApi.Controllers var response = _DeviceAccountService.RemoveRelationPointAccount(FkPointInspectionPlanId, FkDeviceAccountId); return SUCCESS(response); } + + + /// + /// 获取设备状态 设备看板用 + /// + /// 设备类型id + /// + public IActionResult GetDeviceStatus(int devicetype_id) + { + DeviceStatusAnalysisDto response= _DeviceAccountService.GetDeviceStatus(devicetype_id); + return SUCCESS(response); + + + + } } } \ No newline at end of file diff --git a/ZR.Model/MES/dev/DeviceRepair.cs b/ZR.Model/MES/dev/DeviceRepair.cs index 34e62b2..c84f7b2 100644 --- a/ZR.Model/MES/dev/DeviceRepair.cs +++ b/ZR.Model/MES/dev/DeviceRepair.cs @@ -23,7 +23,7 @@ namespace ZR.Model.MES.dev /// 设备id /// [SugarColumn(ColumnName = "fk_device_id")] - public string FkDeviceId { get; set; } + public int FkDeviceId { get; set; } /// /// 报修类型 diff --git a/ZR.Model/MES/dev/Dto/DeviceRepairDto.cs b/ZR.Model/MES/dev/Dto/DeviceRepairDto.cs index 722b937..03c35a5 100644 --- a/ZR.Model/MES/dev/Dto/DeviceRepairDto.cs +++ b/ZR.Model/MES/dev/Dto/DeviceRepairDto.cs @@ -8,7 +8,7 @@ namespace ZR.Model.MES.dev.Dto public class DeviceRepairQueryDto : PagerInfo { public string RepairOrder { get; set; } - public string FkDeviceId { get; set; } + public int FkDeviceId { get; set; } public string RepairPeron { get; set; } public string Phone { get; set; } public string Type { get; set; } diff --git a/ZR.Model/MES/dev/Dto/DeviceStatusAnalysisDto.cs b/ZR.Model/MES/dev/Dto/DeviceStatusAnalysisDto.cs new file mode 100644 index 0000000..a5a5169 --- /dev/null +++ b/ZR.Model/MES/dev/Dto/DeviceStatusAnalysisDto.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZR.Model.MES.dev.Dto +{ + /// + /// 设备状态分析 + /// + public class DeviceStatusAnalysisDto + { + /// + /// 设备总数:存在设备 + /// + public int AllTotal { get; set; } + + /// + /// 正常设备总数 + /// + public int NormalTotal { get; set; } + + /// + /// 未点/巡总数 + /// + public int UnmaintainedTotal { get; set; } + + /// + /// 报修中总数 + /// + public int DamageTotal { get; set; } + + /// + /// 停用总数 + /// + public int NoUseTotal { get; set; } + + + /// + /// 设备详情 + /// + public List LineDetailList { get; set; } + + } + /// + /// 设备详情 + /// + public class LineDetail + { + /// + /// 车间 + /// + public string Workshop { get; set; } + + /// + /// 产线 + /// + public string Workline { get; set; } + + /// + /// 总计 + /// + public int Total { get; set; } + + /// + /// 设备信息 + /// + public List Children { get; set; } + } + /// + /// 设备信息 + /// + public class DeviceInfo + { + /// + /// 设备id + /// + public int Id { get; set; } + + /// + /// 设备名称 + /// + public string DeviceName { get; set; } + + /// + /// 设备code + /// + public string DeviceCode { get; set; } + + + /// + /// 设备状态 :1(正常)2(未维护) 3(报修中)4(停用中) + /// + public int DeviceStatus { get; set; } + + } + + + +} diff --git a/ZR.Service/MES/dev/DeviceAccountService.cs b/ZR.Service/MES/dev/DeviceAccountService.cs index c40c2a6..f54b59f 100644 --- a/ZR.Service/MES/dev/DeviceAccountService.cs +++ b/ZR.Service/MES/dev/DeviceAccountService.cs @@ -29,8 +29,8 @@ namespace ZR.Service.MES.dev // 全部设备parm.FkDeviceType == 1 // 提取parentId DeviceType typeItem = Context.Queryable() - .Where(it=>it.Id == parm.FkDeviceType) - .Where(it=>it.Status==1) + .Where(it => it.Id == parm.FkDeviceType) + .Where(it => it.Status == 1) .First(); int[] typeIds = []; // 二级菜单 @@ -42,9 +42,9 @@ namespace ZR.Service.MES.dev .Select(it => it.Id) .ToArray(); } - + // 非全部设备 - + var predicate = Expressionable.Create() .AndIF(!string.IsNullOrEmpty(parm.DeviceName), it => it.DeviceName.Contains(parm.DeviceName)) @@ -296,6 +296,176 @@ namespace ZR.Service.MES.dev #endregion + + /// + /// 设备状态 + /// + /// 设备类型id + /// + public DeviceStatusAnalysisDto GetDeviceStatus(int devicetype_id) + { + DeviceStatusAnalysisDto analysis = new DeviceStatusAnalysisDto(); + // 车间 + string Workshop = ""; + // 设备总数 + int AllTotal = 0; + //正常设备数 + int NormalTotal = 0; + // 未巡点总数 + int UnmaintainedTotal = 0; + // 报修中总数 + int DamageTotal = 0; + // 停用总数 + int NoUseTotal = 0; + + + + // 1 获取设备类型下面所有的线 + + List All_device_type = null; + DeviceType line = Context.Queryable().Where(it => it.Id == devicetype_id).First(); + if (line.ParentId == 0) + { + 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 }; + } + List LineDetailList = new List(); + // 2 获取每个线下的所有设备 + if (All_device_type.Count > 0) + { + foreach (DeviceType type in All_device_type) + { + LineDetail lineDetail = new LineDetail(); + lineDetail.Workshop = Workshop; + lineDetail.Workline = type.Name; + + + List accounts = Context.Queryable() + .Where(it => it.FkDeviceType == type.Id).ToList(); + lineDetail.Total = accounts.Count; + AllTotal = AllTotal + lineDetail.Total; + List Children = new List(); + if (accounts.Count > 0) + { + + // 3 获取每个设备所有状态 + foreach (var item in accounts) + { + DeviceInfo deviceInfo = new DeviceInfo(); + deviceInfo.Id = item.Id; + deviceInfo.DeviceName = item.DeviceName; + deviceInfo.DeviceCode = item.DeviceCode; + + + //0.4断是否停止中 + if (item.Status == 0) + { + NoUseTotal++; + deviceInfo.DeviceStatus = 4; + continue; + } + + //0.3 判断是否报修中 + bool isExist = Context.Queryable() + .Where(it => it.FkDeviceId == item.Id) + .Where(it => it.Status == 0 || it.Status == 1 || it.Status == 3).Any(); + if (isExist) + { + DamageTotal++; + deviceInfo.DeviceStatus = 3; + continue; + } + //0.2 判断是否维护中 + + //处理点检 + int isExist_point = Context.Queryable() + .LeftJoin((e, p) => e.TaskId == p.Id) + .LeftJoin((e, p, r) => p.Id == r.FkPointInspectionPlanId) + .Where((e, p, r) => r.FkDeviceAccountId == item.Id) + .Where((e, p, r) => e.Status == 0 || e.Status == 1 || e.Status == 3) + .Count(); + UnmaintainedTotal = UnmaintainedTotal + isExist_point; + if (isExist_point>0) + { + + deviceInfo.DeviceStatus = 2; + continue; + + } + + + //处理巡检 + int isExist_route = Context.Queryable() + .LeftJoin((e, p) => e.TaskId == p.Id) + .LeftJoin((e, p, r) => p.Id == r.FkPointInspectionPlanId) + .Where((e, p, r) => r.FkDeviceAccountId == item.Id) + .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; + continue; + + } + deviceInfo.DeviceStatus = 1; + NormalTotal++; + Children.Add(deviceInfo); + + } + + } + + lineDetail.Children = Children; + + } + + } + analysis.AllTotal = AllTotal; + analysis.UnmaintainedTotal = UnmaintainedTotal; + analysis.LineDetailList = LineDetailList; + analysis.NormalTotal = NormalTotal; + + return analysis; + + } + /// + /// 查找指定节点的所有最终子节点 + /// + /// + /// + + public List FindAllLeafNodes(int targetId) + { + List childIds = new List { targetId }; + List result = new List(); + + while (childIds.Any()) + { + int parentId = childIds.First(); + childIds.RemoveAt(0); + + List children = Context.Queryable().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)); + } + } + + return result; + } } diff --git a/ZR.Service/MES/dev/DeviceRepairService.cs b/ZR.Service/MES/dev/DeviceRepairService.cs index a6687a9..79fbc87 100644 --- a/ZR.Service/MES/dev/DeviceRepairService.cs +++ b/ZR.Service/MES/dev/DeviceRepairService.cs @@ -29,13 +29,13 @@ namespace ZR.Service.MES.dev .AndIF(!string.IsNullOrEmpty(parm.RepairOrder), dr => dr.RepairOrder.Contains(parm.RepairOrder)) .AndIF(!string.IsNullOrEmpty(parm.RepairPeron), dr => dr.RepairPeron.Contains(parm.RepairPeron)) .AndIF(!string.IsNullOrEmpty(parm.Phone), dr => dr.Phone.Contains(parm.Phone)) - .AndIF(!string.IsNullOrEmpty(parm.FkDeviceId), dr => dr.FkDeviceId == parm.FkDeviceId) + .AndIF(parm.FkDeviceId>0, dr => dr.FkDeviceId == parm.FkDeviceId) .AndIF(!string.IsNullOrEmpty(parm.Type), dr => dr.Type == parm.Type) .AndIF(parm.Status > -1, dr => dr.Status == parm.Status) ; var response = Queryable() - .LeftJoin((dr,da)=>dr.FkDeviceId == da.Id.ToString()) + .LeftJoin((dr,da)=>dr.FkDeviceId == da.Id) .Where(predicate.ToExpression()) .Select() .ToPage(parm); diff --git a/ZR.Service/MES/dev/IService/IDeviceAccountService.cs b/ZR.Service/MES/dev/IService/IDeviceAccountService.cs index d1348cc..6d94bca 100644 --- a/ZR.Service/MES/dev/IService/IDeviceAccountService.cs +++ b/ZR.Service/MES/dev/IService/IDeviceAccountService.cs @@ -38,6 +38,6 @@ namespace ZR.Service.MES.dev.IService int RemoveRelationPointAccount(string FkPointInspectionPlanId, int FkDeviceAccountId); - + DeviceStatusAnalysisDto GetDeviceStatus(int devicetype_id); } }