fix 代码生成pg版完善,定时任务日志清理,其它细节完善
This commit is contained in:
parent
b8de590d99
commit
84f785cd03
@ -146,7 +146,7 @@ type SysJobLogListRes struct {
|
|||||||
type SysJobLogDeleteReq struct {
|
type SysJobLogDeleteReq struct {
|
||||||
g.Meta `path:"/deleteLogs" tags:"系统后台/定时任务" method:"delete" summary:"删除执行日志"`
|
g.Meta `path:"/deleteLogs" tags:"系统后台/定时任务" method:"delete" summary:"删除执行日志"`
|
||||||
commonApi.Author
|
commonApi.Author
|
||||||
LogIds []uint64 `p:"logIds" v:"required#主键必须"`
|
TargetName string `p:"targetName" v:"required#日志标签名不能为空"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SysJobLogDeleteRes struct {
|
type SysJobLogDeleteRes struct {
|
||||||
|
@ -77,6 +77,6 @@ func (c *sysJobController) Log(ctx context.Context, req *system.SysJobLogListReq
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *sysJobController) LogDelete(ctx context.Context, req *system.SysJobLogDeleteReq) (res *system.SysJobLogDeleteRes, err error) {
|
func (c *sysJobController) LogDelete(ctx context.Context, req *system.SysJobLogDeleteReq) (res *system.SysJobLogDeleteRes, err error) {
|
||||||
err = service.SysJobLog().Delete(ctx, req.LogIds)
|
err = service.SysJobLog().Delete(ctx, req.TargetName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,6 @@ func (s *sSysJob) List(ctx context.Context, req *system.SysJobSearchReq) (listRe
|
|||||||
req.PageSize = consts.PageSize
|
req.PageSize = consts.PageSize
|
||||||
}
|
}
|
||||||
order := "job_id asc"
|
order := "job_id asc"
|
||||||
if req.OrderBy != "" {
|
|
||||||
order = req.OrderBy
|
|
||||||
}
|
|
||||||
var res []*model.SysJobInfoRes
|
var res []*model.SysJobInfoRes
|
||||||
err = m.Fields(system.SysJobSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
err = m.Fields(system.SysJobSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||||
|
@ -29,9 +29,9 @@ func init() {
|
|||||||
|
|
||||||
func New() service.IToolsGenTableColumn {
|
func New() service.IToolsGenTableColumn {
|
||||||
return &sToolsGenTableColumn{
|
return &sToolsGenTableColumn{
|
||||||
ColumnTypeStr: []string{"char", "varchar", "narchar", "varchar2", "tinytext", "text", "mediumtext", "longtext"},
|
ColumnTypeStr: []string{"char", "varchar", "narchar", "varchar2", "tinytext", "text", "mediumtext", "longtext", "character", "character varying", "json", "jsonb"},
|
||||||
ColumnTypeTime: []string{"datetime", "time", "date", "timestamp"},
|
ColumnTypeTime: []string{"datetime", "time", "date", "timestamp"},
|
||||||
ColumnTypeNumber: []string{"tinyint", "smallint", "mediumint", "int", "number", "integer", "bigint", "float", "float", "double", "decimal"},
|
ColumnTypeNumber: []string{"tinyint", "smallint", "mediumint", "int", "number", "integer", "bigint", "float", "float", "double", "decimal", "real", "numeric"},
|
||||||
ColumnNameNotEdit: []string{"created_by", "created_at", "updated_by", "updated_at", "deleted_at", "dept_id"},
|
ColumnNameNotEdit: []string{"created_by", "created_at", "updated_by", "updated_at", "deleted_at", "dept_id"},
|
||||||
ColumnNameNotList: []string{"updated_by", "updated_at", "deleted_at"},
|
ColumnNameNotList: []string{"updated_by", "updated_at", "deleted_at"},
|
||||||
ColumnNameNotDetail: []string{"updated_at", "deleted_at"},
|
ColumnNameNotDetail: []string{"updated_at", "deleted_at"},
|
||||||
@ -65,16 +65,41 @@ func (s *sToolsGenTableColumn) SelectDbTableColumnsByName(ctx context.Context, t
|
|||||||
var res []*entity.ToolsGenTableColumn
|
var res []*entity.ToolsGenTableColumn
|
||||||
err := g.Try(ctx, func(ctx context.Context) {
|
err := g.Try(ctx, func(ctx context.Context) {
|
||||||
db := g.DB()
|
db := g.DB()
|
||||||
|
namespace := db.GetConfig().Namespace
|
||||||
|
if namespace == "" {
|
||||||
|
namespace = "public"
|
||||||
|
}
|
||||||
var sql string
|
var sql string
|
||||||
if service.ToolsGenTable().IsPg() {
|
if service.ToolsGenTable().IsPg() {
|
||||||
//pg数据库
|
//pg数据库
|
||||||
sql = "select c.column_name,(case when c.is_nullable='YES' || k.column_name is not null then '1' else '0' end) as is_required," +
|
sql = "SELECT" +
|
||||||
"(case when k.column_name is not null then '1' else '0' end) as is_pk,c.ordinal_position as sort_order_edit,d.description column_comment," +
|
" a.attname AS column_name," +
|
||||||
"(case when c.column_default like 'nextval%' then '1' else '0' end) as is_increment,c.udt_name as column_type " +
|
" (NOT a.attnotnull OR i.indisprimary::int > 0)::text AS is_required," +
|
||||||
"from information_schema.columns c " +
|
" i.indisprimary::text AS is_pk," +
|
||||||
"left join pg_description d on d.objsubid=c.ordinal_position and d.objoid=c.table_name :: regclass " +
|
" a.attnum AS sort_order_edit," +
|
||||||
"left join information_schema.key_column_usage k on c.table_name=k.table_name and c.column_name=k.column_name and c.table_catalog=k.table_catalog and c.table_schema=k.table_schema "
|
" des.description AS column_comment," +
|
||||||
sql += "where " + gdb.FormatSqlWithArgs(" c.table_name=? ", []interface{}{tableName}) + " order by c.ordinal_position"
|
" (a.atthasdef OR (pg_get_expr(def.adbin, def.adrelid) ~ '^nextval'))::text AS is_increment," +
|
||||||
|
" format_type(a.atttypid, a.atttypmod) AS column_type" +
|
||||||
|
" FROM" +
|
||||||
|
" pg_class t" +
|
||||||
|
" JOIN" +
|
||||||
|
" pg_namespace n ON n.oid = t.relnamespace" +
|
||||||
|
" JOIN" +
|
||||||
|
" pg_attribute a ON a.attrelid = t.oid" +
|
||||||
|
" LEFT JOIN" +
|
||||||
|
" pg_description des ON des.objoid = t.oid AND des.objsubid = a.attnum" +
|
||||||
|
" LEFT JOIN" +
|
||||||
|
" pg_attrdef def ON def.adrelid = t.oid AND def.adnum = a.attnum" +
|
||||||
|
" LEFT JOIN (" +
|
||||||
|
" SELECT " +
|
||||||
|
" indrelid, " +
|
||||||
|
" UNNEST(indkey) AS colidx, " +
|
||||||
|
" indisprimary" +
|
||||||
|
" FROM " +
|
||||||
|
" pg_index" +
|
||||||
|
" ) i ON i.indrelid = t.oid AND i.colidx = a.attnum "
|
||||||
|
sql += " WHERE t.relkind = 'r' AND a.attnum > 0 AND NOT a.attisdropped AND" +
|
||||||
|
gdb.FormatSqlWithArgs(" t.relname = ? AND n.nspname = ? ", []interface{}{tableName, namespace}) + " order by a.attnum"
|
||||||
} else if service.ToolsGenTable().IsDM() {
|
} else if service.ToolsGenTable().IsDM() {
|
||||||
dbName := g.DB().GetSchema()
|
dbName := g.DB().GetSchema()
|
||||||
//达梦数据库
|
//达梦数据库
|
||||||
@ -156,49 +181,8 @@ func (s *sToolsGenTableColumn) InitColumnField(column *entity.ToolsGenTableColum
|
|||||||
column.GoField = gstr.CaseCamel(columnName)
|
column.GoField = gstr.CaseCamel(columnName)
|
||||||
column.HtmlField = gstr.CaseCamelLower(columnName)
|
column.HtmlField = gstr.CaseCamelLower(columnName)
|
||||||
|
|
||||||
if s.IsStringObject(dataType) {
|
//字段类型
|
||||||
//字段为字符串类型
|
column.GoType, column.TsType, column.HtmlType = s.SetFieldType(dataType, column.ColumnType)
|
||||||
column.GoType = "string"
|
|
||||||
column.TsType = "string"
|
|
||||||
columnLength := s.GetColumnLength(column.ColumnType)
|
|
||||||
if columnLength >= 500 {
|
|
||||||
column.HtmlType = "textarea"
|
|
||||||
} else {
|
|
||||||
column.HtmlType = "input"
|
|
||||||
}
|
|
||||||
} else if s.IsTimeObject(dataType) {
|
|
||||||
//字段为时间类型
|
|
||||||
column.GoType = "Time"
|
|
||||||
column.TsType = "string"
|
|
||||||
column.HtmlType = "datetime"
|
|
||||||
} else if s.IsNumberObject(dataType) {
|
|
||||||
//字段为数字类型
|
|
||||||
column.HtmlType = "input"
|
|
||||||
t, _ := gregex.ReplaceString(`\(.+\)`, "", column.ColumnType)
|
|
||||||
t = gstr.Split(gstr.Trim(t), " ")[0]
|
|
||||||
t = gstr.ToLower(t)
|
|
||||||
// 如果是浮点型
|
|
||||||
switch t {
|
|
||||||
case "float", "double", "decimal":
|
|
||||||
column.GoType = "float64"
|
|
||||||
case "bit", "int", "tinyint", "small_int", "smallint", "medium_int", "mediumint":
|
|
||||||
if gstr.ContainsI(column.ColumnType, "unsigned") {
|
|
||||||
column.GoType = "uint"
|
|
||||||
} else {
|
|
||||||
column.GoType = "int"
|
|
||||||
}
|
|
||||||
case "big_int", "bigint":
|
|
||||||
if gstr.ContainsI(column.ColumnType, "unsigned") {
|
|
||||||
column.GoType = "uint64"
|
|
||||||
} else {
|
|
||||||
column.GoType = "int64"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
column.TsType = "number"
|
|
||||||
} else if dataType == "bit" {
|
|
||||||
column.GoType = "bool"
|
|
||||||
column.TsType = "boolean"
|
|
||||||
}
|
|
||||||
|
|
||||||
// 编辑字段
|
// 编辑字段
|
||||||
if s.IsNotEdit(columnName) {
|
if s.IsNotEdit(columnName) {
|
||||||
@ -261,6 +245,54 @@ func (s *sToolsGenTableColumn) InitColumnField(column *entity.ToolsGenTableColum
|
|||||||
column.CascadeColumnName = ""
|
column.CascadeColumnName = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *sToolsGenTableColumn) SetFieldType(sqlType, columnType string) (goType, tsType, htmlType string) {
|
||||||
|
if s.IsStringObject(sqlType) {
|
||||||
|
//字段为字符串类型
|
||||||
|
goType = "string"
|
||||||
|
tsType = "string"
|
||||||
|
columnLength := s.GetColumnLength(columnType)
|
||||||
|
if columnLength >= 500 {
|
||||||
|
htmlType = "textarea"
|
||||||
|
} else {
|
||||||
|
htmlType = "input"
|
||||||
|
}
|
||||||
|
} else if s.IsTimeObject(sqlType) {
|
||||||
|
//字段为时间类型
|
||||||
|
goType = "Time"
|
||||||
|
tsType = "string"
|
||||||
|
htmlType = "datetime"
|
||||||
|
} else if s.IsNumberObject(sqlType) {
|
||||||
|
//字段为数字类型
|
||||||
|
htmlType = "input"
|
||||||
|
t, _ := gregex.ReplaceString(`\(.+\)`, "", columnType)
|
||||||
|
t = gstr.Split(gstr.Trim(t), " ")[0]
|
||||||
|
t = gstr.ToLower(t)
|
||||||
|
// 如果是浮点型
|
||||||
|
switch t {
|
||||||
|
case "float", "double", "decimal", "numeric", "real":
|
||||||
|
goType = "float64"
|
||||||
|
case "bit", "int", "tinyint", "small_int", "smallint", "medium_int", "mediumint", "integer":
|
||||||
|
if gstr.ContainsI(columnType, "unsigned") {
|
||||||
|
goType = "uint"
|
||||||
|
} else {
|
||||||
|
goType = "int"
|
||||||
|
}
|
||||||
|
case "big_int", "bigint":
|
||||||
|
if gstr.ContainsI(columnType, "unsigned") {
|
||||||
|
goType = "uint64"
|
||||||
|
} else {
|
||||||
|
goType = "int64"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tsType = "number"
|
||||||
|
} else if sqlType == "bit" || sqlType == "boolean" || sqlType == "bool" {
|
||||||
|
goType = "bool"
|
||||||
|
tsType = "boolean"
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// GetDbType 获取数据库类型字段
|
// GetDbType 获取数据库类型字段
|
||||||
func (s *sToolsGenTableColumn) GetDbType(columnType string) string {
|
func (s *sToolsGenTableColumn) GetDbType(columnType string) string {
|
||||||
if strings.Index(columnType, "(") > 0 {
|
if strings.Index(columnType, "(") > 0 {
|
||||||
|
@ -9,5 +9,5 @@ package consts
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
Logo = `CiAgIF9fX19fX19fX19fXyAgICAgICAgICAgX18gCiAgLyBfX19fLyBfX19fL19fXyBfX19fX18vIC9fCiAvIC8gX18vIC9fICAvIF9fIGAvIF9fXy8gX18vCi8gL18vIC8gX18vIC8gL18vIChfXyAgKSAvXyAgClxfX19fL18vICAgIFxfXyxfL19fX18vXF9fLyAg`
|
Logo = `CiAgIF9fX19fX19fX19fXyAgICAgICAgICAgX18gCiAgLyBfX19fLyBfX19fL19fXyBfX19fX18vIC9fCiAvIC8gX18vIC9fICAvIF9fIGAvIF9fXy8gX18vCi8gL18vIC8gX18vIC8gL18vIChfXyAgKSAvXyAgClxfX19fL18vICAgIFxfXyxfL19fX18vXF9fLyAg`
|
||||||
Version = "3.3.6"
|
Version = "3.3.7"
|
||||||
)
|
)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
|
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
|
||||||
{{if .table.IsPkInsertable}}
|
{{if .table.IsPkInsertable}}
|
||||||
<el-form-item label="{{.table.PkColumn.ColumnComment}}" prop="{{.table.PkColumn.HtmlField}}">
|
<el-form-item label="{{.table.PkColumn.ColumnComment}}" prop="{{.table.PkColumn.HtmlField}}">
|
||||||
<el-input v-model="formData.{{.table.PkColumn.HtmlField}}" placeholder="请输入{{.table.PkColumn.ColumnComment}}" v-bind:disabled="this.currentOp === 'edit'" />
|
<el-input v-model="formData.{{.table.PkColumn.HtmlField}}" placeholder="请输入{{.table.PkColumn.ColumnComment}}" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{range $index, $column := .table.EditColumns}}
|
{{range $index, $column := .table.EditColumns}}
|
||||||
@ -30,16 +30,16 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
{{else if eq $column.HtmlType "input"}}
|
{{else if eq $column.HtmlType "input"}}
|
||||||
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
|
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
|
||||||
<el-input v-model="formData.{{$column.HtmlField}}" placeholder="请输入{{$column.ColumnComment}}" {{if $column.IsPk}}v-bind:disabled="this.currentOp === 'edit'" {{end}}/>
|
<el-input v-model="formData.{{$column.HtmlField}}" placeholder="请输入{{$column.ColumnComment}}" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
{{else if eq $column.HtmlType "inputNumber"}}
|
{{else if eq $column.HtmlType "inputNumber"}}
|
||||||
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
|
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
|
||||||
<el-input-number v-model="formData.{{$column.HtmlField}}" placeholder="请输入{{$column.ColumnComment}}" {{if $column.IsPk}}v-bind:disabled="this.currentOp === 'edit'" {{end}} />
|
<el-input-number v-model="formData.{{$column.HtmlField}}" placeholder="请输入{{$column.ColumnComment}}" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
{{else if eq $column.HtmlType "select" "selects"}}
|
{{else if eq $column.HtmlType "select" "selects"}}
|
||||||
{{if ne $column.LinkTableName ""}}
|
{{if ne $column.LinkTableName ""}}
|
||||||
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
|
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
|
||||||
<el-select filterable clearable v-model="formData.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" {{if $column.IsPk}}v-bind:disabled="this.currentOp === 'edit'" {{end}} {{if $column.IsCascadeParent}}@change="form{{$column.ColumnName | CaseCamel}}Changed"{{end}} {{if eq $column.HtmlType "selects"}}multiple{{end}}>
|
<el-select filterable clearable v-model="formData.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" {{if $column.IsCascadeParent}}@change="form{{$column.ColumnName | CaseCamel}}Changed"{{end}} {{if eq $column.HtmlType "selects"}}multiple{{end}}>
|
||||||
<el-option
|
<el-option
|
||||||
{{if $column.IsCascade}}
|
{{if $column.IsCascade}}
|
||||||
v-for="item in {{$column.HtmlField}}FormOptions"
|
v-for="item in {{$column.HtmlField}}FormOptions"
|
||||||
@ -54,7 +54,7 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
{{else if ne $column.DictType ""}}
|
{{else if ne $column.DictType ""}}
|
||||||
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
|
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
|
||||||
<el-select filterable clearable v-model="formData.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" {{if $column.IsPk}}v-bind:disabled="this.currentOp === 'edit'" {{end}}>
|
<el-select filterable clearable v-model="formData.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" >
|
||||||
<el-option
|
<el-option
|
||||||
v-for="dict in {{$column.HtmlField}}Options"
|
v-for="dict in {{$column.HtmlField}}Options"
|
||||||
:key="dict.value"
|
:key="dict.value"
|
||||||
@ -69,7 +69,7 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
{{else}}
|
{{else}}
|
||||||
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
|
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
|
||||||
<el-select filterable clearable v-model="formData.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" {{if $column.IsPk}}v-bind:disabled="this.currentOp === 'edit'" {{end}}>
|
<el-select filterable clearable v-model="formData.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" >
|
||||||
<el-option label="请选择字典生成" value="" />
|
<el-option label="请选择字典生成" value="" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user