feat: project public runs to multitable outbox
This commit is contained in:
@@ -57,7 +57,7 @@ func isProjected(resource, action string) bool {
|
|||||||
case "scenario_field":
|
case "scenario_field":
|
||||||
return action == "create" || action == "update" || action == "delete"
|
return action == "create" || action == "update" || action == "delete"
|
||||||
case "sop":
|
case "sop":
|
||||||
return action == "publish" || action == "offline"
|
return action == "publish" || action == "offline" || action == "save_graph"
|
||||||
case "scenario_rule", "knowledge_item", "knowledge_relation":
|
case "scenario_rule", "knowledge_item", "knowledge_relation":
|
||||||
return action == "create" || action == "update" || action == "delete" || action == "archive"
|
return action == "create" || action == "update" || action == "delete" || action == "archive"
|
||||||
case "sop_run":
|
case "sop_run":
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.iwork-ai.com/xdc/iqudo-top1/internal/audit"
|
||||||
|
"git.iwork-ai.com/xdc/iqudo-top1/internal/auth"
|
||||||
"git.iwork-ai.com/xdc/iqudo-top1/internal/model"
|
"git.iwork-ai.com/xdc/iqudo-top1/internal/model"
|
||||||
"git.iwork-ai.com/xdc/iqudo-top1/internal/response"
|
"git.iwork-ai.com/xdc/iqudo-top1/internal/response"
|
||||||
"git.iwork-ai.com/xdc/iqudo-top1/internal/resultcontract"
|
"git.iwork-ai.com/xdc/iqudo-top1/internal/resultcontract"
|
||||||
@@ -104,7 +106,10 @@ func (h *Handler) PublicStart(c *gin.Context) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
payload, _ := json.Marshal(gin.H{"source": "public_sdk", "mapped_field_keys": sortedKeys(normalized), "matched_rule_keys": matchedRules})
|
payload, _ := json.Marshal(gin.H{"source": "public_sdk", "mapped_field_keys": sortedKeys(normalized), "matched_rule_keys": matchedRules})
|
||||||
return tx.Create(&model.SOPRunEvent{TenantID: scenario.TenantID, RunID: run.ID, NodeKey: run.CurrentNodeKey, Action: "start", Payload: datatypes.JSON(payload)}).Error
|
if err := tx.Create(&model.SOPRunEvent{TenantID: scenario.TenantID, RunID: run.ID, NodeKey: run.CurrentNodeKey, Action: "start", Payload: datatypes.JSON(payload)}).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return audit.RecordTx(tx, auth.Principal{TenantID: scenario.TenantID, UserID: scenario.CreatedBy}, "start", "sop_run", run.ID, gin.H{"source": "public_sdk"})
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if body.ExternalRef != "" {
|
if body.ExternalRef != "" {
|
||||||
@@ -178,7 +183,13 @@ func (h *Handler) PublicSubmit(c *gin.Context) {
|
|||||||
if err := tx.Create(&model.SOPRunEvent{TenantID: run.TenantID, RunID: run.ID, NodeKey: run.CurrentNodeKey, Action: "answer", Payload: datatypes.JSON(payload)}).Error; err != nil {
|
if err := tx.Create(&model.SOPRunEvent{TenantID: run.TenantID, RunID: run.ID, NodeKey: run.CurrentNodeKey, Action: "answer", Payload: datatypes.JSON(payload)}).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return advancePublicRun(tx, &run)
|
if err := advancePublicRun(tx, &run); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if run.Status == "completed" {
|
||||||
|
return audit.RecordTx(tx, auth.Principal{TenantID: run.TenantID, UserID: run.OperatorID}, "finish", "sop_run", run.ID, gin.H{"source": "public_sdk", "result": run.Result})
|
||||||
|
}
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.respondPublicMutationError(c, err, "提交节点失败")
|
h.respondPublicMutationError(c, err, "提交节点失败")
|
||||||
@@ -275,7 +286,7 @@ func (h *Handler) PublicFinish(c *gin.Context) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
run.Status, run.Result, run.FinalResult, run.CompletedAt = "completed", body.Result, datatypes.JSON(finalRaw), completedAt
|
run.Status, run.Result, run.FinalResult, run.CompletedAt = "completed", body.Result, datatypes.JSON(finalRaw), completedAt
|
||||||
return nil
|
return audit.RecordTx(tx, auth.Principal{TenantID: run.TenantID, UserID: run.OperatorID}, "finish", "sop_run", run.ID, gin.H{"source": "public_sdk", "result": body.Result})
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.respondPublicMutationError(c, err, "结束执行失败")
|
h.respondPublicMutationError(c, err, "结束执行失败")
|
||||||
|
|||||||
Reference in New Issue
Block a user