fix 代码生产细节完善,导出功能修复

This commit is contained in:
yxh
2024-12-19 15:13:55 +08:00
parent 7bfbf4e37d
commit 8c669310fe
5 changed files with 71 additions and 7 deletions

View File

@@ -20,14 +20,20 @@ package controller
{{$hasCommonService:=false}}
{{$excel :=false}}
{{$serviceVal := "service"}}
{{$modelVal := "model"}}
{{if ne .table.ModuleName "system"}}
{{$serviceVal = "systemService"}}
{{$modelVal = "systemModel"}}
{{end}}
{{$usedSystemModel := false}}
{{$impSystemService := false}}
{{if or .table.ExcelPort .table.ExcelImp}}
{{$excel = true}}
{{end}}
{{if .table.ExcelPort}}
{{if .table.UseSnowId}}
{{$hasGconv = true}}
{{end}}
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
{{$hasGmap = true}}
@@ -42,6 +48,11 @@ package controller
{{$hasGstr = true}}
{{end}}
{{end}}
{{if and (eq $column.HtmlType "userSelectorSingle" "userSelectorMultiple" "deptSelectorMultiple" "deptSelectorSingle") (ne $.table.ModuleName "system")}}
{{$usedSystemModel = true}}
{{$hasGconv = true}}
{{$impSystemService = true}}
{{end}}
{{end}}
{{end}}
import (
@@ -74,6 +85,9 @@ import (
{{if and (ne $.table.ModuleName "system") $hasSystemApi}}
systemApi "{{$.goModName}}/api/v1/system"
{{end}}
{{if $usedSystemModel}}
systemModel "{{.goModName}}/internal/app/system/model"
{{end}}
{{if $hasCommonService}}
commonService "{{.goModName}}/internal/app/common/service"
{{end}}
@@ -229,6 +243,39 @@ func (c *{{$structName}}Controller) Export(ctx context.Context, req *{{.table.Mo
if v.UpdatedUser!=nil{
{{$column.HtmlField}} = v.UpdatedUser.UserNickname
}
{{else if eq $column.HtmlType "userSelectorSingle"}}
//{{$column.ColumnComment}}
{{$column.HtmlField}}Str := ""
if v.Linked{{$column.GoField}} != nil {
{{$column.HtmlField}}Str = v.Linked{{$column.GoField}}.UserNickname
}
{{else if eq $column.HtmlType "userSelectorMultiple"}}
//{{$column.ColumnComment}}
{{$column.HtmlField}}Str:=""
v.Linked{{$column.GoField}}, err = {{$serviceVal}}.SysUser().GetUsers(ctx, gconv.Interfaces(v.{{$column.GoField}}))
if err != nil {
return
}
for _, us := range v.Linked{{$column.GoField}} {
{{$column.HtmlField}}Str += us.UserNickname + ","
}
{{else if eq $column.HtmlType "deptSelectorSingle"}}
//{{$column.ColumnComment}}
{{$column.HtmlField}}Str := ""
{{$column.HtmlField}}Obj := systemService.SysDept().GetByDept(ctx, v.DepartId)
if {{$column.HtmlField}}Obj != nil {
{{$column.HtmlField}}Str = {{$column.HtmlField}}Obj.DeptName
}
{{else if eq $column.HtmlType "deptSelectorMultiple"}}
//{{$column.ColumnComment}}
{{$column.HtmlField}}Str := ""
linked{{$column.GoField}} := make([]*{{$modelVal}}.LinkDeptRes, len(v.{{$column.GoField}}))
for lk, lv := range v.{{$column.GoField}} {
linked{{$column.GoField}}[lk] = {{$serviceVal}}.SysDept().GetByDept(ctx, lv)
}
for _, dv := range linked{{$column.GoField}} {
{{$column.HtmlField}}Str += dv.DeptName + ","
}
{{end}}
{{end}}
{{end}}
@@ -259,6 +306,20 @@ func (c *{{$structName}}Controller) Export(ctx context.Context, req *{{.table.Mo
{{$column.HtmlField}},
{{else if eq $column.HtmlType "date" "datetime"}}
v.{{$column.GoField}}.Format("Y-m-d H:i:s"),
{{else if eq $column.HtmlType "userSelectorSingle"}}
//用户选择器-单选-{{$column.ColumnComment}}
{{$column.HtmlField}}Str,
{{else if eq $column.HtmlType "userSelectorMultiple"}}
//用户选择器-多选-{{$column.ColumnComment}}
{{$column.HtmlField}}Str,
{{else if eq $column.HtmlType "deptSelectorSingle"}}
//部门选择器-单选-{{$column.ColumnComment}}
{{$column.HtmlField}}Str,
{{else if eq $column.HtmlType "deptSelectorMultiple"}}
//部门选择器-多选-{{$column.ColumnComment}}
{{$column.HtmlField}}Str,
{{else if and $column.IsPk $.table.UseSnowId}}
gconv.String(v.{{$column.GoField}}),
{{else}}
v.{{$column.GoField}},
{{end}}

View File

@@ -301,7 +301,7 @@ func (s *s{{.table.ClassName}})List(ctx context.Context, req *model.{{.table.Cla
{{end}}
{{end}}
{{end}}
{{if eq $column.HtmlType "userSelectorSingle"}}
{{if eq $column.HtmlType "userSelectorSingle"}}
Linked{{$column.GoField}} : v.Linked{{$column.GoField}},
{{end}}
{{if eq $column.HtmlType "userSelectorMultiple"}}
@@ -519,7 +519,10 @@ func (s *s{{.table.ClassName}})GetBy{{$pkGoField}}(ctx context.Context, {{$.tabl
{{end}}
{{if $hasDeptSelector}}
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "deptSelectorSingle"}}
{{if eq $column.HtmlType "userSelectorMultiple"}}
res.Linked{{$column.GoField}}, err = {{if $usedSystemModule}}systemService{{else}}service{{end}}.SysUser().GetUsers(ctx, gconv.Interfaces(res.{{$column.GoField}}))
liberr.ErrIsNil(ctx, err)
{{else if eq $column.HtmlType "deptSelectorSingle"}}
res.Linked{{$column.GoField}} = {{if $usedSystemModule}}systemService{{else}}service{{end}}.SysDept().GetByDept(ctx, res.{{$column.GoField}})
{{else if eq $column.HtmlType "deptSelectorMultiple"}}
res.Linked{{$column.GoField}} = make([]*{{if $usedSystemModel}}systemModel{{else}}model{{end}}.LinkDeptRes, len(res.{{$column.GoField}}))

View File

@@ -73,7 +73,7 @@ type {{.table.ClassName}}InfoRes struct {
Linked{{$column.GoField}} *{{if $hasUser}}systemModel.{{end}}LinkUserRes `orm:"with:id={{$column.ColumnName}}" json:"linked{{$column.GoField}}" dc:"{{$column.ColumnComment}}"`
{{end}}
{{if eq $column.HtmlType "userSelectorMultiple"}}
Linked{{$column.GoField}} []*{{if $hasUser}}systemModel.{{end}}LinkUserRes `orm:"with:id={{$column.ColumnName}}" json:"linked{{$column.GoField}}" dc:"{{$column.ColumnComment}}"`
Linked{{$column.GoField}} []*{{if $hasUser}}systemModel.{{end}}SysUserSimpleRes `json:"linked{{$column.GoField}}" dc:"{{$column.ColumnComment}}"`
{{end}}
{{if eq $column.HtmlType "deptSelectorSingle"}}
Linked{{$column.GoField}} *{{if $hasUser}}systemModel.{{end}}LinkDeptRes `json:"linked{{$column.GoField}}" dc:"{{$column.ColumnComment}}"`

View File

@@ -39,7 +39,7 @@
{{else if eq $column.HtmlType "select" "selects"}}
{{if ne $column.LinkTableName ""}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select filterable v-model="formData.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" {{if $column.IsPk}}v-bind:disabled="this.currentOp === 'edit'" {{end}} {{if $column.IsCascadeParent}}@change="form{{$column.ColumnName | CaseCamel}}Changed"{{end}} {{if eq $column.HtmlType "selects"}}multiple{{end}}>
<el-select filterable clearable v-model="formData.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" {{if $column.IsPk}}v-bind:disabled="this.currentOp === 'edit'" {{end}} {{if $column.IsCascadeParent}}@change="form{{$column.ColumnName | CaseCamel}}Changed"{{end}} {{if eq $column.HtmlType "selects"}}multiple{{end}}>
<el-option
{{if $column.IsCascade}}
v-for="item in {{$column.HtmlField}}FormOptions"
@@ -54,7 +54,7 @@
</el-form-item>
{{else if ne $column.DictType ""}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select filterable v-model="formData.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" {{if $column.IsPk}}v-bind:disabled="this.currentOp === 'edit'" {{end}}>
<el-select filterable clearable v-model="formData.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" {{if $column.IsPk}}v-bind:disabled="this.currentOp === 'edit'" {{end}}>
<el-option
v-for="dict in {{$column.HtmlField}}Options"
:key="dict.value"
@@ -69,7 +69,7 @@
</el-form-item>
{{else}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select filterable v-model="formData.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" {{if $column.IsPk}}v-bind:disabled="this.currentOp === 'edit'" {{end}}>
<el-select filterable clearable v-model="formData.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" {{if $column.IsPk}}v-bind:disabled="this.currentOp === 'edit'" {{end}}>
<el-option label="请选择字典生成" value="" />
</el-select>
</el-form-item>