| 
									
										
										
										
											2025-07-11 21:05:58 +08:00
										 |  |  | package enums | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // CertificationStatus 认证状态枚举 | 
					
						
							|  |  |  | type CertificationStatus string | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ( | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 	// === 主流程状态 === | 
					
						
							|  |  |  | 	StatusPending            CertificationStatus = "pending"              // 待认证 | 
					
						
							|  |  |  | 	StatusInfoSubmitted      CertificationStatus = "info_submitted"       // 已提交企业信息 | 
					
						
							|  |  |  | 	StatusEnterpriseVerified CertificationStatus = "enterprise_verified"  // 已企业认证 | 
					
						
							|  |  |  | 	StatusContractApplied    CertificationStatus = "contract_applied"     // 已申请签署合同 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 	StatusContractSigned     CertificationStatus = "contract_signed"      // 已签署合同 | 
					
						
							|  |  |  | 	StatusCompleted          CertificationStatus = "completed"            // 认证完成 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// === 失败状态 === | 
					
						
							|  |  |  | 	StatusInfoRejected     CertificationStatus = "info_rejected"     // 企业信息被拒绝 | 
					
						
							|  |  |  | 	StatusContractRejected CertificationStatus = "contract_rejected" // 合同被拒签 | 
					
						
							|  |  |  | 	StatusContractExpired  CertificationStatus = "contract_expired"  // 合同签署超时 | 
					
						
							| 
									
										
										
										
											2025-07-11 21:05:58 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | // AllStatuses 所有有效状态列表 | 
					
						
							|  |  |  | var AllStatuses = []CertificationStatus{ | 
					
						
							|  |  |  | 	StatusPending, | 
					
						
							|  |  |  | 	StatusInfoSubmitted, | 
					
						
							|  |  |  | 	StatusEnterpriseVerified, | 
					
						
							|  |  |  | 	StatusContractApplied, | 
					
						
							|  |  |  | 	StatusContractSigned, | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 	StatusCompleted, | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 	StatusInfoRejected, | 
					
						
							|  |  |  | 	StatusContractRejected, | 
					
						
							|  |  |  | 	StatusContractExpired, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // MainFlowStatuses 主流程状态列表 | 
					
						
							|  |  |  | var MainFlowStatuses = []CertificationStatus{ | 
					
						
							|  |  |  | 	StatusPending, | 
					
						
							|  |  |  | 	StatusInfoSubmitted, | 
					
						
							|  |  |  | 	StatusEnterpriseVerified, | 
					
						
							|  |  |  | 	StatusContractApplied, | 
					
						
							|  |  |  | 	StatusContractSigned, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // FailureStatuses 失败状态列表 | 
					
						
							|  |  |  | var FailureStatuses = []CertificationStatus{ | 
					
						
							|  |  |  | 	StatusInfoRejected, | 
					
						
							|  |  |  | 	StatusContractRejected, | 
					
						
							|  |  |  | 	StatusContractExpired, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-11 21:05:58 +08:00
										 |  |  | // IsValidStatus 检查状态是否有效 | 
					
						
							|  |  |  | func IsValidStatus(status CertificationStatus) bool { | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 	for _, validStatus := range AllStatuses { | 
					
						
							| 
									
										
										
										
											2025-07-11 21:05:58 +08:00
										 |  |  | 		if status == validStatus { | 
					
						
							|  |  |  | 			return true | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // GetStatusName 获取状态的中文名称 | 
					
						
							|  |  |  | func GetStatusName(status CertificationStatus) string { | 
					
						
							|  |  |  | 	statusNames := map[CertificationStatus]string{ | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 		StatusPending:            "待认证", | 
					
						
							|  |  |  | 		StatusInfoSubmitted:      "已提交企业信息", | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | 		StatusEnterpriseVerified: "已企业认证", | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 		StatusContractApplied:    "已申请签署合同", | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 		StatusContractSigned:     "已签署合同", | 
					
						
							|  |  |  | 		StatusCompleted:          "认证完成", | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 		StatusInfoRejected:       "企业信息被拒绝", | 
					
						
							|  |  |  | 		StatusContractRejected:   "合同被拒签", | 
					
						
							|  |  |  | 		StatusContractExpired:    "合同签署超时", | 
					
						
							| 
									
										
										
										
											2025-07-11 21:05:58 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if name, exists := statusNames[status]; exists { | 
					
						
							|  |  |  | 		return name | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return string(status) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // IsFinalStatus 判断是否为最终状态 | 
					
						
							|  |  |  | func IsFinalStatus(status CertificationStatus) bool { | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 	return status == StatusCompleted | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // 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 | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2025-07-11 21:05:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | // GetStatusCategory 获取状态分类 | 
					
						
							|  |  |  | func GetStatusCategory(status CertificationStatus) string { | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 	if IsMainFlowStatus(status) { | 
					
						
							|  |  |  | 		return "主流程" | 
					
						
							| 
									
										
										
										
											2025-07-11 21:05:58 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 	if IsFailureStatus(status) { | 
					
						
							|  |  |  | 		return "失败状态" | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 	if status == StatusCompleted { | 
					
						
							|  |  |  | 		return "完成" | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 	return "未知" | 
					
						
							| 
									
										
										
										
											2025-07-11 21:05:58 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | // GetStatusPriority 获取状态优先级(用于排序) | 
					
						
							|  |  |  | func GetStatusPriority(status CertificationStatus) int { | 
					
						
							|  |  |  | 	priorities := map[CertificationStatus]int{ | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 		StatusPending:            1, | 
					
						
							|  |  |  | 		StatusInfoSubmitted:      2, | 
					
						
							|  |  |  | 		StatusEnterpriseVerified: 3, | 
					
						
							|  |  |  | 		StatusContractApplied:    4, | 
					
						
							|  |  |  | 		StatusContractSigned:     5, | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 		StatusCompleted:          6, | 
					
						
							|  |  |  | 		StatusInfoRejected:       7, | 
					
						
							|  |  |  | 		StatusContractRejected:   8, | 
					
						
							|  |  |  | 		StatusContractExpired:    9, | 
					
						
							| 
									
										
										
										
											2025-07-11 21:05:58 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | 	if priority, exists := priorities[status]; exists { | 
					
						
							|  |  |  | 		return priority | 
					
						
							| 
									
										
										
										
											2025-07-11 21:05:58 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | 	return 999 | 
					
						
							| 
									
										
										
										
											2025-07-11 21:05:58 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // GetProgressPercentage 获取进度百分比 | 
					
						
							|  |  |  | func GetProgressPercentage(status CertificationStatus) int { | 
					
						
							|  |  |  | 	progressMap := map[CertificationStatus]int{ | 
					
						
							|  |  |  | 		StatusPending:            0, | 
					
						
							|  |  |  | 		StatusInfoSubmitted:      25, | 
					
						
							|  |  |  | 		StatusEnterpriseVerified: 50, | 
					
						
							|  |  |  | 		StatusContractApplied:    75, | 
					
						
							|  |  |  | 		StatusContractSigned:     100, | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 		StatusCompleted:          100, | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 		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,  // 需要签署合同 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 		StatusContractSigned:     false, // 合同已签署,等待系统处理 | 
					
						
							|  |  |  | 		StatusCompleted:          false, // 已完成 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 		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:            "请提交企业信息", | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 		StatusInfoSubmitted:      "请完成企业认证", | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 		StatusEnterpriseVerified: "企业认证完成,请申请签署合同", | 
					
						
							|  |  |  | 		StatusContractApplied:    "请在规定时间内完成合同签署", | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 		StatusContractSigned:     "合同已签署,等待系统处理", | 
					
						
							|  |  |  | 		StatusCompleted:          "认证已完成", | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 		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: { | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 			StatusCompleted, // 可以转换到完成状态 | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		StatusCompleted: { | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 			// 最终状态,无后续状态 | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		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签宝合同签署成功", | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 		string(StatusContractSigned) + "->" + string(StatusCompleted):         "系统处理完成,认证成功", | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  | 		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 "未知转换" | 
					
						
							|  |  |  | } |