mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2025-01-01 13:21:20 +02:00
сделал TemplateFilenameCrudGo
This commit is contained in:
parent
635ef99b6d
commit
279b70109c
@ -1,4 +1,7 @@
|
||||
{
|
||||
"lawsuit_payments.id": "alias.PaymentId",
|
||||
"lawsuit_payments.invoice_id": "alias.InvoiceId",
|
||||
"lawsuit_payments.lawsuit_id": "alias.LawsuitId",
|
||||
"lawsuit_payments.id": "alias.PaymentId",
|
||||
"invoice_debt_type_stats.invoice_id": "alias.InvoiceId",
|
||||
"invoice_debt_type_stats.lawsuit_id": "alias.LawsuitId",
|
||||
|
@ -1,11 +1,11 @@
|
||||
package lawsuit_status_types
|
||||
|
||||
import (
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/tables/lawsuit_status_types"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/tables/table_lawsuit_status_types"
|
||||
)
|
||||
|
||||
// LawsuitStatusType
|
||||
type LawsuitStatusType struct {
|
||||
Table_LawsuitStatusType
|
||||
table_lawsuit_status_types.Table_LawsuitStatusType
|
||||
}
|
||||
|
||||
|
@ -13,3 +13,4 @@ const FILE_PERMISSIONS = 0666
|
||||
const CONFIG_FOLDER_NAME = "configs_"
|
||||
|
||||
const TemplateFilenameCrudGo = "crud.go_"
|
||||
const TemplateFilenameCrudGoTest = "crud_test.go_"
|
||||
|
@ -315,6 +315,15 @@ func FindTablesURL() string {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindTableNameURL - возвращает URL репозитория с пакетом "tables" + TableName
|
||||
func FindTableNameURL(TableName string) string {
|
||||
Otvet := ""
|
||||
|
||||
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_TABLES + "/" + config.Settings.PREFIX_TABLE + TableName
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindGRPCProtoURL - возвращает URL репозитория с пакетом "grpc_proto"
|
||||
func FindGRPCProtoURL() string {
|
||||
Otvet := ""
|
||||
@ -371,6 +380,15 @@ func FindURL_Alias() string {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindURL_Tables - возвращает URL репозитория с пакетом "tables"
|
||||
func FindURL_Tables() string {
|
||||
Otvet := ""
|
||||
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/"
|
||||
Otvet = Otvet + config.Settings.TEMPLATE_FOLDERNAME_TABLES
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// AddImport - добавляет URL в секцию Import, если его там нет
|
||||
func AddImport(Text, URL string) string {
|
||||
Otvet := Text
|
||||
@ -509,3 +527,39 @@ func ReplaceServiceURLImports(Text string) string {
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// ReplaceModelAndTableName - заменяет имя модели и имя таблицы в шаблоне на новые
|
||||
func ReplaceModelAndTableName(TextModel string, Table1 *types.Table) string {
|
||||
Otvet := TextModel
|
||||
|
||||
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL, Table1.NameGo)
|
||||
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindModelComment - возвращает комментарий для модели
|
||||
func FindModelComment(Table1 *types.Table) string {
|
||||
Otvet := ""
|
||||
|
||||
TableName := Table1.Name
|
||||
ModelName := Table1.NameGo
|
||||
COMMENT_MODEL_STRUCT := config.Settings.COMMENT_MODEL_STRUCT
|
||||
|
||||
Otvet = `// ` + ModelName + ` - ` + COMMENT_MODEL_STRUCT + TableName + `: ` + Table1.Comment
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindModelNameComment - возвращает комментарий для названия модели
|
||||
func FindModelNameComment(ModelName string, Table1 *types.Table) string {
|
||||
Otvet := ""
|
||||
|
||||
TableName := Table1.Name
|
||||
//ModelName := Table1.NameGo
|
||||
COMMENT_MODEL_STRUCT := config.Settings.COMMENT_MODEL_STRUCT
|
||||
|
||||
Otvet = `// ` + ModelName + ` - ` + COMMENT_MODEL_STRUCT + TableName + `: ` + Table1.Comment
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
@ -133,7 +133,8 @@ func FindTextImportModel1(Table1 *types.Table) string {
|
||||
func FindTextImportDB1(Table1 *types.Table) string {
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DB_URL := config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_CRUD
|
||||
Otvet := "\n\t\"" + DB_URL + "/db_" + TableName + `"`
|
||||
TableNameWithPrefix := config.Settings.PREFIX_CRUD + TableName
|
||||
Otvet := "\n\t" + TableNameWithPrefix + " \"" + DB_URL + "/" + TableNameWithPrefix + `"`
|
||||
|
||||
return Otvet
|
||||
}
|
||||
@ -198,7 +199,7 @@ func InitCrudTransport_DB() {`
|
||||
func FindTextDB1(Table1 *types.Table) string {
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
ModelName := Table1.NameGo
|
||||
Otvet := "\n\t" + TableName + "." + ModelName + "{}.SetCrudInterface(db_" + TableName + ".Crud_DB{})"
|
||||
Otvet := "\n\t" + TableName + "." + ModelName + "{}.SetCrudInterface(" + config.Settings.PREFIX_CRUD + TableName + ".Crud_DB{})"
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ func CreateTestFiles(Table1 *types.Table) error {
|
||||
DirTemplatesDB := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_CRUD + micro.SeparatorFile()
|
||||
DirReadyDB := DirReady + config.Settings.TEMPLATE_FOLDERNAME_CRUD + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateDB := DirTemplatesDB + config.Settings.PREFIX_CRUD + "test.go_"
|
||||
FilenameTemplateDB := DirTemplatesDB + constants.TemplateFilenameCrudGoTest
|
||||
DirTable := DirReadyDB + config.Settings.PREFIX_CRUD + TableName
|
||||
FilenameReadyDB := DirTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + "_test.go"
|
||||
|
||||
|
@ -39,7 +39,7 @@ func CreateFiles(Table1 *types.Table) error {
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesTable := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_TABLES + micro.SeparatorFile()
|
||||
DirReadyTable := DirReady + config.Settings.TEMPLATE_FOLDERNAME_TABLES + micro.SeparatorFile() + TableName + micro.SeparatorFile()
|
||||
DirReadyTable := DirReady + config.Settings.TEMPLATE_FOLDERNAME_TABLES + micro.SeparatorFile() + config.Settings.PREFIX_TABLE + TableName + micro.SeparatorFile()
|
||||
|
||||
//создадим каталог
|
||||
ok, err := micro.FileExists(DirReadyTable)
|
||||
@ -115,10 +115,16 @@ func FindTextModelStruct(TextModel string, Table1 *types.Table) (string, string,
|
||||
ModelName = create_files.FindSingularName(TableName)
|
||||
ModelName = create_files.FormatName(ModelName)
|
||||
Table1.NameGo = ModelName
|
||||
COMMENT_MODEL_STRUCT := config.Settings.COMMENT_MODEL_STRUCT
|
||||
|
||||
Otvet = `// ` + ModelName + ` - ` + COMMENT_MODEL_STRUCT + TableName + `: ` + Table1.Comment + `
|
||||
type ` + ModelName + ` struct {
|
||||
// Otvet = `// ` + ModelName + ` - ` + COMMENT_MODEL_STRUCT + TableName + `: ` + Table1.Comment + `
|
||||
//type ` + ModelName + ` struct {
|
||||
//`
|
||||
|
||||
Prefix := micro.StringFromUpperCase(config.Settings.PREFIX_TABLE)
|
||||
ModelNameWithPrefix := Prefix + ModelName
|
||||
Otvet = create_files.FindModelNameComment(ModelNameWithPrefix, Table1)
|
||||
Otvet = Otvet + `
|
||||
type ` + ModelNameWithPrefix + ` struct {
|
||||
`
|
||||
|
||||
//сортировка
|
||||
@ -133,6 +139,14 @@ type ` + ModelName + ` struct {
|
||||
has_Columns_Groups := create_files.Has_Columns_Groups(Table1)
|
||||
has_Columns_ExtLinks := create_files.Has_Columns_ExtLink(Table1)
|
||||
|
||||
// если у id есть alias то колонка id будет отдельно
|
||||
ColumnIDName, _ := create_files.FindPrimaryKeyNameType(Table1)
|
||||
_, ok := types.MapConvertID[TableName+"."+ColumnIDName]
|
||||
if ok == true {
|
||||
has_Columns_CommonStruct = false
|
||||
}
|
||||
|
||||
//
|
||||
ImportModelsName := micro.LastWord(config.Settings.TEMPLATE_FOLDERNAME_TABLES)
|
||||
|
||||
if has_Columns_CommonStruct == true {
|
||||
@ -172,6 +186,11 @@ type ` + ModelName + ` struct {
|
||||
Table1.MapColumns[key1] = Column1
|
||||
}
|
||||
|
||||
if has_Columns_CommonStruct == true || has_Columns_NameStruct == true || has_Columns_Groups == true || has_Columns_ExtLinks == true {
|
||||
TablesURL := create_files.FindURL_Tables()
|
||||
TextModel = create_files.AddImport(TextModel, TablesURL)
|
||||
}
|
||||
|
||||
Otvet = Otvet + "\n}"
|
||||
return TextModel, Otvet, ModelName, err
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ func CreateFilesModel_struct(Table1 *types.Table, DirTemplatesModel, DirReadyMod
|
||||
//var ModelName string
|
||||
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
ModelName := Table1.NameGo
|
||||
FilenameTemplateModel := DirTemplatesModel + "model.go_"
|
||||
FilenameReadyModel := DirReadyModel + config.Settings.PREFIX_MODEL + TableName + ".go"
|
||||
|
||||
@ -107,12 +108,18 @@ func CreateFilesModel_struct(Table1 *types.Table, DirTemplatesModel, DirReadyMod
|
||||
//замена импортов на новые URL
|
||||
//TextModel = create_files.ReplaceServiceURLImports(TextModel)
|
||||
|
||||
TextModel = create_files.ReplaceModelAndTableName(TextModel, Table1)
|
||||
|
||||
//замена импортов на новые URL
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
Comment := create_files.FindModelComment(Table1)
|
||||
TextTemplate := "// " + ModelName
|
||||
TextModel = strings.ReplaceAll(TextModel, TextTemplate, Comment)
|
||||
|
||||
TextModel = create_files.DeleteTemplateRepositoryImports(TextModel)
|
||||
|
||||
TablesURL := create_files.FindTablesURL()
|
||||
TextModel = create_files.AddImport(TextModel, TablesURL)
|
||||
TableNameURL := create_files.FindTableNameURL(TableName)
|
||||
TextModel = create_files.AddImport(TextModel, TableNameURL)
|
||||
}
|
||||
|
||||
//запись файла
|
||||
@ -170,9 +177,9 @@ func FindTextModelStruct(TextModel string, Table1 *types.Table) (string, string,
|
||||
var err error
|
||||
|
||||
TableName := Table1.Name
|
||||
ModelName = create_files.FindSingularName(TableName)
|
||||
ModelName = create_files.FormatName(ModelName)
|
||||
Table1.NameGo = ModelName
|
||||
//ModelName = create_files.FindSingularName(TableName)
|
||||
//ModelName = create_files.FormatName(ModelName)
|
||||
//Table1.NameGo = ModelName
|
||||
COMMENT_MODEL_STRUCT := config.Settings.COMMENT_MODEL_STRUCT
|
||||
|
||||
Otvet = `// ` + ModelName + ` - ` + COMMENT_MODEL_STRUCT + TableName + `: ` + Table1.Comment + `
|
||||
|
@ -204,10 +204,19 @@ order by
|
||||
MapTable[TableName0] = Table1
|
||||
OrderNumberTable++
|
||||
}
|
||||
|
||||
//найдём имя модели golang
|
||||
TableName := v.TableName
|
||||
ModelName := create_files.FindSingularName(TableName)
|
||||
ModelName = create_files.FormatName(ModelName)
|
||||
|
||||
//
|
||||
Table1 = CreateTable()
|
||||
Table1.Name = v.TableName
|
||||
Table1.Name = TableName
|
||||
Table1.OrderNumber = OrderNumberTable
|
||||
Table1.Comment = v.TableComment
|
||||
Table1.NameGo = ModelName
|
||||
|
||||
}
|
||||
|
||||
Column1 := types.Column{}
|
||||
|
Loading…
Reference in New Issue
Block a user