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() }