Browse Source

称重获取最新id

杜首举 2 years ago
parent
commit
9295ce0800
2 changed files with 31 additions and 1 deletions
  1. 1 0
      src/MWS.Data/InterFace/IWeight.cs
  2. 30 1
      src/MWS.Data/Manager/WeightManager.cs

+ 1 - 0
src/MWS.Data/InterFace/IWeight.cs

@@ -27,5 +27,6 @@ namespace MWS.Data.InterFace
         List<RecordDto> GetAllExportRecords(int entranceId, int deviceId, int teamId, DateTime? beginTime, DateTime? endTime);
         int GetAllRecordsCount(int entranceId, int deviceId, int teamId, DateTime? beginTime, DateTime? endTime);
         List<RecordDto> GetChartRecords(int entranceId, int deviceId, int teamId, DateTime? beginTime, DateTime? endTime);
+        Record GetNextOne(int id,int deviceId,int isNext);
     }
 }

+ 30 - 1
src/MWS.Data/Manager/WeightManager.cs

@@ -141,7 +141,7 @@ namespace MWS.Data.Manager
         {
 
             string insertSql = "INSERT INTO record (time,grossweight,tareweight,netweight,device,entrance,team)" +
-                "VALUES(@CreationTime,@GrossWeight,@TareWeight,@NetWeight,@device,@entrance,@team)";
+                "VALUES(@CreationTime,@GrossWeight,@TareWeight,@NetWeight,@device,@entrance,@team); select @@IDENTITY";
 
             return Execute<Record>(insertSql, new { CreationTime= t_record.CreationTime,GrossWeight = t_record.GrossWeight, TareWeight = t_record.TareWeight, NetWeight = t_record.NetWeight, device = t_record.Device, entrance = t_record.Entrance, team = t_record.Team });
         }
@@ -430,6 +430,35 @@ namespace MWS.Data.Manager
                 return weightRecordDtos;
             }
         }
+        /// <summary>
+        /// 获取当前数据前一条或后一条
+        /// </summary>
+        /// <param name="id">当前id</param>
+        /// <param name="deviceId">设备id</param>
+        /// <param name="isNext">1代表下一条,0或其他上一条</param>
+        /// <returns></returns>
+        public Record GetNextOne(int id, int deviceId, int isNext)
+        {
+            string selectSql = "SELECT * from record where 1=1 ";
+            if (deviceId > 0)
+            {
+                selectSql += " and device = " + deviceId;
+            }
+            if (isNext==1)
+            {
+                selectSql += " and id>"+id;
+                selectSql += "  order by id limit 1";
+            }
+            else
+            {
+                selectSql += " and id<" + id;
+                selectSql += "  order by id desc limit 1";
+            }
+            
+
+            var weightRecord = Query<Record>(selectSql).FindFirst();
+            return weightRecord;
+        }
     }
 }