zhangzengfei
2024-10-22 a254bc563003a9e7b3a8f1307df38b8ae4274a4f
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
package repository
 
import (
    "errors"
    "gat1400Exchange/models"
    "gat1400Exchange/vo"
)
 
type SubPlatformRepository struct {
}
 
func NewSubPlatformRepository() SubPlatformRepository {
    return SubPlatformRepository{}
}
 
func (s *SubPlatformRepository) Create(req *vo.RequestSubPlatform) error {
    var plat models.SubPlatform
 
    // 设备存在
    if err := plat.FindById(req.Id); err == nil {
        return errors.New("记录已存在")
    }
 
    plat = models.SubPlatform{
        Id:            req.Id,
        HeartbeatTime: "",
        Name:          req.Name,
        UserName:      req.UserName,
        Realm:         req.Realm,
        Password:      req.Password,
        Description:   req.Description,
        RemoteIP:      req.RemoteIP,
        RemotePort:    req.RemotePort,
    }
 
    return plat.Save()
}
 
func (s *SubPlatformRepository) Delete(id string) error {
    var plat models.SubPlatform
 
    return plat.DeleteById(id)
}
 
func (s *SubPlatformRepository) List() ([]models.SubPlatform, error) {
    var plat models.SubPlatform
 
    return plat.FindAll()
}
 
func (s *SubPlatformRepository) Update(req *vo.RequestSubPlatform) error {
    var plat models.SubPlatform
 
    err := plat.FindById(req.Id)
    if err != nil {
        return err
    }
 
    plat.Name = req.Name
    plat.UserName = req.UserName
    plat.Realm = req.Realm
    plat.Password = req.Password
    plat.Description = req.Description
    plat.RemoteIP = req.RemoteIP
    plat.RemotePort = req.RemotePort
 
    return plat.Save()
}