35 lines
817 B
C#
Raw Permalink Normal View History

2025-04-21 14:10:27 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCode.Project.Infrastructure.Common
{
public sealed class IdHelper
{
private static long NextId = 0;
private static readonly object idLock = new object();
private static int IdLastNum = Convert.ToInt32(WebConfigUtils.GetAppSettingsInfo("IdLastNum"));
public static long GetNewId()
{
lock (idLock)
{
if (NextId == 0)
{
NextId = Convert.ToInt64(DateTime.Now.ToString("yyMMddHHmmssfff"));
}
NextId = NextId + 1;
return Convert.ToInt64(NextId.ToString() + IdLastNum);
}
}
}
}