using Infrastructure.Attribute; using Microsoft.AspNetCore.Components.Web; using Microsoft.Extensions.DependencyInjection; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ZR.Model.mes.md; using ZR.Service.mes.md.IService; using ZR.Service.MES.md.IService; using static System.Runtime.InteropServices.JavaScript.JSType; namespace ZR.Service.MES.md { [AppService(ServiceType = typeof(IMdBOMService), ServiceLifetime = LifeTime.Transient)] public class MdBOMService : BaseService, IMdBOMService { int IMdBOMService.AddWorkline(MdBom workline) { throw new NotImplementedException(); } int IMdBOMService.deleteWorkline(int[] ids) { throw new NotImplementedException(); } (int, List) IMdBOMService.GetAll(string productCode, string productName, int pageNum, int pageSize) { int totalNum = 0; if (string.IsNullOrEmpty(productCode) && string.IsNullOrEmpty(productName)) { var data = Context.Queryable().ToPageList(pageNum, pageSize,ref totalNum); return (totalNum, data); } else { //1. 查询本体 var predicate = Expressionable.Create() .AndIF(!string.IsNullOrEmpty(productCode), it => it.ProductCode.Contains(productCode)) .AndIF(!string.IsNullOrEmpty(productName), it => it.ProductName.Contains(productName)) .ToExpression(); List data = Context.Queryable().Where(predicate).ToList(); //2. 查询儿子 if (data != null & data.Count > 0) { List data1 = new List(); List data2 = new List(); foreach (var item in data) { List dataItems = Context.Queryable().Where(it => it.ParentProductId == item.Id).ToList(); data1.AddRange(dataItems); dataItems.Clear(); // 3. 查询孙子 if (data1 != null & data1.Count > 0) { foreach (var item1 in data1) { List dataItemss = Context.Queryable().Where(it1 => it1.ParentProductId == item1.Id).ToList(); data2.AddRange(dataItemss); dataItemss.Clear(); } } } data.AddRange(data1); data.AddRange(data2); } return (data.Count(),data); } } int IMdBOMService.UpdateWorkline(MdBom workline) { throw new NotImplementedException(); } } }