Valeo_Line_MES_backend/MDM/Services/Plant/PlantPlcIoPointService.cs
2026-01-10 13:47:54 +08:00

116 lines
3.8 KiB
C#

using System;
using SqlSugar;
using Infrastructure.Attribute;
using MDM.Services.IPlantService;
using MDM.Service;
using MDM.Model;
using MDM.Model.Plant;
using MDM.Model.Plant.Dto;
using MDM.Repository;
using SqlSugar.IOC;
namespace MDM.Services.Plant
{
/// <summary>
/// PLC点位Service业务层处理
/// </summary>
[AppService(ServiceType = typeof(IPlantPlcIoPointService), ServiceLifetime = LifeTime.Transient)]
public class PlantPlcIoPointService : BaseService<PlantPlcIoPoint>, IPlantPlcIoPointService
{
private readonly PlcIoPointCacheService _cacheService;
public PlantPlcIoPointService(PlcIoPointCacheService cacheService)
{
_cacheService = cacheService;
}
/// <summary>
/// 查询PLC点位列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<PlantPlcIoPointDto> GetList(PlantPlcIoPointQueryDto parm)
{
var predicate = Expressionable.Create<PlantPlcIoPoint>()
.AndIF(!string.IsNullOrEmpty(parm.FkWorkstationCode), it => it.FkWorkstationCode.Contains(parm.FkWorkstationCode))
.AndIF(!string.IsNullOrEmpty(parm.FkProcessParamCode), it => it.FkProcessParamCode.Contains(parm.FkProcessParamCode))
.AndIF(!string.IsNullOrEmpty(parm.FkDeviceCode), it => it.FkDeviceCode.Contains(parm.FkDeviceCode))
;
var response = Queryable()
.Where(predicate.ToExpression())
.ToPage<PlantPlcIoPoint, PlantPlcIoPointDto>(parm);
return response;
}
/// <summary>
/// 获取详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public PlantPlcIoPoint GetInfo(int Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
/// <summary>
/// 添加PLC点位
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public PlantPlcIoPoint AddPlantPlcIoPoint(PlantPlcIoPoint model)
{
PlantPlcIoPoint result = Context.Insertable(model).ExecuteReturnEntity();
if (result != null)
{
var activePoints = Context.Queryable<PlantPlcIoPoint>()
.Where(p => p.IsActive == 1)
.ToList();
_cacheService.InitializeCache(activePoints);
}
return result;
}
/// <summary>
/// 修改PLC点位
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int UpdatePlantPlcIoPoint(PlantPlcIoPoint model)
{
//var response = Update(w => w.Id == model.Id, it => new PlantPlcIoPoint()
//{
// FkWorkstationCode = model.FkWorkstationCode,
// FkProcessParamCode = model.FkProcessParamCode,
// FkDeviceCode = model.FkDeviceCode,
// PointType = model.PointType,
// Address = model.Address,
// IsActive = model.IsActive,
// Description = model.Description,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
//});
//return response;
int result= Update(model, true);
if (result != null)
{
var activePoints = Context.Queryable<PlantPlcIoPoint>()
.Where(p => p.IsActive == 1)
.ToList();
_cacheService.InitializeCache(activePoints);
}
return result;
}
}
}