设备状态

This commit is contained in:
qianhao.xu 2024-06-12 17:41:30 +08:00
parent 501d0abe67
commit a50b59f098
7 changed files with 295 additions and 9 deletions

View File

@ -214,5 +214,20 @@ namespace ZR.Admin.WebApi.Controllers
var response = _DeviceAccountService.RemoveRelationPointAccount(FkPointInspectionPlanId, FkDeviceAccountId);
return SUCCESS(response);
}
/// <summary>
/// 获取设备状态 设备看板用
/// </summary>
/// <param name="devicetype_id">设备类型id</param>
/// <returns></returns>
public IActionResult GetDeviceStatus(int devicetype_id)
{
DeviceStatusAnalysisDto response= _DeviceAccountService.GetDeviceStatus(devicetype_id);
return SUCCESS(response);
}
}
}

View File

@ -23,7 +23,7 @@ namespace ZR.Model.MES.dev
/// 设备id
/// </summary>
[SugarColumn(ColumnName = "fk_device_id")]
public string FkDeviceId { get; set; }
public int FkDeviceId { get; set; }
/// <summary>
/// 报修类型

View File

@ -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; }

View File

@ -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
{
/// <summary>
/// 设备状态分析
/// </summary>
public class DeviceStatusAnalysisDto
{
/// <summary>
/// 设备总数:存在设备
/// </summary>
public int AllTotal { get; set; }
/// <summary>
/// 正常设备总数
/// </summary>
public int NormalTotal { get; set; }
/// <summary>
/// 未点/巡总数
/// </summary>
public int UnmaintainedTotal { get; set; }
/// <summary>
/// 报修中总数
/// </summary>
public int DamageTotal { get; set; }
/// <summary>
/// 停用总数
/// </summary>
public int NoUseTotal { get; set; }
/// <summary>
/// 设备详情
/// </summary>
public List<LineDetail> LineDetailList { get; set; }
}
/// <summary>
/// 设备详情
/// </summary>
public class LineDetail
{
/// <summary>
/// 车间
/// </summary>
public string Workshop { get; set; }
/// <summary>
/// 产线
/// </summary>
public string Workline { get; set; }
/// <summary>
/// 总计
/// </summary>
public int Total { get; set; }
/// <summary>
/// 设备信息
/// </summary>
public List<DeviceInfo> Children { get; set; }
}
/// <summary>
/// 设备信息
/// </summary>
public class DeviceInfo
{
/// <summary>
/// 设备id
/// </summary>
public int Id { get; set; }
/// <summary>
/// 设备名称
/// </summary>
public string DeviceName { get; set; }
/// <summary>
/// 设备code
/// </summary>
public string DeviceCode { get; set; }
/// <summary>
/// 设备状态 1正常2未维护 3报修中4停用中
/// </summary>
public int DeviceStatus { get; set; }
}
}

View File

@ -29,8 +29,8 @@ namespace ZR.Service.MES.dev
// 全部设备parm.FkDeviceType == 1
// 提取parentId
DeviceType typeItem = Context.Queryable<DeviceType>()
.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<DeviceAccount>()
.AndIF(!string.IsNullOrEmpty(parm.DeviceName), it => it.DeviceName.Contains(parm.DeviceName))
@ -296,6 +296,176 @@ namespace ZR.Service.MES.dev
#endregion
/// <summary>
/// 设备状态
/// </summary>
/// <param name="devicetype_id"> 设备类型id</param>
/// <returns></returns>
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<DeviceType> All_device_type = null;
DeviceType line = Context.Queryable<DeviceType>().Where(it => it.Id == devicetype_id).First();
if (line.ParentId == 0)
{
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 };
}
List<LineDetail> LineDetailList = new List<LineDetail>();
// 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<DeviceAccount> accounts = Context.Queryable<DeviceAccount>()
.Where(it => it.FkDeviceType == type.Id).ToList();
lineDetail.Total = accounts.Count;
AllTotal = AllTotal + lineDetail.Total;
List<DeviceInfo> Children = new List<DeviceInfo>();
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<DeviceRepair>()
.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<DeviceTaskExecute>()
.LeftJoin<DevicePointInspectionPlan>((e, p) => e.TaskId == p.Id)
.LeftJoin<DeviceRelPpAt>((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<DeviceTaskExecute>()
.LeftJoin<DeviceRouteInspectionPlan>((e, p) => e.TaskId == p.Id)
.LeftJoin<DeviceRelPpAt>((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;
}
/// <summary>
/// 查找指定节点的所有最终子节点
/// </summary>
/// <param name="targetId"></param>
/// <returns></returns>
public List<DeviceType> FindAllLeafNodes(int targetId)
{
List<int> childIds = new List<int> { targetId };
List<DeviceType> result = new List<DeviceType>();
while (childIds.Any())
{
int parentId = childIds.First();
childIds.RemoveAt(0);
List<int> children = Context.Queryable<DeviceType>().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));
}
}
return result;
}
}

View File

@ -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<DeviceAccount>((dr,da)=>dr.FkDeviceId == da.Id.ToString())
.LeftJoin<DeviceAccount>((dr,da)=>dr.FkDeviceId == da.Id)
.Where(predicate.ToExpression())
.Select<DeviceRepairDto>()
.ToPage(parm);

View File

@ -38,6 +38,6 @@ namespace ZR.Service.MES.dev.IService
int RemoveRelationPointAccount(string FkPointInspectionPlanId, int FkDeviceAccountId);
DeviceStatusAnalysisDto GetDeviceStatus(int devicetype_id);
}
}