using HighWayIot.Log4net; using HighWayIot.Repository.domain; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; namespace HighWayIot.Repository.service.Impl { public class BaseContentServiceImpl : IContentService { private static readonly Lazy lazy = new Lazy(() => new BaseContentServiceImpl()); public static BaseContentServiceImpl Instance => lazy.Value; private LogHelper log = LogHelper.Instance; Repository _repository => new Repository("sqlite"); public List GetContentInfos(string lineNo) { try { List deviceInfo = _repository.GetList(x => x.LineNo == lineNo); return deviceInfo; }catch (Exception ex) { log.Error("RFID内容信息获取异常", ex); return null; } } public List GetContentInfos() { try { List deviceInfo = _repository.GetList(); return deviceInfo; } catch (Exception ex) { log.Error("RFID内容信息获取异常", ex); return null; } } public List Get200Infos(string lineNo) { try { DateTime UsefulTime = DateTime.Now - TimeSpan.FromDays(1); List deviceInfo = _repository.GetList(x => x.LineNo == lineNo && x.LogTime >= UsefulTime).OrderByDescending(x => x.ID).Take(200).ToList(); return deviceInfo; } catch (Exception ex) { log.Error("RFID内容信息获取异常", ex); return null; } } public List Get200Infos() { try { DateTime UsefulTime = DateTime.Now - TimeSpan.FromDays(1); List deviceInfo = _repository.GetList(x => x.LogTime >= UsefulTime).OrderByDescending(x => x.ID).Take(200).ToList(); return deviceInfo; } catch (Exception ex) { log.Error("RFID内容信息获取异常", ex); return null; } } public void AddContentInfo(RFIDContent content) { try { _repository.Insert(content); } catch (Exception ex) { log.Error("RFID内容信息插入异常", ex); } } public bool DelBeforeMonthContent() { try { DateTime time = DateTime.Now - TimeSpan.FromDays(90); _repository.AsDeleteable().Where(x => x.LogTime <= time).ExecuteCommand(); return true; } catch(Exception ex) { log.Error("RFID内容信息删除异常", ex); return false; } } } }