From ec6b35f307292f17caf170820d1b91df23a1272a Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Thu, 5 Dec 2024 12:57:35 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20ExtID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/create_files/create_files_columns.go | 4 +-- .../crud_tables/crud_tables_crud.go | 2 +- .../grpc_client_tables/grpc_client_tables.go | 31 ++++++++++++++++++ .../grpc_client_tables_crud.go | 2 ++ .../create_files/protobuf/protobuf_crud.go | 20 +++++++++--- .../server_grpc_tables_crud.go | 32 +++++++++++++++++++ 6 files changed, 83 insertions(+), 8 deletions(-) diff --git a/internal/create_files/create_files_columns.go b/internal/create_files/create_files_columns.go index 2a8d93f..f04929c 100644 --- a/internal/create_files/create_files_columns.go +++ b/internal/create_files/create_files_columns.go @@ -444,8 +444,8 @@ func Is_Need_Сolumn(Column1 *types.Column) bool { return Otvet } -// GetColumn_ExtID - возвращает колонку ExtID -func GetColumn_ExtID(Table1 *types.Table) *types.Column { +// FindColumn_ExtID - возвращает колонку ExtID +func FindColumn_ExtID(Table1 *types.Table) *types.Column { Column1, ok := Table1.MapColumns["ext_id"] if ok == false { return nil diff --git a/internal/create_files/crud_tables/crud_tables_crud.go b/internal/create_files/crud_tables/crud_tables_crud.go index 2bff820..2a8011f 100644 --- a/internal/create_files/crud_tables/crud_tables_crud.go +++ b/internal/create_files/crud_tables/crud_tables_crud.go @@ -550,7 +550,7 @@ func DeleteFunc_DeleteCtx(TextModel string, Table1 *types.Table) string { func ReplaceText_ExtID0(TextDB string, Table1 *types.Table) string { Otvet := TextDB - ColumnExtID := create_files.GetColumn_ExtID(Table1) + ColumnExtID := create_files.FindColumn_ExtID(Table1) if ColumnExtID == nil { return Otvet } 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 d5b8c77..792c971 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables.go @@ -365,3 +365,34 @@ func Replace_NRPC_CLIENT(Text string) string { return Otvet } + +// Replace_RequestExtID - заменяет RequestExtID{} на Request_Int64_String{} +func Replace_RequestExtID(TextGRPCServer string, Table1 *types.Table) string { + Otvet := TextGRPCServer + + //если нет таких колонок - ничего не делаем + if create_files.Has_Column_ExtID_ConnectionID(Table1) == false { + return Otvet + } + + //если обе колонки Int64 - ничего не делаем + if create_files.Has_Column_ExtID_ConnectionID_Int64(Table1) == true { + return Otvet + } + + // + ColumnExtID := create_files.FindColumn_ExtID(Table1) + if ColumnExtID == nil { + return Otvet + } + + // + if ColumnExtID.TypeGo != "string" { + return Otvet + } + + // + Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestExtID", "grpc_proto.RequestExtIDString") + + return Otvet +} diff --git a/internal/create_files/grpc_client_tables/grpc_client_tables_crud.go b/internal/create_files/grpc_client_tables/grpc_client_tables_crud.go index 190f22a..774cdf3 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables_crud.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables_crud.go @@ -110,6 +110,8 @@ func CreateFiles(Table1 *types.Table) error { TextGRPCClient = create_files.Replace_TemplateTableName_to_TableName(TextGRPCClient, Table1.Name) TextGRPCClient = create_files.AddText_ModuleGenerated(TextGRPCClient) + TextGRPCClient = Replace_RequestExtID(TextGRPCClient, Table1) + //ModelName := Table1.NameGo //TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) //TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) diff --git a/internal/create_files/protobuf/protobuf_crud.go b/internal/create_files/protobuf/protobuf_crud.go index e260844..b18f25d 100644 --- a/internal/create_files/protobuf/protobuf_crud.go +++ b/internal/create_files/protobuf/protobuf_crud.go @@ -19,7 +19,7 @@ func FindText_ProtoTable1(TextProto string, Table1 *types.Table) string { Otvet = Otvet + FindText_Update(TextProto, ModelName) Otvet = Otvet + FindText_Save(TextProto, ModelName) if create_files.Has_Column_ExtID_ConnectionID(Table1) == true { - Otvet = Otvet + FindText_FindByExtId(TextProto, ModelName) + Otvet = Otvet + FindText_FindByExtId(TextProto, Table1) } if create_files.Has_Column_IsDeleted_Bool(Table1) == true { @@ -130,9 +130,9 @@ func FindText_Restore(TextProto string, Table1 *types.Table) string { } // FindText_FindByExtId - возвращает текст .proto -func FindText_FindByExtId(TextProto string, ModelName string) string { +func FindText_FindByExtId(TextProto string, Table1 *types.Table) string { Otvet := "" - Otvet2 := Text_FindByExtId(ModelName) + Otvet2 := Text_FindByExtId(Table1) //проверка такой текст уже есть pos1 := strings.Index(TextProto, Otvet2) @@ -215,8 +215,18 @@ func Text_Restore(Table1 *types.Table) string { } // Text_FindByExtId - возвращает текст .proto -func Text_FindByExtId(ModelName string) string { - Otvet := "rpc " + ModelName + "_FindByExtID(RequestExtID) returns (Response) {}" +func Text_FindByExtId(Table1 *types.Table) string { + Otvet := "" + ModelName := Table1.NameGo_translit + ColumnExtID := create_files.FindColumn_ExtID(Table1) + if ColumnExtID == nil { + return Otvet + } + if ColumnExtID.TypeGo == "string" { + Otvet = "rpc " + ModelName + "_FindByExtID(RequestExtIDString) returns (Response) {}" + } else { + Otvet = "rpc " + ModelName + "_FindByExtID(RequestExtID) returns (Response) {}" + } return Otvet } diff --git a/internal/create_files/server_grpc_tables/server_grpc_tables_crud.go b/internal/create_files/server_grpc_tables/server_grpc_tables_crud.go index b83e91d..e6bfbf7 100644 --- a/internal/create_files/server_grpc_tables/server_grpc_tables_crud.go +++ b/internal/create_files/server_grpc_tables/server_grpc_tables_crud.go @@ -86,6 +86,7 @@ func CreateFiles(Table1 *types.Table) error { TextGRPCServer = create_files.Replace_TemplateModel_to_Model(TextGRPCServer, Table1.NameGo) TextGRPCServer = create_files.Replace_TemplateTableName_to_TableName(TextGRPCServer, Table1.Name) TextGRPCServer = create_files.AddText_ModuleGenerated(TextGRPCServer) + TextGRPCServer = Replace_RequestExtID(TextGRPCServer, Table1) //ModelName := Table1.NameGo //TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) @@ -520,3 +521,34 @@ func Replace_OtvetIDEqual0(Text string, Table1 *types.Table) string { return Otvet } + +// Replace_RequestExtID - заменяет RequestExtID{} на Request_Int64_String{} +func Replace_RequestExtID(TextGRPCServer string, Table1 *types.Table) string { + Otvet := TextGRPCServer + + //если нет таких колонок - ничего не делаем + if create_files.Has_Column_ExtID_ConnectionID(Table1) == false { + return Otvet + } + + //если обе колонки Int64 - ничего не делаем + if create_files.Has_Column_ExtID_ConnectionID_Int64(Table1) == true { + return Otvet + } + + // + ColumnExtID := create_files.FindColumn_ExtID(Table1) + if ColumnExtID == nil { + return Otvet + } + + // + if ColumnExtID.TypeGo != "string" { + return Otvet + } + + // + Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestExtID", "grpc_proto.RequestExtIDString") + + return Otvet +}