tenant.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package dao
  2. import "time"
  3. // 租户
  4. type Tenant struct {
  5. ID int64 `gorm:"primary_key" json:"id"` //编号
  6. TenantId int `gorm:"type:int" json:"tenantId"` //租户ID
  7. TenantName string `gorm:"type:varchar(50)" json:"tenantName"` //租户名称
  8. Domain string `gorm:"type:varchar(255)" json:"domain"` //域名地址
  9. BackgroundUrl string `gorm:"type:varchar(1000)" json:"backgroundUrl"` //系统背景
  10. SysLogoUrl string `gorm:"type:varchar(1000)" json:"sysLogoUrl"` //logo图表
  11. Linkman string `gorm:"type:varchar(20)" json:"linkman"` //联系人
  12. ContactNumber string `gorm:"type:varchar(20)" json:"contactNumber"` //联系电话
  13. Address string `gorm:"type:varchar(255)" json:"address"` //联系地址
  14. AccountNumber int `gorm:"type:int;default -1" json:"accountNumber"` //邮箱
  15. ExpireTime time.Time `gorm:"type:datetime" json:"expireTime"` //过期时间
  16. DatasourceId int64 `gorm:"type:bigint" json:"datasourceId"` //数据源
  17. LicenseKey string `gorm:"type:varchar(1000)" json:"licenseKey"` //授权码
  18. BigScreenName string `gorm:"type:varchar(60)" json:"bigScreenName"` //大屏端显示名称
  19. CreateUser int64 `gorm:"type:bigint" json:"createUser"` //创建人
  20. CreateDept int64 `gorm:"type:bigint" json:"createDept"` //创建部门
  21. CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
  22. UpdateUser int64 `gorm:"type:bigint" json:"updateUser"` //修改人
  23. UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"` //修改时间
  24. Status int `gorm:"type:int " json:"status"` //状态
  25. IsDeleted int `gorm:"type:int" json:"isDeleted"` //是否删除 0=未删除,1=删除
  26. PassKey string `gorm:"type:varchar(10)" json:"passKey"` //租户登录Key
  27. LoginDisplayName string `gorm:"type:varchar(60)" json:"loginDisplayName"` //登录页面显示名称
  28. ContactEmail string `gorm:"type:varchar(255)" json:"contactEmail"` //联系邮箱
  29. CityCode string `gorm:"type:varchar(6)" json:"cityCode"` //城市行政编码
  30. CityName string `gorm:"type:varchar(255)" json:"cityName"` //城市名称
  31. CityLng float64 `gorm:"type:double(18, 14)" json:"cityLng"` //经度
  32. CityLat float64 `gorm:"type:double(18, 14)" json:"cityLat"` //经度
  33. }
  34. func (Tenant) TableName() string {
  35. return "tenant"
  36. }
  37. func (c *Tenant) Get() error {
  38. return Db.Debug().Model(&c).Where("id = ? and is_deleted = 0", c.ID).Find(&c).Error
  39. }
  40. func (c *Tenant) GetByDomain() error {
  41. return Db.Debug().Model(&c).Where("domain = ? and is_deleted = 0", c.Domain).Find(&c).Error
  42. }
  43. func (c *Tenant) GetTenant() error {
  44. return Db.Debug().Model(&c).Where("tenant_id = ? and is_deleted = 0", c.TenantId).Find(&c).Error
  45. }
  46. func (c *Tenant) GetTenantByPasskey() error {
  47. return Db.Debug().Model(&c).Where("pass_key = ? and is_deleted = 0", c.PassKey).Find(&c).Error
  48. }
  49. func (c *Tenant) IsExist() bool {
  50. var count int
  51. _ = Db.Debug().Model(&c).Where("pass_key = ? and is_deleted = 0", c.PassKey).Count(&c).Error
  52. return count > 0
  53. }
  54. func (c *Tenant) GetTenants(offset, limit int) ([]Tenant, error) {
  55. var tenants []Tenant
  56. db := Db.Debug().Model(&c)
  57. if c.TenantId > 0 {
  58. db = db.Where("tenant_id = ?", c.TenantId)
  59. }
  60. if c.TenantName != "" {
  61. db = db.Where("tenant_name like ?", "%"+c.TenantName+"%")
  62. }
  63. if c.Linkman != "" {
  64. db = db.Where("linkman like ?", "%"+c.Linkman+"%")
  65. }
  66. err := db.Where("is_deleted = 0").Offset(offset).Limit(limit).Find(&tenants).Error
  67. return tenants, err
  68. }
  69. func (c *Tenant) Save() error {
  70. return Db.Debug().Model(&c).Save(&c).Error
  71. }
  72. func (c *Tenant) Update() error {
  73. return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
  74. }
  75. func (c *Tenant) GetAll() ([]Tenant, error) {
  76. var tenants []Tenant
  77. err := Db.Debug().Model(&c).Where("is_deleted = 0").Find(&tenants).Error
  78. return tenants, err
  79. }
  80. func (c *Tenant) Remove() error {
  81. return Db.Debug().Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.
  82. UpdateTime, "update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
  83. }