服务器批量导入: - 后端 BatchCreateServers handler: 逐条校验/查重/GB→MB转换/错误明细 - 前端 CSV 解析器 + IP校验 + 模板下载 + 真实API导入 - 删除孤立占位组件 BatchImport.tsx SQL审计: - 修复 TableName 字段与 GORM 接口冲突 → TargetTable - 补全路由注册 + AutoMigrate + 种子数据 审批流程增强 + 告警/菜单微调 // Logan.Li
109 lines
3.9 KiB
Go
109 lines
3.9 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// ApprovalTemplate 审批模板模型
|
|
type ApprovalTemplate struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Name string `gorm:"size:128;not null" json:"name"`
|
|
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
|
Description string `gorm:"size:500" json:"description"`
|
|
Type string `gorm:"size:32;not null" json:"type"` // release, server, permission
|
|
FormSchema string `gorm:"type:text" json:"form_schema"` // JSON
|
|
FlowConfig string `gorm:"type:text" json:"flow_config"` // JSON
|
|
Enabled bool `gorm:"default:true" json:"enabled"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (ApprovalTemplate) TableName() string {
|
|
return "approval_templates"
|
|
}
|
|
|
|
// ApprovalProcess 审批流程模型
|
|
type ApprovalProcess struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
TemplateID uint `json:"template_id"`
|
|
Title string `gorm:"size:255;not null" json:"title"`
|
|
Applicant uint `json:"applicant"`
|
|
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected
|
|
FormData string `gorm:"type:text" json:"form_data"` // JSON
|
|
CurrentStep int `gorm:"default:0" json:"current_step"`
|
|
TotalSteps int `json:"total_steps"`
|
|
ApprovedAt *time.Time `json:"approved_at"`
|
|
RejectedAt *time.Time `json:"rejected_at"`
|
|
RejectReason string `gorm:"size:500" json:"reject_reason"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
// 关联
|
|
Template *ApprovalTemplate `gorm:"foreignKey:TemplateID" json:"template,omitempty"`
|
|
ApplicantUser *User `gorm:"foreignKey:Applicant" json:"applicant_user,omitempty"`
|
|
Steps []ApprovalStep `gorm:"foreignKey:ProcessID" json:"steps,omitempty"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (ApprovalProcess) TableName() string {
|
|
return "approval_processes"
|
|
}
|
|
|
|
// ApprovalStep 审批步骤模型
|
|
type ApprovalStep struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
ProcessID uint `json:"process_id"`
|
|
Step int `json:"step"`
|
|
Approver uint `json:"approver"`
|
|
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected
|
|
Comment string `gorm:"size:500" json:"comment"`
|
|
ApprovedAt *time.Time `json:"approved_at"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
// 关联
|
|
ApproverUser *User `gorm:"foreignKey:Approver" json:"approver_user,omitempty"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (ApprovalStep) TableName() string {
|
|
return "approval_steps"
|
|
}
|
|
|
|
// CreateApprovalTemplateRequest 创建审批模板请求
|
|
type CreateApprovalTemplateRequest struct {
|
|
Name string `json:"name" binding:"required"`
|
|
Code string `json:"code" binding:"required"`
|
|
Description string `json:"description"`
|
|
Type string `json:"type" binding:"required,oneof=server_apply app_deploy"`
|
|
FormSchema string `json:"form_schema"`
|
|
FlowConfig string `json:"flow_config"`
|
|
}
|
|
|
|
// CreateApprovalProcessRequest 创建审批流程请求
|
|
type CreateApprovalProcessRequest struct {
|
|
TemplateID uint `json:"template_id" binding:"required"`
|
|
Title string `json:"title" binding:"required"`
|
|
FormData string `json:"form_data"`
|
|
}
|
|
|
|
// ApproveRequest 审批请求
|
|
type ApproveRequest struct {
|
|
Status string `json:"status" binding:"required,oneof=approved rejected"`
|
|
Comment string `json:"comment"`
|
|
}
|
|
|
|
// ApprovalStats 审批统计
|
|
type ApprovalStats struct {
|
|
Pending int64 `json:"pending"`
|
|
Approved int64 `json:"approved"`
|
|
Rejected int64 `json:"rejected"`
|
|
Total int64 `json:"total"`
|
|
MyPending int64 `json:"my_pending"`
|
|
}
|