Skip to content

Commit a625555

Browse files
pixelmaxQmhuiyifyjpiexlMax(奇淼okppopjoohwan
authored
发布2.8.1 beta版本 (#2014)
AI: 增加了AI前端绘制功能,可以根据描述生成客户端页面【授权用户专属】
 自动化: 自动化模板采用了function模式,更加方便用户二次开发和自定义改动
 自动化: 默认携带ID和CreatedAt排序
 自动化: 所有自动化Select模板默认支持select搜索
 优化:http交互报错信息增加防止多次弹出错误遮罩机制
 ICON: 优化ICON逻辑,防止多次加载svg
 布局:增加侧边分栏模式 布局: 顶栏模式样式优化和高亮逻辑调整 优化: 个人配置不再需要手动点击保存,会根据变化自动保存
 BUG: 修复了菜单点击设为主页勾选被取消的bug 安全: 更新了jwt版本,修复CVE-2025-30204 导出: 默认支持软删除过滤 代码: 优化了部分代码逻辑 本次更新需要重新执行 npm i --------- Signed-off-by: joohwan <[email protected] > Co-authored-by: huiyifyj <[email protected]> Co-authored-by: piexlMax(奇淼 <[email protected]> Co-authored-by: okppop <[email protected]> Co-authored-by: joohwan <[email protected] > Co-authored-by: xuedinge <[email protected]>
1 parent 84a3c3b commit a625555

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2454
-2825
lines changed

Diff for: server/api/v1/system/sys_user.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,13 @@ func (b *BaseApi) GetUserInfo(c *gin.Context) {
467467
// @Success 200 {object} response.Response{msg=string} "重置用户密码"
468468
// @Router /user/resetPassword [post]
469469
func (b *BaseApi) ResetPassword(c *gin.Context) {
470-
var user system.SysUser
471-
err := c.ShouldBindJSON(&user)
470+
var rps systemReq.ResetPassword
471+
err := c.ShouldBindJSON(&rps)
472472
if err != nil {
473473
response.FailWithMessage(err.Error(), c)
474474
return
475475
}
476-
err = userService.ResetPassword(user.ID)
476+
err = userService.ResetPassword(rps.ID, rps.Password)
477477
if err != nil {
478478
global.GVA_LOG.Error("重置失败!", zap.Error(err))
479479
response.FailWithMessage("重置失败"+err.Error(), c)

Diff for: server/core/viper.go

+42-37
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,26 @@ package core
33
import (
44
"flag"
55
"fmt"
6-
"github.com/flipped-aurora/gin-vue-admin/server/core/internal"
7-
"github.com/gin-gonic/gin"
86
"os"
97
"path/filepath"
108

9+
"github.com/flipped-aurora/gin-vue-admin/server/core/internal"
10+
"github.com/flipped-aurora/gin-vue-admin/server/global"
1111
"github.com/fsnotify/fsnotify"
12+
"github.com/gin-gonic/gin"
1213
"github.com/spf13/viper"
13-
14-
"github.com/flipped-aurora/gin-vue-admin/server/global"
1514
)
1615

17-
// Viper //
18-
// 优先级: 命令行 > 环境变量 > 默认值
19-
// Author [SliverHorn](https://github.com/SliverHorn)
20-
func Viper(path ...string) *viper.Viper {
21-
var config string
22-
23-
if len(path) == 0 {
24-
flag.StringVar(&config, "c", "", "choose config file.")
25-
flag.Parse()
26-
if config == "" { // 判断命令行参数是否为空
27-
if configEnv := os.Getenv(internal.ConfigEnv); configEnv == "" { // 判断 internal.ConfigEnv 常量存储的环境变量是否为空
28-
switch gin.Mode() {
29-
case gin.DebugMode:
30-
config = internal.ConfigDefaultFile
31-
case gin.ReleaseMode:
32-
config = internal.ConfigReleaseFile
33-
case gin.TestMode:
34-
config = internal.ConfigTestFile
35-
}
36-
fmt.Printf("您正在使用gin模式的%s环境名称,config的路径为%s\n", gin.Mode(), config)
37-
} else { // internal.ConfigEnv 常量存储的环境变量不为空 将值赋值于config
38-
config = configEnv
39-
fmt.Printf("您正在使用%s环境变量,config的路径为%s\n", internal.ConfigEnv, config)
40-
}
41-
} else { // 命令行参数不为空 将值赋值于config
42-
fmt.Printf("您正在使用命令行的-c参数传递的值,config的路径为%s\n", config)
43-
}
44-
} else { // 函数传递的可变参数的第一个值赋值于config
45-
config = path[0]
46-
fmt.Printf("您正在使用func Viper()传递的值,config的路径为%s\n", config)
47-
}
16+
// Viper 配置
17+
func Viper() *viper.Viper {
18+
config := getConfigPath()
4819

4920
v := viper.New()
5021
v.SetConfigFile(config)
5122
v.SetConfigType("yaml")
5223
err := v.ReadInConfig()
5324
if err != nil {
54-
panic(fmt.Errorf("Fatal error config file: %s \n", err))
25+
panic(fmt.Errorf("fatal error config file: %w", err))
5526
}
5627
v.WatchConfig()
5728

@@ -62,10 +33,44 @@ func Viper(path ...string) *viper.Viper {
6233
}
6334
})
6435
if err = v.Unmarshal(&global.GVA_CONFIG); err != nil {
65-
panic(err)
36+
panic(fmt.Errorf("fatal error unmarshal config: %w", err))
6637
}
6738

6839
// root 适配性 根据root位置去找到对应迁移位置,保证root路径有效
6940
global.GVA_CONFIG.AutoCode.Root, _ = filepath.Abs("..")
7041
return v
7142
}
43+
44+
// getConfigPath 获取配置文件路径, 优先级: 命令行 > 环境变量 > 默认值
45+
func getConfigPath() (config string) {
46+
// `-c` flag parse
47+
flag.StringVar(&config, "c", "", "choose config file.")
48+
flag.Parse()
49+
if config != "" { // 命令行参数不为空 将值赋值于config
50+
fmt.Printf("您正在使用命令行的 '-c' 参数传递的值, config 的路径为 %s\n", config)
51+
return
52+
}
53+
if env := os.Getenv(internal.ConfigEnv); env != "" { // 判断环境变量 GVA_CONFIG
54+
config = env
55+
fmt.Printf("您正在使用 %s 环境变量, config 的路径为 %s\n", internal.ConfigEnv, config)
56+
return
57+
}
58+
59+
switch gin.Mode() { // 根据 gin 模式文件名
60+
case gin.DebugMode:
61+
config = internal.ConfigDebugFile
62+
case gin.ReleaseMode:
63+
config = internal.ConfigReleaseFile
64+
case gin.TestMode:
65+
config = internal.ConfigTestFile
66+
}
67+
fmt.Printf("您正在使用 gin 的 %s 模式运行, config 的路径为 %s\n", gin.Mode(), config)
68+
69+
_, err := os.Stat(config)
70+
if err != nil || os.IsNotExist(err) {
71+
config = internal.ConfigDefaultFile
72+
fmt.Printf("配置文件路径不存在, 使用默认配置文件路径: %s\n", config)
73+
}
74+
75+
return
76+
}

Diff for: server/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/glebarez/sqlite v1.11.0
1414
github.com/go-sql-driver/mysql v1.8.1
1515
github.com/goccy/go-json v0.10.4
16-
github.com/golang-jwt/jwt/v5 v5.2.1
16+
github.com/golang-jwt/jwt/v5 v5.2.2
1717
github.com/google/uuid v1.6.0
1818
github.com/gookit/color v1.5.4
1919
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.24.9+incompatible

Diff for: server/go.sum

+2-3
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,11 @@ github.com/goccy/go-json v0.10.4/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PU
167167
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
168168
github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E=
169169
github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0=
170-
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
171-
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
172170
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
173171
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
174-
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
175172
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
173+
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
174+
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
176175
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
177176
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
178177
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=

Diff for: server/initialize/router.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func Routers() *gin.Engine {
4646
// VUE_APP_BASE_API = /
4747
// VUE_APP_BASE_PATH = http://localhost
4848
// 然后执行打包命令 npm run build。在打开下面3行注释
49-
// Router.Static("/favicon.ico", "./dist/favicon.ico")
49+
// Router.StaticFile("/favicon.ico", "./dist/favicon.ico")
5050
// Router.Static("/assets", "./dist/assets") // dist里面的静态资源
5151
// Router.StaticFile("/", "./dist/index.html") // 前端网页入口页面
5252

Diff for: server/model/system/request/sys_user.go

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ type ChangePasswordReq struct {
3333
NewPassword string `json:"newPassword"` // 新密码
3434
}
3535

36+
type ResetPassword struct {
37+
ID uint `json:"ID" form:"ID"`
38+
Password string `json:"password" form:"password" gorm:"comment:用户登录密码"` // 用户登录密码
39+
}
40+
3641
// SetUserAuth Modify user's auth structure
3742
type SetUserAuth struct {
3843
AuthorityId uint `json:"authorityId"` // 角色ID

Diff for: server/resource/package/server/model/model.go.tpl

+2-38
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
11
{{- if .IsAdd}}
22
// 在结构体中新增如下字段
33
{{- range .Fields}}
4-
{{- if eq .FieldType "enum" }}
5-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};type:enum({{.DataTypeLong}});comment:{{.Comment}};" {{- if .Require }} binding:"required"{{- end -}}`
6-
{{- else if eq .FieldType "picture" }}
7-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
8-
{{- else if eq .FieldType "video" }}
9-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
10-
{{- else if eq .FieldType "file" }}
11-
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end }} swaggertype:"array,object"`
12-
{{- else if eq .FieldType "pictures" }}
13-
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end }} swaggertype:"array,object"`
14-
{{- else if eq .FieldType "richtext" }}
15-
{{.FieldName}} *string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end -}}`
16-
{{- else if eq .FieldType "json" }}
17-
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end }} swaggertype:"object"`
18-
{{- else if eq .FieldType "array" }}
19-
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end }} swaggertype:"array,object"`
20-
{{- else }}
21-
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
22-
{{- end }} {{ if .FieldDesc }}//{{.FieldDesc}}{{ end }}
4+
{{ GenerateField . }}
235
{{- end }}
246

257
{{ else }}
@@ -47,25 +29,7 @@ type {{.StructName}} struct {
4729
global.GVA_MODEL
4830
{{- end }}
4931
{{- range .Fields}}
50-
{{- if eq .FieldType "enum" }}
51-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};type:enum({{.DataTypeLong}});comment:{{.Comment}};" {{- if .Require }} binding:"required"{{- end -}}`
52-
{{- else if eq .FieldType "picture" }}
53-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
54-
{{- else if eq .FieldType "video" }}
55-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
56-
{{- else if eq .FieldType "file" }}
57-
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end }} swaggertype:"array,object"`
58-
{{- else if eq .FieldType "pictures" }}
59-
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end }} swaggertype:"array,object"`
60-
{{- else if eq .FieldType "richtext" }}
61-
{{.FieldName}} *string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end -}}`
62-
{{- else if eq .FieldType "json" }}
63-
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end }} swaggertype:"object"`
64-
{{- else if eq .FieldType "array" }}
65-
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end }} swaggertype:"array,object"`
66-
{{- else }}
67-
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
68-
{{- end }} {{ if .FieldDesc }}//{{.FieldDesc}}{{ end }}
32+
{{ GenerateField . }}
6933
{{- end }}
7034
{{- if .AutoCreateResource }}
7135
CreatedBy uint `gorm:"column:created_by;comment:创建者"`

Diff for: server/resource/package/server/service/service.go.tpl

+6-44
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,7 @@
88
{{- if .IsAdd}}
99

1010
// Get{{.StructName}}InfoList 新增搜索语句
11-
{{- range .Fields}}
12-
{{- if .FieldSearchType}}
13-
{{- if or (eq .FieldType "enum") (eq .FieldType "pictures") (eq .FieldType "picture") (eq .FieldType "video") (eq .FieldType "json") }}
14-
if info.{{.FieldName}} != "" {
15-
{{- if or (eq .FieldType "enum") }}
16-
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+ {{ end }}*info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
17-
{{- else}}
18-
// 数据类型为复杂类型,请根据业务需求自行实现复杂类型的查询业务
19-
{{- end}}
20-
}
21-
{{- else if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}}
22-
if info.Start{{.FieldName}} != nil && info.End{{.FieldName}} != nil {
23-
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ? AND ? ",info.Start{{.FieldName}},info.End{{.FieldName}})
24-
}
25-
{{- else}}
26-
if info.{{.FieldName}} != nil{{- if eq .FieldType "string" }} && *info.{{.FieldName}} != ""{{- end }} {
27-
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}*info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
28-
}
29-
{{- end }}
30-
{{- end }}
31-
{{- end }}
32-
33-
11+
{{ GenerateSearchConditions .Fields }}
3412
// Get{{.StructName}}InfoList 新增排序语句 请自行在搜索语句中添加orderMap内容
3513
{{- range .Fields}}
3614
{{- if .Sort}}
@@ -174,34 +152,18 @@ func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoLis
174152
db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
175153
}
176154
{{- end }}
177-
{{- range .Fields}}
178-
{{- if .FieldSearchType}}
179-
{{- if or (eq .FieldType "enum") (eq .FieldType "pictures") (eq .FieldType "picture") (eq .FieldType "video") (eq .FieldType "json") }}
180-
if info.{{.FieldName}} != "" {
181-
{{- if or (eq .FieldType "enum")}}
182-
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+ {{ end }}*info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
183-
{{- else}}
184-
// 数据类型为复杂类型,请根据业务需求自行实现复杂类型的查询业务
185-
{{- end}}
186-
}
187-
{{- else if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}}
188-
if info.Start{{.FieldName}} != nil && info.End{{.FieldName}} != nil {
189-
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ? AND ? ",info.Start{{.FieldName}},info.End{{.FieldName}})
190-
}
191-
{{- else}}
192-
if info.{{.FieldName}} != nil{{- if eq .FieldType "string" }} && *info.{{.FieldName}} != ""{{- end }} {
193-
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}*info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
194-
}
195-
{{- end }}
196-
{{- end }}
197-
{{- end }}
155+
{{ GenerateSearchConditions .Fields }}
198156
err = db.Count(&total).Error
199157
if err!=nil {
200158
return
201159
}
202160
{{- if .NeedSort}}
203161
var OrderStr string
204162
orderMap := make(map[string]bool)
163+
{{- if .GvaModel }}
164+
orderMap["ID"] = true
165+
orderMap["CreatedAt"] = true
166+
{{- end }}
205167
{{- range .Fields}}
206168
{{- if .Sort}}
207169
orderMap["{{.ColumnName}}"] = true

0 commit comments

Comments
 (0)