99
This commit is contained in:
36
Reportapi/MyCode.Project.Infrastructure/Common/IdHelper.cs
Normal file
36
Reportapi/MyCode.Project.Infrastructure/Common/IdHelper.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using MyCode.Project.Infrastructure.Cache;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user