Files
aiops/backend/internal/models/approval.go
T
attacker 97c4207ff8 refactor: 标准化项目结构 frontend/ + backend/ + SQLite + run.sh
- 目录重构: app/ -> frontend/,与 backend/ 并列
- 数据库: 默认 SQLite(零配置),修复 DSN() bug
- run.sh: 一键启动前后端,支持 start/stop/restart/status
- Makefile: install/dev/build/lint/clean 快捷命令
- vite.config.ts: 配置 dev server 端口 5173 + API 代理到 8080
- config.yaml: SQLite 默认配置,开箱即用
- docs/: 完整开发文档(项目结构/API/数据库/规范/部署)
- 修复: GORM foreign key 关联声明
- 修复: go get gorm.io/driver/sqlite 依赖
2026-06-13 23:34:23 +08:00

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=release server permission"`
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"`
}