using System; using SqlSugar; using Infrastructure.Attribute; using Infrastructure.Extensions; using DOAN.Model; using DOAN.Model.MES.base_.Dto; using DOAN.Model.MES.base_; using DOAN.Repository; using DOAN.Service.MES.base_.IService; using System.Linq; using Mapster; using System.Buffers; using System.ComponentModel; namespace DOAN.Service.MES.base_ { /// /// 物料清单Service业务层处理 /// [AppService(ServiceType = typeof(IBaseMaterialListService), ServiceLifetime = LifeTime.Transient)] public class BaseMaterialListService : BaseService, IBaseMaterialListService { /// /// 查询物料清单列表 /// /// /// public PagedInfo GetList(BaseMaterialListQueryDto parm) { var predicate = Expressionable.Create() .AndIF(!string.IsNullOrEmpty(parm.Name), it => it.Name.Contains(parm.Name)) .AndIF(!string.IsNullOrEmpty(parm.Code), it => it.Code.Contains (parm.Code)) .AndIF(!string.IsNullOrEmpty(parm.FkMaterialTypeCode) , it => it.FkMaterialTypeCode.Contains(parm.FkMaterialTypeCode)) .AndIF(parm.TimeRange != null && parm.TimeRange.Length == 2 && parm.TimeRange[0] > DateTime.MinValue, it => it.CreatedTime >= parm.TimeRange[0]) .AndIF(parm.TimeRange != null && parm.TimeRange.Length == 2 && parm.TimeRange[1] > DateTime.MinValue, it => it.CreatedTime <= parm.TimeRange[1]); var query01 = Queryable() .Where(predicate.ToExpression()); var response = Context.Queryable(query01).LeftJoin((q, t) => q.FkMaterialTypeCode == t.Code) // .LeftJoin((q, t, s) => q.FkSupplierId == s.Id) .Select((q, t) => new BaseMaterialListDto2 { FkMaterialTypeName = t.Name, FkMaterialTypeCode = t.Code, }, true).ToPage(parm); return response; } /// /// 获取详情 /// /// /// public BaseMaterialList GetInfo(string Id) { var response = Queryable() .Where(x => x.Id == Id) .First(); return response; } /// /// 添加物料清单 /// /// /// public BaseMaterialList AddBaseMaterialList(BaseMaterialList model) { model.Id = SnowFlakeSingle.Instance.NextId().ToString(); return Context.Insertable(model).ExecuteReturnEntity(); } /// /// 修改物料清单 /// /// /// public int UpdateBaseMaterialList(BaseMaterialList model) { //var response = Update(w => w.Id == model.Id, it => new BaseMaterialList() //{ // Name = model.Name, // Code = model.Code, // Customer code = model.Customer code, // Color = model.Color, // Specification = model.Specification, // Unit = model.Unit, // Description = model.Description, // ExpirationUnit = model.ExpirationUnit, // ExpirationDate = model.ExpirationDate, // ShelfLifeWarningDays = model.ShelfLifeWarningDays, // IsShelfLife = model.IsShelfLife, // StartTime = model.StartTime, // StopTime = model.StopTime, // BarCode = model.BarCode, // IsBatch = model.IsBatch, // CreatedBy = model.CreatedBy, // CreatedTime = model.CreatedTime, // UpdatedBy = model.UpdatedBy, // UpdatedTime = model.UpdatedTime, //}); //return response; return Update(model, true); } } }