using Snowflake.Core; namespace DS.Module.Core; /// /// Guid工具类 /// public class GuidHelper { /// /// 生成50位有序Guid /// /// public static string GetSequentialGuid() { string guid = Guid.NewGuid().ToString(); var timeStr = (DateTime.Now.Ticks / 10000).ToString("x8"); var newGuid = $"{timeStr.PadLeft(13, '0')}-{guid}"; return newGuid; } /// /// 由连字符分隔的32位数字 /// /// private static string GetGuid() { System.Guid guid = new Guid(); guid = Guid.NewGuid(); return guid.ToString(); } /// /// 根据GUID获取16位的唯一字符串 /// /// /// public static string GuidTo16String() { long i = 1; foreach (byte b in Guid.NewGuid().ToByteArray()) i *= ((int)b + 1); return string.Format("{0:x}", i - DateTime.Now.Ticks); } /// /// 根据GUID获取19位的唯一数字序列 /// /// public static long GuidToLongID() { byte[] buffer = Guid.NewGuid().ToByteArray(); return BitConverter.ToInt64(buffer, 0); } public static string GetSnowflakeId() { var worker = new IdWorker(1, 1); long id = worker.NextId(); return id.ToString(); } }