using Durkee.Mes.Api.Common; using Durkee.Mes.Api.Model.domain; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Text; namespace Durkee.Mes.Api.Repository.service.Impl { public class BaseMaterialServiceImpl : IBaseMaterialService { private Repository _repository; private ILogger _logger; public BaseMaterialServiceImpl(Repository repository,ILogger logger) { _repository = repository; _logger = logger; } /// /// 通过物料编码获取物料信息 /// /// /// public BaseMaterialInfo GetMaterialInfoByMaterialCode(string materialCode) { BaseMaterialInfo materialInfo = null; try { materialInfo = _repository.GetFirst(x=>x.MaterialCode == materialCode); }catch (Exception ex) { _logger.LogError($"根据物料编号获取物料信息异常:{ex.Message}"); } return materialInfo; } /// /// 通过SAP物料编码获取物料信息 /// /// /// public BaseMaterialInfo GetMaterialInfoBySapMaterialCode(string sapMaterialCode) { BaseMaterialInfo materialInfo = null; try { materialInfo = _repository.GetFirst(x => x.SAPMaterialCode == sapMaterialCode); } catch (Exception ex) { _logger.LogError($"根据SAP物料编号获取物料信息异常:{ex.Message}"); } return materialInfo; } /// /// 获取所有的物料信息 /// /// public List GetMaterialInfos() { List materialInfos = null; try { materialInfos = _repository.GetList(); } catch (Exception ex) { _logger.LogError($"获取物料信息异常:{ex.Message}"); } return materialInfos; } /// /// 通过物料类别获取物料信息 /// /// 物料大类 /// 物料细类 /// public List GetMaterialInfosByMaterialType(int majorTypeId, string minorTypeId) { List materialInfos = null; try { Expression> exp = x => true; if(majorTypeId != 0) { exp = exp.And(x=>x.MajorTypeID == majorTypeId); }else if (!string.IsNullOrEmpty(minorTypeId)) { exp = exp.And(x=>x.MinorTypeID == minorTypeId); } materialInfos = _repository.GetList(exp); } catch (Exception ex) { _logger.LogError($"通过物料类型获取物料信息异常:{ex.Message}"); } return materialInfos; } } }