using Aucma.Scada.Model.domain; using HighWayIot.Log4net; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace HighWayIot.Repository.service.Impl { public class BaseBomInfoServiceImpl : IBaseBomInfoService { Repository _bomInfoRepository => new Repository("mes"); private LogHelper logHelper = LogHelper.Instance; /// /// 获取系统班组时间 /// public async Task> getWorkTime() { try { List list = null; var _db = _bomInfoRepository.Context; list = await _db.SqlQueryable("SELECT * FROM VIEW_CURRENT_TEAM_TIME ORDER BY START_TIME").ToListAsync(); return list; } catch (Exception) { return null; } } public List GetBomInfos() { try { var info = _bomInfoRepository.GetList(); return info; } catch (Exception ex) { logHelper.Error("获取BOM集合异常", ex); return null; } } public BaseBomInfo GetChildenBomInfoByMaterialCode(string materialCode, string materialType) { BaseBomInfo bomInfo = null; try { var info = GetChildenByParentId(materialCode); if (info.Count > 0) { bomInfo = info.Where(x => x.materialType == materialType).First(); } } catch (Exception ex) { logHelper.Error("获取BOM集合异常", ex); } return bomInfo; } /// /// 根据物料编号获取BOM信息 /// /// /// public BaseBomInfo GetBomInfoByMaterialCode(string materialCode) { BaseBomInfo bomInfo = null; try { bomInfo = _bomInfoRepository.GetFirst(x => x.materialCode == materialCode); } catch (Exception ex) { logHelper.Error("根据物料编号获取BOM信息异常", ex); } return bomInfo; } private List GetChildenByParentId(string parentId, List result = null) { if (result == null) { result = new List(); } try { var info = _bomInfoRepository.GetList(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; } } }