|
|
@ -107,9 +107,12 @@ function lowerCase(str) { |
|
|
function rmPrefix(str) { |
|
|
function rmPrefix(str) { |
|
|
if (str.indexOf("_") > -1) { |
|
|
if (str.indexOf("_") > -1) { |
|
|
var n = str.indexOf("_"); |
|
|
var n = str.indexOf("_"); |
|
|
return str.slice(n + 1, str.length); |
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
prefix: str.slice(0, n + 1), |
|
|
|
|
|
suffix: str.slice(n + 1, str.length), |
|
|
|
|
|
}; |
|
|
} |
|
|
} |
|
|
return str; |
|
|
|
|
|
|
|
|
return { prefix: "", suffix: str }; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function typeMap(str) { |
|
|
function typeMap(str) { |
|
|
@ -225,7 +228,7 @@ export default { |
|
|
this.schemaKey = Date.now(); |
|
|
this.schemaKey = Date.now(); |
|
|
}, |
|
|
}, |
|
|
handleRouteOutput(v) { |
|
|
handleRouteOutput(v) { |
|
|
const title = rmPrefix(v.title); |
|
|
|
|
|
|
|
|
const title = rmPrefix(v.title).suffix; |
|
|
const tableName = toCamelCase(title); |
|
|
const tableName = toCamelCase(title); |
|
|
const lowTableName = title; |
|
|
const lowTableName = title; |
|
|
const Output = ` |
|
|
const Output = ` |
|
|
@ -240,7 +243,7 @@ export default { |
|
|
return Output; |
|
|
return Output; |
|
|
}, |
|
|
}, |
|
|
handleJsApi(v) { |
|
|
handleJsApi(v) { |
|
|
const title = rmPrefix(v.title); |
|
|
|
|
|
|
|
|
const title = rmPrefix(v.title).suffix; |
|
|
const tableName = toCamelCase(title); |
|
|
const tableName = toCamelCase(title); |
|
|
const lowTableName = title; |
|
|
const lowTableName = title; |
|
|
const Output = ` |
|
|
const Output = ` |
|
|
@ -289,7 +292,7 @@ export default { |
|
|
return Output; |
|
|
return Output; |
|
|
}, |
|
|
}, |
|
|
handleApiOutput(v) { |
|
|
handleApiOutput(v) { |
|
|
const title = rmPrefix(v.title); |
|
|
|
|
|
|
|
|
const title = rmPrefix(v.title).suffix; |
|
|
const tableName = toCamelCase(title); |
|
|
const tableName = toCamelCase(title); |
|
|
const apiOutput = ` |
|
|
const apiOutput = ` |
|
|
package api |
|
|
package api |
|
|
@ -378,7 +381,7 @@ export default { |
|
|
return apiOutput; |
|
|
return apiOutput; |
|
|
}, |
|
|
}, |
|
|
handleServiceOutput(v) { |
|
|
handleServiceOutput(v) { |
|
|
const title = rmPrefix(v.title); |
|
|
|
|
|
|
|
|
const title = rmPrefix(v.title).suffix; |
|
|
const tableName = toCamelCase(title); |
|
|
const tableName = toCamelCase(title); |
|
|
const properties = v.properties; |
|
|
const properties = v.properties; |
|
|
var primary = ``; |
|
|
var primary = ``; |
|
|
@ -400,20 +403,20 @@ export default { |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
|
|
|
|
|
|
"github.com/google/wire" |
|
|
"github.com/google/wire" |
|
|
) |
|
|
|
|
|
|
|
|
) |
|
|
var ${tableName}ServiceSet = wire.NewSet(wire.Struct(new(${tableName}Service), "*")) |
|
|
var ${tableName}ServiceSet = wire.NewSet(wire.Struct(new(${tableName}Service), "*")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type ${tableName}Service struct { |
|
|
type ${tableName}Service struct { |
|
|
${tableName} *model.${tableName}Repo |
|
|
${tableName} *model.${tableName}Repo |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (a *${tableName}Service) Get${tableName}List(ctx context.Context, req *model.${tableName}ReqParams) (*schema.PaginationResult, error) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (a *${tableName}Service) Get${tableName}List(ctx context.Context, req *model.${tableName}ReqParams) (*schema.PaginationResult, error) { |
|
|
var l []*model.${tableName} |
|
|
var l []*model.${tableName} |
|
|
cnt, err := a.${tableName}.Q().Filter(req).List(ctx, &l) |
|
|
cnt, err := a.${tableName}.Q().Filter(req).List(ctx, &l) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, errors.WithStack(err) |
|
|
return nil, errors.WithStack(err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pagination := &schema.PaginationResult{ |
|
|
pagination := &schema.PaginationResult{ |
|
|
Count: cnt, |
|
|
Count: cnt, |
|
|
List: l, |
|
|
List: l, |
|
|
@ -455,7 +458,7 @@ export default { |
|
|
`; |
|
|
`; |
|
|
return serviceOutput; |
|
|
return serviceOutput; |
|
|
}, |
|
|
}, |
|
|
getMyStruct() { |
|
|
|
|
|
|
|
|
getMyStruct(tablePrefix) { |
|
|
var oReq = new XMLHttpRequest(); |
|
|
var oReq = new XMLHttpRequest(); |
|
|
oReq.open("POST", "/sql", false); // 同步请求 |
|
|
oReq.open("POST", "/sql", false); // 同步请求 |
|
|
oReq.setRequestHeader("Content-type", "application/json"); |
|
|
oReq.setRequestHeader("Content-type", "application/json"); |
|
|
@ -464,17 +467,19 @@ export default { |
|
|
JSON.stringify({ |
|
|
JSON.stringify({ |
|
|
content: this.sqlinput, |
|
|
content: this.sqlinput, |
|
|
camel: !this.isUnderScoreCase, |
|
|
camel: !this.isUnderScoreCase, |
|
|
|
|
|
table_prefix: tablePrefix, |
|
|
}) |
|
|
}) |
|
|
); //发送数据需要自定义,这里发送的是JSON结构 |
|
|
); //发送数据需要自定义,这里发送的是JSON结构 |
|
|
var result = oReq.responseText; //响应结果 |
|
|
var result = oReq.responseText; //响应结果 |
|
|
return result; |
|
|
return result; |
|
|
}, |
|
|
}, |
|
|
handleModelOutput(v) { |
|
|
handleModelOutput(v) { |
|
|
var struct = this.getMyStruct(); |
|
|
|
|
|
|
|
|
const tablePrefix = rmPrefix(v.title).prefix; |
|
|
|
|
|
var struct = this.getMyStruct(tablePrefix); |
|
|
console.log("struct", struct); |
|
|
console.log("struct", struct); |
|
|
const requires = v.required; |
|
|
const requires = v.required; |
|
|
const properties = v.properties; |
|
|
const properties = v.properties; |
|
|
const title = rmPrefix(v.title); |
|
|
|
|
|
|
|
|
const title = rmPrefix(v.title).suffix; |
|
|
const tableName = toCamelCase(title); |
|
|
const tableName = toCamelCase(title); |
|
|
const tableNameLower = lowerCase(tableName); |
|
|
const tableNameLower = lowerCase(tableName); |
|
|
var primary = ``; |
|
|
var primary = ``; |
|
|
@ -619,7 +624,7 @@ export default { |
|
|
para.PageSize = 10000 |
|
|
para.PageSize = 10000 |
|
|
} |
|
|
} |
|
|
opt.opts = append(opt.opts, opt.Select(para.Fields...)) |
|
|
opt.opts = append(opt.opts, opt.Select(para.Fields...)) |
|
|
opt.opts = append(opt.opts, opt.Pagination(para)) |
|
|
|
|
|
|
|
|
opt.opts = append(opt.opts, opt.Pagination(para)) |
|
|
if para.Query != nil { |
|
|
if para.Query != nil { |
|
|
`; |
|
|
`; |
|
|
var filtercenter = ``; |
|
|
var filtercenter = ``; |
|
|
@ -639,7 +644,7 @@ export default { |
|
|
const enumlist = o.enum; |
|
|
const enumlist = o.enum; |
|
|
const enumdesc = o.enumDesc; |
|
|
const enumdesc = o.enumDesc; |
|
|
var enumbegin = ` |
|
|
var enumbegin = ` |
|
|
type ${tableKey} ${type} |
|
|
|
|
|
|
|
|
type ${tableKey} ${type} |
|
|
const ( |
|
|
const ( |
|
|
`; |
|
|
`; |
|
|
var enumcenter = ``; |
|
|
var enumcenter = ``; |
|
|
@ -664,7 +669,7 @@ export default { |
|
|
|
|
|
|
|
|
if (key.indexOf("_time") > -1) { |
|
|
if (key.indexOf("_time") > -1) { |
|
|
center += `${skey}Interval []interface{} \`json:"${key}|interval,omitempty"\`\n`; |
|
|
center += `${skey}Interval []interface{} \`json:"${key}|interval,omitempty"\`\n`; |
|
|
filtercenter += ` |
|
|
|
|
|
|
|
|
filtercenter += ` |
|
|
if len(para.Query.${skey}Interval) > 0 { |
|
|
if len(para.Query.${skey}Interval) > 0 { |
|
|
opt.${skey}Interval(para.Query.${skey}Interval) |
|
|
opt.${skey}Interval(para.Query.${skey}Interval) |
|
|
} |
|
|
} |
|
|
@ -689,7 +694,7 @@ export default { |
|
|
// id过滤掉,不能生成,List里面可以查询ID会有风险 |
|
|
// id过滤掉,不能生成,List里面可以查询ID会有风险 |
|
|
if (key.indexOf("_id") > -1) { |
|
|
if (key.indexOf("_id") > -1) { |
|
|
center += `${skey}In []${type} \`json:"${key}|in,omitempty"\`\n`; |
|
|
center += `${skey}In []${type} \`json:"${key}|in,omitempty"\`\n`; |
|
|
filtercenter += ` |
|
|
|
|
|
|
|
|
filtercenter += ` |
|
|
if len(para.Query.${skey}In) > 0 { |
|
|
if len(para.Query.${skey}In) > 0 { |
|
|
opt.${skey}In(para.Query.${skey}In...) |
|
|
opt.${skey}In(para.Query.${skey}In...) |
|
|
} |
|
|
} |
|
|
@ -706,14 +711,14 @@ export default { |
|
|
if (requires.indexOf(key) > -1) { |
|
|
if (requires.indexOf(key) > -1) { |
|
|
center += `${skey} ${type} \`json:"${key},omitempty"\`\n`; |
|
|
center += `${skey} ${type} \`json:"${key},omitempty"\`\n`; |
|
|
if (type == "string") { |
|
|
if (type == "string") { |
|
|
filtercenter += ` |
|
|
|
|
|
|
|
|
filtercenter += ` |
|
|
if para.Query.${skey} != "" { |
|
|
if para.Query.${skey} != "" { |
|
|
opt.${skey}(para.Query.${skey}) |
|
|
opt.${skey}(para.Query.${skey}) |
|
|
} |
|
|
} |
|
|
`; |
|
|
`; |
|
|
} else if (key !== "id") { |
|
|
} else if (key !== "id") { |
|
|
// id过滤掉,不能生成,List里面可以查询ID会有风险 |
|
|
// id过滤掉,不能生成,List里面可以查询ID会有风险 |
|
|
filtercenter += ` |
|
|
|
|
|
|
|
|
filtercenter += ` |
|
|
if para.Query.${skey} != 0 { |
|
|
if para.Query.${skey} != 0 { |
|
|
opt.${skey}(para.Query.${skey}) |
|
|
opt.${skey}(para.Query.${skey}) |
|
|
} |
|
|
} |
|
|
@ -728,7 +733,7 @@ export default { |
|
|
`; |
|
|
`; |
|
|
if (type == "string") { |
|
|
if (type == "string") { |
|
|
center += `${skey}Like ${type} \`json:"${key}|like,omitempty"\`\n`; |
|
|
center += `${skey}Like ${type} \`json:"${key}|like,omitempty"\`\n`; |
|
|
filtercenter += ` |
|
|
|
|
|
|
|
|
filtercenter += ` |
|
|
if para.Query.${skey}Like != "" { |
|
|
if para.Query.${skey}Like != "" { |
|
|
opt.${skey}Like(para.Query.${skey}Like) |
|
|
opt.${skey}Like(para.Query.${skey}Like) |
|
|
} |
|
|
} |
|
|
|