正在显示
17 个修改的文件
包含
439 行增加
和
110 行删除
| 1 | +package factory | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/linmadan/egglib-go/core/application" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +// FastPgUser 快速返回领域用户 | ||
| 9 | +// | ||
| 10 | +// transactionContext 事务 | ||
| 11 | +// userId 用户ID | ||
| 12 | +func FastPgUser(transactionContext application.TransactionContext, userId int64) (domain.UserRepository, *domain.User, error) { | ||
| 13 | + var rep domain.UserRepository | ||
| 14 | + var mod *domain.User | ||
| 15 | + var err error | ||
| 16 | + if value, err := CreateUserRepository(map[string]interface{}{ | ||
| 17 | + "transactionContext": transactionContext, | ||
| 18 | + }); err != nil { | ||
| 19 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 20 | + } else { | ||
| 21 | + rep = value | ||
| 22 | + } | ||
| 23 | + if userId > 0 { | ||
| 24 | + if mod, err = rep.FindOne(map[string]interface{}{"userId": userId}); err != nil { | ||
| 25 | + if err == domain.ErrorNotFound { | ||
| 26 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该用户不存在") | ||
| 27 | + } | ||
| 28 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + return rep, mod, err | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +// FastPgUser 快速返回领域用户基础 | ||
| 35 | +// | ||
| 36 | +// transactionContext 事务 | ||
| 37 | +// userBaseId 用户基础ID | ||
| 38 | +func FastPgUserBase(transactionContext application.TransactionContext, userBaseId int64) (domain.UserBaseRepository, *domain.UserBase, error) { | ||
| 39 | + var rep domain.UserBaseRepository | ||
| 40 | + var mod *domain.UserBase | ||
| 41 | + var err error | ||
| 42 | + if value, err := CreateUserBaseRepository(map[string]interface{}{ | ||
| 43 | + "transactionContext": transactionContext, | ||
| 44 | + }); err != nil { | ||
| 45 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 46 | + } else { | ||
| 47 | + rep = value | ||
| 48 | + } | ||
| 49 | + if userBaseId > 0 { | ||
| 50 | + if mod, err = rep.FindOne(map[string]interface{}{"userBaseId": userBaseId}); err != nil { | ||
| 51 | + if err == domain.ErrorNotFound { | ||
| 52 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "用户基础不存在") | ||
| 53 | + } | ||
| 54 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + return rep, mod, err | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +// FastPgRole 快速返回领域角色 | ||
| 61 | +// | ||
| 62 | +// transactionContext 事务 | ||
| 63 | +// roleId 角色Id | ||
| 64 | +func FastPgRole(transactionContext application.TransactionContext, roleId int64) (domain.RoleRepository, *domain.Role, error) { | ||
| 65 | + var rep domain.RoleRepository | ||
| 66 | + var mod *domain.Role | ||
| 67 | + var err error | ||
| 68 | + if value, err := CreateRoleRepository(map[string]interface{}{ | ||
| 69 | + "transactionContext": transactionContext, | ||
| 70 | + }); err != nil { | ||
| 71 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 72 | + } else { | ||
| 73 | + rep = value | ||
| 74 | + } | ||
| 75 | + if roleId > 0 { | ||
| 76 | + if mod, err = rep.FindOne(map[string]interface{}{"roleId": roleId}); err != nil { | ||
| 77 | + if err == domain.ErrorNotFound { | ||
| 78 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该角色不存在") | ||
| 79 | + } | ||
| 80 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + return rep, mod, err | ||
| 84 | +} | ||
| 85 | + | ||
| 86 | +// FastPgRole 快速返回领域组织 | ||
| 87 | +// | ||
| 88 | +// transactionContext 事务 | ||
| 89 | +// orgId 组织Id | ||
| 90 | +func FastPgOrg(transactionContext application.TransactionContext, orgId int64) (domain.OrgRepository, *domain.Org, error) { | ||
| 91 | + var rep domain.OrgRepository | ||
| 92 | + var mod *domain.Org | ||
| 93 | + var err error | ||
| 94 | + if value, err := CreateOrgRepository(map[string]interface{}{ | ||
| 95 | + "transactionContext": transactionContext, | ||
| 96 | + }); err != nil { | ||
| 97 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 98 | + } else { | ||
| 99 | + rep = value | ||
| 100 | + } | ||
| 101 | + if orgId > 0 { | ||
| 102 | + if mod, err = rep.FindOne(map[string]interface{}{"orgId": orgId}); err != nil { | ||
| 103 | + if err == domain.ErrorNotFound { | ||
| 104 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该角色不存在") | ||
| 105 | + } | ||
| 106 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + return rep, mod, err | ||
| 110 | +} | ||
| 111 | + | ||
| 112 | +// FastPgCompany 快速返回领域公司 | ||
| 113 | +// | ||
| 114 | +// transactionContext 事务 | ||
| 115 | +// companyId 公司Id | ||
| 116 | +func FastPgCompany(transactionContext application.TransactionContext, companyId int64) (domain.CompanyRepository, *domain.Company, error) { | ||
| 117 | + var rep domain.CompanyRepository | ||
| 118 | + var mod *domain.Company | ||
| 119 | + var err error | ||
| 120 | + if value, err := CreateCompanyRepository(map[string]interface{}{ | ||
| 121 | + "transactionContext": transactionContext, | ||
| 122 | + }); err != nil { | ||
| 123 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 124 | + } else { | ||
| 125 | + rep = value | ||
| 126 | + } | ||
| 127 | + if companyId > 0 { | ||
| 128 | + if mod, err = rep.FindOne(map[string]interface{}{"companyId": companyId}); err != nil { | ||
| 129 | + if err == domain.ErrorNotFound { | ||
| 130 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该企业不存在") | ||
| 131 | + } | ||
| 132 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 133 | + } | ||
| 134 | + } | ||
| 135 | + return rep, mod, err | ||
| 136 | +} | ||
| 137 | + | ||
| 138 | +// FastPgMenu 快速返回领域菜单 | ||
| 139 | +// | ||
| 140 | +// transactionContext 事务 | ||
| 141 | +// menuId 菜单Id | ||
| 142 | +func FastPgMenu(transactionContext application.TransactionContext, menuId int64) (domain.MenuRepository, *domain.Menu, error) { | ||
| 143 | + var rep domain.MenuRepository | ||
| 144 | + var mod *domain.Menu | ||
| 145 | + var err error | ||
| 146 | + if value, err := CreateMenuRepository(map[string]interface{}{ | ||
| 147 | + "transactionContext": transactionContext, | ||
| 148 | + }); err != nil { | ||
| 149 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 150 | + } else { | ||
| 151 | + rep = value | ||
| 152 | + } | ||
| 153 | + if menuId > 0 { | ||
| 154 | + if mod, err = rep.FindOne(map[string]interface{}{"menuId": menuId}); err != nil { | ||
| 155 | + if err == domain.ErrorNotFound { | ||
| 156 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该菜单不存在") | ||
| 157 | + } | ||
| 158 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 159 | + } | ||
| 160 | + } | ||
| 161 | + return rep, mod, err | ||
| 162 | +} | ||
| 163 | + | ||
| 164 | +// FastPgCustomizeMenu 快速返回领域自定义菜单 | ||
| 165 | +// | ||
| 166 | +// transactionContext 事务 | ||
| 167 | +// customizeMenuId 自定义菜单Id | ||
| 168 | +func FastPgCustomizeMenu(transactionContext application.TransactionContext, customizeMenuId int64) (domain.CustomizeMenuRepository, *domain.CustomizeMenu, error) { | ||
| 169 | + var rep domain.CustomizeMenuRepository | ||
| 170 | + var mod *domain.CustomizeMenu | ||
| 171 | + var err error | ||
| 172 | + if value, err := CreateCustomizeMenuRepository(map[string]interface{}{ | ||
| 173 | + "transactionContext": transactionContext, | ||
| 174 | + }); err != nil { | ||
| 175 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 176 | + } else { | ||
| 177 | + rep = value | ||
| 178 | + } | ||
| 179 | + if customizeMenuId > 0 { | ||
| 180 | + if mod, err = rep.FindOne(map[string]interface{}{"customizeMenuId": customizeMenuId}); err != nil { | ||
| 181 | + if err == domain.ErrorNotFound { | ||
| 182 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "自定义菜单不存在") | ||
| 183 | + } | ||
| 184 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 185 | + } | ||
| 186 | + } | ||
| 187 | + return rep, mod, err | ||
| 188 | +} | ||
| 189 | + | ||
| 190 | +// FastPgAccountDestroyRecord 快速返回领域账号注销记录 | ||
| 191 | +// | ||
| 192 | +// transactionContext 事务 | ||
| 193 | +// accountDestroyRecordId 账号注销记录Id | ||
| 194 | +func FastPgAccountDestroyRecord(transactionContext application.TransactionContext, accountDestroyRecordId int64) (domain.AccountDestroyRecordRepository, *domain.AccountDestroyRecord, error) { | ||
| 195 | + var rep domain.AccountDestroyRecordRepository | ||
| 196 | + var mod *domain.AccountDestroyRecord | ||
| 197 | + var err error | ||
| 198 | + if value, err := CreateAccountDestroyRecordRepository(map[string]interface{}{ | ||
| 199 | + "transactionContext": transactionContext, | ||
| 200 | + }); err != nil { | ||
| 201 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 202 | + } else { | ||
| 203 | + rep = value | ||
| 204 | + } | ||
| 205 | + if accountDestroyRecordId > 0 { | ||
| 206 | + if mod, err = rep.FindOne(map[string]interface{}{"accountDestroyRecord": accountDestroyRecordId}); err != nil { | ||
| 207 | + if err == domain.ErrorNotFound { | ||
| 208 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "账号注销记录不存在") | ||
| 209 | + } | ||
| 210 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 211 | + } | ||
| 212 | + } | ||
| 213 | + return rep, mod, err | ||
| 214 | +} |
| @@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -16,6 +17,9 @@ type BatchEnableCommand struct { | @@ -16,6 +17,9 @@ type BatchEnableCommand struct { | ||
| 16 | 17 | ||
| 17 | func (batchEnableCommand *BatchEnableCommand) Valid(validation *validation.Validation) { | 18 | func (batchEnableCommand *BatchEnableCommand) Valid(validation *validation.Validation) { |
| 18 | //validation.SetError("CustomValid", "未实现的自定义认证") | 19 | //validation.SetError("CustomValid", "未实现的自定义认证") |
| 20 | + if !(batchEnableCommand.EnableStatus == int(domain.UserStatusEnable) || batchEnableCommand.EnableStatus == int(domain.UserStatusDisable)) { | ||
| 21 | + validation.SetError("CustomValid", "非法启用状态") | ||
| 22 | + } | ||
| 19 | } | 23 | } |
| 20 | 24 | ||
| 21 | func (batchEnableCommand *BatchEnableCommand) ValidateCommand() error { | 25 | func (batchEnableCommand *BatchEnableCommand) ValidateCommand() error { |
| @@ -10,15 +10,15 @@ import ( | @@ -10,15 +10,15 @@ import ( | ||
| 10 | 10 | ||
| 11 | type ListUserQuery struct { | 11 | type ListUserQuery struct { |
| 12 | // 查询偏离量 | 12 | // 查询偏离量 |
| 13 | - Offset int `cname:"查询偏离量" json:"offset" valid:"Required"` | 13 | + Offset int `cname:"查询偏离量" json:"offset"` |
| 14 | // 查询限制 | 14 | // 查询限制 |
| 15 | - Limit int `cname:"查询限制" json:"limit" valid:"Required"` | 15 | + Limit int `cname:"查询限制" json:"limit"` |
| 16 | // 企业id | 16 | // 企业id |
| 17 | - CompanyId int64 `cname:"企业id" json:"companyId,string,omitempty"` | 17 | + CompanyId int64 `cname:"企业id" json:"companyId,omitempty"` |
| 18 | // 组织ID | 18 | // 组织ID |
| 19 | - OrganizationId int64 `cname:"组织ID" json:"organizationId,string,omitempty"` | 19 | + OrganizationId int64 `cname:"组织ID" json:"organizationId,omitempty"` |
| 20 | // 部门编号 | 20 | // 部门编号 |
| 21 | - DepartmentId int64 `cname:"部门编号" json:"departmentId,string,omitempty"` | 21 | + DepartmentId int64 `cname:"部门编号" json:"departmentId,omitempty"` |
| 22 | // 用户姓名 | 22 | // 用户姓名 |
| 23 | UserName string `cname:"用户姓名" json:"userName,omitempty"` | 23 | UserName string `cname:"用户姓名" json:"userName,omitempty"` |
| 24 | // 部门名称 | 24 | // 部门名称 |
| @@ -51,10 +51,28 @@ func (userService *UserService) BatchEnable(batchEnableCommand *command.BatchEna | @@ -51,10 +51,28 @@ func (userService *UserService) BatchEnable(batchEnableCommand *command.BatchEna | ||
| 51 | defer func() { | 51 | defer func() { |
| 52 | transactionContext.RollbackTransaction() | 52 | transactionContext.RollbackTransaction() |
| 53 | }() | 53 | }() |
| 54 | + userRepository, _, err := factory.FastPgUser(transactionContext, 0) | ||
| 55 | + if err != nil { | ||
| 56 | + return nil, err | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + for i := 0; i < len(batchEnableCommand.UserIds); i++ { | ||
| 60 | + if user, err := userRepository.FindOne(map[string]interface{}{"userId": batchEnableCommand.UserIds[i]}); err != nil { | ||
| 61 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 62 | + } else { | ||
| 63 | + if err := user.SetEnableStatus(batchEnableCommand.EnableStatus); err != nil { | ||
| 64 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 65 | + } | ||
| 66 | + if _, err := userRepository.Save(user); err != nil { | ||
| 67 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | + | ||
| 54 | if err := transactionContext.CommitTransaction(); err != nil { | 72 | if err := transactionContext.CommitTransaction(); err != nil { |
| 55 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 73 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 56 | } | 74 | } |
| 57 | - return nil, nil | 75 | + return struct{}{}, nil |
| 58 | } | 76 | } |
| 59 | 77 | ||
| 60 | // 批量重置密码 | 78 | // 批量重置密码 |
| @@ -72,10 +90,28 @@ func (userService *UserService) BatchResetPassword(batchResetPasswordCommand *co | @@ -72,10 +90,28 @@ func (userService *UserService) BatchResetPassword(batchResetPasswordCommand *co | ||
| 72 | defer func() { | 90 | defer func() { |
| 73 | transactionContext.RollbackTransaction() | 91 | transactionContext.RollbackTransaction() |
| 74 | }() | 92 | }() |
| 93 | + | ||
| 94 | + for i := range batchResetPasswordCommand.UserIds { | ||
| 95 | + _, user, err := factory.FastPgUser(transactionContext, batchResetPasswordCommand.UserIds[i]) | ||
| 96 | + if err != nil { | ||
| 97 | + return nil, err | ||
| 98 | + } | ||
| 99 | + userBaseRepository, userBase, err := factory.FastPgUserBase(transactionContext, user.UserBaseId) | ||
| 100 | + if err != nil { | ||
| 101 | + return nil, err | ||
| 102 | + } | ||
| 103 | + if err := userBase.ResetPassword(userBase.Account, batchResetPasswordCommand.Password); err != nil { | ||
| 104 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 105 | + } | ||
| 106 | + if _, err := userBaseRepository.Save(userBase); err != nil { | ||
| 107 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + | ||
| 75 | if err := transactionContext.CommitTransaction(); err != nil { | 111 | if err := transactionContext.CommitTransaction(); err != nil { |
| 76 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 112 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 77 | } | 113 | } |
| 78 | - return nil, nil | 114 | + return struct{}{}, nil |
| 79 | } | 115 | } |
| 80 | 116 | ||
| 81 | // 创建共创用户 | 117 | // 创建共创用户 |
| @@ -249,26 +285,25 @@ func (userService *UserService) GetUser(getUserQuery *query.GetUserQuery) (inter | @@ -249,26 +285,25 @@ func (userService *UserService) GetUser(getUserQuery *query.GetUserQuery) (inter | ||
| 249 | defer func() { | 285 | defer func() { |
| 250 | transactionContext.RollbackTransaction() | 286 | transactionContext.RollbackTransaction() |
| 251 | }() | 287 | }() |
| 252 | - var userRepository domain.UserRepository | ||
| 253 | - if value, err := factory.CreateUserRepository(map[string]interface{}{ | ||
| 254 | - "transactionContext": transactionContext, | ||
| 255 | - }); err != nil { | ||
| 256 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 257 | - } else { | ||
| 258 | - userRepository = value | ||
| 259 | - } | ||
| 260 | - user, err := userRepository.FindOne(map[string]interface{}{"userId": getUserQuery.UserId}) | 288 | + _, user, err := factory.FastPgUser(transactionContext, getUserQuery.UserId) |
| 261 | if err != nil { | 289 | if err != nil { |
| 262 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 290 | + return nil, err |
| 263 | } | 291 | } |
| 264 | - if user == nil { | ||
| 265 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getUserQuery.UserId))) | ||
| 266 | - } else { | ||
| 267 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
| 268 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 269 | - } | ||
| 270 | - return user, nil | 292 | + _, dep, _ := factory.FastPgOrg(transactionContext, user.DepartmentId) |
| 293 | + _, org, _ := factory.FastPgOrg(transactionContext, user.OrganizationId) | ||
| 294 | + _, company, _ := factory.FastPgCompany(transactionContext, user.CompanyId) | ||
| 295 | + _, userBase, _ := factory.FastPgUserBase(transactionContext, user.UserBaseId) | ||
| 296 | + if dep != nil && org != nil && company != nil && userBase != nil { | ||
| 297 | + user.Department = dep.ConvDep() | ||
| 298 | + user.Organization = org.CloneSample() | ||
| 299 | + user.Company = company.CloneSample() | ||
| 300 | + user.UserInfo = userBase.UserInfo | ||
| 301 | + } | ||
| 302 | + | ||
| 303 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 304 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 271 | } | 305 | } |
| 306 | + return user, nil | ||
| 272 | } | 307 | } |
| 273 | 308 | ||
| 274 | // 返回用户有权限的菜单 | 309 | // 返回用户有权限的菜单 |
| @@ -446,22 +481,12 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser | @@ -446,22 +481,12 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser | ||
| 446 | defer func() { | 481 | defer func() { |
| 447 | transactionContext.RollbackTransaction() | 482 | transactionContext.RollbackTransaction() |
| 448 | }() | 483 | }() |
| 449 | - var userRepository domain.UserRepository | ||
| 450 | - if value, err := factory.CreateUserRepository(map[string]interface{}{ | ||
| 451 | - "transactionContext": transactionContext, | ||
| 452 | - }); err != nil { | ||
| 453 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 454 | - } else { | ||
| 455 | - userRepository = value | ||
| 456 | - } | ||
| 457 | - user, err := userRepository.FindOne(map[string]interface{}{"userId": updateUserCommand.UserId}) | 484 | + userRepository, user, err := factory.FastPgUser(transactionContext, updateUserCommand.UserId) |
| 458 | if err != nil { | 485 | if err != nil { |
| 459 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 460 | - } | ||
| 461 | - if user == nil { | ||
| 462 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateUserCommand.UserId))) | 486 | + return nil, err |
| 463 | } | 487 | } |
| 464 | - if err := user.Update(tool_funs.SimpleStructToMap(updateUserCommand)); err != nil { | 488 | + updateData := tool_funs.SimpleStructToMap(updateUserCommand) |
| 489 | + if err := user.Update(updateData); err != nil { | ||
| 465 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 490 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
| 466 | } | 491 | } |
| 467 | if user, err := userRepository.Save(user); err != nil { | 492 | if user, err := userRepository.Save(user); err != nil { |
| @@ -81,3 +81,11 @@ func (company *Company) Update(data map[string]interface{}) error { | @@ -81,3 +81,11 @@ func (company *Company) Update(data map[string]interface{}) error { | ||
| 81 | } | 81 | } |
| 82 | return nil | 82 | return nil |
| 83 | } | 83 | } |
| 84 | + | ||
| 85 | +func (company *Company) CloneSample() *Company { | ||
| 86 | + return &Company{ | ||
| 87 | + CompanyId: company.CompanyId, | ||
| 88 | + Status: company.Status, | ||
| 89 | + CompanyInfo: company.CompanyInfo, | ||
| 90 | + } | ||
| 91 | +} |
| @@ -5,19 +5,19 @@ import "time" | @@ -5,19 +5,19 @@ import "time" | ||
| 5 | // 公司信息 | 5 | // 公司信息 |
| 6 | type CompanyInfo struct { | 6 | type CompanyInfo struct { |
| 7 | // 企业名称 | 7 | // 企业名称 |
| 8 | - CompanyName string `json:"companyName"` | 8 | + CompanyName string `json:"companyName,omitempty"` |
| 9 | // 规模 | 9 | // 规模 |
| 10 | - Scale string `json:"scale"` | 10 | + Scale string `json:"scale,omitempty"` |
| 11 | // 公司Logo地址 | 11 | // 公司Logo地址 |
| 12 | - Logo string `json:"logo"` | 12 | + Logo string `json:"logo,omitempty"` |
| 13 | // 公司地址 | 13 | // 公司地址 |
| 14 | - Address string `json:"address"` | 14 | + Address string `json:"address,omitempty"` |
| 15 | // 所属行业 | 15 | // 所属行业 |
| 16 | - IndustryCategory string `json:"industryCategory"` | 16 | + IndustryCategory string `json:"industryCategory,omitempty"` |
| 17 | // 联系人 | 17 | // 联系人 |
| 18 | //Contacts string `json:"contacts"` | 18 | //Contacts string `json:"contacts"` |
| 19 | // 注册时间 | 19 | // 注册时间 |
| 20 | - RegisteredTime time.Time `json:"registeredTime"` | 20 | + RegisteredTime time.Time `json:"registeredTime,omitempty"` |
| 21 | // 状态 1:已注册 2:待认证 3:已认证 | 21 | // 状态 1:已注册 2:待认证 3:已认证 |
| 22 | //Status int `json:"status"` | 22 | //Status int `json:"status"` |
| 23 | } | 23 | } |
| @@ -113,6 +113,16 @@ type Department struct { | @@ -113,6 +113,16 @@ type Department struct { | ||
| 113 | // 部门编号 | 113 | // 部门编号 |
| 114 | DepartmentNumber string `json:"departmentNumber"` | 114 | DepartmentNumber string `json:"departmentNumber"` |
| 115 | } | 115 | } |
| 116 | +type SampleOrg struct { | ||
| 117 | + // 组织ID | ||
| 118 | + OrgId int64 `json:"orgId,omitempty"` | ||
| 119 | + // 企业id | ||
| 120 | + CompanyId int64 `json:"companyId,omitempty"` | ||
| 121 | + // 组织名称 | ||
| 122 | + OrgName string `json:"orgName,omitempty"` | ||
| 123 | + // 组织编码 | ||
| 124 | + OrgCode string `json:"orgCode,omitempty"` | ||
| 125 | +} | ||
| 116 | 126 | ||
| 117 | // 通过组织获取当前部门信息 | 127 | // 通过组织获取当前部门信息 |
| 118 | func (org *Org) ConvDep() *Department { | 128 | func (org *Org) ConvDep() *Department { |
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "fmt" | ||
| 4 | "time" | 5 | "time" |
| 5 | ) | 6 | ) |
| 6 | 7 | ||
| @@ -36,14 +37,8 @@ type User struct { | @@ -36,14 +37,8 @@ type User struct { | ||
| 36 | UserCode string `json:"userCode,omitempty"` | 37 | UserCode string `json:"userCode,omitempty"` |
| 37 | // 组织机构 | 38 | // 组织机构 |
| 38 | OrganizationId int64 `json:"organizationId,omitempty"` | 39 | OrganizationId int64 `json:"organizationId,omitempty"` |
| 39 | - // 组织机构 | ||
| 40 | - Organization *Org `json:"org,omitempty"` | ||
| 41 | // 所属部门 | 40 | // 所属部门 |
| 42 | DepartmentId int64 `json:"departmentId,omitempty"` | 41 | DepartmentId int64 `json:"departmentId,omitempty"` |
| 43 | - // 部门 | ||
| 44 | - Department *Department `json:"department,omitempty"` | ||
| 45 | - // 用户信息 (冗余,数据存在userBase里面) | ||
| 46 | - UserInfo *UserInfo `json:"userInfo,omitempty"` | ||
| 47 | // 用户关联的组织 | 42 | // 用户关联的组织 |
| 48 | UserOrg []*Org `json:"userOrg,omitempty"` | 43 | UserOrg []*Org `json:"userOrg,omitempty"` |
| 49 | // 用户关联的角色 | 44 | // 用户关联的角色 |
| @@ -60,6 +55,15 @@ type User struct { | @@ -60,6 +55,15 @@ type User struct { | ||
| 60 | CreatedAt time.Time `json:"createdAt,omitempty"` | 55 | CreatedAt time.Time `json:"createdAt,omitempty"` |
| 61 | // 更新时间 | 56 | // 更新时间 |
| 62 | UpdatedAt time.Time `json:"updatedAt,omitempty"` | 57 | UpdatedAt time.Time `json:"updatedAt,omitempty"` |
| 58 | + | ||
| 59 | + // 用户信息 (冗余,数据存在userBase里面) | ||
| 60 | + UserInfo *UserInfo `json:"userInfo,omitempty"` | ||
| 61 | + // 企业id | ||
| 62 | + Company *Company `json:"company,omitempty"` | ||
| 63 | + // 组织机构 | ||
| 64 | + Organization *Org `json:"org,omitempty"` | ||
| 65 | + // 部门 | ||
| 66 | + Department *Department `json:"department,omitempty"` | ||
| 63 | } | 67 | } |
| 64 | 68 | ||
| 65 | type UserRepository interface { | 69 | type UserRepository interface { |
| @@ -77,21 +81,18 @@ func (user *User) Identify() interface{} { | @@ -77,21 +81,18 @@ func (user *User) Identify() interface{} { | ||
| 77 | } | 81 | } |
| 78 | 82 | ||
| 79 | func (user *User) Update(data map[string]interface{}) error { | 83 | func (user *User) Update(data map[string]interface{}) error { |
| 80 | - if userId, ok := data["userId"]; ok { | ||
| 81 | - user.UserId = userId.(int64) | ||
| 82 | - } | ||
| 83 | - if companyId, ok := data["companyId"]; ok { | ||
| 84 | - user.CompanyId = companyId.(int64) | ||
| 85 | - } | ||
| 86 | - if userBaseId, ok := data["userBaseId"]; ok { | ||
| 87 | - user.UserBaseId = userBaseId.(int64) | ||
| 88 | - } | 84 | + //if companyId, ok := data["companyId"]; ok { |
| 85 | + // user.CompanyId = companyId.(int64) | ||
| 86 | + //} | ||
| 87 | + //if userBaseId, ok := data["userBaseId"]; ok { | ||
| 88 | + // user.UserBaseId = userBaseId.(int64) | ||
| 89 | + //} | ||
| 89 | //if userType, ok := data["userType"]; ok { | 90 | //if userType, ok := data["userType"]; ok { |
| 90 | // user.UserType = userType.(int) | 91 | // user.UserType = userType.(int) |
| 91 | //} | 92 | //} |
| 92 | - if userCode, ok := data["userCode"]; ok { | ||
| 93 | - user.UserCode = userCode.(string) | ||
| 94 | - } | 93 | + //if userCode, ok := data["userCode"]; ok { |
| 94 | + // user.UserCode = userCode.(string) | ||
| 95 | + //} | ||
| 95 | if organizationId, ok := data["organizationId"]; ok { | 96 | if organizationId, ok := data["organizationId"]; ok { |
| 96 | user.OrganizationId = organizationId.(int64) | 97 | user.OrganizationId = organizationId.(int64) |
| 97 | } | 98 | } |
| @@ -143,9 +144,6 @@ func (user *User) Update(data map[string]interface{}) error { | @@ -143,9 +144,6 @@ func (user *User) Update(data map[string]interface{}) error { | ||
| 143 | if parentDepName, ok := data["parentDepName"]; ok { | 144 | if parentDepName, ok := data["parentDepName"]; ok { |
| 144 | user.Ext.ParentDepName = parentDepName.(string) | 145 | user.Ext.ParentDepName = parentDepName.(string) |
| 145 | } | 146 | } |
| 146 | - if createdAt, ok := data["createdAt"]; ok { | ||
| 147 | - user.CreatedAt = createdAt.(time.Time) | ||
| 148 | - } | ||
| 149 | if updatedAt, ok := data["updatedAt"]; ok { | 147 | if updatedAt, ok := data["updatedAt"]; ok { |
| 150 | user.UpdatedAt = updatedAt.(time.Time) | 148 | user.UpdatedAt = updatedAt.(time.Time) |
| 151 | } | 149 | } |
| @@ -159,7 +157,24 @@ type UserStatus int | @@ -159,7 +157,24 @@ type UserStatus int | ||
| 159 | // | 157 | // |
| 160 | // accountAfter 变更后的账号 | 158 | // accountAfter 变更后的账号 |
| 161 | func (user *User) DestroyAccount(accountAfter string) error { | 159 | func (user *User) DestroyAccount(accountAfter string) error { |
| 162 | - user.EnableStatus = int(UserStatusDestroy) | 160 | + if err := user.SetEnableStatus(int(UserStatusDestroy)); err != nil { |
| 161 | + return err | ||
| 162 | + } | ||
| 163 | user.Ext.Phone = accountAfter | 163 | user.Ext.Phone = accountAfter |
| 164 | return nil | 164 | return nil |
| 165 | } | 165 | } |
| 166 | + | ||
| 167 | +func (user *User) SetEnableStatus(enableStatus int) error { | ||
| 168 | + userStatus := UserStatus(user.EnableStatus) | ||
| 169 | + if userStatus == UserStatusDestroy { | ||
| 170 | + return fmt.Errorf("账号已注销") | ||
| 171 | + } | ||
| 172 | + if user.EnableStatus == enableStatus { | ||
| 173 | + return fmt.Errorf("重复设置状态") | ||
| 174 | + } | ||
| 175 | + if !(userStatus == UserStatusEnable || userStatus == UserStatusDisable || userStatus == UserStatusDestroy) { | ||
| 176 | + return fmt.Errorf("非法启用状态") | ||
| 177 | + } | ||
| 178 | + user.EnableStatus = enableStatus | ||
| 179 | + return nil | ||
| 180 | +} |
| @@ -83,9 +83,10 @@ func (ptr *PgSignUpCompanyService) SignUpCompany(registerPhone string, password | @@ -83,9 +83,10 @@ func (ptr *PgSignUpCompanyService) SignUpCompany(registerPhone string, password | ||
| 83 | EnableStatus: int(domain.UserStatusEnable), | 83 | EnableStatus: int(domain.UserStatusEnable), |
| 84 | UserInfo: userInfo, | 84 | UserInfo: userInfo, |
| 85 | Ext: &domain.Ext{ | 85 | Ext: &domain.Ext{ |
| 86 | - OrgName: org.OrgName, | ||
| 87 | - DepName: org.OrgName, | ||
| 88 | - Phone: registerPhone, | 86 | + UserName: userInfo.UserName, |
| 87 | + OrgName: org.OrgName, | ||
| 88 | + DepName: org.OrgName, | ||
| 89 | + Phone: registerPhone, | ||
| 89 | }, | 90 | }, |
| 90 | CreatedAt: time.Now(), | 91 | CreatedAt: time.Now(), |
| 91 | UpdatedAt: time.Now(), | 92 | UpdatedAt: time.Now(), |
| @@ -165,8 +165,19 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int | @@ -165,8 +165,19 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int | ||
| 165 | var userModels []*models.User | 165 | var userModels []*models.User |
| 166 | users := make([]*domain.User, 0) | 166 | users := make([]*domain.User, 0) |
| 167 | query := sqlbuilder.BuildQuery(tx.Model(&userModels), queryOptions) | 167 | query := sqlbuilder.BuildQuery(tx.Model(&userModels), queryOptions) |
| 168 | + query.SetWhereByQueryOption("company_id=?", "companyId") | ||
| 169 | + query.SetWhereByQueryOption("organization_id=?", "organizationId") | ||
| 168 | query.SetWhereByQueryOption("user_base_id=?", "userBaseId") | 170 | query.SetWhereByQueryOption("user_base_id=?", "userBaseId") |
| 169 | - query.SetOffsetAndLimit(20) | 171 | + if v, ok := queryOptions["depName"]; ok && len(v.(string)) > 0 { |
| 172 | + query.Where(fmt.Sprintf(`ext->>'depName' like '%%%v%%'`, v)) | ||
| 173 | + } | ||
| 174 | + if v, ok := queryOptions["userName"]; ok && len(v.(string)) > 0 { | ||
| 175 | + query.Where(fmt.Sprintf(`ext->>'userName' like '%%%v%%'`, v)) | ||
| 176 | + } | ||
| 177 | + if v, ok := queryOptions["cooperationCompany"]; ok && len(v.(string)) > 0 { | ||
| 178 | + query.Where(fmt.Sprintf(`cooperation_info->>'cooperationCompany'' like '%%%v%%'`, v)) | ||
| 179 | + } | ||
| 180 | + query.SetOffsetAndLimit(999) | ||
| 170 | query.SetOrderDirect("user_id", "DESC") | 181 | query.SetOrderDirect("user_id", "DESC") |
| 171 | if count, err := query.SelectAndCount(); err != nil { | 182 | if count, err := query.SelectAndCount(); err != nil { |
| 172 | return 0, users, err | 183 | return 0, users, err |
| @@ -126,3 +126,11 @@ func (controller *UserController) UpdateCooperator() { | @@ -126,3 +126,11 @@ func (controller *UserController) UpdateCooperator() { | ||
| 126 | data, err := userService.UpdateCooperator(updateCooperatorCommand) | 126 | data, err := userService.UpdateCooperator(updateCooperatorCommand) |
| 127 | controller.Response(data, err) | 127 | controller.Response(data, err) |
| 128 | } | 128 | } |
| 129 | + | ||
| 130 | +func (controller *UserController) SearchUser() { | ||
| 131 | + userService := service.NewUserService(nil) | ||
| 132 | + listUserQuery := &query.ListUserQuery{} | ||
| 133 | + Must(controller.Unmarshal(listUserQuery)) | ||
| 134 | + data, err := userService.ListUser(listUserQuery) | ||
| 135 | + controller.Response(data, err) | ||
| 136 | +} |
| @@ -10,7 +10,7 @@ func init() { | @@ -10,7 +10,7 @@ func init() { | ||
| 10 | web.Router("/user/:userId", &controllers.UserController{}, "Put:UpdateUser") | 10 | web.Router("/user/:userId", &controllers.UserController{}, "Put:UpdateUser") |
| 11 | web.Router("/user/:userId", &controllers.UserController{}, "Get:GetUser") | 11 | web.Router("/user/:userId", &controllers.UserController{}, "Get:GetUser") |
| 12 | web.Router("/user/:userId", &controllers.UserController{}, "Delete:RemoveUser") | 12 | web.Router("/user/:userId", &controllers.UserController{}, "Delete:RemoveUser") |
| 13 | - web.Router("/user/search", &controllers.UserController{}, "Post:ListUser") | 13 | + web.Router("/user/search", &controllers.UserController{}, "Post:SearchUser") |
| 14 | web.Router("/user/:userId/access-menus", &controllers.UserController{}, "Get:GetUserAccessMenus") | 14 | web.Router("/user/:userId/access-menus", &controllers.UserController{}, "Get:GetUserAccessMenus") |
| 15 | web.Router("/user/:userId/profile", &controllers.UserController{}, "Get:GetUserProfile") | 15 | web.Router("/user/:userId/profile", &controllers.UserController{}, "Get:GetUserProfile") |
| 16 | web.Router("/user/batch-add", &controllers.UserController{}, "Post:BatchAdd") | 16 | web.Router("/user/batch-add", &controllers.UserController{}, "Post:BatchAdd") |
| @@ -11,13 +11,19 @@ import ( | @@ -11,13 +11,19 @@ import ( | ||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | var _ = Describe("批量修改启用状态", func() { | 13 | var _ = Describe("批量修改启用状态", func() { |
| 14 | - return | ||
| 15 | - var userId int64 | 14 | + var Id int64 |
| 16 | BeforeEach(func() { | 15 | BeforeEach(func() { |
| 17 | - _, err := pG.DB.QueryOne( | ||
| 18 | - pg.Scan(&userId), | ||
| 19 | - "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
| 20 | - "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | 16 | + var err error |
| 17 | + _, err = pG.DB.QueryOne( | ||
| 18 | + pg.Scan(&Id), | ||
| 19 | + "INSERT INTO \"users\".\"user_base\"(\"user_base_id\", \"user_info\", \"account\", \"password\", \"im\", \"related_user\", \"status\", \"created_at\", \"updated_at\") VALUES (999, '{\"phone\": \"phone\", \"userName\": \"string\"}', 'phone', 'string', '{\"accid\": \"\", \"imToken\": \"\", \"csAccountId\": \"\"}', '{999}', 1, '2021-07-24 10:16:17.680805+08', '2021-07-24 10:16:17.680805+08') RETURNING user_base_id;", | ||
| 20 | + ) | ||
| 21 | + Expect(err).NotTo(HaveOccurred()) | ||
| 22 | + | ||
| 23 | + _, err = pG.DB.QueryOne( | ||
| 24 | + pg.Scan(&Id), | ||
| 25 | + "INSERT INTO \"users\".\"user\"(\"user_id\", \"company_id\", \"user_base_id\", \"user_type\", \"user_code\", \"organization_id\", \"department_id\", \"user_org\", \"user_role\", \"favorite_menus\", \"cooperation_info\", \"enable_status\", \"ext\", \"created_at\", \"updated_at\") VALUES (999, 5, 999, 1025, 'ADMIN01', 5, 5, '[{\"orgId\": 5, \"orgName\": \"string1\", \"createdAt\": \"0001-01-01T00:00:00Z\", \"deletedAt\": \"0001-01-01T00:00:00Z\", \"updatedAt\": \"0001-01-01T00:00:00Z\"}]', '[{\"ext\": {\"orgName\": \"string1\"}, \"roleId\": 5, \"roleName\": \"企业管理员\", \"createdAt\": \"0001-01-01T00:00:00Z\", \"updatedAt\": \"0001-01-01T00:00:00Z\"}]', '[]', '{\"cooperationCompany\": \"\", \"cooperationDeadline\": \"0001-01-01T00:00:00Z\"}', 1, '{\"phone\": \"18860183031\", \"depName\": \"string1\", \"orgName\": \"string1\"}', '2021-07-24 10:16:17.680805+08', '2021-07-24 10:16:17.680805+08');\n", | ||
| 26 | + ) | ||
| 21 | Expect(err).NotTo(HaveOccurred()) | 27 | Expect(err).NotTo(HaveOccurred()) |
| 22 | }) | 28 | }) |
| 23 | Describe("批量修改启用状态", func() { | 29 | Describe("批量修改启用状态", func() { |
| @@ -25,8 +31,8 @@ var _ = Describe("批量修改启用状态", func() { | @@ -25,8 +31,8 @@ var _ = Describe("批量修改启用状态", func() { | ||
| 25 | It("", func() { | 31 | It("", func() { |
| 26 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 32 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 27 | body := map[string]interface{}{ | 33 | body := map[string]interface{}{ |
| 28 | - "userIds": "array", | ||
| 29 | - "enableStatus": "int", | 34 | + "userIds": []int64{999}, |
| 35 | + "enableStatus": 2, | ||
| 30 | } | 36 | } |
| 31 | httpExpect.POST("/user/batch-enable"). | 37 | httpExpect.POST("/user/batch-enable"). |
| 32 | WithJSON(body). | 38 | WithJSON(body). |
| @@ -41,7 +47,9 @@ var _ = Describe("批量修改启用状态", func() { | @@ -41,7 +47,9 @@ var _ = Describe("批量修改启用状态", func() { | ||
| 41 | }) | 47 | }) |
| 42 | }) | 48 | }) |
| 43 | AfterEach(func() { | 49 | AfterEach(func() { |
| 44 | - _, err := pG.DB.Exec("DELETE FROM users WHERE true") | 50 | + _, err := pG.DB.Exec("DELETE FROM users.user_base WHERE user_base_id = 999") |
| 51 | + Expect(err).NotTo(HaveOccurred()) | ||
| 52 | + _, err = pG.DB.Exec(`DELETE FROM users."user" WHERE user_id = 999`) | ||
| 45 | Expect(err).NotTo(HaveOccurred()) | 53 | Expect(err).NotTo(HaveOccurred()) |
| 46 | }) | 54 | }) |
| 47 | }) | 55 | }) |
| @@ -11,13 +11,19 @@ import ( | @@ -11,13 +11,19 @@ import ( | ||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | var _ = Describe("批量重置密码", func() { | 13 | var _ = Describe("批量重置密码", func() { |
| 14 | - return | ||
| 15 | - var userId int64 | 14 | + var Id int64 |
| 16 | BeforeEach(func() { | 15 | BeforeEach(func() { |
| 17 | - _, err := pG.DB.QueryOne( | ||
| 18 | - pg.Scan(&userId), | ||
| 19 | - "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
| 20 | - "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | 16 | + var err error |
| 17 | + _, err = pG.DB.QueryOne( | ||
| 18 | + pg.Scan(&Id), | ||
| 19 | + "INSERT INTO \"users\".\"user_base\"(\"user_base_id\", \"user_info\", \"account\", \"password\", \"im\", \"related_user\", \"status\", \"created_at\", \"updated_at\") VALUES (999, '{\"phone\": \"phone\", \"userName\": \"string\"}', 'phone', 'string', '{\"accid\": \"\", \"imToken\": \"\", \"csAccountId\": \"\"}', '{999}', 1, '2021-07-24 10:16:17.680805+08', '2021-07-24 10:16:17.680805+08') RETURNING user_base_id;", | ||
| 20 | + ) | ||
| 21 | + Expect(err).NotTo(HaveOccurred()) | ||
| 22 | + | ||
| 23 | + _, err = pG.DB.QueryOne( | ||
| 24 | + pg.Scan(&Id), | ||
| 25 | + "INSERT INTO \"users\".\"user\"(\"user_id\", \"company_id\", \"user_base_id\", \"user_type\", \"user_code\", \"organization_id\", \"department_id\", \"user_org\", \"user_role\", \"favorite_menus\", \"cooperation_info\", \"enable_status\", \"ext\", \"created_at\", \"updated_at\") VALUES (999, 5, 999, 1025, 'ADMIN01', 5, 5, '[{\"orgId\": 5, \"orgName\": \"string1\", \"createdAt\": \"0001-01-01T00:00:00Z\", \"deletedAt\": \"0001-01-01T00:00:00Z\", \"updatedAt\": \"0001-01-01T00:00:00Z\"}]', '[{\"ext\": {\"orgName\": \"string1\"}, \"roleId\": 5, \"roleName\": \"企业管理员\", \"createdAt\": \"0001-01-01T00:00:00Z\", \"updatedAt\": \"0001-01-01T00:00:00Z\"}]', '[]', '{\"cooperationCompany\": \"\", \"cooperationDeadline\": \"0001-01-01T00:00:00Z\"}', 1, '{\"phone\": \"18860183031\", \"depName\": \"string1\", \"orgName\": \"string1\"}', '2021-07-24 10:16:17.680805+08', '2021-07-24 10:16:17.680805+08');\n", | ||
| 26 | + ) | ||
| 21 | Expect(err).NotTo(HaveOccurred()) | 27 | Expect(err).NotTo(HaveOccurred()) |
| 22 | }) | 28 | }) |
| 23 | Describe("批量重置密码", func() { | 29 | Describe("批量重置密码", func() { |
| @@ -25,8 +31,8 @@ var _ = Describe("批量重置密码", func() { | @@ -25,8 +31,8 @@ var _ = Describe("批量重置密码", func() { | ||
| 25 | It("", func() { | 31 | It("", func() { |
| 26 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 32 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 27 | body := map[string]interface{}{ | 33 | body := map[string]interface{}{ |
| 28 | - "userIds": "array", | ||
| 29 | - "password": "string", | 34 | + "userIds": []int64{999}, |
| 35 | + "password": "string999", | ||
| 30 | } | 36 | } |
| 31 | httpExpect.POST("/user/batch-reset-password"). | 37 | httpExpect.POST("/user/batch-reset-password"). |
| 32 | WithJSON(body). | 38 | WithJSON(body). |
| @@ -41,7 +47,9 @@ var _ = Describe("批量重置密码", func() { | @@ -41,7 +47,9 @@ var _ = Describe("批量重置密码", func() { | ||
| 41 | }) | 47 | }) |
| 42 | }) | 48 | }) |
| 43 | AfterEach(func() { | 49 | AfterEach(func() { |
| 44 | - _, err := pG.DB.Exec("DELETE FROM users WHERE true") | 50 | + _, err := pG.DB.Exec("DELETE FROM users.user_base WHERE user_base_id = 999") |
| 51 | + Expect(err).NotTo(HaveOccurred()) | ||
| 52 | + _, err = pG.DB.Exec(`DELETE FROM users."user" WHERE user_id = 999`) | ||
| 45 | Expect(err).NotTo(HaveOccurred()) | 53 | Expect(err).NotTo(HaveOccurred()) |
| 46 | }) | 54 | }) |
| 47 | }) | 55 | }) |
| @@ -24,6 +24,7 @@ var _ = Describe("创建共创用户", func() { | @@ -24,6 +24,7 @@ var _ = Describe("创建共创用户", func() { | ||
| 24 | It("", func() { | 24 | It("", func() { |
| 25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 26 | body := map[string]interface{}{ | 26 | body := map[string]interface{}{ |
| 27 | + "companyId": 999, | ||
| 27 | "cooperationCompany": "string", | 28 | "cooperationCompany": "string", |
| 28 | "cooperationDeadline": "2021-07-25T15:11:56+08:00", | 29 | "cooperationDeadline": "2021-07-25T15:11:56+08:00", |
| 29 | "email": "string", | 30 | "email": "string", |
| @@ -11,20 +11,26 @@ import ( | @@ -11,20 +11,26 @@ import ( | ||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | var _ = Describe("返回", func() { | 13 | var _ = Describe("返回", func() { |
| 14 | - return | ||
| 15 | - var userId int64 | 14 | + var Id int64 |
| 16 | BeforeEach(func() { | 15 | BeforeEach(func() { |
| 17 | - _, err := pG.DB.QueryOne( | ||
| 18 | - pg.Scan(&userId), | ||
| 19 | - "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
| 20 | - "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | 16 | + var err error |
| 17 | + _, err = pG.DB.QueryOne( | ||
| 18 | + pg.Scan(&Id), | ||
| 19 | + "INSERT INTO \"users\".\"user_base\"(\"user_base_id\", \"user_info\", \"account\", \"password\", \"im\", \"related_user\", \"status\", \"created_at\", \"updated_at\") VALUES (999, '{\"phone\": \"phone\", \"userName\": \"string\"}', 'phone', 'string', '{\"accid\": \"\", \"imToken\": \"\", \"csAccountId\": \"\"}', '{999}', 1, '2021-07-24 10:16:17.680805+08', '2021-07-24 10:16:17.680805+08') RETURNING user_base_id;", | ||
| 20 | + ) | ||
| 21 | + Expect(err).NotTo(HaveOccurred()) | ||
| 22 | + | ||
| 23 | + _, err = pG.DB.QueryOne( | ||
| 24 | + pg.Scan(&Id), | ||
| 25 | + "INSERT INTO \"users\".\"user\"(\"user_id\", \"company_id\", \"user_base_id\", \"user_type\", \"user_code\", \"organization_id\", \"department_id\", \"user_org\", \"user_role\", \"favorite_menus\", \"cooperation_info\", \"enable_status\", \"ext\", \"created_at\", \"updated_at\") VALUES (999, 5, 999, 1025, 'ADMIN01', 5, 5, '[{\"orgId\": 5, \"orgName\": \"string1\", \"createdAt\": \"0001-01-01T00:00:00Z\", \"deletedAt\": \"0001-01-01T00:00:00Z\", \"updatedAt\": \"0001-01-01T00:00:00Z\"}]', '[{\"ext\": {\"orgName\": \"string1\"}, \"roleId\": 5, \"roleName\": \"企业管理员\", \"createdAt\": \"0001-01-01T00:00:00Z\", \"updatedAt\": \"0001-01-01T00:00:00Z\"}]', '[]', '{\"cooperationCompany\": \"\", \"cooperationDeadline\": \"0001-01-01T00:00:00Z\"}', 1, '{\"phone\": \"18860183031\", \"depName\": \"string1\", \"orgName\": \"string1\"}', '2021-07-24 10:16:17.680805+08', '2021-07-24 10:16:17.680805+08');\n", | ||
| 26 | + ) | ||
| 21 | Expect(err).NotTo(HaveOccurred()) | 27 | Expect(err).NotTo(HaveOccurred()) |
| 22 | }) | 28 | }) |
| 23 | Describe("根据userId参数返回用户", func() { | 29 | Describe("根据userId参数返回用户", func() { |
| 24 | Context("传入有效的userId", func() { | 30 | Context("传入有效的userId", func() { |
| 25 | It("返回用户数据", func() { | 31 | It("返回用户数据", func() { |
| 26 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 32 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 27 | - httpExpect.GET("/user/{userId}"). | 33 | + httpExpect.GET("/user/999"). |
| 28 | Expect(). | 34 | Expect(). |
| 29 | Status(http.StatusOK). | 35 | Status(http.StatusOK). |
| 30 | JSON(). | 36 | JSON(). |
| @@ -36,7 +42,9 @@ var _ = Describe("返回", func() { | @@ -36,7 +42,9 @@ var _ = Describe("返回", func() { | ||
| 36 | }) | 42 | }) |
| 37 | }) | 43 | }) |
| 38 | AfterEach(func() { | 44 | AfterEach(func() { |
| 39 | - _, err := pG.DB.Exec("DELETE FROM users WHERE true") | 45 | + _, err := pG.DB.Exec("DELETE FROM users.user_base WHERE user_base_id = 999") |
| 46 | + Expect(err).NotTo(HaveOccurred()) | ||
| 47 | + _, err = pG.DB.Exec(`DELETE FROM users."user" WHERE user_id = 999`) | ||
| 40 | Expect(err).NotTo(HaveOccurred()) | 48 | Expect(err).NotTo(HaveOccurred()) |
| 41 | }) | 49 | }) |
| 42 | }) | 50 | }) |
| @@ -11,13 +11,19 @@ import ( | @@ -11,13 +11,19 @@ import ( | ||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | var _ = Describe("返回列表", func() { | 13 | var _ = Describe("返回列表", func() { |
| 14 | - return | ||
| 15 | - var userId int64 | 14 | + var Id int64 |
| 16 | BeforeEach(func() { | 15 | BeforeEach(func() { |
| 17 | - _, err := pG.DB.QueryOne( | ||
| 18 | - pg.Scan(&userId), | ||
| 19 | - "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
| 20 | - "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | 16 | + var err error |
| 17 | + _, err = pG.DB.QueryOne( | ||
| 18 | + pg.Scan(&Id), | ||
| 19 | + "INSERT INTO \"users\".\"user_base\"(\"user_base_id\", \"user_info\", \"account\", \"password\", \"im\", \"related_user\", \"status\", \"created_at\", \"updated_at\") VALUES (999, '{\"phone\": \"phone\", \"userName\": \"string\"}', 'phone', 'string', '{\"accid\": \"\", \"imToken\": \"\", \"csAccountId\": \"\"}', '{999}', 1, '2021-07-24 10:16:17.680805+08', '2021-07-24 10:16:17.680805+08') RETURNING user_base_id;", | ||
| 20 | + ) | ||
| 21 | + Expect(err).NotTo(HaveOccurred()) | ||
| 22 | + | ||
| 23 | + _, err = pG.DB.QueryOne( | ||
| 24 | + pg.Scan(&Id), | ||
| 25 | + "INSERT INTO \"users\".\"user\"(\"user_id\", \"company_id\", \"user_base_id\", \"user_type\", \"user_code\", \"organization_id\", \"department_id\", \"user_org\", \"user_role\", \"favorite_menus\", \"cooperation_info\", \"enable_status\", \"ext\", \"created_at\", \"updated_at\") VALUES (999, 5, 999, 1025, 'ADMIN01', 5, 5, '[{\"orgId\": 5, \"orgName\": \"string1\", \"createdAt\": \"0001-01-01T00:00:00Z\", \"deletedAt\": \"0001-01-01T00:00:00Z\", \"updatedAt\": \"0001-01-01T00:00:00Z\"}]', '[{\"ext\": {\"orgName\": \"string1\"}, \"roleId\": 5, \"roleName\": \"企业管理员\", \"createdAt\": \"0001-01-01T00:00:00Z\", \"updatedAt\": \"0001-01-01T00:00:00Z\"}]', '[]', '{\"cooperationCompany\": \"\", \"cooperationDeadline\": \"0001-01-01T00:00:00Z\"}', 1, '{\"phone\": \"18860183031\", \"depName\": \"string1\", \"orgName\": \"string1\"}', '2021-07-24 10:16:17.680805+08', '2021-07-24 10:16:17.680805+08');\n", | ||
| 26 | + ) | ||
| 21 | Expect(err).NotTo(HaveOccurred()) | 27 | Expect(err).NotTo(HaveOccurred()) |
| 22 | }) | 28 | }) |
| 23 | Describe("根据参数返回用户列表", func() { | 29 | Describe("根据参数返回用户列表", func() { |
| @@ -25,11 +31,11 @@ var _ = Describe("返回列表", func() { | @@ -25,11 +31,11 @@ var _ = Describe("返回列表", func() { | ||
| 25 | It("返回用户数据列表", func() { | 31 | It("返回用户数据列表", func() { |
| 26 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 32 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 27 | body := map[string]interface{}{ | 33 | body := map[string]interface{}{ |
| 28 | - "offset": "int", | ||
| 29 | - "limit": "int", | ||
| 30 | - "companyId": "int64", | ||
| 31 | - "organizationId": "int64", | ||
| 32 | - "departmentId": "int64", | 34 | + "offset": 0, |
| 35 | + "limit": 20, | ||
| 36 | + "companyId": 5, | ||
| 37 | + "organizationId": 5, | ||
| 38 | + "departmentId": 5, | ||
| 33 | "userName": "string", | 39 | "userName": "string", |
| 34 | "depName": "string", | 40 | "depName": "string", |
| 35 | "phone": "string", | 41 | "phone": "string", |
| @@ -43,13 +49,15 @@ var _ = Describe("返回列表", func() { | @@ -43,13 +49,15 @@ var _ = Describe("返回列表", func() { | ||
| 43 | ContainsKey("code").ValueEqual("code", 0). | 49 | ContainsKey("code").ValueEqual("code", 0). |
| 44 | ContainsKey("msg").ValueEqual("msg", "ok"). | 50 | ContainsKey("msg").ValueEqual("msg", "ok"). |
| 45 | ContainsKey("data").Value("data").Object(). | 51 | ContainsKey("data").Value("data").Object(). |
| 46 | - ContainsKey("count").ValueEqual("count", 1). | 52 | + //ContainsKey("count").ValueEqual("count", 1). |
| 47 | ContainsKey("users").Value("users").Array() | 53 | ContainsKey("users").Value("users").Array() |
| 48 | }) | 54 | }) |
| 49 | }) | 55 | }) |
| 50 | }) | 56 | }) |
| 51 | AfterEach(func() { | 57 | AfterEach(func() { |
| 52 | - _, err := pG.DB.Exec("DELETE FROM users WHERE true") | 58 | + _, err := pG.DB.Exec("DELETE FROM users.user_base WHERE user_base_id = 999") |
| 59 | + Expect(err).NotTo(HaveOccurred()) | ||
| 60 | + _, err = pG.DB.Exec(`DELETE FROM users."user" WHERE user_id = 999`) | ||
| 53 | Expect(err).NotTo(HaveOccurred()) | 61 | Expect(err).NotTo(HaveOccurred()) |
| 54 | }) | 62 | }) |
| 55 | }) | 63 | }) |
-
请 注册 或 登录 后发表评论