IdGeneratorHelper.cs 995 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using YiSha.Util;
  7. using YiSha.Util.Extension;
  8. namespace YiSha.IdGenerator
  9. {
  10. /// <summary>
  11. /// 生成数据库主键Id
  12. /// </summary>
  13. public class IdGeneratorHelper
  14. {
  15. private int SnowFlakeWorkerId = GlobalContext.SystemConfig.SnowFlakeWorkerId;
  16. private Snowflake snowflake;
  17. private static readonly IdGeneratorHelper instance = new IdGeneratorHelper();
  18. private IdGeneratorHelper()
  19. {
  20. snowflake = new Snowflake(SnowFlakeWorkerId, 0, 0);
  21. }
  22. public static IdGeneratorHelper Instance
  23. {
  24. get
  25. {
  26. return instance;
  27. }
  28. }
  29. public long GetId()
  30. {
  31. return snowflake.NextId();
  32. }
  33. public string GetGuid()
  34. {
  35. return Guid.NewGuid().ToString().Replace("-", "");
  36. }
  37. }
  38. }