using Infrastructure.Attribute; using Infrastructure.Extensions; using DOAN.Model.PBL.Dto; using DOAN.Model.PBL; using DOAN.Repository; using DOAN.Service.PBL.IService; namespace DOAN.Service.PBL { /// /// 料架表Service业务层处理 /// [AppService(ServiceType = typeof(IStoragelocationService), ServiceLifetime = LifeTime.Transient)] public class StoragelocationService : BaseService, IStoragelocationService { /// /// 查询料架表列表 /// /// /// public PagedInfo GetList(StoragelocationQueryDto parm) { var predicate = QueryExp(parm); var response = Queryable() .Where(predicate.ToExpression()) .ToPage(parm); return response; } /// /// 获取详情 /// /// /// public Storagelocation GetInfo(int Id) { var response = Queryable() .Where(x => x.Id == Id) .First(); return response; } /// /// 添加料架表 /// /// /// public Storagelocation AddStoragelocation(Storagelocation model) { return Insertable(model).ExecuteReturnEntity(); } /// /// 修改料架表 /// /// /// public int UpdateStoragelocation(Storagelocation model) { return Update(model, true); } public List GetPartNumberList() { var response = Queryable() .GroupBy(it=>it.Partnumber) .Select(it=>new StoragelocationPartNumberGroupDto() { RackCode = SqlFunc.AggregateMax(it.RackCode), Partnumber = SqlFunc.AggregateMax( it.Partnumber), PackageNum = SqlFunc.AggregateSum(it.PackageNum) ?? 0 }) .OrderBy(it => it.RackCode) .ToList(); return response; } /// /// 查询导出表达式 /// /// /// private static Expressionable QueryExp(StoragelocationQueryDto parm) { var predicate = Expressionable.Create() .AndIF(!string.IsNullOrEmpty(parm.Partnumber),it=>it.Partnumber.Contains( parm.Partnumber)) .AndIF(!string.IsNullOrEmpty(parm.RackCode),it=>it.RackCode.Contains( parm.RackCode)) ; return predicate; } public List GetRackCodeOptions() { var response = Queryable() .GroupBy(it => it.RackCode) .OrderBy(it => it.RackCode) .Select(it => new SelectOptionsDto() { Key = SqlFunc.AggregateMax(it.Id).ToString(), Label = SqlFunc.AggregateMax(it.RackCode), Value = SqlFunc.AggregateMax(it.RackCode) }) .OrderBy(it => it.Key) .ToList(); return response; } public List GetPartNumberOptions() { var response = Context.Queryable() .Select(it => new SelectOptionsDto() { Key = it.Id.ToString(), Label = it.Productname + it.Productcode + " " + it.MirrorshellName + it.MirrorshellCode, Value = it.MirrorshellCode }) .OrderBy(it => it.Key) .ToList(); return response; } public int UpdateRackPartNumber(string rackCode, int layerNum, string partnumber) { return Context.Updateable() .SetColumns(it => it.Partnumber == partnumber ) .Where(it => it.RackCode == rackCode && it.LayerNum == layerNum) .ExecuteCommand(); } } }