From 10df6325f76452c5e7d943c6a7a58ba30752f505 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Wed, 24 Apr 2024 16:19:05 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20uuid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pkg/crud_starter/crud_starter_manual.go | 2 +- .../app/grpc/server_grpc/server_grpc.go_ | 58 +++++++++---------- internal/create_files/create_files.go | 21 ++++++- .../server_grpc_tables/server_grpc_tables.go | 12 ++++ 4 files changed, 61 insertions(+), 32 deletions(-) diff --git a/bin/notifier_service/pkg/crud_starter/crud_starter_manual.go b/bin/notifier_service/pkg/crud_starter/crud_starter_manual.go index 9cef2c0..b31592a 100644 --- a/bin/notifier_service/pkg/crud_starter/crud_starter_manual.go +++ b/bin/notifier_service/pkg/crud_starter/crud_starter_manual.go @@ -24,4 +24,4 @@ func initCrudTransport_manual_GRPC() { // initCrudTransport_manual_NRPC - заполняет объекты crud для работы с БД через протокол NRPC func initCrudTransport_manual_NRPC() { crud_starter_attachament.SetCrudManualInterface(grpc_attachament.Crud_GRPC{}) -} +} \ No newline at end of file diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc.go_ index 55eb3b5..9f1ab96 100644 --- a/bin/templates/internal/app/grpc/server_grpc/server_grpc.go_ +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc.go_ @@ -30,15 +30,15 @@ func (s *ServerGRPC) LawsuitStatusType_Read(ctx context.Context, Request *grpc_p //запрос в БД db := postgres_gorm.GetConnection() - Model := &lawsuit_status_types.LawsuitStatusType{} - Model.ID = Request.ID - err = crud_lawsuit_status_types.Read_ctx(ctx, db, Model) + m := &lawsuit_status_types.LawsuitStatusType{} + m.ID = Request.ID + err = crud_lawsuit_status_types.Read_ctx(ctx, db, m) if err != nil { return &Otvet, err } //заполяем ответ - ModelString, err := Model.GetJSON() + ModelString, err := m.GetJSON() if err != nil { return &Otvet, err } @@ -68,15 +68,15 @@ func (s *ServerGRPC) LawsuitStatusType_Delete(ctx context.Context, Request *grpc //запрос в БД db := postgres_gorm.GetConnection() - Model := &lawsuit_status_types.LawsuitStatusType{} - Model.ID = Request.ID - err = crud_lawsuit_status_types.Delete_ctx(ctx, db, Model) + m := &lawsuit_status_types.LawsuitStatusType{} + m.ID = Request.ID + err = crud_lawsuit_status_types.Delete_ctx(ctx, db, m) if err != nil { return &Otvet, err } //заполяем ответ - ModelString, err := Model.GetJSON() + ModelString, err := m.GetJSON() if err != nil { return &Otvet, err } @@ -106,15 +106,15 @@ func (s *ServerGRPC) LawsuitStatusType_Restore(ctx context.Context, Request *grp //запрос в БД db := postgres_gorm.GetConnection() - Model := &lawsuit_status_types.LawsuitStatusType{} - Model.ID = Request.ID - err = crud_lawsuit_status_types.Restore_ctx(ctx, db, Model) + m := &lawsuit_status_types.LawsuitStatusType{} + m.ID = Request.ID + err = crud_lawsuit_status_types.Restore_ctx(ctx, db, m) if err != nil { return &Otvet, err } //заполяем ответ - ModelString, err := Model.GetJSON() + ModelString, err := m.GetJSON() if err != nil { return &Otvet, err } @@ -143,21 +143,21 @@ func (s *ServerGRPC) LawsuitStatusType_Create(ctx context.Context, Request *grpc } //получим модель из строки JSON - Model := &lawsuit_status_types.LawsuitStatusType{} - err = Model.GetModelFromJSON(Request.ModelString) + m := &lawsuit_status_types.LawsuitStatusType{} + err = m.GetModelFromJSON(Request.ModelString) if err != nil { return &Otvet, err } //запрос в БД db := postgres_gorm.GetConnection() - err = crud_lawsuit_status_types.Create_ctx(ctx, db, Model) + err = crud_lawsuit_status_types.Create_ctx(ctx, db, m) if err != nil { return &Otvet, err } //заполяем ответ - ModelString, err := Model.GetJSON() + ModelString, err := m.GetJSON() if err != nil { return &Otvet, err } @@ -186,21 +186,21 @@ func (s *ServerGRPC) LawsuitStatusType_Update(ctx context.Context, Request *grpc } //получим модель из строки JSON - Model := &lawsuit_status_types.LawsuitStatusType{} - err = Model.GetModelFromJSON(Request.ModelString) + m := &lawsuit_status_types.LawsuitStatusType{} + err = m.GetModelFromJSON(Request.ModelString) if err != nil { return &Otvet, err } //запрос в БД db := postgres_gorm.GetConnection() - err = crud_lawsuit_status_types.Update_ctx(ctx, db, Model) + err = crud_lawsuit_status_types.Update_ctx(ctx, db, m) if err != nil { return &Otvet, err } //заполяем ответ - ModelString, err := Model.GetJSON() + ModelString, err := m.GetJSON() if err != nil { return &Otvet, err } @@ -229,21 +229,21 @@ func (s *ServerGRPC) LawsuitStatusType_Save(ctx context.Context, Request *grpc_p } //получим модель из строки JSON - Model := lawsuit_status_types.LawsuitStatusType{} - err = Model.GetModelFromJSON(Request.ModelString) + m := lawsuit_status_types.LawsuitStatusType{} + err = m.GetModelFromJSON(Request.ModelString) if err != nil { return &Otvet, err } //запрос в БД db := postgres_gorm.GetConnection() - err = crud_lawsuit_status_types.Save_ctx(ctx, db, &Model) + err = crud_lawsuit_status_types.Save_ctx(ctx, db, &m) if err != nil { return &Otvet, err } //заполяем ответ - ModelString, err := Model.GetJSON() + ModelString, err := m.GetJSON() if err != nil { return &Otvet, err } @@ -273,16 +273,16 @@ func (s *ServerGRPC) LawsuitStatusType_FindByExtID(ctx context.Context, Request //запрос в БД db := postgres_gorm.GetConnection() - Model := &lawsuit_status_types.LawsuitStatusType{} - Model.ExtID = Request.ExtID - Model.ConnectionID = Request.ConnectionId - err = crud_lawsuit_status_types.Find_ByExtID_ctx(ctx, db, Model) + m := &lawsuit_status_types.LawsuitStatusType{} + m.ExtID = Request.ExtID + m.ConnectionID = Request.ConnectionId + err = crud_lawsuit_status_types.Find_ByExtID_ctx(ctx, db, m) if err != nil { return &Otvet, err } //заполяем ответ - ModelString, err := Model.GetJSON() + ModelString, err := m.GetJSON() if err != nil { return &Otvet, err } diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index dc1ca74..88c47ad 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -1244,6 +1244,7 @@ func FindTextProtobufRequest(Table1 *types.Table, TypeGo string) (string, string func FindTextProtobufRequestPrimaryKey(Table1 *types.Table, TypeGo string) (string, string) { Otvet := "RequestId" TextRequestFieldName := "ID" + TextRequest := "Request" switch TypeGo { @@ -1514,6 +1515,9 @@ func FindTextConvertProtobufTypeToGolangType(Table1 *types.Table, Column1 *types TableName := Table1.Name IDName := Column1.Name + RequestColumnName := Column1.NameGo + RequestColumnName = FindRequestColumnName(Table1, Column1) + //alias в Int64 TextConvert, ok := types.MapConvertID[TableName+"."+IDName] if ok == true { @@ -1530,7 +1534,7 @@ func FindTextConvertProtobufTypeToGolangType(Table1 *types.Table, Column1 *types } case "uuid.UUID": { - Otvet = "uuid.FromBytes([]byte(" + VariableName + Column1.NameGo + "))" + Otvet = "uuid.FromBytes([]byte(" + VariableName + RequestColumnName + "))" return Otvet } } @@ -1701,7 +1705,11 @@ func ReplaceTextRequestID_PrimaryKey(Text string, Table1 *types.Table) string { TextRequestID, TextID := FindTextProtobufRequestPrimaryKey(Table1, TypeGo) Otvet = strings.ReplaceAll(Otvet, "RequestId{}", TextRequestID+"{}") - Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextID) + Otvet = strings.ReplaceAll(Otvet, "*grpc_proto.RequestId", "*grpc_proto."+TextRequestID) + //Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextID) + + TextID = FindTextConvertProtobufTypeToGolangType(Table1, PrimaryKeyColumn, "Request.") + Otvet = strings.ReplaceAll(Otvet, "Request.ID", TextID) return Otvet } @@ -1742,3 +1750,12 @@ func FindNegativeValue(TypeGo string) string { return Otvet } + +// FindRequestColumnName - возвращает название колонки в Request +func FindRequestColumnName(Table1 *types.Table, Column1 *types.Column) string { + Otvet := "" + + _, Otvet := FindTextProtobufRequest(Table1, Column1.TypeGo) + + return Otvet +} diff --git a/internal/create_files/server_grpc_tables/server_grpc_tables.go b/internal/create_files/server_grpc_tables/server_grpc_tables.go index d86b4ba..6873438 100644 --- a/internal/create_files/server_grpc_tables/server_grpc_tables.go +++ b/internal/create_files/server_grpc_tables/server_grpc_tables.go @@ -127,6 +127,18 @@ func CreateFiles(Table1 *types.Table) error { CrudTableURL := create_files.FindCrudTableURL(TableName) TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudTableURL) + //замена ID на PrimaryKey + TextGRPCServer = create_files.ReplacePrimaryKeyM_ID(TextGRPCServer, Table1) + + //замена RequestId{} + TextGRPCServer = create_files.ReplaceTextRequestID_PrimaryKey(TextGRPCServer, Table1) + + //замена int64(ID) на ID + TextGRPCServer = create_files.ReplaceIDtoID(TextGRPCServer, Table1) + + //добавим импорт uuid + TextGRPCServer = create_files.CheckAndAddImportUUID_FromText(TextGRPCServer) + //удалим лишние функции TextGRPCServer = DeleteFuncDelete(TextGRPCServer, Table1) TextGRPCServer = DeleteFuncRestore(TextGRPCServer, Table1)