zhuangpei-mesbackend/ZR.Service/MES/dev/DeviceDataAnalysisService.cs

55 lines
2.3 KiB
C#
Raw Normal View History

2024-06-13 16:23:37 +08:00
using Infrastructure.Attribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZR.Model.MES.dev;
using ZR.Model.MES.dev.Dto;
using ZR.Service.MES.dev.IService;
namespace ZR.Service.MES.dev
{
/// <summary>
/// 设备数据分析
/// </summary>
[AppService(ServiceType = typeof(IDeviceDataAnalysisServcie), ServiceLifetime = LifeTime.Transient)]
public class DeviceDataAnalysisService : BaseService<DeviceAccount>, IDeviceDataAnalysisServcie
{
/// <summary>
/// 故障类型 pie
/// </summary>
/// <param name="devicedefault"></param>
/// <returns></returns>
public List<DeviceStatusAnalysisResultDto> DefaultTypePie(DeviceDefaultDto devicedefault)
{
List<DeviceStatusAnalysisResultDto> resultList = new List<DeviceStatusAnalysisResultDto>();
var predicate = Expressionable.Create<DeviceRepair, DeviceAccount>()
.AndIF(devicedefault.DevicetTypeId > 0, (r, a) => a.FkDeviceType == devicedefault.DevicetTypeId)
.AndIF(!string.IsNullOrEmpty(devicedefault.DeviceName), (r, a) => a.DeviceName.Contains(devicedefault.DeviceName))
.AndIF(!string.IsNullOrEmpty(devicedefault.DeviceCode), (r, a) => a.DeviceCode.Contains(devicedefault.DeviceCode))
2024-06-13 16:37:29 +08:00
.AndIF(devicedefault.searchTime[0] > new DateTime(1991, 1, 1), (r, a) => a.CreatedTime >= devicedefault.searchTime[0])
.AndIF(devicedefault.searchTime[1] > new DateTime(1991, 1, 1), (r, a) => a.CreatedTime <= devicedefault.searchTime[1]);
2024-06-13 16:23:37 +08:00
List<DeviceRepair> deviceRepair_list= Context.Queryable<DeviceRepair>()
.LeftJoin<DeviceAccount>((r, a) => r.FkDeviceId == a.Id)
.Where(predicate.ToExpression())
.Select((r,a)=>r).ToList();
var TypeGroups= deviceRepair_list.GroupBy(it => it.Type);
foreach(var group in TypeGroups)
{
DeviceStatusAnalysisResultDto result=new DeviceStatusAnalysisResultDto();
result.name = group.Key;
result.value = group.Count();
resultList.Add(result);
}
return resultList;
}
}
}