1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-11-27 08:40:53 +02:00

сделал ReplacePackageName()

This commit is contained in:
Nikitin Aleksandr 2023-11-17 11:40:03 +03:00
parent 279b70109c
commit e86f662601
6 changed files with 38 additions and 13 deletions

View File

@ -1,4 +1,4 @@
package db_lawsuit_status_types
package crud_lawsuit_status_types
import (
"context"

View File

@ -1,4 +1,4 @@
package db_lawsuit_status_types
package crud_lawsuit_status_types
import (
"github.com/ManyakRus/starter/config"

View File

@ -1,13 +1,13 @@
package lawsuit_status_types
package table_lawsuit_status_types
import (
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/tables"
)
// LawsuitStatusType
type LawsuitStatusType struct {
entities.CommonStruct
entities.NameStruct
tables.CommonStruct
tables.NameStruct
Code string `json:"code" gorm:"column:code;default:0"`
}

View File

@ -563,3 +563,27 @@ func FindModelNameComment(ModelName string, Table1 *types.Table) string {
return Otvet
}
// ReplacePackageName - заменяет имя пакета в шаблоне на новое
func ReplacePackageName(Text, PackageName string) string {
Otvet := Text
//
TextFind := "\tpackage "
pos1 := strings.Index(Otvet, TextFind)
if pos1 < 0 {
log.Error("not found word: package ")
return Otvet
}
s2 := Otvet[pos1:]
posEnd := strings.Index(s2, "\n")
if posEnd < 0 {
log.Error("not found word: \n")
return Otvet
}
Otvet = Otvet[:pos1] + "\t" + PackageName + Otvet[pos1+posEnd:]
return Otvet
}

View File

@ -134,7 +134,7 @@ func FindTextImportDB1(Table1 *types.Table) string {
TableName := strings.ToLower(Table1.Name)
DB_URL := config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_CRUD
TableNameWithPrefix := config.Settings.PREFIX_CRUD + TableName
Otvet := "\n\t" + TableNameWithPrefix + " \"" + DB_URL + "/" + TableNameWithPrefix + `"`
Otvet := "\n\t" + " \"" + DB_URL + "/" + TableNameWithPrefix + `"`
return Otvet
}

View File

@ -116,6 +116,11 @@ func FindTextModelStruct(TextModel string, Table1 *types.Table) (string, string,
ModelName = create_files.FormatName(ModelName)
Table1.NameGo = ModelName
//удалим старые импорты
if config.Settings.USE_DEFAULT_TEMPLATE == true {
TextModel = create_files.DeleteTemplateRepositoryImports(TextModel)
}
// Otvet = `// ` + ModelName + ` - ` + COMMENT_MODEL_STRUCT + TableName + `: ` + Table1.Comment + `
//type ` + ModelName + ` struct {
//`
@ -186,6 +191,7 @@ type ` + ModelNameWithPrefix + ` 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)
@ -203,12 +209,7 @@ func FindTextColumn(TextModel string, Table1 *types.Table, Column1 *types.Column
ColumnName := Column1.Name
ColumnNameLowerCase := strings.ToLower(ColumnName)
ColumnModelName := create_files.FormatName(Column1.Name)
//Column1.NameGo = ColumnModelName
//SQLMapping1, ok := dbmeta.GetMappings()[Column1.Type]
//if ok == false {
// log.Panic("GetMappings() ", Column1.Type, " error: not found")
//}
//Type_go := SQLMapping1.GoType
Type_go := Column1.TypeGo
TextModel, Type_go = FindColumnTypeGoImport(TextModel, Table1, Column1)
//Column1.TypeGo = Type_go