zhuangpei-mesbackend/DOAN.Service/MES/dev/DeviceAccountService.cs

690 lines
26 KiB
C#
Raw Normal View History

2024-05-20 19:13:55 +08:00
using System;
using SqlSugar;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
2024-07-01 16:04:10 +08:00
using DOAN.Model;
2024-06-03 18:26:07 +08:00
2024-07-01 16:04:10 +08:00
using DOAN.Repository;
2024-06-03 18:26:07 +08:00
2024-05-20 19:13:55 +08:00
using System.Linq;
2024-07-01 16:04:10 +08:00
using DOAN.Model.MES.dev;
using DOAN.Model.MES.dev.Dto;
using DOAN.Service.MES.dev.IService;
2024-06-18 09:04:17 +08:00
using System.ComponentModel;
2024-06-26 17:08:18 +08:00
using System.Diagnostics;
2024-05-20 19:13:55 +08:00
2024-07-01 16:04:10 +08:00
namespace DOAN.Service.MES.dev
2024-05-20 19:13:55 +08:00
{
/// <summary>
/// 设备台账Service业务层处理
/// </summary>
[AppService(ServiceType = typeof(IDeviceAccountService), ServiceLifetime = LifeTime.Transient)]
public class DeviceAccountService : BaseService<DeviceAccount>, IDeviceAccountService
{
/// <summary>
/// 查询设备台账列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<DeviceAccountDto> GetList(DeviceAccountQueryDto parm)
{
2024-06-11 13:35:43 +08:00
// 全部设备parm.FkDeviceType == 1
// 提取parentId
DeviceType typeItem = Context.Queryable<DeviceType>()
2024-06-12 17:41:30 +08:00
.Where(it => it.Id == parm.FkDeviceType)
.Where(it => it.Status == 1)
2024-06-11 13:35:43 +08:00
.First();
int[] typeIds = [];
// 二级菜单
if (typeItem != null && typeItem.ParentId == 1)
{
typeIds = Context.Queryable<DeviceType>()
.Where(it => it.ParentId == parm.FkDeviceType)
.Where(it => it.Status == 1)
.Select(it => it.Id)
.ToArray();
}
2024-06-12 17:41:30 +08:00
2024-06-11 13:35:43 +08:00
// 非全部设备
2024-06-12 17:41:30 +08:00
2024-06-11 13:35:43 +08:00
2024-05-20 19:13:55 +08:00
var predicate = Expressionable.Create<DeviceAccount>()
2024-05-28 17:21:58 +08:00
.AndIF(!string.IsNullOrEmpty(parm.DeviceName), it => it.DeviceName.Contains(parm.DeviceName))
2024-05-20 19:13:55 +08:00
.AndIF(!string.IsNullOrEmpty(parm.DeviceSpecification), it => it.DeviceSpecification.Contains(parm.DeviceSpecification))
.AndIF(parm.Status > -1, it => it.Status == parm.Status)
2024-06-11 13:35:43 +08:00
.AndIF(typeItem != null && typeItem.ParentId > 1, it => it.FkDeviceType == parm.FkDeviceType)
.AndIF(typeItem != null && typeItem.ParentId == 1, it => typeIds.Contains(it.FkDeviceType))
2024-05-20 19:13:55 +08:00
;
var response = Queryable()
.Where(predicate.ToExpression())
.OrderByDescending(it => it.UpdatedTime)
.OrderByDescending(it => it.CreatedTime)
.ToPage<DeviceAccount, DeviceAccountDto>(parm);
return response;
}
2024-06-19 10:04:09 +08:00
/// <summary>
/// 通常在数据库层面执行联表查询JOIN会比在程序层面逐一查询左表和右表更快一些。
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
2024-06-24 16:08:18 +08:00
public PagedInfo<DeviceAccountDto> GetList_Route2(DeviceAccountQueryDto2 parm)
2024-05-28 17:23:55 +08:00
{
2024-06-24 16:08:18 +08:00
2024-05-28 17:23:55 +08:00
var predicate = Expressionable.Create<DeviceAccount, DeviceRelRpAt>()
.AndIF(!string.IsNullOrEmpty(parm.DeviceName), (a, r) => a.DeviceName.Contains(parm.DeviceName))
.AndIF(!string.IsNullOrEmpty(parm.DeviceSpecification), (a, r) => a.DeviceSpecification.Contains(parm.DeviceSpecification))
.And((a, r) => a.Status == 1)
.AndIF(parm.FkDeviceType > 0, (a, r) => a.FkDeviceType == parm.FkDeviceType)
2024-06-18 09:04:17 +08:00
.And((a, r) => r.FkRouteInspectionPlanId == parm.fkRouteInspectionPlanId)
2024-05-28 17:23:55 +08:00
;
2024-06-18 09:04:17 +08:00
var temp = Context.Queryable<DeviceAccount>()
2024-05-29 19:09:03 +08:00
.LeftJoin<DeviceRelRpAt>((a, r) => a.Id == r.FkDeviceAccountId)
2024-06-18 09:04:17 +08:00
.Where(predicate.ToExpression()).Select((a, r) => a);
2024-06-19 10:04:09 +08:00
2024-06-24 16:08:18 +08:00
if (parm.Flag == 0)
{
int[] exist = temp.Select(a => a.Id).ToArray();
temp = Context.Queryable<DeviceAccount>().Where(it => !exist.Contains(it.Id)).Distinct();
}
2024-06-18 09:04:17 +08:00
2024-06-24 16:08:18 +08:00
var reponse = temp
.ToPage<DeviceAccount, DeviceAccountDto>(parm);
2024-05-28 17:23:55 +08:00
2024-06-18 09:04:17 +08:00
return reponse;
2024-05-28 17:23:55 +08:00
}
2024-06-24 16:08:18 +08:00
public PagedInfo<DeviceAccountDto> GetList_Route(DeviceAccountQueryDto2 parm)
{
2024-05-29 19:09:03 +08:00
2024-06-24 16:08:18 +08:00
//未绑定
if (parm.Flag == 0)
{
int[] account_array = Context
.Queryable<DeviceAccount>()
.LeftJoin<DeviceRelRpAt>((a, r) => a.Id == r.FkDeviceAccountId)
.Where((a, r) => r.FkRouteInspectionPlanId == parm.fkRouteInspectionPlanId)
.Select((a, r) => a.Id)
.ToArray();
var predicate = Expressionable.Create<DeviceAccount>()
.AndIF(!string.IsNullOrEmpty(parm.DeviceName), (a) => a.DeviceName.Contains(parm.DeviceName))
.AndIF(!string.IsNullOrEmpty(parm.DeviceSpecification), (a) => a.DeviceSpecification.Contains(parm.DeviceSpecification))
.And((a) => a.Status == 1)
.AndIF(parm.FkDeviceType > 0, (a) => a.FkDeviceType == parm.FkDeviceType)
;
return Context.Queryable<DeviceAccount>()
.Where(it => !account_array.Contains(it.Id))
.Where(predicate.ToExpression())
.ToPage<DeviceAccount, DeviceAccountDto>(parm)
;
}
else if (parm.Flag == 1)
{
// 获取绑定的account
return Context.Queryable<DeviceAccount>()
.LeftJoin<DeviceRelRpAt>((a, r) => a.Id == r.FkDeviceAccountId)
.Where((a, r) => r.FkRouteInspectionPlanId == parm.fkRouteInspectionPlanId)
.ToPage<DeviceAccount, DeviceAccountDto>(parm);
}
return null;
}
public PagedInfo<DeviceAccountDto> GetList_Point2(DeviceAccountQueryDto3 parm)
2024-06-19 10:30:05 +08:00
{
var predicate = Expressionable.Create<DeviceAccount, DeviceRelPpAt>()
.AndIF(!string.IsNullOrEmpty(parm.DeviceName), (a, r) => a.DeviceName.Contains(parm.DeviceName))
.AndIF(!string.IsNullOrEmpty(parm.DeviceSpecification), (a, r) => a.DeviceSpecification.Contains(parm.DeviceSpecification))
.And((a, r) => a.Status == 1)
.AndIF(parm.FkDeviceType > 0, (a, r) => a.FkDeviceType == parm.FkDeviceType)
.And((a, r) => r.FkPointInspectionPlanId == parm.fkPointInspectionPlanId)
;
var temp = Context.Queryable<DeviceAccount>()
.LeftJoin<DeviceRelPpAt>((a, r) => a.Id == r.FkDeviceAccountId)
.Where(predicate.ToExpression()).Select((a, r) => a);
if (parm.Flag == 0)
{
int[] exist = temp.Select(a => a.Id).ToArray();
temp = Context.Queryable<DeviceAccount>().Where(it => !exist.Contains(it.Id)).Distinct();
}
var reponse = temp
.ToPage<DeviceAccount, DeviceAccountDto>(parm);
return reponse;
}
2024-06-24 16:08:18 +08:00
public PagedInfo<DeviceAccountDto> GetList_Point(DeviceAccountQueryDto3 parm)
{
2024-06-26 15:13:57 +08:00
2024-06-24 16:08:18 +08:00
//未绑定
if (parm.Flag == 0)
{
int[] account_array = Context
.Queryable<DeviceAccount>()
.LeftJoin<DeviceRelPpAt>((a, r) => a.Id == r.FkDeviceAccountId)
.Where((a, r) => r.FkPointInspectionPlanId == parm.fkPointInspectionPlanId)
.Select((a, r) => a.Id)
.ToArray();
var predicate = Expressionable.Create<DeviceAccount>()
.AndIF(!string.IsNullOrEmpty(parm.DeviceName), (a) => a.DeviceName.Contains(parm.DeviceName))
.AndIF(!string.IsNullOrEmpty(parm.DeviceSpecification), (a) => a.DeviceSpecification.Contains(parm.DeviceSpecification))
.And((a) => a.Status == 1)
.AndIF(parm.FkDeviceType > 0, (a) => a.FkDeviceType == parm.FkDeviceType)
;
return Context.Queryable<DeviceAccount>()
.Where(it => !account_array.Contains(it.Id))
.Where(predicate.ToExpression())
.ToPage<DeviceAccount, DeviceAccountDto>(parm)
;
}
else if (parm.Flag == 1)
{
// 获取绑定的account
return Context.Queryable<DeviceAccount>()
.LeftJoin<DeviceRelPpAt>((a, r) => a.Id == r.FkDeviceAccountId)
.Where((a, r) => r.FkPointInspectionPlanId == parm.fkPointInspectionPlanId)
.ToPage<DeviceAccount, DeviceAccountDto>(parm);
}
return null;
}
2024-06-19 10:30:05 +08:00
2024-05-20 19:13:55 +08:00
/// <summary>
/// 获取详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public DeviceAccount GetInfo(int Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
/// <summary>
/// 添加设备台账
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public DeviceAccount AddDeviceAccount(DeviceAccount model)
{
return Context.Insertable(model).ExecuteReturnEntity();
}
/// <summary>
/// 修改设备台账
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int UpdateDeviceAccount(DeviceAccount model)
{
//var response = Update(w => w.Id == model.Id, it => new DeviceAccount()
//{
// FkDeviceType = model.FkDeviceType,
// DeviceName = model.DeviceName,
// DeviceCode = model.DeviceCode,
// Workshop = model.Workshop,
// Workline = model.Workline,
// Status = model.Status,
// DeviceImage = model.DeviceImage,
// DeviceFile = model.DeviceFile,
// DeviceSpecification = model.DeviceSpecification,
// ResponsiblePerson = model.ResponsiblePerson,
// Remark = model.Remark,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
//});
//return response;
return Update(model, true);
}
2024-06-26 15:13:57 +08:00
/// <summary>
/// 获取树节点
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public List<SelectTreeDto> GetSelectTree2(DeviceAccountQueryDto parm)
2024-05-28 17:21:58 +08:00
{
try
{
var predicate = Expressionable.Create<DeviceAccount>()
.And(it => it.Status == 1);
2024-06-26 15:13:57 +08:00
2024-05-28 17:21:58 +08:00
List<SelectTreeDto> accountList = Queryable()
.Where(predicate.ToExpression())
.OrderByDescending(it => it.UpdatedTime)
.OrderByDescending(it => it.CreatedTime)
.Select(it => new SelectTreeDto
{
Id = null,
ParentId = it.FkDeviceType.ToString(),
Label = (it.DeviceName + '-' + it.DeviceCode),
2024-06-26 15:13:57 +08:00
Value = it.FkDeviceType.ToString()
2024-05-28 17:21:58 +08:00
})
.ToList();
int[] fkDeviceTypeIds = accountList.Select(it => int.Parse(it.Value)).ToArray();
2024-06-26 15:13:57 +08:00
2024-05-28 17:21:58 +08:00
List<SelectTreeDto> deviceTypeList = Context.Queryable<DeviceType>()
.Where(it => fkDeviceTypeIds.Contains(it.Id))
.Select(it => new SelectTreeDto
{
Id = it.Id.ToString(),
ParentId = it.ParentId.ToString(),
Label = it.Name,
Value = it.Name
}).ToList();
List<SelectTreeDto> list = deviceTypeList.Concat(accountList).ToList();
return list;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
2024-05-29 19:09:03 +08:00
2024-06-26 15:13:57 +08:00
/// <summary>
/// 获取树节点
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public List<SelectTreeDto> GetSelectTree(DeviceAccountQueryDto parm)
{
// 获取 类型父子节点
List<SelectTreeDto> deviceTypeList = Context.Queryable<DeviceType>()
.Where(it => it.Status == 1)
.OrderBy(it => it.Id)
.Select(it => new SelectTreeDto
{
2024-07-05 14:30:02 +08:00
Id =(it.Id * 10000).ToString(),
ParentId = (it.ParentId*10000).ToString(),
2024-06-26 15:13:57 +08:00
Label = it.Name,
Value = it.Name
2024-07-05 11:50:49 +08:00
})
.ToList();
2024-06-26 15:13:57 +08:00
// 获取 类型表 绑定的设备 父子节点
2024-06-26 17:08:18 +08:00
List<SelectTreeDto> accountList = Context.Queryable<DeviceAccount>().Where(it => it.Status == 1).OrderBy(it => it.Id)
2024-06-26 15:13:57 +08:00
.Select(it => new SelectTreeDto
{
2024-07-05 11:50:49 +08:00
// Id = it.Id.ToString() + it.FkDeviceType.ToString(),//解决合并后id重复
2024-07-05 14:30:02 +08:00
Id = it.Id.ToString(),//解决合并后id重复
ParentId = (it.FkDeviceType*10000).ToString(),
2024-07-05 11:50:49 +08:00
Label = it.DeviceCode + "||" +it.DeviceName ,
2024-06-26 15:13:57 +08:00
Value = it.Id.ToString()
}).ToList();
2024-06-26 17:08:18 +08:00
return deviceTypeList.Concat(accountList).OrderBy(it => int.Parse(it.Id)).ToList();
2024-06-26 15:13:57 +08:00
}
2024-05-29 19:09:03 +08:00
/// <summary>
/// 添加绑定关系 巡检计划和设备台账
/// </summary>
/// <param name="parm"></param>
/// <param name="CreatedBy"></param>
/// <returns></returns>
public int AddRelation(DeviceAccount_routeinspect_Dto parm, string CreatedBy)
{
List<DeviceRelRpAt> DeviceRelRpAt_list = new List<DeviceRelRpAt>();
if (parm.FkDeviceAccountIdList.Length > 0)
{
foreach (var id in parm.FkDeviceAccountIdList)
{
DeviceRelRpAt rel = new DeviceRelRpAt();
rel.FkRouteInspectionPlanId = parm.FkRouteInspectionPlanId;
rel.FkDeviceAccountId = id;
rel.CreatedBy = CreatedBy;
rel.CreatedTime = DateTime.Now;
DeviceRelRpAt_list.Add(rel);
}
}
int result = Context.Insertable(DeviceRelRpAt_list).ExecuteCommand();
return result;
}
/// <summary>
/// 移除关系
/// </summary>
/// <param name="FkRouteInspectionPlanId"></param>
/// <param name="FkDeviceAccountId"></param>
/// <returns></returns>
public int Remove_relation(string FkRouteInspectionPlanId, int FkDeviceAccountId)
{
return Context.Deleteable<DeviceRelRpAt>()
.Where(it => it.FkRouteInspectionPlanId == FkRouteInspectionPlanId)
.Where(it => it.FkDeviceAccountId == FkDeviceAccountId)
.ExecuteCommand();
}
2024-05-30 14:22:25 +08:00
#region
2024-06-24 16:08:18 +08:00
2024-05-30 14:22:25 +08:00
/// <summary>
/// 添加绑定关系 巡检计划和设备台账
/// </summary>
/// <param name="parm"></param>
/// <param name="CreatedBy"></param>
/// <returns></returns>
public int AddRelationPointAccount(DeviceAccount_pointinspect_Dto parm, string CreatedBy)
{
List<DeviceRelPpAt> DeviceRelRpAt_list = new List<DeviceRelPpAt>();
if (parm.FkDeviceAccountIdList.Length > 0)
{
foreach (var id in parm.FkDeviceAccountIdList)
{
DeviceRelPpAt rel = new DeviceRelPpAt();
rel.FkPointInspectionPlanId = parm.FkPointInspectionPlanId;
rel.FkDeviceAccountId = id;
rel.CreatedBy = CreatedBy;
rel.CreatedTime = DateTime.Now;
DeviceRelRpAt_list.Add(rel);
}
}
int result = Context.Insertable(DeviceRelRpAt_list).ExecuteCommand();
return result;
}
/// <summary>
/// 移除关系
/// </summary>
/// <param name="FkRouteInspectionPlanId"></param>
/// <param name="FkDeviceAccountId"></param>
/// <returns></returns>
public int RemoveRelationPointAccount(string FkPointInspectionPlanId, int FkDeviceAccountId)
{
return Context.Deleteable<DeviceRelPpAt>()
.Where(it => it.FkPointInspectionPlanId == FkPointInspectionPlanId)
.Where(it => it.FkDeviceAccountId == FkDeviceAccountId)
.ExecuteCommand();
}
#endregion
2024-06-12 17:41:30 +08:00
/// <summary>
/// 设备状态
/// </summary>
/// <param name="devicetype_id"> 设备类型id</param>
/// <returns></returns>
public DeviceStatusAnalysisDto GetDeviceStatus(int devicetype_id)
{
2024-06-26 17:19:03 +08:00
2024-06-12 17:41:30 +08:00
DeviceStatusAnalysisDto analysis = new DeviceStatusAnalysisDto();
2024-06-24 16:08:18 +08:00
2024-06-12 17:41:30 +08:00
// 设备总数
int AllTotal = 0;
//正常设备数
int NormalTotal = 0;
// 未巡点总数
int UnmaintainedTotal = 0;
// 报修中总数
int DamageTotal = 0;
// 停用总数
int NoUseTotal = 0;
2024-06-26 17:08:18 +08:00
Stopwatch stopwatch = new Stopwatch();
2024-06-12 17:41:30 +08:00
2024-06-26 17:08:18 +08:00
// 开始计时
stopwatch.Start();
2024-06-12 17:41:30 +08:00
// 1 获取设备类型下面所有的线
List<DeviceType> All_device_type = null;
2024-06-26 17:08:18 +08:00
2024-06-13 10:07:19 +08:00
All_device_type = FindAllLeafNodes(devicetype_id);
2024-06-26 17:08:18 +08:00
2024-06-24 16:08:18 +08:00
List<LineDetail> LineDetailList = new List<LineDetail>();
2024-06-26 17:08:18 +08:00
// 停止计时
stopwatch.Stop();
// 输出执行时间
2024-06-26 17:19:03 +08:00
Console.WriteLine("代码段执行时间: {0} 秒", stopwatch.ElapsedMilliseconds / 1000);
2024-06-12 17:41:30 +08:00
// 2 获取每个线下的所有设备
if (All_device_type.Count > 0)
{
2024-06-26 17:19:03 +08:00
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();
var query_point = Context.Queryable<DeviceTaskExecute>()
.LeftJoin<DevicePointInspectionPlan>((e, p) => e.TaskId == p.Id)
.LeftJoin<DeviceRelPpAt>((e, p, r) => p.Id == r.FkPointInspectionPlanId)
2024-06-26 17:19:03 +08:00
.Where((e, p, r) => e.Status == 0 || e.Status == 1 || e.Status == 3)
2024-06-26 17:19:03 +08:00
.Select((e, p, r) => new
{
FkDeviceAccountId = r.FkDeviceAccountId,
2024-06-26 17:19:03 +08:00
2024-06-26 17:19:03 +08:00
}).ToList();
var query_route = Context.Queryable<DeviceTaskExecute>()
.LeftJoin<DeviceRouteInspectionPlan>((e, p) => e.TaskId == p.Id)
.LeftJoin<DeviceRelPpAt>((e, p, r) => p.Id == r.FkPointInspectionPlanId)
2024-06-26 17:19:03 +08:00
.Where((e, p, r) => e.Status == 0 || e.Status == 1 || e.Status == 3)
2024-06-26 17:19:03 +08:00
.Select((e, p, r) => new
{
FkDeviceAccountId = r.FkDeviceAccountId,
2024-06-26 17:19:03 +08:00
2024-06-26 17:19:03 +08:00
}).ToList();
2024-06-26 17:08:18 +08:00
2024-06-12 17:41:30 +08:00
foreach (DeviceType type in All_device_type)
{
LineDetail lineDetail = new LineDetail();
2024-06-26 17:08:18 +08:00
lineDetail.Workshop = all_deviceTyepe_s.Where(n => n.Id == type.ParentId).Select(n => n.Name).First();
2024-06-12 17:41:30 +08:00
lineDetail.Workline = type.Name;
2024-06-26 17:08:18 +08:00
List<DeviceAccount> accounts = all_account_s.Where(it => it.FkDeviceType == type.Id).ToList();
2024-06-12 17:41:30 +08:00
lineDetail.Total = accounts.Count;
AllTotal = AllTotal + lineDetail.Total;
List<DeviceInfo> Children = new List<DeviceInfo>();
if (accounts.Count > 0)
{
2024-06-24 16:08:18 +08:00
2024-06-12 17:41:30 +08:00
// 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;
2024-06-24 16:08:18 +08:00
2024-06-13 10:07:19 +08:00
Children.Add(deviceInfo);
2024-06-12 17:41:30 +08:00
continue;
}
//0.3 判断是否报修中
2024-06-26 17:08:18 +08:00
bool isExist = all_deviceRepair_s
2024-06-12 17:41:30 +08:00
.Where(it => it.FkDeviceId == item.Id)
.Where(it => it.Status == 0 || it.Status == 1 || it.Status == 3).Any();
if (isExist)
{
DamageTotal++;
deviceInfo.DeviceStatus = 3;
2024-06-24 16:08:18 +08:00
2024-06-13 10:07:19 +08:00
Children.Add(deviceInfo);
2024-06-12 17:41:30 +08:00
continue;
}
2024-06-26 17:19:03 +08:00
2024-06-26 17:19:03 +08:00
2024-06-12 17:41:30 +08:00
2024-06-26 17:19:03 +08:00
//var query = from person in people
// join address in addresses on person.Id equals address.PersonId into addressGroup
// from addressItem in addressGroup.DefaultIfEmpty()
// join phoneNumber in phoneNumbers on person.Id equals phoneNumber.PersonId into phoneGroup
// from phoneNumberItem in phoneGroup.DefaultIfEmpty()
// select new
// {
// PersonName = person.Name,
// Address = addressItem?.AddressLine ?? "No address available",
// PhoneNumber = phoneNumberItem?.Number ?? "No phone number available"
// };
2024-06-12 17:41:30 +08:00
//处理点检
2024-06-26 17:19:03 +08:00
int isExist_point = query_point
2024-06-26 17:19:03 +08:00
.Where(it => it.FkDeviceAccountId == item.Id).Count();
2024-06-24 16:08:18 +08:00
// UnmaintainedTotal = UnmaintainedTotal + isExist_point;
if (isExist_point > 0)
2024-06-12 17:41:30 +08:00
{
deviceInfo.DeviceStatus = 2;
2024-06-13 11:09:04 +08:00
UnmaintainedTotal++;
2024-06-13 10:07:19 +08:00
Children.Add(deviceInfo);
2024-06-12 17:41:30 +08:00
continue;
}
//处理巡检
2024-06-26 17:19:03 +08:00
int isExist_route = query_route.Where(it => it.FkDeviceAccountId == item.Id).Count();
2024-06-12 17:41:30 +08:00
2024-06-24 16:08:18 +08:00
if (isExist_route > 0)
2024-06-12 17:41:30 +08:00
{
deviceInfo.DeviceStatus = 2;
2024-06-13 11:09:04 +08:00
UnmaintainedTotal++;
2024-06-13 10:07:19 +08:00
Children.Add(deviceInfo);
2024-06-12 17:41:30 +08:00
continue;
}
deviceInfo.DeviceStatus = 1;
NormalTotal++;
Children.Add(deviceInfo);
}
}
lineDetail.Children = Children;
2024-06-13 10:07:19 +08:00
LineDetailList.Add(lineDetail);
2024-06-12 17:41:30 +08:00
}
2024-06-26 17:08:18 +08:00
2024-06-12 17:41:30 +08:00
}
analysis.AllTotal = AllTotal;
analysis.UnmaintainedTotal = UnmaintainedTotal;
analysis.LineDetailList = LineDetailList;
2024-06-24 16:08:18 +08:00
analysis.DamageTotal = DamageTotal;
2024-06-12 17:41:30 +08:00
analysis.NormalTotal = NormalTotal;
2024-06-13 10:58:42 +08:00
analysis.NoUseTotal = NoUseTotal;
2024-06-26 17:19:03 +08:00
2024-06-12 17:41:30 +08:00
return analysis;
}
/// <summary>
/// 查找指定节点的所有最终子节点
/// </summary>
/// <param name="targetId"></param>
/// <returns></returns>
public List<DeviceType> FindAllLeafNodes(int targetId)
{
2024-06-26 17:19:03 +08:00
List<DeviceType> list_device_types = Context.Queryable<DeviceType>().ToList();
2024-06-12 17:41:30 +08:00
List<int> childIds = new List<int> { targetId };
List<DeviceType> result = new List<DeviceType>();
while (childIds.Any())
{
int parentId = childIds.First();
childIds.RemoveAt(0);
2024-06-26 17:08:18 +08:00
List<int> children = list_device_types.Where(n => n.ParentId == parentId).Select(n => n.Id).ToList();
2024-06-12 17:41:30 +08:00
if (children.Any())
{
childIds.AddRange(children);
}
else
{
2024-06-26 17:08:18 +08:00
result.Add(list_device_types.First(n => n.Id == parentId));
2024-06-12 17:41:30 +08:00
}
}
return result;
}
2024-06-13 10:45:08 +08:00
/// <summary>
/// 用于在父子节点对象中,根据输入的节点 ID 找到最终的父节点:
/// </summary>
/// <param name="nodeId"></param>
/// <returns></returns>
public DeviceType FindFinalParentNode(int nodeId)
{
DeviceType currentNode = Context.Queryable<DeviceType>().Where(n => n.Id == nodeId).First();
if (currentNode == null)
{
return null;
}
DeviceType parentNode = Context.Queryable<DeviceType>().Where(n => n.Id == currentNode.ParentId).First();
while (parentNode != null)
{
currentNode = parentNode;
parentNode = Context.Queryable<DeviceType>().Where(n => n.Id == currentNode.ParentId).First();
}
return currentNode;
}
2024-05-20 19:13:55 +08:00
}
2024-05-29 19:09:03 +08:00
2024-05-20 19:13:55 +08:00
}