2 Star 0 Fork 0

BOBO/创想视频核心服务

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sys_map.go 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
zhouyp 提交于 2024-07-16 14:51 . init:初始化内框代码
package validate
import (
"context"
"gitee.com/bobo-rs/innovideo-services/framework/dao"
"gitee.com/bobo-rs/innovideo-services/framework/service"
"gitee.com/bobo-rs/innovideo-services/library/exception"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gvalid"
)
// RuleRegisterSysMap 注册系统字典规则
func RuleRegisterSysMap() {
gvalid.RegisterRuleByMap(map[string]gvalid.RuleFunc{
`sys-map-exists-id`: RuleSysMapExistsById,
`sys-map-value-exists-id`: RuleSysMapValueExistsById,
`sys-map-exists-name`: RuleSysMapExistsByName,
})
}
// RuleSysMapExistsById 通过字典ID检测字典值是否存在
func RuleSysMapExistsById(ctx context.Context, in gvalid.RuleFuncInput) error {
if in.Value.Uint() == 0 {
return nil
}
// 是否存在
if b, _ := service.SysMap().MapModel().ExistsPri(ctx, in.Value.Uint()); !b {
return exception.New(`字典名不存在`)
}
return nil
}
// RuleSysMapExistsByName 通过字典名检测字典是否存在
func RuleSysMapExistsByName(ctx context.Context, in gvalid.RuleFuncInput) error {
if in.Value.IsEmpty() {
return nil
}
// 是否存在
if b, _ := service.SysMap().MapModel().Exists(ctx, g.Map{
dao.SysMap.Columns().Name: in.Value.String(),
}); !b {
return exception.New(`字典名不存在`)
}
return nil
}
// RuleSysMapValueExistsById 通过字典值ID检测字典值是否存在
func RuleSysMapValueExistsById(ctx context.Context, in gvalid.RuleFuncInput) error {
if in.Value.Uint() == 0 {
return nil
}
// 字典值是否存在
if b, _ := service.SysMap().ValueModel().ExistsPri(ctx, in.Value.Uint()); !b {
return exception.New(`字典值不存在`)
}
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bobo-rs/innovideo-services.git
git@gitee.com:bobo-rs/innovideo-services.git
bobo-rs
innovideo-services
创想视频核心服务
v1.0.19

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385