From 60096ccaae1ce0345bac11956f9d0f08c6a41453 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Tue, 12 Mar 2024 15:35:08 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20TEMPLATE?= =?UTF-8?q?S=5FGRPC=5FCLIENT=5FTABLES=5FCACHE=5FFILENAME?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server_grpc/server_grpc_table_cache.go_ | 5 +- bin/templates/pkg/db/crud/crud_tables.go_ | 2 +- .../pkg/db/crud/crud_tables_rapira.go_ | 2 +- .../pkg/object_model/entities/model_crud.go_ | 13 +++-- internal/constants/constants.go | 4 +- internal/create_files/create_files.go | 48 ++++++++++++++++++- .../db_crud_tables/db_crud_tables.go | 11 +++-- .../grpc_client_tables/grpc_client_tables.go | 4 +- .../grpc_server_tables/grpc_server_tables.go | 14 +++--- 9 files changed, 77 insertions(+), 26 deletions(-) diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_cache.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_cache.go_ index 175476c..24a2155 100644 --- a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_cache.go_ +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_cache.go_ @@ -27,9 +27,8 @@ func (s *ServerGRPC) LawsuitStatusType_ReadFromCache(ctx context.Context, Reques } //запрос в БД - Model := &lawsuit_status_types.LawsuitStatusType{} - Model.ID = Request.ID - err = Model.ReadFromCache() + Model := lawsuit_status_types.LawsuitStatusType{} + Model, err = Model.ReadFromCache(Request.ID) if err != nil { return &Otvet, err } diff --git a/bin/templates/pkg/db/crud/crud_tables.go_ b/bin/templates/pkg/db/crud/crud_tables.go_ index 10582fe..0f3cb9a 100644 --- a/bin/templates/pkg/db/crud/crud_tables.go_ +++ b/bin/templates/pkg/db/crud/crud_tables.go_ @@ -187,7 +187,7 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ } //удалим из кэша - //cache.Remove(m.ID) + //cache.Remove(int64(m.ID)) //запишем NULL в пустые колонки MapOmit := crud_functions.MapOmit_from_MassOmit(MassOmit) diff --git a/bin/templates/pkg/db/crud/crud_tables_rapira.go_ b/bin/templates/pkg/db/crud/crud_tables_rapira.go_ index 19cc22a..7be8c4c 100644 --- a/bin/templates/pkg/db/crud/crud_tables_rapira.go_ +++ b/bin/templates/pkg/db/crud/crud_tables_rapira.go_ @@ -187,7 +187,7 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ } //удалим из кэша - //cache.Remove(m.ID) + //cache.Remove(int64(m.ID)) //запишем NULL в пустые колонки MapOmit := crud_functions.MapOmit_from_MassOmit(MassOmit) diff --git a/bin/templates/pkg/object_model/entities/model_crud.go_ b/bin/templates/pkg/object_model/entities/model_crud.go_ index 9d051c3..5b4ef63 100644 --- a/bin/templates/pkg/object_model/entities/model_crud.go_ +++ b/bin/templates/pkg/object_model/entities/model_crud.go_ @@ -23,7 +23,7 @@ type ICrud_LawsuitStatusType interface { Delete(*LawsuitStatusType) error Restore(*LawsuitStatusType) error Find_ByExtID(*LawsuitStatusType) error - ReadFromCache(*LawsuitStatusType) error + ReadFromCache(ID int64) (LawsuitStatusType, error) } // TableName - возвращает имя таблицы в БД @@ -169,14 +169,17 @@ func (m *LawsuitStatusType) Find_ByExtID() error { } // ReadFromCache - находит запись в кэше или в БД по ID, и заполняет в объект -func (m *LawsuitStatusType) ReadFromCache() error { +func (m *LawsuitStatusType) ReadFromCache(ID int64) (LawsuitStatusType, error) { + Otvet := LawsuitStatusType{} + var err error + if Crud_LawsuitStatusType == nil { - return constants.ErrorCrudIsNotInit + return Otvet, constants.ErrorCrudIsNotInit } - err := Crud_LawsuitStatusType.ReadFromCache(m) + Otvet, err = Crud_LawsuitStatusType.ReadFromCache(ID) - return err + return Otvet, err } // SetCrudInterface - заполняет интерфейс crud: DB, GRPC, NRPC diff --git a/internal/constants/constants.go b/internal/constants/constants.go index 63a6759..b9640d5 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -56,7 +56,9 @@ const GRPC_CLIENT_TABLE_UPDATE_FUNC_TEST_FILENAME = "grpc_client_table_update_fu const CRUD_TABLES_CACHE_FILENAME = "crud_table_cache.go_" const CRUD_TABLES_CACHE_TEST_FILENAME = "crud_table_cache_test.go_" -const TEXT_CACHE_REMOVE = "cache.Remove(m.ID)" +const TEXT_CACHE_REMOVE = "cache.Remove(int64(m.ID))" const SERVER_GRPC_TABLE_CACHE_FILENAME = "server_grpc_table_cache.go_" const SERVER_GRPC_TABLE_CACHE_TEST_FILENAME = "server_grpc_table_cache_test.go_" + +const TEXT_OTVET_ID_ALIAS = "Otvet.ID = ID" diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index 8445c36..943353c 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -1175,8 +1175,8 @@ func FindTextProtobufRequest_ID_Type(Table1 *types.Table, Column1 *types.Column, return Otvet, TextRequestFieldName, TextRequestFieldGolang } -// ConvertIdToAlias - заменяет ID на Alias -func ConvertIdToAlias(Text string, Table1 *types.Table) string { +// ConvertRequestIdToAlias - заменяет ID на Alias +func ConvertRequestIdToAlias(Text string, Table1 *types.Table) string { Otvet := Text TableName := Table1.Name @@ -1201,6 +1201,50 @@ func ConvertIdToAlias(Text string, Table1 *types.Table) string { return Otvet } +// ConvertIDToAlias_OtvetID - заменяет "Otvet.ID = ID" на "Otvet.ID = alias.Name(ID)" +func ConvertIDToAlias_OtvetID(Text string, Table1 *types.Table) string { + Otvet := Text + + TableName := Table1.Name + IDName, _ := FindPrimaryKeyNameType(Table1) + TextConvert, ok := types.MapConvertID[TableName+"."+IDName] + if ok == false { + return Otvet + } + + if TextConvert[:6] != "alias." { + return Otvet + } + + TextFrom := constants.TEXT_OTVET_ID_ALIAS + TextTo := TextFrom + TextTo = strings.ReplaceAll(TextFrom, " ID", " "+TextConvert+"(ID)") + + Otvet = strings.ReplaceAll(Otvet, TextFrom, TextTo) + URL := FindURL_Alias() + if URL == "" { + return Otvet + } + + Otvet = AddImport(Otvet, URL) + + return Otvet +} + +// DeleteCommentFromString - удаляет комментарий из строки // +func DeleteCommentFromString(TextFrom string) string { + Otvet := TextFrom + + pos1 := strings.Index(Otvet, "//") + if pos1 < 0 { + return Otvet + } + + Otvet = Otvet[:pos1] + + return Otvet +} + // FindTextConvertGolangTypeToProtobufType - возвращает имя переменной + имя колонки, преобразованное в тип protobuf func FindTextConvertGolangTypeToProtobufType(Table1 *types.Table, Column1 *types.Column, VariableName string) string { Otvet := VariableName + Column1.NameGo diff --git a/internal/create_files/db_crud_tables/db_crud_tables.go b/internal/create_files/db_crud_tables/db_crud_tables.go index 59c7655..6f090cb 100644 --- a/internal/create_files/db_crud_tables/db_crud_tables.go +++ b/internal/create_files/db_crud_tables/db_crud_tables.go @@ -539,7 +539,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error { ModelTableURL := create_files.FindModelTableURL(TableName) TextCrud = create_files.AddImport(TextCrud, ModelTableURL) - TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1) + //TextCrud = create_files.ConvertRequestIdToAlias(TextCrud, Table1) } //создание текста @@ -692,7 +692,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { ModelTableURL := create_files.FindModelTableURL(TableName) TextCrud = create_files.AddImport(TextCrud, ModelTableURL) - TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1) + TextCrud = create_files.ConvertRequestIdToAlias(TextCrud, Table1) } //создание текста @@ -816,7 +816,7 @@ func CreateFilesCache(Table1 *types.Table) error { ModelTableURL := create_files.FindModelTableURL(TableName) TextCache = create_files.AddImport(TextCache, ModelTableURL) - //TextCache = create_files.ConvertIdToAlias(TextCache, Table1) + //TextCache = create_files.ConvertRequestIdToAlias(TextCache, Table1) } //замена слов @@ -825,6 +825,9 @@ func CreateFilesCache(Table1 *types.Table) error { TextCache = strings.ReplaceAll(TextCache, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) TextCache = config.Settings.TEXT_MODULE_GENERATED + TextCache + //alias + TextCache = create_files.ConvertIDToAlias_OtvetID(TextCache, Table1) + //удаление пустого импорта TextCache = create_files.DeleteEmptyImport(TextCache) @@ -877,7 +880,7 @@ func CreateFilesCacheTest(Table1 *types.Table) error { ModelTableURL := create_files.FindModelTableURL(TableName) TextCache = create_files.AddImport(TextCache, ModelTableURL) - //TextCache = create_files.ConvertIdToAlias(TextCache, Table1) + //TextCache = create_files.ConvertRequestIdToAlias(TextCache, Table1) } //замена слов diff --git a/internal/create_files/grpc_client_tables/grpc_client_tables.go b/internal/create_files/grpc_client_tables/grpc_client_tables.go index 918cd37..5e1f16a 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables.go @@ -432,7 +432,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error { ModelTableURL := create_files.FindModelTableURL(TableName) TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ModelTableURL) - //TextGRPC_Client = create_files.ConvertIdToAlias(TextGRPC_Client, Table1) + //TextGRPC_Client = create_files.ConvertRequestIdToAlias(TextGRPC_Client, Table1) } //создание текста @@ -579,7 +579,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { ModelTableURL := create_files.FindModelTableURL(TableName) TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ModelTableURL) - //TextGRPC_Client = create_files.ConvertIdToAlias(TextGRPC_Client, Table1) + //TextGRPC_Client = create_files.ConvertRequestIdToAlias(TextGRPC_Client, Table1) } //создание текста diff --git a/internal/create_files/grpc_server_tables/grpc_server_tables.go b/internal/create_files/grpc_server_tables/grpc_server_tables.go index a253357..0c5d13f 100644 --- a/internal/create_files/grpc_server_tables/grpc_server_tables.go +++ b/internal/create_files/grpc_server_tables/grpc_server_tables.go @@ -137,7 +137,7 @@ func CreateFiles(Table1 *types.Table) error { TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer if config.Settings.USE_DEFAULT_TEMPLATE == true { - TextGRPCServer = create_files.ConvertIdToAlias(TextGRPCServer, Table1) + TextGRPCServer = create_files.ConvertRequestIdToAlias(TextGRPCServer, Table1) } //удаление пустого импорта @@ -426,7 +426,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error { TextGRPCServer = TextGRPCServer + TextUpdateEveryColumn if config.Settings.USE_DEFAULT_TEMPLATE == true { - TextGRPCServer = create_files.ConvertIdToAlias(TextGRPCServer, Table1) + TextGRPCServer = create_files.ConvertRequestIdToAlias(TextGRPCServer, Table1) TextGRPCServer = create_files.CheckAndAddImportAlias(TextGRPCServer) TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer } @@ -559,7 +559,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { CrudStarterURL := create_files.FindCrudStarterURL() TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudStarterURL) - //TextGRPCServer = create_files.ConvertIdToAlias(TextGRPCServer, Table1) + //TextGRPCServer = create_files.ConvertRequestIdToAlias(TextGRPCServer, Table1) } //создание текста @@ -689,9 +689,9 @@ func CreateFilesCache(Table1 *types.Table) error { TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer - if config.Settings.USE_DEFAULT_TEMPLATE == true { - TextGRPCServer = create_files.ConvertIdToAlias(TextGRPCServer, Table1) - } + //if config.Settings.USE_DEFAULT_TEMPLATE == true { + // TextGRPCServer = create_files.ConvertRequestIdToAlias(TextGRPCServer, Table1) + //} //удаление пустого импорта TextGRPCServer = create_files.DeleteEmptyImport(TextGRPCServer) @@ -751,7 +751,7 @@ func CreateFilesCacheTest(Table1 *types.Table) error { TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer if config.Settings.USE_DEFAULT_TEMPLATE == true { - TextGRPCServer = create_files.ConvertIdToAlias(TextGRPCServer, Table1) + TextGRPCServer = create_files.ConvertRequestIdToAlias(TextGRPCServer, Table1) } //удаление пустого импорта