310 lines
11 KiB
Go
310 lines
11 KiB
Go
package enums
|
||
|
||
// CertificationStatus 认证状态枚举
|
||
type CertificationStatus string
|
||
|
||
const (
|
||
// === 主流程状态 ===
|
||
StatusPending CertificationStatus = "pending" // 待认证
|
||
StatusInfoPendingReview CertificationStatus = "info_pending_review" // 企业信息待人工审核
|
||
StatusInfoSubmitted CertificationStatus = "info_submitted" // 已提交企业信息(审核通过)
|
||
StatusEnterpriseVerified CertificationStatus = "enterprise_verified" // 已企业认证
|
||
StatusContractApplied CertificationStatus = "contract_applied" // 已申请签署合同
|
||
StatusContractSigned CertificationStatus = "contract_signed" // 已签署合同
|
||
StatusCompleted CertificationStatus = "completed" // 认证完成
|
||
|
||
// === 失败状态 ===
|
||
StatusInfoRejected CertificationStatus = "info_rejected" // 企业信息被拒绝
|
||
StatusContractRejected CertificationStatus = "contract_rejected" // 合同被拒签
|
||
StatusContractExpired CertificationStatus = "contract_expired" // 合同签署超时
|
||
)
|
||
|
||
// AllStatuses 所有有效状态列表
|
||
var AllStatuses = []CertificationStatus{
|
||
StatusPending,
|
||
StatusInfoPendingReview,
|
||
StatusInfoSubmitted,
|
||
StatusEnterpriseVerified,
|
||
StatusContractApplied,
|
||
StatusContractSigned,
|
||
StatusCompleted,
|
||
StatusInfoRejected,
|
||
StatusContractRejected,
|
||
StatusContractExpired,
|
||
}
|
||
|
||
// MainFlowStatuses 主流程状态列表
|
||
var MainFlowStatuses = []CertificationStatus{
|
||
StatusPending,
|
||
StatusInfoPendingReview,
|
||
StatusInfoSubmitted,
|
||
StatusEnterpriseVerified,
|
||
StatusContractApplied,
|
||
StatusContractSigned,
|
||
}
|
||
|
||
// FailureStatuses 失败状态列表
|
||
var FailureStatuses = []CertificationStatus{
|
||
StatusInfoRejected,
|
||
StatusContractRejected,
|
||
StatusContractExpired,
|
||
}
|
||
|
||
// IsValidStatus 检查状态是否有效
|
||
func IsValidStatus(status CertificationStatus) bool {
|
||
for _, validStatus := range AllStatuses {
|
||
if status == validStatus {
|
||
return true
|
||
}
|
||
}
|
||
return false
|
||
}
|
||
|
||
// GetStatusName 获取状态的中文名称
|
||
func GetStatusName(status CertificationStatus) string {
|
||
statusNames := map[CertificationStatus]string{
|
||
StatusPending: "待认证",
|
||
StatusInfoPendingReview: "企业信息待审核",
|
||
StatusInfoSubmitted: "已提交企业信息",
|
||
StatusEnterpriseVerified: "已企业认证",
|
||
StatusContractApplied: "已申请签署合同",
|
||
StatusContractSigned: "已签署合同",
|
||
StatusCompleted: "认证完成",
|
||
StatusInfoRejected: "企业信息被拒绝",
|
||
StatusContractRejected: "合同被拒签",
|
||
StatusContractExpired: "合同签署超时",
|
||
}
|
||
|
||
if name, exists := statusNames[status]; exists {
|
||
return name
|
||
}
|
||
return string(status)
|
||
}
|
||
|
||
// IsFinalStatus 判断是否为最终状态
|
||
func IsFinalStatus(status CertificationStatus) bool {
|
||
return status == StatusCompleted
|
||
}
|
||
|
||
// 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 {
|
||
if IsMainFlowStatus(status) {
|
||
return "主流程"
|
||
}
|
||
if IsFailureStatus(status) {
|
||
return "失败状态"
|
||
}
|
||
if status == StatusCompleted {
|
||
return "完成"
|
||
}
|
||
return "未知"
|
||
}
|
||
|
||
// GetStatusPriority 获取状态优先级(用于排序)
|
||
func GetStatusPriority(status CertificationStatus) int {
|
||
priorities := map[CertificationStatus]int{
|
||
StatusPending: 1,
|
||
StatusInfoPendingReview: 2,
|
||
StatusInfoSubmitted: 3,
|
||
StatusEnterpriseVerified: 4,
|
||
StatusContractApplied: 5,
|
||
StatusContractSigned: 6,
|
||
StatusCompleted: 7,
|
||
StatusInfoRejected: 8,
|
||
StatusContractRejected: 9,
|
||
StatusContractExpired: 10,
|
||
}
|
||
|
||
if priority, exists := priorities[status]; exists {
|
||
return priority
|
||
}
|
||
return 999
|
||
}
|
||
|
||
// GetProgressPercentage 获取进度百分比
|
||
func GetProgressPercentage(status CertificationStatus) int {
|
||
progressMap := map[CertificationStatus]int{
|
||
StatusPending: 0,
|
||
StatusInfoPendingReview: 15,
|
||
StatusInfoSubmitted: 25,
|
||
StatusEnterpriseVerified: 50,
|
||
StatusContractApplied: 75,
|
||
StatusContractSigned: 100,
|
||
StatusCompleted: 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, // 需要提交企业信息
|
||
StatusInfoPendingReview: false, // 等待人工审核
|
||
StatusInfoSubmitted: false, // 等待完成企业认证
|
||
StatusEnterpriseVerified: true, // 需要申请合同
|
||
StatusContractApplied: true, // 需要签署合同
|
||
StatusContractSigned: false, // 合同已签署,等待系统处理
|
||
StatusCompleted: 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: "请提交企业信息",
|
||
StatusInfoPendingReview: "企业信息已提交,请等待管理员审核",
|
||
StatusInfoSubmitted: "请完成企业认证",
|
||
StatusEnterpriseVerified: "企业认证完成,请申请签署合同",
|
||
StatusContractApplied: "请在规定时间内完成合同签署",
|
||
StatusContractSigned: "合同已签署,等待系统处理",
|
||
StatusCompleted: "认证已完成",
|
||
StatusInfoRejected: "企业信息验证失败,请修正后重新提交",
|
||
StatusContractRejected: "合同签署被拒绝,可重新申请",
|
||
StatusContractExpired: "合同签署已超时,请重新申请",
|
||
}
|
||
|
||
if hint, exists := hints[status]; exists {
|
||
return hint
|
||
}
|
||
return ""
|
||
}
|
||
|
||
// GetNextValidStatuses 获取当前状态的下一个有效状态列表
|
||
func GetNextValidStatuses(currentStatus CertificationStatus) []CertificationStatus {
|
||
nextStatusMap := map[CertificationStatus][]CertificationStatus{
|
||
StatusPending: {
|
||
StatusInfoPendingReview, // 用户提交企业信息,进入待审核
|
||
StatusInfoSubmitted, // 暂时跳过人工审核,直接进入已提交
|
||
StatusCompleted,
|
||
},
|
||
StatusInfoPendingReview: {
|
||
StatusInfoSubmitted,
|
||
StatusInfoRejected,
|
||
StatusCompleted,
|
||
},
|
||
StatusInfoSubmitted: {
|
||
StatusEnterpriseVerified,
|
||
StatusInfoRejected,
|
||
// 管理员/系统可直接完成认证
|
||
StatusCompleted,
|
||
},
|
||
StatusEnterpriseVerified: {
|
||
StatusContractApplied,
|
||
// 管理员/系统可直接完成认证(无合同场景)
|
||
StatusCompleted,
|
||
},
|
||
StatusContractApplied: {
|
||
StatusContractSigned,
|
||
StatusContractRejected,
|
||
StatusContractExpired,
|
||
// 管理员/系统可在合同流程中直接完成认证
|
||
StatusCompleted,
|
||
},
|
||
StatusContractSigned: {
|
||
StatusCompleted, // 可以转换到完成状态
|
||
},
|
||
StatusCompleted: {
|
||
// 最终状态,无后续状态
|
||
},
|
||
StatusInfoRejected: {
|
||
StatusInfoPendingReview, // 用户修正后重新提交,进入人工审核
|
||
StatusInfoSubmitted, // 兼容旧路径:直接重新提交
|
||
// 管理员/系统可直接标记为完成
|
||
StatusCompleted,
|
||
},
|
||
StatusContractRejected: {
|
||
StatusEnterpriseVerified, // 重置到企业认证状态
|
||
// 管理员/系统可直接标记为完成
|
||
StatusCompleted,
|
||
},
|
||
StatusContractExpired: {
|
||
StatusEnterpriseVerified, // 重置到企业认证状态
|
||
// 管理员/系统可直接标记为完成
|
||
StatusCompleted,
|
||
},
|
||
}
|
||
|
||
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(StatusInfoPendingReview): "用户提交企业信息,等待人工审核",
|
||
string(StatusInfoPendingReview) + "->" + string(StatusInfoSubmitted): "管理员审核通过",
|
||
string(StatusInfoPendingReview) + "->" + string(StatusInfoRejected): "管理员审核拒绝",
|
||
string(StatusPending) + "->" + string(StatusInfoSubmitted): "用户提交企业信息",
|
||
string(StatusInfoSubmitted) + "->" + string(StatusEnterpriseVerified): "e签宝企业认证成功",
|
||
string(StatusInfoSubmitted) + "->" + string(StatusInfoRejected): "e签宝企业认证失败",
|
||
string(StatusEnterpriseVerified) + "->" + string(StatusContractApplied): "用户申请签署合同",
|
||
string(StatusContractApplied) + "->" + string(StatusContractSigned): "e签宝合同签署成功",
|
||
string(StatusContractSigned) + "->" + string(StatusCompleted): "系统处理完成,认证成功",
|
||
string(StatusContractApplied) + "->" + string(StatusContractRejected): "用户拒绝签署合同",
|
||
string(StatusContractApplied) + "->" + string(StatusContractExpired): "合同签署超时",
|
||
string(StatusInfoRejected) + "->" + string(StatusInfoPendingReview): "用户修正后重新提交企业信息",
|
||
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 "未知转换"
|
||
}
|
||
|
||
// CanAdminRejectEnterpriseInfoPhase 是否允许管理员拒绝企业信息(仅 early phase)
|
||
func CanAdminRejectEnterpriseInfoPhase(status CertificationStatus) bool {
|
||
return status == StatusInfoPendingReview || status == StatusInfoSubmitted
|
||
}
|