diff --git a/Makefile b/Makefile index 7d1bfdd3..7b4f17e2 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ PROJECT_I18N=true # Swagger type, support yml,json | Swagger 文件类型,支持yml,json SWAGGER_TYPE=json -` + # Ent enabled features | Ent 启用的官方特性 ENT_FEATURE=sql/execquery,intercept,sql/modifier diff --git a/go.sum b/go.sum index e10b13ec..da030e64 100644 --- a/go.sum +++ b/go.sum @@ -240,6 +240,8 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= diff --git a/rpc/ent/department/where.go b/rpc/ent/department/where.go index 04b7a272..cf99ebb4 100644 --- a/rpc/ent/department/where.go +++ b/rpc/ent/department/where.go @@ -475,6 +475,16 @@ func LeaderHasSuffix(v string) predicate.Department { return predicate.Department(sql.FieldHasSuffix(FieldLeader, v)) } +// LeaderIsNil applies the IsNil predicate on the "leader" field. +func LeaderIsNil() predicate.Department { + return predicate.Department(sql.FieldIsNull(FieldLeader)) +} + +// LeaderNotNil applies the NotNil predicate on the "leader" field. +func LeaderNotNil() predicate.Department { + return predicate.Department(sql.FieldNotNull(FieldLeader)) +} + // LeaderEqualFold applies the EqualFold predicate on the "leader" field. func LeaderEqualFold(v string) predicate.Department { return predicate.Department(sql.FieldEqualFold(FieldLeader, v)) @@ -540,6 +550,16 @@ func PhoneHasSuffix(v string) predicate.Department { return predicate.Department(sql.FieldHasSuffix(FieldPhone, v)) } +// PhoneIsNil applies the IsNil predicate on the "phone" field. +func PhoneIsNil() predicate.Department { + return predicate.Department(sql.FieldIsNull(FieldPhone)) +} + +// PhoneNotNil applies the NotNil predicate on the "phone" field. +func PhoneNotNil() predicate.Department { + return predicate.Department(sql.FieldNotNull(FieldPhone)) +} + // PhoneEqualFold applies the EqualFold predicate on the "phone" field. func PhoneEqualFold(v string) predicate.Department { return predicate.Department(sql.FieldEqualFold(FieldPhone, v)) @@ -605,6 +625,16 @@ func EmailHasSuffix(v string) predicate.Department { return predicate.Department(sql.FieldHasSuffix(FieldEmail, v)) } +// EmailIsNil applies the IsNil predicate on the "email" field. +func EmailIsNil() predicate.Department { + return predicate.Department(sql.FieldIsNull(FieldEmail)) +} + +// EmailNotNil applies the NotNil predicate on the "email" field. +func EmailNotNil() predicate.Department { + return predicate.Department(sql.FieldNotNull(FieldEmail)) +} + // EmailEqualFold applies the EqualFold predicate on the "email" field. func EmailEqualFold(v string) predicate.Department { return predicate.Department(sql.FieldEqualFold(FieldEmail, v)) diff --git a/rpc/ent/department_create.go b/rpc/ent/department_create.go index fbf3a380..81ae151b 100644 --- a/rpc/ent/department_create.go +++ b/rpc/ent/department_create.go @@ -104,18 +104,42 @@ func (dc *DepartmentCreate) SetLeader(s string) *DepartmentCreate { return dc } +// SetNillableLeader sets the "leader" field if the given value is not nil. +func (dc *DepartmentCreate) SetNillableLeader(s *string) *DepartmentCreate { + if s != nil { + dc.SetLeader(*s) + } + return dc +} + // SetPhone sets the "phone" field. func (dc *DepartmentCreate) SetPhone(s string) *DepartmentCreate { dc.mutation.SetPhone(s) return dc } +// SetNillablePhone sets the "phone" field if the given value is not nil. +func (dc *DepartmentCreate) SetNillablePhone(s *string) *DepartmentCreate { + if s != nil { + dc.SetPhone(*s) + } + return dc +} + // SetEmail sets the "email" field. func (dc *DepartmentCreate) SetEmail(s string) *DepartmentCreate { dc.mutation.SetEmail(s) return dc } +// SetNillableEmail sets the "email" field if the given value is not nil. +func (dc *DepartmentCreate) SetNillableEmail(s *string) *DepartmentCreate { + if s != nil { + dc.SetEmail(*s) + } + return dc +} + // SetRemark sets the "remark" field. func (dc *DepartmentCreate) SetRemark(s string) *DepartmentCreate { dc.mutation.SetRemark(s) @@ -256,15 +280,6 @@ func (dc *DepartmentCreate) check() error { if _, ok := dc.mutation.Name(); !ok { return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Department.name"`)} } - if _, ok := dc.mutation.Leader(); !ok { - return &ValidationError{Name: "leader", err: errors.New(`ent: missing required field "Department.leader"`)} - } - if _, ok := dc.mutation.Phone(); !ok { - return &ValidationError{Name: "phone", err: errors.New(`ent: missing required field "Department.phone"`)} - } - if _, ok := dc.mutation.Email(); !ok { - return &ValidationError{Name: "email", err: errors.New(`ent: missing required field "Department.email"`)} - } return nil } diff --git a/rpc/ent/department_update.go b/rpc/ent/department_update.go index 174c76ce..1c4fba3d 100644 --- a/rpc/ent/department_update.go +++ b/rpc/ent/department_update.go @@ -133,6 +133,12 @@ func (du *DepartmentUpdate) SetNillableLeader(s *string) *DepartmentUpdate { return du } +// ClearLeader clears the value of the "leader" field. +func (du *DepartmentUpdate) ClearLeader() *DepartmentUpdate { + du.mutation.ClearLeader() + return du +} + // SetPhone sets the "phone" field. func (du *DepartmentUpdate) SetPhone(s string) *DepartmentUpdate { du.mutation.SetPhone(s) @@ -147,6 +153,12 @@ func (du *DepartmentUpdate) SetNillablePhone(s *string) *DepartmentUpdate { return du } +// ClearPhone clears the value of the "phone" field. +func (du *DepartmentUpdate) ClearPhone() *DepartmentUpdate { + du.mutation.ClearPhone() + return du +} + // SetEmail sets the "email" field. func (du *DepartmentUpdate) SetEmail(s string) *DepartmentUpdate { du.mutation.SetEmail(s) @@ -161,6 +173,12 @@ func (du *DepartmentUpdate) SetNillableEmail(s *string) *DepartmentUpdate { return du } +// ClearEmail clears the value of the "email" field. +func (du *DepartmentUpdate) ClearEmail() *DepartmentUpdate { + du.mutation.ClearEmail() + return du +} + // SetRemark sets the "remark" field. func (du *DepartmentUpdate) SetRemark(s string) *DepartmentUpdate { du.mutation.SetRemark(s) @@ -370,12 +388,21 @@ func (du *DepartmentUpdate) sqlSave(ctx context.Context) (n int, err error) { if value, ok := du.mutation.Leader(); ok { _spec.SetField(department.FieldLeader, field.TypeString, value) } + if du.mutation.LeaderCleared() { + _spec.ClearField(department.FieldLeader, field.TypeString) + } if value, ok := du.mutation.Phone(); ok { _spec.SetField(department.FieldPhone, field.TypeString, value) } + if du.mutation.PhoneCleared() { + _spec.ClearField(department.FieldPhone, field.TypeString) + } if value, ok := du.mutation.Email(); ok { _spec.SetField(department.FieldEmail, field.TypeString, value) } + if du.mutation.EmailCleared() { + _spec.ClearField(department.FieldEmail, field.TypeString) + } if value, ok := du.mutation.Remark(); ok { _spec.SetField(department.FieldRemark, field.TypeString, value) } @@ -625,6 +652,12 @@ func (duo *DepartmentUpdateOne) SetNillableLeader(s *string) *DepartmentUpdateOn return duo } +// ClearLeader clears the value of the "leader" field. +func (duo *DepartmentUpdateOne) ClearLeader() *DepartmentUpdateOne { + duo.mutation.ClearLeader() + return duo +} + // SetPhone sets the "phone" field. func (duo *DepartmentUpdateOne) SetPhone(s string) *DepartmentUpdateOne { duo.mutation.SetPhone(s) @@ -639,6 +672,12 @@ func (duo *DepartmentUpdateOne) SetNillablePhone(s *string) *DepartmentUpdateOne return duo } +// ClearPhone clears the value of the "phone" field. +func (duo *DepartmentUpdateOne) ClearPhone() *DepartmentUpdateOne { + duo.mutation.ClearPhone() + return duo +} + // SetEmail sets the "email" field. func (duo *DepartmentUpdateOne) SetEmail(s string) *DepartmentUpdateOne { duo.mutation.SetEmail(s) @@ -653,6 +692,12 @@ func (duo *DepartmentUpdateOne) SetNillableEmail(s *string) *DepartmentUpdateOne return duo } +// ClearEmail clears the value of the "email" field. +func (duo *DepartmentUpdateOne) ClearEmail() *DepartmentUpdateOne { + duo.mutation.ClearEmail() + return duo +} + // SetRemark sets the "remark" field. func (duo *DepartmentUpdateOne) SetRemark(s string) *DepartmentUpdateOne { duo.mutation.SetRemark(s) @@ -892,12 +937,21 @@ func (duo *DepartmentUpdateOne) sqlSave(ctx context.Context) (_node *Department, if value, ok := duo.mutation.Leader(); ok { _spec.SetField(department.FieldLeader, field.TypeString, value) } + if duo.mutation.LeaderCleared() { + _spec.ClearField(department.FieldLeader, field.TypeString) + } if value, ok := duo.mutation.Phone(); ok { _spec.SetField(department.FieldPhone, field.TypeString, value) } + if duo.mutation.PhoneCleared() { + _spec.ClearField(department.FieldPhone, field.TypeString) + } if value, ok := duo.mutation.Email(); ok { _spec.SetField(department.FieldEmail, field.TypeString, value) } + if duo.mutation.EmailCleared() { + _spec.ClearField(department.FieldEmail, field.TypeString) + } if value, ok := duo.mutation.Remark(); ok { _spec.SetField(department.FieldRemark, field.TypeString, value) } diff --git a/rpc/ent/migrate/schema.go b/rpc/ent/migrate/schema.go index 4964f3c3..bb01f55b 100644 --- a/rpc/ent/migrate/schema.go +++ b/rpc/ent/migrate/schema.go @@ -43,9 +43,9 @@ var ( {Name: "sort", Type: field.TypeUint32, Comment: "Sort Number | 排序编号", Default: 1}, {Name: "name", Type: field.TypeString, Comment: "Department name | 部门名称"}, {Name: "ancestors", Type: field.TypeString, Nullable: true, Comment: "Parents' IDs | 父级列表"}, - {Name: "leader", Type: field.TypeString, Comment: "Department leader | 部门负责人"}, - {Name: "phone", Type: field.TypeString, Comment: "Leader's phone number | 负责人电话"}, - {Name: "email", Type: field.TypeString, Comment: "Leader's email | 部门负责人电子邮箱"}, + {Name: "leader", Type: field.TypeString, Nullable: true, Comment: "Department leader | 部门负责人"}, + {Name: "phone", Type: field.TypeString, Nullable: true, Comment: "Leader's phone number | 负责人电话"}, + {Name: "email", Type: field.TypeString, Nullable: true, Comment: "Leader's email | 部门负责人电子邮箱"}, {Name: "remark", Type: field.TypeString, Nullable: true, Comment: "Remark | 备注"}, {Name: "parent_id", Type: field.TypeUint64, Nullable: true, Comment: "Parent department ID | 父级部门ID", Default: 0}, } diff --git a/rpc/ent/mutation.go b/rpc/ent/mutation.go index eb4c30e8..cffdf269 100644 --- a/rpc/ent/mutation.go +++ b/rpc/ent/mutation.go @@ -1206,9 +1206,22 @@ func (m *DepartmentMutation) OldLeader(ctx context.Context) (v string, err error return oldValue.Leader, nil } +// ClearLeader clears the value of the "leader" field. +func (m *DepartmentMutation) ClearLeader() { + m.leader = nil + m.clearedFields[department.FieldLeader] = struct{}{} +} + +// LeaderCleared returns if the "leader" field was cleared in this mutation. +func (m *DepartmentMutation) LeaderCleared() bool { + _, ok := m.clearedFields[department.FieldLeader] + return ok +} + // ResetLeader resets all changes to the "leader" field. func (m *DepartmentMutation) ResetLeader() { m.leader = nil + delete(m.clearedFields, department.FieldLeader) } // SetPhone sets the "phone" field. @@ -1242,9 +1255,22 @@ func (m *DepartmentMutation) OldPhone(ctx context.Context) (v string, err error) return oldValue.Phone, nil } +// ClearPhone clears the value of the "phone" field. +func (m *DepartmentMutation) ClearPhone() { + m.phone = nil + m.clearedFields[department.FieldPhone] = struct{}{} +} + +// PhoneCleared returns if the "phone" field was cleared in this mutation. +func (m *DepartmentMutation) PhoneCleared() bool { + _, ok := m.clearedFields[department.FieldPhone] + return ok +} + // ResetPhone resets all changes to the "phone" field. func (m *DepartmentMutation) ResetPhone() { m.phone = nil + delete(m.clearedFields, department.FieldPhone) } // SetEmail sets the "email" field. @@ -1278,9 +1304,22 @@ func (m *DepartmentMutation) OldEmail(ctx context.Context) (v string, err error) return oldValue.Email, nil } +// ClearEmail clears the value of the "email" field. +func (m *DepartmentMutation) ClearEmail() { + m.email = nil + m.clearedFields[department.FieldEmail] = struct{}{} +} + +// EmailCleared returns if the "email" field was cleared in this mutation. +func (m *DepartmentMutation) EmailCleared() bool { + _, ok := m.clearedFields[department.FieldEmail] + return ok +} + // ResetEmail resets all changes to the "email" field. func (m *DepartmentMutation) ResetEmail() { m.email = nil + delete(m.clearedFields, department.FieldEmail) } // SetRemark sets the "remark" field. @@ -1794,6 +1833,15 @@ func (m *DepartmentMutation) ClearedFields() []string { if m.FieldCleared(department.FieldAncestors) { fields = append(fields, department.FieldAncestors) } + if m.FieldCleared(department.FieldLeader) { + fields = append(fields, department.FieldLeader) + } + if m.FieldCleared(department.FieldPhone) { + fields = append(fields, department.FieldPhone) + } + if m.FieldCleared(department.FieldEmail) { + fields = append(fields, department.FieldEmail) + } if m.FieldCleared(department.FieldRemark) { fields = append(fields, department.FieldRemark) } @@ -1820,6 +1868,15 @@ func (m *DepartmentMutation) ClearField(name string) error { case department.FieldAncestors: m.ClearAncestors() return nil + case department.FieldLeader: + m.ClearLeader() + return nil + case department.FieldPhone: + m.ClearPhone() + return nil + case department.FieldEmail: + m.ClearEmail() + return nil case department.FieldRemark: m.ClearRemark() return nil diff --git a/rpc/ent/schema/department.go b/rpc/ent/schema/department.go index aac63abb..23a2b0c0 100644 --- a/rpc/ent/schema/department.go +++ b/rpc/ent/schema/department.go @@ -22,13 +22,13 @@ func (Department) Fields() []ent.Field { Comment("Parents' IDs | 父级列表"). Annotations(entsql.WithComments(true)), field.String("leader"). - Comment("Department leader | 部门负责人"). + Comment("Department leader | 部门负责人").Optional(). Annotations(entsql.WithComments(true)), field.String("phone"). - Comment("Leader's phone number | 负责人电话"). + Comment("Leader's phone number | 负责人电话").Optional(). Annotations(entsql.WithComments(true)), field.String("email"). - Comment("Leader's email | 部门负责人电子邮箱"). + Comment("Leader's email | 部门负责人电子邮箱").Optional(). Annotations(entsql.WithComments(true)), field.String("remark").Optional(). Comment("Remark | 备注").