12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using SqlSugar;
- using EInk.Models;
- namespace DataAcquisition
- {
- public class GuidCache
- {
- public static Queue<string> GuidQueue = new Queue<string>();
- private static int capacity = 3000;
- private static IConfigurationRoot config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
- private static ISqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
- {
- DbType = SqlSugar.DbType.PostgreSQL,
- ConnectionString = config.GetValue<string>("LocalDbConnectionString"),
- IsAutoCloseConnection = true
- });
- public static void GetGuidCache()
- {
- DateTime endtime = DateTime.Now;
- endtime = endtime.AddHours(-6);
- var QueryResult = db.Queryable<Lot2Lot3Model>().Where(x => x.create_time >= endtime).OrderBy(x => x.create_time).Select(it => it.lot_id).ToList();//返回guid字段
- if (QueryResult != null && QueryResult.Count != 0)
- {
- if (QueryResult.Count < capacity)
- {
- GuidQueue = new Queue<string>(QueryResult);
- }
- else
- {
- GuidQueue = new Queue<string>(QueryResult.GetRange(QueryResult.Count - capacity, capacity));
- }
- }
- }
- public static bool ContainVerification(string guid)
- {
- if (GuidQueue.Contains(guid))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public static void Add(string guid)
- {
- if (GuidQueue.Count() >= capacity)
- {
- int i = GuidQueue.Count() - capacity + 1;
- for (; i > 0; i--)
- {
- GuidQueue.Dequeue();
- }
- }
- GuidQueue.Enqueue(guid);
- }
- }
- }
|