sys_user.go 1.7 KB
package domain

import (
	"context"
	"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/tool"
	"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
)

type SysUser struct {
	Id        int64  `json:",omitempty"` // 唯一标识
	Name      string `json:",omitempty"` // 姓名
	Phone     string `json:",omitempty"` // 手机号码
	Avatar    string `json:",omitempty"` // 头像
	Password  string `json:",omitempty"` // 密码
	CreatedAt int64  `json:",omitempty"`
	UpdatedAt int64  `json:",omitempty"`
	DeletedAt int64  `json:",omitempty"`
	Version   int    `json:",omitempty"`
	//Email     string `json:",omitempty"` // 邮箱
	//Sex       int    `json:",omitempty"` // 0:女 1:男

	EmployeeId int64 `json:"-"`
}

type SysUserRepository interface {
	Insert(ctx context.Context, conn transaction.Conn, dm *SysUser) (*SysUser, error)
	Update(ctx context.Context, conn transaction.Conn, dm *SysUser) (*SysUser, error)
	UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *SysUser) (*SysUser, error)
	Delete(ctx context.Context, conn transaction.Conn, dm *SysUser) (*SysUser, error)
	FindOne(ctx context.Context, conn transaction.Conn, id int64) (*SysUser, error)
	FindOneByPhone(ctx context.Context, conn transaction.Conn, phone string) (*SysUser, error)
	FindOneUnscoped(ctx context.Context, conn transaction.Conn, id int64) (*SysUser, error)
	Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*SysUser, error)
}

func NewDomainSysUser(phone string, name string, password string) *SysUser {
	if password == "" {
		password = "123456"
	}
	if name == "" {
		name = "用户" + tool.Krand(6, tool.KC_RAND_KIND_NUM)
	}
	return &SysUser{
		Phone:    phone,
		Name:     name,
		Password: tool.Md5ByString(password),
	}
}