|
|
|
@ -93,6 +93,7 @@ function toCamelCase(str) { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function titleCase(str) { |
|
|
|
const newStr = str.slice(0, 1).toUpperCase() + str.slice(1); |
|
|
|
return newStr; |
|
|
|
@ -103,6 +104,16 @@ function lowerCase(str) { |
|
|
|
return newStr; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 删除如t_user中的t_前缀 |
|
|
|
function rmPrefix(str) { |
|
|
|
if (str.indexOf('_') > -1) { |
|
|
|
var ss = str.split('_') |
|
|
|
return ss[1] |
|
|
|
} |
|
|
|
return str |
|
|
|
} |
|
|
|
|
|
|
|
function typeMap(str) { |
|
|
|
const kv = { |
|
|
|
integer: "int64", |
|
|
|
@ -216,8 +227,9 @@ export default { |
|
|
|
this.schemaKey = Date.now(); |
|
|
|
}, |
|
|
|
handleRouteOutput(v) { |
|
|
|
const tableName = toCamelCase(v.title); |
|
|
|
const lowTableName = v.title; |
|
|
|
const title = rmPrefix(v.title); |
|
|
|
const tableName = toCamelCase(title); |
|
|
|
const lowTableName = title |
|
|
|
const Output = ` |
|
|
|
{ |
|
|
|
${lowTableName} := admin.Group("${lowTableName}") |
|
|
|
@ -230,8 +242,9 @@ export default { |
|
|
|
return Output; |
|
|
|
}, |
|
|
|
handleJsApi(v) { |
|
|
|
const tableName = toCamelCase(v.title); |
|
|
|
const lowTableName = v.title; |
|
|
|
const title = rmPrefix(v.title); |
|
|
|
const tableName = toCamelCase(title); |
|
|
|
const lowTableName = title |
|
|
|
const Output = ` |
|
|
|
import request from '@/utils/request'; |
|
|
|
export function get${tableName}(data) { |
|
|
|
@ -278,7 +291,8 @@ export default { |
|
|
|
return Output; |
|
|
|
}, |
|
|
|
handleApiOutput(v) { |
|
|
|
const tableName = toCamelCase(v.title); |
|
|
|
const title = rmPrefix(v.title); |
|
|
|
const tableName = toCamelCase(title); |
|
|
|
const apiOutput = ` |
|
|
|
package api |
|
|
|
|
|
|
|
@ -289,6 +303,7 @@ export default { |
|
|
|
"Carp/internal/app/service" |
|
|
|
"Carp/pkg/errors" |
|
|
|
"Carp/pkg/utils" |
|
|
|
"Carp/pkg/utils/excelize" |
|
|
|
|
|
|
|
"github.com/gin-gonic/gin" |
|
|
|
"github.com/google/wire" |
|
|
|
@ -340,20 +355,22 @@ export default { |
|
|
|
return |
|
|
|
} |
|
|
|
if req.Export { |
|
|
|
file := resp.(*xlsx.File) |
|
|
|
ginplus.ResExcel(c, file, "导出信息列表") |
|
|
|
f, _ := excelize.Excelize(resp, |
|
|
|
excelize.ColumnFilter("create_time", excelize.FilterTimestamp), |
|
|
|
) |
|
|
|
ginplus.ResExcel(c, f, "导出信息列表") |
|
|
|
return |
|
|
|
} |
|
|
|
ginplus.ResPage(c, resp) |
|
|
|
} |
|
|
|
|
|
|
|
func (l *${tableName}Api) Delete${tableName}(c *gin.Context) { |
|
|
|
var req schema.Ids |
|
|
|
var req schema.IDResult |
|
|
|
if err := ginplus.ParseJSON(c, &req); err != nil { |
|
|
|
ginplus.ResError(c, err) |
|
|
|
return |
|
|
|
} |
|
|
|
if err := l.${tableName}Service.Del${tableName}(c.Request.Context(), req.IDs...); err != nil { |
|
|
|
if err := l.${tableName}Service.Del${tableName}(c.Request.Context(), req.ID); err != nil { |
|
|
|
ginplus.ResError(c, err) |
|
|
|
return |
|
|
|
} |
|
|
|
@ -363,8 +380,9 @@ export default { |
|
|
|
return apiOutput; |
|
|
|
}, |
|
|
|
handleServiceOutput(v) { |
|
|
|
const title = rmPrefix(v.title); |
|
|
|
const tableName = toCamelCase(title); |
|
|
|
const properties = v.properties; |
|
|
|
const tableName = toCamelCase(v.title); |
|
|
|
var primary = ``; |
|
|
|
Object.keys(properties).forEach(function (key) { |
|
|
|
const o = properties[key]; |
|
|
|
@ -380,7 +398,6 @@ export default { |
|
|
|
"Carp/internal/app/model" |
|
|
|
"Carp/internal/app/schema" |
|
|
|
"Carp/pkg/errors" |
|
|
|
"Carp/pkg/utils/excelize" |
|
|
|
"context" |
|
|
|
"encoding/json" |
|
|
|
|
|
|
|
@ -399,12 +416,6 @@ export default { |
|
|
|
return nil, errors.WithStack(err) |
|
|
|
} |
|
|
|
|
|
|
|
if req.Export { |
|
|
|
rst, _ := excelize.Excelize(l, |
|
|
|
excelize.ColumnFilter("create_time", excelize.FilterTimestamp), |
|
|
|
) |
|
|
|
return rst, nil |
|
|
|
} |
|
|
|
pagination := &schema.PaginationResult{ |
|
|
|
Count: cnt, |
|
|
|
List: l, |
|
|
|
@ -424,15 +435,12 @@ export default { |
|
|
|
} |
|
|
|
|
|
|
|
func (a *${tableName}Service) Del${tableName}(ctx context.Context, ${primaryLower} ...int64) error { |
|
|
|
var l []model.${tableName} |
|
|
|
_, err := a.${tableName}.Q().${primary}In(${primaryLower}...).List(ctx, &l) |
|
|
|
var o model.${tableName} |
|
|
|
err := a.${tableName}.Q().${primary}(${primaryLower}).One(ctx, &o) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
for _, d := range l { |
|
|
|
a.${tableName}.Delete(ctx, d.${primary}) |
|
|
|
} |
|
|
|
return nil |
|
|
|
return a.${tableName}.Delete(ctx, o.${primary}) |
|
|
|
} |
|
|
|
|
|
|
|
func (a *${tableName}Service) Create${tableName}(ctx context.Context, r *model.${tableName}) error { |
|
|
|
|