|
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/jinzhu/gorm"
|
|
)
|
|
|
|
// ServiceLst 角色表
|
|
type ServiceLst struct {
|
|
ServicePath string `gorm:"pk int 'service_path'" json:"service_path"`
|
|
// 节点路径 需要前端拼写 规则 /services/ + 输入的IP + / + 名字 比如 /services/127.0.0.1/ETL
|
|
ServiceName string `gorm:"varchar(255) 'service_name' not null" json:"service_name"` // 名字
|
|
ServiceIp string `gorm:"varchar(255) 'service_ip' not null" json:"service_ip"`// ip
|
|
State int `gorm:"int 'state' not null" json:"state"`// 状态 0未启动 1启动 2暂停
|
|
ExePath string `gorm:"varchar(255) 'exe_path' not null" json:"exe_path"` // exe路径 C:/backend/LAPP_ETL/etl.exe
|
|
Info string `gorm:"varchar(255) 'info' not null" json:"info"`// 备注
|
|
}
|
|
|
|
// TableName 获取表名
|
|
func (ServiceLst) TableName() string {
|
|
return gorm.DefaultTableNameHandler(nil, "ServiceLst")
|
|
}
|
|
|
|
// All 查询全部角色
|
|
func (m *ServiceLst) All() (list []*ServiceLst, err error) {
|
|
err = client.Table(m.TableName()).Scan(&list).Error
|
|
return
|
|
}
|
|
|
|
// Save 保存
|
|
func (m *ServiceLst) Save() (err error) {
|
|
err = client.Table(m.TableName()).Save(m).Error
|
|
return
|
|
}
|
|
|
|
// Del 删除
|
|
func (m *ServiceLst) Del(ServicePath string) (err error) {
|
|
err = client.Table(m.TableName()).Where("service_path = ?", ServicePath).Delete(m).Error
|
|
return
|
|
}
|
|
|
|
// Insert 添加
|
|
func (m *ServiceLst) Insert() (err error) {
|
|
err = client.Create(m).Error
|
|
return
|
|
}
|
|
|
|
// Update 修改
|
|
func (m *ServiceLst) Update() (err error) {
|
|
edit := make(map[string]interface{}, 0)
|
|
js, _ := json.Marshal(m)
|
|
json.Unmarshal(js, &edit)
|
|
err = client.Model(new(ServiceLst)).Where("service_path = ?", m.ServicePath).Updates(edit).Error
|
|
return
|
|
}
|
|
|
|
func (m *ServiceLst) FindById(ServicePath string) (one *ServiceLst, err error) {
|
|
one = new(ServiceLst)
|
|
err = client.Model(m).Where("service_path = ?", ServicePath).Find(one).Error
|
|
return
|
|
}
|