mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-26 16:46:14 +08:00
add 生成验证字典
This commit is contained in:
@@ -9,8 +9,11 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
@@ -180,5 +183,31 @@ func makeValidatorFunc(field *sysin.GenCodesColumnListModel) (err error, rule st
|
||||
} else {
|
||||
err = gerror.New("not support")
|
||||
}
|
||||
|
||||
// 生成验证字典
|
||||
if field.DictType > 0 {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
valueType gdb.Value
|
||||
resultValue gdb.Result
|
||||
)
|
||||
valueType, err = dao.SysDictType.Ctx(ctx).Fields(dao.SysDictType.Columns().Type).Where(dao.SysDictType.Columns().Id, field.DictType).Value()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
resultValue, err = dao.SysDictData.Ctx(context.Background()).Fields(dao.SysDictData.Columns().Value).Where(dao.SysDictData.Columns().Type, valueType.String()).All()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if resultValue.Len() > 0 {
|
||||
names := make([]string, 0)
|
||||
for _, item := range resultValue {
|
||||
names = append(names, item["value"].String())
|
||||
}
|
||||
dictRule := "in:" + strings.Join(names, ",")
|
||||
rule += fmt.Sprintf(EditInpValidatorGenerally, dictRule, field.GoName, field.Dc+"值不正确")
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user