temp
This commit is contained in:
215
internal/domains/certification/enums/actor_type.go
Normal file
215
internal/domains/certification/enums/actor_type.go
Normal file
@@ -0,0 +1,215 @@
|
||||
package enums
|
||||
|
||||
// ActorType 操作者类型枚举
|
||||
type ActorType string
|
||||
|
||||
const (
|
||||
// === 操作者类型 ===
|
||||
ActorTypeUser ActorType = "user" // 用户操作
|
||||
ActorTypeSystem ActorType = "system" // 系统操作
|
||||
ActorTypeAdmin ActorType = "admin" // 管理员操作
|
||||
ActorTypeEsign ActorType = "esign" // e签宝回调操作
|
||||
)
|
||||
|
||||
// AllActorTypes 所有操作者类型列表
|
||||
var AllActorTypes = []ActorType{
|
||||
ActorTypeUser,
|
||||
ActorTypeSystem,
|
||||
ActorTypeAdmin,
|
||||
ActorTypeEsign,
|
||||
}
|
||||
|
||||
// IsValidActorType 检查操作者类型是否有效
|
||||
func IsValidActorType(actorType ActorType) bool {
|
||||
for _, validType := range AllActorTypes {
|
||||
if actorType == validType {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetActorTypeName 获取操作者类型的中文名称
|
||||
func GetActorTypeName(actorType ActorType) string {
|
||||
typeNames := map[ActorType]string{
|
||||
ActorTypeUser: "用户",
|
||||
ActorTypeSystem: "系统",
|
||||
ActorTypeAdmin: "管理员",
|
||||
ActorTypeEsign: "e签宝",
|
||||
}
|
||||
|
||||
if name, exists := typeNames[actorType]; exists {
|
||||
return name
|
||||
}
|
||||
return string(actorType)
|
||||
}
|
||||
|
||||
// GetActorTypeDescription 获取操作者类型描述
|
||||
func GetActorTypeDescription(actorType ActorType) string {
|
||||
descriptions := map[ActorType]string{
|
||||
ActorTypeUser: "用户主动操作",
|
||||
ActorTypeSystem: "系统自动操作",
|
||||
ActorTypeAdmin: "管理员操作",
|
||||
ActorTypeEsign: "e签宝回调操作",
|
||||
}
|
||||
|
||||
if desc, exists := descriptions[actorType]; exists {
|
||||
return desc
|
||||
}
|
||||
return string(actorType)
|
||||
}
|
||||
|
||||
// IsAutomatedActor 判断是否为自动化操作者
|
||||
func IsAutomatedActor(actorType ActorType) bool {
|
||||
automatedActors := map[ActorType]bool{
|
||||
ActorTypeUser: false, // 用户手动操作
|
||||
ActorTypeSystem: true, // 系统自动操作
|
||||
ActorTypeAdmin: false, // 管理员手动操作
|
||||
ActorTypeEsign: true, // e签宝自动回调
|
||||
}
|
||||
|
||||
if automated, exists := automatedActors[actorType]; exists {
|
||||
return automated
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsHumanActor 判断是否为人工操作者
|
||||
func IsHumanActor(actorType ActorType) bool {
|
||||
return !IsAutomatedActor(actorType)
|
||||
}
|
||||
|
||||
// GetActorTypePriority 获取操作者类型优先级(用于日志排序等)
|
||||
func GetActorTypePriority(actorType ActorType) int {
|
||||
priorities := map[ActorType]int{
|
||||
ActorTypeUser: 1, // 用户操作最重要
|
||||
ActorTypeAdmin: 2, // 管理员操作次之
|
||||
ActorTypeEsign: 3, // e签宝回调
|
||||
ActorTypeSystem: 4, // 系统操作最后
|
||||
}
|
||||
|
||||
if priority, exists := priorities[actorType]; exists {
|
||||
return priority
|
||||
}
|
||||
return 999
|
||||
}
|
||||
|
||||
// GetPermissionLevel 获取权限级别
|
||||
func GetPermissionLevel(actorType ActorType) int {
|
||||
levels := map[ActorType]int{
|
||||
ActorTypeUser: 1, // 普通用户权限
|
||||
ActorTypeSystem: 2, // 系统权限
|
||||
ActorTypeEsign: 2, // e签宝权限(与系统同级)
|
||||
ActorTypeAdmin: 3, // 管理员最高权限
|
||||
}
|
||||
|
||||
if level, exists := levels[actorType]; exists {
|
||||
return level
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// CanPerformAction 检查操作者是否可以执行指定操作
|
||||
func CanPerformAction(actorType ActorType, action string) bool {
|
||||
permissions := map[ActorType][]string{
|
||||
ActorTypeUser: {
|
||||
"submit_enterprise_info", // 提交企业信息
|
||||
"apply_contract", // 申请合同
|
||||
"view_certification", // 查看认证信息
|
||||
},
|
||||
ActorTypeSystem: {
|
||||
"auto_transition", // 自动状态转换
|
||||
"system_maintenance", // 系统维护
|
||||
"data_cleanup", // 数据清理
|
||||
},
|
||||
ActorTypeAdmin: {
|
||||
"manual_transition", // 手动状态转换
|
||||
"view_all_certifications", // 查看所有认证
|
||||
"system_configuration", // 系统配置
|
||||
"user_management", // 用户管理
|
||||
},
|
||||
ActorTypeEsign: {
|
||||
"callback_notification", // 回调通知
|
||||
"status_update", // 状态更新
|
||||
"verification_result", // 验证结果
|
||||
},
|
||||
}
|
||||
|
||||
if actions, exists := permissions[actorType]; exists {
|
||||
for _, permittedAction := range actions {
|
||||
if permittedAction == action {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetAllowedActions 获取操作者允许执行的所有操作
|
||||
func GetAllowedActions(actorType ActorType) []string {
|
||||
permissions := map[ActorType][]string{
|
||||
ActorTypeUser: {
|
||||
"submit_enterprise_info",
|
||||
"apply_contract",
|
||||
"view_certification",
|
||||
},
|
||||
ActorTypeSystem: {
|
||||
"auto_transition",
|
||||
"system_maintenance",
|
||||
"data_cleanup",
|
||||
},
|
||||
ActorTypeAdmin: {
|
||||
"manual_transition",
|
||||
"view_all_certifications",
|
||||
"system_configuration",
|
||||
"user_management",
|
||||
},
|
||||
ActorTypeEsign: {
|
||||
"callback_notification",
|
||||
"status_update",
|
||||
"verification_result",
|
||||
},
|
||||
}
|
||||
|
||||
if actions, exists := permissions[actorType]; exists {
|
||||
return actions
|
||||
}
|
||||
return []string{}
|
||||
}
|
||||
|
||||
// GetActorTypeFromContext 从上下文推断操作者类型
|
||||
func GetActorTypeFromContext(context map[string]interface{}) ActorType {
|
||||
// 检查是否为e签宝回调
|
||||
if _, exists := context["esign_callback"]; exists {
|
||||
return ActorTypeEsign
|
||||
}
|
||||
|
||||
// 检查是否为管理员操作
|
||||
if isAdmin, exists := context["is_admin"]; exists && isAdmin.(bool) {
|
||||
return ActorTypeAdmin
|
||||
}
|
||||
|
||||
// 检查是否为用户操作
|
||||
if userID, exists := context["user_id"]; exists && userID != nil {
|
||||
return ActorTypeUser
|
||||
}
|
||||
|
||||
// 默认为系统操作
|
||||
return ActorTypeSystem
|
||||
}
|
||||
|
||||
// FormatActorInfo 格式化操作者信息
|
||||
func FormatActorInfo(actorType ActorType, actorID string) string {
|
||||
switch actorType {
|
||||
case ActorTypeUser:
|
||||
return "用户(" + actorID + ")"
|
||||
case ActorTypeAdmin:
|
||||
return "管理员(" + actorID + ")"
|
||||
case ActorTypeSystem:
|
||||
return "系统"
|
||||
case ActorTypeEsign:
|
||||
return "e签宝回调"
|
||||
default:
|
||||
return string(actorType) + "(" + actorID + ")"
|
||||
}
|
||||
}
|
||||
@@ -4,23 +4,50 @@ package enums
|
||||
type CertificationStatus string
|
||||
|
||||
const (
|
||||
// 主流程状态
|
||||
StatusPending CertificationStatus = "pending" // 待认证
|
||||
StatusInfoSubmitted CertificationStatus = "info_submitted" // 已提交企业信息
|
||||
StatusEnterpriseVerified CertificationStatus = "enterprise_verified" // 已企业认证
|
||||
StatusContractApplied CertificationStatus = "contract_applied" // 已申请签署合同
|
||||
StatusContractSigned CertificationStatus = "contract_signed" // 已签署合同
|
||||
StatusCompleted CertificationStatus = "completed" // 认证完成
|
||||
// === 主流程状态 ===
|
||||
StatusPending CertificationStatus = "pending" // 待认证
|
||||
StatusInfoSubmitted CertificationStatus = "info_submitted" // 已提交企业信息
|
||||
StatusEnterpriseVerified CertificationStatus = "enterprise_verified" // 已企业认证
|
||||
StatusContractApplied CertificationStatus = "contract_applied" // 已申请签署合同
|
||||
StatusContractSigned CertificationStatus = "contract_signed" // 已签署合同(认证完成)
|
||||
|
||||
// === 失败状态 ===
|
||||
StatusInfoRejected CertificationStatus = "info_rejected" // 企业信息被拒绝
|
||||
StatusContractRejected CertificationStatus = "contract_rejected" // 合同被拒签
|
||||
StatusContractExpired CertificationStatus = "contract_expired" // 合同签署超时
|
||||
)
|
||||
|
||||
// AllStatuses 所有有效状态列表
|
||||
var AllStatuses = []CertificationStatus{
|
||||
StatusPending,
|
||||
StatusInfoSubmitted,
|
||||
StatusEnterpriseVerified,
|
||||
StatusContractApplied,
|
||||
StatusContractSigned,
|
||||
StatusInfoRejected,
|
||||
StatusContractRejected,
|
||||
StatusContractExpired,
|
||||
}
|
||||
|
||||
// MainFlowStatuses 主流程状态列表
|
||||
var MainFlowStatuses = []CertificationStatus{
|
||||
StatusPending,
|
||||
StatusInfoSubmitted,
|
||||
StatusEnterpriseVerified,
|
||||
StatusContractApplied,
|
||||
StatusContractSigned,
|
||||
}
|
||||
|
||||
// FailureStatuses 失败状态列表
|
||||
var FailureStatuses = []CertificationStatus{
|
||||
StatusInfoRejected,
|
||||
StatusContractRejected,
|
||||
StatusContractExpired,
|
||||
}
|
||||
|
||||
// IsValidStatus 检查状态是否有效
|
||||
func IsValidStatus(status CertificationStatus) bool {
|
||||
validStatuses := []CertificationStatus{
|
||||
StatusPending, StatusInfoSubmitted, StatusEnterpriseVerified,
|
||||
StatusContractApplied, StatusContractSigned, StatusCompleted,
|
||||
}
|
||||
|
||||
for _, validStatus := range validStatuses {
|
||||
for _, validStatus := range AllStatuses {
|
||||
if status == validStatus {
|
||||
return true
|
||||
}
|
||||
@@ -31,12 +58,14 @@ func IsValidStatus(status CertificationStatus) bool {
|
||||
// GetStatusName 获取状态的中文名称
|
||||
func GetStatusName(status CertificationStatus) string {
|
||||
statusNames := map[CertificationStatus]string{
|
||||
StatusPending: "待认证",
|
||||
StatusInfoSubmitted: "已提交企业信息",
|
||||
StatusPending: "待认证",
|
||||
StatusInfoSubmitted: "已提交企业信息",
|
||||
StatusEnterpriseVerified: "已企业认证",
|
||||
StatusContractApplied: "已申请合同",
|
||||
StatusContractSigned: "已签署合同",
|
||||
StatusCompleted: "认证完成",
|
||||
StatusContractApplied: "已申请签署合同",
|
||||
StatusContractSigned: "认证完成",
|
||||
StatusInfoRejected: "企业信息被拒绝",
|
||||
StatusContractRejected: "合同被拒签",
|
||||
StatusContractExpired: "合同签署超时",
|
||||
}
|
||||
|
||||
if name, exists := statusNames[status]; exists {
|
||||
@@ -47,32 +76,51 @@ func GetStatusName(status CertificationStatus) string {
|
||||
|
||||
// IsFinalStatus 判断是否为最终状态
|
||||
func IsFinalStatus(status CertificationStatus) bool {
|
||||
return status == StatusCompleted
|
||||
return status == StatusContractSigned
|
||||
}
|
||||
|
||||
// IsFailureStatus 判断是否为失败状态
|
||||
func IsFailureStatus(status CertificationStatus) bool {
|
||||
for _, failureStatus := range FailureStatuses {
|
||||
if status == failureStatus {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsMainFlowStatus 判断是否为主流程状态
|
||||
func IsMainFlowStatus(status CertificationStatus) bool {
|
||||
for _, mainStatus := range MainFlowStatuses {
|
||||
if status == mainStatus {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetStatusCategory 获取状态分类
|
||||
func GetStatusCategory(status CertificationStatus) string {
|
||||
switch status {
|
||||
case StatusPending:
|
||||
return "initial"
|
||||
case StatusInfoSubmitted, StatusEnterpriseVerified, StatusContractApplied, StatusContractSigned:
|
||||
return "processing"
|
||||
case StatusCompleted:
|
||||
return "completed"
|
||||
default:
|
||||
return "unknown"
|
||||
if IsMainFlowStatus(status) {
|
||||
return "主流程"
|
||||
}
|
||||
if IsFailureStatus(status) {
|
||||
return "失败状态"
|
||||
}
|
||||
return "未知"
|
||||
}
|
||||
|
||||
// GetStatusPriority 获取状态优先级(用于排序)
|
||||
func GetStatusPriority(status CertificationStatus) int {
|
||||
priorities := map[CertificationStatus]int{
|
||||
StatusPending: 0,
|
||||
StatusInfoSubmitted: 1,
|
||||
StatusEnterpriseVerified: 2,
|
||||
StatusContractApplied: 3,
|
||||
StatusContractSigned: 4,
|
||||
StatusCompleted: 5,
|
||||
StatusPending: 1,
|
||||
StatusInfoSubmitted: 2,
|
||||
StatusEnterpriseVerified: 3,
|
||||
StatusContractApplied: 4,
|
||||
StatusContractSigned: 5,
|
||||
StatusInfoRejected: 6,
|
||||
StatusContractRejected: 7,
|
||||
StatusContractExpired: 8,
|
||||
}
|
||||
|
||||
if priority, exists := priorities[status]; exists {
|
||||
@@ -80,3 +128,131 @@ func GetStatusPriority(status CertificationStatus) int {
|
||||
}
|
||||
return 999
|
||||
}
|
||||
|
||||
// GetProgressPercentage 获取进度百分比
|
||||
func GetProgressPercentage(status CertificationStatus) int {
|
||||
progressMap := map[CertificationStatus]int{
|
||||
StatusPending: 0,
|
||||
StatusInfoSubmitted: 25,
|
||||
StatusEnterpriseVerified: 50,
|
||||
StatusContractApplied: 75,
|
||||
StatusContractSigned: 100,
|
||||
StatusInfoRejected: 25,
|
||||
StatusContractRejected: 75,
|
||||
StatusContractExpired: 75,
|
||||
}
|
||||
|
||||
if progress, exists := progressMap[status]; exists {
|
||||
return progress
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// IsUserActionRequired 检查是否需要用户操作
|
||||
func IsUserActionRequired(status CertificationStatus) bool {
|
||||
userActionRequired := map[CertificationStatus]bool{
|
||||
StatusPending: true, // 需要提交企业信息
|
||||
StatusInfoSubmitted: false, // 等待系统验证
|
||||
StatusEnterpriseVerified: true, // 需要申请合同
|
||||
StatusContractApplied: true, // 需要签署合同
|
||||
StatusContractSigned: false, // 已完成
|
||||
StatusInfoRejected: true, // 需要重新提交
|
||||
StatusContractRejected: true, // 需要重新申请
|
||||
StatusContractExpired: true, // 需要重新申请
|
||||
}
|
||||
|
||||
if required, exists := userActionRequired[status]; exists {
|
||||
return required
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetUserActionHint 获取用户操作提示
|
||||
func GetUserActionHint(status CertificationStatus) string {
|
||||
hints := map[CertificationStatus]string{
|
||||
StatusPending: "请提交企业信息",
|
||||
StatusInfoSubmitted: "系统正在验证企业信息,请稍候",
|
||||
StatusEnterpriseVerified: "企业认证完成,请申请签署合同",
|
||||
StatusContractApplied: "请在规定时间内完成合同签署",
|
||||
StatusContractSigned: "认证已完成",
|
||||
StatusInfoRejected: "企业信息验证失败,请修正后重新提交",
|
||||
StatusContractRejected: "合同签署被拒绝,可重新申请",
|
||||
StatusContractExpired: "合同签署已超时,请重新申请",
|
||||
}
|
||||
|
||||
if hint, exists := hints[status]; exists {
|
||||
return hint
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetNextValidStatuses 获取当前状态的下一个有效状态列表
|
||||
func GetNextValidStatuses(currentStatus CertificationStatus) []CertificationStatus {
|
||||
nextStatusMap := map[CertificationStatus][]CertificationStatus{
|
||||
StatusPending: {
|
||||
StatusInfoSubmitted,
|
||||
},
|
||||
StatusInfoSubmitted: {
|
||||
StatusEnterpriseVerified,
|
||||
StatusInfoRejected,
|
||||
},
|
||||
StatusEnterpriseVerified: {
|
||||
StatusContractApplied,
|
||||
},
|
||||
StatusContractApplied: {
|
||||
StatusContractSigned,
|
||||
StatusContractRejected,
|
||||
StatusContractExpired,
|
||||
},
|
||||
StatusContractSigned: {
|
||||
// 最终状态,无后续状态
|
||||
},
|
||||
StatusInfoRejected: {
|
||||
StatusInfoSubmitted, // 可以重新提交
|
||||
},
|
||||
StatusContractRejected: {
|
||||
StatusEnterpriseVerified, // 重置到企业认证状态
|
||||
},
|
||||
StatusContractExpired: {
|
||||
StatusEnterpriseVerified, // 重置到企业认证状态
|
||||
},
|
||||
}
|
||||
|
||||
if nextStatuses, exists := nextStatusMap[currentStatus]; exists {
|
||||
return nextStatuses
|
||||
}
|
||||
return []CertificationStatus{}
|
||||
}
|
||||
|
||||
// CanTransitionTo 检查是否可以从当前状态转换到目标状态
|
||||
func CanTransitionTo(currentStatus, targetStatus CertificationStatus) bool {
|
||||
validNextStatuses := GetNextValidStatuses(currentStatus)
|
||||
for _, validStatus := range validNextStatuses {
|
||||
if validStatus == targetStatus {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetTransitionReason 获取状态转换的原因描述
|
||||
func GetTransitionReason(from, to CertificationStatus) string {
|
||||
transitionReasons := map[string]string{
|
||||
string(StatusPending) + "->" + string(StatusInfoSubmitted): "用户提交企业信息",
|
||||
string(StatusInfoSubmitted) + "->" + string(StatusEnterpriseVerified): "e签宝企业认证成功",
|
||||
string(StatusInfoSubmitted) + "->" + string(StatusInfoRejected): "e签宝企业认证失败",
|
||||
string(StatusEnterpriseVerified) + "->" + string(StatusContractApplied): "用户申请签署合同",
|
||||
string(StatusContractApplied) + "->" + string(StatusContractSigned): "e签宝合同签署成功",
|
||||
string(StatusContractApplied) + "->" + string(StatusContractRejected): "用户拒绝签署合同",
|
||||
string(StatusContractApplied) + "->" + string(StatusContractExpired): "合同签署超时",
|
||||
string(StatusInfoRejected) + "->" + string(StatusInfoSubmitted): "用户重新提交企业信息",
|
||||
string(StatusContractRejected) + "->" + string(StatusEnterpriseVerified): "重置状态,准备重新申请",
|
||||
string(StatusContractExpired) + "->" + string(StatusEnterpriseVerified): "重置状态,准备重新申请",
|
||||
}
|
||||
|
||||
key := string(from) + "->" + string(to)
|
||||
if reason, exists := transitionReasons[key]; exists {
|
||||
return reason
|
||||
}
|
||||
return "未知转换"
|
||||
}
|
||||
|
||||
270
internal/domains/certification/enums/failure_reason.go
Normal file
270
internal/domains/certification/enums/failure_reason.go
Normal file
@@ -0,0 +1,270 @@
|
||||
package enums
|
||||
|
||||
// FailureReason 失败原因枚举
|
||||
type FailureReason string
|
||||
|
||||
const (
|
||||
// === 企业信息验证失败原因 ===
|
||||
FailureReasonEnterpriseNotExists FailureReason = "enterprise_not_exists" // 企业不存在
|
||||
FailureReasonEnterpriseInfoMismatch FailureReason = "enterprise_info_mismatch" // 企业信息不匹配
|
||||
FailureReasonEnterpriseStatusAbnormal FailureReason = "enterprise_status_abnormal" // 企业状态异常
|
||||
FailureReasonLegalPersonMismatch FailureReason = "legal_person_mismatch" // 法定代表人信息不匹配
|
||||
FailureReasonEsignVerificationFailed FailureReason = "esign_verification_failed" // e签宝验证失败
|
||||
FailureReasonInvalidDocument FailureReason = "invalid_document" // 证件信息无效
|
||||
|
||||
// === 合同签署失败原因 ===
|
||||
FailureReasonContractRejectedByUser FailureReason = "contract_rejected_by_user" // 用户拒绝签署
|
||||
FailureReasonContractExpired FailureReason = "contract_expired" // 合同签署超时
|
||||
FailureReasonSignProcessFailed FailureReason = "sign_process_failed" // 签署流程失败
|
||||
FailureReasonContractGenFailed FailureReason = "contract_gen_failed" // 合同生成失败
|
||||
FailureReasonEsignFlowError FailureReason = "esign_flow_error" // e签宝流程错误
|
||||
|
||||
// === 系统错误原因 ===
|
||||
FailureReasonSystemError FailureReason = "system_error" // 系统错误
|
||||
FailureReasonNetworkError FailureReason = "network_error" // 网络错误
|
||||
FailureReasonTimeout FailureReason = "timeout" // 操作超时
|
||||
FailureReasonUnknownError FailureReason = "unknown_error" // 未知错误
|
||||
)
|
||||
|
||||
// AllFailureReasons 所有失败原因列表
|
||||
var AllFailureReasons = []FailureReason{
|
||||
// 企业信息验证失败
|
||||
FailureReasonEnterpriseNotExists,
|
||||
FailureReasonEnterpriseInfoMismatch,
|
||||
FailureReasonEnterpriseStatusAbnormal,
|
||||
FailureReasonLegalPersonMismatch,
|
||||
FailureReasonEsignVerificationFailed,
|
||||
FailureReasonInvalidDocument,
|
||||
|
||||
// 合同签署失败
|
||||
FailureReasonContractRejectedByUser,
|
||||
FailureReasonContractExpired,
|
||||
FailureReasonSignProcessFailed,
|
||||
FailureReasonContractGenFailed,
|
||||
FailureReasonEsignFlowError,
|
||||
|
||||
// 系统错误
|
||||
FailureReasonSystemError,
|
||||
FailureReasonNetworkError,
|
||||
FailureReasonTimeout,
|
||||
FailureReasonUnknownError,
|
||||
}
|
||||
|
||||
// EnterpriseVerificationFailureReasons 企业验证失败原因列表
|
||||
var EnterpriseVerificationFailureReasons = []FailureReason{
|
||||
FailureReasonEnterpriseNotExists,
|
||||
FailureReasonEnterpriseInfoMismatch,
|
||||
FailureReasonEnterpriseStatusAbnormal,
|
||||
FailureReasonLegalPersonMismatch,
|
||||
FailureReasonEsignVerificationFailed,
|
||||
FailureReasonInvalidDocument,
|
||||
}
|
||||
|
||||
// ContractSignFailureReasons 合同签署失败原因列表
|
||||
var ContractSignFailureReasons = []FailureReason{
|
||||
FailureReasonContractRejectedByUser,
|
||||
FailureReasonContractExpired,
|
||||
FailureReasonSignProcessFailed,
|
||||
FailureReasonContractGenFailed,
|
||||
FailureReasonEsignFlowError,
|
||||
}
|
||||
|
||||
// SystemErrorReasons 系统错误原因列表
|
||||
var SystemErrorReasons = []FailureReason{
|
||||
FailureReasonSystemError,
|
||||
FailureReasonNetworkError,
|
||||
FailureReasonTimeout,
|
||||
FailureReasonUnknownError,
|
||||
}
|
||||
|
||||
// IsValidFailureReason 检查失败原因是否有效
|
||||
func IsValidFailureReason(reason FailureReason) bool {
|
||||
for _, validReason := range AllFailureReasons {
|
||||
if reason == validReason {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetFailureReasonName 获取失败原因的中文名称
|
||||
func GetFailureReasonName(reason FailureReason) string {
|
||||
reasonNames := map[FailureReason]string{
|
||||
// 企业信息验证失败
|
||||
FailureReasonEnterpriseNotExists: "企业不存在",
|
||||
FailureReasonEnterpriseInfoMismatch: "企业信息不匹配",
|
||||
FailureReasonEnterpriseStatusAbnormal: "企业状态异常",
|
||||
FailureReasonLegalPersonMismatch: "法定代表人信息不匹配",
|
||||
FailureReasonEsignVerificationFailed: "e签宝验证失败",
|
||||
FailureReasonInvalidDocument: "证件信息无效",
|
||||
|
||||
// 合同签署失败
|
||||
FailureReasonContractRejectedByUser: "用户拒绝签署",
|
||||
FailureReasonContractExpired: "合同签署超时",
|
||||
FailureReasonSignProcessFailed: "签署流程失败",
|
||||
FailureReasonContractGenFailed: "合同生成失败",
|
||||
FailureReasonEsignFlowError: "e签宝流程错误",
|
||||
|
||||
// 系统错误
|
||||
FailureReasonSystemError: "系统错误",
|
||||
FailureReasonNetworkError: "网络错误",
|
||||
FailureReasonTimeout: "操作超时",
|
||||
FailureReasonUnknownError: "未知错误",
|
||||
}
|
||||
|
||||
if name, exists := reasonNames[reason]; exists {
|
||||
return name
|
||||
}
|
||||
return string(reason)
|
||||
}
|
||||
|
||||
// GetFailureReasonCategory 获取失败原因分类
|
||||
func GetFailureReasonCategory(reason FailureReason) string {
|
||||
categories := map[FailureReason]string{
|
||||
// 企业信息验证失败
|
||||
FailureReasonEnterpriseNotExists: "企业验证",
|
||||
FailureReasonEnterpriseInfoMismatch: "企业验证",
|
||||
FailureReasonEnterpriseStatusAbnormal: "企业验证",
|
||||
FailureReasonLegalPersonMismatch: "企业验证",
|
||||
FailureReasonEsignVerificationFailed: "企业验证",
|
||||
FailureReasonInvalidDocument: "企业验证",
|
||||
|
||||
// 合同签署失败
|
||||
FailureReasonContractRejectedByUser: "合同签署",
|
||||
FailureReasonContractExpired: "合同签署",
|
||||
FailureReasonSignProcessFailed: "合同签署",
|
||||
FailureReasonContractGenFailed: "合同签署",
|
||||
FailureReasonEsignFlowError: "合同签署",
|
||||
|
||||
// 系统错误
|
||||
FailureReasonSystemError: "系统错误",
|
||||
FailureReasonNetworkError: "系统错误",
|
||||
FailureReasonTimeout: "系统错误",
|
||||
FailureReasonUnknownError: "系统错误",
|
||||
}
|
||||
|
||||
if category, exists := categories[reason]; exists {
|
||||
return category
|
||||
}
|
||||
return "未知"
|
||||
}
|
||||
|
||||
// IsEnterpriseVerificationFailure 判断是否为企业验证失败
|
||||
func IsEnterpriseVerificationFailure(reason FailureReason) bool {
|
||||
for _, verifyReason := range EnterpriseVerificationFailureReasons {
|
||||
if reason == verifyReason {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsContractSignFailure 判断是否为合同签署失败
|
||||
func IsContractSignFailure(reason FailureReason) bool {
|
||||
for _, signReason := range ContractSignFailureReasons {
|
||||
if reason == signReason {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsSystemError 判断是否为系统错误
|
||||
func IsSystemError(reason FailureReason) bool {
|
||||
for _, systemReason := range SystemErrorReasons {
|
||||
if reason == systemReason {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetSuggestedAction 获取建议的后续操作
|
||||
func GetSuggestedAction(reason FailureReason) string {
|
||||
actions := map[FailureReason]string{
|
||||
// 企业信息验证失败
|
||||
FailureReasonEnterpriseNotExists: "请检查企业名称和统一社会信用代码是否正确",
|
||||
FailureReasonEnterpriseInfoMismatch: "请核对企业信息是否与工商登记信息一致",
|
||||
FailureReasonEnterpriseStatusAbnormal: "请确认企业状态正常,如有疑问请联系客服",
|
||||
FailureReasonLegalPersonMismatch: "请核对法定代表人信息是否正确",
|
||||
FailureReasonEsignVerificationFailed: "请稍后重试,如持续失败请联系客服",
|
||||
FailureReasonInvalidDocument: "请检查证件信息是否有效",
|
||||
|
||||
// 合同签署失败
|
||||
FailureReasonContractRejectedByUser: "您可以重新申请签署合同",
|
||||
FailureReasonContractExpired: "请重新申请签署合同",
|
||||
FailureReasonSignProcessFailed: "请重新尝试签署,如持续失败请联系客服",
|
||||
FailureReasonContractGenFailed: "系统正在处理,请稍后重试",
|
||||
FailureReasonEsignFlowError: "请稍后重试,如持续失败请联系客服",
|
||||
|
||||
// 系统错误
|
||||
FailureReasonSystemError: "系统暂时不可用,请稍后重试",
|
||||
FailureReasonNetworkError: "网络连接异常,请检查网络后重试",
|
||||
FailureReasonTimeout: "操作超时,请重新尝试",
|
||||
FailureReasonUnknownError: "发生未知错误,请联系客服",
|
||||
}
|
||||
|
||||
if action, exists := actions[reason]; exists {
|
||||
return action
|
||||
}
|
||||
return "请联系客服处理"
|
||||
}
|
||||
|
||||
// IsRetryable 判断是否可以重试
|
||||
func IsRetryable(reason FailureReason) bool {
|
||||
retryableReasons := map[FailureReason]bool{
|
||||
// 企业信息验证失败 - 用户数据问题,可重试
|
||||
FailureReasonEnterpriseNotExists: true,
|
||||
FailureReasonEnterpriseInfoMismatch: true,
|
||||
FailureReasonEnterpriseStatusAbnormal: false, // 企业状态问题,需要外部解决
|
||||
FailureReasonLegalPersonMismatch: true,
|
||||
FailureReasonEsignVerificationFailed: true, // 可能是临时问题
|
||||
FailureReasonInvalidDocument: true,
|
||||
|
||||
// 合同签署失败
|
||||
FailureReasonContractRejectedByUser: true, // 用户可以改变主意
|
||||
FailureReasonContractExpired: true, // 可以重新申请
|
||||
FailureReasonSignProcessFailed: true, // 可能是临时问题
|
||||
FailureReasonContractGenFailed: true, // 可能是临时问题
|
||||
FailureReasonEsignFlowError: true, // 可能是临时问题
|
||||
|
||||
// 系统错误 - 大部分可重试
|
||||
FailureReasonSystemError: true,
|
||||
FailureReasonNetworkError: true,
|
||||
FailureReasonTimeout: true,
|
||||
FailureReasonUnknownError: false, // 未知错误,不建议自动重试
|
||||
}
|
||||
|
||||
if retryable, exists := retryableReasons[reason]; exists {
|
||||
return retryable
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetRetrySuggestion 获取重试建议
|
||||
func GetRetrySuggestion(reason FailureReason) string {
|
||||
if !IsRetryable(reason) {
|
||||
return "此问题不建议重试,请联系客服处理"
|
||||
}
|
||||
|
||||
suggestions := map[FailureReason]string{
|
||||
FailureReasonEnterpriseNotExists: "请修正企业信息后重新提交",
|
||||
FailureReasonEnterpriseInfoMismatch: "请核对企业信息后重新提交",
|
||||
FailureReasonLegalPersonMismatch: "请确认法定代表人信息后重新提交",
|
||||
FailureReasonEsignVerificationFailed: "请稍后重新尝试",
|
||||
FailureReasonInvalidDocument: "请检查证件信息后重新提交",
|
||||
FailureReasonContractRejectedByUser: "如需要可重新申请合同",
|
||||
FailureReasonContractExpired: "请重新申请合同签署",
|
||||
FailureReasonSignProcessFailed: "请重新尝试签署",
|
||||
FailureReasonContractGenFailed: "请稍后重新申请",
|
||||
FailureReasonEsignFlowError: "请稍后重新尝试",
|
||||
FailureReasonSystemError: "请稍后重试",
|
||||
FailureReasonNetworkError: "请检查网络连接后重试",
|
||||
FailureReasonTimeout: "请重新尝试操作",
|
||||
}
|
||||
|
||||
if suggestion, exists := suggestions[reason]; exists {
|
||||
return suggestion
|
||||
}
|
||||
return "请重新尝试操作"
|
||||
}
|
||||
Reference in New Issue
Block a user