zhangzengfei
2024-05-17 3e9a1a28b1283e40bc7edb94e2370c74e7fd68e0
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
70
71
72
73
74
75
76
77
78
79
80
81
82
package repository
 
import (
    "time"
 
    "gat1400Exchange/models"
    "gat1400Exchange/vo"
)
 
type ApeRepository struct {
}
 
func NewApeRepository() ApeRepository {
    return ApeRepository{}
}
 
func (a *ApeRepository) Keepalive(id string) error {
    var ape models.Ape
 
    // 设备存在
    if err := ape.FindById(id); err != nil {
        return nil
    }
 
    return ape.Keepalive()
}
 
func (a *ApeRepository) Create(id string) error {
    var ape models.Ape
 
    // 设备存在
    if err := ape.FindById(id); err == nil {
        return nil
    }
 
    ape.Id = id
    ape.Name = id
    ape.HeartbeatTime = time.Now().Format("2006-01-02 15:04:05")
    ape.Ext = vo.Ape{
        ApeID:            id,
        Name:             "",
        Model:            "",
        IPAddr:           "",
        IPV6Addr:         "",
        Port:             0,
        Longitude:        0,
        Latitude:         0,
        PlaceCode:        "",
        Place:            "",
        OrgCode:          "",
        CapDirection:     0,
        MonitorDirection: "",
        MonitorAreaDesc:  "",
        IsOnline:         "2",
        OwnerApsID:       "",
        UserID:           "",
        Password:         "",
        FunctionType:     "2",
    }
 
    return ape.Save()
}
 
func (a *ApeRepository) List() ([]models.Ape, error) {
    var ape models.Ape
 
    return ape.FindAll()
}
 
func (a *ApeRepository) Update(req *vo.Ape) error {
    var ape models.Ape
 
    err := ape.FindById(req.ApeID)
    if err != nil {
        return err
    }
 
    ape.Name = req.Name
    ape.Ext = *req
 
    return ape.Save()
}