205 lines
6.7 KiB
C#
205 lines
6.7 KiB
C#
using System;
|
||
using SqlSugar;
|
||
using Infrastructure.Attribute;
|
||
using Infrastructure.Extensions;
|
||
using DOAN.Model;
|
||
using DOAN.Model.Dto;
|
||
using DOAN.Model.MES.dev.Dto;
|
||
using DOAN.Model.MES.dev;
|
||
using DOAN.Repository;
|
||
using DOAN.Service.MES.dev.IService;
|
||
using System.Linq;
|
||
using DOAN.Model.MES.product.Dto;
|
||
using DOAN.Model.MES.product;
|
||
|
||
namespace DOAN.Service.MES.dev
|
||
{
|
||
/// <summary>
|
||
/// 设备运行绩效分析Service业务层处理
|
||
/// </summary>
|
||
[AppService(ServiceType = typeof(IDevicePerformanceService), ServiceLifetime = LifeTime.Transient)]
|
||
public class DevicePerformanceService : BaseService<DevicePerformance>, IDevicePerformanceService
|
||
{
|
||
/// <summary>
|
||
/// 查询设备运行绩效分析列表
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
public PagedInfo<DevicePerformanceDto> GetList(DevicePerformanceQueryDto parm)
|
||
{
|
||
|
||
var response = Queryable();
|
||
|
||
if (parm.FillDateTime != null && parm.FillDateTime.Length == 2)
|
||
{
|
||
if (parm.FillDateTime[0] > DateTime.MinValue)
|
||
{
|
||
response = response.Where(it => it.FillDate >= parm.FillDateTime[0]);
|
||
}
|
||
|
||
if (parm.FillDateTime[1] > DateTime.MinValue)
|
||
{
|
||
|
||
response = response.Where(it => it.FillDate <= parm.FillDateTime[1]);
|
||
}
|
||
}
|
||
|
||
return response.ToPage<DevicePerformance, DevicePerformanceDto>(parm);
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取详情
|
||
/// </summary>
|
||
/// <param name="Id"></param>
|
||
/// <returns></returns>
|
||
public DevicePerformance GetInfo(string Id)
|
||
{
|
||
var response = Queryable()
|
||
.Where(x => x.Id == Id)
|
||
.First();
|
||
|
||
return response;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加设备运行绩效分析
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
public int AddDevicePerformance(DevicePerformance model)
|
||
{
|
||
if (model.FillDate!=null)
|
||
{
|
||
if (Queryable().Where(x => x.FillDate.Value.ToString("yyyy-MM-dd") == model.FillDate.Value.ToString("yyyy-MM-dd")).Count() > 0)
|
||
{
|
||
return -1;//填写日期不能重复
|
||
}
|
||
else
|
||
{
|
||
model.Id = XueHua;
|
||
AutoCalculation(ref model);
|
||
return Context.Insertable(model).ExecuteCommand();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return -2;//填写日期不能为空
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改设备运行绩效分析
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
public int UpdateDevicePerformance(DevicePerformance model)
|
||
{
|
||
AutoCalculation(ref model);
|
||
//var response = Update(w => w.Id == model.Id, it => new DevicePerformance()
|
||
//{
|
||
// Usabletime = model.Usabletime,
|
||
// PlanRuntime = model.PlanRuntime,
|
||
// PlanningNoProductionTime = model.PlanningNoProductionTime,
|
||
// PlanningEatTime = model.PlanningEatTime,
|
||
// PlanningTeamTime = model.PlanningTeamTime,
|
||
// PlanningTraining = model.PlanningTraining,
|
||
// PlanningRest = model.PlanningRest,
|
||
// PlanningMaintenance = model.PlanningMaintenance,
|
||
// PlanningStopEnergy = model.PlanningStopEnergy,
|
||
// DeviceActualRuntime = model.DeviceActualRuntime,
|
||
// FaultShutdownQuantity = model.FaultShutdownQuantity,
|
||
// FaultShutdownRate = model.FaultShutdownRate,
|
||
// GoodConditionRate = model.GoodConditionRate,
|
||
// ComprehensiveEquipmentOperatingRate = model.ComprehensiveEquipmentOperatingRate,
|
||
// Mtbf = model.Mtbf,
|
||
// Mttr = model.Mttr,
|
||
// FillDate = model.FillDate,
|
||
// CreatedBy = model.CreatedBy,
|
||
// CreatedTime = model.CreatedTime,
|
||
// UpdatedBy = model.UpdatedBy,
|
||
// UpdatedTime = model.UpdatedTime,
|
||
//});
|
||
//return response;
|
||
return Update(model, true);
|
||
}
|
||
|
||
private void AutoCalculation(ref DevicePerformance model)
|
||
{
|
||
|
||
|
||
// 设备计划运行时间:(分钟)=设备可使用时间:(分钟)-节假日
|
||
model.PlanRuntime = model.Usabletime - model.Holiday??0;
|
||
|
||
//设备实际可用时间:(分钟)
|
||
model.ActualUsableTime = model.PlanRuntime - model.PlanningNoProductionTime - model.PlanningEatTime - model.PlanningTeamTime - model.PlanningTraining - model.PlanningRest - model.PlanningMaintenance - model.PlanningStopEnergy;
|
||
|
||
//设备实际运行时间:(分钟)
|
||
model.DeviceActualRuntime = model.ActualUsableTime - model.AccidentDeviceFailureTime - model.AccidentProductPrepare - model.AccidentLineLackMaterial - model.AccidentLineReplaceModel - model.AccidentQualityProblem - model.AccidentOthers;
|
||
|
||
|
||
//故障停机率
|
||
if (model.ActualUsableTime > 0 || model.ActualUsableTime < 0)
|
||
{
|
||
model.FaultShutdownRate = Math.Round(model.AccidentDeviceFailureTime / model.ActualUsableTime, 2);
|
||
}
|
||
else
|
||
{
|
||
model.FaultShutdownRate = -1;
|
||
}
|
||
|
||
//设备完好率
|
||
if (model.ActualUsableTime > 0 || model.ActualUsableTime < 0)
|
||
{
|
||
model.GoodConditionRate = Math.Round(model.DeviceActualRuntime / model.ActualUsableTime, 2);
|
||
}
|
||
else
|
||
{
|
||
model.GoodConditionRate = -1;
|
||
}
|
||
|
||
//计划外停机率
|
||
model.AccidentShutdownRate = 1 - model.GoodConditionRate;
|
||
|
||
//综合设备开机率
|
||
if (model.PlanRuntime > 0|| model.PlanRuntime <0)
|
||
{
|
||
model.ComprehensiveEquipmentOperatingRate = Math.Round( model.DeviceActualRuntime / model.PlanRuntime,2);
|
||
}
|
||
else
|
||
{
|
||
model.ComprehensiveEquipmentOperatingRate = 0;
|
||
|
||
}
|
||
|
||
if (model.FaultShutdownQuantity != null && model.FaultShutdownQuantity.Value != 0)
|
||
{
|
||
//MTBF(设备实际运行时间/故障总次数/60
|
||
model.Mtbf = Math.Round((model.DeviceActualRuntime / model.FaultShutdownQuantity.Value) / 60, 2);
|
||
}
|
||
else
|
||
{
|
||
model.Mtbf = 0;
|
||
|
||
}
|
||
|
||
if (model.FaultShutdownQuantity != null && model.FaultShutdownQuantity.Value != 0)
|
||
{
|
||
//MTTR(设备故障停机时间/故障总次数)
|
||
model.Mttr = Math.Round(model.AccidentDeviceFailureTime / model.FaultShutdownQuantity.Value, 2);
|
||
}
|
||
else
|
||
{
|
||
model.Mtbf = 0;
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
}
|
||
} |