package api // ========================================================================== // 生成日期:{{.CreatedAt}} // 生成路径: apps/{{.PackageName}}/api/{{.TableName}}.go // 生成人:{{.FunctionAuthor}} // ========================================================================== import ( "pandax/kit/model" "pandax/kit/restfulx" "pandax/apps/{{.PackageName}}/entity" "pandax/apps/{{.PackageName}}/services" "pandax/kit/utils" ) type {{.ClassName}}Api struct { {{.ClassName}}App services.{{.ClassName}}Model } // Get{{.ClassName}}List {{.FunctionName}}列表数据 func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *restfulx.ReqCtx) { data := entity.{{.ClassName}}{} pageNum := restfulx.QueryInt(rc, "pageNum", 1) pageSize := restfulx.QueryInt(rc, "pageSize", 10) {{- range $index, $column := .Columns -}} {{- if eq $column.IsRequired "1" -}} {{- if eq $column.GoType "string" }} data.{{$column.GoField}} = restfulx.QueryParam(rc, "{{$column.JsonField}}") {{- else if or (eq $column.GoType "int") (eq $column.GoType "int64") (eq $column.GoType "uint") (eq $column.GoType "uint64") -}} data.{{$column.GoField}} = restfulx.QueryInt(rc, "{{$column.JsonField}}", 0) {{- end -}} {{- end -}} {{- end }} list, total := p.{{.ClassName}}App.FindListPage(pageNum, pageSize, data) rc.ResData = model.ResultPage{ Total: total, PageNum: int64(pageNum), PageSize: int64(pageSize), Data: list, } } // Get{{.ClassName}} 获取{{.FunctionName}} func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *restfulx.ReqCtx) { {{ if eq .PkGoType "string" -}} {{.PkJsonField}} := restfulx.PathParam(rc, "{{.PkJsonField}}") rc.ResData = p.{{.ClassName}}App.FindOne({{.PkJsonField}}) {{- else -}} {{.PkJsonField}} := restfulx.PathParamInt(rc, "{{.PkJsonField}}") rc.ResData = p.{{.ClassName}}App.FindOne(int64({{.PkJsonField}})) {{- end}} } // Insert{{.ClassName}} 添加{{.FunctionName}} func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *restfulx.ReqCtx) { var data entity.{{.ClassName}} restfulx.BindQuery(rc, &data) p.{{.ClassName}}App.Insert(data) } // Update{{.ClassName}} 修改{{.FunctionName}} func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *restfulx.ReqCtx) { var data entity.{{.ClassName}} restfulx.BindQuery(rc, &data) p.{{.ClassName}}App.Update(data) } // Delete{{.ClassName}} 删除{{.FunctionName}} func (p *{{.ClassName}}Api) Delete{{.ClassName}}(rc *restfulx.ReqCtx) { {{.PkJsonField}} := restfulx.PathParam(rc,"{{.PkJsonField}}") {{ if eq .PkGoType "string" -}} {{.PkJsonField}}s := strings.Split({{.PkJsonField}}, ",") {{- else -}} {{.PkJsonField}}s := utils.IdsStrToIdsIntGroup({{.PkJsonField}}) {{- end }} p.{{.ClassName}}App.Delete({{.PkJsonField}}s) }