venderDao.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 string `gorm:"type:varchar(12)" json:"tenantId"` //租户id
  13. CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
  14. CreateUser int `gorm:"type:int" json:"createUser"` //新增记录操作用户ID
  15. UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"` //修改时间
  16. UpdateUser int `gorm:"type:int" 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.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.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.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.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. }
  48. func (c DeviceVendor) GetDeviceVendors(offset, limit int) ([]DeviceVendor, int64, error) {
  49. var devices []DeviceVendor
  50. var count int64
  51. db := Db.Model(&c).Where("is_deleted=0")
  52. if c.VendorValue != "" {
  53. db.Where("vendor_value like ? ", "%"+c.VendorValue+"%")
  54. }
  55. if c.DeviceType >= 0 {
  56. db.Where("device_type=? ", c.DeviceType)
  57. }
  58. db.Count(&count)
  59. err := db.Order("id desc").Find(&devices).Error
  60. return devices, count, err
  61. }
  62. func (c DeviceVendor) Remove() error {
  63. return Db.Model(&c).Where("id=?", c.ID).Update("is_delete", 1).Error
  64. }