using Admin.Core.IRepository; using Admin.Core.IService; using Admin.Core.Model; using Admin.Core.Model.Model_New; using Admin.Core.Model.ViewModels; using log4net; using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.IdentityModel.Logging; using NPOI.XSSF.UserModel; 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; private readonly IBaseBomInfoRepository _baseBomInfoRepository; public BaseBomInfoServices(IBaseRepository dal, IBaseBomInfoRepository baseBomInfoRepository) { this._dal = dal; base.BaseDal = dal; _baseBomInfoRepository = baseBomInfoRepository; } /// /// 获取系统班组时间 /// public async Task> getWorkTime() { try { List list = null; var _db = this.BaseDal.Db; list = await _db.CopyNew().Ado.SqlQueryAsync("SELECT * FROM VIEW_CURRENT_TEAM_TIME ORDER BY START_TIME"); return list; } catch (Exception) { return null; } } /// /// public async Task GetBomInfoByMaterialCode(string materialCode) { BaseBomInfo bomInfo = null; try { bomInfo = await _dal.FirstAsync(x => x.MaterialCode == materialCode); } catch (Exception ex) { logHelper.Error("根据物料编号获取BOM信息异常", ex); } return bomInfo; } 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; } public async Task> GetBoxChildData(string materialCode) { return await _baseBomInfoRepository.GetBoxChildData(materialCode); } } }