diff --git a/app/business/tool/toolModels/genTableColumn.go b/app/business/tool/toolModels/genTableColumn.go index 26bb6938e942397620f0c3b301973b41708038e1..2bf93c4304fa25d892aee062c030163baa55bdf5 100644 --- a/app/business/tool/toolModels/genTableColumn.go +++ b/app/business/tool/toolModels/genTableColumn.go @@ -108,7 +108,7 @@ func GetGenTableColumnDML(column *InformationSchemaColumn, tableId int64, userId default: //字段为字符串类型 genTableColumn.GoType = "string" - if strings.EqualFold(dataType, "text") || strings.EqualFold(dataType, "tinytext") || strings.EqualFold(dataType, "mediumtext") || strings.EqualFold(dataType, "longtext") { + if stringUtils.ReMatchingStr(dataType, "text|tinytext|mediumtext|longtext|longblob") { genTableColumn.HtmlType = "textarea" } else { columnLength := genUtils.GetColumnLength(column.ColumnType) diff --git a/app/business/tool/toolService/toolServiceImpl/genTableServiceImpl.go b/app/business/tool/toolService/toolServiceImpl/genTableServiceImpl.go index 1891e516fa16a48c110239a4bf794ea901652914..9beedfe9fe8988235534c161e09df1c58d22acaa 100644 --- a/app/business/tool/toolService/toolServiceImpl/genTableServiceImpl.go +++ b/app/business/tool/toolService/toolServiceImpl/genTableServiceImpl.go @@ -132,6 +132,7 @@ func (genTabletService *GenTabletService) setTemplateData(data map[string]any) { for _, vo := range column { if vo.IsPk == "1" { data["IdField"] = vo.HtmlField + data["GoField"] = vo.GoField data["IdType"] = vo.GoType data["IdColumnName"] = vo.ColumnName break diff --git a/app/business/tool/utils/tableColumn.go b/app/business/tool/utils/tableColumn.go index 19081e3437d1098d00f03437a7e8496339f9f25c..9af3cd1c6910a5a51b5781470d3546c09ccea315 100644 --- a/app/business/tool/utils/tableColumn.go +++ b/app/business/tool/utils/tableColumn.go @@ -1,5 +1,10 @@ package genUtils +import ( + "regexp" + "strings" +) + // ColumnTypeStr 数据库字符串类型 var ColumnTypeStr = []string{"char", "varchar", "narchar", "varchar2", "tinytext", "text", "mediumtext", "longtext"} @@ -12,14 +17,13 @@ var ColumnTypeNumber = []string{"tinyint", "smallint", "mediumint", "int", "numb // ColumnNameBaseEntity 页面基础字段 var ColumnNameBaseEntity = []string{"create_by", "create_time", "update_by", "update_time"} -// IsExistInArray 判断string 是否存在在数组中 +// IsExistInArray 正则判断string 是否存在在数组中 func IsExistInArray(value string, array []string) bool { - for _, v := range array { - if v == value { - return true - } + re, err := regexp.Compile(strings.Join(array, "|")) + if err != nil { + return false } - return false + return re.MatchString(value) } // IsStringObject 判断是否是数据库字符串类型 diff --git a/app/utils/stringUtils/stringUtils.go b/app/utils/stringUtils/stringUtils.go index 76810939b87820fecfc6545a3b99223b0b8bd4f0..9f8a276af2d686e692c95aea55f35a267589a002 100644 --- a/app/utils/stringUtils/stringUtils.go +++ b/app/utils/stringUtils/stringUtils.go @@ -36,7 +36,7 @@ func ToUnderScoreCase(str string) string { return retStr } -//ConvertToBigCamelCase 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld +// ConvertToBigCamelCase 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld func ConvertToBigCamelCase(name string) string { if name == "" { return "" @@ -56,7 +56,7 @@ func ConvertToBigCamelCase(name string) string { return result } -//ConvertToLittleCamelCase 将下划线大写方式命名的字符串转换为驼峰式,首字母小写。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->helloWorld +// ConvertToLittleCamelCase 将下划线大写方式命名的字符串转换为驼峰式,首字母小写。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->helloWorld func ConvertToLittleCamelCase(name string) string { if name == "" { return "" @@ -91,3 +91,12 @@ func DeleteExtraSpace(s string) string { } return string(tmpStr) } + +// ReMatchingStr 使用正则匹配文本内容是否包含特定内容 +func ReMatchingStr(text string, pattern string) bool { + re, err := regexp.Compile(pattern) + if err != nil { + return false + } + return re.MatchString(text) +} diff --git a/template/go/controller/controller.tmpl b/template/go/controller/controller.tmpl index da1884f426959067084b2208e35f79d29de8ade1..b89dc5911ecfc8298ecd7809bd9645e8ef1a5a1f 100644 --- a/template/go/controller/controller.tmpl +++ b/template/go/controller/controller.tmpl @@ -1,8 +1,8 @@ package {{.Table.ModuleName}}Controller import ( - "{{.Table.PackageName}}{{.Table.ModuleName}}Server" - "{{.Table.PackageName}}{{.Table.ModuleName}}Server/{{.Table.ModuleName}}ServerImpl" + "{{.Table.PackageName}}{{.Table.ModuleName}}Service" + "{{.Table.PackageName}}{{.Table.ModuleName}}Service/{{.Table.ModuleName}}ServiceImpl" "{{.Table.PackageName}}{{.Table.ModuleName}}Models" "baize/app/utils/baizeContext" "github.com/gin-gonic/gin" @@ -16,11 +16,11 @@ import ( type {{.Table.StructName}} struct { - {{.Table.BusinessName}}Server {{.Table.ModuleName}}Server.I{{.Table.StructName}}Server + {{.Table.BusinessName}}Service {{.Table.ModuleName}}Service.I{{.Table.StructName}}Service } -func New{{.Table.StructName}}(ps *{{.Table.ModuleName}}ServerImpl.I{{.Table.StructName}}Server) *{{.Table.StructName}} { -return &{{.Table.StructName}}{ {{.Table.BusinessName}}Server:{{.Table.BusinessName}}Server } +func New{{.Table.StructName}}({{.Table.BusinessName}}Service *{{.Table.ModuleName}}ServiceImpl.{{.Table.StructName}}Service) *{{.Table.StructName}} { +return &{{.Table.StructName}}{ {{.Table.BusinessName}}Service:{{.Table.BusinessName}}Service } } // {{.Table.StructName}}List 查询{{.Table.FunctionName}}列表查询 @@ -35,7 +35,7 @@ return &{{.Table.StructName}}{ {{.Table.BusinessName}}Server:{{.Table.BusinessNa func ({{.Table.BusinessName}} *{{.Table.StructName}}) {{.Table.StructName}}List(c *gin.Context) { dql := new({{.Table.ModuleName}}Models.{{.Table.StructName}}DQL ) _ = c.ShouldBind(dql) - list, count := {{.Table.BusinessName}}.{{.Table.BusinessName}}Server.Select{{.Table.StructName}}List(c, dql) + list, count := {{.Table.BusinessName}}.{{.Table.BusinessName}}Service.Select{{.Table.StructName}}ListAndTotal(c, dql) baizeContext.SuccessListData(c, list, count) } @@ -51,7 +51,7 @@ func ({{.Table.BusinessName}} *{{.Table.StructName}}) {{.Table.StructName}}List( func ({{.Table.BusinessName}} *{{.Table.StructName}}) {{.Table.StructName}}Export(c *gin.Context) { dql := new({{.Table.ModuleName}}Models.{{.Table.StructName}}DQL ) _ = c.ShouldBind(dql) - data := {{.Table.BusinessName}}.{{.Table.BusinessName}}Server.{{.Table.StructName}}Export(c, dql) + data := {{.Table.BusinessName}}.{{.Table.BusinessName}}Service.Export{{.Table.StructName}}Excel(c, dql) baizeContext.DataPackageExcel(c, data) } @@ -70,26 +70,26 @@ func ({{.Table.BusinessName}} *{{.Table.StructName}}) {{.Table.StructName}}GetIn baizeContext.ParameterError(c) return } - baizeContext.SuccessData(c, {{.Table.BusinessName}}.{{.Table.BusinessName}}Server.Select{{.Table.StructName}}ById(c, {{.IdField}})) + baizeContext.SuccessData(c, {{.Table.BusinessName}}.{{.Table.BusinessName}}Service.Select{{.Table.StructName}}ById(c, {{.IdField}})) } // {{.Table.StructName}}Add 添加{{.Table.FunctionName}} // @Summary 添加{{.Table.FunctionName}} // @Description 添加{{.Table.FunctionName}} // @Tags {{.Table.FunctionName}}相关 -// @Param object body {{.Table.ModuleName}}.{{.Table.BusinessName}}Vo true "公司信息" +// @Param object body {{.Table.ModuleName}}Models.{{.Table.StructName}}Vo true "公司信息" // @Security BearerAuth // @Produce application/json // @Success 200 {object} response.ResponseData "成功" // @Router /{{.Table.ModuleName}}/{{.Table.BusinessName}} [post] func ({{.Table.BusinessName}} *{{.Table.StructName}}) {{.Table.StructName}}Add(c *gin.Context) { - vo := new({{.Table.ModuleName}}.{{.Table.BusinessName}}Vo) + vo := new({{.Table.ModuleName}}Models.{{.Table.StructName}}Vo) if err := c.ShouldBindJSON(vo); err != nil { baizeContext.ParameterError(c) return } vo.SetCreateBy(baizeContext.GetUserId(c)) - {{.Table.BusinessName}}.{{.Table.BusinessName}}Server.Insert{{.Table.StructName}}(c, vo) + {{.Table.BusinessName}}.{{.Table.BusinessName}}Service.Insert{{.Table.StructName}}(c, vo) baizeContext.Success(c) } @@ -97,19 +97,19 @@ func ({{.Table.BusinessName}} *{{.Table.StructName}}) {{.Table.StructName}}Add(c // @Summary 修改{{.Table.FunctionName}} // @Description 修改{{.Table.FunctionName}} // @Tags {{.Table.FunctionName}}相关 -// @Param object body {{.Table.ModuleName}}.{{.Table.BusinessName}}Vo true "公司信息" +// @Param object body {{.Table.ModuleName}}Models.{{.Table.StructName}}Vo true "公司信息" // @Security BearerAuth // @Produce application/json // @Success 200 {object} response.ResponseData "成功" // @Router /{{.Table.ModuleName}}/{{.Table.BusinessName}} [put] func ({{.Table.BusinessName}} *{{.Table.StructName}}) {{.Table.StructName}}Edit(c *gin.Context) { - vo := new({{.Table.ModuleName}}.{{.Table.BusinessName}}Vo) + vo := new({{.Table.ModuleName}}Models.{{.Table.StructName}}Vo) if err := c.ShouldBindJSON(vo); err != nil { baizeContext.ParameterError(c) return } vo.SetUpdateBy(baizeContext.GetUserId(c)) - {{.Table.BusinessName}}.{{.Table.BusinessName}}Server.Update{{.Table.StructName}}(c, vo) + {{.Table.BusinessName}}.{{.Table.BusinessName}}Service.Update{{.Table.StructName}}(c, vo) baizeContext.Success(c) } @@ -123,6 +123,6 @@ func ({{.Table.BusinessName}} *{{.Table.StructName}}) {{.Table.StructName}}Edit( // @Success 200 {object} response.ResponseData "成功" // @Router /{{.Table.ModuleName}}/{{.Table.BusinessName}}/{{ "{" }}{{.IdField}}s} [delete] func ({{.Table.BusinessName}} *{{.Table.StructName}}) {{.Table.StructName}}Remove(c *gin.Context) { - {{.Table.BusinessName}}.{{.Table.BusinessName}}Server.Delete{{.Table.StructName}}ByIds(c, baizeContext.ParamInt64Array(c, "{{.IdField}}s")) + {{.Table.BusinessName}}.{{.Table.BusinessName}}Service.Delete{{.Table.StructName}}ByIds(c, baizeContext.ParamInt64Array(c, "{{.IdField}}s")) baizeContext.Success(c) } diff --git a/template/go/dao/daoImpl/daoImpl.tmpl b/template/go/dao/daoImpl/daoImpl.tmpl index d5bc66b1b1685ceba3c381f17cd3122600efde2f..507fe7aacfb959738906c482d91c1af4a4f451f0 100644 --- a/template/go/dao/daoImpl/daoImpl.tmpl +++ b/template/go/dao/daoImpl/daoImpl.tmpl @@ -4,6 +4,8 @@ import ( "{{.Table.PackageName}}{{.Table.ModuleName}}Models" "database/sql" "fmt" + "context" + "errors" "github.com/baizeplus/sqly" ) @@ -76,7 +78,7 @@ func ({{.Table.BusinessName}}Dao *{{.Table.StructName}}Dao) Insert{{.Table.Str value := "" insertStr := fmt.Sprintf(insertSQL, key, value) - _, err := db.NamedExecContext(ctx, insertStr, dept) + _, err := db.NamedExecContext(ctx, insertStr, {{.Table.BusinessName}}) if err != nil { panic(err) } diff --git a/template/go/model/model.tmpl b/template/go/model/model.tmpl index 102abca844c6623e69c73cea42c019e9e727bc74..4b3806151ccd274e9c4952bd35f4afd14b486783 100644 --- a/template/go/model/model.tmpl +++ b/template/go/model/model.tmpl @@ -1,4 +1,4 @@ -package {{.Table.ModuleName}}Model +package {{.Table.ModuleName}}Models import ( "baize/app/baize" diff --git a/template/go/server/serverImpl/oneServieceImpl.tmpl b/template/go/server/serverImpl/oneServieceImpl.tmpl new file mode 100644 index 0000000000000000000000000000000000000000..83cb94db4ad86102b679563b2a245a7b43dc4a86 --- /dev/null +++ b/template/go/server/serverImpl/oneServieceImpl.tmpl @@ -0,0 +1,11 @@ +package {{.Table.ModuleName}}ServiceImpl + +import "github.com/google/wire" +// ========================================================================== +// date:{{.GenerateTime.Format "2006-01-02 15:04:05" }} +// author:{{.Table.FunctionAuthor}} +// version: v1.0 +// 建议放到 {{.Table.ModuleName}}ServiceImpl 目录下,建议命名为: servieceImpl.go +// ========================================================================== + +var ProviderSet = wire.NewSet(New{{.Table.StructName}}Service) diff --git a/template/go/server/serverImpl/serverImpl.tmpl b/template/go/server/serverImpl/serverImpl.tmpl index 23c41ef0e745b4a3adbdba385a4fa48d3aa8dcf4..6156ad12489b89476c159cc5e6dee3b7be8f6efd 100644 --- a/template/go/server/serverImpl/serverImpl.tmpl +++ b/template/go/server/serverImpl/serverImpl.tmpl @@ -21,8 +21,8 @@ type {{.Table.StructName}}Service struct { {{.Table.BusinessName}}Dao {{.Table.ModuleName}}Dao.I{{.Table.StructName}}Dao } -func New{{.Table.StructName}}Service(data *sqly.DB, {{.Table.BusinessName}}Dao *{{.Table.ModuleName}}Impl.{{.Table.StructName}}Dao) *PostService { - return &PostService{ +func New{{.Table.StructName}}Service(data *sqly.DB, {{.Table.BusinessName}}Dao *{{.Table.ModuleName}}DaoImpl.{{.Table.StructName}}Dao) *{{.Table.StructName}}Service { + return &{{.Table.StructName}}Service{ data: data, {{.Table.BusinessName}}Dao: {{.Table.BusinessName}}Dao, } @@ -34,11 +34,11 @@ func ({{.Table.BusinessName}}Service *{{.Table.StructName}}Service)Select{{.Tabl } func ({{.Table.BusinessName}}Service *{{.Table.StructName}}Service)Select{{.Table.StructName}}ListAndTotal(c *gin.Context, {{.Table.BusinessName}} *{{.Table.ModuleName}}Models.{{.Table.StructName}}DQL) (list []*{{.Table.ModuleName}}Models.{{.Table.StructName}}Vo, total *int64) { - return {{.Table.BusinessName}}Service.{{.Table.BusinessName}}Dao.Select{{.Table.StructName}}ListAndTotal(c,{{.Table.BusinessName}}Service.data,{{.IdField}}) + return {{.Table.BusinessName}}Service.{{.Table.BusinessName}}Dao.Select{{.Table.StructName}}ListAndTotal(c,{{.Table.BusinessName}}Service.data,{{.Table.BusinessName}}) } func ({{.Table.BusinessName}}Service *{{.Table.StructName}}Service)Export{{.Table.StructName}}Excel(c *gin.Context, {{.Table.BusinessName}} *{{.Table.ModuleName}}Models.{{.Table.StructName}}DQL) (data []byte) { - list := {{.Table.BusinessName}}Service.{{.Table.BusinessName}}Dao.Select{{.Table.StructName}}List(c,{{.Table.BusinessName}}Service.data,{{.IdField}}) + list := {{.Table.BusinessName}}Service.{{.Table.BusinessName}}Dao.Select{{.Table.StructName}}List(c,{{.Table.BusinessName}}Service.data,{{.Table.BusinessName}}) toExcel, err := excel.SliceToExcel(list) if err != nil { panic(err) @@ -51,14 +51,14 @@ func ({{.Table.BusinessName}}Service *{{.Table.StructName}}Service)Export{{.Tabl } func ({{.Table.BusinessName}}Service *{{.Table.StructName}}Service)Insert{{.Table.StructName}}(c *gin.Context, {{.Table.BusinessName}} *{{.Table.ModuleName}}Models.{{.Table.StructName}}Vo){ - {{.Table.BusinessName}}.IdField = snowflake.GenID() + {{.Table.BusinessName}}.{{.GoField}} = snowflake.GenID() {{.Table.BusinessName}}Service.{{.Table.BusinessName}}Dao.Insert{{.Table.StructName}}(c, {{.Table.BusinessName}}Service.data, {{.Table.BusinessName}}) } -func ({{.Table.BusinessName}}Service *{{.Table.StructName}}Service)Update{{.Table.StructName}}(c *gin.Context, db sqly.SqlyContext, {{.Table.BusinessName}} *{{.Table.ModuleName}}Models.{{.Table.StructName}}Vo) { +func ({{.Table.BusinessName}}Service *{{.Table.StructName}}Service)Update{{.Table.StructName}}(c *gin.Context, {{.Table.BusinessName}} *{{.Table.ModuleName}}Models.{{.Table.StructName}}Vo) { {{.Table.BusinessName}}Service.{{.Table.BusinessName}}Dao.Update{{.Table.StructName}}(c, {{.Table.BusinessName}}Service.data, {{.Table.BusinessName}}) } func ({{.Table.BusinessName}}Service *{{.Table.StructName}}Service)Delete{{.Table.StructName}}ByIds(c *gin.Context,{{.IdField}}s []{{.IdType}} ) { - {{.Table.BusinessName}}Service.{{.Table.BusinessName}}Dao.Delete{{.Table.StructName}}(c, {{.Table.BusinessName}}Service.data, {{.IdField}}s) + {{.Table.BusinessName}}Service.{{.Table.BusinessName}}Dao.Delete{{.Table.StructName}}ByIds(c, {{.Table.BusinessName}}Service.data, {{.IdField}}s) } diff --git a/template/go/server/service.tmpl b/template/go/server/service.tmpl index 81d1a92020c85b9953be9a6241f82af3547a70b9..a455f464306589328816a00618ae1140c1c9a22b 100644 --- a/template/go/server/service.tmpl +++ b/template/go/server/service.tmpl @@ -18,6 +18,6 @@ type I{{.Table.StructName}}Service interface { Select{{.Table.StructName}}ListAndTotal(c *gin.Context, {{.Table.BusinessName}} *{{.Table.ModuleName}}Models.{{.Table.StructName}}DQL) (list []*{{.Table.ModuleName}}Models.{{.Table.StructName}}Vo, total *int64) Export{{.Table.StructName}}Excel(c *gin.Context, {{.Table.BusinessName}} *{{.Table.ModuleName}}Models.{{.Table.StructName}}DQL) (data []byte) Insert{{.Table.StructName}}(c *gin.Context, {{.Table.BusinessName}} *{{.Table.ModuleName}}Models.{{.Table.StructName}}Vo) - Update{{.Table.StructName}}(c *gin.Context, db sqly.SqlyContext, {{.Table.BusinessName}} *{{.Table.ModuleName}}Models.{{.Table.StructName}}Vo) + Update{{.Table.StructName}}(c *gin.Context, {{.Table.BusinessName}} *{{.Table.ModuleName}}Models.{{.Table.StructName}}Vo) Delete{{.Table.StructName}}ByIds(c *gin.Context,{{.IdField}}s []{{.IdType}} ) }