mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[fix]规则链添加或修改存在多条主链
This commit is contained in:
@@ -114,7 +114,8 @@ func (p *RuleChainApi) UpdateRuleRoot(rc *restfulx.ReqCtx) {
|
||||
var rule entity.RuleChain
|
||||
restfulx.BindJsonAndValid(rc, &rule)
|
||||
// 修改主链为普通链
|
||||
p.RuleChainApp.UpdateByRoot()
|
||||
err := p.RuleChainApp.UpdateByRoot()
|
||||
biz.ErrIsNil(err, "修改主链错误")
|
||||
// 修改当前链为主链
|
||||
p.RuleChainApp.Update(rule)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ type (
|
||||
Insert(data entity.RuleChain) *entity.RuleChain
|
||||
FindOne(id string) *entity.RuleChain
|
||||
FindOneByRoot() *entity.RuleChain
|
||||
UpdateByRoot()
|
||||
UpdateByRoot() error
|
||||
FindListPage(page, pageSize int, data entity.RuleChain) (*[]entity.RuleChainBase, int64)
|
||||
FindList(data entity.RuleChain) *[]entity.RuleChain
|
||||
FindListBaseLabel(data entity.RuleChain) *[]entity.RuleChainBaseLabel
|
||||
@@ -37,8 +37,18 @@ var RuleChainModelDao RuleChainModel = &ruleChainModelImpl{
|
||||
}
|
||||
|
||||
func (m *ruleChainModelImpl) Insert(data entity.RuleChain) *entity.RuleChain {
|
||||
tx := global.Db.Begin()
|
||||
// 如果新增的链为主链,那么将原来的设置为普通连
|
||||
if data.Root == "1" {
|
||||
err := m.UpdateByRoot()
|
||||
biz.ErrIsNil(err, "修改主链错误")
|
||||
}
|
||||
err := global.Db.Table(m.table).Create(&data).Error
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
biz.ErrIsNil(err, "添加规则链失败")
|
||||
tx.Commit()
|
||||
return &data
|
||||
}
|
||||
|
||||
@@ -60,8 +70,9 @@ func (m *ruleChainModelImpl) FindOneByRoot() *entity.RuleChain {
|
||||
}
|
||||
|
||||
// UpdateByRoot 修改主链为普通链
|
||||
func (m *ruleChainModelImpl) UpdateByRoot() {
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Where("root = ?", "1").Update("root", "0").Error, "修改规则链失败")
|
||||
func (m *ruleChainModelImpl) UpdateByRoot() error {
|
||||
tx := global.Db.Table(m.table).Where("root = ?", "1").Update("root", "0")
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
func (m *ruleChainModelImpl) FindListPage(page, pageSize int, data entity.RuleChain) (*[]entity.RuleChainBase, int64) {
|
||||
@@ -114,11 +125,22 @@ func (m *ruleChainModelImpl) FindListBaseLabel(data entity.RuleChain) *[]entity.
|
||||
}
|
||||
|
||||
func (m *ruleChainModelImpl) Update(data entity.RuleChain) *entity.RuleChain {
|
||||
tx := global.Db.Begin()
|
||||
// 如果新增的链为主链,那么将原来的设置为普通连
|
||||
if data.Root == "1" {
|
||||
err := m.UpdateByRoot()
|
||||
biz.ErrIsNil(err, "修改主链错误")
|
||||
}
|
||||
err := global.Db.Table(m.table).Updates(&data).Error
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
biz.ErrIsNil(err, "修改规则链失败")
|
||||
tx.Commit()
|
||||
//更改本地规则链缓存
|
||||
if data.RuleDataJson != "" {
|
||||
go global.EventEmitter.Emit(events.ProductChainRuleEvent, data.Id, data.RuleDataJson)
|
||||
}
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Updates(&data).Error, "修改规则链失败")
|
||||
return &data
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user