作者 yangfu

merge chenaq branch

... ... @@ -39,6 +39,7 @@ func CreateReturnGoodsService(options map[string]interface{}) (service.ReturnGoo
}
func CreateUserCreateService(options map[string]interface{}) (service.UserCreateService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
... ... @@ -53,3 +54,11 @@ func CreatePhoneAuthService(options map[string]interface{}) (service.PhoneAuthSe
}
return domainService.NewPhoneAuthenticationService(transactionContext)
}
func CreateAddUserService(options map[string]interface{}) (service.AddUserService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return domainService.NewAddUserService(transactionContext)
}
... ...
... ... @@ -7,13 +7,15 @@ import (
)
type CreateUserCommand struct {
//按位与 1.高管 001 右第0位高管 ; 2.合伙人 010 右第1位合伙人 ;3.高管,合伙人 011;
//按位与 1.高管 001 右第0位高管 ; 2.合伙人 010 右第1位合伙人 ;3.高管,合伙人 011;
// 1.高管 2.合伙人 3高管,合伙人 4:游客
UserType int `json:"userType" valid:"Required"`
// 管理员类型 1.超级管理员 10:企业管理员 100:普通用户
AdminType int `json:"adminType" valid:"Required"`
// 状态 1正常 2禁用
Status int64 `json:"status" valid:"Required"`
//用户账号(手机号)
UserAccount string `json:"userAccount" valid:"Required"`
// 业务员
Salesmans []*domain.Salesman `json:"salesmans,omitempty"`
// 用户信息
... ...
... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/user/command"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/user/query"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain/service"
)
// 用户管理服务
... ... @@ -53,21 +54,22 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser
newUser := &domain.User{
UserType: createUserCommand.UserType,
AdminType: createUserCommand.AdminType,
UserAccount: createUserCommand.UserAccount,
Status: createUserCommand.Status,
UserInfo: createUserCommand.UserInfo,
PartnerInfo: createUserCommand.PartnerInfo,
AccessPartners: createUserCommand.AccessPartners,
}
var userRepository domain.UserRepository
if value, err := factory.CreateUserRepository(map[string]interface{}{
var addUserService service.AddUserService
if value, err := factory.CreateAddUserService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
userRepository = value
addUserService = value
}
if user, err := userRepository.Save(newUser); err != nil {
if user, err := addUserService.AddUser(newUser); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
... ...
package service
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
)
type AddUserService interface {
coreDomain.DomainEventPublisher
AddUser(*domain.User) (*domain.User, error)
}
... ...
... ... @@ -6,30 +6,32 @@ import (
)
const (
StatusEnable int64 = 1 //启用
StatusDisable int64 = 2 //禁用
StatusEnable int64 = 1 //启用
StatusDisable int64 = 2 //禁用
)
// 管理员类型 1.超级管理员 10:企业管理员 100:普通用户
const (
SuperAdministrator = 1 //超级管理员
EnterpriseAdministrator = 10 //企业管理员
NormalUser = 100 //普通用户
SuperAdministrator = 1 //超级管理员
EnterpriseAdministrator = 10 //企业管理员
NormalUser = 100 //普通用户
)
// UserType
const (
Manager = 1 //高管
Partner = 2 //合伙人
Guest = 3 //游客
Manager = 1 //高管
Partner = 2 //合伙人
Guest = 3 //游客
)
// 用户实体
type User struct {
// 用户id
UserId int64 `json:"userId"`
// 1.高管 2.合伙人 4:游客
UserType int `json:"userType"`
//用户账号(手机号)
UserAccount string `json:"userAccount"`
// 用户权限
Permissions []int `json:"permissions"`
// 公司Id
... ... @@ -129,43 +131,43 @@ func (user *User) Update(data map[string]interface{}) error {
//添加/编辑高管
func CheckAdminUserType (dm *User)(*User,error) {
if dm.UserInfo.Uid == int64(0){
return nil,fmt.Errorf("高管的uid不能为空")
func CheckAdminUserType(dm *User) (*User, error) {
if dm.UserInfo.Uid == int64(0) {
return nil, fmt.Errorf("高管的uid不能为空")
}
if dm.UserInfo.Email == ""{
return nil,fmt.Errorf("高管的Email不能为空")
if dm.UserInfo.Email == "" {
return nil, fmt.Errorf("高管的Email不能为空")
}
if dm.UserInfo.EntryTime.IsZero() {
return nil,fmt.Errorf("高管的入职时间不能为空")
return nil, fmt.Errorf("高管的入职时间不能为空")
}
if dm.UserInfo.Workplace == ""{
return nil,fmt.Errorf("高管的工作地不能为空")
if dm.UserInfo.Workplace == "" {
return nil, fmt.Errorf("高管的工作地不能为空")
}
if dm.UserInfo.JobNumber == ""{
return nil,fmt.Errorf("高管的工号不能为空")
if dm.UserInfo.JobNumber == "" {
return nil, fmt.Errorf("高管的工号不能为空")
}
return dm,nil
return dm, nil
}
//添加/编辑合伙人
type PartnerUserType struct {}
type PartnerUserType struct{}
func CheckPartnerUserType (dm *User)(*User,error) {
if dm.PartnerInfo.Status == 0{
return nil,fmt.Errorf("合伙人的状态不能为空")
func CheckPartnerUserType(dm *User) (*User, error) {
if dm.PartnerInfo.Status == 0 {
return nil, fmt.Errorf("合伙人的状态不能为空")
}
if dm.PartnerInfo.PartnerAccount == ""{
return nil,fmt.Errorf("合伙人账号不能为空")
if dm.PartnerInfo.PartnerAccount == "" {
return nil, fmt.Errorf("合伙人账号不能为空")
}
if dm.PartnerInfo.PartnerName == ""{
return nil,fmt.Errorf("合伙人姓名不能为空")
if dm.PartnerInfo.PartnerName == "" {
return nil, fmt.Errorf("合伙人姓名不能为空")
}
if len(dm.PartnerInfo.PartnerCategorys) == 0 {
return nil,fmt.Errorf("合伙人类别不能为空")
if len(dm.PartnerInfo.PartnerCategorys) == 0 {
return nil, fmt.Errorf("合伙人类别不能为空")
}
if len(dm.PartnerInfo.Salesmans) == 0{
return nil,fmt.Errorf("合伙人查看合伙人账号不能为空")
if len(dm.PartnerInfo.Salesmans) == 0 {
return nil, fmt.Errorf("合伙人查看合伙人账号不能为空")
}
return dm,nil
}
\ No newline at end of file
return dm, nil
}
... ...
package domainService
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
type AddUserService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *AddUserService) AddUser(user *domain.User) (*domain.User, error) {
if user.UserType&1 > 0 {
if _, err := domain.CheckAdminUserType(user); err != nil {
return nil, err
}
}
if user.UserType&2 > 0 {
if _, err := domain.CheckPartnerUserType(user); err != nil {
return nil, err
}
}
var userRepository domain.UserRepository
if repository, err := repository.NewUserRepository(service.transactionContext); err != nil {
return nil, err
} else {
userRepository = repository
}
count, existUser, err := userRepository.Find(map[string]interface{}{
"userAccount": user.UserAccount,
"companyId": user.CompanyId,
})
if count != 0 {
if existUser[0].UserType^user.UserType == 0 {
return nil, fmt.Errorf("用户已存在")
}
if existUser[0].UserType&1 > 0 {
user.UserInfo = existUser[0].UserInfo
}
if existUser[0].UserType&2 > 0 {
user.PartnerInfo = existUser[0].PartnerInfo
}
user.UserType = existUser[0].UserType + user.UserType
}
user, err = userRepository.Save(user)
if err != nil {
return nil, err
}
return user, nil
}
func NewAddUserService(transactionContext *pgTransaction.TransactionContext) (*AddUserService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &AddUserService{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -13,6 +13,8 @@ type User struct {
UserType int
// 用户权限
Permissions []int `pg:",array"`
//用户账号(手机号)
UserAccount string
// 公司Id
CompanyId int64
// 用户信息
... ...
... ... @@ -30,6 +30,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error)
"user_type",
"permissions",
"company_id",
"user_account",
"user_info",
"partner_info",
"status",
... ... @@ -58,6 +59,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error)
&user.UserType,
pg.Array(&user.Permissions),
&user.CompanyId,
&user.UserAccount,
&user.UserInfo,
&user.PartnerInfo,
&user.Status,
... ... @@ -72,6 +74,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error)
user.UserType,
pg.Array(user.Permissions),
user.CompanyId,
user.UserAccount,
user.UserInfo,
user.PartnerInfo,
user.Status,
... ... @@ -90,6 +93,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error)
&user.UserType,
pg.Array(&user.Permissions),
&user.CompanyId,
&user.UserAccount,
&user.UserInfo,
&user.PartnerInfo,
&user.Status,
... ... @@ -104,6 +108,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error)
user.UserType,
pg.Array(user.Permissions),
user.CompanyId,
user.UserAccount,
user.UserInfo,
user.PartnerInfo,
user.Status,
... ...