venderDao.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package dao
  2. import (
  3. "time"
  4. )
  5. // DeviceVendor 厂家
  6. type DeviceVendor struct {
  7. ID int `gorm:"primary_key" json:"id"` //编号
  8. VendorType int `gorm:"int" json:"vendorType"` //类型:1-厂家名称,2-品牌,3-型号
  9. VendorValue string `gorm:"type:varchar(200)" json:"vendorValue"` //值
  10. ParentId int `gorm:"type:int" json:"parentId"` //父id,厂家为-1
  11. DeviceType int `gorm:"type:int" json:"deviceType"` //设备类型
  12. TenantId int `gorm:"type:int" json:"tenantId"` //租户id
  13. CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
  14. CreateUser int64 `gorm:"type:bigint" json:"createUser"` //新增记录操作用户ID
  15. UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"` //修改时间
  16. UpdateUser int64 `gorm:"type:bigint" json:"updateUser"` //修改用户
  17. IsDeleted int `gorm:"type:int" json:"isDeleted"` //是否删除 0=未删除,1=删除
  18. }
  19. func (DeviceVendor) TableName() string {
  20. return "device_vendor"
  21. }
  22. func (c *DeviceVendor) GetVendor() ([]DeviceVendor, error) {
  23. var vendors []DeviceVendor
  24. err := Db.Debug().Model(&c).Select("id, parent_id, vendor_value").
  25. Where(" vendor_type = 1 and device_type = ? and is_deleted = 0 and tenant_id = ?", c.DeviceType, c.TenantId).
  26. Find(&vendors).Error
  27. return vendors, err
  28. }
  29. func (c *DeviceVendor) GetBrand() ([]DeviceVendor, error) {
  30. var vendors []DeviceVendor
  31. err := Db.Debug().Model(&c).Select("id, parent_id, vendor_value").
  32. Where(" vendor_type = 2 and device_type = ? and is_deleted = 0 and tenant_id = ?", c.DeviceType, c.TenantId).Find(&vendors).Error
  33. return vendors, err
  34. }
  35. func (c *DeviceVendor) GetModel() ([]DeviceVendor, error) {
  36. var vendors []DeviceVendor
  37. if c.ParentId > 0 {
  38. err := Db.Debug().Model(&c).Select("id, parent_id, vendor_value").
  39. Where(" vendor_type = 3 and device_type = ? and is_deleted = 0 and tenant_id = ? and parent_id = ?",
  40. c.DeviceType, c.TenantId, c.ParentId).Find(&vendors).Error
  41. return vendors, err
  42. } else {
  43. err := Db.Debug().Model(&c).Select("id, parent_id, vendor_value").
  44. Where(" vendor_type = 3 and device_type = ? and is_deleted = 0 and tenant_id = ?", c.DeviceType, c.TenantId).Find(&vendors).Error
  45. return vendors, err
  46. }
  47. }