change branch gen
This commit is contained in:
parent
e41c576cbb
commit
f9aeb49107
@ -154,20 +154,17 @@ func (t *TransGlobal) SaveNew(db *common.DB) {
|
||||
dbr := db.Must().Clauses(clause.OnConflict{
|
||||
DoNothing: true,
|
||||
}).Create(t)
|
||||
if dbr.RowsAffected == 0 && t.Status == "committed" { // 如果数据库已经存放了prepared的事务,则修改状态
|
||||
if dbr.RowsAffected > 0 { // 如果这个是新事务,保存所有的分支
|
||||
branches := t.getProcessor().GenBranches()
|
||||
if len(branches) > 0 {
|
||||
writeTransLog(t.Gid, "save branches", t.Status, "", common.MustMarshalString(branches))
|
||||
db.Must().Clauses(clause.OnConflict{
|
||||
DoNothing: true,
|
||||
}).Create(&branches)
|
||||
}
|
||||
} else if dbr.RowsAffected == 0 && t.Status == "committed" { // 如果数据库已经存放了prepared的事务,则修改状态
|
||||
dbr = db.Must().Model(t).Where("gid=? and status=?", t.Gid, "prepared").Select(append(updates, "status")).Updates(t)
|
||||
}
|
||||
if dbr.RowsAffected == 0 { // 未保存任何数据,直接返回
|
||||
return nil
|
||||
}
|
||||
// 保存所有的分支
|
||||
branches := t.getProcessor().GenBranches()
|
||||
if len(branches) > 0 {
|
||||
writeTransLog(t.Gid, "save branches", t.Status, "", common.MustMarshalString(branches))
|
||||
db.Must().Clauses(clause.OnConflict{
|
||||
DoNothing: true,
|
||||
}).Create(&branches)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
e2p(err)
|
||||
|
||||
@ -22,7 +22,7 @@ func (t *TransMsgProcessor) GenBranches() []TransBranch {
|
||||
for _, step := range steps {
|
||||
branches = append(branches, TransBranch{
|
||||
Gid: t.Gid,
|
||||
Branch: fmt.Sprintf("%d", len(branches)+1),
|
||||
Branch: common.GenGid(),
|
||||
Data: step["data"].(string),
|
||||
Url: step["action"].(string),
|
||||
BranchType: "action",
|
||||
|
||||
@ -20,10 +20,11 @@ func (t *TransSagaProcessor) GenBranches() []TransBranch {
|
||||
steps := []M{}
|
||||
common.MustUnmarshalString(t.Data, &steps)
|
||||
for _, step := range steps {
|
||||
branch := common.GenGid()
|
||||
for _, branchType := range []string{"compensate", "action"} {
|
||||
branches = append(branches, TransBranch{
|
||||
Gid: t.Gid,
|
||||
Branch: fmt.Sprintf("%d", len(branches)+1),
|
||||
Branch: branch,
|
||||
Data: step["data"].(string),
|
||||
Url: step[branchType].(string),
|
||||
BranchType: branchType,
|
||||
|
||||
@ -20,10 +20,11 @@ func (t *TransTccProcessor) GenBranches() []TransBranch {
|
||||
steps := []M{}
|
||||
common.MustUnmarshalString(t.Data, &steps)
|
||||
for _, step := range steps {
|
||||
branch := common.GenGid()
|
||||
for _, branchType := range []string{"cancel", "confirm", "try"} {
|
||||
branches = append(branches, TransBranch{
|
||||
Gid: t.Gid,
|
||||
Branch: fmt.Sprintf("%d", len(branches)+1),
|
||||
Branch: branch,
|
||||
Data: step["data"].(string),
|
||||
Url: step[branchType].(string),
|
||||
BranchType: branchType,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user