You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

uIdGeneratorOptions.pas 3.3 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. unit uIdGeneratorOptions;
  2. interface
  3. uses
  4. System.DateUtils, System.SysUtils;
  5. type
  6. TIdGeneratorOptions = class
  7. private
  8. FMethod: SmallInt;
  9. // FBaseTime: TDateTime;
  10. FBaseTime: Int64;
  11. FWorkerId: Word;
  12. FWorkerIdBitLength: Byte;
  13. FSeqBitLength: Byte;
  14. FMaxSeqNumber: Integer;
  15. FMinSeqNumber: Word;
  16. FTopOverCostCount: Integer;
  17. FDataCenterId: Cardinal;
  18. FDataCenterIdBitLength: Byte;
  19. FTimestampType: Byte;
  20. public
  21. /// <summary>
  22. /// ѩ㷽
  23. /// 1-Ư㷨|2-ͳ㷨Ĭ1
  24. /// </summary>
  25. property Method: SmallInt read FMethod write FMethod default 1;
  26. /// <summary>
  27. /// ʱ䣨UTCʽ
  28. /// ܳǰϵͳʱ
  29. /// </summary>
  30. // property BaseTime: TDateTime read FBaseTime write FBaseTime;
  31. property BaseTime: Int64 read FBaseTime write FBaseTime;
  32. /// <summary>
  33. ///
  34. /// ⲿ趨ֵ 2^WorkerIdBitLength-1
  35. /// </summary>
  36. property WorkerId: Word read FWorkerId write FWorkerId default 0;
  37. /// <summary>
  38. /// λ
  39. /// Ĭֵ6ȡֵΧ [1, 15]Ҫλ+λ22
  40. /// </summary>
  41. property WorkerIdBitLength: Byte read FWorkerIdBitLength write FWorkerIdBitLength default 6; // 10;
  42. /// <summary>
  43. /// λ
  44. /// Ĭֵ6ȡֵΧ [3, 21]Ҫλ+λ22
  45. /// </summary>
  46. property SeqBitLength: Byte read FSeqBitLength write FSeqBitLength default 6; // 10;
  47. /// <summary>
  48. ///
  49. /// ÷Χ [MinSeqNumber, 2^SeqBitLength-1]Ĭֵ0ʾȡֵ2^SeqBitLength-1]
  50. /// </summary>
  51. property MaxSeqNumber: Integer read FMaxSeqNumber write FMaxSeqNumber default 0;
  52. /// <summary>
  53. /// С
  54. /// Ĭֵ5ȡֵΧ [5, MaxSeqNumber]ÿǰ5Ӧ0-4DZλ1-4ʱزӦԤλ0ֵֹԤλ
  55. /// </summary>
  56. property MinSeqNumber: Word read FMinSeqNumber write FMinSeqNumber default 5;
  57. /// <summary>
  58. /// Ưƴ
  59. /// Ĭ2000ƼΧ500-10000йأ
  60. /// </summary>
  61. property TopOverCostCount: Integer read FTopOverCostCount write FTopOverCostCount default 2000;
  62. /// <summary>
  63. /// IDĬ0
  64. /// </summary>
  65. property DataCenterId: Cardinal read FDataCenterId write FDataCenterId default 0;
  66. /// <summary>
  67. /// IDȣĬ0
  68. /// </summary>
  69. property DataCenterIdBitLength: Byte read FDataCenterIdBitLength write FDataCenterIdBitLength default 0;
  70. /// <summary>
  71. /// ʱͣ0-룬1-룩Ĭ0
  72. /// </summary>
  73. property TimestampType: Byte read FTimestampType write FTimestampType default 0;
  74. constructor Create(); overload;
  75. constructor Create(WorkerId: Word); overload;
  76. end;
  77. implementation
  78. { TIdGeneratorOptions }
  79. constructor TIdGeneratorOptions.Create(WorkerId: Word);
  80. begin
  81. FBaseTime := 1582136402000; // EncodeDateTime(2020, 2, 20, 2, 20, 2, 20);
  82. FWorkerId := WorkerId;
  83. end;
  84. constructor TIdGeneratorOptions.Create();
  85. begin
  86. FBaseTime := 1582136402000; // EncodeDateTime(2020, 2, 20, 2, 20, 2, 20);
  87. end;
  88. end.