approveflow/app/provider/flow_instance/model/approval_reversal.go

56 lines
2.1 KiB
Go
Raw Normal View History

2024-11-14 17:02:41 +08:00
package model
2024-11-19 17:03:12 +08:00
import (
"approveflow/app/base"
"encoding/json"
)
2024-11-14 17:02:41 +08:00
// ApprovalReversal 审批反转表
type ApprovalReversal struct {
2024-11-19 17:03:12 +08:00
InstanceID int64 `gorm:"type:bigint;index;not null" json:"instance_id"` // 关联的审批实例ID
StepID int64 `gorm:"type:bigint;index;not null" json:"step_id"` // 关联的步骤ID
StepKey string `gorm:"type:varchar(50);index;not null" json:"step_key"` // 关联的步骤ID
ReversedStepKey string `gorm:"type:varchar(50);index;not null" json:"reversed_step_id"` // 反转的步骤ID
FixAction string `gorm:"type:varchar(100);not null" json:"fix_action"` // 修正动作
Reason string `gorm:"type:text" json:"reason"` // 反转原因
2024-11-14 17:02:41 +08:00
base.Model
}
2024-11-19 17:03:12 +08:00
// FixAction 定义常量表示审批反转的修正动作
const (
FixActionReApproveAndUpdateData = "ReApproveAndUpdateData"
FixActionReApprove = "ReApprove" // 重新审批
FixActionReassignApprover = "ReassignApprover" // 重新指定审批人
FixActionRollback = "Rollback" // 回滚到某个步骤
FixActionUpdateData = "UpdateData" // 更新审批数据
FixActionReopen = "Reopen" // 重新打开审批流程
)
2024-11-14 17:02:41 +08:00
2024-11-19 17:03:12 +08:00
func (reversal *ApprovalReversal) MarshalBinary() ([]byte, error) {
return json.Marshal(reversal)
}
func (reversal *ApprovalReversal) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, reversal)
}
func NewReversal(step *InstanceStep, reversedStep *InstanceStep, reason string, fixAction string) *ApprovalReversal {
reversal := &ApprovalReversal{
StepID: step.ID,
StepKey: step.Key,
ReversedStepKey: reversedStep.Key,
FixAction: fixAction,
Reason: reason,
}
return reversal
2024-11-14 17:02:41 +08:00
}
// FixIssue 执行修正操作
func (reversal *ApprovalReversal) FixIssue(instance *ApprovalInstance, action, reason string) error {
reversal.InstanceID = instance.ID
reversal.FixAction = action
reversal.Reason = reason
// 根据修正动作进行修正逻辑
return nil
}