From 920f3164474befe4721a4365e19638ff2e2aabda Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期三, 08 五月 2024 14:58:37 +0800
Subject: [PATCH] 新增查询

---
 Yw.Service.Run.Core/04-dal/02-postgresql/RunRealRecord.cs |  104 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 104 insertions(+), 0 deletions(-)

diff --git a/Yw.Service.Run.Core/04-dal/02-postgresql/RunRealRecord.cs b/Yw.Service.Run.Core/04-dal/02-postgresql/RunRealRecord.cs
index ecd4a77..1db57a3 100644
--- a/Yw.Service.Run.Core/04-dal/02-postgresql/RunRealRecord.cs
+++ b/Yw.Service.Run.Core/04-dal/02-postgresql/RunRealRecord.cs
@@ -301,6 +301,36 @@
         }
 
         /// <summary>
+        /// 閫氳繃 ObjectType 鍜� ObjectID 鑾峰彇 (闄愬埗鏁伴噺)
+        /// </summary>
+        public List<Entity.RunRealRecord> GetLimitByObjectTypeAndObjectID(string ObjectType, long ObjectID, DateTime? StartTime, DateTime? EndTime, int Limit, bool? Run = null)
+        {
+            if (StartTime.HasValue && EndTime.HasValue)
+            {
+                if (StartTime.Value > EndTime.Value)
+                {
+                    return default;
+                }
+            }
+            var exp = Expressionable.Create<Entity.RunRealRecord>();
+            exp.AndIF(StartTime.HasValue, x => x.DataTime >= StartTime.Value);
+            exp.AndIF(EndTime.HasValue, x => x.DataTime <= EndTime.Value);
+            exp.And(x => x.ObjectType == ObjectType);
+            exp.And(x => x.ObjectID == ObjectID);
+            exp.AndIF(Run.HasValue && Run.Value, x => x.RSa == RunStatus.Run);
+            exp.AndIF(Run.HasValue && !Run.Value, x => x.RSa == RunStatus.Shut);
+
+            using (var db = new SqlSugarClient(ConnectionConfig))
+            {
+                var list = db.Queryable<Entity.RunRealRecord>()
+                    .Where(exp.ToExpression())
+                    .OrderBy(x => x.DataTime, OrderByType.Asc)
+                    .ToList();
+                return list?.ToLimitList(Limit);
+            }
+        }
+
+        /// <summary>
         /// 閫氳繃 ObjectType 鍜� ObjectID 鑾峰彇鏌愭棩鐨勬暟鎹�
         /// </summary>
         public List<Entity.RunRealRecord> GetByObjectTypeAndObjectIDOfDay(string ObjectType, long ObjectID, DateTime Day, bool? Run = null)
@@ -318,6 +348,28 @@
                     .Where(exp.ToExpression())
                     .OrderBy(x => x.DataTime, OrderByType.Asc)
                     .ToList();
+            }
+        }
+
+        /// <summary>
+        /// 閫氳繃 ObjectType 鍜� ObjectID 鑾峰彇鏌愭棩鐨勬暟鎹� (闄愬埗鏁伴噺)
+        /// </summary>
+        public List<Entity.RunRealRecord> GetLimitByObjectTypeAndObjectIDOfDay(string ObjectType, long ObjectID, DateTime Day, int Limit, bool? Run = null)
+        {
+            var exp = Expressionable.Create<Entity.RunRealRecord>();
+            exp.And(x => x.DataTime >= Day.Date && x.DataTime < Day.AddDays(1).Date);
+            exp.And(x => x.ObjectType == ObjectType);
+            exp.And(x => x.ObjectID == ObjectID);
+            exp.AndIF(Run.HasValue && Run.Value, x => x.RSa == RunStatus.Run);
+            exp.AndIF(Run.HasValue && !Run.Value, x => x.RSa == RunStatus.Shut);
+
+            using (var db = new SqlSugarClient(ConnectionConfig))
+            {
+                var list = db.Queryable<Entity.RunRealRecord>()
+                    .Where(exp.ToExpression())
+                    .OrderBy(x => x.DataTime, OrderByType.Asc)
+                    .ToList();
+                return list?.ToLimitList(Limit);
             }
         }
 
@@ -347,6 +399,32 @@
         }
 
         /// <summary>
+        /// 閫氳繃 ObjectType 鍜� ObjectID 鑾峰彇鏃ユ湡鍖洪棿鍐呯殑鏁版嵁 (闄愬埗鏁伴噺)
+        /// </summary>
+        public List<Entity.RunRealRecord> GetLimitByObjectTypeAndObjectIDOfDayRange(string ObjectType, long ObjectID, DateTime StartDay, DateTime EndDay, int Limit, bool? Run = null)
+        {
+            if (StartDay.Date > EndDay.Date)
+            {
+                return default;
+            }
+            var exp = Expressionable.Create<Entity.RunRealRecord>();
+            exp.And(x => x.DataTime >= StartDay.Date && x.DataTime < EndDay.AddDays(1).Date);
+            exp.And(x => x.ObjectType == ObjectType);
+            exp.And(x => x.ObjectID == ObjectID);
+            exp.AndIF(Run.HasValue && Run.Value, x => x.RSa == RunStatus.Run);
+            exp.AndIF(Run.HasValue && !Run.Value, x => x.RSa == RunStatus.Shut);
+
+            using (var db = new SqlSugarClient(ConnectionConfig))
+            {
+                var list = db.Queryable<Entity.RunRealRecord>()
+                    .Where(exp.ToExpression())
+                    .OrderBy(x => x.DataTime, OrderByType.Asc)
+                    .ToList();
+                return list?.ToLimitList(Limit);
+            }
+        }
+
+        /// <summary>
         /// 閫氳繃 ObjectType 鍜� ObjectID 鑾峰彇鏃堕棿鍖洪棿鍐呯殑鏁版嵁
         /// </summary>
         public List<Entity.RunRealRecord> GetByObjectTypeAndObjectIDOfTimeRange(string ObjectType, long ObjectID, DateTime StartTime, DateTime EndTime, bool? Run = null)
@@ -372,6 +450,32 @@
         }
 
         /// <summary>
+        /// 閫氳繃 ObjectType 鍜� ObjectID 鑾峰彇鏃堕棿鍖洪棿鍐呯殑鏁版嵁 (闄愬埗鏁伴噺)
+        /// </summary>
+        public List<Entity.RunRealRecord> GetLimitByObjectTypeAndObjectIDOfTimeRange(string ObjectType, long ObjectID, DateTime StartTime, DateTime EndTime, int Limit, bool? Run = null)
+        {
+            if (StartTime > EndTime)
+            {
+                return default;
+            }
+            var exp = Expressionable.Create<Entity.RunRealRecord>();
+            exp.And(x => x.DataTime >= StartTime && x.DataTime <= EndTime);
+            exp.And(x => x.ObjectType == ObjectType);
+            exp.And(x => x.ObjectID == ObjectID);
+            exp.AndIF(Run.HasValue && Run.Value, x => x.RSa == RunStatus.Run);
+            exp.AndIF(Run.HasValue && !Run.Value, x => x.RSa == RunStatus.Shut);
+
+            using (var db = new SqlSugarClient(ConnectionConfig))
+            {
+                var list = db.Queryable<Entity.RunRealRecord>()
+                    .Where(exp.ToExpression())
+                    .OrderBy(x => x.DataTime, OrderByType.Asc)
+                    .ToList();
+                return list?.ToLimitList(Limit);
+            }
+        }
+
+        /// <summary>
         /// 閫氳繃 ObjectType 鍜� ObjectID 鑾峰彇鍒嗛〉鍒楄〃
         /// </summary>
         public List<Entity.RunRealRecord> GetPageListByObjectTypeAndObjectID(string ObjectType, long ObjectID, DateTime? StartTime, DateTime? EndTime, bool? Run, int PageIndex, int PageSize, ref int Total)

--
Gitblit v1.9.3