mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-11-24 08:22:42 +02:00
сделал find_by_functions.json
This commit is contained in:
parent
a4500dc01a
commit
aa80ba91be
@ -1 +1 @@
|
||||
{}
|
||||
[]
|
@ -1 +1 @@
|
||||
{"connections":["branch_id","is_legal"]}
|
||||
[{"Table":"connections","Columns":["branch_id","is_legal"]}]
|
||||
|
@ -1 +1 @@
|
||||
{}
|
||||
[]
|
@ -1 +1 @@
|
||||
{"connections":["branch_id"]}
|
||||
[{"Table":"connections","Columns":["branch_id"]}]
|
@ -67,21 +67,15 @@ example:
|
||||
|
||||
------------------------------------------------------------------------
|
||||
findby_functions.json
|
||||
Need for automatic create functions searching 1 row in table filtered by column_name
|
||||
Fill "TableName":["column_name"]
|
||||
Fill "TableName":["column_name","column2_name"]
|
||||
Need for automatic create functions searching 1 row in table filtered by column_name,
|
||||
example:
|
||||
{
|
||||
"lawsuits": ["contract_id"]
|
||||
}
|
||||
[{"Table":"table_name1","Columns":["column_name1"]}]
|
||||
[{"Table":"table_name1","Columns":["column_name1","column_name2"]}]
|
||||
|
||||
|
||||
------------------------------------------------------------------------
|
||||
findmassby_function.json
|
||||
Need for automatic create functions searching many rows in table filtered by column_name
|
||||
Fill "TableName":["column_name"]
|
||||
Fill "TableName":["column_name","column2_name"]
|
||||
Need for automatic create functions searching many rows in table filtered by column_name,
|
||||
example:
|
||||
{
|
||||
"lawsuits": ["contract_id"]
|
||||
}
|
||||
[{"Table":"table_name1","Columns":["column_name1"]}]
|
||||
[{"Table":"table_name1","Columns":["column_name1","column_name2"]}]
|
||||
|
@ -19,7 +19,7 @@ func FindBy_FieldNamesWithUnderline_ctx(ctx context.Context, db *gorm.DB, m *law
|
||||
|
||||
tx := db.WithContext(ctx)
|
||||
|
||||
tx := tx.Where("ColumnName = ?", m.FieldName)
|
||||
tx = tx.Where("ColumnName = ?", m.FieldName)
|
||||
tx = tx.First(m)
|
||||
err = tx.Error
|
||||
|
||||
|
@ -9,7 +9,7 @@ func TestFindBy_FieldNamesWithUnderline(t *testing.T) {
|
||||
Otvet.FieldName = 0
|
||||
err := crud.FindBy_FieldNamesWithUnderline(&Otvet)
|
||||
if err != nil {
|
||||
t.Log("crud_"+TableName+"_test.TestFindBy_FieldNamesWithUnderline() FieldNamesWithUnderline=", FieldNames_TEST, " error: ", err)
|
||||
t.Log("crud_"+TableName+"_test.TestFindBy_FieldNamesWithUnderline() FieldNamesWithComma:", FieldNamesDefault, " error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1 +1,12 @@
|
||||
package crud_lawsuit_status_types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/ManyakRus/starter/postgres_gorm"
|
||||
"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"
|
||||
)
|
||||
|
||||
|
@ -0,0 +1,31 @@
|
||||
// FindMassBy_FieldNamesWithUnderline - находит запись в БД по FieldNamesWithPlus
|
||||
func (crud Crud_DB) FindMassBy_FieldNamesWithUnderline(m *lawsuit_status_types.LawsuitStatusType) ([]lawsuit_status_types.LawsuitStatusType, error) {
|
||||
Otvet := make([]files.File, 0)
|
||||
var err error
|
||||
|
||||
ctxMain := context.Background()
|
||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(db_constants.TIMEOUT_DB_SECONDS))
|
||||
defer ctxCancelFunc()
|
||||
|
||||
db := postgres_gorm.GetConnection()
|
||||
|
||||
Otvet, err = FindMassBy_FieldNamesWithUnderline_ctx(ctx, db, m)
|
||||
|
||||
return Otvet, err
|
||||
}
|
||||
|
||||
// FindMassBy_FieldNamesWithUnderline_ctx - находит запись в БД по FieldNamesWithPlus
|
||||
func FindMassBy_FieldNamesWithUnderline_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitStatusType) ([]lawsuit_status_types.LawsuitStatusType, error) {
|
||||
var err error
|
||||
Otvet := make([]files.File, 0)
|
||||
|
||||
tx := db.WithContext(ctx)
|
||||
|
||||
tx = tx.Where("ColumnName = ?", m.FieldName)
|
||||
tx = tx.Order("ColumnNamesWithComma")
|
||||
tx = tx.Find(m)
|
||||
err = tx.Error
|
||||
|
||||
return Otvet, err
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
func TestFindMassBy_FieldNamesWithUnderline(t *testing.T) {
|
||||
config_main.LoadEnv()
|
||||
|
||||
postgres_gorm.Connect()
|
||||
defer postgres_gorm.CloseConnection()
|
||||
|
||||
crud := Crud_DB{}
|
||||
Otvet := lawsuit_status_types.LawsuitStatusType{}
|
||||
Otvet.FieldName = 0
|
||||
Otvet, err := crud.FindMassBy_FieldNamesWithUnderline(&Otvet)
|
||||
if err != nil {
|
||||
t.Log("crud_"+TableName+"_test.TestFindMassBy_FieldNamesWithUnderline() FieldNamesWithComma:", FieldNamesDefault, " error: ", err)
|
||||
}
|
||||
}
|
||||
|
@ -1 +1,9 @@
|
||||
package crud_lawsuit_status_types
|
||||
|
||||
import (
|
||||
"github.com/ManyakRus/starter/config_main"
|
||||
"github.com/ManyakRus/starter/postgres_gorm"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -81,17 +81,33 @@ 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 = CreateFilesFindByTest(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFilesFindByTest() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//
|
||||
err = CreateFilesFindMassBy(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFilesFindMassBy() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//
|
||||
err = CreateFilesFindMassByTest(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFilesFindMassByTest() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
func CreateFilesFindBy(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
if len(types.MapFindBy) == 0 {
|
||||
if len(types.MassFindBy) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -108,11 +108,11 @@ func CreateFilesFindBy(Table1 *types.Table) error {
|
||||
func CreateFilesFindByTable(Table1 *types.Table, TextTemplateFunction string) string {
|
||||
Otvet := ""
|
||||
|
||||
for TableName1, MassColumns1 := range types.MapFindBy {
|
||||
if TableName1 != Table1.Name {
|
||||
for _, TableColumns1 := range types.MassFindBy {
|
||||
if TableColumns1.TableName != Table1.Name {
|
||||
continue
|
||||
}
|
||||
Otvet1 := CreateFilesFindByTable1(Table1, TextTemplateFunction, MassColumns1)
|
||||
Otvet1 := CreateFilesFindByTable1(Table1, TextTemplateFunction, TableColumns1.MassColumnNames)
|
||||
Otvet = Otvet + Otvet1
|
||||
}
|
||||
|
||||
@ -125,13 +125,11 @@ func CreateFilesFindByTable1(Table1 *types.Table, TextTemplateFunction string, M
|
||||
|
||||
//
|
||||
FieldNamesWithUnderline := ""
|
||||
|
||||
//
|
||||
FieldNamesWithComma := ""
|
||||
TextWhere := ""
|
||||
|
||||
//
|
||||
TextFind := "\t" + `tx := tx.Where("ColumnName = ?", m.FieldName)` + "\n"
|
||||
TextWhere := ""
|
||||
TextFind := "\t" + `tx = tx.Where("ColumnName = ?", m.FieldName)` + "\n"
|
||||
Underline := ""
|
||||
Plus := ""
|
||||
for _, ColumnName1 := range MassColumns1 {
|
||||
@ -139,7 +137,7 @@ func CreateFilesFindByTable1(Table1 *types.Table, TextTemplateFunction string, M
|
||||
if ok == false {
|
||||
log.Panic(Table1.Name + " .MapColumns[" + ColumnName1 + "] = false")
|
||||
}
|
||||
TextWhere = TextWhere + "\t" + `tx := tx.Where("` + ColumnName1 + ` = ?", m.` + Column1.NameGo + `)` + "\n"
|
||||
TextWhere = TextWhere + "\t" + `tx = tx.Where("` + ColumnName1 + ` = ?", m.` + Column1.NameGo + `)` + "\n"
|
||||
FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + Column1.NameGo
|
||||
FieldNamesWithComma = FieldNamesWithComma + Plus + Column1.NameGo
|
||||
Underline = "_"
|
||||
@ -156,7 +154,7 @@ func CreateFilesFindByTable1(Table1 *types.Table, TextTemplateFunction string, M
|
||||
func CreateFilesFindByTest(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
if len(types.MapFindBy) == 0 {
|
||||
if len(types.MassFindBy) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -246,11 +244,11 @@ func CreateFilesFindByTest(Table1 *types.Table) error {
|
||||
func CreateFilesFindByTestTable(Table1 *types.Table, TextTemplateFunction string) string {
|
||||
Otvet := ""
|
||||
|
||||
for TableName1, MassColumns1 := range types.MapFindBy {
|
||||
if TableName1 != Table1.Name {
|
||||
for _, TableColumns1 := range types.MassFindBy {
|
||||
if TableColumns1.TableName != Table1.Name {
|
||||
continue
|
||||
}
|
||||
Otvet1 := CreateFilesFindByTestTable1(Table1, TextTemplateFunction, MassColumns1)
|
||||
Otvet1 := CreateFilesFindByTestTable1(Table1, TextTemplateFunction, TableColumns1.MassColumnNames)
|
||||
Otvet = Otvet + Otvet1
|
||||
}
|
||||
|
||||
@ -263,6 +261,7 @@ func CreateFilesFindByTestTable1(Table1 *types.Table, TextTemplateFunction strin
|
||||
|
||||
//
|
||||
FieldNamesWithUnderline := ""
|
||||
FieldNamesWithComma := ""
|
||||
|
||||
//
|
||||
TextAssignFind := "\t" + `Otvet.FieldName = 0` + "\n"
|
||||
@ -279,6 +278,7 @@ func CreateFilesFindByTestTable1(Table1 *types.Table, TextTemplateFunction strin
|
||||
DefaultValue := create_files.FindTextDefaultValue(Column1.TypeGo)
|
||||
TextAssign = TextAssign + "\t" + `Otvet.` + Column1.NameGo + ` = ` + DefaultValue + "\n"
|
||||
FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + Column1.NameGo
|
||||
FieldNamesWithComma = FieldNamesWithComma + Comma + Column1.NameGo
|
||||
TextFieldName_TEST = TextFieldName_TEST + Comma + DefaultValue
|
||||
|
||||
Underline = "_"
|
||||
@ -286,7 +286,8 @@ func CreateFilesFindByTestTable1(Table1 *types.Table, TextTemplateFunction strin
|
||||
}
|
||||
Otvet = strings.ReplaceAll(Otvet, TextAssignFind, TextAssign)
|
||||
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
|
||||
Otvet = strings.ReplaceAll(Otvet, "FieldNames_TEST", TextFieldName_TEST)
|
||||
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithComma", FieldNamesWithComma)
|
||||
Otvet = strings.ReplaceAll(Otvet, "FieldNamesDefault", TextFieldName_TEST)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
299
internal/create_files/crud_tables/crud_tables_findmassby.go
Normal file
299
internal/create_files/crud_tables/crud_tables_findmassby.go
Normal file
@ -0,0 +1,299 @@
|
||||
package crud_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 файл в папке crud
|
||||
func CreateFilesFindMassBy(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
if len(types.MassFindMassBy) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesCrud := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_CRUD + micro.SeparatorFile()
|
||||
DirReadyCrud := DirReady + config.Settings.TEMPLATE_FOLDERNAME_CRUD + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateCrud := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_FINDMASSBY_FILENAME
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyCrud + config.Settings.PREFIX_CRUD + TableName
|
||||
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + 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(FilenameTemplateCrud)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateCrud, " error: ", err)
|
||||
}
|
||||
TextCrud := string(bytes)
|
||||
|
||||
//загрузим шаблон файла функции
|
||||
FilenameTemplateCrudFunction := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_FINDMASSBY_FUNCTION_FILENAME
|
||||
bytes, err = os.ReadFile(FilenameTemplateCrudFunction)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateCrudFunction, " error: ", err)
|
||||
}
|
||||
TextTemplatedFunction := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
TextCrud = create_files.ReplacePackageName(TextCrud, DirReadyTable)
|
||||
|
||||
ModelName := Table1.NameGo
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextCrud = create_files.DeleteTemplateRepositoryImports(TextCrud)
|
||||
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||
|
||||
ConstantsURL := create_files.FindDBConstantsURL()
|
||||
TextCrud = create_files.AddImport(TextCrud, ConstantsURL)
|
||||
|
||||
}
|
||||
|
||||
//создание функций
|
||||
TextCrudFunc := CreateFilesFindMassByTable(Table1, TextTemplatedFunction)
|
||||
if TextCrudFunc == "" {
|
||||
return err
|
||||
}
|
||||
TextCrud = TextCrud + TextCrudFunc
|
||||
|
||||
//создание текста
|
||||
TextCrud = strings.ReplaceAll(TextCrud, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
TextCrud = strings.ReplaceAll(TextCrud, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextCrud = config.Settings.TEXT_MODULE_GENERATED + TextCrud
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextCrud = create_files.ReplaceServiceURLImports(TextCrud)
|
||||
|
||||
//uuid
|
||||
TextCrud = create_files.CheckAndAddImportUUID_FromText(TextCrud)
|
||||
|
||||
//alias
|
||||
TextCrud = create_files.CheckAndAddImportAlias(TextCrud)
|
||||
|
||||
//удаление пустого импорта
|
||||
TextCrud = create_files.DeleteEmptyImport(TextCrud)
|
||||
|
||||
//удаление пустых строк
|
||||
TextCrud = create_files.DeleteEmptyLines(TextCrud)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReady, []byte(TextCrud), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateFilesFindMassByTable - создаёт текст всех функций
|
||||
func CreateFilesFindMassByTable(Table1 *types.Table, TextTemplateFunction string) string {
|
||||
Otvet := ""
|
||||
|
||||
for _, TableColumns1 := range types.MassFindMassBy {
|
||||
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, MassColumns1 []string) string {
|
||||
Otvet := TextTemplateFunction
|
||||
|
||||
//
|
||||
FieldNamesWithUnderline := ""
|
||||
FieldNamesWithComma := ""
|
||||
ColumnNamesWithComma := ""
|
||||
|
||||
//
|
||||
TextFind := "\t" + `tx = tx.Where("ColumnName = ?", m.FieldName)` + "\n"
|
||||
TextWhere := ""
|
||||
Underline := ""
|
||||
Plus := ""
|
||||
Comma := ""
|
||||
for _, ColumnName1 := range MassColumns1 {
|
||||
Column1, ok := Table1.MapColumns[ColumnName1]
|
||||
if ok == false {
|
||||
log.Panic(Table1.Name + " .MapColumns[" + ColumnName1 + "] = false")
|
||||
}
|
||||
TextWhere = TextWhere + "\t" + `tx = tx.Where("` + ColumnName1 + ` = ?", m.` + Column1.NameGo + `)` + "\n"
|
||||
FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + Column1.NameGo
|
||||
FieldNamesWithComma = FieldNamesWithComma + Plus + Column1.NameGo
|
||||
ColumnNamesWithComma = ColumnNamesWithComma + Comma + Column1.Name
|
||||
|
||||
Underline = "_"
|
||||
Plus = "+"
|
||||
Comma = ", "
|
||||
}
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, TextWhere)
|
||||
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
|
||||
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithPlus", FieldNamesWithComma)
|
||||
Otvet = strings.ReplaceAll(Otvet, "ColumnNamesWithComma", ColumnNamesWithComma)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// CreateFilesFindMassByTest - создаёт 1 файл в папке crud
|
||||
func CreateFilesFindMassByTest(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
if len(types.MassFindMassBy) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesCrud := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_CRUD + micro.SeparatorFile()
|
||||
DirReadyCrud := DirReady + config.Settings.TEMPLATE_FOLDERNAME_CRUD + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateCrud := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_FINDMASSBY_FILENAME
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyCrud + config.Settings.PREFIX_CRUD + TableName
|
||||
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + 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(FilenameTemplateCrud)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateCrud, " error: ", err)
|
||||
}
|
||||
TextCrud := string(bytes)
|
||||
|
||||
//загрузим шаблон файла функции
|
||||
FilenameTemplateCrudFunction := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_FINDMASSBY_FUNCTION_TEST_FILENAME
|
||||
bytes, err = os.ReadFile(FilenameTemplateCrudFunction)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateCrudFunction, " error: ", err)
|
||||
}
|
||||
TextTemplatedFunction := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
TextCrud = create_files.ReplacePackageName(TextCrud, DirReadyTable)
|
||||
|
||||
ModelName := Table1.NameGo
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextCrud = create_files.DeleteTemplateRepositoryImports(TextCrud)
|
||||
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||
|
||||
}
|
||||
|
||||
//создание функций
|
||||
TextCrudFunc := CreateFilesFindMassByTestTable(Table1, TextTemplatedFunction)
|
||||
if TextCrudFunc == "" {
|
||||
return err
|
||||
}
|
||||
TextCrud = TextCrud + TextCrudFunc
|
||||
|
||||
//создание текста
|
||||
TextCrud = strings.ReplaceAll(TextCrud, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
TextCrud = strings.ReplaceAll(TextCrud, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextCrud = config.Settings.TEXT_MODULE_GENERATED + TextCrud
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextCrud = create_files.ReplaceServiceURLImports(TextCrud)
|
||||
|
||||
//uuid
|
||||
TextCrud = create_files.CheckAndAddImportUUID_FromText(TextCrud)
|
||||
|
||||
//alias
|
||||
TextCrud = create_files.CheckAndAddImportAlias(TextCrud)
|
||||
|
||||
//удаление пустого импорта
|
||||
TextCrud = create_files.DeleteEmptyImport(TextCrud)
|
||||
|
||||
//удаление пустых строк
|
||||
TextCrud = create_files.DeleteEmptyLines(TextCrud)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReady, []byte(TextCrud), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateFilesFindMassByTestTable - создаёт текст всех функций
|
||||
func CreateFilesFindMassByTestTable(Table1 *types.Table, TextTemplateFunction string) string {
|
||||
Otvet := ""
|
||||
|
||||
for _, TableColumns1 := range types.MassFindMassBy {
|
||||
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, MassColumns1 []string) string {
|
||||
Otvet := TextTemplateFunction
|
||||
|
||||
//
|
||||
FieldNamesWithUnderline := ""
|
||||
FieldNamesWithComma := ""
|
||||
|
||||
//
|
||||
TextAssignFind := "\t" + `Otvet.FieldName = 0` + "\n"
|
||||
TextAssign := ""
|
||||
TextFieldName_TEST := ""
|
||||
|
||||
Underline := ""
|
||||
Comma := ""
|
||||
for _, ColumnName1 := range MassColumns1 {
|
||||
Column1, ok := Table1.MapColumns[ColumnName1]
|
||||
if ok == false {
|
||||
log.Panic(Table1.Name + " .MapColumns[" + ColumnName1 + "] = false")
|
||||
}
|
||||
DefaultValue := create_files.FindTextDefaultValue(Column1.TypeGo)
|
||||
TextAssign = TextAssign + "\t" + `Otvet.` + Column1.NameGo + ` = ` + 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
|
||||
}
|
@ -220,8 +220,14 @@ func LoadFindBy() {
|
||||
log.Panic(TextError)
|
||||
}
|
||||
|
||||
//MassFindBy1 := types.TableNameColumnNames{}
|
||||
//MassFindBy1.TableName = "TableName"
|
||||
//MassFindBy1.MassColumnNames = []string{"ColumnName"}
|
||||
//types.MassFindBy = append(types.MassFindBy, MassFindBy1)
|
||||
//bytes, _ = json.Marshal(types.MassFindBy) //удалить
|
||||
|
||||
//json в map
|
||||
err = json.Unmarshal(bytes, &types.MapFindBy)
|
||||
err = json.Unmarshal(bytes, &types.MassFindBy)
|
||||
if err != nil {
|
||||
log.Panic("Unmarshal() error: ", err)
|
||||
}
|
||||
@ -243,7 +249,7 @@ func LoadFindMassBy() {
|
||||
}
|
||||
|
||||
//json в map
|
||||
err = json.Unmarshal(bytes, &types.MapFindMassBy)
|
||||
err = json.Unmarshal(bytes, &types.MassFindMassBy)
|
||||
if err != nil {
|
||||
log.Panic("Unmarshal() error: ", err)
|
||||
}
|
||||
|
@ -52,8 +52,13 @@ var MapModelCrudDeleteFunctions = make(map[string]string, 0)
|
||||
// MapRenameFunctions - карта функций которые будут переименованый в файлах crud
|
||||
var MapRenameFunctions = make(map[string][]ReplaceStruct, 0)
|
||||
|
||||
// MapFindBy - карта функций которые будут созданы для поиска 1 строки в таблице
|
||||
var MapFindBy = make(map[string][]string, 0)
|
||||
type TableNameColumnNames struct {
|
||||
TableName string `json:"Table"`
|
||||
MassColumnNames []string `json:"Columns"`
|
||||
}
|
||||
|
||||
// MapFindMassBy - карта функций которые будут созданы для поиска много строк в таблице
|
||||
var MapFindMassBy = make(map[string][]string, 0)
|
||||
// MassFindBy - карта функций которые будут созданы для поиска 1 строки в таблице
|
||||
var MassFindBy = make([]TableNameColumnNames, 0)
|
||||
|
||||
// MassFindMassBy - карта функций которые будут созданы для поиска много строк в таблице
|
||||
var MassFindMassBy = make([]TableNameColumnNames, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user