using System; using System.Linq; using DOAN.Model; using DOAN.Model.Dto; using DOAN.Model.MES.dev; using DOAN.Model.MES.dev.Dto; using DOAN.Repository; using DOAN.Service.MES.dev.IService; using Infrastructure.Attribute; using Infrastructure.Extensions; using Mapster; using SqlSugar; namespace DOAN.Service.MES.dev { /// /// 备品备件基本信息表Service业务层处理 /// [AppService( ServiceType = typeof(IDeviceSparePartsService), ServiceLifetime = LifeTime.Transient )] public class DeviceSparePartsService : BaseService, IDeviceSparePartsService { /// /// 查询备品备件基本信息表列表 /// /// /// public PagedInfo GetList(DeviceSparePartsQueryDto parm) { var predicate = Expressionable .Create() .AndIF( !string.IsNullOrEmpty(parm.PartName), s => s.PartName.Contains(parm.PartName) ) .AndIF( !string.IsNullOrEmpty(parm.PartCode), s => s.PartCode.Contains(parm.PartCode) ) .AndIF( !string.IsNullOrEmpty(parm.Description), s => s.Description.Contains(parm.Description) ) .AndIF(parm.CategoryId > -1, s => s.CategoryId == parm.CategoryId.Value) .AndIF(parm.FkSupplierId > -1, s => s.FkSupplierId == parm.FkSupplierId.Value); var response = Context .Queryable( (s, sp, pc) => new JoinQueryInfos( JoinType.Left, s.FkSupplierId == sp.SupplierId, JoinType.Left, s.CategoryId == pc.CategoryId ) ) .Where(predicate.ToExpression()) .Select( (s, sp, pc) => new DeviceSparePartsDto { // 映射原有字段 PartId = s.PartId, PartName = s.PartName, PartCode = s.PartCode, Description = s.Description, CategoryId = s.CategoryId, CategoryName = pc.CategoryName, UnitOfMeasure = s.UnitOfMeasure, MinStockLevel = s.MinStockLevel, MaxStockLevel = s.MaxStockLevel, CreatedAt = s.CreatedAt, UpdatedAt = s.UpdatedAt, FkSupplierId = sp.SupplierId, SupplierName = sp.SupplierName, Phone = sp.Phone } ) .ToPage(parm); /*var response = Queryable() .Where(predicate.ToExpression()) .ToPage(parm);*/ return response; } public List GetListNOPage(string query) { var response = Queryable() .WhereIF( !string.IsNullOrEmpty(query), x => x.PartName.Contains(query) || x.PartCode.Contains(query) ) .ToList() .Adapt, List>(); return response; } /// /// 获取详情 /// /// /// public DeviceSpareParts GetInfo(int PartId) { var response = Queryable().Where(x => x.PartId == PartId).First(); return response; } /// /// 添加备品备件基本信息表 /// /// /// public DeviceSpareParts AddDeviceSpareParts(DeviceSpareParts model) { return Context.Insertable(model).ExecuteReturnEntity(); } /// /// 修改备品备件基本信息表 /// /// /// public int UpdateDeviceSpareParts(DeviceSpareParts model) { //var response = Update(w => w.PartId == model.PartId, it => new DeviceSpareParts() //{ // PartName = model.PartName, // PartNumber = model.PartNumber, // Description = model.Description, // UnitOfMeasure = model.UnitOfMeasure, // MinStockLevel = model.MinStockLevel, // MaxStockLevel = model.MaxStockLevel, // CreatedAt = model.CreatedAt, // UpdatedAt = model.UpdatedAt, //}); //return response; return Update(model, true); } public List GetSupplierOptions() { return Context .Queryable() .Select(s => new DropdownOption { Value = s.SupplierId, Label = s.SupplierName }) .ToList(); } public List GetDevicePartsCategoriesOptions() { return Context .Queryable() .Select(s => new DropdownOption { Value = s.CategoryId, Label = s.CategoryName }) .ToList(); } } }