fix 修复代码生成bug
This commit is contained in:
parent
79440bf6fe
commit
043d0e6ea9
@ -10,6 +10,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
"github.com/tiger1103/gfast/v3/api/v1/common"
|
"github.com/tiger1103/gfast/v3/api/v1/common"
|
||||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
|
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
|
||||||
@ -63,7 +64,7 @@ func (c *toolsGenTableController) GenColumnList(ctx context.Context, req *system
|
|||||||
|
|
||||||
// RelationTable 获取关联表数据
|
// RelationTable 获取关联表数据
|
||||||
func (c *toolsGenTableController) RelationTable(ctx context.Context, req *system.ToolsGenRelationTableReq) (res *system.ToolsGenRelationTableRes, err error) {
|
func (c *toolsGenTableController) RelationTable(ctx context.Context, req *system.ToolsGenRelationTableReq) (res *system.ToolsGenRelationTableRes, err error) {
|
||||||
res, err = service.ToolsGenTable().GetRelationTable(ctx,req)
|
res, err = service.ToolsGenTable().GetRelationTable(ctx, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +83,7 @@ func (c *toolsGenTableController) Preview(ctx context.Context, req *system.Tools
|
|||||||
|
|
||||||
// BatchGenCode 代码生成
|
// BatchGenCode 代码生成
|
||||||
func (c *toolsGenTableController) BatchGenCode(ctx context.Context, req *system.ToolsGenTableBatchGenCodeReq) (res *system.ToolsGenTableBatchGenCodeRes, err error) {
|
func (c *toolsGenTableController) BatchGenCode(ctx context.Context, req *system.ToolsGenTableBatchGenCodeReq) (res *system.ToolsGenTableBatchGenCodeRes, err error) {
|
||||||
err = service.ToolsGenTable().GenCode(ctx, req.Ids)
|
err = service.ToolsGenTable().GenCode(gctx.New(), req.Ids)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ func (s *sToolsGenTable) SelectDbTableList(ctx context.Context, req *system.Tool
|
|||||||
var sqlStr string
|
var sqlStr string
|
||||||
if s.IsMysql() {
|
if s.IsMysql() {
|
||||||
sqlStr = " from information_schema.tables where table_schema = (select database())" +
|
sqlStr = " from information_schema.tables where table_schema = (select database())" +
|
||||||
" and table_name table_name NOT LIKE 'tools_gen_%' and table_name NOT IN (select table_name from " + dao.ToolsGenTable.Table() + ") "
|
" and table_name NOT LIKE 'tools_gen_%' and table_name NOT IN (select table_name from " + dao.ToolsGenTable.Table() + ") "
|
||||||
if req != nil {
|
if req != nil {
|
||||||
if req.TableName != "" {
|
if req.TableName != "" {
|
||||||
sqlStr += gdb.FormatSqlWithArgs(" and lower(table_name) like lower(?)", []interface{}{"%" + req.TableName + "%"})
|
sqlStr += gdb.FormatSqlWithArgs(" and lower(table_name) like lower(?)", []interface{}{"%" + req.TableName + "%"})
|
||||||
|
@ -303,14 +303,14 @@ func (c *{{$structName}}Controller) ExcelTemplate(ctx context.Context,req *{{.ta
|
|||||||
r.Response.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
r.Response.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||||
r.Response.Header().Set("Accept-Ranges", "bytes")
|
r.Response.Header().Set("Accept-Ranges", "bytes")
|
||||||
r.Response.Header().Set("Access-Control-Expose-Headers", "*")
|
r.Response.Header().Set("Access-Control-Expose-Headers", "*")
|
||||||
r.Response.Header().Set("Content-Disposition", "attachment; filename="+gurl.Encode("代码生成测试表模板")+".xlsx")
|
r.Response.Header().Set("Content-Disposition", "attachment; filename="+gurl.Encode("{{.table.TableComment}}模板")+".xlsx")
|
||||||
r.Response.Buffer()
|
r.Response.Buffer()
|
||||||
r.Exit()
|
r.Exit()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func(c *{{$structName}}Controller)Import(ctx context.Context,req *{{.table.ModuleName}}.{{.table.ClassName}}ImportReq)(res *{{.table.ModuleName}}.{{.table.ClassName}}ImportRes,err error){
|
func(c *{{$structName}}Controller)Import(ctx context.Context,req *{{.table.ModuleName}}.{{.table.ClassName}}ImportReq)(res *{{.table.ModuleName}}.{{.table.ClassName}}ImportRes,err error){
|
||||||
err = service.DemoGen().Import(ctx,req.File)
|
err = service.{{.table.ClassName}}().Import(ctx,req.File)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -42,6 +42,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
{{if .table.ExcelImp}}
|
{{if .table.ExcelImp}}
|
||||||
|
"errors"
|
||||||
"github.com/gogf/gf/v2/net/ghttp"
|
"github.com/gogf/gf/v2/net/ghttp"
|
||||||
"github.com/gogf/gf/v2/database/gdb"
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
"github.com/xuri/excelize/v2"
|
"github.com/xuri/excelize/v2"
|
||||||
@ -347,6 +348,7 @@ func(s *s{{.table.ClassName}})Import(ctx context.Context,file *ghttp.UploadFile)
|
|||||||
}
|
}
|
||||||
d:=make([]interface{}, len(rows[0]))
|
d:=make([]interface{}, len(rows[0]))
|
||||||
data=make([]do.{{.table.ClassName}},len(rows)-1)
|
data=make([]do.{{.table.ClassName}},len(rows)-1)
|
||||||
|
|
||||||
for k,v:=range rows{
|
for k,v:=range rows{
|
||||||
if k==0{
|
if k==0{
|
||||||
continue
|
continue
|
||||||
@ -354,17 +356,19 @@ func(s *s{{.table.ClassName}})Import(ctx context.Context,file *ghttp.UploadFile)
|
|||||||
for kv,vv:=range v{
|
for kv,vv:=range v{
|
||||||
d[kv] = vv
|
d[kv] = vv
|
||||||
}
|
}
|
||||||
|
{{if $.table.UseSnowId}}
|
||||||
|
var {{$.table.PkColumn.HtmlField}} uint64
|
||||||
|
{{$.table.PkColumn.HtmlField}}, err = commonService.SnowID().GenID()
|
||||||
|
liberr.ErrIsNil(ctx, err)
|
||||||
|
{{end}}
|
||||||
data[k-1] = do.{{.table.ClassName}}{
|
data[k-1] = do.{{.table.ClassName}}{
|
||||||
{{$i:=0}}
|
{{$i:=0}}
|
||||||
{{range $index, $column := .table.Columns}}
|
{{range $index, $column := .table.Columns}}
|
||||||
{{$add:=false}}
|
{{$add:=false}}
|
||||||
{{if $.table.IsPkInsertable}}
|
{{if and $column.IsPk $.table.IsPkInsertable}}
|
||||||
{{$.table.PkColumn.GoField}}:d[{{$i}}],
|
{{$.table.PkColumn.GoField}}:d[{{$i}}],
|
||||||
{{$add = true}}
|
{{$add = true}}
|
||||||
{{else if $.table.UseSnowId}}
|
{{else if and $column.IsPk $.table.UseSnowId}}
|
||||||
var {{$.table.PkColumn.HtmlField}} uint64
|
|
||||||
{{$.table.PkColumn.HtmlField}}, err = commonService.SnowID().GenID()
|
|
||||||
liberr.ErrIsNil(ctx, err)
|
|
||||||
{{$.table.PkColumn.GoField}}:{{$.table.PkColumn.HtmlField}},
|
{{$.table.PkColumn.GoField}}:{{$.table.PkColumn.HtmlField}},
|
||||||
{{else if and (ne $column.IsPk true) (ne $column.HtmlType "imagefile") (ne $column.HtmlType "images") (ne $column.HtmlType "file") (ne $column.HtmlType "files")}}
|
{{else if and (ne $column.IsPk true) (ne $column.HtmlType "imagefile") (ne $column.HtmlType "images") (ne $column.HtmlType "file") (ne $column.HtmlType "files")}}
|
||||||
{{$add = true}}
|
{{$add = true}}
|
||||||
|
@ -36,7 +36,7 @@ type I{{.table.ClassName}} interface {
|
|||||||
{{if .table.ExcelPort }}
|
{{if .table.ExcelPort }}
|
||||||
GetExportData(ctx context.Context, req *model.{{.table.ClassName}}SearchReq) (listRes []*model.{{.table.ClassName}}InfoRes, err error)
|
GetExportData(ctx context.Context, req *model.{{.table.ClassName}}SearchReq) (listRes []*model.{{.table.ClassName}}InfoRes, err error)
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .table.ExcelPort }}
|
{{if .table.ExcelImp }}
|
||||||
Import(ctx context.Context,file *ghttp.UploadFile)(err error)
|
Import(ctx context.Context,file *ghttp.UploadFile)(err error)
|
||||||
{{end}}
|
{{end}}
|
||||||
GetBy{{.table.PkColumn.GoField}}(ctx context.Context, {{.table.PkColumn.GoField}} {{$.table.PkColumn.GoType}}) (res *model.{{.table.ClassName}}InfoRes,err error)
|
GetBy{{.table.PkColumn.GoField}}(ctx context.Context, {{.table.PkColumn.GoField}} {{$.table.PkColumn.GoType}}) (res *model.{{.table.ClassName}}InfoRes,err error)
|
||||||
|
@ -724,7 +724,7 @@ export default defineComponent({
|
|||||||
{{if .table.ExcelPort }}
|
{{if .table.ExcelPort }}
|
||||||
handleExport,
|
handleExport,
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .table.ExcelPort }}
|
{{if .table.ExcelImp }}
|
||||||
handleImport,
|
handleImport,
|
||||||
loadExcel{{.table.ClassName}}Ref,
|
loadExcel{{.table.ClassName}}Ref,
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user