refactor(搜索功能): 优化时间范围搜索逻辑,使用createdAtRange替代startCreatedAt和endCreatedAt
将时间范围搜索逻辑从`startCreatedAt`和`endCreatedAt`改为`createdAtRange`,简化代码并提高可维护性。同时更新了相关模板文件和验证规则,确保前后端一致性和用户体验的连贯性。
This commit is contained in:
@@ -14,15 +14,14 @@ package request
|
||||
{{- if not .OnlyTemplate}}
|
||||
import (
|
||||
"{{.Module}}/model/common/request"
|
||||
{{ if or .HasSearchTimer .GvaModel}}"time"{{ end }}
|
||||
{{ if .HasSearchTimer}}"time"{{ end }}
|
||||
)
|
||||
{{- end}}
|
||||
type {{.StructName}}Search struct{
|
||||
{{- if not .OnlyTemplate}}
|
||||
|
||||
{{- if .GvaModel }}
|
||||
StartCreatedAt *time.Time `json:"startCreatedAt" form:"startCreatedAt"`
|
||||
EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"`
|
||||
CreatedAtRange []string `json:"createdAtRange" form:"createdAtRange[]"`
|
||||
{{- end }}
|
||||
{{- range .Fields}}
|
||||
{{- if ne .FieldSearchType ""}}
|
||||
@@ -36,4 +35,4 @@ type {{.StructName}}Search struct{
|
||||
{{- end}}
|
||||
{{- end }}
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
@@ -155,8 +155,8 @@ func (s *{{.Abbreviation}}) Get{{.StructName}}InfoList(ctx context.Context, info
|
||||
var {{.Abbreviation}}s []model.{{.StructName}}
|
||||
// 如果有条件搜索 下方会自动创建搜索语句
|
||||
{{- if .GvaModel }}
|
||||
if info.StartCreatedAt !=nil && info.EndCreatedAt !=nil {
|
||||
db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
|
||||
if info.CreatedAtRange !=nil && len(info.CreatedAtRange) == 2 {
|
||||
db = db.Where("created_at BETWEEN ? AND ?", info.CreatedAtRange[0], info.CreatedAtRange[1])
|
||||
}
|
||||
{{- end }}
|
||||
{{ GenerateSearchConditions .Fields }}
|
||||
|
||||
Reference in New Issue
Block a user