From a2b5f08c2512420182d5a9b5e0f8b22caa7a2180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=BA=E4=BA=AE?= <927919732@qq.com> Date: Sat, 15 Jun 2024 22:37:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fixed=20fd7d81e=20from=20https://gitee.com/?= =?UTF-8?q?baizeplus/baize/pulls/3=20=E4=BC=98=E5=8C=96=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=88=A4=E6=96=AD=E5=92=8C=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/go/server/service.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/go/server/service.tmpl b/template/go/server/service.tmpl index 81d1a92..a455f46 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}} ) } -- Gitee From d18386ef2cf0554ce8a2b476a05bfbdc4d6e65c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=BA=E4=BA=AE?= <927919732@qq.com> Date: Sat, 15 Jun 2024 22:12:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fixed=20c2c1060=20from=20https://gitee.com/?= =?UTF-8?q?baizeplus/baize/pulls/3=20=E4=BC=98=E5=8C=96=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=88=A4=E6=96=AD=E5=92=8C=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tool/toolModels/genTableColumn.go | 2 +- .../toolServiceImpl/genTableServiceImpl.go | 1 + app/business/tool/utils/tableColumn.go | 16 ++++++---- app/utils/stringUtils/stringUtils.go | 13 ++++++-- template/go/controller/controller.tmpl | 30 +++++++++---------- template/go/dao/daoImpl/daoImpl.tmpl | 4 ++- template/go/model/model.tmpl | 2 +- .../go/server/serverImpl/oneServieceImpl.tmpl | 11 +++++++ template/go/server/serverImpl/serverImpl.tmpl | 14 ++++----- 9 files changed, 60 insertions(+), 33 deletions(-) create mode 100644 template/go/server/serverImpl/oneServieceImpl.tmpl diff --git a/app/business/tool/toolModels/genTableColumn.go b/app/business/tool/toolModels/genTableColumn.go index 26bb693..2bf93c4 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 1891e51..9beedfe 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 19081e3..9af3cd1 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 7681093..9f8a276 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 da1884f..b89dc59 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 d5bc66b..507fe7a 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 102abca..4b38061 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 0000000..83cb94d --- /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 23c41ef..6156ad1 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) } -- Gitee