using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.DAL { /// /// 能效汇总(多)日记录 /// public class EtaSumMultiDayRecord : CorpDAL { /// /// /// public override ConnectionConfig ConnectionConfig { get { return ConfigHelper.RecordConnectionConfig; } } /// /// /// /// /// public override bool Inserts(List list) { if (list == null || list.Count < 1) return default; var corpIds = list.Select(x => x.CorpID).Distinct().ToList(); if (corpIds.Count() != 1 || corpIds[0] < 1) return default; using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig)) { try { db.BeginTran(); foreach (var item in list) { var id = db.Insertable(item).ExecuteReturnSnowflakeId(); if (id < 1) { db.RollbackTran(); return false; } } db.CommitTran(); return true; } catch { db.RollbackTran(); return false; } } } /// /// 通过对象获取 /// public List GetByObject(long CorpID, string ObjectType, long ObjectID) { using (var db = new SqlSugarClient(ConnectionConfig)) { return db.Queryable() .Where(x => x.CorpID == CorpID && x.ObjectType == ObjectType && x.ObjectID == ObjectID) .ToList(); } } /// /// 通过 CorpID 获取某日的数据 /// public List GetByCorpIDOfDay(long CorpID, DateTime Day) { using (var db = new SqlSugarClient(ConnectionConfig)) { return db.Queryable() .Where(x => x.CorpID == CorpID) .Where(x => x.DataDay == Day.Date) .ToList(); } } /// /// 通过对象获取某日的数据 /// public List GetByObjectOfDay(long CorpID, string ObjectType, long ObjectID, DateTime Day) { using (var db = new SqlSugarClient(ConnectionConfig)) { return db.Queryable() .Where(x => x.CorpID == CorpID && x.ObjectType == ObjectType && x.ObjectID == ObjectID) .Where(x => x.DataDay == Day.Date) .ToList(); } } /// /// 通过 CorpID 获取日期区间内的数据 /// public List GetByCorpIDOfDayRange(long CorpID, DateTime StartDay, DateTime EndDay) { if (StartDay.Date > EndDay.Date) return default; using (var db = new SqlSugarClient(ConnectionConfig)) { return db.Queryable() .Where(x => x.CorpID == CorpID) .Where(x => x.DataDay >= StartDay.Date && x.DataDay <= EndDay.Date) .ToList(); } } /// /// 通过对象获取日期区间内的数据 /// public List GetByObjectOfDayRange(long CorpID, string ObjectType, long ObjectID, DateTime StartDay, DateTime EndDay) { if (StartDay.Date > EndDay.Date) return default; using (var db = new SqlSugarClient(ConnectionConfig)) { return db.Queryable() .Where(x => x.CorpID == CorpID && x.ObjectType == ObjectType && x.ObjectID == ObjectID) .Where(x => x.DataDay >=StartDay.Date&&x.DataDay<=EndDay.Date) .ToList(); } } /// /// 通过对象获取日期区间内的最大流量的记录数据 /// public Entity.EtaSumMultiDayRecord GetMaxQtByObjectOfDayRange(long CorpID, string ObjectType, long ObjectID, DateTime StartDay, DateTime EndDay) { if (StartDay.Date > EndDay.Date) return default; using (var db = new SqlSugarClient(ConnectionConfig)) { return db.Queryable() .Where(x => x.CorpID == CorpID && x.ObjectType == ObjectType && x.ObjectID == ObjectID) .Where(x => x.DataDay >= StartDay.Date && x.DataDay <= EndDay.Date) .OrderBy(x => x.Qt, OrderByType.Desc).First(); } } } }