123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package dao
- import (
- "time"
- )
- type DeviceVendor struct {
- ID int `gorm:"primary_key" json:"id"`
- VendorType int `gorm:"int" json:"vendorType"`
- VendorValue string `gorm:"type:varchar(200)" json:"vendorValue"`
- ParentId int `gorm:"type:int" json:"parentId"`
- DeviceType int `gorm:"type:int" json:"deviceType"`
- TenantId int `gorm:"type:int" json:"tenantId"`
- CreateTime time.Time `gorm:"type:datetime" json:"createTime"`
- CreateUser int64 `gorm:"type:bigint" json:"createUser"`
- UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"`
- UpdateUser int64 `gorm:"type:bigint" json:"updateUser"`
- IsDeleted int `gorm:"type:int" json:"isDeleted"`
- }
- func (DeviceVendor) TableName() string {
- return "device_vendor"
- }
- func (c *DeviceVendor) GetVendor() ([]DeviceVendor, error) {
- var vendors []DeviceVendor
- err := Db.Debug().Model(&c).Select("id, parent_id, vendor_value").
- Where(" vendor_type = 1 and device_type = ? and is_deleted = 0 and tenant_id = ?", c.DeviceType, c.TenantId).
- Find(&vendors).Error
- return vendors, err
- }
- func (c *DeviceVendor) GetBrand() ([]DeviceVendor, error) {
- var vendors []DeviceVendor
- err := Db.Debug().Model(&c).Select("id, parent_id, vendor_value").
- Where(" vendor_type = 2 and device_type = ? and is_deleted = 0 and tenant_id = ?", c.DeviceType, c.TenantId).Find(&vendors).Error
- return vendors, err
- }
- func (c *DeviceVendor) GetModel() ([]DeviceVendor, error) {
- var vendors []DeviceVendor
- if c.ParentId > 0 {
- err := Db.Debug().Model(&c).Select("id, parent_id, vendor_value").
- Where(" vendor_type = 3 and device_type = ? and is_deleted = 0 and tenant_id = ? and parent_id = ?",
- c.DeviceType, c.TenantId, c.ParentId).Find(&vendors).Error
- return vendors, err
- } else {
- err := Db.Debug().Model(&c).Select("id, parent_id, vendor_value").
- Where(" vendor_type = 3 and device_type = ? and is_deleted = 0 and tenant_id = ?", c.DeviceType, c.TenantId).Find(&vendors).Error
- return vendors, err
- }
- }
|