feat(deploy): 增加部署文件域名验证和存在性检查
- 在创建部署文件时增加域名必填验证 - 添加域名存在性检查,防止重复使用已存在的域名 - 优化了参数绑定和错误处理逻辑
This commit is contained in:
parent
e8aa95b7c5
commit
d94ced13b0
|
@ -6,26 +6,26 @@ import (
|
||||||
|
|
||||||
// SysDeployFile 部署文件记录表
|
// SysDeployFile 部署文件记录表
|
||||||
type SysDeployFile struct {
|
type SysDeployFile struct {
|
||||||
DeployId string `gorm:"column:deploy_id;type:varchar(64);primary_key;comment:部署ID" json:"deployId"`
|
DeployId string `gorm:"column:deploy_id;type:varchar(64);primary_key;comment:部署ID" json:"deployId"`
|
||||||
FileName string `gorm:"column:file_name;type:varchar(255);not null;comment:原始文件名" json:"fileName"`
|
FileName string `gorm:"column:file_name;type:varchar(255);not null;comment:原始文件名" json:"fileName" binding:"required"`
|
||||||
ProjectName string `gorm:"column:project_name;type:varchar(100);not null;comment:项目名称" json:"projectName"`
|
ProjectName string `gorm:"column:project_name;type:varchar(100);not null;comment:项目名称" json:"projectName" binding:"required"`
|
||||||
Domain string `gorm:"column:domain;type:varchar(255);not null;comment:访问域名" json:"domain"`
|
Domain string `gorm:"column:domain;type:varchar(255);not null;comment:访问域名" json:"domain" binding:"required"`
|
||||||
DeployPath string `gorm:"column:deploy_path;type:varchar(500);not null;comment:部署路径" json:"deployPath"`
|
DeployPath string `gorm:"column:deploy_path;type:varchar(500);not null;comment:部署路径" json:"deployPath"`
|
||||||
FileSize int64 `gorm:"column:file_size;type:bigint;comment:文件大小(字节)" json:"fileSize"`
|
FileSize int64 `gorm:"column:file_size;type:bigint;comment:文件大小(字节)" json:"fileSize"`
|
||||||
FileHash string `gorm:"column:file_hash;type:varchar(64);comment:文件哈希值" json:"fileHash"`
|
FileHash string `gorm:"column:file_hash;type:varchar(64);comment:文件哈希值" json:"fileHash"`
|
||||||
Status string `gorm:"column:status;type:char(1);default:1;comment:状态(0停用 1正常 2部署中 3部署失败)" json:"status"`
|
Status string `gorm:"column:status;type:char(1);default:1;comment:状态(0停用 1正常 2部署中 3部署失败)" json:"status"`
|
||||||
DeployStatus string `gorm:"column:deploy_status;type:char(1);default:0;comment:部署状态(0未部署 1部署成功 2部署失败)" json:"deployStatus"`
|
DeployStatus string `gorm:"column:deploy_status;type:char(1);default:0;comment:部署状态(0未部署 1部署成功 2部署失败)" json:"deployStatus"`
|
||||||
ErrorMsg string `gorm:"column:error_msg;type:text;comment:错误信息" json:"errorMsg"`
|
ErrorMsg string `gorm:"column:error_msg;type:text;comment:错误信息" json:"errorMsg"`
|
||||||
Version string `gorm:"column:version;type:varchar(50);comment:版本号" json:"version"`
|
Version string `gorm:"column:version;type:varchar(50);comment:版本号" json:"version"`
|
||||||
Description string `gorm:"column:description;type:varchar(500);comment:描述" json:"description"`
|
Description string `gorm:"column:description;type:varchar(500);comment:描述" json:"description"`
|
||||||
DelFlag string `gorm:"column:del_flag;type:char(1);default:0;comment:删除标志(0代表存在 1代表删除)" json:"delFlag"`
|
DelFlag string `gorm:"column:del_flag;type:char(1);default:0;comment:删除标志(0代表存在 1代表删除)" json:"delFlag"`
|
||||||
CreateBy string `gorm:"column:create_by;type:varchar(64);comment:创建者" json:"createBy"`
|
CreateBy string `gorm:"column:create_by;type:varchar(64);comment:创建者" json:"createBy"`
|
||||||
CreateTime *time.Time `gorm:"column:create_time;type:datetime;comment:创建时间" json:"createTime"`
|
CreateTime *time.Time `gorm:"column:create_time;type:datetime;comment:创建时间" json:"createTime"`
|
||||||
UpdateBy string `gorm:"column:update_by;type:varchar(64);comment:更新者" json:"updateBy"`
|
UpdateBy string `gorm:"column:update_by;type:varchar(64);comment:更新者" json:"updateBy"`
|
||||||
UpdateTime *time.Time `gorm:"column:update_time;type:datetime;comment:更新时间" json:"updateTime"`
|
UpdateTime *time.Time `gorm:"column:update_time;type:datetime;comment:更新时间" json:"updateTime"`
|
||||||
DeployTime *time.Time `gorm:"column:deploy_time;type:datetime;comment:部署时间" json:"deployTime"`
|
DeployTime *time.Time `gorm:"column:deploy_time;type:datetime;comment:部署时间" json:"deployTime"`
|
||||||
LastAccessTime *time.Time `gorm:"column:last_access_time;type:datetime;comment:最后访问时间" json:"lastAccessTime"`
|
LastAccessTime *time.Time `gorm:"column:last_access_time;type:datetime;comment:最后访问时间" json:"lastAccessTime"`
|
||||||
AccessCount int64 `gorm:"column:access_count;type:bigint;default:0;comment:访问次数" json:"accessCount"`
|
AccessCount int64 `gorm:"column:access_count;type:bigint;default:0;comment:访问次数" json:"accessCount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName 表名
|
// TableName 表名
|
||||||
|
@ -35,10 +35,10 @@ func (m *SysDeployFile) TableName() string {
|
||||||
|
|
||||||
// DeployFileStatus 部署文件状态常量
|
// DeployFileStatus 部署文件状态常量
|
||||||
const (
|
const (
|
||||||
DeployFileStatusDisabled = "0" // 停用
|
DeployFileStatusDisabled = "0" // 停用
|
||||||
DeployFileStatusNormal = "1" // 正常
|
DeployFileStatusNormal = "1" // 正常
|
||||||
DeployFileStatusDeploying = "2" // 部署中
|
DeployFileStatusDeploying = "2" // 部署中
|
||||||
DeployFileStatusFailed = "3" // 部署失败
|
DeployFileStatusFailed = "3" // 部署失败
|
||||||
)
|
)
|
||||||
|
|
||||||
// DeployStatus 部署状态常量
|
// DeployStatus 部署状态常量
|
||||||
|
|
|
@ -36,6 +36,19 @@ func (s *SysDeployFileService) Create(c *gin.Context) serializer.Response {
|
||||||
return serializer.ParamErr("参数绑定失败!", err)
|
return serializer.ParamErr("参数绑定失败!", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 验证必填字段
|
||||||
|
if deployFile.Domain == "" {
|
||||||
|
logger.Error(c, "域名不能为空!")
|
||||||
|
return serializer.ParamErr("域名不能为空!", fmt.Errorf("域名不能为空"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查域名是否已存在
|
||||||
|
var existingDeployFile model.SysDeployFile
|
||||||
|
if err := s.Db.Where("domain = ? AND del_flag = ?", deployFile.Domain, "0").First(&existingDeployFile).Error; err == nil {
|
||||||
|
logger.Error(c, "域名已存在!")
|
||||||
|
return serializer.ParamErr("域名已存在,请使用其他域名!", fmt.Errorf("域名已存在"))
|
||||||
|
}
|
||||||
|
|
||||||
// 生成部署ID
|
// 生成部署ID
|
||||||
if id, err := SysSequenceServiceBuilder(deployFile.TableName()).GenerateId(); err == nil {
|
if id, err := SysSequenceServiceBuilder(deployFile.TableName()).GenerateId(); err == nil {
|
||||||
deployFile.DeployId = id
|
deployFile.DeployId = id
|
||||||
|
|
Loading…
Reference in New Issue