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{
|
dbr := db.Must().Clauses(clause.OnConflict{
|
||||||
DoNothing: true,
|
DoNothing: true,
|
||||||
}).Create(t)
|
}).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)
|
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
|
return nil
|
||||||
})
|
})
|
||||||
e2p(err)
|
e2p(err)
|
||||||
|
|||||||
@ -22,7 +22,7 @@ func (t *TransMsgProcessor) GenBranches() []TransBranch {
|
|||||||
for _, step := range steps {
|
for _, step := range steps {
|
||||||
branches = append(branches, TransBranch{
|
branches = append(branches, TransBranch{
|
||||||
Gid: t.Gid,
|
Gid: t.Gid,
|
||||||
Branch: fmt.Sprintf("%d", len(branches)+1),
|
Branch: common.GenGid(),
|
||||||
Data: step["data"].(string),
|
Data: step["data"].(string),
|
||||||
Url: step["action"].(string),
|
Url: step["action"].(string),
|
||||||
BranchType: "action",
|
BranchType: "action",
|
||||||
|
|||||||
@ -20,10 +20,11 @@ func (t *TransSagaProcessor) GenBranches() []TransBranch {
|
|||||||
steps := []M{}
|
steps := []M{}
|
||||||
common.MustUnmarshalString(t.Data, &steps)
|
common.MustUnmarshalString(t.Data, &steps)
|
||||||
for _, step := range steps {
|
for _, step := range steps {
|
||||||
|
branch := common.GenGid()
|
||||||
for _, branchType := range []string{"compensate", "action"} {
|
for _, branchType := range []string{"compensate", "action"} {
|
||||||
branches = append(branches, TransBranch{
|
branches = append(branches, TransBranch{
|
||||||
Gid: t.Gid,
|
Gid: t.Gid,
|
||||||
Branch: fmt.Sprintf("%d", len(branches)+1),
|
Branch: branch,
|
||||||
Data: step["data"].(string),
|
Data: step["data"].(string),
|
||||||
Url: step[branchType].(string),
|
Url: step[branchType].(string),
|
||||||
BranchType: branchType,
|
BranchType: branchType,
|
||||||
|
|||||||
@ -20,10 +20,11 @@ func (t *TransTccProcessor) GenBranches() []TransBranch {
|
|||||||
steps := []M{}
|
steps := []M{}
|
||||||
common.MustUnmarshalString(t.Data, &steps)
|
common.MustUnmarshalString(t.Data, &steps)
|
||||||
for _, step := range steps {
|
for _, step := range steps {
|
||||||
|
branch := common.GenGid()
|
||||||
for _, branchType := range []string{"cancel", "confirm", "try"} {
|
for _, branchType := range []string{"cancel", "confirm", "try"} {
|
||||||
branches = append(branches, TransBranch{
|
branches = append(branches, TransBranch{
|
||||||
Gid: t.Gid,
|
Gid: t.Gid,
|
||||||
Branch: fmt.Sprintf("%d", len(branches)+1),
|
Branch: branch,
|
||||||
Data: step["data"].(string),
|
Data: step["data"].(string),
|
||||||
Url: step[branchType].(string),
|
Url: step[branchType].(string),
|
||||||
BranchType: branchType,
|
BranchType: branchType,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user