mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2025-02-20 08:08:17 +02:00
сделал find_by_functions.json
This commit is contained in:
parent
1829544c26
commit
f1d0e30361
@ -0,0 +1,14 @@
|
|||||||
|
package grpc_lawsuit_status_types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client_func"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_constants"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc_nrpc"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,43 @@
|
|||||||
|
// FieldNamesWithUnderline - находит модель в БД по FieldNamesWithPlus
|
||||||
|
func (crud Crud_GRPC) FindBy_FieldNamesWithUnderline(m *lawsuit_status_types.LawsuitStatusType) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
// подключение
|
||||||
|
grpc_client_func.Func_Connect_GRPC_NRPC.Connect_GRPC_NRPC()
|
||||||
|
|
||||||
|
// подготовка запроса
|
||||||
|
var VersionModel = crud.GetVersionModel()
|
||||||
|
|
||||||
|
Request := &grpc_proto.RequestName{}
|
||||||
|
Request.VersionModel = VersionModel
|
||||||
|
Request.RequestFieldName = m.FieldName
|
||||||
|
|
||||||
|
ctxMain := context.Background()
|
||||||
|
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(grpc_constants.GetTimeoutSeconds()))
|
||||||
|
defer ctxCancelFunc()
|
||||||
|
|
||||||
|
// запрос
|
||||||
|
var Response *grpc_proto.Response
|
||||||
|
if grpc_nrpc.NeedNRPC == true {
|
||||||
|
Response, err = nrpc_client.Client.LawsuitStatusType_FindBy_FieldNamesWithUnderline(Request)
|
||||||
|
} else {
|
||||||
|
Response, err = grpc_client_func.Client.LawsuitStatusType_FindBy_FieldNamesWithUnderline(ctx, Request)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
sError := err.Error()
|
||||||
|
if grpc_client_func.IsErrorModelVersion(err) == true {
|
||||||
|
log.Panic("table: ", TableName, " error: ", err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ответ
|
||||||
|
sModel := Response.ModelString
|
||||||
|
err = json.Unmarshal([]byte(sModel), f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
|||||||
|
func TestFindBy_FieldsWithUnderline(t *testing.T) {
|
||||||
|
config_main.LoadEnv()
|
||||||
|
grpc_client_func.Func_Connect_GRPC_NRPC.Connect_GRPC_NRPC()
|
||||||
|
defer grpc_client.CloseConnection()
|
||||||
|
|
||||||
|
crud := Crud_GRPC{}
|
||||||
|
Otvet := lawsuit_status_types.LawsuitStatusType{}
|
||||||
|
Otvet.FieldName = 0
|
||||||
|
err := crud.FindBy_FieldNamesWithUnderline(&Otvet)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Log("TestFindBy_FieldNamesWithUnderline() error: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
|||||||
|
package grpc_lawsuit_status_types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ManyakRus/starter/config_main"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,14 @@
|
|||||||
|
package grpc_lawsuit_status_types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client_func"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_constants"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc_nrpc"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,44 @@
|
|||||||
|
// FieldNamesWithUnderline - находит массив записей в БД по FieldNamesWithPlus
|
||||||
|
func (crud Crud_GRPC) FindMassBy_FieldNamesWithUnderline(m *lawsuit_status_types.LawsuitStatusType) ([]lawsuit_status_types.LawsuitStatusType, error) {
|
||||||
|
Otvet := make([]files.File, 0)
|
||||||
|
// var Otvet model.File
|
||||||
|
|
||||||
|
// подключение
|
||||||
|
if grpc_client_func.Client == nil {
|
||||||
|
grpc_client_func.Func_Connect_GRPC_NRPC.Connect_GRPC_NRPC()
|
||||||
|
}
|
||||||
|
|
||||||
|
// подготовка запроса
|
||||||
|
var VersionModel = crud.GetVersionModel()
|
||||||
|
|
||||||
|
Request := &grpc_proto.RequestName{}
|
||||||
|
Request.VersionModel = VersionModel
|
||||||
|
Request.RequestFieldName = m.FieldName
|
||||||
|
|
||||||
|
ctxMain := context.Background()
|
||||||
|
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(grpc_constants.GetTimeoutSeconds()))
|
||||||
|
defer ctxCancelFunc()
|
||||||
|
|
||||||
|
// запрос
|
||||||
|
Response, err := grpc_client_func.Client.LawsuitStatusType_FindMassBy_FieldNamesWithUnderline(ctx, Request)
|
||||||
|
if err != nil {
|
||||||
|
sError := err.Error()
|
||||||
|
if grpc_client_func.IsErrorModelVersion(err) == true {
|
||||||
|
log.Panic("table: ", TableName, " error: ", err)
|
||||||
|
}
|
||||||
|
return Otvet, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ответ
|
||||||
|
var m1 lawsuit_status_types.LawsuitStatusType
|
||||||
|
for _, v := range Response.MassModelString {
|
||||||
|
err = json.Unmarshal([]byte(v), &m1)
|
||||||
|
if err != nil {
|
||||||
|
return Otvet, err
|
||||||
|
}
|
||||||
|
Otvet = append(Otvet, m1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Otvet, err
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
|||||||
|
func TestCrud_GRPC_FindMassBy_FieldsWithUnderline(t *testing.T) {
|
||||||
|
config_main.LoadEnv()
|
||||||
|
grpc_client_func.Func_Connect_GRPC_NRPC.Connect_GRPC_NRPC()
|
||||||
|
defer grpc_client.CloseConnection()
|
||||||
|
|
||||||
|
crud := Crud_GRPC{}
|
||||||
|
Model1 := lawsuit_status_types.LawsuitStatusType{}
|
||||||
|
Model1.FieldName= 41
|
||||||
|
Otvet, err := crud.FindMassBy_FieldNamesWithUnderline(&Model1)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Log("TestCrud_GRPC_FindMassBy_FieldNamesWithUnderline() error: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
|||||||
|
package grpc_lawsuit_status_types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ManyakRus/starter/config_main"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
@ -1,9 +1,7 @@
|
|||||||
Name Level Lines count Functions count
|
Name Level Lines count Functions count
|
||||||
. 1 792417 30025
|
|
||||||
bin 2 777203 29506
|
|
||||||
cmd 2 46 3
|
cmd 2 46 3
|
||||||
docs 2 0 0
|
docs 2 0 0
|
||||||
examples 2 599 26
|
examples 2 599 26
|
||||||
internal 2 10825 343
|
internal 2 15305 456
|
||||||
pkg 2 3744 147
|
pkg 2 3744 147
|
||||||
scripts 2 0 0
|
scripts 2 0 0
|
||||||
|
@ -119,6 +119,15 @@ type SettingsINI struct {
|
|||||||
TEMPLATES_MODEL_FINDBY_FUNCTION_FILENAME string
|
TEMPLATES_MODEL_FINDBY_FUNCTION_FILENAME string
|
||||||
TEMPLATES_MODEL_FINDMASSBY_FILENAME string
|
TEMPLATES_MODEL_FINDMASSBY_FILENAME string
|
||||||
TEMPLATES_MODEL_FINDMASSBY_FUNCTION_FILENAME string
|
TEMPLATES_MODEL_FINDMASSBY_FUNCTION_FILENAME string
|
||||||
|
|
||||||
|
TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_FILENAME string
|
||||||
|
TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_TEST_FILENAME string
|
||||||
|
TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_FUNCTION_FILENAME string
|
||||||
|
TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_FUNCTION_TEST_FILENAME string
|
||||||
|
TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_FILENAME string
|
||||||
|
TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_TEST_FILENAME string
|
||||||
|
TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_FUNCTION_FILENAME string
|
||||||
|
TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_FUNCTION_TEST_FILENAME string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Getenv(Name string, IsRequired bool) string {
|
func Getenv(Name string, IsRequired bool) string {
|
||||||
@ -670,6 +679,46 @@ func FillSettings() {
|
|||||||
s = Getenv(Name, true)
|
s = Getenv(Name, true)
|
||||||
Settings.TEMPLATES_MODEL_FINDMASSBY_FUNCTION_FILENAME = s
|
Settings.TEMPLATES_MODEL_FINDMASSBY_FUNCTION_FILENAME = s
|
||||||
|
|
||||||
|
//
|
||||||
|
Name = "TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_FILENAME"
|
||||||
|
s = Getenv(Name, true)
|
||||||
|
Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_FILENAME = s
|
||||||
|
|
||||||
|
//
|
||||||
|
Name = "TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_TEST_FILENAME"
|
||||||
|
s = Getenv(Name, true)
|
||||||
|
Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_TEST_FILENAME = s
|
||||||
|
|
||||||
|
//
|
||||||
|
Name = "TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_FUNCTION_FILENAME"
|
||||||
|
s = Getenv(Name, true)
|
||||||
|
Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_FUNCTION_FILENAME = s
|
||||||
|
|
||||||
|
//
|
||||||
|
Name = "TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_FUNCTION_TEST_FILENAME"
|
||||||
|
s = Getenv(Name, true)
|
||||||
|
Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_FUNCTION_TEST_FILENAME = s
|
||||||
|
|
||||||
|
//
|
||||||
|
Name = "TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_FILENAME"
|
||||||
|
s = Getenv(Name, true)
|
||||||
|
Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_FILENAME = s
|
||||||
|
|
||||||
|
//
|
||||||
|
Name = "TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_TEST_FILENAME"
|
||||||
|
s = Getenv(Name, true)
|
||||||
|
Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_TEST_FILENAME = s
|
||||||
|
|
||||||
|
//
|
||||||
|
Name = "TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_FUNCTION_FILENAME"
|
||||||
|
s = Getenv(Name, true)
|
||||||
|
Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_FUNCTION_FILENAME = s
|
||||||
|
|
||||||
|
//
|
||||||
|
Name = "TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_FUNCTION_TEST_FILENAME"
|
||||||
|
s = Getenv(Name, true)
|
||||||
|
Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_FUNCTION_TEST_FILENAME = s
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentDirectory - возвращает текущую директорию ОС
|
// CurrentDirectory - возвращает текущую директорию ОС
|
||||||
|
@ -846,8 +846,8 @@ func Find_GRPC_NRPC_URL() string {
|
|||||||
return Otvet
|
return Otvet
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find_grpc_client_func_URL - возвращает URL репозитория с пакетом "grpc_client_func"
|
// Find_GRPCClient_func_URL - возвращает URL репозитория с пакетом "grpc_client_func"
|
||||||
func Find_grpc_client_func_URL() string {
|
func Find_GRPCClient_func_URL() string {
|
||||||
Otvet := ""
|
Otvet := ""
|
||||||
|
|
||||||
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT_FUNC
|
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT_FUNC
|
||||||
@ -2889,7 +2889,7 @@ func FindRequestFieldName_FromMass(Column *types.Column, MassColumns []*types.Co
|
|||||||
Number := 0
|
Number := 0
|
||||||
for _, Column1 := range MassColumns {
|
for _, Column1 := range MassColumns {
|
||||||
TypeProto1 := ConvertGolangTypeNameToProtobufTypeName(Column1.TypeGo)
|
TypeProto1 := ConvertGolangTypeNameToProtobufTypeName(Column1.TypeGo)
|
||||||
if TypeProto == TypeProto1 {
|
if TypeProto == TypeProto1 && Column != Column1 {
|
||||||
Number = Number + 1
|
Number = Number + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2901,7 +2901,9 @@ func FindRequestFieldName_FromMass(Column *types.Column, MassColumns []*types.Co
|
|||||||
Suffix := "_" + strconv.Itoa(Number)
|
Suffix := "_" + strconv.Itoa(Number)
|
||||||
|
|
||||||
Otvet = ConvertGolangTypeNameToProtobufFieldName(Column.Type)
|
Otvet = ConvertGolangTypeNameToProtobufFieldName(Column.Type)
|
||||||
Otvet = Otvet + Suffix
|
if Number > 1 {
|
||||||
|
Otvet = Otvet + Suffix
|
||||||
|
}
|
||||||
|
|
||||||
return Otvet
|
return Otvet
|
||||||
}
|
}
|
||||||
@ -3037,6 +3039,14 @@ func ConvertProtobufVariableToGolangVariable_with_MassColumns(Column *types.Colu
|
|||||||
return VariableField, GolangCode
|
return VariableField, GolangCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//// ConvertGolangVariableToProtobufVariable_with_MassColumns - преобразованное в тип protobuf из golang
|
||||||
|
//func ConvertGolangVariableToProtobufVariable_with_MassColumns(Column *types.Column, MassColumns []*types.Column) string {
|
||||||
|
// Otvet := ""
|
||||||
|
//
|
||||||
|
// Otvet = FindRequestFieldName_FromMass(Column, MassColumns)
|
||||||
|
// return Otvet
|
||||||
|
//}
|
||||||
|
|
||||||
// FindRequestFieldNames_FromMass - возвращает строку с именами колонок для Protobuf
|
// FindRequestFieldNames_FromMass - возвращает строку с именами колонок для Protobuf
|
||||||
func FindRequestFieldNames_FromMass(MassColumns []*types.Column) string {
|
func FindRequestFieldNames_FromMass(MassColumns []*types.Column) string {
|
||||||
Otvet := ""
|
Otvet := ""
|
||||||
|
@ -80,7 +80,7 @@ func CreateGRPCClient() error {
|
|||||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, NRPC_CLIENT_URL)
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, NRPC_CLIENT_URL)
|
||||||
|
|
||||||
//grpc_client_func
|
//grpc_client_func
|
||||||
GRPC_CLIENT_FUNC_URL := create_files.Find_grpc_client_func_URL()
|
GRPC_CLIENT_FUNC_URL := create_files.Find_GRPCClient_func_URL()
|
||||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPC_CLIENT_FUNC_URL)
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPC_CLIENT_FUNC_URL)
|
||||||
|
|
||||||
//CRUD_STARTER_URL
|
//CRUD_STARTER_URL
|
||||||
|
@ -79,6 +79,21 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
err = CreateFilesFindBy(Table1)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("CreateFilesFindBy() table: ", Table1.Name, " error: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
err = CreateFilesFindMassBy(Table1)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("CreateFilesFindMassBy() table: ", Table1.Name, " error: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@ -131,7 +146,7 @@ func CreateFiles(Table1 *types.Table) error {
|
|||||||
//TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCClientlURL)
|
//TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCClientlURL)
|
||||||
|
|
||||||
//grpc client func
|
//grpc client func
|
||||||
GRPCClientFuncURL := create_files.Find_grpc_client_func_URL()
|
GRPCClientFuncURL := create_files.Find_GRPCClient_func_URL()
|
||||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPCClientFuncURL)
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPCClientFuncURL)
|
||||||
|
|
||||||
//nrpc client
|
//nrpc client
|
||||||
@ -439,7 +454,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
|
|||||||
//TextGRPC_Client = create_files.AddImport(TextGRPC_Client, GRPCClientURL)
|
//TextGRPC_Client = create_files.AddImport(TextGRPC_Client, GRPCClientURL)
|
||||||
|
|
||||||
//grpc client func
|
//grpc client func
|
||||||
GRPCClientFuncURL := create_files.Find_grpc_client_func_URL()
|
GRPCClientFuncURL := create_files.Find_GRPCClient_func_URL()
|
||||||
TextGRPC_Client = create_files.AddImport(TextGRPC_Client, GRPCClientFuncURL)
|
TextGRPC_Client = create_files.AddImport(TextGRPC_Client, GRPCClientFuncURL)
|
||||||
|
|
||||||
GRPCConstantsURL := create_files.FindGRPCConstantsURL()
|
GRPCConstantsURL := create_files.FindGRPCConstantsURL()
|
||||||
@ -774,7 +789,7 @@ func CreateFiles_GRPC_Client_Cache(Table1 *types.Table) error {
|
|||||||
//TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCClientlURL)
|
//TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCClientlURL)
|
||||||
|
|
||||||
//grpc client func
|
//grpc client func
|
||||||
GRPCClientFuncURL := create_files.Find_grpc_client_func_URL()
|
GRPCClientFuncURL := create_files.Find_GRPCClient_func_URL()
|
||||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPCClientFuncURL)
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPCClientFuncURL)
|
||||||
|
|
||||||
//nrpc client
|
//nrpc client
|
||||||
|
@ -0,0 +1,317 @@
|
|||||||
|
package grpc_client_tables
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/config"
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/constants"
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/create_files"
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/types"
|
||||||
|
"github.com/ManyakRus/starter/log"
|
||||||
|
"github.com/ManyakRus/starter/micro"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreateFilesFindBy - создаёт 1 файл в папке grpc_client
|
||||||
|
func CreateFilesFindBy(Table1 *types.Table) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if len(types.MassFindBy_String) == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
//чтение файлов
|
||||||
|
DirBin := micro.ProgramDir_bin()
|
||||||
|
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||||
|
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||||
|
DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||||
|
DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||||
|
|
||||||
|
FilenameTemplateGRPCClient := DirTemplatesGRPCClient + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_FILENAME
|
||||||
|
TableName := strings.ToLower(Table1.Name)
|
||||||
|
DirReadyTable := DirReadyGRPCClient
|
||||||
|
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CLIENT_GRPC + TableName + micro.SeparatorFile() + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_findby.go"
|
||||||
|
|
||||||
|
//создадим каталог
|
||||||
|
ok, err := micro.FileExists(DirReadyTable)
|
||||||
|
if ok == false {
|
||||||
|
err = os.MkdirAll(DirReadyTable, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//загрузим шаблон файла
|
||||||
|
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("ReadFile() ", FilenameTemplateGRPCClient, " error: ", err)
|
||||||
|
}
|
||||||
|
TextGRPCClient := string(bytes)
|
||||||
|
|
||||||
|
//загрузим шаблон файла функции
|
||||||
|
FilenameTemplateGRPCClientFunction := DirTemplatesGRPCClient + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_FUNCTION_FILENAME
|
||||||
|
bytes, err = os.ReadFile(FilenameTemplateGRPCClientFunction)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("ReadFile() ", FilenameTemplateGRPCClientFunction, " error: ", err)
|
||||||
|
}
|
||||||
|
TextTemplatedFunction := string(bytes)
|
||||||
|
|
||||||
|
//заменим имя пакета на новое
|
||||||
|
TextGRPCClient = create_files.ReplacePackageName(TextGRPCClient, DirReadyTable)
|
||||||
|
|
||||||
|
ModelName := Table1.NameGo
|
||||||
|
//заменим импорты
|
||||||
|
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||||
|
TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient)
|
||||||
|
|
||||||
|
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, ModelTableURL)
|
||||||
|
|
||||||
|
ProtoURL := create_files.FindProtoURL()
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, ProtoURL)
|
||||||
|
|
||||||
|
GRPCClient_func_URL := create_files.Find_GRPCClient_func_URL()
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPCClient_func_URL)
|
||||||
|
|
||||||
|
GRPCConstantsURL := create_files.FindGRPCConstantsURL()
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPCConstantsURL)
|
||||||
|
|
||||||
|
GRPC_NRPC_URL := create_files.Find_GRPC_NRPC_URL()
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPC_NRPC_URL)
|
||||||
|
|
||||||
|
NRPC_Client_URL := create_files.FindNRPC_Client_URL()
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, NRPC_Client_URL)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//создание функций
|
||||||
|
TextClientGRPCFunc := CreateFilesFindByTable(Table1, TextTemplatedFunction)
|
||||||
|
if TextClientGRPCFunc == "" {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
TextGRPCClient = TextGRPCClient + TextClientGRPCFunc
|
||||||
|
|
||||||
|
//создание текста
|
||||||
|
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||||
|
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||||
|
TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient
|
||||||
|
|
||||||
|
//замена импортов на новые URL
|
||||||
|
TextGRPCClient = create_files.ReplaceServiceURLImports(TextGRPCClient)
|
||||||
|
|
||||||
|
//uuid
|
||||||
|
TextGRPCClient = create_files.CheckAndAddImportUUID_FromText(TextGRPCClient)
|
||||||
|
|
||||||
|
//alias
|
||||||
|
TextGRPCClient = create_files.CheckAndAddImportAlias(TextGRPCClient)
|
||||||
|
|
||||||
|
//удаление пустого импорта
|
||||||
|
TextGRPCClient = create_files.DeleteEmptyImport(TextGRPCClient)
|
||||||
|
|
||||||
|
//удаление пустых строк
|
||||||
|
TextGRPCClient = create_files.DeleteEmptyLines(TextGRPCClient)
|
||||||
|
|
||||||
|
//запись файла
|
||||||
|
err = os.WriteFile(FilenameReady, []byte(TextGRPCClient), constants.FILE_PERMISSIONS)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFilesFindByTable - создаёт текст всех функций
|
||||||
|
func CreateFilesFindByTable(Table1 *types.Table, TextTemplateFunction string) string {
|
||||||
|
Otvet := ""
|
||||||
|
|
||||||
|
for _, TableColumns1 := range types.MassFindBy_String {
|
||||||
|
if TableColumns1.TableName != Table1.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
Otvet1 := CreateFilesFindByTable1(Table1, TextTemplateFunction, TableColumns1.MassColumnNames)
|
||||||
|
Otvet = Otvet + Otvet1
|
||||||
|
}
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFilesFindByTable1 - создаёт текст всех функций
|
||||||
|
func CreateFilesFindByTable1(Table1 *types.Table, TextTemplateFunction string, MassColumnsString []string) string {
|
||||||
|
Otvet := TextTemplateFunction
|
||||||
|
|
||||||
|
//
|
||||||
|
FieldNamesWithUnderline := ""
|
||||||
|
FieldNamesWithComma := ""
|
||||||
|
TextAssign := ""
|
||||||
|
|
||||||
|
MassColumns := create_files.FindMassColumns_from_MassColumnsString(Table1, MassColumnsString)
|
||||||
|
|
||||||
|
//
|
||||||
|
TextFind := "\t" + `Request.RequestFieldName = m.FieldName` + "\n"
|
||||||
|
Underline := ""
|
||||||
|
Plus := ""
|
||||||
|
RequestName := "Request_"
|
||||||
|
for _, ColumnName1 := range MassColumnsString {
|
||||||
|
Column1, ok := Table1.MapColumns[ColumnName1]
|
||||||
|
if ok == false {
|
||||||
|
log.Panic(Table1.Name + " .MapColumns[" + ColumnName1 + "] = false")
|
||||||
|
}
|
||||||
|
TextRequest := create_files.FindRequestFieldName_FromMass(Column1, MassColumns)
|
||||||
|
TextAssign = TextAssign + "\tRequest." + TextRequest + " = m." + Column1.NameGo + "\n"
|
||||||
|
FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + Column1.NameGo
|
||||||
|
FieldNamesWithComma = FieldNamesWithComma + Plus + Column1.NameGo
|
||||||
|
|
||||||
|
ProtoTypeName := create_files.ConvertGolangTypeNameToProtobufFieldName(Column1.TypeGo)
|
||||||
|
RequestName = RequestName + Underline + ProtoTypeName
|
||||||
|
|
||||||
|
Underline = "_"
|
||||||
|
Plus = "+"
|
||||||
|
}
|
||||||
|
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "RequestName", RequestName)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, TextFind, TextAssign)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithPlus", FieldNamesWithComma)
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFilesFindByTest - создаёт 1 файл в папке grpc_client
|
||||||
|
func CreateFilesFindByTest(Table1 *types.Table) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if len(types.MassFindBy_String) == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
//чтение файлов
|
||||||
|
DirBin := micro.ProgramDir_bin()
|
||||||
|
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||||
|
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||||
|
DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||||
|
DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||||
|
|
||||||
|
FilenameTemplateGRPCClient := DirTemplatesGRPCClient + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_FILENAME
|
||||||
|
TableName := strings.ToLower(Table1.Name)
|
||||||
|
DirReadyTable := DirReadyGRPCClient
|
||||||
|
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_findby_test.go"
|
||||||
|
|
||||||
|
//создадим каталог
|
||||||
|
ok, err := micro.FileExists(DirReadyTable)
|
||||||
|
if ok == false {
|
||||||
|
err = os.MkdirAll(DirReadyTable, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//загрузим шаблон файла
|
||||||
|
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("ReadFile() ", FilenameTemplateGRPCClient, " error: ", err)
|
||||||
|
}
|
||||||
|
TextGRPCClient := string(bytes)
|
||||||
|
|
||||||
|
//загрузим шаблон файла функции
|
||||||
|
FilenameTemplateGRPCClientFunction := DirTemplatesGRPCClient + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDBY_FUNCTION_TEST_FILENAME
|
||||||
|
bytes, err = os.ReadFile(FilenameTemplateGRPCClientFunction)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("ReadFile() ", FilenameTemplateGRPCClientFunction, " error: ", err)
|
||||||
|
}
|
||||||
|
TextTemplatedFunction := string(bytes)
|
||||||
|
|
||||||
|
//заменим имя пакета на новое
|
||||||
|
TextGRPCClient = create_files.ReplacePackageName(TextGRPCClient, DirReadyTable)
|
||||||
|
|
||||||
|
ModelName := Table1.NameGo
|
||||||
|
//заменим импорты
|
||||||
|
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||||
|
TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient)
|
||||||
|
|
||||||
|
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, ModelTableURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
//создание функций
|
||||||
|
TextGRPCClientFunc := CreateFilesFindByTestTable(Table1, TextTemplatedFunction)
|
||||||
|
if TextGRPCClientFunc == "" {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
TextGRPCClient = TextGRPCClient + TextGRPCClientFunc
|
||||||
|
|
||||||
|
//создание текста
|
||||||
|
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||||
|
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||||
|
TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient
|
||||||
|
|
||||||
|
//замена импортов на новые URL
|
||||||
|
TextGRPCClient = create_files.ReplaceServiceURLImports(TextGRPCClient)
|
||||||
|
|
||||||
|
//uuid
|
||||||
|
TextGRPCClient = create_files.CheckAndAddImportUUID_FromText(TextGRPCClient)
|
||||||
|
|
||||||
|
//alias
|
||||||
|
TextGRPCClient = create_files.CheckAndAddImportAlias(TextGRPCClient)
|
||||||
|
|
||||||
|
//удаление пустого импорта
|
||||||
|
TextGRPCClient = create_files.DeleteEmptyImport(TextGRPCClient)
|
||||||
|
|
||||||
|
//удаление пустых строк
|
||||||
|
TextGRPCClient = create_files.DeleteEmptyLines(TextGRPCClient)
|
||||||
|
|
||||||
|
//запись файла
|
||||||
|
err = os.WriteFile(FilenameReady, []byte(TextGRPCClient), constants.FILE_PERMISSIONS)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFilesFindByTestTable - создаёт текст всех функций
|
||||||
|
func CreateFilesFindByTestTable(Table1 *types.Table, TextTemplateFunction string) string {
|
||||||
|
Otvet := ""
|
||||||
|
|
||||||
|
for _, TableColumns1 := range types.MassFindBy_String {
|
||||||
|
if TableColumns1.TableName != Table1.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
Otvet1 := CreateFilesFindByTestTable1(Table1, TextTemplateFunction, TableColumns1.MassColumnNames)
|
||||||
|
Otvet = Otvet + Otvet1
|
||||||
|
}
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFilesFindByTestTable1 - создаёт текст всех функций
|
||||||
|
func CreateFilesFindByTestTable1(Table1 *types.Table, TextTemplateFunction string, MassColumnsString []string) string {
|
||||||
|
Otvet := TextTemplateFunction
|
||||||
|
|
||||||
|
//
|
||||||
|
FieldNamesWithUnderline := ""
|
||||||
|
FieldNamesWithComma := ""
|
||||||
|
|
||||||
|
//
|
||||||
|
TextAssignFind := "\t" + `Request.RequestFieldName = 0` + "\n"
|
||||||
|
TextAssign := ""
|
||||||
|
TextFieldName_TEST := ""
|
||||||
|
|
||||||
|
MassColumns := create_files.FindMassColumns_from_MassColumnsString(Table1, MassColumnsString)
|
||||||
|
|
||||||
|
Underline := ""
|
||||||
|
Comma := ""
|
||||||
|
for _, ColumnName1 := range MassColumnsString {
|
||||||
|
Column1, ok := Table1.MapColumns[ColumnName1]
|
||||||
|
if ok == false {
|
||||||
|
log.Panic(Table1.Name + " .MapColumns[" + ColumnName1 + "] = false")
|
||||||
|
}
|
||||||
|
DefaultValue := create_files.FindTextDefaultValue(Column1.TypeGo)
|
||||||
|
RequestFieldName := create_files.FindRequestFieldName_FromMass(Column1, MassColumns)
|
||||||
|
TextAssign = TextAssign + "\t" + `Request` + RequestFieldName + ` = ` + DefaultValue + "\n"
|
||||||
|
FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + Column1.NameGo
|
||||||
|
FieldNamesWithComma = FieldNamesWithComma + Comma + Column1.NameGo
|
||||||
|
TextFieldName_TEST = TextFieldName_TEST + Comma + DefaultValue
|
||||||
|
|
||||||
|
Underline = "_"
|
||||||
|
Comma = ", "
|
||||||
|
}
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, TextAssignFind, TextAssign)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithComma", FieldNamesWithComma)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "FieldNamesDefault", TextFieldName_TEST)
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
@ -0,0 +1,317 @@
|
|||||||
|
package grpc_client_tables
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/config"
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/constants"
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/create_files"
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/types"
|
||||||
|
"github.com/ManyakRus/starter/log"
|
||||||
|
"github.com/ManyakRus/starter/micro"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreateFilesFindMassBy - создаёт 1 файл в папке grpc_client
|
||||||
|
func CreateFilesFindMassBy(Table1 *types.Table) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if len(types.MassFindMassBy_String) == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
//чтение файлов
|
||||||
|
DirBin := micro.ProgramDir_bin()
|
||||||
|
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||||
|
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||||
|
DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||||
|
DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||||
|
|
||||||
|
FilenameTemplateGRPCClient := DirTemplatesGRPCClient + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_FILENAME
|
||||||
|
TableName := strings.ToLower(Table1.Name)
|
||||||
|
DirReadyTable := DirReadyGRPCClient
|
||||||
|
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CLIENT_GRPC + TableName + micro.SeparatorFile() + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_findmassby.go"
|
||||||
|
|
||||||
|
//создадим каталог
|
||||||
|
ok, err := micro.FileExists(DirReadyTable)
|
||||||
|
if ok == false {
|
||||||
|
err = os.MkdirAll(DirReadyTable, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//загрузим шаблон файла
|
||||||
|
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("ReadFile() ", FilenameTemplateGRPCClient, " error: ", err)
|
||||||
|
}
|
||||||
|
TextGRPCClient := string(bytes)
|
||||||
|
|
||||||
|
//загрузим шаблон файла функции
|
||||||
|
FilenameTemplateGRPCClientFunction := DirTemplatesGRPCClient + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_FUNCTION_FILENAME
|
||||||
|
bytes, err = os.ReadFile(FilenameTemplateGRPCClientFunction)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("ReadFile() ", FilenameTemplateGRPCClientFunction, " error: ", err)
|
||||||
|
}
|
||||||
|
TextTemplatedFunction := string(bytes)
|
||||||
|
|
||||||
|
//заменим имя пакета на новое
|
||||||
|
TextGRPCClient = create_files.ReplacePackageName(TextGRPCClient, DirReadyTable)
|
||||||
|
|
||||||
|
ModelName := Table1.NameGo
|
||||||
|
//заменим импорты
|
||||||
|
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||||
|
TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient)
|
||||||
|
|
||||||
|
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, ModelTableURL)
|
||||||
|
|
||||||
|
ProtoURL := create_files.FindProtoURL()
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, ProtoURL)
|
||||||
|
|
||||||
|
GRPCClient_func_URL := create_files.Find_GRPCClient_func_URL()
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPCClient_func_URL)
|
||||||
|
|
||||||
|
GRPCConstantsURL := create_files.FindGRPCConstantsURL()
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPCConstantsURL)
|
||||||
|
|
||||||
|
GRPC_NRPC_URL := create_files.Find_GRPC_NRPC_URL()
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPC_NRPC_URL)
|
||||||
|
|
||||||
|
NRPC_Client_URL := create_files.FindNRPC_Client_URL()
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, NRPC_Client_URL)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//создание функций
|
||||||
|
TextGRPCClientFunc := CreateFilesFindMassByTable(Table1, TextTemplatedFunction)
|
||||||
|
if TextGRPCClientFunc == "" {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
TextGRPCClient = TextGRPCClient + TextGRPCClientFunc
|
||||||
|
|
||||||
|
//создание текста
|
||||||
|
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||||
|
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||||
|
TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient
|
||||||
|
|
||||||
|
//замена импортов на новые URL
|
||||||
|
TextGRPCClient = create_files.ReplaceServiceURLImports(TextGRPCClient)
|
||||||
|
|
||||||
|
//uuid
|
||||||
|
TextGRPCClient = create_files.CheckAndAddImportUUID_FromText(TextGRPCClient)
|
||||||
|
|
||||||
|
//alias
|
||||||
|
TextGRPCClient = create_files.CheckAndAddImportAlias(TextGRPCClient)
|
||||||
|
|
||||||
|
//удаление пустого импорта
|
||||||
|
TextGRPCClient = create_files.DeleteEmptyImport(TextGRPCClient)
|
||||||
|
|
||||||
|
//удаление пустых строк
|
||||||
|
TextGRPCClient = create_files.DeleteEmptyLines(TextGRPCClient)
|
||||||
|
|
||||||
|
//запись файла
|
||||||
|
err = os.WriteFile(FilenameReady, []byte(TextGRPCClient), constants.FILE_PERMISSIONS)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFilesFindMassByTable - создаёт текст всех функций
|
||||||
|
func CreateFilesFindMassByTable(Table1 *types.Table, TextTemplateFunction string) string {
|
||||||
|
Otvet := ""
|
||||||
|
|
||||||
|
for _, TableColumns1 := range types.MassFindMassBy_String {
|
||||||
|
if TableColumns1.TableName != Table1.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
Otvet1 := CreateFilesFindMassByTable1(Table1, TextTemplateFunction, TableColumns1.MassColumnNames)
|
||||||
|
Otvet = Otvet + Otvet1
|
||||||
|
}
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFilesFindMassByTable1 - создаёт текст всех функций
|
||||||
|
func CreateFilesFindMassByTable1(Table1 *types.Table, TextTemplateFunction string, MassColumnsString []string) string {
|
||||||
|
Otvet := TextTemplateFunction
|
||||||
|
|
||||||
|
//
|
||||||
|
FieldNamesWithUnderline := ""
|
||||||
|
FieldNamesWithComma := ""
|
||||||
|
TextAssign := ""
|
||||||
|
|
||||||
|
MassColumns := create_files.FindMassColumns_from_MassColumnsString(Table1, MassColumnsString)
|
||||||
|
|
||||||
|
//
|
||||||
|
TextFind := "\t" + `Request.RequestFieldName = m.FieldName` + "\n"
|
||||||
|
Underline := ""
|
||||||
|
Plus := ""
|
||||||
|
RequestName := "Request_"
|
||||||
|
for _, ColumnName1 := range MassColumnsString {
|
||||||
|
Column1, ok := Table1.MapColumns[ColumnName1]
|
||||||
|
if ok == false {
|
||||||
|
log.Panic(Table1.Name + " .MapColumns[" + ColumnName1 + "] = false")
|
||||||
|
}
|
||||||
|
TextRequest := create_files.FindRequestFieldName_FromMass(Column1, MassColumns)
|
||||||
|
TextAssign = TextAssign + "\tRequest." + TextRequest + " = m." + Column1.NameGo + "\n"
|
||||||
|
FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + Column1.NameGo
|
||||||
|
FieldNamesWithComma = FieldNamesWithComma + Plus + Column1.NameGo
|
||||||
|
|
||||||
|
ProtoTypeName := create_files.ConvertGolangTypeNameToProtobufFieldName(Column1.TypeGo)
|
||||||
|
RequestName = RequestName + Underline + ProtoTypeName
|
||||||
|
|
||||||
|
Underline = "_"
|
||||||
|
Plus = "+"
|
||||||
|
}
|
||||||
|
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "RequestName", RequestName)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, TextFind, TextAssign)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithPlus", FieldNamesWithComma)
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFilesFindMassByTest - создаёт 1 файл в папке grpc_client
|
||||||
|
func CreateFilesFindMassByTest(Table1 *types.Table) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if len(types.MassFindMassBy_String) == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
//чтение файлов
|
||||||
|
DirBin := micro.ProgramDir_bin()
|
||||||
|
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||||
|
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||||
|
DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||||
|
DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||||
|
|
||||||
|
FilenameTemplateGRPCClient := DirTemplatesGRPCClient + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_FILENAME
|
||||||
|
TableName := strings.ToLower(Table1.Name)
|
||||||
|
DirReadyTable := DirReadyGRPCClient
|
||||||
|
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_findmassby_test.go"
|
||||||
|
|
||||||
|
//создадим каталог
|
||||||
|
ok, err := micro.FileExists(DirReadyTable)
|
||||||
|
if ok == false {
|
||||||
|
err = os.MkdirAll(DirReadyTable, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//загрузим шаблон файла
|
||||||
|
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("ReadFile() ", FilenameTemplateGRPCClient, " error: ", err)
|
||||||
|
}
|
||||||
|
TextGRPCClient := string(bytes)
|
||||||
|
|
||||||
|
//загрузим шаблон файла функции
|
||||||
|
FilenameTemplateGRPCClientFunction := DirTemplatesGRPCClient + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_FINDMASSBY_FUNCTION_TEST_FILENAME
|
||||||
|
bytes, err = os.ReadFile(FilenameTemplateGRPCClientFunction)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("ReadFile() ", FilenameTemplateGRPCClientFunction, " error: ", err)
|
||||||
|
}
|
||||||
|
TextTemplatedFunction := string(bytes)
|
||||||
|
|
||||||
|
//заменим имя пакета на новое
|
||||||
|
TextGRPCClient = create_files.ReplacePackageName(TextGRPCClient, DirReadyTable)
|
||||||
|
|
||||||
|
ModelName := Table1.NameGo
|
||||||
|
//заменим импорты
|
||||||
|
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||||
|
TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient)
|
||||||
|
|
||||||
|
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||||
|
TextGRPCClient = create_files.AddImport(TextGRPCClient, ModelTableURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
//создание функций
|
||||||
|
TextGRPCClientFunc := CreateFilesFindMassByTestTable(Table1, TextTemplatedFunction)
|
||||||
|
if TextGRPCClientFunc == "" {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
TextGRPCClient = TextGRPCClient + TextGRPCClientFunc
|
||||||
|
|
||||||
|
//создание текста
|
||||||
|
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||||
|
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||||
|
TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient
|
||||||
|
|
||||||
|
//замена импортов на новые URL
|
||||||
|
TextGRPCClient = create_files.ReplaceServiceURLImports(TextGRPCClient)
|
||||||
|
|
||||||
|
//uuid
|
||||||
|
TextGRPCClient = create_files.CheckAndAddImportUUID_FromText(TextGRPCClient)
|
||||||
|
|
||||||
|
//alias
|
||||||
|
TextGRPCClient = create_files.CheckAndAddImportAlias(TextGRPCClient)
|
||||||
|
|
||||||
|
//удаление пустого импорта
|
||||||
|
TextGRPCClient = create_files.DeleteEmptyImport(TextGRPCClient)
|
||||||
|
|
||||||
|
//удаление пустых строк
|
||||||
|
TextGRPCClient = create_files.DeleteEmptyLines(TextGRPCClient)
|
||||||
|
|
||||||
|
//запись файла
|
||||||
|
err = os.WriteFile(FilenameReady, []byte(TextGRPCClient), constants.FILE_PERMISSIONS)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFilesFindMassByTestTable - создаёт текст всех функций
|
||||||
|
func CreateFilesFindMassByTestTable(Table1 *types.Table, TextTemplateFunction string) string {
|
||||||
|
Otvet := ""
|
||||||
|
|
||||||
|
for _, TableColumns1 := range types.MassFindMassBy_String {
|
||||||
|
if TableColumns1.TableName != Table1.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
Otvet1 := CreateFilesFindMassByTestTable1(Table1, TextTemplateFunction, TableColumns1.MassColumnNames)
|
||||||
|
Otvet = Otvet + Otvet1
|
||||||
|
}
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFilesFindMassByTestTable1 - создаёт текст всех функций
|
||||||
|
func CreateFilesFindMassByTestTable1(Table1 *types.Table, TextTemplateFunction string, MassColumnsString []string) string {
|
||||||
|
Otvet := TextTemplateFunction
|
||||||
|
|
||||||
|
//
|
||||||
|
FieldNamesWithUnderline := ""
|
||||||
|
FieldNamesWithComma := ""
|
||||||
|
|
||||||
|
//
|
||||||
|
TextAssignFind := "\t" + `Request.RequestFieldName = 0` + "\n"
|
||||||
|
TextAssign := ""
|
||||||
|
TextFieldName_TEST := ""
|
||||||
|
|
||||||
|
MassColumns := create_files.FindMassColumns_from_MassColumnsString(Table1, MassColumnsString)
|
||||||
|
|
||||||
|
Underline := ""
|
||||||
|
Comma := ""
|
||||||
|
for _, ColumnName1 := range MassColumnsString {
|
||||||
|
Column1, ok := Table1.MapColumns[ColumnName1]
|
||||||
|
if ok == false {
|
||||||
|
log.Panic(Table1.Name + " .MapColumns[" + ColumnName1 + "] = false")
|
||||||
|
}
|
||||||
|
DefaultValue := create_files.FindTextDefaultValue(Column1.TypeGo)
|
||||||
|
RequestFieldName := create_files.FindRequestFieldName_FromMass(Column1, MassColumns)
|
||||||
|
TextAssign = TextAssign + "\t" + `Request` + RequestFieldName + ` = ` + DefaultValue + "\n"
|
||||||
|
FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + Column1.NameGo
|
||||||
|
FieldNamesWithComma = FieldNamesWithComma + Comma + Column1.NameGo
|
||||||
|
TextFieldName_TEST = TextFieldName_TEST + Comma + DefaultValue
|
||||||
|
|
||||||
|
Underline = "_"
|
||||||
|
Comma = ", "
|
||||||
|
}
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, TextAssignFind, TextAssign)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithComma", FieldNamesWithComma)
|
||||||
|
Otvet = strings.ReplaceAll(Otvet, "FieldNamesDefault", TextFieldName_TEST)
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
@ -81,7 +81,7 @@ func CreateNRPCClient() error {
|
|||||||
GRPC_NRPC_URL := create_files.Find_GRPC_NRPC_URL()
|
GRPC_NRPC_URL := create_files.Find_GRPC_NRPC_URL()
|
||||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, GRPC_NRPC_URL)
|
TextNRPCClient = create_files.AddImport(TextNRPCClient, GRPC_NRPC_URL)
|
||||||
|
|
||||||
GRPC_func_URL := create_files.Find_grpc_client_func_URL()
|
GRPC_func_URL := create_files.Find_GRPCClient_func_URL()
|
||||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, GRPC_func_URL)
|
TextNRPCClient = create_files.AddImport(TextNRPCClient, GRPC_func_URL)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user