|
|
@@ -8,69 +8,157 @@ import (
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- FieldID = "ID"
|
|
|
- FieldTenantID = "TenantID"
|
|
|
- FieldCreateUserID = "CreateUserID"
|
|
|
+ // FieldID ID字段名
|
|
|
+ FieldID = "ID"
|
|
|
+
|
|
|
+ // FieldTenantID 租户ID字段名
|
|
|
+ FieldTenantID = "TenantID"
|
|
|
+
|
|
|
+ // FieldCreateUserID 创建用户ID字段名
|
|
|
+ FieldCreateUserID = "CreateUserID"
|
|
|
+
|
|
|
+ // FieldLastUpdateUserID 最近更新用户ID字段名
|
|
|
FieldLastUpdateUserID = "LastUpdateUserID"
|
|
|
- FieldCreatedTime = "CreatedTime"
|
|
|
- FieldLastUpdatedTime = "LastUpdatedTime"
|
|
|
+
|
|
|
+ // FieldCreatedTime 创建时间字段名
|
|
|
+ FieldCreatedTime = "CreatedTime"
|
|
|
+
|
|
|
+ // FieldLastUpdatedTime 最近更新时间字段名
|
|
|
+ FieldLastUpdatedTime = "LastUpdatedTime"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- ColumnID = "id"
|
|
|
- ColumnTenantID = "tenant_id"
|
|
|
- ColumnCreateUserID = "create_user_id"
|
|
|
+ // ColumnID ID列名
|
|
|
+ ColumnID = "id"
|
|
|
+
|
|
|
+ // ColumnTenantID 租户ID列名
|
|
|
+ ColumnTenantID = "tenant_id"
|
|
|
+
|
|
|
+ // ColumnCreateUserID 创建用户ID列名
|
|
|
+ ColumnCreateUserID = "create_user_id"
|
|
|
+
|
|
|
+ // ColumnLastUpdateUserID 最新更新用户ID列名
|
|
|
ColumnLastUpdateUserID = "last_update_user_id"
|
|
|
- ColumnCreatedTime = "created_time"
|
|
|
- ColumnLastUpdatedTime = "last_updated_time"
|
|
|
+
|
|
|
+ // ColumnCreatedTime 创建时间列名
|
|
|
+ ColumnCreatedTime = "created_time"
|
|
|
+
|
|
|
+ // ColumnLastUpdatedTime 最近更新时间列名
|
|
|
+ ColumnLastUpdatedTime = "last_updated_time"
|
|
|
)
|
|
|
|
|
|
+const (
|
|
|
+ idLen = 32
|
|
|
+)
|
|
|
+
|
|
|
+// TenantIDField 租户ID字段
|
|
|
type TenantIDField struct {
|
|
|
TenantID string `sqlmapping:"column:tenant_id;" sqlresult:"column:tenant_id;" check:"required,len=32"`
|
|
|
}
|
|
|
|
|
|
+// UserIDFields 用户ID相关字段
|
|
|
type UserIDFields struct {
|
|
|
CreateUserID string `sqlmapping:"column:create_user_id;" sqlresult:"column:create_user_id;" check:"required,len=32"`
|
|
|
LastUpdateUserID string `sqlmapping:"column:last_update_user_id;" sqlresult:"column:last_update_user_id;" check:"required,len=32"`
|
|
|
}
|
|
|
|
|
|
+// TimeFields 时间相关字段
|
|
|
type TimeFields struct {
|
|
|
CreatedTime time.Time `sqlmapping:"column:created_time;" sqlresult:"column:created_time;"`
|
|
|
LastUpdatedTime time.Time `sqlmapping:"column:last_updated_time;" sqlresult:"column:last_updated_time;"`
|
|
|
}
|
|
|
|
|
|
+// CheckFieldID 校验领域实体的ID字段是否合规
|
|
|
+// 参数:
|
|
|
+// - entity: 领域实体
|
|
|
+// 返回值:
|
|
|
+// - 错误
|
|
|
func CheckFieldID(entity Entity) error {
|
|
|
return checkIDTypeField(entity, FieldID, "ID")
|
|
|
}
|
|
|
|
|
|
+// CheckFieldTenantID 校验领域实体的租户ID字段是否合规
|
|
|
+// 参数:
|
|
|
+// - entity: 领域实体
|
|
|
+// 返回值:
|
|
|
+// - 错误
|
|
|
func CheckFieldTenantID(entity Entity) error {
|
|
|
return checkIDTypeField(entity, FieldTenantID, "租户ID")
|
|
|
}
|
|
|
|
|
|
+// CheckFieldCreateUserID 校验领域实体的创建用户ID字段是否合规
|
|
|
+// 参数:
|
|
|
+// - entity: 领域实体
|
|
|
+// 返回值:
|
|
|
+// - 错误
|
|
|
func CheckFieldCreateUserID(entity Entity) error {
|
|
|
return checkIDTypeField(entity, FieldCreateUserID, "创建用户ID")
|
|
|
}
|
|
|
|
|
|
+// CheckFieldLastUpdateUserID 校验领域实体的最近更新用户ID字段是否合规
|
|
|
+// 参数:
|
|
|
+// - entity: 领域实体
|
|
|
+// 返回值:
|
|
|
+// - 错误
|
|
|
func CheckFieldLastUpdateUserID(entity Entity) error {
|
|
|
return checkIDTypeField(entity, FieldLastUpdateUserID, "最近更新用户ID")
|
|
|
}
|
|
|
|
|
|
+// CheckFieldIDResult 利用check.Struct函数返回的结果校验领域实体的ID字段是否合规
|
|
|
+// 参数:
|
|
|
+// - checkResult: check.Struct函数返回的结果
|
|
|
+// 返回值:
|
|
|
+// - 错误
|
|
|
func CheckFieldIDResult(checkResult check.Result) error {
|
|
|
return checkIDTypeResult(checkResult, FieldID, FieldID)
|
|
|
}
|
|
|
|
|
|
+// CheckFieldTenantIDResult 利用check.Struct函数返回的结果校验领域实体的租户ID字段是否合规
|
|
|
+// 参数:
|
|
|
+// - checkResult: check.Struct函数返回的结果
|
|
|
+// 返回值:
|
|
|
+// - 错误
|
|
|
func CheckFieldTenantIDResult(checkResult check.Result) error {
|
|
|
return checkIDTypeResult(checkResult, FieldTenantID, FieldTenantID)
|
|
|
}
|
|
|
|
|
|
+// CheckFieldCreateUserIDResult 利用check.Struct函数返回的结果校验领域实体的创建用户ID字段是否合规
|
|
|
+// 参数:
|
|
|
+// - checkResult: check.Struct函数返回的结果
|
|
|
+// 返回值:
|
|
|
+// - 错误
|
|
|
func CheckFieldCreateUserIDResult(checkResult check.Result) error {
|
|
|
return checkIDTypeResult(checkResult, FieldCreateUserID, FieldCreateUserID)
|
|
|
}
|
|
|
|
|
|
+// CheckFieldLastUpdateUserIDResult 利用check.Struct函数返回的结果校验领域实体的最近更新用户ID字段是否合规
|
|
|
+// 参数:
|
|
|
+// - checkResult: check.Struct函数返回的结果
|
|
|
+// 返回值:
|
|
|
+// - 错误
|
|
|
func CheckFieldLastUpdateUserIDResult(checkResult check.Result) error {
|
|
|
return checkIDTypeResult(checkResult, FieldLastUpdateUserID, FieldLastUpdateUserID)
|
|
|
}
|
|
|
|
|
|
+// CheckIDTypeValue 校验ID类型的字段,如ID,租户ID,用户ID等,特点是字符串类型,不能为空且长度严格为32字节
|
|
|
+// 参数:
|
|
|
+// - domainCNName: 领域中文名,可以使用DomainCNName()方法获得
|
|
|
+// - fieldCNName: 字段的中文名称(用于构造报错信息)
|
|
|
+// - id: id字段的值
|
|
|
+// 返回值:
|
|
|
+// - 错误
|
|
|
+func CheckIDTypeValue(domainCNName string, fieldCNName string, id string) error {
|
|
|
+ if strutils.IsStringEmpty(id) {
|
|
|
+ return errors.New(domainCNName + fieldCNName + "为空")
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(id) != idLen {
|
|
|
+ return errors.New(domainCNName + fieldCNName + "长度不正确")
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func checkIDTypeField(entity Entity, fieldName string, fieldCNName string) error {
|
|
|
checkResult := check.Struct(entity, map[string]string{
|
|
|
fieldName: entity.DomainCNName() + fieldCNName,
|
|
|
@@ -92,19 +180,3 @@ func checkIDTypeResult(checkResult check.Result, domainCNName string, fieldName
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
-
|
|
|
-const (
|
|
|
- idLen = 32
|
|
|
-)
|
|
|
-
|
|
|
-func CheckIDTypeValue(domainCNName string, fieldCNName string, id string) error {
|
|
|
- if strutils.IsStringEmpty(id) {
|
|
|
- return errors.New(domainCNName + fieldCNName + "为空")
|
|
|
- }
|
|
|
-
|
|
|
- if len(id) != idLen {
|
|
|
- return errors.New(domainCNName + fieldCNName + "长度不正确")
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
-}
|