mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 18:20:50 +00:00
feat✨优化字典数据错误判断写法
This commit is contained in:
committed by
wenjianzhang
parent
c6d94c03fb
commit
c6a52134b3
@@ -1,104 +0,0 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"errors"
|
||||
vd "github.com/bytedance/go-tagexpr/v2/validator"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/common/dto"
|
||||
common "go-admin/common/models"
|
||||
)
|
||||
|
||||
type SysCategorySearch struct {
|
||||
dto.Pagination `search:"-"`
|
||||
Name string `form:"name" search:"type:exact;column:name;table:sys_category" comment:"名称" vd:"?"`
|
||||
Status string `form:"status" search:"type:exact;column:status;table:sys_category" comment:"状态" vd:"?"`
|
||||
CateId int `form:"cateId" search:"type:exact;column:cate_id;table:sys_category" comment:"分类id" vd:"?"`
|
||||
}
|
||||
|
||||
func (m *SysCategorySearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
func (m *SysCategorySearch) Bind(ctx *gin.Context) error {
|
||||
log := api.GetRequestLogger(ctx)
|
||||
|
||||
err := ctx.ShouldBind(m)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBind error: %s", err.Error())
|
||||
}
|
||||
|
||||
if err = vd.Validate(m); err != nil {
|
||||
log.Errorf("Validate error: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *SysCategorySearch) Generate() dto.Index {
|
||||
o := *m
|
||||
return &o
|
||||
}
|
||||
|
||||
type SysCategoryControl struct {
|
||||
ID int `uri:"Id" comment:"标识"`
|
||||
Name string `json:"name" comment:"名称" vd:"len($)>0 && $!=' '; msg:'invalid name: 不能是空字符串'"`
|
||||
Img string `json:"img" comment:"图标" vd:"?"`
|
||||
Sort int `json:"sort" comment:"排序" vd:"?"`
|
||||
Status int `json:"status" comment:"状态" vd:"$>0; msg:'invalid status: 状态无效'"`
|
||||
Remark string `json:"remark" comment:"备注" vd:"?"`
|
||||
}
|
||||
|
||||
func (s *SysCategoryControl) Bind(ctx *gin.Context) error {
|
||||
log := api.GetRequestLogger(ctx)
|
||||
err := ctx.ShouldBindUri(s)
|
||||
if err != nil {
|
||||
log.Errorf("ShouldBindUri error: %s", err.Error())
|
||||
return errors.New("数据绑定出错")
|
||||
}
|
||||
err = ctx.ShouldBind(s)
|
||||
if err != nil {
|
||||
log.Errorf("ShouldBind error: %s", err.Error())
|
||||
err = errors.New("数据绑定出错")
|
||||
}
|
||||
if err1 := vd.Validate(s); err != nil {
|
||||
log.Errorf("Validate error: %s", err1.Error())
|
||||
return err1
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SysCategoryControl) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *SysCategoryControl) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.SysCategory{
|
||||
Model: common.Model{Id: s.ID},
|
||||
Name: s.Name,
|
||||
Img: s.Img,
|
||||
Sort: s.Sort,
|
||||
Status: s.Status,
|
||||
Remark: s.Remark,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *SysCategoryControl) GetId() interface{} {
|
||||
return s.ID
|
||||
}
|
||||
|
||||
type SysCategoryById struct {
|
||||
dto.ObjectById `vd:"?"`
|
||||
}
|
||||
|
||||
func (s *SysCategoryById) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *SysCategoryById) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.SysCategory{}, nil
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/common/dto"
|
||||
common "go-admin/common/models"
|
||||
)
|
||||
|
||||
type SysContentSearch struct {
|
||||
dto.Pagination `search:"-"`
|
||||
Name string `form:"name" search:"type:exact;column:name;table:sys_category" comment:"名称"`
|
||||
Status string `form:"status" search:"type:exact;column:status;table:sys_category" comment:"状态"`
|
||||
}
|
||||
|
||||
func (m *SysContentSearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
func (m *SysContentSearch) Bind(ctx *gin.Context) error {
|
||||
log := api.GetRequestLogger(ctx)
|
||||
err := ctx.ShouldBind(m)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBind error: %s", err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *SysContentSearch) Generate() dto.Index {
|
||||
o := *m
|
||||
return &o
|
||||
}
|
||||
|
||||
type SysContentControl struct {
|
||||
ID int `uri:"ID" comment:""` //
|
||||
CateId int `json:"cateId" comment:""`
|
||||
Name string `json:"name" comment:""`
|
||||
Status int `json:"status" comment:""`
|
||||
Img string `json:"img" comment:""`
|
||||
Content string `json:"content" comment:""`
|
||||
Remark string `json:"remark" comment:""`
|
||||
Sort int `json:"sort" comment:""`
|
||||
}
|
||||
|
||||
func (s *SysContentControl) Bind(ctx *gin.Context) error {
|
||||
log := api.GetRequestLogger(ctx)
|
||||
err := ctx.ShouldBindUri(s)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBindUri error: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
err = ctx.ShouldBind(s)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBind error: %s", err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SysContentControl) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *SysContentControl) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.SysContent{
|
||||
Model: common.Model{s.ID},
|
||||
CateId: s.CateId,
|
||||
Name: s.Name,
|
||||
Status: s.Status,
|
||||
Img: s.Img,
|
||||
Content: s.Content,
|
||||
Remark: s.Remark,
|
||||
Sort: s.Sort,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *SysContentControl) GetId() interface{} {
|
||||
return s.ID
|
||||
}
|
||||
|
||||
type SysContentById struct {
|
||||
dto.ObjectById
|
||||
}
|
||||
|
||||
func (s *SysContentById) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *SysContentById) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.SysContent{}, nil
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/common/dto"
|
||||
common "go-admin/common/models"
|
||||
)
|
||||
|
||||
type SysFileDirSearch struct {
|
||||
dto.Pagination `search:"-"`
|
||||
|
||||
ID int `form:"Id" search:"type:exact;column:id;table:sys_file_dir" comment:"标识"`
|
||||
Label string `form:"label" search:"type:exact;column:label;table:sys_file_dir" comment:"目录名称"`
|
||||
PId string `form:"pId" search:"type:exact;column:p_id;table:sys_file_dir" comment:"上级目录"`
|
||||
//Sort string `form:"sort" search:"type:exact;column:sort;table:sys_file_dir" comment:"排序"`
|
||||
Path string `form:"path" search:"type:exact;column:path;table:sys_file_dir" comment:"路径"`
|
||||
}
|
||||
|
||||
func (m *SysFileDirSearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
func (m *SysFileDirSearch) Bind(ctx *gin.Context) error {
|
||||
log := api.GetRequestLogger(ctx)
|
||||
err := ctx.ShouldBind(m)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBind error: %s", err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *SysFileDirSearch) Generate() dto.Index {
|
||||
o := *m
|
||||
return &o
|
||||
}
|
||||
|
||||
type SysFileDirControl struct {
|
||||
ID int `uri:"Id" comment:"标识"` // 标识
|
||||
Label string `json:"label" comment:"目录名称"`
|
||||
PId int `json:"pId" comment:"上级目录"`
|
||||
Sort string `json:"sort" comment:"排序"`
|
||||
Path string `json:"path" comment:"路径"`
|
||||
CreateBy int `json:"-"`
|
||||
UpdateBy int `json:"-"`
|
||||
}
|
||||
|
||||
func (s *SysFileDirControl) Bind(ctx *gin.Context) error {
|
||||
log := api.GetRequestLogger(ctx)
|
||||
err := ctx.ShouldBindUri(s)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBindUri error: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
err = ctx.ShouldBind(s)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBind error: %s", err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SysFileDirControl) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *SysFileDirControl) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.SysFileDir{
|
||||
Model: common.Model{Id: s.ID},
|
||||
Label: s.Label,
|
||||
PId: s.PId,
|
||||
//Sort: s.Sort,
|
||||
Path: s.Path,
|
||||
ControlBy: common.ControlBy{
|
||||
CreateBy: s.CreateBy,
|
||||
UpdateBy: s.UpdateBy,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *SysFileDirControl) GetId() interface{} {
|
||||
return s.ID
|
||||
}
|
||||
|
||||
type SysFileDirById struct {
|
||||
dto.ObjectById
|
||||
UpdateBy int `json:"-"`
|
||||
}
|
||||
|
||||
func (s *SysFileDirById) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *SysFileDirById) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.SysFileDir{}, nil
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/common/dto"
|
||||
common "go-admin/common/models"
|
||||
)
|
||||
|
||||
type SysFileInfoSearch struct {
|
||||
dto.Pagination `search:"-"`
|
||||
ID int `form:"Id" search:"type:exact;column:id;table:sys_file_info" comment:"标识"`
|
||||
Type string `form:"type" search:"type:exact;column:type;table:sys_file_info" comment:"类型"`
|
||||
Name string `form:"name" search:"type:exact;column:name;table:sys_file_info" comment:"名称"`
|
||||
PId string `form:"pId" search:"type:exact;column:p_id;table:sys_file_info" comment:"目录"`
|
||||
Source string `form:"source" search:"type:exact;column:source;table:sys_file_info" comment:"来源"`
|
||||
}
|
||||
|
||||
func (m *SysFileInfoSearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
type SysFileInfoControl struct {
|
||||
ID int `uri:"id" comment:"标识"` // 标识
|
||||
Type string `json:"type" comment:"类型"`
|
||||
Name string `json:"name" comment:"名称"`
|
||||
Size string `json:"size" comment:"大小"`
|
||||
PId int `json:"pId" comment:"目录"`
|
||||
Source string `json:"source" comment:"来源"`
|
||||
Url string `json:"url" comment:"地址"`
|
||||
FullUrl string `json:"fullUrl" comment:"全地址"`
|
||||
CreateBy int `json:"-"`
|
||||
UpdateBy int `json:"-"`
|
||||
}
|
||||
|
||||
func (s *SysFileInfoControl) Generate() (*models.SysFileInfo, error) {
|
||||
return &models.SysFileInfo{
|
||||
Model: common.Model{Id: s.ID},
|
||||
Type: s.Type,
|
||||
Name: s.Name,
|
||||
Size: s.Size,
|
||||
PId: s.PId,
|
||||
Source: s.Source,
|
||||
Url: s.Url,
|
||||
FullUrl: s.FullUrl,
|
||||
ControlBy: common.ControlBy{CreateBy: s.CreateBy, UpdateBy: s.UpdateBy},
|
||||
}, nil
|
||||
}
|
||||
|
||||
type SysFileInfoById struct {
|
||||
dto.ObjectById
|
||||
UpdateBy int `json:"-"`
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/common/dto"
|
||||
common "go-admin/common/models"
|
||||
)
|
||||
|
||||
type SysJobSearch struct {
|
||||
dto.Pagination `search:"-"`
|
||||
JobId int `form:"jobId" search:"type:exact;column:job_id;table:sys_job"`
|
||||
JobName string `form:"jobName" search:"type:icontains;column:job_name;table:sys_job"`
|
||||
JobGroup string `form:"jobGroup" search:"type:exact;column:job_group;table:sys_job"`
|
||||
CronExpression string `form:"cronExpression" search:"type:exact;column:cron_expression;table:sys_job"`
|
||||
InvokeTarget string `form:"invokeTarget" search:"type:exact;column:invoke_target;table:sys_job"`
|
||||
Status int `form:"status" search:"type:exact;column:status;table:sys_job"`
|
||||
}
|
||||
|
||||
func (m *SysJobSearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
func (m *SysJobSearch) Bind(ctx *gin.Context) error {
|
||||
log := api.GetRequestLogger(ctx)
|
||||
err := ctx.ShouldBind(m)
|
||||
if err != nil {
|
||||
log.Errorf("Bind error: %s", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *SysJobSearch) Generate() dto.Index {
|
||||
o := *m
|
||||
return &o
|
||||
}
|
||||
|
||||
type SysJobControl struct {
|
||||
JobId int `json:"jobId"`
|
||||
JobName string `json:"jobName" validate:"required"` // 名称
|
||||
JobGroup string `json:"jobGroup"` // 任务分组
|
||||
JobType int `json:"jobType"` // 任务类型
|
||||
CronExpression string `json:"cronExpression"` // cron表达式
|
||||
InvokeTarget string `json:"invokeTarget"` // 调用目标
|
||||
Args string `json:"args"` // 目标参数
|
||||
MisfirePolicy int `json:"misfirePolicy"` // 执行策略
|
||||
Concurrent int `json:"concurrent"` // 是否并发
|
||||
Status int `json:"status"` // 状态
|
||||
EntryId int `json:"entryId"` // job启动时返回的id
|
||||
}
|
||||
|
||||
func (s *SysJobControl) Bind(ctx *gin.Context) error {
|
||||
return ctx.ShouldBind(s)
|
||||
}
|
||||
|
||||
func (s *SysJobControl) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *SysJobControl) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.SysJob{
|
||||
JobId: s.JobId,
|
||||
JobName: s.JobName,
|
||||
JobGroup: s.JobGroup,
|
||||
JobType: s.JobType,
|
||||
CronExpression: s.CronExpression,
|
||||
InvokeTarget: s.InvokeTarget,
|
||||
Args: s.Args,
|
||||
MisfirePolicy: s.MisfirePolicy,
|
||||
Concurrent: s.Concurrent,
|
||||
Status: s.Status,
|
||||
EntryId: s.EntryId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *SysJobControl) GetId() interface{} {
|
||||
return s.JobId
|
||||
}
|
||||
|
||||
type SysJobById struct {
|
||||
dto.ObjectById
|
||||
}
|
||||
|
||||
func (s *SysJobById) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *SysJobById) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.SysJob{}, nil
|
||||
}
|
||||
|
||||
type SysJobItem struct {
|
||||
JobId int `json:"jobId"`
|
||||
JobName string `json:"jobName" validate:"required"` // 名称
|
||||
JobGroup string `json:"jobGroup"` // 任务分组
|
||||
JobType int `json:"jobType"` // 任务类型
|
||||
CronExpression string `json:"cronExpression"` // cron表达式
|
||||
InvokeTarget string `json:"invokeTarget"` // 调用目标
|
||||
Args string `json:"args"` // 目标参数
|
||||
MisfirePolicy int `json:"misfirePolicy"` // 执行策略
|
||||
Concurrent int `json:"concurrent"` // 是否并发
|
||||
Status int `json:"status"` // 状态
|
||||
EntryId int `json:"entryId"` // job启动时返回的id
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/common/dto"
|
||||
common "go-admin/common/models"
|
||||
)
|
||||
|
||||
type SysChinaAreaDataSearch struct {
|
||||
dto.Pagination `search:"-"`
|
||||
PId string `form:"pId" search:"type:exact;column:p_id;table:sys_china_area_data" comment:"上级编码"`
|
||||
Name string `form:"name" search:"type:exact;column:name;table:sys_china_area_data" comment:"名称"`
|
||||
}
|
||||
|
||||
func (m *SysChinaAreaDataSearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
func (m *SysChinaAreaDataSearch) Bind(ctx *gin.Context) error {
|
||||
log := api.GetRequestLogger(ctx)
|
||||
err := ctx.ShouldBind(m)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBind error: %s", err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
type SysChinaAreaDataControl struct {
|
||||
Id int `uri:"id" comment:"编码"` // 编码
|
||||
PId string `json:"pId" comment:"上级编码"`
|
||||
Name string `json:"name" comment:"名称"`
|
||||
CreateTime time.Time `json:"createTime" comment:""`
|
||||
UpdateTime time.Time `json:"updateTime" comment:""`
|
||||
DeleteTime time.Time `json:"deleteTime" comment:""`
|
||||
}
|
||||
|
||||
func (s *SysChinaAreaDataControl) Bind(ctx *gin.Context) error {
|
||||
log := api.GetRequestLogger(ctx)
|
||||
err := ctx.ShouldBindUri(s)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBindUri error: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
err = ctx.ShouldBind(s)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBind error: %s", err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SysChinaAreaDataControl) Generate() (*models.SysChinaAreaData, error) {
|
||||
return &models.SysChinaAreaData{
|
||||
|
||||
Model: common.Model{Id: s.Id},
|
||||
PId: s.PId,
|
||||
Name: s.Name,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *SysChinaAreaDataControl) GetId() interface{} {
|
||||
return s.Id
|
||||
}
|
||||
|
||||
type SysChinaAreaDataById struct {
|
||||
Id int `uri:"id"`
|
||||
Ids []int `json:"ids"`
|
||||
}
|
||||
|
||||
func (s *SysChinaAreaDataById) GetId() interface{} {
|
||||
if len(s.Ids) > 0 {
|
||||
s.Ids = append(s.Ids, s.Id)
|
||||
return s.Ids
|
||||
}
|
||||
return s.Id
|
||||
}
|
||||
|
||||
func (s *SysChinaAreaDataById) Bind(ctx *gin.Context) error {
|
||||
log := api.GetRequestLogger(ctx)
|
||||
err := ctx.ShouldBindUri(s)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBindUri error: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
err = ctx.ShouldBind(s)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBind error: %s", err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SysChinaAreaDataById) SetUpdateBy(id int) {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user