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 { /// /// PLC点位Service业务层处理 /// [AppService(ServiceType = typeof(IPlantPlcIoPointService), ServiceLifetime = LifeTime.Transient)] public class PlantPlcIoPointService : BaseService, IPlantPlcIoPointService { private readonly PlcIoPointCacheService _cacheService; public PlantPlcIoPointService(PlcIoPointCacheService cacheService) { _cacheService = cacheService; } /// /// 查询PLC点位列表 /// /// /// public PagedInfo GetList(PlantPlcIoPointQueryDto parm) { var predicate = Expressionable.Create() .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(parm); return response; } /// /// 获取详情 /// /// /// public PlantPlcIoPoint GetInfo(int Id) { var response = Queryable() .Where(x => x.Id == Id) .First(); return response; } /// /// 添加PLC点位 /// /// /// public PlantPlcIoPoint AddPlantPlcIoPoint(PlantPlcIoPoint model) { PlantPlcIoPoint result = Context.Insertable(model).ExecuteReturnEntity(); if (result != null) { var activePoints = Context.Queryable() .Where(p => p.IsActive == 1) .ToList(); _cacheService.InitializeCache(activePoints); } return result; } /// /// 修改PLC点位 /// /// /// 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() .Where(p => p.IsActive == 1) .ToList(); _cacheService.InitializeCache(activePoints); } return result; } } }