update:update gen code temp

This commit is contained in:
zhangwenjian committed 2020-08-29 16:32:59 +08:00
1 parent 3063386ec6
commit 77499b50cc
6 files changed
+57 -67

No files matched your search

+2 -2
View File
@@ -20,10 +20,10 @@ func GetSysJobList(c *gin.Context) {
var pageIndex = 1 var pageIndex = 1
if size := c.Request.FormValue("pageSize"); size != "" { if size := c.Request.FormValue("pageSize"); size != "" {
pageSize = tools.StrToInt(err, size) pageSize,err = tools.StringToInt(size)
} }
if index := c.Request.FormValue("pageIndex"); index != "" { if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = tools.StrToInt(err, index) pageIndex,err = tools.StringToInt(index)
} }
var v dto.SysJobSearch var v dto.SysJobSearch
+1 -1
View File
@@ -105,7 +105,7 @@ func GetDictDataByDictType(c *gin.Context) {
// @Security Bearer // @Security Bearer
func InsertDictData(c *gin.Context) { func InsertDictData(c *gin.Context) {
var data models.DictData var data models.DictData
err := c.BindWith(&data, binding.JSON) err := c.ShouldBindJSON(&data)
data.CreateBy = tools.GetUserIdStr(c) data.CreateBy = tools.GetUserIdStr(c)
tools.HasError(err, "", 500) tools.HasError(err, "", 500)
result, err := data.Create() result, err := data.Create()
+1 -1
View File
@@ -15,8 +15,8 @@ require (
github.com/gogf/gf v1.13.4 github.com/gogf/gf v1.13.4
github.com/google/uuid v1.1.1 github.com/google/uuid v1.1.1
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/matchstalk/redisqueue v1.0.3
github.com/matchstalk/go-admin-core v1.0.2 github.com/matchstalk/go-admin-core v1.0.2
github.com/matchstalk/redisqueue v1.0.3
github.com/mojocn/base64Captcha v1.3.1 github.com/mojocn/base64Captcha v1.3.1
github.com/mssola/user_agent v0.5.2 github.com/mssola/user_agent v0.5.2
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
+2
View File
@@ -328,6 +328,7 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA=
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
github.com/mattn/goveralls v0.0.5 h1:spfq8AyZ0cCk57Za6/juJ5btQxeE1FaEGMdfcI+XO48= github.com/mattn/goveralls v0.0.5 h1:spfq8AyZ0cCk57Za6/juJ5btQxeE1FaEGMdfcI+XO48=
github.com/mattn/goveralls v0.0.5/go.mod h1:Xg2LHi51faXLyKXwsndxiW6uxEEQT9+3sjGzzwU4xy0= github.com/mattn/goveralls v0.0.5/go.mod h1:Xg2LHi51faXLyKXwsndxiW6uxEEQT9+3sjGzzwU4xy0=
@@ -676,6 +677,7 @@ gorm.io/driver/mysql v0.3.2/go.mod h1:jC/HyPAZJ0xqfGlOqYybd8oNPMtGrkNgvwjWuKDT7f
gorm.io/driver/postgres v0.2.6/go.mod h1:AsPyuhKFOplSmQwOPsycVKbe0dRxF8v18KZ7p9i8dIs= gorm.io/driver/postgres v0.2.6/go.mod h1:AsPyuhKFOplSmQwOPsycVKbe0dRxF8v18KZ7p9i8dIs=
gorm.io/driver/postgres v0.2.9 h1:oMY4f4tLEUVg3eapqHFzVEplWKy1Gj1cGBEe9wJ1yWM= gorm.io/driver/postgres v0.2.9 h1:oMY4f4tLEUVg3eapqHFzVEplWKy1Gj1cGBEe9wJ1yWM=
gorm.io/driver/postgres v0.2.9/go.mod h1:YATpayFLKALuiVXVRNbDfoEJwECHSMYzl1SmXJ2+CIg= gorm.io/driver/postgres v0.2.9/go.mod h1:YATpayFLKALuiVXVRNbDfoEJwECHSMYzl1SmXJ2+CIg=
gorm.io/driver/sqlite v1.0.9 h1:rqOPFRPY3U5fL5AZSDVa9Np+XpkUbxLVmvpG+i1VHjg=
gorm.io/driver/sqlite v1.0.9/go.mod h1:xkm8/CEmA3yc4zRd0pdCqm43BjO8Hm6avfTpxWb/7c4= gorm.io/driver/sqlite v1.0.9/go.mod h1:xkm8/CEmA3yc4zRd0pdCqm43BjO8Hm6avfTpxWb/7c4=
gorm.io/driver/sqlserver v0.2.4 h1:AGofGL/TfzTZotzIHlaLISfxEKJpzj0ATbtXJW+ga1A= gorm.io/driver/sqlserver v0.2.4 h1:AGofGL/TfzTZotzIHlaLISfxEKJpzj0ATbtXJW+ga1A=
gorm.io/driver/sqlserver v0.2.4/go.mod h1:TcPfkdce5b8qlCMgyUeUdm7HQa1ZzWUuxzI+odcueLA= gorm.io/driver/sqlserver v0.2.4/go.mod h1:TcPfkdce5b8qlCMgyUeUdm7HQa1ZzWUuxzI+odcueLA=
+6 -13
View File
@@ -17,25 +17,18 @@ func Get{{.ClassName}}List(c *gin.Context) {
var pageIndex = 1 var pageIndex = 1
if size := c.Request.FormValue("pageSize"); size != "" { if size := c.Request.FormValue("pageSize"); size != "" {
pageSize = tools.StrToInt(err, size) pageSize, err = tools.StringToInt(size)
} }
if index := c.Request.FormValue("pageIndex"); index != "" { if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = tools.StrToInt(err, index) pageIndex, err = tools.StringToInt(index)
} }
{{ range .Columns -}} var v dto.{{.ClassName}}Search
{{$z := .IsQuery}} err = c.Bind(&v)
{{- if ($z) -}} tools.HasError(err, "数据解析失败", 422)
{{ if eq (.GoType) "int" -}}
data.{{.GoField}}, _ = tools.StringToInt(c.Request.FormValue("{{.JsonField}}"))
{{ else -}}
data.{{.GoField}} = c.Request.FormValue("{{.JsonField}}")
{{ end }}
{{- end -}}
{{end}}
data.DataScope = tools.GetUserIdStr(c) data.DataScope = tools.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex) result, count, err := data.GetPage(pageSize, pageIndex, v)
tools.HasError(err, "", -1) tools.HasError(err, "", -1)
app.PageOK(c, result, count, pageIndex, pageSize, "") app.PageOK(c, result, count, pageIndex, pageSize, "")
+45 -50
View File
@@ -1,16 +1,18 @@
package models package models
import ( import (
orm "go-admin/global" orm "go-admin/global"
"go-admin/tools" "go-admin/tools"
{{$ii := 1}} {{ range .Columns }}
{{ range .Columns }} {{- if eq .GoField "CreatedAt" -}}
{{- if eq .GoType "time.Time" -}}{{- if eq $ii 1 -}} "time" {{$ii = 2}}{{- end}}{{- end}} {{- else if eq .GoField "UpdatedAt" -}}
{{- end }} {{- else if eq .GoField "DeletedAt" -}}
{{- else if eq .GoType "time.Time" -}}"time"{{- end}}
{{- end }}
) )
type {{.ClassName}} struct { type {{.ClassName}} struct {
{{ range .Columns -}} {{ range .Columns -}}
{{$x := .Pk}} {{$x := .Pk}}
{{- if ($x) }} {{- if ($x) }}
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key"` // {{.ColumnComment}} {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key"` // {{.ColumnComment}}
@@ -19,34 +21,34 @@ type {{.ClassName}} struct {
{{- else if eq .GoField "DeletedAt" -}} {{- else if eq .GoField "DeletedAt" -}}
{{- else }} {{- else }}
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};"` // {{.ColumnComment}}{{end -}} {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};"` // {{.ColumnComment}}{{end -}}
{{- end }} {{- end }}
DataScope string `json:"dataScope" gorm:"-"` DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"` Params string `json:"params" gorm:"-"`
BaseModel BaseModel
} }
func ({{.ClassName}}) TableName() string { func ({{.ClassName}}) TableName() string {
return "{{.TBName}}" return "{{.TBName}}"
} }
// 创建{{.ClassName}} // 创建{{.ClassName}}
func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) { func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) {
var doc {{.ClassName}} var doc {{.ClassName}}
result := orm.Eloquent.Table(e.TableName()).Create(&e) result := orm.Eloquent.Table(e.TableName()).Create(&e)
if result.Error != nil { if result.Error != nil {
err := result.Error err := result.Error
return doc, err return doc, err
} }
doc = *e doc = *e
return doc, nil return doc, nil
} }
// 获取{{.ClassName}} // 获取{{.ClassName}}
func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) { func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) {
var doc {{.ClassName}} var doc {{.ClassName}}
table := orm.Eloquent.Table(e.TableName()) table := orm.Eloquent.Table(e.TableName())
{{ range .Columns }} {{ range .Columns }}
{{$x := .Pk}} {{$x := .Pk}}
{{- if ($x) }} {{- if ($x) }}
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} { if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
@@ -57,40 +59,33 @@ table := orm.Eloquent.Table(e.TableName())
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}}) table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
} }
{{ end -}} {{ end -}}
{{- end }} {{- end }}
if err := table.First(&doc).Error; err != nil { if err := table.First(&doc).Error; err != nil {
return doc, err return doc, err
} }
return doc, nil return doc, nil
} }
// 获取{{.ClassName}}带分页 // 获取{{.ClassName}}带分页
func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}}, int, error) { func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int, v interface{}) ([]{{.ClassName}}, int, error) {
var doc []{{.ClassName}} var doc []{{.ClassName}}
table := orm.Eloquent.Table(e.TableName()) table := orm.Eloquent.Table(e.TableName()).Scopes(tools.MakeCondition(v))
{{ range .Columns }}
{{- if .IsQuery }} // 数据权限控制(如果不需要数据权限请将此处去掉)
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} { dataPermission := new(DataPermission)
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}}) dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
table,err := dataPermission.GetDataScope(e.TableName(), table)
if err != nil {
return nil, 0, err
} }
{{ end -}} var count int
{{- end }}
// 数据权限控制(如果不需要数据权限请将此处去掉) if err := table.Scopes(tools.Paginate(pageSize, pageIndex)).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
dataPermission := new(DataPermission) return nil, 0, err
dataPermission.UserId, _ = tools.StringToInt(e.DataScope) }
table,err := dataPermission.GetDataScope(e.TableName(), table) return doc, count, nil
if err != nil {
return nil, 0, err
}
var count int
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
return nil, 0, err
}
return doc, count, nil
} }
// 更新{{.ClassName}} // 更新{{.ClassName}}