bugfix: same stra in nid
This commit is contained in:
parent
72ec59bdac
commit
f590194fba
|
@ -192,6 +192,20 @@ func StraGet(col string, val interface{}) (*Stra, error) {
|
|||
return &obj, nil
|
||||
}
|
||||
|
||||
func StraFindOne(where string, args ...interface{}) (*Stra, error) {
|
||||
var obj Stra
|
||||
has, err := DB["mon"].Where(where, args...).Get(&obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !has {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return &obj, nil
|
||||
}
|
||||
|
||||
func StraDel(id int64) error {
|
||||
session := DB["mon"].NewSession()
|
||||
defer session.Close()
|
||||
|
|
|
@ -24,8 +24,10 @@ func straPost(c *gin.Context) {
|
|||
|
||||
errors.Dangerous(stra.Encode())
|
||||
|
||||
oldStra, _ := models.StraGet("name", stra.Name)
|
||||
if oldStra != nil && oldStra.Nid == stra.Nid {
|
||||
old, err := models.StraFindOne("nid=? and name=?", stra.Nid, stra.Name)
|
||||
dangerous(err)
|
||||
|
||||
if old != nil {
|
||||
bomb("同节点下策略名称 %s 已存在", stra.Name)
|
||||
}
|
||||
|
||||
|
@ -54,8 +56,10 @@ func straPut(c *gin.Context) {
|
|||
stra.LastUpdator = username
|
||||
errors.Dangerous(stra.Encode())
|
||||
|
||||
oldStra, _ := models.StraGet("name", stra.Name)
|
||||
if oldStra != nil && oldStra.Id != stra.Id && oldStra.Nid == stra.Nid {
|
||||
old, err := models.StraFindOne("nid=? and name=? and id <> ?", stra.Nid, stra.Name, stra.Id)
|
||||
dangerous(err)
|
||||
|
||||
if old != nil {
|
||||
bomb("同节点下策略名称 %s 已存在", stra.Name)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue