zhangzengfei
2023-11-28 3a706d3378aa3626501370352963883fd2783558
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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"`   //安装时间
 
    AppName         string         `gorm:"column:appName" json:"appName"`   //汇总展现到页面上,此进程无法获取app和sdks表信息
    IconBlob         string         `gorm:"column:iconBlob" json:"iconBlob"`
    Version         string         `gorm:"column:version" json:"version"`
    IsDefault         bool         `gorm:"column:isDefault" json:"isDefault"`
    Upgrade         bool         `gorm:"column:upgrade" json:"upgrade"`
}
 
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) SelectById(id string) (int64, error){
    result := db.Table(da.TableName()).Where("id=?",id).First(&da)
    if result.Error != nil || result.RowsAffected == 0 {
        return 0, err
    }
    return result.RowsAffected, nil
}
 
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) 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
}