using HighWayIot.Log4net; using HighWayIot.Repository.domain; using Models; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; namespace HighWayIot.Repository.service { public class ZxMaterialService { private static readonly Lazy lazy = new Lazy(() => new ZxMaterialService()); public static ZxMaterialService Instance { get { return lazy.Value; } } private LogHelper log = LogHelper.Instance; Repository _repository => new Repository("sqlserver"); /// /// 查询所有物料信息 /// /// 物料名 /// 类型 /// 子类型 /// 是否按是否使用查询 /// 是否使用 /// public List GetMaterialInfos(string materialName = null, string materialType = null, string childType = null, bool isAvaliableUse = false, bool isUse = false) { try { List entity = _repository.GetList(x => x.IsDeleted == false); if(!string.IsNullOrEmpty(materialName)) { entity = entity.Where(x => x.MaterialName.Contains(materialName)).ToList(); } if(!string.IsNullOrEmpty(materialType)) { if(!string.IsNullOrEmpty(childType)) { entity = entity.Where(x => x.MaterialType == materialType && x.ChildType == childType).ToList(); } else { entity = entity.Where(x => x.MaterialType == materialType).ToList(); } } if(isAvaliableUse == true) { entity = entity.Where(x => x.IsUse == isUse).ToList(); } return entity; } catch (Exception ex) { log.Error("物料信息获取异常", ex); return null; } } /// /// 根据Id获取单条数据 /// /// 物料编号 /// public ZxMaterialEntity GetSingleEntityById(int id) { try { return _repository.GetById(id); } catch (Exception ex) { log.Error("单条物料信息获取异常", ex); return null; } } /// /// 根据MaterialCode获取数据 /// /// 物料编号 /// public List GetEntityByMaterialCode(string materialCode) { try { return _repository.GetList(x => x.MaterialCode == materialCode && x.IsDeleted == false); } catch (Exception ex) { log.Error("根据MaterialCode获取物料信息获取异常", ex); return null; } } /// /// 修改物料信息 /// /// /// public bool UpdateMaterialInfo(ZxMaterialEntity entity) { try { return _repository.Update(entity); } catch (Exception ex) { log.Error("物料信息修改异常", ex); return false; } } /// /// 新增物料信息 /// /// /// public bool InsertMaterialInfo(ZxMaterialEntity entity) { try { return _repository.Insert(entity); } catch (Exception ex) { log.Error("物料信息添加异常", ex); return false; } } /// /// 删除物料信息 /// /// /// public bool DeleteMaterialInfoById(int id) { try { ZxMaterialEntity e = _repository.GetById(id); e.IsDeleted = true; return _repository.Update(e); } catch (Exception ex) { log.Error("物料信息删除异常", ex); return false; } } } }