BaseModel.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using SqlSugar;
  2. using SqlSugar.DistributedSystem.Snowflake;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace Wms.Screen.SqlSugar
  10. {
  11. public class BaseEntityModel
  12. {
  13. }
  14. public class BaseModel: BaseEntityModel
  15. {
  16. public BaseModel() { }
  17. [SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
  18. public virtual long Id { get; set; } = IdFactory.NewId();
  19. [SugarColumn(ColumnName = "Memo", Length = 500, IsNullable = true, ColumnDataType = "nvarchar", DefaultValue = "")]
  20. public virtual string Memo { get; set; }
  21. [SugarColumn(ColumnName = "AddWho", Length = 50, ColumnDataType = "nvarchar", DefaultValue = "", IsNullable = false)]
  22. public virtual string AddWho { get; set; } = "";
  23. [SugarColumn(ColumnName = "EditWho", Length = 50, ColumnDataType = "nvarchar", DefaultValue = "", IsNullable = false)]
  24. public virtual string EditWho { get; set; } = "";
  25. [SugarColumn(ColumnName = "AddTime", DefaultValue = "1900-1-1", IsNullable = false)]
  26. public virtual DateTime AddTime { get; set; } = DateTime.Now;
  27. [SugarColumn(ColumnName = "EditTime", DefaultValue = "1900-1-1", IsNullable = false)]
  28. public virtual DateTime EditTime { get; set; } = DateTime.Now;
  29. }
  30. public static class IdFactory
  31. {
  32. private static readonly object locker = new object();
  33. private static IdWorker _idworker;
  34. public static IdWorker GetInstance()
  35. {
  36. if (_idworker == null)
  37. {
  38. lock (locker)
  39. {
  40. if (_idworker == null)
  41. {
  42. _idworker = new IdWorker(1, 1);
  43. }
  44. }
  45. }
  46. return _idworker;
  47. }
  48. public static long NewId()
  49. {
  50. return GetInstance().NextId();
  51. }
  52. }
  53. }