feat: 新增预警定时扫描器,移除附件归档字段并为角色表补充更新时间

This commit is contained in:
SunYF
2026-10-31 15:41:27 +08:00
parent 11dbdaae75
commit 0c03d32682
107 changed files with 10790 additions and 1844 deletions
+2 -24
View File
@@ -39,10 +39,6 @@ type Attachment struct {
FileMd5 string `json:"fileMd5,omitempty"`
// MIME类型
MimeType string `json:"mimeType,omitempty"`
// 是否已归档
Archived bool `json:"archived,omitempty"`
// 归档时间(unix秒)
ArchivedAt int64 `json:"archivedAt,omitempty"`
// 逻辑删除
Deleted bool `json:"deleted,omitempty"`
// 删除时间(unix秒)
@@ -63,9 +59,9 @@ func (*Attachment) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case attachment.FieldArchived, attachment.FieldDeleted:
case attachment.FieldDeleted:
values[i] = new(sql.NullBool)
case attachment.FieldID, attachment.FieldFileSize, attachment.FieldArchivedAt, attachment.FieldDeletedAt, attachment.FieldPurgedAt:
case attachment.FieldID, attachment.FieldFileSize, attachment.FieldDeletedAt, attachment.FieldPurgedAt:
values[i] = new(sql.NullInt64)
case attachment.FieldBizType, attachment.FieldBizId, attachment.FieldFileName, attachment.FieldFilePath, attachment.FieldUploader, attachment.FieldFileType, attachment.FieldFileExt, attachment.FieldFileMd5, attachment.FieldMimeType, attachment.FieldDeletedBy, attachment.FieldDeletedReason, attachment.FieldPurgedBy:
values[i] = new(sql.NullString)
@@ -158,18 +154,6 @@ func (_m *Attachment) assignValues(columns []string, values []any) error {
} else if value.Valid {
_m.MimeType = value.String
}
case attachment.FieldArchived:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field archived", values[i])
} else if value.Valid {
_m.Archived = value.Bool
}
case attachment.FieldArchivedAt:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field archivedAt", values[i])
} else if value.Valid {
_m.ArchivedAt = value.Int64
}
case attachment.FieldDeleted:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field deleted", values[i])
@@ -275,12 +259,6 @@ func (_m *Attachment) String() string {
builder.WriteString("mimeType=")
builder.WriteString(_m.MimeType)
builder.WriteString(", ")
builder.WriteString("archived=")
builder.WriteString(fmt.Sprintf("%v", _m.Archived))
builder.WriteString(", ")
builder.WriteString("archivedAt=")
builder.WriteString(fmt.Sprintf("%v", _m.ArchivedAt))
builder.WriteString(", ")
builder.WriteString("deleted=")
builder.WriteString(fmt.Sprintf("%v", _m.Deleted))
builder.WriteString(", ")
-20
View File
@@ -35,10 +35,6 @@ const (
FieldFileMd5 = "file_md5"
// FieldMimeType holds the string denoting the mimetype field in the database.
FieldMimeType = "mime_type"
// FieldArchived holds the string denoting the archived field in the database.
FieldArchived = "archived"
// FieldArchivedAt holds the string denoting the archivedat field in the database.
FieldArchivedAt = "archived_at"
// FieldDeleted holds the string denoting the deleted field in the database.
FieldDeleted = "deleted"
// FieldDeletedAt holds the string denoting the deletedat field in the database.
@@ -69,8 +65,6 @@ var Columns = []string{
FieldFileExt,
FieldFileMd5,
FieldMimeType,
FieldArchived,
FieldArchivedAt,
FieldDeleted,
FieldDeletedAt,
FieldDeletedBy,
@@ -122,10 +116,6 @@ var (
DefaultMimeType string
// MimeTypeValidator is a validator for the "mimeType" field. It is called by the builders before save.
MimeTypeValidator func(string) error
// DefaultArchived holds the default value on creation for the "archived" field.
DefaultArchived bool
// DefaultArchivedAt holds the default value on creation for the "archivedAt" field.
DefaultArchivedAt int64
// DefaultDeleted holds the default value on creation for the "deleted" field.
DefaultDeleted bool
// DefaultDeletedAt holds the default value on creation for the "deletedAt" field.
@@ -211,16 +201,6 @@ func ByMimeType(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldMimeType, opts...).ToFunc()
}
// ByArchived orders the results by the archived field.
func ByArchived(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldArchived, opts...).ToFunc()
}
// ByArchivedAt orders the results by the archivedAt field.
func ByArchivedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldArchivedAt, opts...).ToFunc()
}
// ByDeleted orders the results by the deleted field.
func ByDeleted(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDeleted, opts...).ToFunc()
-60
View File
@@ -109,16 +109,6 @@ func MimeType(v string) predicate.Attachment {
return predicate.Attachment(sql.FieldEQ(FieldMimeType, v))
}
// Archived applies equality check predicate on the "archived" field. It's identical to ArchivedEQ.
func Archived(v bool) predicate.Attachment {
return predicate.Attachment(sql.FieldEQ(FieldArchived, v))
}
// ArchivedAt applies equality check predicate on the "archivedAt" field. It's identical to ArchivedAtEQ.
func ArchivedAt(v int64) predicate.Attachment {
return predicate.Attachment(sql.FieldEQ(FieldArchivedAt, v))
}
// Deleted applies equality check predicate on the "deleted" field. It's identical to DeletedEQ.
func Deleted(v bool) predicate.Attachment {
return predicate.Attachment(sql.FieldEQ(FieldDeleted, v))
@@ -814,56 +804,6 @@ func MimeTypeContainsFold(v string) predicate.Attachment {
return predicate.Attachment(sql.FieldContainsFold(FieldMimeType, v))
}
// ArchivedEQ applies the EQ predicate on the "archived" field.
func ArchivedEQ(v bool) predicate.Attachment {
return predicate.Attachment(sql.FieldEQ(FieldArchived, v))
}
// ArchivedNEQ applies the NEQ predicate on the "archived" field.
func ArchivedNEQ(v bool) predicate.Attachment {
return predicate.Attachment(sql.FieldNEQ(FieldArchived, v))
}
// ArchivedAtEQ applies the EQ predicate on the "archivedAt" field.
func ArchivedAtEQ(v int64) predicate.Attachment {
return predicate.Attachment(sql.FieldEQ(FieldArchivedAt, v))
}
// ArchivedAtNEQ applies the NEQ predicate on the "archivedAt" field.
func ArchivedAtNEQ(v int64) predicate.Attachment {
return predicate.Attachment(sql.FieldNEQ(FieldArchivedAt, v))
}
// ArchivedAtIn applies the In predicate on the "archivedAt" field.
func ArchivedAtIn(vs ...int64) predicate.Attachment {
return predicate.Attachment(sql.FieldIn(FieldArchivedAt, vs...))
}
// ArchivedAtNotIn applies the NotIn predicate on the "archivedAt" field.
func ArchivedAtNotIn(vs ...int64) predicate.Attachment {
return predicate.Attachment(sql.FieldNotIn(FieldArchivedAt, vs...))
}
// ArchivedAtGT applies the GT predicate on the "archivedAt" field.
func ArchivedAtGT(v int64) predicate.Attachment {
return predicate.Attachment(sql.FieldGT(FieldArchivedAt, v))
}
// ArchivedAtGTE applies the GTE predicate on the "archivedAt" field.
func ArchivedAtGTE(v int64) predicate.Attachment {
return predicate.Attachment(sql.FieldGTE(FieldArchivedAt, v))
}
// ArchivedAtLT applies the LT predicate on the "archivedAt" field.
func ArchivedAtLT(v int64) predicate.Attachment {
return predicate.Attachment(sql.FieldLT(FieldArchivedAt, v))
}
// ArchivedAtLTE applies the LTE predicate on the "archivedAt" field.
func ArchivedAtLTE(v int64) predicate.Attachment {
return predicate.Attachment(sql.FieldLTE(FieldArchivedAt, v))
}
// DeletedEQ applies the EQ predicate on the "deleted" field.
func DeletedEQ(v bool) predicate.Attachment {
return predicate.Attachment(sql.FieldEQ(FieldDeleted, v))
-50
View File
@@ -142,34 +142,6 @@ func (_c *AttachmentCreate) SetNillableMimeType(v *string) *AttachmentCreate {
return _c
}
// SetArchived sets the "archived" field.
func (_c *AttachmentCreate) SetArchived(v bool) *AttachmentCreate {
_c.mutation.SetArchived(v)
return _c
}
// SetNillableArchived sets the "archived" field if the given value is not nil.
func (_c *AttachmentCreate) SetNillableArchived(v *bool) *AttachmentCreate {
if v != nil {
_c.SetArchived(*v)
}
return _c
}
// SetArchivedAt sets the "archivedAt" field.
func (_c *AttachmentCreate) SetArchivedAt(v int64) *AttachmentCreate {
_c.mutation.SetArchivedAt(v)
return _c
}
// SetNillableArchivedAt sets the "archivedAt" field if the given value is not nil.
func (_c *AttachmentCreate) SetNillableArchivedAt(v *int64) *AttachmentCreate {
if v != nil {
_c.SetArchivedAt(*v)
}
return _c
}
// SetDeleted sets the "deleted" field.
func (_c *AttachmentCreate) SetDeleted(v bool) *AttachmentCreate {
_c.mutation.SetDeleted(v)
@@ -323,14 +295,6 @@ func (_c *AttachmentCreate) defaults() {
v := attachment.DefaultMimeType
_c.mutation.SetMimeType(v)
}
if _, ok := _c.mutation.Archived(); !ok {
v := attachment.DefaultArchived
_c.mutation.SetArchived(v)
}
if _, ok := _c.mutation.ArchivedAt(); !ok {
v := attachment.DefaultArchivedAt
_c.mutation.SetArchivedAt(v)
}
if _, ok := _c.mutation.Deleted(); !ok {
v := attachment.DefaultDeleted
_c.mutation.SetDeleted(v)
@@ -437,12 +401,6 @@ func (_c *AttachmentCreate) check() error {
return &ValidationError{Name: "mimeType", err: fmt.Errorf(`ent: validator failed for field "Attachment.mimeType": %w`, err)}
}
}
if _, ok := _c.mutation.Archived(); !ok {
return &ValidationError{Name: "archived", err: errors.New(`ent: missing required field "Attachment.archived"`)}
}
if _, ok := _c.mutation.ArchivedAt(); !ok {
return &ValidationError{Name: "archivedAt", err: errors.New(`ent: missing required field "Attachment.archivedAt"`)}
}
if _, ok := _c.mutation.Deleted(); !ok {
return &ValidationError{Name: "deleted", err: errors.New(`ent: missing required field "Attachment.deleted"`)}
}
@@ -557,14 +515,6 @@ func (_c *AttachmentCreate) createSpec() (*Attachment, *sqlgraph.CreateSpec) {
_spec.SetField(attachment.FieldMimeType, field.TypeString, value)
_node.MimeType = value
}
if value, ok := _c.mutation.Archived(); ok {
_spec.SetField(attachment.FieldArchived, field.TypeBool, value)
_node.Archived = value
}
if value, ok := _c.mutation.ArchivedAt(); ok {
_spec.SetField(attachment.FieldArchivedAt, field.TypeInt64, value)
_node.ArchivedAt = value
}
if value, ok := _c.mutation.Deleted(); ok {
_spec.SetField(attachment.FieldDeleted, field.TypeBool, value)
_node.Deleted = value
-88
View File
@@ -175,41 +175,6 @@ func (_u *AttachmentUpdate) SetNillableMimeType(v *string) *AttachmentUpdate {
return _u
}
// SetArchived sets the "archived" field.
func (_u *AttachmentUpdate) SetArchived(v bool) *AttachmentUpdate {
_u.mutation.SetArchived(v)
return _u
}
// SetNillableArchived sets the "archived" field if the given value is not nil.
func (_u *AttachmentUpdate) SetNillableArchived(v *bool) *AttachmentUpdate {
if v != nil {
_u.SetArchived(*v)
}
return _u
}
// SetArchivedAt sets the "archivedAt" field.
func (_u *AttachmentUpdate) SetArchivedAt(v int64) *AttachmentUpdate {
_u.mutation.ResetArchivedAt()
_u.mutation.SetArchivedAt(v)
return _u
}
// SetNillableArchivedAt sets the "archivedAt" field if the given value is not nil.
func (_u *AttachmentUpdate) SetNillableArchivedAt(v *int64) *AttachmentUpdate {
if v != nil {
_u.SetArchivedAt(*v)
}
return _u
}
// AddArchivedAt adds value to the "archivedAt" field.
func (_u *AttachmentUpdate) AddArchivedAt(v int64) *AttachmentUpdate {
_u.mutation.AddArchivedAt(v)
return _u
}
// SetDeleted sets the "deleted" field.
func (_u *AttachmentUpdate) SetDeleted(v bool) *AttachmentUpdate {
_u.mutation.SetDeleted(v)
@@ -456,15 +421,6 @@ func (_u *AttachmentUpdate) sqlSave(ctx context.Context) (_node int, err error)
if value, ok := _u.mutation.MimeType(); ok {
_spec.SetField(attachment.FieldMimeType, field.TypeString, value)
}
if value, ok := _u.mutation.Archived(); ok {
_spec.SetField(attachment.FieldArchived, field.TypeBool, value)
}
if value, ok := _u.mutation.ArchivedAt(); ok {
_spec.SetField(attachment.FieldArchivedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedArchivedAt(); ok {
_spec.AddField(attachment.FieldArchivedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.Deleted(); ok {
_spec.SetField(attachment.FieldDeleted, field.TypeBool, value)
}
@@ -658,41 +614,6 @@ func (_u *AttachmentUpdateOne) SetNillableMimeType(v *string) *AttachmentUpdateO
return _u
}
// SetArchived sets the "archived" field.
func (_u *AttachmentUpdateOne) SetArchived(v bool) *AttachmentUpdateOne {
_u.mutation.SetArchived(v)
return _u
}
// SetNillableArchived sets the "archived" field if the given value is not nil.
func (_u *AttachmentUpdateOne) SetNillableArchived(v *bool) *AttachmentUpdateOne {
if v != nil {
_u.SetArchived(*v)
}
return _u
}
// SetArchivedAt sets the "archivedAt" field.
func (_u *AttachmentUpdateOne) SetArchivedAt(v int64) *AttachmentUpdateOne {
_u.mutation.ResetArchivedAt()
_u.mutation.SetArchivedAt(v)
return _u
}
// SetNillableArchivedAt sets the "archivedAt" field if the given value is not nil.
func (_u *AttachmentUpdateOne) SetNillableArchivedAt(v *int64) *AttachmentUpdateOne {
if v != nil {
_u.SetArchivedAt(*v)
}
return _u
}
// AddArchivedAt adds value to the "archivedAt" field.
func (_u *AttachmentUpdateOne) AddArchivedAt(v int64) *AttachmentUpdateOne {
_u.mutation.AddArchivedAt(v)
return _u
}
// SetDeleted sets the "deleted" field.
func (_u *AttachmentUpdateOne) SetDeleted(v bool) *AttachmentUpdateOne {
_u.mutation.SetDeleted(v)
@@ -969,15 +890,6 @@ func (_u *AttachmentUpdateOne) sqlSave(ctx context.Context) (_node *Attachment,
if value, ok := _u.mutation.MimeType(); ok {
_spec.SetField(attachment.FieldMimeType, field.TypeString, value)
}
if value, ok := _u.mutation.Archived(); ok {
_spec.SetField(attachment.FieldArchived, field.TypeBool, value)
}
if value, ok := _u.mutation.ArchivedAt(); ok {
_spec.SetField(attachment.FieldArchivedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedArchivedAt(); ok {
_spec.AddField(attachment.FieldArchivedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.Deleted(); ok {
_spec.SetField(attachment.FieldDeleted, field.TypeBool, value)
}
+1 -2
View File
@@ -166,8 +166,6 @@ var (
{Name: "file_ext", Type: field.TypeString, Size: 16, Comment: "扩展名(小写,不含点)", Default: ""},
{Name: "file_md5", Type: field.TypeString, Size: 64, Comment: "文件MD5(秒传/去重)", Default: ""},
{Name: "mime_type", Type: field.TypeString, Size: 128, Comment: "MIME类型", Default: ""},
{Name: "archived", Type: field.TypeBool, Comment: "是否已归档", Default: false},
{Name: "archived_at", Type: field.TypeInt64, Comment: "归档时间(unix秒)", Default: 0},
{Name: "deleted", Type: field.TypeBool, Comment: "逻辑删除", Default: false},
{Name: "deleted_at", Type: field.TypeInt64, Comment: "删除时间(unix秒)", Default: 0},
{Name: "deleted_by", Type: field.TypeString, Size: 64, Comment: "删除人", Default: ""},
@@ -824,6 +822,7 @@ var (
{Name: "remark", Type: field.TypeString, Size: 255, Default: ""},
{Name: "permission_codes", Type: field.TypeJSON, Nullable: true, Comment: "权限编码列表,如 produce.workorder:view", SchemaType: map[string]string{"postgres": "jsonb"}},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime, Nullable: true, Comment: "更新时间"},
}
// RoleTable holds the schema information for the "role" table.
RoleTable = &schema.Table{
+75 -143
View File
@@ -3770,9 +3770,6 @@ type AttachmentMutation struct {
fileExt *string
fileMd5 *string
mimeType *string
archived *bool
archivedAt *int64
addarchivedAt *int64
deleted *bool
deletedAt *int64
adddeletedAt *int64
@@ -4307,98 +4304,6 @@ func (m *AttachmentMutation) ResetMimeType() {
m.mimeType = nil
}
// SetArchived sets the "archived" field.
func (m *AttachmentMutation) SetArchived(b bool) {
m.archived = &b
}
// Archived returns the value of the "archived" field in the mutation.
func (m *AttachmentMutation) Archived() (r bool, exists bool) {
v := m.archived
if v == nil {
return
}
return *v, true
}
// OldArchived returns the old "archived" field's value of the Attachment entity.
// If the Attachment object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AttachmentMutation) OldArchived(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldArchived is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldArchived requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldArchived: %w", err)
}
return oldValue.Archived, nil
}
// ResetArchived resets all changes to the "archived" field.
func (m *AttachmentMutation) ResetArchived() {
m.archived = nil
}
// SetArchivedAt sets the "archivedAt" field.
func (m *AttachmentMutation) SetArchivedAt(i int64) {
m.archivedAt = &i
m.addarchivedAt = nil
}
// ArchivedAt returns the value of the "archivedAt" field in the mutation.
func (m *AttachmentMutation) ArchivedAt() (r int64, exists bool) {
v := m.archivedAt
if v == nil {
return
}
return *v, true
}
// OldArchivedAt returns the old "archivedAt" field's value of the Attachment entity.
// If the Attachment object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AttachmentMutation) OldArchivedAt(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldArchivedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldArchivedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldArchivedAt: %w", err)
}
return oldValue.ArchivedAt, nil
}
// AddArchivedAt adds i to the "archivedAt" field.
func (m *AttachmentMutation) AddArchivedAt(i int64) {
if m.addarchivedAt != nil {
*m.addarchivedAt += i
} else {
m.addarchivedAt = &i
}
}
// AddedArchivedAt returns the value that was added to the "archivedAt" field in this mutation.
func (m *AttachmentMutation) AddedArchivedAt() (r int64, exists bool) {
v := m.addarchivedAt
if v == nil {
return
}
return *v, true
}
// ResetArchivedAt resets all changes to the "archivedAt" field.
func (m *AttachmentMutation) ResetArchivedAt() {
m.archivedAt = nil
m.addarchivedAt = nil
}
// SetDeleted sets the "deleted" field.
func (m *AttachmentMutation) SetDeleted(b bool) {
m.deleted = &b
@@ -4689,7 +4594,7 @@ func (m *AttachmentMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *AttachmentMutation) Fields() []string {
fields := make([]string, 0, 19)
fields := make([]string, 0, 17)
if m.bizType != nil {
fields = append(fields, attachment.FieldBizType)
}
@@ -4723,12 +4628,6 @@ func (m *AttachmentMutation) Fields() []string {
if m.mimeType != nil {
fields = append(fields, attachment.FieldMimeType)
}
if m.archived != nil {
fields = append(fields, attachment.FieldArchived)
}
if m.archivedAt != nil {
fields = append(fields, attachment.FieldArchivedAt)
}
if m.deleted != nil {
fields = append(fields, attachment.FieldDeleted)
}
@@ -4777,10 +4676,6 @@ func (m *AttachmentMutation) Field(name string) (ent.Value, bool) {
return m.FileMd5()
case attachment.FieldMimeType:
return m.MimeType()
case attachment.FieldArchived:
return m.Archived()
case attachment.FieldArchivedAt:
return m.ArchivedAt()
case attachment.FieldDeleted:
return m.Deleted()
case attachment.FieldDeletedAt:
@@ -4824,10 +4719,6 @@ func (m *AttachmentMutation) OldField(ctx context.Context, name string) (ent.Val
return m.OldFileMd5(ctx)
case attachment.FieldMimeType:
return m.OldMimeType(ctx)
case attachment.FieldArchived:
return m.OldArchived(ctx)
case attachment.FieldArchivedAt:
return m.OldArchivedAt(ctx)
case attachment.FieldDeleted:
return m.OldDeleted(ctx)
case attachment.FieldDeletedAt:
@@ -4926,20 +4817,6 @@ func (m *AttachmentMutation) SetField(name string, value ent.Value) error {
}
m.SetMimeType(v)
return nil
case attachment.FieldArchived:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetArchived(v)
return nil
case attachment.FieldArchivedAt:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetArchivedAt(v)
return nil
case attachment.FieldDeleted:
v, ok := value.(bool)
if !ok {
@@ -4993,9 +4870,6 @@ func (m *AttachmentMutation) AddedFields() []string {
if m.addfileSize != nil {
fields = append(fields, attachment.FieldFileSize)
}
if m.addarchivedAt != nil {
fields = append(fields, attachment.FieldArchivedAt)
}
if m.adddeletedAt != nil {
fields = append(fields, attachment.FieldDeletedAt)
}
@@ -5012,8 +4886,6 @@ func (m *AttachmentMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case attachment.FieldFileSize:
return m.AddedFileSize()
case attachment.FieldArchivedAt:
return m.AddedArchivedAt()
case attachment.FieldDeletedAt:
return m.AddedDeletedAt()
case attachment.FieldPurgedAt:
@@ -5034,13 +4906,6 @@ func (m *AttachmentMutation) AddField(name string, value ent.Value) error {
}
m.AddFileSize(v)
return nil
case attachment.FieldArchivedAt:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddArchivedAt(v)
return nil
case attachment.FieldDeletedAt:
v, ok := value.(int64)
if !ok {
@@ -5115,12 +4980,6 @@ func (m *AttachmentMutation) ResetField(name string) error {
case attachment.FieldMimeType:
m.ResetMimeType()
return nil
case attachment.FieldArchived:
m.ResetArchived()
return nil
case attachment.FieldArchivedAt:
m.ResetArchivedAt()
return nil
case attachment.FieldDeleted:
m.ResetDeleted()
return nil
@@ -22374,6 +22233,7 @@ type RoleMutation struct {
permissionCodes *[]string
appendpermissionCodes []string
createdAt *time.Time
updatedAt *time.Time
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*Role, error)
@@ -22693,6 +22553,55 @@ func (m *RoleMutation) ResetCreatedAt() {
m.createdAt = nil
}
// SetUpdatedAt sets the "updatedAt" field.
func (m *RoleMutation) SetUpdatedAt(t time.Time) {
m.updatedAt = &t
}
// UpdatedAt returns the value of the "updatedAt" field in the mutation.
func (m *RoleMutation) UpdatedAt() (r time.Time, exists bool) {
v := m.updatedAt
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updatedAt" field's value of the Role entity.
// If the Role object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RoleMutation) OldUpdatedAt(ctx context.Context) (v *time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
}
return oldValue.UpdatedAt, nil
}
// ClearUpdatedAt clears the value of the "updatedAt" field.
func (m *RoleMutation) ClearUpdatedAt() {
m.updatedAt = nil
m.clearedFields[role.FieldUpdatedAt] = struct{}{}
}
// UpdatedAtCleared returns if the "updatedAt" field was cleared in this mutation.
func (m *RoleMutation) UpdatedAtCleared() bool {
_, ok := m.clearedFields[role.FieldUpdatedAt]
return ok
}
// ResetUpdatedAt resets all changes to the "updatedAt" field.
func (m *RoleMutation) ResetUpdatedAt() {
m.updatedAt = nil
delete(m.clearedFields, role.FieldUpdatedAt)
}
// Where appends a list predicates to the RoleMutation builder.
func (m *RoleMutation) Where(ps ...predicate.Role) {
m.predicates = append(m.predicates, ps...)
@@ -22727,7 +22636,7 @@ func (m *RoleMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *RoleMutation) Fields() []string {
fields := make([]string, 0, 5)
fields := make([]string, 0, 6)
if m.name != nil {
fields = append(fields, role.FieldName)
}
@@ -22743,6 +22652,9 @@ func (m *RoleMutation) Fields() []string {
if m.createdAt != nil {
fields = append(fields, role.FieldCreatedAt)
}
if m.updatedAt != nil {
fields = append(fields, role.FieldUpdatedAt)
}
return fields
}
@@ -22761,6 +22673,8 @@ func (m *RoleMutation) Field(name string) (ent.Value, bool) {
return m.PermissionCodes()
case role.FieldCreatedAt:
return m.CreatedAt()
case role.FieldUpdatedAt:
return m.UpdatedAt()
}
return nil, false
}
@@ -22780,6 +22694,8 @@ func (m *RoleMutation) OldField(ctx context.Context, name string) (ent.Value, er
return m.OldPermissionCodes(ctx)
case role.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case role.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
}
return nil, fmt.Errorf("unknown Role field %s", name)
}
@@ -22824,6 +22740,13 @@ func (m *RoleMutation) SetField(name string, value ent.Value) error {
}
m.SetCreatedAt(v)
return nil
case role.FieldUpdatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
}
return fmt.Errorf("unknown Role field %s", name)
}
@@ -22857,6 +22780,9 @@ func (m *RoleMutation) ClearedFields() []string {
if m.FieldCleared(role.FieldPermissionCodes) {
fields = append(fields, role.FieldPermissionCodes)
}
if m.FieldCleared(role.FieldUpdatedAt) {
fields = append(fields, role.FieldUpdatedAt)
}
return fields
}
@@ -22874,6 +22800,9 @@ func (m *RoleMutation) ClearField(name string) error {
case role.FieldPermissionCodes:
m.ClearPermissionCodes()
return nil
case role.FieldUpdatedAt:
m.ClearUpdatedAt()
return nil
}
return fmt.Errorf("unknown Role nullable field %s", name)
}
@@ -22897,6 +22826,9 @@ func (m *RoleMutation) ResetField(name string) error {
case role.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case role.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
}
return fmt.Errorf("unknown Role field %s", name)
}
+16 -2
View File
@@ -27,7 +27,9 @@ type Role struct {
// 权限编码列表,如 produce.workorder:view
PermissionCodes []string `json:"permissionCodes,omitempty"`
// CreatedAt holds the value of the "createdAt" field.
CreatedAt time.Time `json:"createdAt,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
// 更新时间
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
selectValues sql.SelectValues
}
@@ -42,7 +44,7 @@ func (*Role) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullInt64)
case role.FieldName, role.FieldCode, role.FieldRemark:
values[i] = new(sql.NullString)
case role.FieldCreatedAt:
case role.FieldCreatedAt, role.FieldUpdatedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
@@ -97,6 +99,13 @@ func (_m *Role) assignValues(columns []string, values []any) error {
} else if value.Valid {
_m.CreatedAt = value.Time
}
case role.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updatedAt", values[i])
} else if value.Valid {
_m.UpdatedAt = new(time.Time)
*_m.UpdatedAt = value.Time
}
default:
_m.selectValues.Set(columns[i], values[i])
}
@@ -147,6 +156,11 @@ func (_m *Role) String() string {
builder.WriteString(", ")
builder.WriteString("createdAt=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := _m.UpdatedAt; v != nil {
builder.WriteString("updatedAt=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteByte(')')
return builder.String()
}
+12
View File
@@ -23,6 +23,8 @@ const (
FieldPermissionCodes = "permission_codes"
// FieldCreatedAt holds the string denoting the createdat field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updatedat field in the database.
FieldUpdatedAt = "updated_at"
// Table holds the table name of the role in the database.
Table = "role"
)
@@ -35,6 +37,7 @@ var Columns = []string{
FieldRemark,
FieldPermissionCodes,
FieldCreatedAt,
FieldUpdatedAt,
}
// ValidColumn reports if the column name is valid (part of the table columns).
@@ -58,6 +61,10 @@ var (
RemarkValidator func(string) error
// DefaultCreatedAt holds the default value on creation for the "createdAt" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updatedAt" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updatedAt" field.
UpdateDefaultUpdatedAt func() time.Time
// IDValidator is a validator for the "id" field. It is called by the builders before save.
IDValidator func(int) error
)
@@ -89,3 +96,8 @@ func ByRemark(opts ...sql.OrderTermOption) OrderOption {
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updatedAt field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
+55
View File
@@ -74,6 +74,11 @@ func CreatedAt(v time.Time) predicate.Role {
return predicate.Role(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updatedAt" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.Role {
return predicate.Role(sql.FieldEQ(FieldUpdatedAt, v))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.Role {
return predicate.Role(sql.FieldEQ(FieldName, v))
@@ -319,6 +324,56 @@ func CreatedAtLTE(v time.Time) predicate.Role {
return predicate.Role(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updatedAt" field.
func UpdatedAtEQ(v time.Time) predicate.Role {
return predicate.Role(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updatedAt" field.
func UpdatedAtNEQ(v time.Time) predicate.Role {
return predicate.Role(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updatedAt" field.
func UpdatedAtIn(vs ...time.Time) predicate.Role {
return predicate.Role(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updatedAt" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.Role {
return predicate.Role(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updatedAt" field.
func UpdatedAtGT(v time.Time) predicate.Role {
return predicate.Role(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updatedAt" field.
func UpdatedAtGTE(v time.Time) predicate.Role {
return predicate.Role(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updatedAt" field.
func UpdatedAtLT(v time.Time) predicate.Role {
return predicate.Role(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updatedAt" field.
func UpdatedAtLTE(v time.Time) predicate.Role {
return predicate.Role(sql.FieldLTE(FieldUpdatedAt, v))
}
// UpdatedAtIsNil applies the IsNil predicate on the "updatedAt" field.
func UpdatedAtIsNil() predicate.Role {
return predicate.Role(sql.FieldIsNull(FieldUpdatedAt))
}
// UpdatedAtNotNil applies the NotNil predicate on the "updatedAt" field.
func UpdatedAtNotNil() predicate.Role {
return predicate.Role(sql.FieldNotNull(FieldUpdatedAt))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Role) predicate.Role {
return predicate.Role(sql.AndPredicates(predicates...))
+22
View File
@@ -66,6 +66,20 @@ func (_c *RoleCreate) SetNillableCreatedAt(v *time.Time) *RoleCreate {
return _c
}
// SetUpdatedAt sets the "updatedAt" field.
func (_c *RoleCreate) SetUpdatedAt(v time.Time) *RoleCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updatedAt" field if the given value is not nil.
func (_c *RoleCreate) SetNillableUpdatedAt(v *time.Time) *RoleCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *RoleCreate) SetID(v int) *RoleCreate {
_c.mutation.SetID(v)
@@ -115,6 +129,10 @@ func (_c *RoleCreate) defaults() {
v := role.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := role.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
@@ -203,6 +221,10 @@ func (_c *RoleCreate) createSpec() (*Role, *sqlgraph.CreateSpec) {
_spec.SetField(role.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(role.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = &value
}
return _node, _spec
}
+55
View File
@@ -8,6 +8,7 @@ import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
@@ -89,6 +90,18 @@ func (_u *RoleUpdate) ClearPermissionCodes() *RoleUpdate {
return _u
}
// SetUpdatedAt sets the "updatedAt" field.
func (_u *RoleUpdate) SetUpdatedAt(v time.Time) *RoleUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// ClearUpdatedAt clears the value of the "updatedAt" field.
func (_u *RoleUpdate) ClearUpdatedAt() *RoleUpdate {
_u.mutation.ClearUpdatedAt()
return _u
}
// Mutation returns the RoleMutation object of the builder.
func (_u *RoleUpdate) Mutation() *RoleMutation {
return _u.mutation
@@ -96,6 +109,7 @@ func (_u *RoleUpdate) Mutation() *RoleMutation {
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *RoleUpdate) Save(ctx context.Context) (int, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
@@ -121,6 +135,14 @@ func (_u *RoleUpdate) ExecX(ctx context.Context) {
}
}
// defaults sets the default values of the builder before save.
func (_u *RoleUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok && !_u.mutation.UpdatedAtCleared() {
v := role.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *RoleUpdate) check() error {
if v, ok := _u.mutation.Name(); ok {
@@ -179,6 +201,12 @@ func (_u *RoleUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if _u.mutation.PermissionCodesCleared() {
_spec.ClearField(role.FieldPermissionCodes, field.TypeJSON)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(role.FieldUpdatedAt, field.TypeTime, value)
}
if _u.mutation.UpdatedAtCleared() {
_spec.ClearField(role.FieldUpdatedAt, field.TypeTime)
}
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
@@ -261,6 +289,18 @@ func (_u *RoleUpdateOne) ClearPermissionCodes() *RoleUpdateOne {
return _u
}
// SetUpdatedAt sets the "updatedAt" field.
func (_u *RoleUpdateOne) SetUpdatedAt(v time.Time) *RoleUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// ClearUpdatedAt clears the value of the "updatedAt" field.
func (_u *RoleUpdateOne) ClearUpdatedAt() *RoleUpdateOne {
_u.mutation.ClearUpdatedAt()
return _u
}
// Mutation returns the RoleMutation object of the builder.
func (_u *RoleUpdateOne) Mutation() *RoleMutation {
return _u.mutation
@@ -281,6 +321,7 @@ func (_u *RoleUpdateOne) Select(field string, fields ...string) *RoleUpdateOne {
// Save executes the query and returns the updated Role entity.
func (_u *RoleUpdateOne) Save(ctx context.Context) (*Role, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
@@ -306,6 +347,14 @@ func (_u *RoleUpdateOne) ExecX(ctx context.Context) {
}
}
// defaults sets the default values of the builder before save.
func (_u *RoleUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok && !_u.mutation.UpdatedAtCleared() {
v := role.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *RoleUpdateOne) check() error {
if v, ok := _u.mutation.Name(); ok {
@@ -381,6 +430,12 @@ func (_u *RoleUpdateOne) sqlSave(ctx context.Context) (_node *Role, err error) {
if _u.mutation.PermissionCodesCleared() {
_spec.ClearField(role.FieldPermissionCodes, field.TypeJSON)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(role.FieldUpdatedAt, field.TypeTime, value)
}
if _u.mutation.UpdatedAtCleared() {
_spec.ClearField(role.FieldUpdatedAt, field.TypeTime)
}
_spec.AddModifiers(_u.modifiers...)
_node = &Role{config: _u.config}
_spec.Assign = _node.assignValues
+12 -14
View File
@@ -323,40 +323,32 @@ func init() {
attachment.DefaultMimeType = attachmentDescMimeType.Default.(string)
// attachment.MimeTypeValidator is a validator for the "mimeType" field. It is called by the builders before save.
attachment.MimeTypeValidator = attachmentDescMimeType.Validators[0].(func(string) error)
// attachmentDescArchived is the schema descriptor for archived field.
attachmentDescArchived := attachmentFields[12].Descriptor()
// attachment.DefaultArchived holds the default value on creation for the archived field.
attachment.DefaultArchived = attachmentDescArchived.Default.(bool)
// attachmentDescArchivedAt is the schema descriptor for archivedAt field.
attachmentDescArchivedAt := attachmentFields[13].Descriptor()
// attachment.DefaultArchivedAt holds the default value on creation for the archivedAt field.
attachment.DefaultArchivedAt = attachmentDescArchivedAt.Default.(int64)
// attachmentDescDeleted is the schema descriptor for deleted field.
attachmentDescDeleted := attachmentFields[14].Descriptor()
attachmentDescDeleted := attachmentFields[12].Descriptor()
// attachment.DefaultDeleted holds the default value on creation for the deleted field.
attachment.DefaultDeleted = attachmentDescDeleted.Default.(bool)
// attachmentDescDeletedAt is the schema descriptor for deletedAt field.
attachmentDescDeletedAt := attachmentFields[15].Descriptor()
attachmentDescDeletedAt := attachmentFields[13].Descriptor()
// attachment.DefaultDeletedAt holds the default value on creation for the deletedAt field.
attachment.DefaultDeletedAt = attachmentDescDeletedAt.Default.(int64)
// attachmentDescDeletedBy is the schema descriptor for deletedBy field.
attachmentDescDeletedBy := attachmentFields[16].Descriptor()
attachmentDescDeletedBy := attachmentFields[14].Descriptor()
// attachment.DefaultDeletedBy holds the default value on creation for the deletedBy field.
attachment.DefaultDeletedBy = attachmentDescDeletedBy.Default.(string)
// attachment.DeletedByValidator is a validator for the "deletedBy" field. It is called by the builders before save.
attachment.DeletedByValidator = attachmentDescDeletedBy.Validators[0].(func(string) error)
// attachmentDescDeletedReason is the schema descriptor for deletedReason field.
attachmentDescDeletedReason := attachmentFields[17].Descriptor()
attachmentDescDeletedReason := attachmentFields[15].Descriptor()
// attachment.DefaultDeletedReason holds the default value on creation for the deletedReason field.
attachment.DefaultDeletedReason = attachmentDescDeletedReason.Default.(string)
// attachment.DeletedReasonValidator is a validator for the "deletedReason" field. It is called by the builders before save.
attachment.DeletedReasonValidator = attachmentDescDeletedReason.Validators[0].(func(string) error)
// attachmentDescPurgedAt is the schema descriptor for purgedAt field.
attachmentDescPurgedAt := attachmentFields[18].Descriptor()
attachmentDescPurgedAt := attachmentFields[16].Descriptor()
// attachment.DefaultPurgedAt holds the default value on creation for the purgedAt field.
attachment.DefaultPurgedAt = attachmentDescPurgedAt.Default.(int64)
// attachmentDescPurgedBy is the schema descriptor for purgedBy field.
attachmentDescPurgedBy := attachmentFields[19].Descriptor()
attachmentDescPurgedBy := attachmentFields[17].Descriptor()
// attachment.DefaultPurgedBy holds the default value on creation for the purgedBy field.
attachment.DefaultPurgedBy = attachmentDescPurgedBy.Default.(string)
// attachment.PurgedByValidator is a validator for the "purgedBy" field. It is called by the builders before save.
@@ -1375,6 +1367,12 @@ func init() {
roleDescCreatedAt := roleFields[5].Descriptor()
// role.DefaultCreatedAt holds the default value on creation for the createdAt field.
role.DefaultCreatedAt = roleDescCreatedAt.Default.(func() time.Time)
// roleDescUpdatedAt is the schema descriptor for updatedAt field.
roleDescUpdatedAt := roleFields[6].Descriptor()
// role.DefaultUpdatedAt holds the default value on creation for the updatedAt field.
role.DefaultUpdatedAt = roleDescUpdatedAt.Default.(func() time.Time)
// role.UpdateDefaultUpdatedAt holds the default value on update for the updatedAt field.
role.UpdateDefaultUpdatedAt = roleDescUpdatedAt.UpdateDefault.(func() time.Time)
// roleDescID is the schema descriptor for id field.
roleDescID := roleFields[0].Descriptor()
// role.IDValidator is a validator for the "id" field. It is called by the builders before save.