作者 yangfu

merge chenaq branch

@@ -39,6 +39,7 @@ func CreateReturnGoodsService(options map[string]interface{}) (service.ReturnGoo @@ -39,6 +39,7 @@ func CreateReturnGoodsService(options map[string]interface{}) (service.ReturnGoo
39 } 39 }
40 40
41 func CreateUserCreateService(options map[string]interface{}) (service.UserCreateService, error) { 41 func CreateUserCreateService(options map[string]interface{}) (service.UserCreateService, error) {
  42 +
42 var transactionContext *pgTransaction.TransactionContext 43 var transactionContext *pgTransaction.TransactionContext
43 if value, ok := options["transactionContext"]; ok { 44 if value, ok := options["transactionContext"]; ok {
44 transactionContext = value.(*pgTransaction.TransactionContext) 45 transactionContext = value.(*pgTransaction.TransactionContext)
@@ -53,3 +54,11 @@ func CreatePhoneAuthService(options map[string]interface{}) (service.PhoneAuthSe @@ -53,3 +54,11 @@ func CreatePhoneAuthService(options map[string]interface{}) (service.PhoneAuthSe
53 } 54 }
54 return domainService.NewPhoneAuthenticationService(transactionContext) 55 return domainService.NewPhoneAuthenticationService(transactionContext)
55 } 56 }
  57 +
  58 +func CreateAddUserService(options map[string]interface{}) (service.AddUserService, error) {
  59 + var transactionContext *pgTransaction.TransactionContext
  60 + if value, ok := options["transactionContext"]; ok {
  61 + transactionContext = value.(*pgTransaction.TransactionContext)
  62 + }
  63 + return domainService.NewAddUserService(transactionContext)
  64 +}
@@ -7,13 +7,15 @@ import ( @@ -7,13 +7,15 @@ import (
7 ) 7 )
8 8
9 type CreateUserCommand struct { 9 type CreateUserCommand struct {
10 - //按位与 1.高管 001 右第0位高管 ; 2.合伙人 010 右第1位合伙人 ;3.高管,合伙人 011; 10 + //按位与 1.高管 001 右第0位高管 ; 2.合伙人 010 右第1位合伙人 ;3.高管,合伙人 011;
11 // 1.高管 2.合伙人 3高管,合伙人 4:游客 11 // 1.高管 2.合伙人 3高管,合伙人 4:游客
12 UserType int `json:"userType" valid:"Required"` 12 UserType int `json:"userType" valid:"Required"`
13 // 管理员类型 1.超级管理员 10:企业管理员 100:普通用户 13 // 管理员类型 1.超级管理员 10:企业管理员 100:普通用户
14 AdminType int `json:"adminType" valid:"Required"` 14 AdminType int `json:"adminType" valid:"Required"`
15 // 状态 1正常 2禁用 15 // 状态 1正常 2禁用
16 Status int64 `json:"status" valid:"Required"` 16 Status int64 `json:"status" valid:"Required"`
  17 + //用户账号(手机号)
  18 + UserAccount string `json:"userAccount" valid:"Required"`
17 // 业务员 19 // 业务员
18 Salesmans []*domain.Salesman `json:"salesmans,omitempty"` 20 Salesmans []*domain.Salesman `json:"salesmans,omitempty"`
19 // 用户信息 21 // 用户信息
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/user/command" 8 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/user/command"
9 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/user/query" 9 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/user/query"
10 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" 10 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain/service"
11 ) 12 )
12 13
13 // 用户管理服务 14 // 用户管理服务
@@ -53,21 +54,22 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser @@ -53,21 +54,22 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser
53 newUser := &domain.User{ 54 newUser := &domain.User{
54 UserType: createUserCommand.UserType, 55 UserType: createUserCommand.UserType,
55 AdminType: createUserCommand.AdminType, 56 AdminType: createUserCommand.AdminType,
  57 + UserAccount: createUserCommand.UserAccount,
56 Status: createUserCommand.Status, 58 Status: createUserCommand.Status,
57 UserInfo: createUserCommand.UserInfo, 59 UserInfo: createUserCommand.UserInfo,
58 PartnerInfo: createUserCommand.PartnerInfo, 60 PartnerInfo: createUserCommand.PartnerInfo,
59 AccessPartners: createUserCommand.AccessPartners, 61 AccessPartners: createUserCommand.AccessPartners,
60 } 62 }
61 - var userRepository domain.UserRepository  
62 - if value, err := factory.CreateUserRepository(map[string]interface{}{ 63 + var addUserService service.AddUserService
  64 + if value, err := factory.CreateAddUserService(map[string]interface{}{
63 "transactionContext": transactionContext, 65 "transactionContext": transactionContext,
64 }); err != nil { 66 }); err != nil {
65 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 67 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
66 } else { 68 } else {
67 - userRepository = value 69 + addUserService = value
68 } 70 }
69 71
70 - if user, err := userRepository.Save(newUser); err != nil { 72 + if user, err := addUserService.AddUser(newUser); err != nil {
71 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 73 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
72 } else { 74 } else {
73 if err := transactionContext.CommitTransaction(); err != nil { 75 if err := transactionContext.CommitTransaction(); err != nil {
  1 +package service
  2 +
  3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  6 +)
  7 +
  8 +type AddUserService interface {
  9 + coreDomain.DomainEventPublisher
  10 + AddUser(*domain.User) (*domain.User, error)
  11 +}
@@ -6,30 +6,32 @@ import ( @@ -6,30 +6,32 @@ import (
6 ) 6 )
7 7
8 const ( 8 const (
9 - StatusEnable int64 = 1 //启用  
10 - StatusDisable int64 = 2 //禁用 9 + StatusEnable int64 = 1 //启用
  10 + StatusDisable int64 = 2 //禁用
11 ) 11 )
  12 +
12 // 管理员类型 1.超级管理员 10:企业管理员 100:普通用户 13 // 管理员类型 1.超级管理员 10:企业管理员 100:普通用户
13 const ( 14 const (
14 - SuperAdministrator = 1 //超级管理员  
15 - EnterpriseAdministrator = 10 //企业管理员  
16 - NormalUser = 100 //普通用户 15 + SuperAdministrator = 1 //超级管理员
  16 + EnterpriseAdministrator = 10 //企业管理员
  17 + NormalUser = 100 //普通用户
17 ) 18 )
18 19
19 // UserType 20 // UserType
20 const ( 21 const (
21 - Manager = 1 //高管  
22 - Partner = 2 //合伙人  
23 - Guest = 3 //游客 22 + Manager = 1 //高管
  23 + Partner = 2 //合伙人
  24 + Guest = 3 //游客
24 ) 25 )
25 26
26 -  
27 // 用户实体 27 // 用户实体
28 type User struct { 28 type User struct {
29 // 用户id 29 // 用户id
30 UserId int64 `json:"userId"` 30 UserId int64 `json:"userId"`
31 // 1.高管 2.合伙人 4:游客 31 // 1.高管 2.合伙人 4:游客
32 UserType int `json:"userType"` 32 UserType int `json:"userType"`
  33 + //用户账号(手机号)
  34 + UserAccount string `json:"userAccount"`
33 // 用户权限 35 // 用户权限
34 Permissions []int `json:"permissions"` 36 Permissions []int `json:"permissions"`
35 // 公司Id 37 // 公司Id
@@ -129,43 +131,43 @@ func (user *User) Update(data map[string]interface{}) error { @@ -129,43 +131,43 @@ func (user *User) Update(data map[string]interface{}) error {
129 131
130 //添加/编辑高管 132 //添加/编辑高管
131 133
132 -func CheckAdminUserType (dm *User)(*User,error) {  
133 - if dm.UserInfo.Uid == int64(0){  
134 - return nil,fmt.Errorf("高管的uid不能为空") 134 +func CheckAdminUserType(dm *User) (*User, error) {
  135 + if dm.UserInfo.Uid == int64(0) {
  136 + return nil, fmt.Errorf("高管的uid不能为空")
135 } 137 }
136 - if dm.UserInfo.Email == ""{  
137 - return nil,fmt.Errorf("高管的Email不能为空") 138 + if dm.UserInfo.Email == "" {
  139 + return nil, fmt.Errorf("高管的Email不能为空")
138 } 140 }
139 if dm.UserInfo.EntryTime.IsZero() { 141 if dm.UserInfo.EntryTime.IsZero() {
140 - return nil,fmt.Errorf("高管的入职时间不能为空") 142 + return nil, fmt.Errorf("高管的入职时间不能为空")
141 } 143 }
142 - if dm.UserInfo.Workplace == ""{  
143 - return nil,fmt.Errorf("高管的工作地不能为空") 144 + if dm.UserInfo.Workplace == "" {
  145 + return nil, fmt.Errorf("高管的工作地不能为空")
144 } 146 }
145 - if dm.UserInfo.JobNumber == ""{  
146 - return nil,fmt.Errorf("高管的工号不能为空") 147 + if dm.UserInfo.JobNumber == "" {
  148 + return nil, fmt.Errorf("高管的工号不能为空")
147 } 149 }
148 - return dm,nil 150 + return dm, nil
149 } 151 }
150 152
151 //添加/编辑合伙人 153 //添加/编辑合伙人
152 -type PartnerUserType struct {} 154 +type PartnerUserType struct{}
153 155
154 -func CheckPartnerUserType (dm *User)(*User,error) {  
155 - if dm.PartnerInfo.Status == 0{  
156 - return nil,fmt.Errorf("合伙人的状态不能为空") 156 +func CheckPartnerUserType(dm *User) (*User, error) {
  157 + if dm.PartnerInfo.Status == 0 {
  158 + return nil, fmt.Errorf("合伙人的状态不能为空")
157 } 159 }
158 - if dm.PartnerInfo.PartnerAccount == ""{  
159 - return nil,fmt.Errorf("合伙人账号不能为空") 160 + if dm.PartnerInfo.PartnerAccount == "" {
  161 + return nil, fmt.Errorf("合伙人账号不能为空")
160 } 162 }
161 - if dm.PartnerInfo.PartnerName == ""{  
162 - return nil,fmt.Errorf("合伙人姓名不能为空") 163 + if dm.PartnerInfo.PartnerName == "" {
  164 + return nil, fmt.Errorf("合伙人姓名不能为空")
163 } 165 }
164 - if len(dm.PartnerInfo.PartnerCategorys) == 0 {  
165 - return nil,fmt.Errorf("合伙人类别不能为空") 166 + if len(dm.PartnerInfo.PartnerCategorys) == 0 {
  167 + return nil, fmt.Errorf("合伙人类别不能为空")
166 } 168 }
167 - if len(dm.PartnerInfo.Salesmans) == 0{  
168 - return nil,fmt.Errorf("合伙人查看合伙人账号不能为空") 169 + if len(dm.PartnerInfo.Salesmans) == 0 {
  170 + return nil, fmt.Errorf("合伙人查看合伙人账号不能为空")
169 } 171 }
170 - return dm,nil  
171 -}  
  172 + return dm, nil
  173 +}
  1 +package domainService
  2 +
  3 +import (
  4 + "fmt"
  5 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  6 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
  8 +
  9 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  10 +)
  11 +
  12 +type AddUserService struct {
  13 + coreDomain.BaseEventPublisher
  14 + transactionContext *pgTransaction.TransactionContext
  15 +}
  16 +
  17 +func (service *AddUserService) AddUser(user *domain.User) (*domain.User, error) {
  18 +
  19 + if user.UserType&1 > 0 {
  20 + if _, err := domain.CheckAdminUserType(user); err != nil {
  21 + return nil, err
  22 + }
  23 + }
  24 +
  25 + if user.UserType&2 > 0 {
  26 + if _, err := domain.CheckPartnerUserType(user); err != nil {
  27 + return nil, err
  28 + }
  29 + }
  30 +
  31 + var userRepository domain.UserRepository
  32 + if repository, err := repository.NewUserRepository(service.transactionContext); err != nil {
  33 + return nil, err
  34 + } else {
  35 + userRepository = repository
  36 + }
  37 +
  38 + count, existUser, err := userRepository.Find(map[string]interface{}{
  39 + "userAccount": user.UserAccount,
  40 + "companyId": user.CompanyId,
  41 + })
  42 +
  43 + if count != 0 {
  44 + if existUser[0].UserType^user.UserType == 0 {
  45 + return nil, fmt.Errorf("用户已存在")
  46 + }
  47 + if existUser[0].UserType&1 > 0 {
  48 + user.UserInfo = existUser[0].UserInfo
  49 + }
  50 + if existUser[0].UserType&2 > 0 {
  51 + user.PartnerInfo = existUser[0].PartnerInfo
  52 + }
  53 + user.UserType = existUser[0].UserType + user.UserType
  54 + }
  55 +
  56 + user, err = userRepository.Save(user)
  57 +
  58 + if err != nil {
  59 + return nil, err
  60 + }
  61 +
  62 + return user, nil
  63 +}
  64 +
  65 +func NewAddUserService(transactionContext *pgTransaction.TransactionContext) (*AddUserService, error) {
  66 + if transactionContext == nil {
  67 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  68 + } else {
  69 + return &AddUserService{
  70 + transactionContext: transactionContext,
  71 + }, nil
  72 + }
  73 +}
@@ -13,6 +13,8 @@ type User struct { @@ -13,6 +13,8 @@ type User struct {
13 UserType int 13 UserType int
14 // 用户权限 14 // 用户权限
15 Permissions []int `pg:",array"` 15 Permissions []int `pg:",array"`
  16 + //用户账号(手机号)
  17 + UserAccount string
16 // 公司Id 18 // 公司Id
17 CompanyId int64 19 CompanyId int64
18 // 用户信息 20 // 用户信息
@@ -30,6 +30,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error) @@ -30,6 +30,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error)
30 "user_type", 30 "user_type",
31 "permissions", 31 "permissions",
32 "company_id", 32 "company_id",
  33 + "user_account",
33 "user_info", 34 "user_info",
34 "partner_info", 35 "partner_info",
35 "status", 36 "status",
@@ -58,6 +59,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error) @@ -58,6 +59,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error)
58 &user.UserType, 59 &user.UserType,
59 pg.Array(&user.Permissions), 60 pg.Array(&user.Permissions),
60 &user.CompanyId, 61 &user.CompanyId,
  62 + &user.UserAccount,
61 &user.UserInfo, 63 &user.UserInfo,
62 &user.PartnerInfo, 64 &user.PartnerInfo,
63 &user.Status, 65 &user.Status,
@@ -72,6 +74,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error) @@ -72,6 +74,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error)
72 user.UserType, 74 user.UserType,
73 pg.Array(user.Permissions), 75 pg.Array(user.Permissions),
74 user.CompanyId, 76 user.CompanyId,
  77 + user.UserAccount,
75 user.UserInfo, 78 user.UserInfo,
76 user.PartnerInfo, 79 user.PartnerInfo,
77 user.Status, 80 user.Status,
@@ -90,6 +93,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error) @@ -90,6 +93,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error)
90 &user.UserType, 93 &user.UserType,
91 pg.Array(&user.Permissions), 94 pg.Array(&user.Permissions),
92 &user.CompanyId, 95 &user.CompanyId,
  96 + &user.UserAccount,
93 &user.UserInfo, 97 &user.UserInfo,
94 &user.PartnerInfo, 98 &user.PartnerInfo,
95 &user.Status, 99 &user.Status,
@@ -104,6 +108,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error) @@ -104,6 +108,7 @@ func (repository *UserRepository) Save(user *domain.User) (*domain.User, error)
104 user.UserType, 108 user.UserType,
105 pg.Array(user.Permissions), 109 pg.Array(user.Permissions),
106 user.CompanyId, 110 user.CompanyId,
  111 + user.UserAccount,
107 user.UserInfo, 112 user.UserInfo,
108 user.PartnerInfo, 113 user.PartnerInfo,
109 user.Status, 114 user.Status,