feat: 完善 dictionary 相关功能。

main
NoahLan 1 year ago
parent ec7677a6e9
commit 8d19325240

@ -47,6 +47,12 @@ const (
UserSocialUserIdNotEmpty code.Code = iota + 1500
)
// Dictionary
const (
DictionaryNameNotEmpty code.Code = iota + 1600
DictionaryNameInUsed
)
func init() {
// Common
msg.Add(WrongCode, "auth.wrongCode")

@ -27,38 +27,50 @@ enum DistrictQueryType {
Parents = 3;
}
message DepartmentReq {
message DepartmentInfo {
int64 ID = 1;
string name = 2;
int64 leader_id = 3;
int64 parent_id = 4;
bool with_leader = 5;
bool with_user = 6;
bool with_children = 7;
optional Pagination page = 10;
string status = 2;
string created_at = 3;
string updated_at = 4;
string name = 5;
int64 leader_id = 6;
string remark = 7;
int64 parent_id = 8;
DepartmentInfo parent = 10;
repeated DepartmentInfo children = 11;
repeated UserInfo users = 12;
UserInfo leader = 13;
}
message DepartmentListResp {
message DeleteDictionaryDetailReq {
repeated int64 ids = 1;
int64 dict_id = 2;
}
message UserSocialListResp {
optional Pagination page = 1;
repeated DepartmentInfo data = 2;
repeated UserSocialInfo data = 2;
}
message DictionaryReq {
int64 ID = 1;
//
message BaseResp {
int32 code = 1;
string msg = 2;
}
message GetDistrictNameResp {
string code = 1;
string name = 2;
string title = 3;
bool with_details = 4;
optional Pagination page = 10;
repeated string name_list = 3;
}
message DictionaryDetailReq {
message RecordReq {
int64 user_id = 1;
}
message OauthProviderListResp {
optional Pagination page = 1;
int64 ID = 2;
int64 dict_id = 3;
string title = 4;
string key = 5;
string value = 6;
bool with_dictionary = 7;
repeated OauthProviderInfo data = 2;
}
message TokenInfo {
@ -74,73 +86,74 @@ message TokenInfo {
UserInfo user = 10;
}
message OauthProviderInfo {
message UserReq {
int64 ID = 1;
string created_at = 2;
string updated_at = 3;
string name = 4;
string client_id = 5;
string client_secret = 6;
string redirect_url = 7;
string scopes = 8;
string auth_url = 9;
string token_url = 10;
string info_url = 11;
string description = 12;
bool system = 13;
bool init = 14;
string username = 2;
string phone_number = 3;
string email = 4;
string nickname = 5;
bool with_role = 6;
bool with_social = 7;
bool with_department = 8;
bool with_token = 9;
bool with_login_record = 10;
optional Pagination page = 20;
}
message RoleListResp {
message GetUserRolesReq {
optional Pagination page = 1;
repeated RoleInfo data = 2;
int64 user_id = 2;
}
message IDReq {
int64 ID = 1;
message DepartmentListResp {
optional Pagination page = 1;
repeated DepartmentInfo data = 2;
}
// DistrictInfo
message DistrictInfo {
int64 ID = 1;
string created_at = 2;
string updated_at = 3;
string name = 4;
string short_name = 5;
string code = 6;
string province = 7;
string city = 8;
string area = 9;
string street = 10;
uint32 level = 11;
double latitude = 12;
double longitude = 13;
repeated DistrictInfo children = 20;
message DictionaryDetailListResp {
optional Pagination page = 1;
repeated DictionaryDetailInfo data = 2;
}
message DistrictTree {
repeated DistrictInfo tree = 1;
message DistrictListResp {
optional Pagination page = 1;
repeated DistrictInfo data = 2;
}
message DistrictCodeReq {
string code = 1;
message OauthProviderReq {
int64 ID = 1;
string name = 2;
string client_id = 3;
optional bool system = 4;
optional bool init = 5;
optional Pagination page = 10;
}
message GetDistrictNameReq {
string code = 1;
string separator = 2;
message CallbackReq {
string state = 1;
string code = 2;
}
message LoginRecordInfo {
message OauthRedirectResp {
string url = 1;
}
message UserInfo {
int64 ID = 1;
string status = 2;
string created_at = 3;
string updated_at = 4;
int64 user_id = 5;
string last_login_at = 6;
string last_login_ipv4 = 7;
string last_login_device = 8;
string last_login_ua = 9;
uint64 login_count = 10;
string username = 5;
optional string phone_number = 6;
optional string email = 7;
string password = 8;
optional string nickname = 9;
map<string,string> metas = 10;
repeated RoleInfo roles = 20;
repeated UserSocialInfo socials = 21;
repeated DepartmentInfo departments = 22;
repeated TokenInfo tokens = 23;
LoginRecordInfo login_record = 24;
}
message UserRoleReq {
@ -149,12 +162,28 @@ message UserRoleReq {
repeated string role_codes = 3;
}
// Base message
message Empty {}
message DictionaryInfo {
int64 ID = 1;
string status = 2;
string created_at = 3;
string updated_at = 4;
string title = 5;
string name = 6;
string description = 7;
repeated DictionaryDetailInfo details = 10;
}
message DictionaryDetailListResp {
optional Pagination page = 1;
repeated DictionaryDetailInfo data = 2;
message DictionaryDetailInfo {
int64 ID = 1;
string status = 2;
string created_at = 3;
string updated_at = 4;
string title = 5;
string key = 6;
string value = 7;
uint32 sort = 8;
int64 dictionary_id = 9;
DictionaryInfo dictionary = 10;
}
message DistrictReq {
@ -170,14 +199,8 @@ message DistrictReq {
DistrictQueryType query_type = 11;
}
message OauthLoginReq {
string state = 1;
string provider = 2;
}
message GetUserRolesReq {
optional Pagination page = 1;
int64 user_id = 2;
message DistrictCodeReq {
string code = 1;
}
//
@ -187,35 +210,47 @@ message Pagination {
uint64 current = 3;
}
message DictionaryInfo {
message GetDistrictNameReq {
string code = 1;
string separator = 2;
}
message LoginRecordInfo {
int64 ID = 1;
string status = 2;
string created_at = 3;
string updated_at = 4;
string title = 5;
string name = 6;
string description = 7;
repeated DictionaryDetailInfo details = 10;
}
message OauthProviderListResp {
optional Pagination page = 1;
repeated OauthProviderInfo data = 2;
int64 user_id = 5;
string last_login_at = 6;
string last_login_ipv4 = 7;
string last_login_device = 8;
string last_login_ua = 9;
uint64 login_count = 10;
}
message TokenUserReq {
int64 user_id = 1;
message OauthProviderInfo {
int64 ID = 1;
string created_at = 2;
string updated_at = 3;
string name = 4;
string client_id = 5;
string client_secret = 6;
string redirect_url = 7;
string scopes = 8;
string auth_url = 9;
string token_url = 10;
string info_url = 11;
string description = 12;
bool system = 13;
bool init = 14;
}
message UserSocialListResp {
optional Pagination page = 1;
repeated UserSocialInfo data = 2;
message OauthLoginReq {
string state = 1;
string provider = 2;
}
message GetDistrictNameResp {
string code = 1;
string name = 2;
repeated string name_list = 3;
message TokenUserReq {
int64 user_id = 1;
}
message TokenReq {
@ -228,18 +263,32 @@ message TokenReq {
optional Pagination page = 10;
}
message UserReq {
message TokenListResp {
optional Pagination page = 1;
repeated TokenInfo data = 2;
}
message DictionaryDetailReq {
optional Pagination page = 1;
int64 ID = 2;
int64 dict_id = 3;
string title = 4;
string key = 5;
string value = 6;
bool with_dictionary = 7;
}
message DictionaryReq {
int64 ID = 1;
string username = 2;
string phone_number = 3;
string email = 4;
string nickname = 5;
bool with_role = 6;
bool with_social = 7;
bool with_department = 8;
bool with_token = 9;
bool with_login_record = 10;
optional Pagination page = 20;
string name = 2;
string title = 3;
bool with_details = 4;
optional Pagination page = 10;
}
message RoleListResp {
optional Pagination page = 1;
repeated RoleInfo data = 2;
}
message UserSocialInfo {
@ -259,44 +308,49 @@ message UserSocialInfo {
UserInfo user = 14;
}
message TokenListResp {
optional Pagination page = 1;
repeated TokenInfo data = 2;
}
message UserListResp {
optional Pagination page = 1;
repeated UserInfo data = 2;
}
//
message BaseResp {
int32 code = 1;
string msg = 2;
message DepartmentReq {
int64 ID = 1;
string name = 2;
int64 leader_id = 3;
int64 parent_id = 4;
bool with_leader = 5;
bool with_user = 6;
bool with_children = 7;
optional Pagination page = 10;
}
message DeleteDictionaryDetailReq {
repeated int64 ids = 1;
int64 dict_id = 2;
// ID
message BaseIDResp {
int64 ID = 1;
int32 code = 2;
string msg = 3;
}
message RecordReq {
int64 user_id = 1;
message DictionaryListResp {
optional Pagination page = 1;
repeated DictionaryInfo data = 2;
}
message OauthRedirectResp {
string url = 1;
// DistrictInfo
message DistrictInfo {
int64 ID = 1;
string created_at = 2;
string updated_at = 3;
string name = 4;
string short_name = 5;
string code = 6;
string province = 7;
string city = 8;
string area = 9;
string street = 10;
uint32 level = 11;
double latitude = 12;
double longitude = 13;
repeated DistrictInfo children = 20;
}
message RoleInfo {
int64 ID = 1;
string status = 2;
string created_at = 3;
string updated_at = 4;
string code = 5;
string name = 6;
string description = 7;
repeated UserInfo users = 10;
message DistrictTree {
repeated DistrictInfo tree = 1;
}
message RoleReq {
@ -307,49 +361,28 @@ message RoleReq {
optional Pagination page = 10;
}
message DictionaryDetailInfo {
int64 ID = 1;
string status = 2;
string created_at = 3;
string updated_at = 4;
string title = 5;
string key = 6;
string value = 7;
uint32 sort = 8;
int64 dictionary_id = 9;
DictionaryInfo dictionary = 10;
message UserListResp {
optional Pagination page = 1;
repeated UserInfo data = 2;
}
message DistrictListResp {
optional Pagination page = 1;
repeated DistrictInfo data = 2;
message IDsReq {
repeated int64 ids = 1;
}
message OauthProviderReq {
message IDReq {
int64 ID = 1;
string name = 2;
string client_id = 3;
optional bool system = 4;
optional bool init = 5;
optional Pagination page = 10;
}
message UserInfo {
message RoleInfo {
int64 ID = 1;
string status = 2;
string created_at = 3;
string updated_at = 4;
string username = 5;
optional string phone_number = 6;
optional string email = 7;
string password = 8;
optional string nickname = 9;
map<string,string> metas = 10;
repeated RoleInfo roles = 20;
repeated UserSocialInfo socials = 21;
repeated DepartmentInfo departments = 22;
repeated TokenInfo tokens = 23;
LoginRecordInfo login_record = 24;
string code = 5;
string name = 6;
string description = 7;
repeated UserInfo users = 10;
}
message UserSocialReq {
@ -364,41 +397,8 @@ message UserSocialReq {
optional Pagination page = 10;
}
message IDsReq {
repeated int64 ids = 1;
}
// ID
message BaseIDResp {
int64 ID = 1;
int32 code = 2;
string msg = 3;
}
message DepartmentInfo {
int64 ID = 1;
string status = 2;
string created_at = 3;
string updated_at = 4;
string name = 5;
int64 leader_id = 6;
string remark = 7;
int64 parent_id = 8;
DepartmentInfo parent = 10;
repeated DepartmentInfo children = 11;
repeated UserInfo users = 12;
UserInfo leader = 13;
}
message DictionaryListResp {
optional Pagination page = 1;
repeated DictionaryInfo data = 2;
}
message CallbackReq {
string state = 1;
string code = 2;
}
// Base message
message Empty {}
service Core {
// group: base
@ -420,9 +420,9 @@ service Core {
// group: dictionary
rpc updateDictionary(DictionaryInfo) returns (BaseResp);
// group: dictionary
rpc getDictionaryList(UserReq) returns (UserListResp);
rpc getDictionaryList(DictionaryReq) returns (DictionaryListResp);
// group: dictionary
rpc getDictionary(UserReq) returns (DictionaryInfo);
rpc getDictionary(DictionaryReq) returns (DictionaryInfo);
// group: dictionary
rpc deleteDictionary(IDsReq) returns (BaseResp);
// Details

@ -71,8 +71,8 @@ type (
// Dictionary Management
CreateDictionary(ctx context.Context, in *DictionaryInfo, opts ...grpc.CallOption) (*BaseIDResp, error)
UpdateDictionary(ctx context.Context, in *DictionaryInfo, opts ...grpc.CallOption) (*BaseResp, error)
GetDictionaryList(ctx context.Context, in *UserReq, opts ...grpc.CallOption) (*UserListResp, error)
GetDictionary(ctx context.Context, in *UserReq, opts ...grpc.CallOption) (*DictionaryInfo, error)
GetDictionaryList(ctx context.Context, in *DictionaryReq, opts ...grpc.CallOption) (*DictionaryListResp, error)
GetDictionary(ctx context.Context, in *DictionaryReq, opts ...grpc.CallOption) (*DictionaryInfo, error)
DeleteDictionary(ctx context.Context, in *IDsReq, opts ...grpc.CallOption) (*BaseResp, error)
// Details
CreateDictionaryDetail(ctx context.Context, in *DictionaryDetailInfo, opts ...grpc.CallOption) (*BaseIDResp, error)
@ -184,12 +184,12 @@ func (m *defaultCore) UpdateDictionary(ctx context.Context, in *DictionaryInfo,
return client.UpdateDictionary(ctx, in, opts...)
}
func (m *defaultCore) GetDictionaryList(ctx context.Context, in *UserReq, opts ...grpc.CallOption) (*UserListResp, error) {
func (m *defaultCore) GetDictionaryList(ctx context.Context, in *DictionaryReq, opts ...grpc.CallOption) (*DictionaryListResp, error) {
client := core.NewCoreClient(m.cli.Conn())
return client.GetDictionaryList(ctx, in, opts...)
}
func (m *defaultCore) GetDictionary(ctx context.Context, in *UserReq, opts ...grpc.CallOption) (*DictionaryInfo, error) {
func (m *defaultCore) GetDictionary(ctx context.Context, in *DictionaryReq, opts ...grpc.CallOption) (*DictionaryInfo, error) {
client := core.NewCoreClient(m.cli.Conn())
return client.GetDictionary(ctx, in, opts...)
}

@ -73,9 +73,9 @@ service Core {
// group: dictionary
rpc updateDictionary (DictionaryInfo) returns (BaseResp);
// group: dictionary
rpc getDictionaryList (UserReq) returns (UserListResp);
rpc getDictionaryList (DictionaryReq) returns (DictionaryListResp);
// group: dictionary
rpc getDictionary (UserReq) returns (DictionaryInfo);
rpc getDictionary (DictionaryReq) returns (DictionaryInfo);
// group: dictionary
rpc deleteDictionary (IDsReq) returns (BaseResp);
// Details

@ -34,7 +34,7 @@ const (
// EdgeDetails holds the string denoting the details edge name in mutations.
EdgeDetails = "details"
// Table holds the table name of the dictionary in the database.
Table = "sys_dictionaries"
Table = "sys_dictionary"
// DetailsTable is the table that holds the details relation/edge.
DetailsTable = "sys_dictionary_details"
// DetailsInverseTable is the table name for the DictionaryDetail entity.

@ -38,7 +38,7 @@ const (
DictionaryTable = "sys_dictionary_details"
// DictionaryInverseTable is the table name for the Dictionary entity.
// It exists in this package in order to avoid circular dependency with the "dictionary" package.
DictionaryInverseTable = "sys_dictionaries"
DictionaryInverseTable = "sys_dictionary"
// DictionaryColumn is the table column denoting the dictionary relation/edge.
DictionaryColumn = "dictionary_id"
)

@ -42,8 +42,8 @@ var (
},
},
}
// SysDictionariesColumns holds the columns for the "sys_dictionaries" table.
SysDictionariesColumns = []*schema.Column{
// SysDictionaryColumns holds the columns for the "sys_dictionary" table.
SysDictionaryColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Comment: "Primary Key | 主键"},
{Name: "created_at", Type: field.TypeTime, Comment: "Create Time | 创建时间", SchemaType: map[string]string{"mysql": "datetime"}},
{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 更新时间", SchemaType: map[string]string{"mysql": "datetime"}},
@ -53,12 +53,12 @@ var (
{Name: "name", Type: field.TypeString, Unique: true, Comment: "The name of dictionary for search | 字典搜索名称"},
{Name: "description", Type: field.TypeString, Nullable: true, Comment: "The description of dictionary | 字典的描述"},
}
// SysDictionariesTable holds the schema information for the "sys_dictionaries" table.
SysDictionariesTable = &schema.Table{
Name: "sys_dictionaries",
// SysDictionaryTable holds the schema information for the "sys_dictionary" table.
SysDictionaryTable = &schema.Table{
Name: "sys_dictionary",
Comment: "字典表",
Columns: SysDictionariesColumns,
PrimaryKey: []*schema.Column{SysDictionariesColumns[0]},
Columns: SysDictionaryColumns,
PrimaryKey: []*schema.Column{SysDictionaryColumns[0]},
}
// SysDictionaryDetailsColumns holds the columns for the "sys_dictionary_details" table.
SysDictionaryDetailsColumns = []*schema.Column{
@ -79,10 +79,10 @@ var (
PrimaryKey: []*schema.Column{SysDictionaryDetailsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "sys_dictionary_details_sys_dictionaries_details",
Symbol: "sys_dictionary_details_sys_dictionary_details",
Columns: []*schema.Column{SysDictionaryDetailsColumns[7]},
RefColumns: []*schema.Column{SysDictionariesColumns[0]},
OnDelete: schema.NoAction,
RefColumns: []*schema.Column{SysDictionaryColumns[0]},
OnDelete: schema.Cascade,
},
},
}
@ -133,7 +133,7 @@ var (
Symbol: "sys_login_record_sys_user_loginRecord",
Columns: []*schema.Column{SysLoginRecordColumns[9]},
RefColumns: []*schema.Column{SysUserColumns[0]},
OnDelete: schema.NoAction,
OnDelete: schema.Cascade,
},
},
}
@ -206,7 +206,7 @@ var (
Symbol: "sys_token_sys_user_token",
Columns: []*schema.Column{SysTokenColumns[10]},
RefColumns: []*schema.Column{SysUserColumns[0]},
OnDelete: schema.NoAction,
OnDelete: schema.Cascade,
},
},
}
@ -217,7 +217,6 @@ var (
{Name: "created_at", Type: field.TypeTime, Comment: "Create Time | 创建时间", SchemaType: map[string]string{"mysql": "datetime"}},
{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 更新时间", SchemaType: map[string]string{"mysql": "datetime"}},
{Name: "version", Type: field.TypeInt64, Comment: "optimistic lock | 乐观锁", Default: 1},
{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Soft delete | 软删除(逻辑删除)", SchemaType: map[string]string{"mysql": "datetime"}},
{Name: "username", Type: field.TypeString, Unique: true, Comment: "User's login name | 登录名"},
{Name: "phone_number", Type: field.TypeString, Unique: true, Nullable: true, Comment: "Phone number | 手机号"},
{Name: "email", Type: field.TypeString, Unique: true, Nullable: true, Comment: "Email | 邮箱号"},
@ -252,7 +251,7 @@ var (
Symbol: "sys_usermeta_sys_user_metas",
Columns: []*schema.Column{SysUsermetaColumns[6]},
RefColumns: []*schema.Column{SysUserColumns[0]},
OnDelete: schema.NoAction,
OnDelete: schema.Cascade,
},
},
Indexes: []*schema.Index{
@ -300,7 +299,7 @@ var (
Symbol: "sys_user_social_sys_user_socials",
Columns: []*schema.Column{SysUserSocialColumns[12]},
RefColumns: []*schema.Column{SysUserColumns[0]},
OnDelete: schema.NoAction,
OnDelete: schema.Cascade,
},
},
}
@ -357,7 +356,7 @@ var (
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
SysDepartmentTable,
SysDictionariesTable,
SysDictionaryTable,
SysDictionaryDetailsTable,
SysDistrictTable,
SysLoginRecordTable,
@ -378,10 +377,10 @@ func init() {
SysDepartmentTable.Annotation = &entsql.Annotation{
Table: "sys_department",
}
SysDictionariesTable.Annotation = &entsql.Annotation{
Table: "sys_dictionaries",
SysDictionaryTable.Annotation = &entsql.Annotation{
Table: "sys_dictionary",
}
SysDictionaryDetailsTable.ForeignKeys[0].RefTable = SysDictionariesTable
SysDictionaryDetailsTable.ForeignKeys[0].RefTable = SysDictionaryTable
SysDictionaryDetailsTable.Annotation = &entsql.Annotation{
Table: "sys_dictionary_details",
}

@ -7612,7 +7612,6 @@ type UserMutation struct {
updated_at *time.Time
version *int64
addversion *int64
deleted_at *time.Time
username *string
phone_number *string
email *string
@ -7909,55 +7908,6 @@ func (m *UserMutation) ResetVersion() {
m.addversion = nil
}
// SetDeletedAt sets the "deleted_at" field.
func (m *UserMutation) SetDeletedAt(t time.Time) {
m.deleted_at = &t
}
// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *UserMutation) DeletedAt() (r time.Time, exists bool) {
v := m.deleted_at
if v == nil {
return
}
return *v, true
}
// OldDeletedAt returns the old "deleted_at" field's value of the User entity.
// If the User 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 *UserMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDeletedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
}
return oldValue.DeletedAt, nil
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *UserMutation) ClearDeletedAt() {
m.deleted_at = nil
m.clearedFields[user.FieldDeletedAt] = struct{}{}
}
// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *UserMutation) DeletedAtCleared() bool {
_, ok := m.clearedFields[user.FieldDeletedAt]
return ok
}
// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *UserMutation) ResetDeletedAt() {
m.deleted_at = nil
delete(m.clearedFields, user.FieldDeletedAt)
}
// SetUsername sets the "username" field.
func (m *UserMutation) SetUsername(s string) {
m.username = &s
@ -8520,7 +8470,7 @@ func (m *UserMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *UserMutation) Fields() []string {
fields := make([]string, 0, 10)
fields := make([]string, 0, 9)
if m.status != nil {
fields = append(fields, user.FieldStatus)
}
@ -8533,9 +8483,6 @@ func (m *UserMutation) Fields() []string {
if m.version != nil {
fields = append(fields, user.FieldVersion)
}
if m.deleted_at != nil {
fields = append(fields, user.FieldDeletedAt)
}
if m.username != nil {
fields = append(fields, user.FieldUsername)
}
@ -8567,8 +8514,6 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) {
return m.UpdatedAt()
case user.FieldVersion:
return m.Version()
case user.FieldDeletedAt:
return m.DeletedAt()
case user.FieldUsername:
return m.Username()
case user.FieldPhoneNumber:
@ -8596,8 +8541,6 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er
return m.OldUpdatedAt(ctx)
case user.FieldVersion:
return m.OldVersion(ctx)
case user.FieldDeletedAt:
return m.OldDeletedAt(ctx)
case user.FieldUsername:
return m.OldUsername(ctx)
case user.FieldPhoneNumber:
@ -8645,13 +8588,6 @@ func (m *UserMutation) SetField(name string, value ent.Value) error {
}
m.SetVersion(v)
return nil
case user.FieldDeletedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDeletedAt(v)
return nil
case user.FieldUsername:
v, ok := value.(string)
if !ok {
@ -8732,9 +8668,6 @@ func (m *UserMutation) AddField(name string, value ent.Value) error {
// mutation.
func (m *UserMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(user.FieldDeletedAt) {
fields = append(fields, user.FieldDeletedAt)
}
if m.FieldCleared(user.FieldPhoneNumber) {
fields = append(fields, user.FieldPhoneNumber)
}
@ -8758,9 +8691,6 @@ func (m *UserMutation) FieldCleared(name string) bool {
// error if the field is not defined in the schema.
func (m *UserMutation) ClearField(name string) error {
switch name {
case user.FieldDeletedAt:
m.ClearDeletedAt()
return nil
case user.FieldPhoneNumber:
m.ClearPhoneNumber()
return nil
@ -8790,9 +8720,6 @@ func (m *UserMutation) ResetField(name string) error {
case user.FieldVersion:
m.ResetVersion()
return nil
case user.FieldDeletedAt:
m.ResetDeletedAt()
return nil
case user.FieldUsername:
m.ResetUsername()
return nil

@ -37,7 +37,9 @@ func (Dictionary) Mixin() []ent.Mixin {
func (Dictionary) Edges() []ent.Edge {
return []ent.Edge{
edge.To("details", DictionaryDetail.Type), // one to many
// one to many
edge.To("details", DictionaryDetail.Type).
Annotations(entsql.OnDelete(entsql.Cascade)),
}
}

@ -6,7 +6,6 @@ import (
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
mixins2 "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/schema/mixins"
"git.noahlan.cn/noahlan/ntool-biz/core/orm/nent/mixins"
"git.noahlan.cn/noahlan/ntool/nrandom"
)
@ -32,18 +31,28 @@ func (User) Mixin() []ent.Mixin {
mixins.StatusMixin{},
mixins.TimeMixin{},
mixins.OptimisticLockMixin{},
mixins2.SoftDeleteMixin{},
}
}
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("metas", UserMeta.Type), // one to many
edge.To("roles", Role.Type), // one to many
edge.To("socials", UserSocial.Type), // one to many
edge.To("departments", Department.Type), // one to many
edge.To("token", Token.Type), // one to many
edge.To("loginRecord", LoginRecord.Type).Unique(), // one to one
// one to many
edge.To("metas", UserMeta.Type).
Annotations(entsql.OnDelete(entsql.Cascade)),
// one to many
edge.To("roles", Role.Type),
// one to many
edge.To("socials", UserSocial.Type).
Annotations(entsql.OnDelete(entsql.Cascade)),
// one to many
edge.To("departments", Department.Type),
// one to many
edge.To("token", Token.Type).
Annotations(entsql.OnDelete(entsql.Cascade)),
// one to one
edge.To("loginRecord", LoginRecord.Type).
Annotations(entsql.OnDelete(entsql.Cascade)).
Unique(),
}
}

@ -1712,30 +1712,6 @@ func (u *UserCreate) SetNotNilVersion(value *int64) *UserCreate {
return u
}
// set field if value's pointer is not nil.
func (u *UserUpdate) SetNotNilDeletedAt(value *time.Time) *UserUpdate {
if value != nil {
return u.SetDeletedAt(*value)
}
return u
}
// set field if value's pointer is not nil.
func (u *UserUpdateOne) SetNotNilDeletedAt(value *time.Time) *UserUpdateOne {
if value != nil {
return u.SetDeletedAt(*value)
}
return u
}
// set field if value's pointer is not nil.
func (u *UserCreate) SetNotNilDeletedAt(value *time.Time) *UserCreate {
if value != nil {
return u.SetDeletedAt(*value)
}
return u
}
// set field if value's pointer is not nil.
func (u *UserUpdate) SetNotNilUsername(value *string) *UserUpdate {
if value != nil {

@ -28,8 +28,6 @@ type User struct {
UpdatedAt time.Time `json:"updated_at,omitempty"`
// optimistic lock | 乐观锁
Version int64 `json:"version,omitempty"`
// Soft delete | 软删除(逻辑删除)
DeletedAt time.Time `json:"deleted_at,omitempty"`
// User's login name | 登录名
Username string `json:"username,omitempty"`
// Phone number | 手机号
@ -132,7 +130,7 @@ func (*User) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullInt64)
case user.FieldStatus, user.FieldUsername, user.FieldPhoneNumber, user.FieldEmail, user.FieldPassword, user.FieldNickname:
values[i] = new(sql.NullString)
case user.FieldCreatedAt, user.FieldUpdatedAt, user.FieldDeletedAt:
case user.FieldCreatedAt, user.FieldUpdatedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
@ -179,12 +177,6 @@ func (u *User) assignValues(columns []string, values []any) error {
} else if value.Valid {
u.Version = value.Int64
}
case user.FieldDeletedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
} else if value.Valid {
u.DeletedAt = value.Time
}
case user.FieldUsername:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field username", values[i])
@ -296,9 +288,6 @@ func (u *User) String() string {
builder.WriteString("version=")
builder.WriteString(fmt.Sprintf("%v", u.Version))
builder.WriteString(", ")
builder.WriteString("deleted_at=")
builder.WriteString(u.DeletedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("username=")
builder.WriteString(u.Username)
builder.WriteString(", ")

@ -25,8 +25,6 @@ const (
FieldUpdatedAt = "updated_at"
// FieldVersion holds the string denoting the version field in the database.
FieldVersion = "version"
// FieldDeletedAt holds the string denoting the deleted_at field in the database.
FieldDeletedAt = "deleted_at"
// FieldUsername holds the string denoting the username field in the database.
FieldUsername = "username"
// FieldPhoneNumber holds the string denoting the phone_number field in the database.
@ -98,7 +96,6 @@ var Columns = []string{
FieldCreatedAt,
FieldUpdatedAt,
FieldVersion,
FieldDeletedAt,
FieldUsername,
FieldPhoneNumber,
FieldEmail,
@ -184,11 +181,6 @@ func ByVersion(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldVersion, opts...).ToFunc()
}
// ByDeletedAt orders the results by the deleted_at field.
func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
}
// ByUsername orders the results by the username field.
func ByUsername(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUsername, opts...).ToFunc()

@ -71,11 +71,6 @@ func Version(v int64) predicate.User {
return predicate.User(sql.FieldEQ(FieldVersion, v))
}
// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ.
func DeletedAt(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldDeletedAt, v))
}
// Username applies equality check predicate on the "username" field. It's identical to UsernameEQ.
func Username(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldUsername, v))
@ -251,56 +246,6 @@ func VersionLTE(v int64) predicate.User {
return predicate.User(sql.FieldLTE(FieldVersion, v))
}
// DeletedAtEQ applies the EQ predicate on the "deleted_at" field.
func DeletedAtEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldDeletedAt, v))
}
// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field.
func DeletedAtNEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldNEQ(FieldDeletedAt, v))
}
// DeletedAtIn applies the In predicate on the "deleted_at" field.
func DeletedAtIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldIn(FieldDeletedAt, vs...))
}
// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field.
func DeletedAtNotIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldNotIn(FieldDeletedAt, vs...))
}
// DeletedAtGT applies the GT predicate on the "deleted_at" field.
func DeletedAtGT(v time.Time) predicate.User {
return predicate.User(sql.FieldGT(FieldDeletedAt, v))
}
// DeletedAtGTE applies the GTE predicate on the "deleted_at" field.
func DeletedAtGTE(v time.Time) predicate.User {
return predicate.User(sql.FieldGTE(FieldDeletedAt, v))
}
// DeletedAtLT applies the LT predicate on the "deleted_at" field.
func DeletedAtLT(v time.Time) predicate.User {
return predicate.User(sql.FieldLT(FieldDeletedAt, v))
}
// DeletedAtLTE applies the LTE predicate on the "deleted_at" field.
func DeletedAtLTE(v time.Time) predicate.User {
return predicate.User(sql.FieldLTE(FieldDeletedAt, v))
}
// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field.
func DeletedAtIsNil() predicate.User {
return predicate.User(sql.FieldIsNull(FieldDeletedAt))
}
// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field.
func DeletedAtNotNil() predicate.User {
return predicate.User(sql.FieldNotNull(FieldDeletedAt))
}
// UsernameEQ applies the EQ predicate on the "username" field.
func UsernameEQ(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldUsername, v))

@ -85,20 +85,6 @@ func (uc *UserCreate) SetNillableVersion(i *int64) *UserCreate {
return uc
}
// SetDeletedAt sets the "deleted_at" field.
func (uc *UserCreate) SetDeletedAt(t time.Time) *UserCreate {
uc.mutation.SetDeletedAt(t)
return uc
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (uc *UserCreate) SetNillableDeletedAt(t *time.Time) *UserCreate {
if t != nil {
uc.SetDeletedAt(*t)
}
return uc
}
// SetUsername sets the "username" field.
func (uc *UserCreate) SetUsername(s string) *UserCreate {
uc.mutation.SetUsername(s)
@ -404,10 +390,6 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
_spec.SetField(user.FieldVersion, field.TypeInt64, value)
_node.Version = value
}
if value, ok := uc.mutation.DeletedAt(); ok {
_spec.SetField(user.FieldDeletedAt, field.TypeTime, value)
_node.DeletedAt = value
}
if value, ok := uc.mutation.Username(); ok {
_spec.SetField(user.FieldUsername, field.TypeString, value)
_node.Username = value
@ -618,24 +600,6 @@ func (u *UserUpsert) AddVersion(v int64) *UserUpsert {
return u
}
// SetDeletedAt sets the "deleted_at" field.
func (u *UserUpsert) SetDeletedAt(v time.Time) *UserUpsert {
u.Set(user.FieldDeletedAt, v)
return u
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *UserUpsert) UpdateDeletedAt() *UserUpsert {
u.SetExcluded(user.FieldDeletedAt)
return u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *UserUpsert) ClearDeletedAt() *UserUpsert {
u.SetNull(user.FieldDeletedAt)
return u
}
// SetUsername sets the "username" field.
func (u *UserUpsert) SetUsername(v string) *UserUpsert {
u.Set(user.FieldUsername, v)
@ -814,27 +778,6 @@ func (u *UserUpsertOne) UpdateVersion() *UserUpsertOne {
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *UserUpsertOne) SetDeletedAt(v time.Time) *UserUpsertOne {
return u.Update(func(s *UserUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *UserUpsertOne) UpdateDeletedAt() *UserUpsertOne {
return u.Update(func(s *UserUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *UserUpsertOne) ClearDeletedAt() *UserUpsertOne {
return u.Update(func(s *UserUpsert) {
s.ClearDeletedAt()
})
}
// SetUsername sets the "username" field.
func (u *UserUpsertOne) SetUsername(v string) *UserUpsertOne {
return u.Update(func(s *UserUpsert) {
@ -1188,27 +1131,6 @@ func (u *UserUpsertBulk) UpdateVersion() *UserUpsertBulk {
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *UserUpsertBulk) SetDeletedAt(v time.Time) *UserUpsertBulk {
return u.Update(func(s *UserUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *UserUpsertBulk) UpdateDeletedAt() *UserUpsertBulk {
return u.Update(func(s *UserUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *UserUpsertBulk) ClearDeletedAt() *UserUpsertBulk {
return u.Update(func(s *UserUpsert) {
s.ClearDeletedAt()
})
}
// SetUsername sets the "username" field.
func (u *UserUpsertBulk) SetUsername(v string) *UserUpsertBulk {
return u.Update(func(s *UserUpsert) {

@ -77,26 +77,6 @@ func (uu *UserUpdate) AddVersion(i int64) *UserUpdate {
return uu
}
// SetDeletedAt sets the "deleted_at" field.
func (uu *UserUpdate) SetDeletedAt(t time.Time) *UserUpdate {
uu.mutation.SetDeletedAt(t)
return uu
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (uu *UserUpdate) SetNillableDeletedAt(t *time.Time) *UserUpdate {
if t != nil {
uu.SetDeletedAt(*t)
}
return uu
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (uu *UserUpdate) ClearDeletedAt() *UserUpdate {
uu.mutation.ClearDeletedAt()
return uu
}
// SetUsername sets the "username" field.
func (uu *UserUpdate) SetUsername(s string) *UserUpdate {
uu.mutation.SetUsername(s)
@ -461,12 +441,6 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
if value, ok := uu.mutation.AddedVersion(); ok {
_spec.AddField(user.FieldVersion, field.TypeInt64, value)
}
if value, ok := uu.mutation.DeletedAt(); ok {
_spec.SetField(user.FieldDeletedAt, field.TypeTime, value)
}
if uu.mutation.DeletedAtCleared() {
_spec.ClearField(user.FieldDeletedAt, field.TypeTime)
}
if value, ok := uu.mutation.Username(); ok {
_spec.SetField(user.FieldUsername, field.TypeString, value)
}
@ -808,26 +782,6 @@ func (uuo *UserUpdateOne) AddVersion(i int64) *UserUpdateOne {
return uuo
}
// SetDeletedAt sets the "deleted_at" field.
func (uuo *UserUpdateOne) SetDeletedAt(t time.Time) *UserUpdateOne {
uuo.mutation.SetDeletedAt(t)
return uuo
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableDeletedAt(t *time.Time) *UserUpdateOne {
if t != nil {
uuo.SetDeletedAt(*t)
}
return uuo
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (uuo *UserUpdateOne) ClearDeletedAt() *UserUpdateOne {
uuo.mutation.ClearDeletedAt()
return uuo
}
// SetUsername sets the "username" field.
func (uuo *UserUpdateOne) SetUsername(s string) *UserUpdateOne {
uuo.mutation.SetUsername(s)
@ -1222,12 +1176,6 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
if value, ok := uuo.mutation.AddedVersion(); ok {
_spec.AddField(user.FieldVersion, field.TypeInt64, value)
}
if value, ok := uuo.mutation.DeletedAt(); ok {
_spec.SetField(user.FieldDeletedAt, field.TypeTime, value)
}
if uuo.mutation.DeletedAtCleared() {
_spec.ClearField(user.FieldDeletedAt, field.TypeTime)
}
if value, ok := uuo.mutation.Username(); ok {
_spec.SetField(user.FieldUsername, field.TypeString, value)
}

@ -2,6 +2,15 @@ package dictionary
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/dal/errx"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/dictionary"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/entx"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"
"git.noahlan.cn/noahlan/ntool-biz/core/orm/nent/types"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -21,7 +30,42 @@ func NewCreateDictionaryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
// Dictionary Management
func (l *CreateDictionaryLogic) CreateDictionary(in *core.DictionaryInfo) (*core.BaseIDResp, error) {
// todo: add your logic here and delete this line
var dbData *ent.Dictionary
if err := entx.WithTx(l.ctx, l.svcCtx.DB, func(tx *ent.Tx) error {
var err error
if err := l.preCheck(tx, in); err != nil {
return err
}
dbData, err = tx.Dictionary.Create().
SetStatus(types.ParseStatus(in.Status)).
SetTitle(in.Title).
SetName(in.Name).
SetDescription(in.Description).Save(l.ctx)
if err != nil {
return hander.HandleEntErr(err, in)
}
return nil
}); err != nil {
return nil, err
}
return &core.BaseIDResp{
ID: dbData.ID,
Code: code.StatusOK,
Msg: msg.CreateSuccess,
}, nil
}
return &core.BaseIDResp{}, nil
func (l *CreateDictionaryLogic) preCheck(tx *ent.Tx, in *core.DictionaryInfo) error {
if in.Name == "" {
return nstatus.NewBizErrWithCode(errx.DictionaryNameNotEmpty)
} else {
exist, err := tx.Dictionary.Query().Where(dictionary.NameEQ(in.Name)).Exist(l.ctx)
if err != nil {
return hander.HandleEntErr(err, in)
}
if exist {
return nstatus.NewBizErrWithCode(errx.DictionaryNameInUsed)
}
}
return nil
}

@ -2,6 +2,10 @@ package dictionary
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/dictionary"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -20,7 +24,12 @@ func NewDeleteDictionaryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
func (l *DeleteDictionaryLogic) DeleteDictionary(in *core.IDsReq) (*core.BaseResp, error) {
// todo: add your logic here and delete this line
return &core.BaseResp{}, nil
_, err := l.svcCtx.DB.Dictionary.Delete().Where(dictionary.IDIn(in.Ids...)).Exec(l.ctx)
if err != nil {
return nil, hander.HandleEntErr(err, in)
}
return &core.BaseResp{
Code: code.StatusOK,
Msg: msg.DeleteSuccess,
}, nil
}

@ -2,6 +2,11 @@ package dictionary
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/dictionary"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/predicate"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -19,8 +24,45 @@ func NewGetDictionaryListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
}
func (l *GetDictionaryListLogic) GetDictionaryList(in *core.UserReq) (*core.UserListResp, error) {
// todo: add your logic here and delete this line
func (l *GetDictionaryListLogic) GetDictionaryList(in *core.DictionaryReq) (*core.DictionaryListResp, error) {
var predicates []predicate.Dictionary
if in.Name != "" {
predicates = append(predicates, dictionary.NameContains(in.Name))
}
if in.Title != "" {
predicates = append(predicates, dictionary.TitleContains(in.Title))
}
query := l.svcCtx.DB.Dictionary.Query().Where(predicates...)
if in.WithDetails {
query.WithDetails()
}
var (
pagination *core.Pagination
list []*ent.Dictionary
err error
)
if in.Page != nil {
result, pageErr := query.Page(l.ctx, in.Page.Current, in.Page.Size)
if pageErr == nil {
pagination = utils.ConvertPaginationDb(result.PageDetails)
list = result.List
} else {
err = pageErr
}
} else {
list, err = query.All(l.ctx)
}
if err != nil {
return nil, hander.HandleEntErr(err, in)
}
resp := &core.DictionaryListResp{
Page: pagination,
Data: make([]*core.DictionaryInfo, len(list)),
}
return &core.UserListResp{}, nil
for i, v := range list {
resp.Data[i] = l.svcCtx.Convert.ConvertDictionaryRpc(l.ctx, v)
}
return resp, nil
}

@ -2,6 +2,9 @@ package dictionary
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/dictionary"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/predicate"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -19,8 +22,30 @@ func NewGetDictionaryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get
}
}
func (l *GetDictionaryLogic) GetDictionary(in *core.UserReq) (*core.DictionaryInfo, error) {
// todo: add your logic here and delete this line
func (l *GetDictionaryLogic) GetDictionary(in *core.DictionaryReq) (*core.DictionaryInfo, error) {
var predicates []predicate.Dictionary
if in.ID != 0 {
predicates = append(predicates, dictionary.IDEQ(in.ID))
goto Query
}
if in.Name != "" {
predicates = append(predicates, dictionary.NameEQ(in.Name))
}
if in.Title != "" {
predicates = append(predicates, dictionary.TitleEQ(in.Title))
}
if len(predicates) == 0 {
return nil, nil
}
Query:
query := l.svcCtx.DB.Dictionary.Query().Where(predicates...)
if in.WithDetails {
query.WithDetails()
}
dbData, err := query.First(l.ctx)
if err != nil {
return nil, hander.HandleEntErr(err, in)
}
return &core.DictionaryInfo{}, nil
return l.svcCtx.Convert.ConvertDictionaryRpc(l.ctx, dbData), nil
}

@ -2,9 +2,17 @@ package dictionary
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/dal/errx"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/dictionary"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/entx"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"
"git.noahlan.cn/noahlan/ntool-biz/core/orm/nent/types"
)
type UpdateDictionaryLogic struct {
@ -20,7 +28,43 @@ func NewUpdateDictionaryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
func (l *UpdateDictionaryLogic) UpdateDictionary(in *core.DictionaryInfo) (*core.BaseResp, error) {
// todo: add your logic here and delete this line
if err := entx.WithTx(l.ctx, l.svcCtx.DB, func(tx *ent.Tx) error {
var err error
if err := l.preCheck(tx, in); err != nil {
return err
}
update := tx.Dictionary.Update().Where(dictionary.IDEQ(in.ID))
update.SetNotEmptyTitle(in.Title).
SetNotEmptyName(in.Name).
SetNotEmptyDescription(in.Description)
if in.Status != "" {
update.SetStatus(types.ParseStatus(in.Status))
}
err = update.Exec(l.ctx)
if err != nil {
return hander.HandleEntErr(err, in)
}
return nil
}); err != nil {
return nil, err
}
return &core.BaseResp{
Code: code.StatusOK,
Msg: msg.UpdateSuccess,
}, nil
}
return &core.BaseResp{}, nil
func (l *UpdateDictionaryLogic) preCheck(tx *ent.Tx, in *core.DictionaryInfo) error {
if in.Name == "" {
return nstatus.NewBizErrWithCode(errx.DictionaryNameNotEmpty)
} else {
exist, err := tx.Dictionary.Query().Where(dictionary.NameEQ(in.Name)).Exist(l.ctx)
if err != nil {
return hander.HandleEntErr(err, in)
}
if exist {
return nstatus.NewBizErrWithCode(errx.DictionaryNameInUsed)
}
}
return nil
}

@ -74,12 +74,12 @@ func (s *CoreServer) UpdateDictionary(ctx context.Context, in *core.DictionaryIn
return l.UpdateDictionary(in)
}
func (s *CoreServer) GetDictionaryList(ctx context.Context, in *core.UserReq) (*core.UserListResp, error) {
func (s *CoreServer) GetDictionaryList(ctx context.Context, in *core.DictionaryReq) (*core.DictionaryListResp, error) {
l := dictionary.NewGetDictionaryListLogic(ctx, s.svcCtx)
return l.GetDictionaryList(in)
}
func (s *CoreServer) GetDictionary(ctx context.Context, in *core.UserReq) (*core.DictionaryInfo, error) {
func (s *CoreServer) GetDictionary(ctx context.Context, in *core.DictionaryReq) (*core.DictionaryInfo, error) {
l := dictionary.NewGetDictionaryLogic(ctx, s.svcCtx)
return l.GetDictionary(in)
}

@ -190,6 +190,37 @@ func (c *Convert) ConvertDistrictRpc(_ context.Context, v *ent.District) *core.D
}
var tmp core.DistrictInfo
_ = copier.Copy(&tmp, v)
tmp.CreatedAt = ntime.Format(v.CreatedAt)
tmp.UpdatedAt = ntime.Format(v.UpdatedAt)
return &tmp
}
func (c *Convert) ConvertDictionaryRpc(ctx context.Context, v *ent.Dictionary) *core.DictionaryInfo {
if v == nil {
return nil
}
var tmp core.DictionaryInfo
_ = copier.Copy(&tmp, v)
tmp.CreatedAt = ntime.Format(v.CreatedAt)
tmp.UpdatedAt = ntime.Format(v.UpdatedAt)
if len(v.Edges.Details) > 0 {
tmp.Details = make([]*core.DictionaryDetailInfo, len(v.Edges.Details))
for i, item := range v.Edges.Details {
tmp.Details[i] = c.ConvertDictionaryDetailRpc(ctx, item)
}
}
return &tmp
}
func (c *Convert) ConvertDictionaryDetailRpc(_ context.Context, v *ent.DictionaryDetail) *core.DictionaryDetailInfo {
if v == nil {
return nil
}
var tmp core.DictionaryDetailInfo
_ = copier.Copy(&tmp, v)
tmp.DictionaryId = v.DictionaryID
return &tmp
}

File diff suppressed because it is too large Load Diff

@ -41,9 +41,9 @@ type CoreClient interface {
// group: dictionary
UpdateDictionary(ctx context.Context, in *DictionaryInfo, opts ...grpc.CallOption) (*BaseResp, error)
// group: dictionary
GetDictionaryList(ctx context.Context, in *UserReq, opts ...grpc.CallOption) (*UserListResp, error)
GetDictionaryList(ctx context.Context, in *DictionaryReq, opts ...grpc.CallOption) (*DictionaryListResp, error)
// group: dictionary
GetDictionary(ctx context.Context, in *UserReq, opts ...grpc.CallOption) (*DictionaryInfo, error)
GetDictionary(ctx context.Context, in *DictionaryReq, opts ...grpc.CallOption) (*DictionaryInfo, error)
// group: dictionary
DeleteDictionary(ctx context.Context, in *IDsReq, opts ...grpc.CallOption) (*BaseResp, error)
// Details
@ -227,8 +227,8 @@ func (c *coreClient) UpdateDictionary(ctx context.Context, in *DictionaryInfo, o
return out, nil
}
func (c *coreClient) GetDictionaryList(ctx context.Context, in *UserReq, opts ...grpc.CallOption) (*UserListResp, error) {
out := new(UserListResp)
func (c *coreClient) GetDictionaryList(ctx context.Context, in *DictionaryReq, opts ...grpc.CallOption) (*DictionaryListResp, error) {
out := new(DictionaryListResp)
err := c.cc.Invoke(ctx, "/core.Core/getDictionaryList", in, out, opts...)
if err != nil {
return nil, err
@ -236,7 +236,7 @@ func (c *coreClient) GetDictionaryList(ctx context.Context, in *UserReq, opts ..
return out, nil
}
func (c *coreClient) GetDictionary(ctx context.Context, in *UserReq, opts ...grpc.CallOption) (*DictionaryInfo, error) {
func (c *coreClient) GetDictionary(ctx context.Context, in *DictionaryReq, opts ...grpc.CallOption) (*DictionaryInfo, error) {
out := new(DictionaryInfo)
err := c.cc.Invoke(ctx, "/core.Core/getDictionary", in, out, opts...)
if err != nil {
@ -664,9 +664,9 @@ type CoreServer interface {
// group: dictionary
UpdateDictionary(context.Context, *DictionaryInfo) (*BaseResp, error)
// group: dictionary
GetDictionaryList(context.Context, *UserReq) (*UserListResp, error)
GetDictionaryList(context.Context, *DictionaryReq) (*DictionaryListResp, error)
// group: dictionary
GetDictionary(context.Context, *UserReq) (*DictionaryInfo, error)
GetDictionary(context.Context, *DictionaryReq) (*DictionaryInfo, error)
// group: dictionary
DeleteDictionary(context.Context, *IDsReq) (*BaseResp, error)
// Details
@ -799,10 +799,10 @@ func (UnimplementedCoreServer) CreateDictionary(context.Context, *DictionaryInfo
func (UnimplementedCoreServer) UpdateDictionary(context.Context, *DictionaryInfo) (*BaseResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateDictionary not implemented")
}
func (UnimplementedCoreServer) GetDictionaryList(context.Context, *UserReq) (*UserListResp, error) {
func (UnimplementedCoreServer) GetDictionaryList(context.Context, *DictionaryReq) (*DictionaryListResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetDictionaryList not implemented")
}
func (UnimplementedCoreServer) GetDictionary(context.Context, *UserReq) (*DictionaryInfo, error) {
func (UnimplementedCoreServer) GetDictionary(context.Context, *DictionaryReq) (*DictionaryInfo, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetDictionary not implemented")
}
func (UnimplementedCoreServer) DeleteDictionary(context.Context, *IDsReq) (*BaseResp, error) {
@ -1095,7 +1095,7 @@ func _Core_UpdateDictionary_Handler(srv interface{}, ctx context.Context, dec fu
}
func _Core_GetDictionaryList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UserReq)
in := new(DictionaryReq)
if err := dec(in); err != nil {
return nil, err
}
@ -1107,13 +1107,13 @@ func _Core_GetDictionaryList_Handler(srv interface{}, ctx context.Context, dec f
FullMethod: "/core.Core/getDictionaryList",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CoreServer).GetDictionaryList(ctx, req.(*UserReq))
return srv.(CoreServer).GetDictionaryList(ctx, req.(*DictionaryReq))
}
return interceptor(ctx, in, info, handler)
}
func _Core_GetDictionary_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UserReq)
in := new(DictionaryReq)
if err := dec(in); err != nil {
return nil, err
}
@ -1125,7 +1125,7 @@ func _Core_GetDictionary_Handler(srv interface{}, ctx context.Context, dec func(
FullMethod: "/core.Core/getDictionary",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CoreServer).GetDictionary(ctx, req.(*UserReq))
return srv.(CoreServer).GetDictionary(ctx, req.(*DictionaryReq))
}
return interceptor(ctx, in, info, handler)
}

Loading…
Cancel
Save