优化模版生成
This commit is contained in:
1 parent
91f2adb340
commit
6bc3e6c00b
12 files changed
+53
-50
No files matched your search
@@ -10,14 +10,14 @@ import (
|
||||
|
||||
type SysDept struct {
|
||||
DeptId int `json:"deptId" gorm:"primary_key;auto_increment;"` //部门编码
|
||||
ParentId int `json:"parentId" gorm:""` //上级部门
|
||||
DeptPath string `json:"deptPath" gorm:"size:255;"` //
|
||||
DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
|
||||
Sort int `json:"sort" gorm:""` //排序
|
||||
Leader string `json:"leader" gorm:"size:128;"` //负责人
|
||||
Phone string `json:"phone" gorm:"size:11;"` //手机
|
||||
Email string `json:"email" gorm:"size:64;"` //邮箱
|
||||
Status string `json:"status" gorm:"size:4;"` //状态
|
||||
ParentId int `json:"parentId" gorm:""` //上级部门
|
||||
DeptPath string `json:"deptPath" gorm:"size:255;"` //
|
||||
DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
|
||||
Sort int `json:"sort" gorm:""` //排序
|
||||
Leader string `json:"leader" gorm:"size:128;"` //负责人
|
||||
Phone string `json:"phone" gorm:"size:11;"` //手机
|
||||
Email string `json:"email" gorm:"size:64;"` //邮箱
|
||||
Status string `json:"status" gorm:"size:4;"` //状态
|
||||
CreateBy string `json:"createBy" gorm:"size:64;"`
|
||||
UpdateBy string `json:"updateBy" gorm:"size:64;"`
|
||||
DataScope string `json:"dataScope" gorm:"-"`
|
||||
|
||||
@@ -9,18 +9,18 @@ import (
|
||||
|
||||
type DictData struct {
|
||||
DictCode int `gorm:"primary_key;auto_increment;" json:"dictCode" example:"1"` //字典编码
|
||||
DictSort int `gorm:"" json:"dictSort"` //显示顺序
|
||||
DictLabel string `gorm:"size:128;" json:"dictLabel"` //数据标签
|
||||
DictValue string `gorm:"size:255;" json:"dictValue"` //数据键值
|
||||
DictType string `gorm:"size:64;" json:"dictType"` //字典类型
|
||||
CssClass string `gorm:"size:128;" json:"cssClass"` //
|
||||
ListClass string `gorm:"size:128;" json:"listClass"` //
|
||||
IsDefault string `gorm:"size:8;" json:"isDefault"` //
|
||||
Status string `gorm:"size:4;" json:"status"` //状态
|
||||
Default string `gorm:"size:8;" json:"default"` //
|
||||
CreateBy string `gorm:"size:64;" json:"createBy"` //
|
||||
UpdateBy string `gorm:"size:64;" json:"updateBy"` //
|
||||
Remark string `gorm:"size:255;" json:"remark"` //备注
|
||||
DictSort int `gorm:"" json:"dictSort"` //显示顺序
|
||||
DictLabel string `gorm:"size:128;" json:"dictLabel"` //数据标签
|
||||
DictValue string `gorm:"size:255;" json:"dictValue"` //数据键值
|
||||
DictType string `gorm:"size:64;" json:"dictType"` //字典类型
|
||||
CssClass string `gorm:"size:128;" json:"cssClass"` //
|
||||
ListClass string `gorm:"size:128;" json:"listClass"` //
|
||||
IsDefault string `gorm:"size:8;" json:"isDefault"` //
|
||||
Status string `gorm:"size:4;" json:"status"` //状态
|
||||
Default string `gorm:"size:8;" json:"default"` //
|
||||
CreateBy string `gorm:"size:64;" json:"createBy"` //
|
||||
UpdateBy string `gorm:"size:64;" json:"updateBy"` //
|
||||
Remark string `gorm:"size:255;" json:"remark"` //备注
|
||||
Params string `gorm:"-" json:"params"`
|
||||
DataScope string `gorm:"-" json:"dataScope"`
|
||||
BaseModel
|
||||
|
||||
@@ -12,15 +12,15 @@ import (
|
||||
|
||||
func InitDb(db *gorm.DB) (err error) {
|
||||
filePath := "config/db.sql"
|
||||
err = ExecSql(db,filePath)
|
||||
err = ExecSql(db, filePath)
|
||||
if global.Driver == "postgres" {
|
||||
filePath = "config/pg.sql"
|
||||
err = ExecSql(db,filePath)
|
||||
err = ExecSql(db, filePath)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func ExecSql(db *gorm.DB,filePath string) error {
|
||||
func ExecSql(db *gorm.DB, filePath string) error {
|
||||
sql, err := Ioutil(filePath)
|
||||
if err != nil {
|
||||
fmt.Println("数据库基础数据初始化脚本读取失败!原因:", err.Error())
|
||||
|
||||
@@ -8,19 +8,19 @@ import (
|
||||
|
||||
type LoginLog struct {
|
||||
InfoId int `json:"infoId" gorm:"primary_key;auto_increment;"` //主键
|
||||
Username string `json:"username" gorm:"size:128;"` //用户名
|
||||
Status string `json:"status" gorm:"size:4;"` //状态
|
||||
Ipaddr string `json:"ipaddr" gorm:"size:255;"` //ip地址
|
||||
LoginLocation string `json:"loginLocation" gorm:"size:255;"` //归属地
|
||||
Browser string `json:"browser" gorm:"size:255;"` //浏览器
|
||||
Os string `json:"os" gorm:"size:255;"` //系统
|
||||
Platform string `json:"platform" gorm:"size:255;"` // 固件
|
||||
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;"` //登录时间
|
||||
CreateBy string `json:"createBy" gorm:"size:128;"` //创建人
|
||||
UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者
|
||||
DataScope string `json:"dataScope" gorm:"-"` //数据
|
||||
Params string `json:"params" gorm:"-"` //
|
||||
Remark string `json:"remark" gorm:"size:255;"` //备注
|
||||
Username string `json:"username" gorm:"size:128;"` //用户名
|
||||
Status string `json:"status" gorm:"size:4;"` //状态
|
||||
Ipaddr string `json:"ipaddr" gorm:"size:255;"` //ip地址
|
||||
LoginLocation string `json:"loginLocation" gorm:"size:255;"` //归属地
|
||||
Browser string `json:"browser" gorm:"size:255;"` //浏览器
|
||||
Os string `json:"os" gorm:"size:255;"` //系统
|
||||
Platform string `json:"platform" gorm:"size:255;"` // 固件
|
||||
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;"` //登录时间
|
||||
CreateBy string `json:"createBy" gorm:"size:128;"` //创建人
|
||||
UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者
|
||||
DataScope string `json:"dataScope" gorm:"-"` //数据
|
||||
Params string `json:"params" gorm:"-"` //
|
||||
Remark string `json:"remark" gorm:"size:255;"` //备注
|
||||
Msg string `json:"msg" gorm:"size:255;"`
|
||||
BaseModel
|
||||
}
|
||||
|
||||
@@ -47,10 +47,10 @@ type SysJobControl struct {
|
||||
CronExpression string `json:"cronExpression"` // cron表达式
|
||||
InvokeTarget string `json:"invokeTarget"` // 调用目标
|
||||
Args string `json:"args"` // 目标参数
|
||||
MisfirePolicy int `json:"misfirePolicy"` // 执行策略
|
||||
MisfirePolicy int `json:"misfirePolicy"` // 执行策略
|
||||
Concurrent int `json:"concurrent"` // 是否并发
|
||||
Status int `json:"status"` // 状态
|
||||
EntryId int `json:"entryId"` // job启动时返回的id
|
||||
EntryId int `json:"entryId"` // job启动时返回的id
|
||||
}
|
||||
|
||||
func (s *SysJobControl) Bind(ctx *gin.Context) error {
|
||||
|
||||
@@ -40,6 +40,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
|
||||
github.com/bsm/redislock v0.5.0 h1:ODM11/cbuUXQqLgZWK6XQnufaTjsBE2UcwBc2EAFNDA=
|
||||
github.com/bsm/redislock v0.5.0/go.mod h1:qagqKlV+xiLy26iV34Y3zRPxRcJjQYbV7pZfWFeSZ8M=
|
||||
github.com/casbin/casbin/v2 v2.2.2/go.mod h1:XXtYGrs/0zlOsJMeRteEdVi/FsB0ph7KgNfjoCoJUD8=
|
||||
github.com/casbin/casbin/v2 v2.11.2 h1:kdJ3ZMfPtz6uzKwAaW4G4NIld0U2KeHrgFcEhi40evc=
|
||||
@@ -111,8 +112,10 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
|
||||
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
|
||||
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
|
||||
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
|
||||
github.com/go-redis/redis v6.15.7+incompatible h1:3skhDh95XQMpnqeqNftPkQD9jL9e5e36z/1SUm6dy1U=
|
||||
github.com/go-redis/redis v6.15.7+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
|
||||
github.com/go-redis/redis/v7 v7.2.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
|
||||
github.com/go-redis/redis/v7 v7.4.0 h1:7obg6wUoj05T0EpY0o8B59S9w5yeMWql7sw2kwNW1x4=
|
||||
github.com/go-redis/redis/v7 v7.4.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
|
||||
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
|
||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
@@ -279,6 +282,7 @@ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/matchstalk/go-admin-core v1.2.0 h1:yk8bnH7dVGDgyEliG2MchSyupdh24wc0sDUrxnu8sGY=
|
||||
github.com/matchstalk/go-admin-core v1.2.0/go.mod h1:iCxDnmPHR3+d/5Q+yrdt+QBXhmWhbj7+GeHcUjD9Rn8=
|
||||
github.com/matchstalk/redisqueue v1.0.3 h1:ZRrEhnvA6/YxLu2EbzdZYeQHQQYT8yZBAi1qv/USEQA=
|
||||
github.com/matchstalk/redisqueue v1.0.3/go.mod h1:5DZ3X4w9t+6Wv9vz9wmUt/i15gsOorGXRnqzGhBP6zI=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
||||
|
||||
@@ -27,7 +27,7 @@ m = r.sub == p.sub && (keyMatch2(r.obj, p.obj) || keyMatch(r.obj, p.obj)) && (r.
|
||||
`
|
||||
|
||||
func Setup() {
|
||||
Apter, err := gormAdapter.NewAdapterByDBUsePrefix(global.Eloquent,"sys_")
|
||||
Apter, err := gormAdapter.NewAdapterByDBUsePrefix(global.Eloquent, "sys_")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -46,12 +46,13 @@ type {{.ClassName}}Control struct {
|
||||
{{ range .Columns -}}
|
||||
{{$x := .Pk}}
|
||||
{{- if ($x) }}
|
||||
{{.GoField}} uint `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"` // {{.ColumnComment}}
|
||||
{{.GoField}} uint `uri:"{{.JsonField}}" comment:"{{.ColumnComment}}"` // {{.ColumnComment}}
|
||||
{{- else if eq .GoField "CreatedAt" -}}
|
||||
{{- else if eq .GoField "UpdatedAt" -}}
|
||||
{{- else if eq .GoField "DeletedAt" -}}
|
||||
{{- else if eq .GoField "CreateBy" -}}
|
||||
{{- else if eq .GoField "UpdateBy" -}}
|
||||
|
||||
{{.GoField}} uint `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
|
||||
{{- else }}
|
||||
|
||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
|
||||
@@ -60,6 +61,9 @@ type {{.ClassName}}Control struct {
|
||||
}
|
||||
|
||||
func (s *{{.ClassName}}Control) Bind(ctx *gin.Context) error {
|
||||
if err := ctx.BindUri(s); err != nil {
|
||||
return err
|
||||
}
|
||||
return ctx.Bind(s)
|
||||
}
|
||||
|
||||
@@ -78,10 +82,7 @@ func (s *{{.ClassName}}Control) GenerateM() (common.ActiveRecord, error) {
|
||||
{{- else if eq .GoField "UpdatedAt" -}}
|
||||
{{- else if eq .GoField "DeletedAt" -}}
|
||||
{{- else if eq .GoField "CreateBy" -}}
|
||||
ControlBy: common.ControlBy{
|
||||
CreateBy: s.CreateBy,
|
||||
UpdateBy: s.UpdateBy,
|
||||
},
|
||||
|
||||
|
||||
{{- else if eq .GoField "UpdateBy" -}}
|
||||
{{- else }}
|
||||
|
||||
@@ -27,8 +27,6 @@ type {{.ClassName}} struct {
|
||||
{{- else }}
|
||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};comment:{{- if eq .ColumnComment "" -}}{{.GoField}}{{- else -}}{{.ColumnComment}}{{end -}}"` // {{end -}}
|
||||
{{- end }}
|
||||
DataScope string `json:"dataScope" gorm:"-"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
}
|
||||
|
||||
func ({{.ClassName}}) TableName() string {
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
<el-table-column type="selection" width="55" align="center"/>
|
||||
{{- range .Columns -}}
|
||||
{{- $x := .IsList -}}
|
||||
{{- if ($x) }}
|
||||
{{- if (eq $x "1") }}
|
||||
{{- if ne .FkTableName "" -}}
|
||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}" :formatter="{{.JsonField}}Format" width="100">
|
||||
<template slot-scope="scope">
|
||||
|
||||
+1
-1
@@ -24,4 +24,4 @@ func (res *Response) ReturnOK() *Response {
|
||||
func (res *Response) ReturnError(code int) *Response {
|
||||
res.Code = code
|
||||
return res
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -53,7 +53,7 @@ func HasError(err error, msg string, code ...int) {
|
||||
msg = err.Error()
|
||||
}
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
log.Printf("%s:%v",file, line)
|
||||
log.Printf("%s:%v", file, line)
|
||||
panic("CustomError#" + strconv.Itoa(statusCode) + "#" + msg)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user