| | |
| | | package models |
| | | |
| | | type DeviceApp struct { |
| | | Id string `gorm:"column:id;primary_key;type:varchar(50);unique;not null;" json:"id"` |
| | | DevId string `gorm:"column:devId" json:"devId"` |
| | | MachineCode string `gorm:"column:machineCode" json:"machineCode"` |
| | | ActivateCode string `gorm:"column:activateCode" json:"activateCode"` |
| | | AppId string `gorm:"column:appId" json:"appId"` |
| | | ExpireTime string `gorm:"column:expireTime" json:"expireTime"` //激活时间 |
| | | InstallTime string `gorm:"column:installTime" json:"installTime"` //安装时间 |
| | | } |
| | | |
| | | func (DeviceApp) TableName() string { |
| | | return "t_device_app" |
| | | } |
| | | |
| | | func (da *DeviceApp) Insert() bool { |
| | | result := db.Table(da.TableName()).Create(&da) |
| | | if result.Error == nil && result.RowsAffected > 0 { |
| | | return true |
| | | } |
| | | return false |
| | | } |
| | | |
| | | func (da *DeviceApp) Update() bool { |
| | | result := db.Table(da.TableName()).Where("id=?", da.Id).Update(&da) |
| | | if result.Error ==nil && result.RowsAffected > 0 { |
| | | return true |
| | | } |
| | | return false |
| | | } |
| | | |
| | | func (da *DeviceApp) Exist(devId string, appId string) (int64, error) { |
| | | result := db.Table(da.TableName()).Where("devId=? and appId=?", devId, appId).First(&da) |
| | | return result.RowsAffected, result.Error |
| | | } |
| | | |
| | | func (da *DeviceApp) DeleteById(id string) bool { |
| | | result := db.Exec("delete from "+da.TableName()+" where id='"+id+"'") |
| | | if result.Error == nil && result.RowsAffected > 0 { |
| | | return true |
| | | } |
| | | return false |
| | | } |
| | | |
| | | func (da *DeviceApp) FindByActivateCode(activateCode string) (list []DeviceApp, err error) { |
| | | result := db.Table(da.TableName()).Where("activateCode=?", activateCode).Find(&list) |
| | | if result.Error != nil { |
| | | return []DeviceApp{},result.Error |
| | | } |
| | | return list, nil |
| | | } |
| | | |
| | | func (da *DeviceApp) FindByMachineCode(machineCode string, serverId string) (list []DeviceApp, err error) { |
| | | result := db.Table(da.TableName()).Where("machineCode=? or devId=?", machineCode, serverId).Order("installTime desc").Find(&list) |
| | | if result.Error != nil { |
| | | return []DeviceApp{},result.Error |
| | | } |
| | | return list, nil |
| | | } |
| | | |
| | | func (da *DeviceApp) FindAll() (list []DeviceApp) { |
| | | if err := db.Table(da.TableName()).Scan(&list).Error; err != nil { |
| | | return []DeviceApp{} |
| | | } |
| | | return |
| | | package models
|
| | |
|
| | | type DeviceApp struct {
|
| | | Id string `gorm:"column:id;primary_key;type:varchar(50);unique;not null;" json:"id"`
|
| | | DevId string `gorm:"column:devId" json:"devId"`
|
| | | MachineCode string `gorm:"column:machineCode" json:"machineCode"`
|
| | | ActivateCode string `gorm:"column:activateCode" json:"activateCode"`
|
| | | AppId string `gorm:"column:appId" json:"appId"`
|
| | | ExpireTime string `gorm:"column:expireTime" json:"expireTime"` //激活时间
|
| | | InstallTime string `gorm:"column:installTime" json:"installTime"` //安装时间
|
| | | }
|
| | |
|
| | | func (DeviceApp) TableName() string {
|
| | | return "t_device_app"
|
| | | }
|
| | |
|
| | | func (da *DeviceApp) Insert() bool {
|
| | | result := db.Table(da.TableName()).Create(&da)
|
| | | if result.Error == nil && result.RowsAffected > 0 {
|
| | | return true
|
| | | }
|
| | | return false
|
| | | }
|
| | |
|
| | | func (da *DeviceApp) Update() bool {
|
| | | result := db.Table(da.TableName()).Where("id=?", da.Id).Update(&da)
|
| | | if result.Error ==nil && result.RowsAffected > 0 {
|
| | | return true
|
| | | }
|
| | | return false
|
| | | }
|
| | |
|
| | | func (da *DeviceApp) Exist(devId string, appId string) (int64, error) {
|
| | | result := db.Table(da.TableName()).Where("devId=? and appId=?", devId, appId).First(&da)
|
| | | return result.RowsAffected, result.Error
|
| | | }
|
| | |
|
| | | func (da *DeviceApp) DeleteById(id string) bool {
|
| | | result := db.Exec("delete from "+da.TableName()+" where id='"+id+"'")
|
| | | if result.Error == nil && result.RowsAffected > 0 {
|
| | | return true
|
| | | }
|
| | | return false
|
| | | }
|
| | |
|
| | | func (da *DeviceApp) FindByActivateCode(activateCode string) (list []DeviceApp, err error) {
|
| | | result := db.Table(da.TableName()).Where("activateCode=?", activateCode).Find(&list)
|
| | | if result.Error != nil {
|
| | | return []DeviceApp{},result.Error
|
| | | }
|
| | | return list, nil
|
| | | }
|
| | |
|
| | | func (da *DeviceApp) FindByMachineCode(machineCode string, serverId string) (list []DeviceApp, err error) {
|
| | | result := db.Table(da.TableName()).Where("machineCode=? or devId=?", machineCode, serverId).Order("installTime desc").Find(&list)
|
| | | if result.Error != nil {
|
| | | return []DeviceApp{},result.Error
|
| | | }
|
| | | return list, nil
|
| | | }
|
| | |
|
| | | func (da *DeviceApp) FindAll() (list []DeviceApp) {
|
| | | if err := db.Table(da.TableName()).Scan(&list).Error; err != nil {
|
| | | return []DeviceApp{}
|
| | | }
|
| | | return
|
| | | } |