123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- package user
- 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"
- )
- const (
- FieldUserName = "UserName"
- FieldPassword = "Password"
- FieldName = "Name"
- FieldPhone = "Phone"
- FieldEmail = "Email"
- FieldToken = "Token"
- FieldLastLoginTime = "LastLoginTime"
- )
- var (
- ColumnUserName = domain.ColumnName(FieldUserName)
- ColumnPassword = domain.ColumnName(FieldPassword)
- ColumnName = domain.ColumnName(FieldName)
- ColumnPhone = domain.ColumnName(FieldPhone)
- ColumnEmail = domain.ColumnName(FieldEmail)
- ColumnToken = domain.ColumnName(FieldToken)
- ColumnLastLoginTime = domain.ColumnName(FieldLastLoginTime)
- )
- var fieldMap = map[string]string{
- FieldUserName: "用户名",
- FieldPassword: "密码",
- FieldName: "姓名",
- FieldPhone: "手机号",
- FieldEmail: "邮箱",
- FieldToken: "token",
- FieldLastLoginTime: "最近登录时间",
- }
- 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" sqlresult:"column:password" check:"required,lte=256"`
- Name string `sqlmapping:"column:name;updateClear" sqlresult:"column:name" check:"lte=256"`
- Phone string `sqlmapping:"column:phone;updateClear" sqlresult:"column:phone" check:"lte=128"`
- Email string `sqlmapping:"column:email;updateClear" sqlresult:"column:email" check:"lte=512"`
- Token string `sqlmapping:"column:token;notUpdate" sqlresult:"column:token"`
- LastLoginTime time.Time `sqlmapping:"column:last_login_time;notUpdate" sqlresult:"column:last_login_time" check:"required,timezero"`
- RoleIDs []string `sqlmapping:"-" sqlresult:"-"`
- entity.TimeFields
- }
- func (e *Entity) DomainCNName() string {
- return "用户"
- }
- func (e *Entity) DomainCamelName() string {
- return "User"
- }
- func (e *Entity) ForCreate() error {
- checkResult := check.Struct(e, fieldMap)
- err := entity.CheckFieldIDResult(checkResult)
- if err != nil {
- return err
- }
- err = domain.CheckField(checkResult, e.DomainCNName(), FieldUserName)
- if err != nil {
- return err
- }
- return nil
- }
- func (e *Entity) ForDelete() error {
- checkResult := check.Struct(e, fieldMap)
- err := entity.CheckFieldIDResult(checkResult)
- if err != nil {
- return err
- }
- return nil
- }
- func (e *Entity) ForUpdate() error {
- checkResult := check.Struct(e, fieldMap)
- err := entity.CheckFieldIDResult(checkResult)
- if err != nil {
- return err
- }
- err = e.checkUpdateFields()
- if err != nil {
- return err
- }
- return nil
- }
- func (e *Entity) checkUpdateFields() error {
- if strutils.AllBlank(e.Password) && e.LastLoginTime.IsZero() {
- return errors.New(e.DomainCNName() + "没有传递需要更新的字段")
- }
- return nil
- }
|