tenant.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package dao
  2. import "time"
  3. // 租户
  4. type Tenant struct {
  5. ID int64 `gorm:"primary_key" json:"id"` //编号
  6. TenantId string `gorm:"type:varchar(12);default '000000'" 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.Model(&c).Where("id = ? and is_deleted = 0", c.ID).Find(&c).Error
  39. }
  40. func (c *Tenant) GetTenant() error {
  41. return Db.Model(&c).Where("tenant_id = ? and is_deleted = 0", c.TenantId).Find(&c).Error
  42. }
  43. func (c *Tenant) GetTenantByPasskey() error {
  44. return Db.Model(&c).Where("pass_key = ? and is_deleted = 0", c.PassKey).Find(&c).Error
  45. }
  46. func (c *Tenant) IsExist() bool {
  47. var count int
  48. _ = Db.Model(&c).Where("pass_key = ? and is_deleted = 0", c.PassKey).Count(&c).Error
  49. return count > 0
  50. }
  51. func (c *Tenant) GetTenants(offset, limit int) ([]Tenant, error) {
  52. var tenants []Tenant
  53. db := Db.Model(&c)
  54. if c.TenantId != "" {
  55. db = db.Where("tenant_id like ?", "%"+c.TenantId+"%")
  56. }
  57. if c.TenantName != "" {
  58. db = db.Where("tenant_name like ?", "%"+c.TenantName+"%")
  59. }
  60. if c.Linkman != "" {
  61. db = db.Where("linkman like ?", "%"+c.Linkman+"%")
  62. }
  63. err := db.Where("is_deleted = 0").Offset(offset).Limit(limit).Find(&tenants).Error
  64. return tenants, err
  65. }
  66. func (c *Tenant) Save() error {
  67. return Db.Model(&c).Save(&c).Error
  68. }
  69. func (c *Tenant) Update() error {
  70. return Db.Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
  71. }
  72. func (c *Tenant) GetAll() ([]Tenant, error) {
  73. var tenants []Tenant
  74. err := Db.Model(&c).Where("is_deleted = 0").Find(&tenants).Error
  75. return tenants, err
  76. }
  77. func (c *Tenant) Remove() error {
  78. return Db.Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.
  79. UpdateTime,
  80. "update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
  81. }