diff --git a/bin/templates/configs_/mapping.json b/bin/templates/configs_/mapping.json index 8909743..30c101a 100644 --- a/bin/templates/configs_/mapping.json +++ b/bin/templates/configs_/mapping.json @@ -257,7 +257,7 @@ "sql_type": "timestamp", "go_type": "time.Time", "json_type": "Text", - "protobuf_type": "uint64", + "protobuf_type": "google.protobuf.Timestamp", "guregu_type": "null.Time", "go_nullable_type": "time.Time", "swagger_type": "time.Time" @@ -266,7 +266,7 @@ "sql_type": "timestamptz", "go_type": "time.Time", "json_type": "Text", - "protobuf_type": "uint64", + "protobuf_type": "google.protobuf.Timestamp", "guregu_type": "null.Time", "go_nullable_type": "time.Time", "swagger_type": "time.Time" 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 1aef749..2fa229a 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_ @@ -7,6 +7,7 @@ import ( "github.com/ManyakRus/starter/contextmain" "github.com/ManyakRus/starter/postgres_gorm" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/db_constants" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" ) @@ -30,7 +31,7 @@ func (s *ServerGRPC) LawsuitStatusType_ReadFromCache(ctx context.Context, Reques } ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() //запрос в БД diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update.go_ index 64b673f..9471259 100644 --- a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update.go_ +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update.go_ @@ -7,7 +7,7 @@ import ( "github.com/ManyakRus/starter/postgres_gorm" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/db_constants" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/crud/crud_lawsuit_status_types" "time" ) diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func.go_ index 503e25f..9d90ae6 100644 --- a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func.go_ +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func.go_ @@ -18,7 +18,7 @@ func (s *ServerGRPC) LawsuitStatusType_Update(ctx context.Context, Request *grpc } ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() //запрос в БД diff --git a/bin/templates/pkg/db/crud/crud_table_cache.go_ b/bin/templates/pkg/db/crud/crud_table_cache.go_ index f5772fe..16b33c9 100644 --- a/bin/templates/pkg/db/crud/crud_table_cache.go_ +++ b/bin/templates/pkg/db/crud/crud_table_cache.go_ @@ -5,7 +5,7 @@ import ( "time" "github.com/ManyakRus/starter/contextmain" "github.com/hashicorp/golang-lru/v2/expirable" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/db_constants" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "github.com/ManyakRus/starter/postgres_gorm" "gorm.io/gorm" @@ -38,7 +38,7 @@ func (crud Crud_DB) ReadFromCache(ID int64) (lawsuit_status_types.LawsuitStatusT // поищем в БД ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() diff --git a/bin/templates/pkg/db/crud/crud_table_update.go_ b/bin/templates/pkg/db/crud/crud_table_update.go_ index b35b33d..e9cf7b8 100644 --- a/bin/templates/pkg/db/crud/crud_table_update.go_ +++ b/bin/templates/pkg/db/crud/crud_table_update.go_ @@ -7,7 +7,7 @@ import ( "github.com/ManyakRus/starter/contextmain" "github.com/ManyakRus/starter/micro" "github.com/ManyakRus/starter/postgres_gorm" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/db_constants" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "gorm.io/gorm" "time" @@ -19,7 +19,7 @@ func (crud Crud_DB) UpdateManyFields(m *lawsuit_status_types.LawsuitStatusType, var err error ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() diff --git a/bin/templates/pkg/db/crud/crud_table_update_func.go_ b/bin/templates/pkg/db/crud/crud_table_update_func.go_ index 8f481b3..5e56f13 100644 --- a/bin/templates/pkg/db/crud/crud_table_update_func.go_ +++ b/bin/templates/pkg/db/crud/crud_table_update_func.go_ @@ -3,7 +3,7 @@ func (crud Crud_DB) Read(m *lawsuit_status_types.LawsuitStatusType) error { var err error ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() diff --git a/bin/templates/pkg/db/crud/crud_tables.go_ b/bin/templates/pkg/db/crud/crud_tables.go_ index 8d154de..adba5e3 100644 --- a/bin/templates/pkg/db/crud/crud_tables.go_ +++ b/bin/templates/pkg/db/crud/crud_tables.go_ @@ -6,7 +6,7 @@ import ( "fmt" "github.com/ManyakRus/starter/micro" "github.com/ManyakRus/starter/postgres_gorm" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/db_constants" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "time" "github.com/ManyakRus/starter/contextmain" @@ -26,7 +26,7 @@ func (crud Crud_DB) Read(m *lawsuit_status_types.LawsuitStatusType) error { var err error ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -60,7 +60,7 @@ func Read_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS // Save - записывает новый или существующий объект в базу данных func (crud Crud_DB) Save(m *lawsuit_status_types.LawsuitStatusType) error { ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -84,7 +84,7 @@ func Save_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS // Update - записывает существующий объект в базу данных func (crud Crud_DB) Update(m *lawsuit_status_types.LawsuitStatusType) error { ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -115,7 +115,7 @@ func Update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.Lawsui // Create - записывает новый объект в базу данных func (crud Crud_DB) Create(m *lawsuit_status_types.LawsuitStatusType) error { ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -148,7 +148,7 @@ func (crud Crud_DB) create_update(m *lawsuit_status_types.LawsuitStatusType) err var err error ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -218,7 +218,7 @@ func (crud Crud_DB) Restore(m *lawsuit_status_types.LawsuitStatusType) error { var err error ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -265,7 +265,7 @@ func (crud Crud_DB) Find_ByExtID(m *lawsuit_status_types.LawsuitStatusType) erro // ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -307,7 +307,7 @@ func (crud Crud_DB) Delete(m *lawsuit_status_types.LawsuitStatusType) error { var err error ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() diff --git a/bin/templates/pkg/db/crud/crud_tables_rapira.go_ b/bin/templates/pkg/db/crud/crud_tables_rapira.go_ index 24545d4..2155d1e 100644 --- a/bin/templates/pkg/db/crud/crud_tables_rapira.go_ +++ b/bin/templates/pkg/db/crud/crud_tables_rapira.go_ @@ -6,7 +6,7 @@ import ( "fmt" "github.com/ManyakRus/starter/micro" "github.com/ManyakRus/starter/postgres_gorm" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/db_constants" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "time" "github.com/ManyakRus/starter/contextmain" @@ -26,7 +26,7 @@ func (crud Crud_DB) Read(m *lawsuit_status_types.LawsuitStatusType) error { var err error ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -60,7 +60,7 @@ func Read_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS // Save - записывает новый или существующий объект в базу данных func (crud Crud_DB) Save(m *lawsuit_status_types.LawsuitStatusType) error { ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -84,7 +84,7 @@ func Save_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS // Update - записывает существующий объект в базу данных func (crud Crud_DB) Update(m *lawsuit_status_types.LawsuitStatusType) error { ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -115,7 +115,7 @@ func Update_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.Lawsui // Create - записывает новый объект в базу данных func (crud Crud_DB) Create(m *lawsuit_status_types.LawsuitStatusType) error { ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -148,7 +148,7 @@ func (crud Crud_DB) create_update(m *lawsuit_status_types.LawsuitStatusType) err var err error ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -218,7 +218,7 @@ func (crud Crud_DB) Delete(m *lawsuit_status_types.LawsuitStatusType) error { var err error ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -259,7 +259,7 @@ func (crud Crud_DB) Restore(m *lawsuit_status_types.LawsuitStatusType) error { var err error ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() @@ -306,7 +306,7 @@ func (crud Crud_DB) Find_ByExtID(m *lawsuit_status_types.LawsuitStatusType) erro // ctxMain := contextmain.GetContext() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS)) defer ctxCancelFunc() db := postgres_gorm.GetConnection() diff --git a/bin/templates/pkg/db/db_constants/constants.go b/bin/templates/pkg/db/db_constants/db_constants.go similarity index 93% rename from bin/templates/pkg/db/db_constants/constants.go rename to bin/templates/pkg/db/db_constants/db_constants.go index 8ed01e1..a252a44 100644 --- a/bin/templates/pkg/db/db_constants/constants.go +++ b/bin/templates/pkg/db/db_constants/db_constants.go @@ -1,4 +1,4 @@ -package constants +package db_constants import ( "errors" diff --git a/bin/templates/pkg/object_model/entities/model_crud.go_ b/bin/templates/pkg/object_model/entities/model_crud.go_ index 56efa90..222bf15 100644 --- a/bin/templates/pkg/object_model/entities/model_crud.go_ +++ b/bin/templates/pkg/object_model/entities/model_crud.go_ @@ -5,7 +5,7 @@ import ( "github.com/vmihailenco/msgpack/v5" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/calc_struct_version" "reflect" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/db_constants" ) // versionLawsuitStatusType - версия структуры модели, с учётом имен и типов полей @@ -95,7 +95,7 @@ func (m LawsuitStatusType) GetJSON() (string, error) { // Read - находит запись в БД по ID, и заполняет в объект func (m *LawsuitStatusType) Read() error { if Crud_LawsuitStatusType == nil { - return constants.ErrorCrudIsNotInit + return db_constants.ErrorCrudIsNotInit } err := Crud_LawsuitStatusType.Read(m) @@ -106,7 +106,7 @@ func (m *LawsuitStatusType) Read() error { // Save - записывает объект в БД по ID func (m *LawsuitStatusType) Save() error { if Crud_LawsuitStatusType == nil { - return constants.ErrorCrudIsNotInit + return db_constants.ErrorCrudIsNotInit } err := Crud_LawsuitStatusType.Save(m) @@ -117,7 +117,7 @@ func (m *LawsuitStatusType) Save() error { // Update - обновляет объект в БД по ID func (m *LawsuitStatusType) Update() error { if Crud_LawsuitStatusType == nil { - return constants.ErrorCrudIsNotInit + return db_constants.ErrorCrudIsNotInit } err := Crud_LawsuitStatusType.Update(m) @@ -128,7 +128,7 @@ func (m *LawsuitStatusType) Update() error { // Create - создаёт объект в БД с новым ID func (m *LawsuitStatusType) Create() error { if Crud_LawsuitStatusType == nil { - return constants.ErrorCrudIsNotInit + return db_constants.ErrorCrudIsNotInit } err := Crud_LawsuitStatusType.Create(m) @@ -139,7 +139,7 @@ func (m *LawsuitStatusType) Create() error { // Delete - устанавливает признак пометки удаления в БД func (m *LawsuitStatusType) Delete() error { if Crud_LawsuitStatusType == nil { - return constants.ErrorCrudIsNotInit + return db_constants.ErrorCrudIsNotInit } err := Crud_LawsuitStatusType.Delete(m) @@ -150,7 +150,7 @@ func (m *LawsuitStatusType) Delete() error { // Restore - снимает признак пометки удаления в БД func (m *LawsuitStatusType) Restore() error { if Crud_LawsuitStatusType == nil { - return constants.ErrorCrudIsNotInit + return db_constants.ErrorCrudIsNotInit } err := Crud_LawsuitStatusType.Restore(m) @@ -161,7 +161,7 @@ func (m *LawsuitStatusType) Restore() error { // Find_ByExtID - находит объект по ExtID func (m *LawsuitStatusType) Find_ByExtID() error { if Crud_LawsuitStatusType == nil { - return constants.ErrorCrudIsNotInit + return db_constants.ErrorCrudIsNotInit } err := Crud_LawsuitStatusType.Find_ByExtID(m) @@ -175,7 +175,7 @@ func (m *LawsuitStatusType) ReadFromCache(ID int64) (LawsuitStatusType, error) { var err error if Crud_LawsuitStatusType == nil { - return Otvet, constants.ErrorCrudIsNotInit + return Otvet, db_constants.ErrorCrudIsNotInit } Otvet, err = Crud_LawsuitStatusType.ReadFromCache(ID) @@ -193,7 +193,7 @@ func (m LawsuitStatusType) SetCrudInterface(crud ICrud_LawsuitStatusType) { // UpdateManyFields - находит запись в БД по ID, и изменяет только нужные колонки func (m *LawsuitStatusType) UpdateManyFields(MassNeedUpdateFields []string) error { if Crud_LawsuitStatusType == nil { - return constants.ErrorCrudIsNotInit + return db_constants.ErrorCrudIsNotInit } err := Crud_LawsuitStatusType.UpdateManyFields(m, MassNeedUpdateFields) diff --git a/bin/templates/pkg/object_model/entities/model_table_update.go_ b/bin/templates/pkg/object_model/entities/model_table_update.go_ index ea688eb..97e2bde 100644 --- a/bin/templates/pkg/object_model/entities/model_table_update.go_ +++ b/bin/templates/pkg/object_model/entities/model_table_update.go_ @@ -1,6 +1,6 @@ package lawsuit_status_types import ( - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/db_constants" ) diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index ce33f06..c842f59 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -1266,10 +1266,11 @@ func AddInterfaceFunction(s, TextAdd string) string { } // FindTextProtobufRequest - возвращает "RequestID" и "ID" - имя message из .proto, в зависимости от типа, а также название поля -func FindTextProtobufRequest(Table1 *types.Table, TypeGo string) (string, string) { - Otvet := "RequestId" - TextRequestFieldName := "ID" - TextRequest := "Request" +func FindTextProtobufRequest(Table1 *types.Table) (string, string) { + Otvet := "" + TextRequestFieldName := "" + + TextRequest := "Request_" PrimaryKeyColumn := FindPrimaryKeyColumn(Table1) if PrimaryKeyColumn == nil { @@ -1277,60 +1278,74 @@ func FindTextProtobufRequest(Table1 *types.Table, TypeGo string) (string, string } PrimaryKeyTypeGo := PrimaryKeyColumn.TypeGo + //switch PrimaryKeyTypeGo { + //case "string", "uuid.UUID": + // TextRequest = "Request" + //} + + TextRequestFieldName = PrimaryKeyColumn.TypeGo + + TextRequestFieldName = micro.StringFromUpperCase(TextRequestFieldName) + Otvet = TextRequest + TextRequestFieldName + switch PrimaryKeyTypeGo { case "string", "uuid.UUID": - TextRequest = "Request" - } - - switch TypeGo { - case "int", "int64": - { - if PrimaryKeyTypeGo == "int64" { - Otvet = TextRequest + "Id" - TextRequestFieldName = "ID" - } else { - Otvet = TextRequest + "Int64" - TextRequestFieldName = "Int64" - } - } - - case "int32": - { - Otvet = TextRequest + "Int32" - TextRequestFieldName = "Int32" - } - case "string": - { - Otvet = TextRequest + "String" - TextRequestFieldName = "String_1" - } - case "uuid.UUID": - { - Otvet = TextRequest + "String" - TextRequestFieldName = "String_1" - } + TextRequestFieldName = "String_1" + Otvet = TextRequest + "String" case "time.Time": - { - Otvet = TextRequest + "Date" - TextRequestFieldName = "Date" - } - case "float32": - { - Otvet = TextRequest + "Float32" - TextRequestFieldName = "Float32" - } - case "float64": - { - Otvet = TextRequest + "Float64" - TextRequestFieldName = "Float64" - } - case "bool": - { - Otvet = TextRequest + "Bool" - TextRequestFieldName = "Bool" - } + TextRequestFieldName = "Date" + Otvet = TextRequest + "Date" } + //switch TypeGo { + //case "int", "int64": + // { + // if PrimaryKeyTypeGo == "int64" { + // Otvet = TextRequest + "Id" + // TextRequestFieldName = "ID" + // } else { + // Otvet = TextRequest + "Int64" + // TextRequestFieldName = "Int64" + // } + // } + // + //case "int32": + // { + // Otvet = TextRequest + "Int32" + // TextRequestFieldName = "Int32" + // } + //case "string": + // { + // Otvet = TextRequest + "String" + // TextRequestFieldName = "String_1" + // } + //case "uuid.UUID": + // { + // Otvet = TextRequest + "String" + // TextRequestFieldName = "String_1" + // } + //case "time.Time": + // { + // Otvet = TextRequest + "Date" + // TextRequestFieldName = "Date" + // } + //case "float32": + // { + // Otvet = TextRequest + "Float32" + // TextRequestFieldName = "Float32" + // } + //case "float64": + // { + // Otvet = TextRequest + "Float64" + // TextRequestFieldName = "Float64" + // } + //case "bool": + // { + // Otvet = TextRequest + "Bool" + // TextRequestFieldName = "Bool" + // } + //} + return Otvet, TextRequestFieldName } @@ -1412,7 +1427,7 @@ func FindTextProtobufRequest_ID_Type(Table1 *types.Table, Column1 *types.Column, PrimaryKey_TypeGo := PrimaryKeyColumn.TypeGo //Text_Request_ID := "Request_ID" - Otvet, _ = FindTextProtobufRequest(Table1, PrimaryKey_TypeGo) + Otvet, _ = FindTextProtobufRequest(Table1) //Text_Request_ID = "Request_" + TextID TextRequestProtoName := "" @@ -1423,44 +1438,34 @@ func FindTextProtobufRequest_ID_Type(Table1 *types.Table, Column1 *types.Column, { TextRequestProtoName = "Int64" TextRequestFieldName = "Int64" - TextRequestFieldGolang = VariableName + "Int64" + if PrimaryKey_TypeGo == "int64" { + TextRequestFieldName = "Int64_2" + } + TextRequestFieldGolang = VariableName + TextRequestFieldName } case "int32": { - if Column1.TypeGo == "Int32" && PrimaryKeyColumn.TypeGo == "Int32" { - TextRequestProtoName = "Int32" + TextRequestProtoName = "Int32" + TextRequestFieldName = "Int32" + if PrimaryKey_TypeGo == "int32" { TextRequestFieldName = "Int32_2" - TextRequestFieldGolang = VariableName + "Int32" - } else { - TextRequestProtoName = "Int32" - TextRequestFieldName = "Int32" - TextRequestFieldGolang = VariableName + "Int32" } + TextRequestFieldGolang = VariableName + TextRequestFieldName } case "string": { - if Column1.TypeGo == "string" && PrimaryKeyColumn.TypeGo == "string" { - TextRequestProtoName = "String" + TextRequestProtoName = "String" + TextRequestFieldName = "String_1" + if PrimaryKey_TypeGo == "string" || PrimaryKey_TypeGo == "uuid.UUID" { TextRequestFieldName = "String_2" - TextRequestFieldGolang = VariableName + "String_2" - } else { - TextRequestProtoName = "String" - TextRequestFieldName = "String_1" - TextRequestFieldGolang = VariableName + "String_1" } + TextRequestFieldGolang = VariableName + TextRequestFieldName } case "uuid.UUID": { - if PrimaryKeyColumn.TypeGo == "string" || PrimaryKeyColumn.TypeGo == "uuid.UUID" { - TextRequestProtoName = "String" - TextRequestFieldName = "String_2" - TextRequestFieldGolang = VariableName + "String_2" - } else { - TextRequestProtoName = "String" - TextRequestFieldName = "String_1" - TextRequestFieldGolang = VariableName + "String_1" - } + TextRequestProtoName = "String" + TextRequestFieldName = "String_1" TextGolangLine = "value, err := uuid.Parse(" + VariableName + "" + TextRequestFieldName + ")" + ` if Request.` + TextRequestFieldName + ` == "" { value = uuid.Nil @@ -1470,30 +1475,46 @@ func FindTextProtobufRequest_ID_Type(Table1 *types.Table, Column1 *types.Column, return &Otvet, err } ` + if PrimaryKey_TypeGo == "string" || PrimaryKey_TypeGo == "uuid.UUID" { + TextRequestFieldName = "String_2" + } + TextRequestFieldGolang = VariableName + TextRequestFieldName } case "time.Time": { TextRequestProtoName = "Date" TextRequestFieldName = "Date" - TextRequestFieldGolang = VariableName + "Date.AsTime()" + if PrimaryKey_TypeGo == "time.Time" { + TextRequestFieldName = "Date_2" + } + TextRequestFieldGolang = VariableName + TextRequestFieldName + ".AsTime()" } case "float32": { TextRequestProtoName = "Float32" TextRequestFieldName = "Float32" - TextRequestFieldGolang = VariableName + "Float32" + if PrimaryKey_TypeGo == "float32" { + TextRequestFieldName = "Float32_2" + } + TextRequestFieldGolang = VariableName + TextRequestFieldName } case "float64": { TextRequestProtoName = "Float64" TextRequestFieldName = "Float64" - TextRequestFieldGolang = VariableName + "Float64" + if PrimaryKey_TypeGo == "float64" { + TextRequestFieldName = "Float64_2" + } + TextRequestFieldGolang = VariableName + TextRequestFieldName } case "bool": { TextRequestProtoName = "Bool" TextRequestFieldName = "Bool" - TextRequestFieldGolang = VariableName + "Bool" + if PrimaryKey_TypeGo == "bool" { + TextRequestFieldName = "Bool_2" + } + TextRequestFieldGolang = VariableName + TextRequestFieldName } } @@ -1797,14 +1818,23 @@ func Replace_Postgres_ID_Test(Text string, Table1 *types.Table) string { IDMinimum = FindTextDefaultValue(PrimaryKeyColumn.TypeGo) } - if PrimaryKeyColumn.TypeGo == "uuid.UUID" { - if Table1.IDMinimum == "" { - Otvet = strings.ReplaceAll(Otvet, TextFind, `var Postgres_ID_Test = `+IDMinimum+``) - } else { - Otvet = strings.ReplaceAll(Otvet, TextFind, `var Postgres_ID_Test, _ = uuid.Parse("`+IDMinimum+`")`) + switch PrimaryKeyColumn.TypeGo { + case "uuid.UUID": + { + if Table1.IDMinimum == "" { + Otvet = strings.ReplaceAll(Otvet, TextFind, `var Postgres_ID_Test = `+IDMinimum+``) + } else { + Otvet = strings.ReplaceAll(Otvet, TextFind, `var Postgres_ID_Test, _ = uuid.Parse("`+IDMinimum+`")`) + } + } + case "string": + { + Otvet = strings.ReplaceAll(Otvet, TextFind, `const Postgres_ID_Test = "`+IDMinimum+`"`) + } + default: + { + Otvet = strings.ReplaceAll(Otvet, TextFind, "const Postgres_ID_Test = "+IDMinimum) } - } else { - Otvet = strings.ReplaceAll(Otvet, TextFind, "const Postgres_ID_Test = "+IDMinimum) } return Otvet @@ -1828,15 +1858,24 @@ func Replace_Model_ID_Test(Text string, Table1 *types.Table) string { } DefaultModelName := config.Settings.TEXT_TEMPLATE_MODEL - if PrimaryKeyColumn.TypeGo == "uuid.UUID" { - if Table1.IDMinimum == "" { - Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test = `+IDMinimum+``) - } else { - Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test, _ = uuid.Parse("`+IDMinimum+`")`) + switch PrimaryKeyColumn.TypeGo { + case "uuid.UUID": + { + if Table1.IDMinimum == "" { + Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test = `+IDMinimum+``) + } else { + Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test, _ = uuid.Parse("`+IDMinimum+`")`) + } + Otvet = strings.ReplaceAll(Otvet, ``+DefaultModelName+`_ID_Test`, ``+ModelName+`_ID_Test.String()`) + } + case "string": + { + Otvet = strings.ReplaceAll(Otvet, TextFind, `const `+ModelName+`_ID_Test = "`+IDMinimum+`"`) + } + default: + { + Otvet = strings.ReplaceAll(Otvet, TextFind, `const `+ModelName+`_ID_Test = `+IDMinimum) } - Otvet = strings.ReplaceAll(Otvet, ``+DefaultModelName+`_ID_Test`, ``+ModelName+`_ID_Test.String()`) - } else { - Otvet = strings.ReplaceAll(Otvet, TextFind, `const `+ModelName+`_ID_Test = `+IDMinimum) } return Otvet @@ -1877,9 +1916,9 @@ func ReplaceTextRequestID_PrimaryKey1(Text string, Table1 *types.Table, TextRequ return Otvet } - TypeGo := PrimaryKeyColumn.TypeGo + //TypeGo := PrimaryKeyColumn.TypeGo - TextRequestID, TextID := FindTextProtobufRequest(Table1, TypeGo) + TextRequestID, TextID := FindTextProtobufRequest(Table1) _, GolangCode := FindTextConvertProtobufTypeToGolangType(Table1, PrimaryKeyColumn, "Request.") if GolangCode != "" { @@ -1960,7 +1999,7 @@ func FindNegativeValue(TypeGo string) string { func FindRequestColumnName(Table1 *types.Table, Column1 *types.Column) string { Otvet := "" - _, Otvet = FindTextProtobufRequest(Table1, Column1.TypeGo) + _, Otvet = FindTextProtobufRequest(Table1) return Otvet } diff --git a/internal/create_files/crud_tables/crud_tables.go b/internal/create_files/crud_tables/crud_tables.go index 0229b5c..4db7176 100644 --- a/internal/create_files/crud_tables/crud_tables.go +++ b/internal/create_files/crud_tables/crud_tables.go @@ -631,7 +631,7 @@ func FindTextUpdateEveryColumn1(TextCrudUpdateFunc string, Table1 *types.Table, ModelName := Table1.NameGo ColumnName := Column1.NameGo FuncName := "Update_" + ColumnName - TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Table1, Column1.TypeGo) + TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Table1) //запись null в nullable колонки if Column1.IsNullable == true && (Column1.TableKey != "" || Column1.TypeGo == "time.Time") { @@ -795,7 +795,7 @@ func FindTextUpdateEveryColumnTest1(TextCrudUpdateFunc string, Table1 *types.Tab ModelName := Table1.NameGo ColumnName := Column1.NameGo FuncName := "Update_" + ColumnName - TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Table1, Column1.TypeGo) + TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Table1) DefaultValue := create_files.FindTextDefaultValue(Column1.TypeGo) Otvet = create_files.ReplacePrimaryKeyM_ID(Otvet, Table1) diff --git a/internal/create_files/entities_tables/entities_tables.go b/internal/create_files/entities_tables/entities_tables.go index 723e397..7627a2f 100644 --- a/internal/create_files/entities_tables/entities_tables.go +++ b/internal/create_files/entities_tables/entities_tables.go @@ -631,7 +631,7 @@ func FindTextUpdateEveryColumn(Table1 *types.Table, Column1 *types.Column) strin // Update_` + ColumnName + ` - изменяет объект в БД по ID, присваивает ` + ColumnName + ` func (m *` + ModelName + `) Update_` + ColumnName + `() error { if Crud_` + ModelName + ` == nil { - return constants.ErrorCrudIsNotInit + return db_constants.ErrorCrudIsNotInit } err := Crud_` + ModelName + `.Update_` + ColumnName + `(m) diff --git a/internal/create_files/protobuf/protobuf.go b/internal/create_files/protobuf/protobuf.go index 6ee9a3c..58a65b8 100644 --- a/internal/create_files/protobuf/protobuf.go +++ b/internal/create_files/protobuf/protobuf.go @@ -6,6 +6,7 @@ import ( "github.com/ManyakRus/crud_generator/internal/create_files" "github.com/ManyakRus/crud_generator/internal/folders" "github.com/ManyakRus/crud_generator/internal/types" + "github.com/ManyakRus/crud_generator/pkg/dbmeta" "github.com/ManyakRus/starter/log" "github.com/ManyakRus/starter/micro" "os" @@ -89,6 +90,7 @@ func CreateFileProto(MapAll map[string]*types.Table) error { if config.Settings.NEED_CREATE_CACHE_API == true { TextProtoNew = TextProtoNew + FindTextProtoTable1_Cache(TextProto, Table1) } + TextProto = AddTextMessageRequestID(TextProto, Table1) } //найдём куда вставить текст @@ -135,6 +137,8 @@ func FindTextProtoTable1(TextProto string, Table1 *types.Table) string { Otvet := "\n" //"\n\t//\n" ModelName := Table1.NameGo + //Otvet = Otvet + AddTextMessageRequestID(TextProto, Table1) + Otvet = Otvet + FindTextRead(TextProto, Table1) Otvet = Otvet + FindTextCreate(TextProto, ModelName) Otvet = Otvet + FindTextUpdate(TextProto, ModelName) @@ -276,9 +280,7 @@ func TextRead(Table1 *types.Table) string { return Otvet } - TypeGo := PrimaryKeyColumn.TypeGo - TextRequest := "RequestId" - TextRequest, _ = create_files.FindTextProtobufRequest(Table1, TypeGo) + TextRequest, _ := create_files.FindTextProtobufRequest(Table1) Otvet = "rpc " + ModelName + "_Read(" + TextRequest + ") returns (Response) {}" return Otvet @@ -332,14 +334,14 @@ func FindTextProtoTable1_UpdateEveryColumn(TextProto string, Table1 *types.Table //ModelName := Table1.NameGo - //сортировка по названию таблиц + //сортировка по названию колонок keys := make([]string, 0, len(Table1.MapColumns)) for k := range Table1.MapColumns { keys = append(keys, k) } sort.Strings(keys) - //найдём новый текст для каждой таблицы + //найдём новый текст для каждой колонки for _, key1 := range keys { Column1, ok := Table1.MapColumns[key1] if ok == false { @@ -368,6 +370,9 @@ func FindTextUpdateEveryColumn(TextProto string, Table1 *types.Table, Column1 *t Otvet := "" Otvet2 := TextUpdateEveryColumn(Table1, Column1) + //добавим текст message RequestId_Float64 { + //Otvet = Otvet + AddTextMessageRequestID_ColumnType(TextProto, Table1, Column1) + //проверка такой текст уже есть pos1 := strings.Index(TextProto, Otvet2) if pos1 >= 0 { @@ -430,7 +435,7 @@ func TextReadFromCache(Table1 *types.Table) string { return Otvet } - TextRequestId, _ := create_files.FindTextProtobufRequest(Table1, PrimaryKeyColumn.TypeGo) + TextRequestId, _ := create_files.FindTextProtobufRequest(Table1) ModelName := Table1.NameGo Otvet = "rpc " + ModelName + "_ReadFromCache(" + TextRequestId + ") returns (Response) {}" @@ -469,3 +474,122 @@ func TextUpdateManyFields(ModelName string) string { return Otvet } + +// AddTextMessageRequestID - в текст .proto добавляет message с RequestID +func AddTextMessageRequestID1(Text string, Table1 *types.Table) string { + Otvet := Text + + //найдём текст RequestID + PrimaryKeyColumn := create_files.FindPrimaryKeyColumn(Table1) + if PrimaryKeyColumn == nil { + return Otvet + } + + TextRequest, TextFieldName := create_files.FindTextProtobufRequest(Table1) + + //найдём уже есть message + TextFind := "message " + TextRequest + " {" + pos1 := strings.Index(Otvet, TextFind) + if pos1 >= 0 { + return Otvet + } + + //найдём ProtobufTypePK + MappingPK, ok := dbmeta.GetMappings()[PrimaryKeyColumn.Type] + if ok == false { + log.Error("Неизвестный тип столбца " + PrimaryKeyColumn.Type) + return Otvet + } + ProtobufTypePK := MappingPK.ProtobufType + + //добавим message + TextMessage := ` +// ` + TextRequest + ` - параметры запроса на сервер +message ` + TextRequest + ` { + uint32 VersionModel= 1; //версия структуры модели + ` + ProtobufTypePK + ` ` + TextFieldName + ` = 2; // id записи в БД +} +` + + Otvet = Otvet + TextMessage + + return Otvet +} + +// AddTextMessageRequestID_ColumnType - в текст .proto добавляет message с RequestID_Int64 +func AddTextMessageRequestID_ColumnType(Text string, Table1 *types.Table, Column1 *types.Column) string { + Otvet := Text + + //найдём текст RequestID + PrimaryKeyColumn := create_files.FindPrimaryKeyColumn(Table1) + if PrimaryKeyColumn == nil { + return Otvet + } + // + _, FieldNamePK := create_files.FindTextProtobufRequest(Table1) + + TextRequest, FieldName, _, _ := create_files.FindTextProtobufRequest_ID_Type(Table1, Column1, "_") + + //найдём уже есть message + TextFind := "message " + TextRequest + " {" + pos1 := strings.Index(Otvet, TextFind) + if pos1 >= 0 { + return Otvet + } + + //найдём ProtobufTypePK + MappingPK, ok := dbmeta.GetMappings()[PrimaryKeyColumn.Type] + if ok == false { + log.Error("Неизвестный тип столбца " + PrimaryKeyColumn.Type) + return Otvet + } + ProtobufTypePK := MappingPK.ProtobufType + + //найдём ProtobufTypeColumn + Mapping1, ok := dbmeta.GetMappings()[Column1.Type] + if ok == false { + log.Error("Неизвестный тип столбца " + Column1.Type) + return Otvet + } + ProtobufTypeColumn := Mapping1.ProtobufType + + //добавим message + TextMessage := ` +// ` + TextRequest + ` - параметры запроса на сервер +message ` + TextRequest + ` { + uint32 VersionModel= 1; //версия структуры модели + ` + ProtobufTypePK + ` ` + FieldNamePK + ` = 2; // id записи в БД + ` + ProtobufTypeColumn + ` ` + FieldName + ` = 3; // значение поиска +} +` + + Otvet = Otvet + TextMessage + + return Otvet +} + +// AddTextMessageRequestID - возвращает текст в.proto для таблицы +func AddTextMessageRequestID(TextProto string, Table1 *types.Table) string { + Otvet := TextProto //"\n\t//\n" + + Otvet = AddTextMessageRequestID1(Otvet, Table1) + + //сортировка по названию колонок + keys := make([]string, 0, len(Table1.MapColumns)) + for k := range Table1.MapColumns { + keys = append(keys, k) + } + sort.Strings(keys) + + //для каждой колонки добавим добавим message RequestId_Int64 + for _, key1 := range keys { + Column1, ok := Table1.MapColumns[key1] + if ok == false { + log.Panic("FindTextProtoTable1_UpdateEveryColumn() Table1.MapColumns[key1] = false") + } + + Otvet = AddTextMessageRequestID_ColumnType(Otvet, Table1, Column1) + } + + return Otvet +}