using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.DAL
|
{
|
/// <summary>
|
/// 能效汇总(多)日记录
|
/// </summary>
|
public class EtaSumMultiDayRecord : CorpDAL<Entity.EtaSumMultiDayRecord>
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public override ConnectionConfig ConnectionConfig
|
{
|
get { return ConfigHelper.RecordConnectionConfig; }
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="list"></param>
|
/// <returns></returns>
|
public override bool Inserts(List<Entity.EtaSumMultiDayRecord> 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;
|
}
|
|
}
|
}
|
|
/// <summary>
|
/// 通过对象获取
|
/// </summary>
|
public List<Entity.EtaSumMultiDayRecord> GetByObject(long CorpID, string ObjectType, long ObjectID)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.EtaSumMultiDayRecord>()
|
.Where(x => x.CorpID == CorpID && x.ObjectType == ObjectType && x.ObjectID == ObjectID)
|
.ToList();
|
}
|
}
|
|
/// <summary>
|
/// 通过 CorpID 获取某日的数据
|
/// </summary>
|
public List<Entity.EtaSumMultiDayRecord> GetByCorpIDOfDay(long CorpID, DateTime Day)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.EtaSumMultiDayRecord>()
|
.Where(x => x.CorpID == CorpID)
|
.Where(x => x.DataDay == Day.Date)
|
.ToList();
|
}
|
}
|
|
/// <summary>
|
/// 通过对象获取某日的数据
|
/// </summary>
|
public List<Entity.EtaSumMultiDayRecord> GetByObjectOfDay(long CorpID, string ObjectType, long ObjectID, DateTime Day)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.EtaSumMultiDayRecord>()
|
.Where(x => x.CorpID == CorpID && x.ObjectType == ObjectType && x.ObjectID == ObjectID)
|
.Where(x => x.DataDay == Day.Date)
|
.ToList();
|
}
|
}
|
|
/// <summary>
|
/// 通过 CorpID 获取日期区间内的数据
|
/// </summary>
|
public List<Entity.EtaSumMultiDayRecord> GetByCorpIDOfDayRange(long CorpID, DateTime StartDay, DateTime EndDay)
|
{
|
if (StartDay.Date > EndDay.Date)
|
return default;
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.EtaSumMultiDayRecord>()
|
.Where(x => x.CorpID == CorpID)
|
.Where(x => x.DataDay >= StartDay.Date && x.DataDay <= EndDay.Date)
|
.ToList();
|
}
|
}
|
|
/// <summary>
|
/// 通过对象获取日期区间内的数据
|
/// </summary>
|
public List<Entity.EtaSumMultiDayRecord> 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<Entity.EtaSumMultiDayRecord>()
|
.Where(x => x.CorpID == CorpID && x.ObjectType == ObjectType && x.ObjectID == ObjectID)
|
.Where(x => x.DataDay >=StartDay.Date&&x.DataDay<=EndDay.Date)
|
.ToList();
|
}
|
}
|
|
/// <summary>
|
/// 通过对象获取日期区间内的最大流量的记录数据
|
/// </summary>
|
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<Entity.EtaSumMultiDayRecord>()
|
.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();
|
}
|
}
|
|
|
|
}
|
}
|