using System; using SqlSugar; using Infrastructure.Attribute; using Infrastructure.Extensions; using ZR.Model; using ZR.Repository; using System.Linq; using ZR.Service.MES.dev.IService; using ZR.Model.MES.dev; using ZR.Model.MES.dev; using ZR.Model.MES.dev.Dto; using ZR.Service.MES.dev.IService; namespace ZR.Service.MES.dev { /// /// 设备检查项Service业务层处理 /// [AppService(ServiceType = typeof(IDeviceInspectService), ServiceLifetime = LifeTime.Transient)] public class DeviceInspectService : BaseService, IDeviceInspectService { /// /// 查询设备检查项列表 /// /// /// public PagedInfo GetList(DeviceInspectQueryDto parm) { var predicate = Expressionable.Create(); predicate.AndIF(!string.IsNullOrEmpty(parm.Name), it => it.Name.Contains(parm.Name)) .AndIF(parm.Status >= 0, it => it.Status == parm.Status); var response = Queryable() .Where(predicate.ToExpression()) .ToPage(parm); return response; } /// /// 设备绑定模块 查询未绑定且状态为1 的设备检查项 /// /// /// public PagedInfo GetList2(DeviceInspectQueryDto2 parm) { var predicate = Expressionable.Create(); predicate .AndIF(!string.IsNullOrEmpty(parm.Name), (r, i) => i.Name.Contains(parm.Name)) .And((r, i) => i.Status == 1) .AndIF(parm.Isbind == 1, (r, i) => r.FkAccountId == parm.FkAccountId) .AndIF(parm.Isbind == 0, (r, i) => r.FkAccountId != parm.FkAccountId||r.FkInspectId==null); ISugarQueryable query = Context.Queryable() .RightJoin((r, i) => r.FkInspectId == i.Id) .Where(predicate.ToExpression()) .OrderBy((r, i)=>r.Sort) .Select((r, i) => i); var response = query.ToPage(parm); return response; } /// /// 获取详情 /// /// /// public DeviceInspect GetInfo(int Id) { var response = Queryable() .Where(x => x.Id == Id) .First(); return response; } /// /// 添加设备检查项 /// /// /// public DeviceInspect AddDeviceInspect(DeviceInspect model) { return Context.Insertable(model).ExecuteReturnEntity(); } /// /// 修改设备检查项 /// /// /// public int UpdateDeviceInspect(DeviceInspect model) { //var response = Update(w => w.Id == model.Id, it => new DeviceInspect() //{ // Image = model.Image, // Sort = model.Sort, // Type = model.Type, // Remark = model.Remark, // Status = model.Status, // Name = model.Name, // CreatedBy = model.CreatedBy, // CreatedTime = model.CreatedTime, // UpdatedBy = model.UpdatedBy, // UpdatedTime = model.UpdatedTime, //}); //return response; return Update(model, true); } /// /// 增加绑定关系 /// /// /// public int AddBindrelative(DeviceInspectQueryDto3 parm,string name) { int result = 0; List rel_account_inspect_list=new List (); if(parm.inspect_ids != null&& parm.inspect_ids.Count() > 0) { foreach(var id in parm.inspect_ids) { DeviceRelAccountInspect inspect = new DeviceRelAccountInspect(); inspect.FkAccountId = parm.account_id; inspect.FkInspectId = id; inspect.CreatedBy = name; inspect.CreatedTime= DateTime.Now; inspect.Sort = 1; rel_account_inspect_list.Add(inspect); } result= Context.Insertable(rel_account_inspect_list).ExecuteCommand(); } return result; } /// /// 删除绑定接口 /// /// /// /// public int RemoveBindrelative(int account_id,int inspect_id) { return Context.Deleteable().Where(it => it.FkAccountId == account_id).Where(it => it.FkInspectId == inspect_id).ExecuteCommand(); } public int SortBindrelative(List parm) { return Context.Updateable(parm).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); } } }