yjp před 1 rokem
rodič
revize
20a88e9a97
1 změnil soubory, kde provedl 18 přidání a 1 odebrání
  1. 18 1
      convenient/domain/auth/user/entity.go

+ 18 - 1
convenient/domain/auth/user/entity.go

@@ -4,6 +4,8 @@ import (
 	"git.sxidc.com/go-framework/baize/framework/core/domain"
 	"git.sxidc.com/go-framework/baize/framework/core/domain/entity"
 	"git.sxidc.com/go-framework/baize/framework/core/tag/check"
+	"git.sxidc.com/go-tools/utils/strutils"
+	"github.com/pkg/errors"
 	"time"
 )
 
@@ -29,7 +31,7 @@ type Entity struct {
 	entity.Base
 	UserName      string    `sqlmapping:"column:user_name;notUpdate" sqlresult:"column:user_name" check:"required,lte=256"`
 	Password      string    `sqlmapping:"column:password;aes:'@MKU^AAOP%H*K¥VJ<%G&j*o#$XZSWQ@L'" sqlresult:"column:password;aes:'@MKU^AAOP%H*K¥VJ<%G&j*o#$XZSWQ@L'" check:"required,lte=256"`
-	LastLoginTime time.Time `sqlmapping:"column:last_login_time;notUpdate" sqlresult:"column:last_login_time"`
+	LastLoginTime time.Time `sqlmapping:"column:last_login_time;notUpdate" sqlresult:"column:last_login_time" check:"required,timezero"`
 
 	RoleIDs []string
 
@@ -91,3 +93,18 @@ func (e *Entity) ForUpdate() error {
 
 	return nil
 }
+
+func (e *Entity) checkUpdateFields(checkResult check.Result) error {
+	if strutils.AllBlank(e.Password) && e.LastLoginTime.IsZero() {
+		return errors.New(e.DomainCNName() + "没有传递需要更新的字段")
+	}
+
+	if strutils.IsStringNotEmpty(e.Password) {
+		err := domain.CheckField(checkResult, e.DomainCNName(), FieldPassword)
+		if err != nil {
+			return err
+		}
+	}
+
+	return nil
+}