Skip to content

Commit

Permalink
代码生成器支持直接使用字典
Browse files Browse the repository at this point in the history
修复查询涉及sql关键字时sql语句报错问题
  • Loading branch information
QM303176530 committed Jul 18, 2020
1 parent d07a1e9 commit 323236e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions server/model/sys_auto_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ type Field struct {
Comment string `json:"comment"`
ColumnName string `json:"columnName"`
FieldSearchType string `json:"fieldSearchType"`
DictType string `json:"dictType"`
}
25 changes: 21 additions & 4 deletions server/resource/template/fe/table.vue.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@
<el-table-column label="日期" width="180">
<template slot-scope="scope">{{ "{{scope.row.CreatedAt|formatDate}}" }}</template>
</el-table-column>
{{range .Fields}} {{- if eq .FieldType "bool" }}
{{range .Fields}}
{{- if .DictType}}
<el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
<template slot-scope="scope">
{{"{{"}}filterDict(scope.row.{{.FieldJson}},"{{.DictType}}"){{"}}"}}
</template>
</el-table-column>
{{- else if eq .FieldType "bool" }}
<el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
<template slot-scope="scope">{{ "{{scope.row."}}{{.FieldJson}}{{"|formatBoolean}}" }}</template>
</el-table-column> {{- else }}
Expand Down Expand Up @@ -117,6 +124,11 @@ export default {
type: "",
deleteVisible: false,
multipleSelection: [],
{{- range .Fields}}
{{- if .DictType }}
{{.DictType}}Options:[],
{{ end -}}
{{end -}}
formData: {
{{range .Fields}}{{.FieldJson}}:null,{{ end }}
}
Expand Down Expand Up @@ -222,9 +234,14 @@ export default {
this.dialogFormVisible = true;
}
},
created() {
this.getTableData();
}
async created() {
await this.getTableData();
{{- range .Fields -}}
{{- if .DictType -}}
await this.getDict("{{.DictType}}")
{{- end -}}
{{- end -}}
}
};
</script>

Expand Down
12 changes: 6 additions & 6 deletions server/resource/template/te/service.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} model.{{.StructNa
}

// @title Get{{.StructName}}InfoList
// @description get {{.StructName}} list by pagination, 分页获取用户列表
// @description get {{.StructName}} list by pagination, 分页获取{{.StructName}}
// @auth (2020/04/05 20:22)
// @param info PageInfo
// @return error
Expand All @@ -79,23 +79,23 @@ func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error,
{{- if .FieldSearchType}}
{{- if eq .FieldType "string" }}
if info.{{.FieldName}} != "" {
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+ {{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
db = db.Where("`{{.ColumnName}}` {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+ {{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
}
{{- else if eq .FieldType "bool" }}
if info.{{.FieldName}} != nil {
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
db = db.Where("`{{.ColumnName}}` {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
}
{{- else if eq .FieldType "int" }}
if info.{{.FieldName}} != 0 {
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
db = db.Where("`{{.ColumnName}}` {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
}
{{- else if eq .FieldType "float64" }}
if info.{{.FieldName}} != 0 {
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
db = db.Where("`{{.ColumnName}}` {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
}
{{- else if eq .FieldType "time.Time" }}
if !info.{{.FieldName}}.IsZero() {
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
db = db.Where("`{{.ColumnName}}` {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
}
{{- end }}
{{- end }}
Expand Down

0 comments on commit 323236e

Please sign in to comment.