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 ZxWeightService { private static readonly Lazy lazy = new Lazy(() => new ZxWeightService()); public static ZxWeightService Instance { get { return lazy.Value; } } private LogHelper log = LogHelper.Instance; Repository _repository => new Repository("sqlserver"); /// /// 根据配方编号查询称量信息 /// /// 配方号 /// public List GetWeightInfos(string recipeCode) { try { List entity = _repository.GetList(x => x.RecipeCode == recipeCode && x.IsDeleted == false); return entity; } catch (Exception ex) { log.Error("称量信息获取异常", ex); return null; } } /// /// 新增称量信息 /// /// 称量信息 /// public bool InsertWeightInfo(ZxWeightEntity entity) { try { return _repository.Insert(entity); } catch (Exception ex) { log.Error("称量信息添加异常", ex); return false; } } /// /// 修改称量信息 /// /// 称量信息 /// public bool UpdateWeightInfo(ZxWeightEntity entity) { try { return _repository.Update(entity); } catch(Exception ex) { log.Error("称量信息修改异常", ex); return false; } } /// /// 根据ID删除称量信息 /// /// ID /// public bool DeleteWeightInfoById(int id) { try { ZxWeightEntity e = _repository.GetById(id); e.IsDeleted = true; return _repository.Update(e); } catch (Exception ex) { log.Error("称量信息删除异常", ex); return false; } } /// /// 根据RecipeCode删除称量信息 /// /// 配方号 /// public bool DeleteWeightInfoByRecipeCode(string recipeCode) { try { List es = _repository.GetList(x => x.RecipeCode == recipeCode && x.IsDeleted == false); es.ForEach(x => x.IsDeleted = true); if (es.Count == 0) { return true; } return _repository.UpdateRange(es); } catch (Exception ex) { log.Error("称量信息删除异常", ex); return false; } } } }