|
|
@@ -11,6 +11,7 @@ import (
|
|
|
"git.sxidc.com/go-framework/baize/framework/core/tag/check"
|
|
|
"git.sxidc.com/go-tools/utils/encoding"
|
|
|
"git.sxidc.com/go-tools/utils/strutils"
|
|
|
+ "github.com/pkg/errors"
|
|
|
)
|
|
|
|
|
|
// Simple Bind参数
|
|
|
@@ -23,7 +24,6 @@ type Simple struct {
|
|
|
}
|
|
|
|
|
|
func (simple *Simple) Bind(binder *binding.Binder) {
|
|
|
- // TODO 定制需要加密的字段逻辑,Name赋值默认值
|
|
|
entity_crud.BindSimple(binder, &entity_crud.Simple[Info]{
|
|
|
Entity: &Entity{},
|
|
|
Schema: simple.Schema,
|
|
|
@@ -158,14 +158,68 @@ func (simple *Simple) Bind(binder *binding.Binder) {
|
|
|
|
|
|
return nil
|
|
|
},
|
|
|
- }), entity_crud.WithQueryConditionFieldCallback[Info](func(conditions *sql.Conditions, fieldName string, columnName string, value any) (hasDeal bool) {
|
|
|
+ }), entity_crud.WithQueryConditionFieldCallback[Info](func(conditions *sql.Conditions, fieldName string, columnName string, value any) (hasDeal bool, err error) {
|
|
|
+ if value == nil {
|
|
|
+ return true, nil
|
|
|
+ }
|
|
|
+
|
|
|
switch fieldName {
|
|
|
- case FieldPassword:
|
|
|
+ case FieldUserName:
|
|
|
+ userName, ok := value.(string)
|
|
|
+ if !ok {
|
|
|
+ return false, errors.New("用户名字段类型不是string")
|
|
|
+ }
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(userName) {
|
|
|
+ conditions.Like(ColumnUserName, "%"+userName+"%")
|
|
|
+ }
|
|
|
+
|
|
|
+ return true, nil
|
|
|
case FieldName:
|
|
|
+ name, ok := value.(string)
|
|
|
+ if !ok {
|
|
|
+ return false, errors.New("姓名字段类型不是string")
|
|
|
+ }
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(name) {
|
|
|
+ conditions.Like(ColumnName, "%"+name+"%")
|
|
|
+ }
|
|
|
+
|
|
|
+ return true, nil
|
|
|
case FieldPhone:
|
|
|
+ phone, ok := value.(string)
|
|
|
+ if !ok {
|
|
|
+ return false, errors.New("手机号字段类型不是string")
|
|
|
+ }
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(phone) {
|
|
|
+ encryptedPassword, err := encoding.AESEncrypt(phone, simple.AESKey)
|
|
|
+ if err != nil {
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+
|
|
|
+ conditions.Equal(ColumnPassword, encryptedPassword)
|
|
|
+ }
|
|
|
+
|
|
|
+ return true, nil
|
|
|
case FieldEmail:
|
|
|
+ email, ok := value.(string)
|
|
|
+ if !ok {
|
|
|
+ return false, errors.New("邮箱字段类型不是string")
|
|
|
+ }
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(email) {
|
|
|
+ encryptedPassword, err := encoding.AESEncrypt(email, simple.AESKey)
|
|
|
+ if err != nil {
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+
|
|
|
+ conditions.Equal(ColumnPassword, encryptedPassword)
|
|
|
+ }
|
|
|
+
|
|
|
+ return true, nil
|
|
|
default:
|
|
|
- return false
|
|
|
+ return false, nil
|
|
|
}
|
|
|
}))
|
|
|
}
|