temp
This commit is contained in:
@@ -1,45 +1,235 @@
|
||||
package responses
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"tyapi-server/internal/domains/certification/entities/value_objects"
|
||||
"tyapi-server/internal/domains/certification/enums"
|
||||
"tyapi-server/internal/domains/certification/repositories"
|
||||
"tyapi-server/internal/domains/certification/services/state_machine"
|
||||
)
|
||||
|
||||
// CertificationResponse 认证响应
|
||||
type CertificationResponse struct {
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
Status enums.CertificationStatus `json:"status"`
|
||||
StatusName string `json:"status_name"`
|
||||
Progress int `json:"progress"`
|
||||
IsUserActionRequired bool `json:"is_user_action_required"`
|
||||
InfoSubmittedAt *time.Time `json:"info_submitted_at,omitempty"`
|
||||
EnterpriseVerifiedAt *time.Time `json:"enterprise_verified_at,omitempty"`
|
||||
ContractAppliedAt *time.Time `json:"contract_applied_at,omitempty"`
|
||||
ContractSignedAt *time.Time `json:"contract_signed_at,omitempty"`
|
||||
CompletedAt *time.Time `json:"completed_at,omitempty"`
|
||||
Enterprise *EnterpriseInfoResponse `json:"enterprise,omitempty"`
|
||||
ContractURL string `json:"contract_url,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
Status enums.CertificationStatus `json:"status"`
|
||||
StatusName string `json:"status_name"`
|
||||
Progress int `json:"progress"`
|
||||
|
||||
// 企业信息
|
||||
EnterpriseInfo *value_objects.EnterpriseInfo `json:"enterprise_info,omitempty"`
|
||||
|
||||
// 合同信息
|
||||
ContractInfo *value_objects.ContractInfo `json:"contract_info,omitempty"`
|
||||
|
||||
// 时间戳
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
InfoSubmittedAt *time.Time `json:"info_submitted_at,omitempty"`
|
||||
EnterpriseVerifiedAt *time.Time `json:"enterprise_verified_at,omitempty"`
|
||||
ContractAppliedAt *time.Time `json:"contract_applied_at,omitempty"`
|
||||
ContractSignedAt *time.Time `json:"contract_signed_at,omitempty"`
|
||||
|
||||
// 业务状态
|
||||
IsCompleted bool `json:"is_completed"`
|
||||
IsFailed bool `json:"is_failed"`
|
||||
IsUserActionRequired bool `json:"is_user_action_required"`
|
||||
|
||||
// 失败信息
|
||||
FailureReason enums.FailureReason `json:"failure_reason,omitempty"`
|
||||
FailureReasonName string `json:"failure_reason_name,omitempty"`
|
||||
FailureMessage string `json:"failure_message,omitempty"`
|
||||
CanRetry bool `json:"can_retry,omitempty"`
|
||||
RetryCount int `json:"retry_count,omitempty"`
|
||||
|
||||
// 用户操作提示
|
||||
NextAction string `json:"next_action,omitempty"`
|
||||
AvailableActions []string `json:"available_actions,omitempty"`
|
||||
|
||||
// 元数据
|
||||
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
// EnterpriseInfoResponse 企业信息响应
|
||||
type EnterpriseInfoResponse struct {
|
||||
ID string `json:"id"`
|
||||
CompanyName string `json:"company_name"`
|
||||
UnifiedSocialCode string `json:"unified_social_code"`
|
||||
LegalPersonName string `json:"legal_person_name"`
|
||||
LegalPersonID string `json:"legal_person_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
// CertificationListResponse 认证列表响应
|
||||
type CertificationListResponse struct {
|
||||
Items []*CertificationResponse `json:"items"`
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
TotalPages int `json:"total_pages"`
|
||||
}
|
||||
|
||||
// EnterpriseAuthURLResponse 企业认证链接响应
|
||||
type EnterpriseAuthURLResponse struct {
|
||||
EsignFlowID string `json:"esign_flow_id"` // e签宝认证流程ID
|
||||
AuthURL string `json:"auth_url"` // 认证链接
|
||||
ShortURL string `json:"short_url"` // 短链接
|
||||
ExpireAt string `json:"expire_at"` // 过期时间
|
||||
// ContractSignUrlResponse 合同签署URL响应
|
||||
type ContractSignUrlResponse struct {
|
||||
CertificationID string `json:"certification_id"`
|
||||
ContractSignURL string `json:"contract_sign_url"`
|
||||
ContractURL string `json:"contract_url,omitempty"`
|
||||
ExpireAt *time.Time `json:"expire_at,omitempty"`
|
||||
NextAction string `json:"next_action"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// CallbackResponse 回调响应
|
||||
type CallbackResponse struct {
|
||||
Success bool `json:"success"`
|
||||
CertificationID string `json:"certification_id"`
|
||||
CallbackType string `json:"callback_type"`
|
||||
ProcessedAt time.Time `json:"processed_at"`
|
||||
OldStatus enums.CertificationStatus `json:"old_status,omitempty"`
|
||||
NewStatus enums.CertificationStatus `json:"new_status,omitempty"`
|
||||
Message string `json:"message"`
|
||||
StateTransition *state_machine.StateTransitionResult `json:"state_transition,omitempty"`
|
||||
}
|
||||
|
||||
// CertificationStatisticsResponse 认证统计响应
|
||||
type CertificationStatisticsResponse struct {
|
||||
Period string `json:"period"`
|
||||
TimeRange string `json:"time_range"`
|
||||
Statistics *repositories.CertificationStatistics `json:"statistics"`
|
||||
ProgressStats *repositories.CertificationProgressStats `json:"progress_stats,omitempty"`
|
||||
Charts map[string]interface{} `json:"charts,omitempty"`
|
||||
GeneratedAt time.Time `json:"generated_at"`
|
||||
}
|
||||
|
||||
// SystemMonitoringResponse 系统监控响应
|
||||
type SystemMonitoringResponse struct {
|
||||
TimeRange string `json:"time_range"`
|
||||
Metrics map[string]interface{} `json:"metrics"`
|
||||
Alerts []SystemAlert `json:"alerts,omitempty"`
|
||||
SystemHealth SystemHealthStatus `json:"system_health"`
|
||||
LastUpdatedAt time.Time `json:"last_updated_at"`
|
||||
}
|
||||
|
||||
// SystemAlert 系统警告
|
||||
type SystemAlert struct {
|
||||
Level string `json:"level"` // info, warning, error, critical
|
||||
Type string `json:"type"` // 警告类型
|
||||
Message string `json:"message"` // 警告消息
|
||||
Metric string `json:"metric"` // 相关指标
|
||||
Value interface{} `json:"value"` // 当前值
|
||||
Threshold interface{} `json:"threshold"` // 阈值
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
// SystemHealthStatus 系统健康状态
|
||||
type SystemHealthStatus struct {
|
||||
Overall string `json:"overall"` // healthy, warning, critical
|
||||
Components map[string]string `json:"components"` // 各组件状态
|
||||
LastCheck time.Time `json:"last_check"`
|
||||
Details map[string]interface{} `json:"details,omitempty"`
|
||||
}
|
||||
|
||||
// ================ 响应构建辅助方法 ================
|
||||
|
||||
// NewCertificationListResponse 创建认证列表响应
|
||||
func NewCertificationListResponse(items []*CertificationResponse, total int64, page, pageSize int) *CertificationListResponse {
|
||||
totalPages := int((total + int64(pageSize) - 1) / int64(pageSize))
|
||||
if totalPages == 0 {
|
||||
totalPages = 1
|
||||
}
|
||||
|
||||
return &CertificationListResponse{
|
||||
Items: items,
|
||||
Total: total,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
TotalPages: totalPages,
|
||||
}
|
||||
}
|
||||
|
||||
// NewContractSignUrlResponse 创建合同签署URL响应
|
||||
func NewContractSignUrlResponse(certificationID, signURL, contractURL, nextAction, message string) *ContractSignUrlResponse {
|
||||
response := &ContractSignUrlResponse{
|
||||
CertificationID: certificationID,
|
||||
ContractSignURL: signURL,
|
||||
ContractURL: contractURL,
|
||||
NextAction: nextAction,
|
||||
Message: message,
|
||||
}
|
||||
|
||||
// 设置过期时间(默认24小时)
|
||||
expireAt := time.Now().Add(24 * time.Hour)
|
||||
response.ExpireAt = &expireAt
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
// NewCallbackResponse 创建回调响应
|
||||
func NewCallbackResponse(success bool, certificationID, callbackType, message string) *CallbackResponse {
|
||||
return &CallbackResponse{
|
||||
Success: success,
|
||||
CertificationID: certificationID,
|
||||
CallbackType: callbackType,
|
||||
ProcessedAt: time.Now(),
|
||||
Message: message,
|
||||
}
|
||||
}
|
||||
|
||||
// NewSystemAlert 创建系统警告
|
||||
func NewSystemAlert(level, alertType, message, metric string, value, threshold interface{}) *SystemAlert {
|
||||
return &SystemAlert{
|
||||
Level: level,
|
||||
Type: alertType,
|
||||
Message: message,
|
||||
Metric: metric,
|
||||
Value: value,
|
||||
Threshold: threshold,
|
||||
CreatedAt: time.Now(),
|
||||
Metadata: make(map[string]interface{}),
|
||||
}
|
||||
}
|
||||
|
||||
// IsSuccess 检查响应是否成功
|
||||
func (r *CallbackResponse) IsSuccess() bool {
|
||||
return r.Success
|
||||
}
|
||||
|
||||
// HasStateTransition 检查是否有状态转换
|
||||
func (r *CallbackResponse) HasStateTransition() bool {
|
||||
return r.StateTransition != nil
|
||||
}
|
||||
|
||||
// GetStatusChange 获取状态变更描述
|
||||
func (r *CallbackResponse) GetStatusChange() string {
|
||||
if !r.HasStateTransition() {
|
||||
return ""
|
||||
}
|
||||
|
||||
if r.OldStatus == r.NewStatus {
|
||||
return "状态无变化"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("从 %s 转换为 %s",
|
||||
enums.GetStatusName(r.OldStatus),
|
||||
enums.GetStatusName(r.NewStatus))
|
||||
}
|
||||
|
||||
// IsHealthy 检查系统是否健康
|
||||
func (r *SystemMonitoringResponse) IsHealthy() bool {
|
||||
return r.SystemHealth.Overall == "healthy"
|
||||
}
|
||||
|
||||
// GetCriticalAlerts 获取严重警告
|
||||
func (r *SystemMonitoringResponse) GetCriticalAlerts() []*SystemAlert {
|
||||
var criticalAlerts []*SystemAlert
|
||||
for i := range r.Alerts {
|
||||
if r.Alerts[i].Level == "critical" {
|
||||
criticalAlerts = append(criticalAlerts, &r.Alerts[i])
|
||||
}
|
||||
}
|
||||
return criticalAlerts
|
||||
}
|
||||
|
||||
// HasAlerts 检查是否有警告
|
||||
func (r *SystemMonitoringResponse) HasAlerts() bool {
|
||||
return len(r.Alerts) > 0
|
||||
}
|
||||
|
||||
// GetMetricValue 获取指标值
|
||||
func (r *SystemMonitoringResponse) GetMetricValue(metric string) (interface{}, bool) {
|
||||
value, exists := r.Metrics[metric]
|
||||
return value, exists
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user