using Admin.Core.IRepository; using Admin.Core.IService; using Admin.Core.Model; using Admin.Core.Model.Model_New; using log4net; using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.IdentityModel.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Admin.Core.Service { public class BaseBomInfoServices : BaseServices, IBaseBomInfoServices { private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(BaseBomInfoServices)); private readonly IBaseRepository _dal; public BaseBomInfoServices(IBaseRepository dal) { this._dal = dal; base.BaseDal = dal; } public async Task GetChildenBomInfoByMaterialCode(string materialCode, string materialType) { BaseBomInfo bomInfo = null; try { var info =await GetChildenByParentId(materialCode); if (info.Count > 0) { bomInfo = info.FirstOrDefault(x => x.MaterialType == materialType); } } catch (Exception ex) { logHelper.Error("获取BOM集合异常", ex); } return bomInfo; } private async Task> GetChildenByParentId(string parentId, List result = null) { if (result == null) { result = new List(); } try { var info =await _dal.QueryAsync(x => x.ParentId == parentId); if (info.Count > 0) { foreach (var item in info) { result.Add(item); var childInfos = GetChildenByParentId(item.MaterialCode, result); } } } catch (Exception ex) { logHelper.Error("获取BOM集合异常", ex); } return result; } } }