作者 yangfu

Merge branch 'dev' into test

1 FROM 192.168.0.243:5000/mmm/allied-creation-user:20210809 1 FROM 192.168.0.243:5000/mmm/allied-creation-user:20210809
2 -ENV APP_DIR $GOPATH/src/project-20210825 2 +ENV APP_DIR $GOPATH/src/project-20210906
3 RUN mkdir -p $APP_DIR 3 RUN mkdir -p $APP_DIR
4 WORKDIR $APP_DIR/ 4 WORKDIR $APP_DIR/
5 COPY ./pkg pkg 5 COPY ./pkg pkg
@@ -10,7 +10,7 @@ import ( @@ -10,7 +10,7 @@ import (
10 10
11 type DestroyAccountCommand struct { 11 type DestroyAccountCommand struct {
12 // 用户Id 用户唯一标识 12 // 用户Id 用户唯一标识
13 - UserId int64 `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"` 13 + Account string `cname:"账号" json:"account" valid:"Required"`
14 } 14 }
15 15
16 func (destroyAccountCommand *DestroyAccountCommand) Valid(validation *validation.Validation) { 16 func (destroyAccountCommand *DestroyAccountCommand) Valid(validation *validation.Validation) {
@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 type UserBaseDto struct { 7 type UserBaseDto struct {
8 // 用户基础数据id 8 // 用户基础数据id
9 UserBaseId int64 `json:"userBaseId,omitempty"` 9 UserBaseId int64 `json:"userBaseId,omitempty"`
  10 + UserType int `json:"userType"`
10 // 用户信息 11 // 用户信息
11 UserInfo *domain.UserInfo `json:"userInfo,omitempty"` 12 UserInfo *domain.UserInfo `json:"userInfo,omitempty"`
12 // 手机号码 13 // 手机号码
@@ -28,5 +29,6 @@ type UserBaseDto struct { @@ -28,5 +29,6 @@ type UserBaseDto struct {
28 func (u *UserBaseDto) LoadDto(ub *domain.UserBase) { 29 func (u *UserBaseDto) LoadDto(ub *domain.UserBase) {
29 u.UserBaseId = ub.UserBaseId 30 u.UserBaseId = ub.UserBaseId
30 u.UserInfo = ub.UserInfo 31 u.UserInfo = ub.UserInfo
  32 + u.UserType = domain.UserTypeVisitor
31 u.Im = ub.Im 33 u.Im = ub.Im
32 } 34 }
@@ -9,11 +9,15 @@ import ( @@ -9,11 +9,15 @@ import (
9 ) 9 )
10 10
11 type UserInfoQuery struct { 11 type UserInfoQuery struct {
12 - Account string `cname:"账号" json:"account" valid:"Required"` 12 + Account string `cname:"账号" json:"account"`
  13 + UserBaseId int64 `cname:"用户编号" json:"userBaseId"`
13 } 14 }
14 15
15 func (userInfoQuery *UserInfoQuery) Valid(validation *validation.Validation) { 16 func (userInfoQuery *UserInfoQuery) Valid(validation *validation.Validation) {
16 //validation.SetError("CustomValid", "未实现的自定义认证") 17 //validation.SetError("CustomValid", "未实现的自定义认证")
  18 + if len(userInfoQuery.Account) == 0 && userInfoQuery.UserBaseId <= 0 {
  19 + validation.SetError("CustomValid", "参数不能为空")
  20 + }
17 } 21 }
18 22
19 func (userInfoQuery *UserInfoQuery) ValidateQuery() error { 23 func (userInfoQuery *UserInfoQuery) ValidateQuery() error {
@@ -81,7 +81,7 @@ func (authService *AuthService) DestroyAccount(destroyAccountCommand *command.De @@ -81,7 +81,7 @@ func (authService *AuthService) DestroyAccount(destroyAccountCommand *command.De
81 if err != nil { 81 if err != nil {
82 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 82 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
83 } 83 }
84 - if err := accountDestroyService.DestroyAccount(nil, destroyAccountCommand.UserId); err != nil { 84 + if err := accountDestroyService.DestroyAccount(nil, destroyAccountCommand.Account); err != nil {
85 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 85 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
86 } 86 }
87 87
@@ -319,8 +319,13 @@ func (authService *AuthService) UserInfo(userInfoQuery *query.UserInfoQuery) (in @@ -319,8 +319,13 @@ func (authService *AuthService) UserInfo(userInfoQuery *query.UserInfoQuery) (in
319 transactionContext.RollbackTransaction() 319 transactionContext.RollbackTransaction()
320 }() 320 }()
321 321
  322 + var userBase *domain.UserBase
322 userBaseRepository, _, _ := factory.FastPgUserBase(transactionContext, 0) 323 userBaseRepository, _, _ := factory.FastPgUserBase(transactionContext, 0)
323 - userBase, err := userBaseRepository.FindOne(map[string]interface{}{"account": userInfoQuery.Account}) 324 + if len(userInfoQuery.Account) > 0 {
  325 + userBase, err = userBaseRepository.FindOne(map[string]interface{}{"account": userInfoQuery.Account})
  326 + } else if userInfoQuery.UserBaseId > 0 {
  327 + userBase, err = userBaseRepository.FindOne(map[string]interface{}{"userBaseId": userInfoQuery.UserBaseId})
  328 + }
324 if err != nil { 329 if err != nil {
325 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 330 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
326 } 331 }
@@ -25,6 +25,8 @@ type ListOrgQuery struct { @@ -25,6 +25,8 @@ type ListOrgQuery struct {
25 ParentId int64 `cname:"父级ID" json:"parentId,omitempty"` 25 ParentId int64 `cname:"父级ID" json:"parentId,omitempty"`
26 // 是否是组织(是:1 不是:2) 26 // 是否是组织(是:1 不是:2)
27 IsOrg int `cname:"是否是组织(是:1 不是:2)" json:"isOrg,omitempty"` 27 IsOrg int `cname:"是否是组织(是:1 不是:2)" json:"isOrg,omitempty"`
  28 + // 模糊匹配组织名称
  29 + MatchOrgName string `cname:"部门名称" json:"matchOrgName,omitempty"`
28 } 30 }
29 31
30 func (listOrgQuery *ListOrgQuery) Valid(validation *validation.Validation) { 32 func (listOrgQuery *ListOrgQuery) Valid(validation *validation.Validation) {
@@ -185,7 +185,7 @@ func (orgService *OrgService) GetOrgSubDepartment(getOrgSubDepartmentQuery *quer @@ -185,7 +185,7 @@ func (orgService *OrgService) GetOrgSubDepartment(getOrgSubDepartmentQuery *quer
185 treeNodes[i] = orgs[i] 185 treeNodes[i] = orgs[i]
186 } 186 }
187 tree := domain.NewTrees(treeNodes) 187 tree := domain.NewTrees(treeNodes)
188 - nodes := tree.AllChildNodes(org) 188 + nodes := tree.AllSubDepartment(org)
189 if err := transactionContext.CommitTransaction(); err != nil { 189 if err := transactionContext.CommitTransaction(); err != nil {
190 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 190 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
191 } 191 }
@@ -12,7 +12,7 @@ import ( @@ -12,7 +12,7 @@ import (
12 type GetRoleRelatedUsersQuery struct { 12 type GetRoleRelatedUsersQuery struct {
13 OperateInfo *domain.OperateInfo `json:"-"` 13 OperateInfo *domain.OperateInfo `json:"-"`
14 // 组织ID 14 // 组织ID
15 - OrgId int64 `cname:"组织ID" json:"orgId,string,omitempty"` 15 + OrgId int64 `cname:"组织ID" json:"orgId,omitempty"`
16 16
17 // 角色ID 17 // 角色ID
18 RoleId int64 `cname:"角色ID" json:"roleId" valid:"Required"` 18 RoleId int64 `cname:"角色ID" json:"roleId" valid:"Required"`
@@ -20,6 +20,8 @@ type GetRoleRelatedUsersQuery struct { @@ -20,6 +20,8 @@ type GetRoleRelatedUsersQuery struct {
20 DepartmentId int64 `cname:"部门编号" json:"departmentId,omitempty"` 20 DepartmentId int64 `cname:"部门编号" json:"departmentId,omitempty"`
21 // 只需要关联的用户 true:仅返回关联用户信息 false:返回所有其他信息(未关联的用户) 21 // 只需要关联的用户 true:仅返回关联用户信息 false:返回所有其他信息(未关联的用户)
22 //OnlyRelatedUser bool `cname:"部门编号" json:"onlyRelatedUser,omitempty"` 22 //OnlyRelatedUser bool `cname:"部门编号" json:"onlyRelatedUser,omitempty"`
  23 + // 组织ID
  24 + InOrgIds []int64 `cname:"组织ID" json:"orgIds,omitempty"`
23 } 25 }
24 26
25 func (getRoleRelatedUsersQuery *GetRoleRelatedUsersQuery) Valid(validation *validation.Validation) { 27 func (getRoleRelatedUsersQuery *GetRoleRelatedUsersQuery) Valid(validation *validation.Validation) {
@@ -27,6 +27,8 @@ type ListRoleQuery struct { @@ -27,6 +27,8 @@ type ListRoleQuery struct {
27 OrgId int64 `cname:"组织ID" json:"orgId,omitempty"` 27 OrgId int64 `cname:"组织ID" json:"orgId,omitempty"`
28 // 匹配多个组织 28 // 匹配多个组织
29 InOrgIds []int64 `cname:"匹配多个组织" json:"inOrgIds,omitempty"` 29 InOrgIds []int64 `cname:"匹配多个组织" json:"inOrgIds,omitempty"`
  30 + // 角色名称
  31 + MatchRoleName string `cname:"匹配角色名称" json:"matchRoleName,omitempty"`
30 } 32 }
31 33
32 func (listRoleQuery *ListRoleQuery) Valid(validation *validation.Validation) { 34 func (listRoleQuery *ListRoleQuery) Valid(validation *validation.Validation) {
@@ -218,10 +218,15 @@ func (roleService *RoleService) GetRoleRelatedUsers(getRoleRelatedUsersQuery *qu @@ -218,10 +218,15 @@ func (roleService *RoleService) GetRoleRelatedUsers(getRoleRelatedUsersQuery *qu
218 } 218 }
219 queryOptions := make(map[string]interface{}) 219 queryOptions := make(map[string]interface{})
220 queryOptions["companyId"] = role.CompanyId 220 queryOptions["companyId"] = role.CompanyId
221 - queryOptions["organizationId"] = getRoleRelatedUsersQuery.OrgId  
222 if getRoleRelatedUsersQuery.DepartmentId > 0 { 221 if getRoleRelatedUsersQuery.DepartmentId > 0 {
223 queryOptions["departmentId"] = getRoleRelatedUsersQuery.DepartmentId 222 queryOptions["departmentId"] = getRoleRelatedUsersQuery.DepartmentId
224 } 223 }
  224 + // 按组织过滤
  225 + if len(getRoleRelatedUsersQuery.InOrgIds) > 0 {
  226 + queryOptions["inOrgIds"] = getRoleRelatedUsersQuery.InOrgIds
  227 + } else {
  228 + queryOptions["organizationId"] = getRoleRelatedUsersQuery.OrgId
  229 + }
225 queryOptions["userType"] = domain.UserTypeEmployee 230 queryOptions["userType"] = domain.UserTypeEmployee
226 _, users, err := userRepository.Find(queryOptions) 231 _, users, err := userRepository.Find(queryOptions)
227 if err != nil { 232 if err != nil {
@@ -39,6 +39,8 @@ type ListUserQuery struct { @@ -39,6 +39,8 @@ type ListUserQuery struct {
39 PullRealTime bool `cname:"拉取最新数据" json:"pullRealTime,omitempty"` 39 PullRealTime bool `cname:"拉取最新数据" json:"pullRealTime,omitempty"`
40 // 状态(1:启用 2:禁用 3:注销) 40 // 状态(1:启用 2:禁用 3:注销)
41 EnableStatus int `cname:"状态(1:启用 2:禁用 3:注销)" json:"enableStatus,omitempty"` 41 EnableStatus int `cname:"状态(1:启用 2:禁用 3:注销)" json:"enableStatus,omitempty"`
  42 + // 状态(1:启用 2:禁用 3:注销)
  43 + InEnableStatus []int `cname:"状态(1:启用 2:禁用 3:注销)" json:"inEnableStatus,omitempty"`
42 } 44 }
43 45
44 func (listUserQuery *ListUserQuery) Valid(validation *validation.Validation) { 46 func (listUserQuery *ListUserQuery) Valid(validation *validation.Validation) {
@@ -65,10 +65,15 @@ func (userService *UserService) BatchAdd2(batchAddCommand *command.BatchAdd2Comm @@ -65,10 +65,15 @@ func (userService *UserService) BatchAdd2(batchAddCommand *command.BatchAdd2Comm
65 batchAddUserService, _ := factory.CreateBatchAddUserService(map[string]interface{}{ 65 batchAddUserService, _ := factory.CreateBatchAddUserService(map[string]interface{}{
66 "transactionContext": transactionContext, 66 "transactionContext": transactionContext,
67 }) 67 })
68 - if err = batchAddUserService.BatchAddUser2(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil {  
69 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 68 + var failRows []*domain.BatchAddUserItem
  69 + if failRows, err = batchAddUserService.BatchAddUser2(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil {
  70 + return batchAddCommand.Users, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  71 + }
  72 + if len(failRows) != 0 {
  73 + return map[string]interface{}{
  74 + "failRows": failRows,
  75 + }, nil //有错误行,回滚
70 } 76 }
71 -  
72 if err := transactionContext.CommitTransaction(); err != nil { 77 if err := transactionContext.CommitTransaction(); err != nil {
73 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 78 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
74 } 79 }
@@ -360,12 +365,24 @@ func (userService *UserService) GetUser(getUserQuery *query.GetUserQuery) (inter @@ -360,12 +365,24 @@ func (userService *UserService) GetUser(getUserQuery *query.GetUserQuery) (inter
360 _, org, _ := factory.FastPgOrg(transactionContext, user.OrganizationId) 365 _, org, _ := factory.FastPgOrg(transactionContext, user.OrganizationId)
361 _, company, _ := factory.FastPgCompany(transactionContext, user.CompanyId) 366 _, company, _ := factory.FastPgCompany(transactionContext, user.CompanyId)
362 _, userBase, _ := factory.FastPgUserBase(transactionContext, user.UserBaseId) 367 _, userBase, _ := factory.FastPgUserBase(transactionContext, user.UserBaseId)
363 - if dep != nil && org != nil && userBase != nil {  
364 - user.Department = dep.ConvDep()  
365 - user.Organization = org.CloneSample() 368 + if company != nil {
366 user.Company = company.CloneSample() 369 user.Company = company.CloneSample()
  370 + }
  371 + if org != nil {
  372 + user.Organization = org.CloneSample()
  373 + }
  374 + if dep != nil {
  375 + user.Department = dep.ConvDep()
  376 + }
  377 + if userBase != nil {
367 user.UserInfo = userBase.UserInfo 378 user.UserInfo = userBase.UserInfo
368 } 379 }
  380 + // TODO:后期可以移除有冗余roleType
  381 + for i := range user.UserRole {
  382 + if _, role, _ := factory.FastPgRole(transactionContext, user.UserRole[i].RoleId); role != nil {
  383 + user.UserRole[i].RoleType = role.RoleType
  384 + }
  385 + }
369 userDto := &dto.UserDto{Im: userBase.Im} 386 userDto := &dto.UserDto{Im: userBase.Im}
370 if err := userDto.LoadDto(user, company); err != nil { 387 if err := userDto.LoadDto(user, company); err != nil {
371 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 388 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -402,7 +419,7 @@ func (userService *UserService) GetUserAccessMenus(getUserAccessMenusQuery *quer @@ -402,7 +419,7 @@ func (userService *UserService) GetUserAccessMenus(getUserAccessMenusQuery *quer
402 "transactionContext": transactionContext, 419 "transactionContext": transactionContext,
403 }) 420 })
404 421
405 - menus, err := roleAccessMenusService.AccessMenus(nil, user.UserRoleIds(), domain.AccessMenusOptions{ 422 + menus, err := roleAccessMenusService.AccessMenus(getUserAccessMenusQuery.OperateInfo, user.UserRoleIds(), domain.AccessMenusOptions{
406 CompanyId: user.CompanyId, 423 CompanyId: user.CompanyId,
407 MenuCategory: getUserAccessMenusQuery.MenuCategory, 424 MenuCategory: getUserAccessMenusQuery.MenuCategory,
408 OrgId: getUserAccessMenusQuery.OrgId, 425 OrgId: getUserAccessMenusQuery.OrgId,
@@ -127,6 +127,7 @@ func (role *Role) CloneSample() *Role { @@ -127,6 +127,7 @@ func (role *Role) CloneSample() *Role {
127 RoleId: role.RoleId, 127 RoleId: role.RoleId,
128 RoleName: role.RoleName, 128 RoleName: role.RoleName,
129 Ext: role.Ext, 129 Ext: role.Ext,
  130 + RoleType: role.RoleType,
130 } 131 }
131 } 132 }
132 133
@@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" @@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
4 4
5 // PgAuthAccountDestroyService 账号注销服务 5 // PgAuthAccountDestroyService 账号注销服务
6 type PgAuthAccountDestroyService interface { 6 type PgAuthAccountDestroyService interface {
7 - DestroyAccount(optUser *domain.User, userId int64) error 7 + DestroyAccount(optUser *domain.User, userId string) error
8 } 8 }
@@ -5,5 +5,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" @@ -5,5 +5,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
5 // PgBatchAddUserService 批量添加用户服务 5 // PgBatchAddUserService 批量添加用户服务
6 type PgBatchAddUserService interface { 6 type PgBatchAddUserService interface {
7 BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error 7 BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error
8 - BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) error 8 + BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error)
9 } 9 }
@@ -111,6 +111,35 @@ func traverse(tree *Tree, node TreeNode) bool { @@ -111,6 +111,35 @@ func traverse(tree *Tree, node TreeNode) bool {
111 return match 111 return match
112 } 112 }
113 113
  114 +// 返回tree下的所有子部门 (如果节点是组织,跳过)
  115 +func (tree *Tree) AllSubDepartment(node TreeNode) []TreeNode {
  116 + treeNode := tree.find(node)
  117 + if treeNode == nil {
  118 + return []TreeNode{}
  119 + }
  120 + var stack []*Tree
  121 + stack = append(stack, treeNode)
  122 + var res []TreeNode
  123 + rootId := treeNode.Node.(*Org).OrgId
  124 + for {
  125 + if len(stack) == 0 {
  126 + break
  127 + }
  128 + pop := stack[0]
  129 + stack = stack[1:]
  130 + /***特殊处理***/
  131 + if org, ok := pop.Node.(*Org); ok && org.OrgId != int64(rootId) {
  132 + if org.IsOrg == IsOrgFlag {
  133 + continue
  134 + }
  135 + }
  136 + /***特殊处理***/
  137 + stack = append(stack, pop.Nodes...)
  138 + res = append(res, pop.Node)
  139 + }
  140 + return res
  141 +}
  142 +
114 // Int64String 1 -> "1" 1->1 143 // Int64String 1 -> "1" 1->1
115 type Int64String int64 144 type Int64String int64
116 145
@@ -14,6 +14,7 @@ const ( @@ -14,6 +14,7 @@ const (
14 const ( 14 const (
15 UserTypeEmployee = 1 15 UserTypeEmployee = 1
16 UserTypeCooperation = 2 16 UserTypeCooperation = 2
  17 + UserTypeVisitor = 4 // 游客
17 UserTypeCompanyAdmin = 1024 18 UserTypeCompanyAdmin = 1024
18 ) 19 )
19 20
@@ -293,21 +294,24 @@ type BatchAddUserItem struct { @@ -293,21 +294,24 @@ type BatchAddUserItem struct {
293 // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加) 294 // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)
294 UserType int `json:"userType,omitempty"` 295 UserType int `json:"userType,omitempty"`
295 // 用户姓名 296 // 用户姓名
296 - UserName string `json:"userName,omitempty"` 297 + UserName string `json:"userName"`
297 // 手机号码 298 // 手机号码
298 - Phone string `json:"phone,omitempty"` 299 + Phone string `json:"phone"`
299 // 邮箱 300 // 邮箱
300 - Email string `json:"email,omitempty"` 301 + Email string `json:"email"`
301 // 用户编号 企业内标识 302 // 用户编号 企业内标识
302 - UserCode string `json:"userCode,omitempty"` 303 + UserCode string `json:"userCode"`
303 // 组织编码 304 // 组织编码
304 - Org string `json:"org,omitempty"` 305 + Org string `json:"org"`
305 // 部门编码 306 // 部门编码
306 - Department string `json:"department,omitempty"` 307 + Department string `json:"department"`
307 // 状态(1:启用 2:禁用 3:注销) 308 // 状态(1:启用 2:禁用 3:注销)
308 EnableStatus int `json:"enableStatus,omitempty"` 309 EnableStatus int `json:"enableStatus,omitempty"`
309 // 共创公司 cooperationCompany 310 // 共创公司 cooperationCompany
310 CooperationCompany string `json:"cooperationCompany"` 311 CooperationCompany string `json:"cooperationCompany"`
311 // 共创到期时间 (yyyy-MM-dd) cooperationDeadline 312 // 共创到期时间 (yyyy-MM-dd) cooperationDeadline
312 CooperationDeadline time.Time `json:"cooperationDeadline"` 313 CooperationDeadline time.Time `json:"cooperationDeadline"`
  314 +
  315 + // 失败理由
  316 + FailReason string `json:"failReason"`
313 } 317 }
@@ -13,21 +13,21 @@ type PgAuthAccountDestroyService struct { @@ -13,21 +13,21 @@ type PgAuthAccountDestroyService struct {
13 transactionContext *pgTransaction.TransactionContext 13 transactionContext *pgTransaction.TransactionContext
14 } 14 }
15 15
16 -func (ptr *PgAuthAccountDestroyService) DestroyAccount(optUser *domain.User, userId int64) error { 16 +func (ptr *PgAuthAccountDestroyService) DestroyAccount(optUser *domain.User, account string) error {
17 // 1.查询账号记录 17 // 1.查询账号记录
18 userRepository, _ := repository.NewUserRepository(ptr.transactionContext) 18 userRepository, _ := repository.NewUserRepository(ptr.transactionContext)
19 - var userBaseId int64  
20 - if user, err := userRepository.FindOne(map[string]interface{}{"userId": userId}); err != nil {  
21 - if err == domain.ErrorNotFound {  
22 - return fmt.Errorf("该用户不存在")  
23 - }  
24 - return err  
25 - } else {  
26 - userBaseId = user.UserBaseId  
27 - } 19 + //var userBaseId int64
  20 + //if user, err := userRepository.FindOne(map[string]interface{}{"userId": userId}); err != nil {
  21 + // if err == domain.ErrorNotFound {
  22 + // return fmt.Errorf("该用户不存在")
  23 + // }
  24 + // return err
  25 + //} else {
  26 + // userBaseId = user.UserBaseId
  27 + //}
28 28
29 userBaseRepository, _ := repository.NewUserBaseRepository(ptr.transactionContext) 29 userBaseRepository, _ := repository.NewUserBaseRepository(ptr.transactionContext)
30 - userBase, err := userBaseRepository.FindOne(map[string]interface{}{"userBaseId": userBaseId}) 30 + userBase, err := userBaseRepository.FindOne(map[string]interface{}{"account": account})
31 if err != nil { 31 if err != nil {
32 return err 32 return err
33 } 33 }
@@ -14,9 +14,6 @@ type PgBatchAddOrgService struct { @@ -14,9 +14,6 @@ type PgBatchAddOrgService struct {
14 } 14 }
15 15
16 func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgList []*domain.BatchAddOrgItem) error { 16 func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgList []*domain.BatchAddOrgItem) error {
17 - var (  
18 - err error  
19 - )  
20 orgRepository, err := repository.NewOrgRepository(ptr.transactionContext) 17 orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
21 if err != nil { 18 if err != nil {
22 return err 19 return err
@@ -37,7 +34,7 @@ func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgLis @@ -37,7 +34,7 @@ func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgLis
37 CompanyId: optUser.CompanyId, 34 CompanyId: optUser.CompanyId,
38 OrgCode: item.OrgCode, 35 OrgCode: item.OrgCode,
39 OrgName: item.OrgName, 36 OrgName: item.OrgName,
40 - IsOrg: domain.IsOrgFlag, 37 + IsOrg: domain.IsNotOrgFlag,
41 ParentId: 0, 38 ParentId: 0,
42 OrgStatus: domain.OrgStatusEnable, 39 OrgStatus: domain.OrgStatusEnable,
43 CreatedAt: time.Now(), 40 CreatedAt: time.Now(),
@@ -82,17 +82,18 @@ func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, user @@ -82,17 +82,18 @@ func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, user
82 return nil 82 return nil
83 } 83 }
84 84
85 -func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) error { 85 +func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error) {
86 var ( 86 var (
87 err error 87 err error
88 ) 88 )
  89 + var failRows = make([]*domain.BatchAddUserItem, 0)
89 orgRepository, err := repository.NewOrgRepository(ptr.transactionContext) 90 orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
90 if err != nil { 91 if err != nil {
91 - return err 92 + return failRows, err
92 } 93 }
93 _, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId, "limit": 10000}) 94 _, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId, "limit": 10000})
94 if err != nil { 95 if err != nil {
95 - return err 96 + return failRows, err
96 } 97 }
97 var mapOrg = make(map[string]*domain.Org) 98 var mapOrg = make(map[string]*domain.Org)
98 for i := range orgs { 99 for i := range orgs {
@@ -103,15 +104,24 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use @@ -103,15 +104,24 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
103 for i := range users { 104 for i := range users {
104 user := users[i] 105 user := users[i]
105 if err = ptr.preCheck2(user); err != nil { 106 if err = ptr.preCheck2(user); err != nil {
106 - return err 107 + user.FailReason = err.Error()
  108 + failRows = append(failRows, user)
  109 + continue
  110 + //return err
107 } 111 }
108 var org, dep *domain.Org 112 var org, dep *domain.Org
109 var ok bool 113 var ok bool
110 if org, ok = mapOrg[user.Org]; !ok { 114 if org, ok = mapOrg[user.Org]; !ok {
111 - return fmt.Errorf("导入的组织机构不存在:" + user.Org) 115 + user.FailReason = "导入的组织机构不存在:" + user.Org
  116 + failRows = append(failRows, user)
  117 + continue
  118 + //return fmt.Errorf("导入的组织机构不存在:" + user.Org)
112 } 119 }
113 if dep, ok = mapOrg[user.Department]; !ok { 120 if dep, ok = mapOrg[user.Department]; !ok {
114 - return fmt.Errorf("导入的所属部门不存在:" + user.Department) 121 + user.FailReason = "导入的所属部门不存在:" + user.Department
  122 + failRows = append(failRows, user)
  123 + continue
  124 + //return fmt.Errorf("导入的所属部门不存在:" + user.Department)
115 } 125 }
116 newUser := &domain.User{ 126 newUser := &domain.User{
117 CompanyId: user.CompanyId, 127 CompanyId: user.CompanyId,
@@ -143,10 +153,13 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use @@ -143,10 +153,13 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
143 UpdatedAt: time.Now(), 153 UpdatedAt: time.Now(),
144 } 154 }
145 if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil { 155 if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil {
146 - return fmt.Errorf("%v %v", user.UserName, err.Error()) 156 + user.FailReason = err.Error()
  157 + failRows = append(failRows, user)
  158 + continue
  159 + //return fmt.Errorf("%v %v", user.UserName, err.Error())
147 } 160 }
148 } 161 }
149 - return nil 162 + return failRows, nil
150 } 163 }
151 164
152 func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error { 165 func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error {
@@ -191,6 +191,9 @@ func (repository *OrgRepository) Find(queryOptions map[string]interface{}) (int6 @@ -191,6 +191,9 @@ func (repository *OrgRepository) Find(queryOptions map[string]interface{}) (int6
191 query.SetWhereByQueryOption("org_name = ?", "depName") 191 query.SetWhereByQueryOption("org_name = ?", "depName")
192 query.SetWhereByQueryOption("org_code = ?", "orgCode") 192 query.SetWhereByQueryOption("org_code = ?", "orgCode")
193 query.SetWhereByQueryOption("parent_id = ?", "parentId") 193 query.SetWhereByQueryOption("parent_id = ?", "parentId")
  194 + if v, ok := queryOptions["matchOrgName"]; ok && len(v.(string)) > 0 {
  195 + query.Where(fmt.Sprintf(`org_name like '%%%v%%'`, v))
  196 + }
194 query.SetOrderDirect("org_id", "ASC") 197 query.SetOrderDirect("org_id", "ASC")
195 if count, err := query.SelectAndCount(); err != nil { 198 if count, err := query.SelectAndCount(); err != nil {
196 return 0, orgs, err 199 return 0, orgs, err
@@ -185,6 +185,9 @@ func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int @@ -185,6 +185,9 @@ func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int
185 if orgName, ok := queryOptions["orgName"]; ok && len(orgName.(string)) > 0 { 185 if orgName, ok := queryOptions["orgName"]; ok && len(orgName.(string)) > 0 {
186 query.Where(fmt.Sprintf("ext->>'orgName' like '%%%v%%'", orgName)) 186 query.Where(fmt.Sprintf("ext->>'orgName' like '%%%v%%'", orgName))
187 } 187 }
  188 + if matchRoleName, ok := queryOptions["matchRoleName"]; ok && len(matchRoleName.(string)) > 0 {
  189 + query.Where(fmt.Sprintf("role_name like '%%%v%%'", matchRoleName))
  190 + }
188 // 包含删除的 191 // 包含删除的
189 if v, ok := queryOptions["includeDeleted"]; ok && !(v.(bool)) { 192 if v, ok := queryOptions["includeDeleted"]; ok && !(v.(bool)) {
190 query.Where("deleted_at is null") 193 query.Where("deleted_at is null")
@@ -204,7 +204,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int @@ -204,7 +204,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int
204 query.SetWhereByQueryOption("(user_type & ?)>0", "userType") 204 query.SetWhereByQueryOption("(user_type & ?)>0", "userType")
205 query.SetWhereByQueryOption("enable_status=?", "enableStatus") 205 query.SetWhereByQueryOption("enable_status=?", "enableStatus")
206 query.SetWhereByQueryOption(fmt.Sprintf(`user_role @> '[{"roleId":%v}]'`, queryOptions["roleId"]), "roleId") 206 query.SetWhereByQueryOption(fmt.Sprintf(`user_role @> '[{"roleId":%v}]'`, queryOptions["roleId"]), "roleId")
207 - 207 + if v, ok := queryOptions["inEnableStatus"]; ok && len(v.([]int)) > 0 {
  208 + query.Where(`enable_status in (?)`, pg.In(v))
  209 + }
208 if v, ok := queryOptions["depName"]; ok && len(v.(string)) > 0 { 210 if v, ok := queryOptions["depName"]; ok && len(v.(string)) > 0 {
209 query.Where(fmt.Sprintf(`ext->>'depName' like '%%%v%%'`, v)) 211 query.Where(fmt.Sprintf(`ext->>'depName' like '%%%v%%'`, v))
210 } 212 }
@@ -92,6 +92,17 @@ func (controller *RoleController) GetRoleRelatedUsers() { @@ -92,6 +92,17 @@ func (controller *RoleController) GetRoleRelatedUsers() {
92 controller.Response(data, err) 92 controller.Response(data, err)
93 } 93 }
94 94
  95 +func (controller *RoleController) RoleRelatedUsers() {
  96 + roleService := service.NewRoleService(nil)
  97 + getRoleRelatedUsersQuery := &query.GetRoleRelatedUsersQuery{}
  98 + controller.Unmarshal(getRoleRelatedUsersQuery)
  99 + roleId, _ := controller.GetInt64(":roleId")
  100 + getRoleRelatedUsersQuery.RoleId = roleId
  101 + getRoleRelatedUsersQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
  102 + data, err := roleService.GetRoleRelatedUsers(getRoleRelatedUsersQuery)
  103 + controller.Response(data, err)
  104 +}
  105 +
95 func (controller *RoleController) GetRoleAccessMenus() { 106 func (controller *RoleController) GetRoleAccessMenus() {
96 roleService := service.NewRoleService(nil) 107 roleService := service.NewRoleService(nil)
97 getRoleAccessMenusQuery := &query.GetRoleAccessMenusQuery{} 108 getRoleAccessMenusQuery := &query.GetRoleAccessMenusQuery{}
@@ -13,5 +13,5 @@ func init() { @@ -13,5 +13,5 @@ func init() {
13 web.Router("/auth/reset-phone", &controllers.AuthController{}, "Post:PhoneAuthResetPhone") 13 web.Router("/auth/reset-phone", &controllers.AuthController{}, "Post:PhoneAuthResetPhone")
14 web.Router("/auth/destroy-account", &controllers.AuthController{}, "Post:DestroyAccount") 14 web.Router("/auth/destroy-account", &controllers.AuthController{}, "Post:DestroyAccount")
15 web.Router("/auth/refresh-im", &controllers.AuthController{}, "Post:RefreshIM") 15 web.Router("/auth/refresh-im", &controllers.AuthController{}, "Post:RefreshIM")
16 - web.Router("/auth/user-base-info", &controllers.AuthController{}, "Post:UserInfo") 16 + web.Router("/auth/user-info", &controllers.AuthController{}, "Post:UserInfo")
17 } 17 }
@@ -12,6 +12,7 @@ func init() { @@ -12,6 +12,7 @@ func init() {
12 web.Router("/role/:roleId", &controllers.RoleController{}, "Delete:RemoveRole") 12 web.Router("/role/:roleId", &controllers.RoleController{}, "Delete:RemoveRole")
13 web.Router("/role/search", &controllers.RoleController{}, "Post:SearchRole") 13 web.Router("/role/search", &controllers.RoleController{}, "Post:SearchRole")
14 web.Router("/role/:roleId/related-user", &controllers.RoleController{}, "Get:GetRoleRelatedUsers") 14 web.Router("/role/:roleId/related-user", &controllers.RoleController{}, "Get:GetRoleRelatedUsers")
  15 + web.Router("/role/:roleId/related-user", &controllers.RoleController{}, "Post:RoleRelatedUsers")
15 web.Router("/role/:roleId/access-menus", &controllers.RoleController{}, "Get:GetRoleAccessMenus") 16 web.Router("/role/:roleId/access-menus", &controllers.RoleController{}, "Get:GetRoleAccessMenus")
16 web.Router("/role/:roleId/access-menus", &controllers.RoleController{}, "Put:UpdateRoleAccessMenus") 17 web.Router("/role/:roleId/access-menus", &controllers.RoleController{}, "Put:UpdateRoleAccessMenus")
17 web.Router("/role/assign", &controllers.RoleController{}, "Post:AssginRoleToUsers") 18 web.Router("/role/assign", &controllers.RoleController{}, "Post:AssginRoleToUsers")