feature:自动化代码增加数据源配置功能
This commit is contained in:
@@ -166,6 +166,25 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}List(c *gin.Co
|
||||
}
|
||||
}
|
||||
|
||||
{{- if .HasDataSource }}
|
||||
// Get{{.StructName}}DataSource 获取{{.StructName}}的数据源
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 获取{{.StructName}}的数据源
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}DataSource [get]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}DataSource(c *gin.Context) {
|
||||
// 此接口为获取数据源定义的数据
|
||||
if dataSource, err := {{.Abbreviation}}Service.Get{{.StructName}}DataSource(); err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
} else {
|
||||
response.OkWithData(dataSource, c)
|
||||
}
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
// Get{{.StructName}}Public 不需要鉴权的{{.Description}}接口
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 不需要鉴权的{{.Description}}接口
|
||||
|
||||
@@ -27,6 +27,9 @@ func (s *{{.StructName}}Router) Init{{.StructName}}Router(Router *gin.RouterGrou
|
||||
{{.Abbreviation}}RouterWithoutRecord.GET("get{{.StructName}}List", {{.Abbreviation}}Api.Get{{.StructName}}List) // 获取{{.Description}}列表
|
||||
}
|
||||
{
|
||||
{{- if .HasDataSource}}
|
||||
{{.Abbreviation}}RouterWithoutAuth.GET("get{{.StructName}}DataSource", {{.Abbreviation}}Api.Get{{.StructName}}DataSource) // 获取{{.Description}}数据源
|
||||
{{- end}}
|
||||
{{.Abbreviation}}RouterWithoutAuth.GET("get{{.StructName}}Public", {{.Abbreviation}}Api.Get{{.StructName}}Public) // 获取{{.Description}}列表
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,3 +137,12 @@ func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoLis
|
||||
err = db.Find(&{{.Abbreviation}}s).Error
|
||||
return {{.Abbreviation}}s, total, err
|
||||
}
|
||||
|
||||
{{- if .HasDataSource }}
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}DataSource() (res map[string][]map[string]any, err error) {
|
||||
{{range $key, $value := .DataSourceMap}}
|
||||
{{$db}}.Table("{{$value.Table}}").Select("{{$value.Label}} as label,{{$value.Value}} as value").Scan(&res["{{$key}}"])
|
||||
{{- end }}
|
||||
return
|
||||
}
|
||||
{{- end }}
|
||||
Reference in New Issue
Block a user