正在显示
11 个修改的文件
包含
247 行增加
和
41 行删除
| @@ -46,3 +46,11 @@ func CreatePgDataAuthService(options map[string]interface{}) (domain.DataAuthor, | @@ -46,3 +46,11 @@ func CreatePgDataAuthService(options map[string]interface{}) (domain.DataAuthor, | ||
| 46 | } | 46 | } |
| 47 | return domainService.NewPgDataAuthService(transactionContext) | 47 | return domainService.NewPgDataAuthService(transactionContext) |
| 48 | } | 48 | } |
| 49 | + | ||
| 50 | +func CreatePgUpdateUserService(options map[string]interface{}) (service.PgUpdateUserService, error) { | ||
| 51 | + var transactionContext *pgTransaction.TransactionContext | ||
| 52 | + if value, ok := options["transactionContext"]; ok { | ||
| 53 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
| 54 | + } | ||
| 55 | + return domainService.NewPgUpdateUserService(transactionContext) | ||
| 56 | +} |
| @@ -21,13 +21,15 @@ type UpdateCooperatorCommand struct { | @@ -21,13 +21,15 @@ type UpdateCooperatorCommand struct { | ||
| 21 | // 用户编号 企业内标识 | 21 | // 用户编号 企业内标识 |
| 22 | UserCode string `cname:"用户编号 企业内标识" json:"userCode" valid:"Required"` | 22 | UserCode string `cname:"用户编号 企业内标识" json:"userCode" valid:"Required"` |
| 23 | // 用户Id 用户唯一标识 | 23 | // 用户Id 用户唯一标识 |
| 24 | - UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | 24 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"` |
| 25 | + // 手机号码 | ||
| 26 | + Phone string `cname:"手机号码" json:"phone" valid:"Required"` | ||
| 25 | // 用户姓名 | 27 | // 用户姓名 |
| 26 | UserName string `cname:"用户姓名" json:"userName" valid:"Required"` | 28 | UserName string `cname:"用户姓名" json:"userName" valid:"Required"` |
| 27 | // 头像 | 29 | // 头像 |
| 28 | Avatar string `cname:"头像" json:"avatar" valid:"Required"` | 30 | Avatar string `cname:"头像" json:"avatar" valid:"Required"` |
| 29 | // 组织ID | 31 | // 组织ID |
| 30 | - OrgId int64 `cname:"组织ID" json:"orgId,string" valid:"Required"` | 32 | + OrgId int64 `cname:"组织ID" json:"orgId" valid:"Required"` |
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | func (updateCooperatorCommand *UpdateCooperatorCommand) Valid(validation *validation.Validation) { | 35 | func (updateCooperatorCommand *UpdateCooperatorCommand) Valid(validation *validation.Validation) { |
| @@ -12,11 +12,11 @@ import ( | @@ -12,11 +12,11 @@ import ( | ||
| 12 | 12 | ||
| 13 | type UpdateUserCommand struct { | 13 | type UpdateUserCommand struct { |
| 14 | // 用户Id 用户唯一标识 | 14 | // 用户Id 用户唯一标识 |
| 15 | - UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | 15 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"` |
| 16 | // 组织机构 | 16 | // 组织机构 |
| 17 | - OrganizationId int64 `cname:"组织机构" json:"organizationId,string,omitempty"` | 17 | + OrganizationId int64 `cname:"组织机构" json:"organizationId,omitempty"` |
| 18 | // 所属部门 | 18 | // 所属部门 |
| 19 | - DepartmentId int64 `cname:"所属部门" json:"departmentId,string,omitempty"` | 19 | + DepartmentId int64 `cname:"所属部门" json:"departmentId,omitempty"` |
| 20 | // 用户关联的组织 | 20 | // 用户关联的组织 |
| 21 | UserOrg []*domain.Org `cname:"用户关联的组织" json:"userOrg,omitempty"` | 21 | UserOrg []*domain.Org `cname:"用户关联的组织" json:"userOrg,omitempty"` |
| 22 | // 用户关联的角色 | 22 | // 用户关联的角色 |
| @@ -439,10 +439,31 @@ func (userService *UserService) UpdateCooperator(updateCooperatorCommand *comman | @@ -439,10 +439,31 @@ func (userService *UserService) UpdateCooperator(updateCooperatorCommand *comman | ||
| 439 | defer func() { | 439 | defer func() { |
| 440 | transactionContext.RollbackTransaction() | 440 | transactionContext.RollbackTransaction() |
| 441 | }() | 441 | }() |
| 442 | + | ||
| 443 | + _, user, err := factory.FastPgUser(transactionContext, updateCooperatorCommand.UserId) | ||
| 444 | + if err != nil { | ||
| 445 | + return nil, err | ||
| 446 | + } | ||
| 447 | + user.OrganizationId = updateCooperatorCommand.OrgId | ||
| 448 | + | ||
| 449 | + userInfo := &domain.UserInfo{ | ||
| 450 | + UserName: updateCooperatorCommand.UserName, | ||
| 451 | + Phone: updateCooperatorCommand.Phone, | ||
| 452 | + Avatar: updateCooperatorCommand.Avatar, | ||
| 453 | + Email: updateCooperatorCommand.Email, | ||
| 454 | + } | ||
| 455 | + | ||
| 456 | + updateUserService, _ := factory.CreatePgUpdateUserService(map[string]interface{}{ | ||
| 457 | + "transactionContext": transactionContext, | ||
| 458 | + }) | ||
| 459 | + if user, err = updateUserService.UpdateUser(nil, user, userInfo, updateCooperatorCommand.EnableStatus); err != nil { | ||
| 460 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 461 | + } | ||
| 462 | + | ||
| 442 | if err := transactionContext.CommitTransaction(); err != nil { | 463 | if err := transactionContext.CommitTransaction(); err != nil { |
| 443 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 464 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 444 | } | 465 | } |
| 445 | - return nil, nil | 466 | + return struct{}{}, nil |
| 446 | } | 467 | } |
| 447 | 468 | ||
| 448 | // 更新我喜欢菜单列表 | 469 | // 更新我喜欢菜单列表 |
| @@ -481,22 +502,33 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser | @@ -481,22 +502,33 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser | ||
| 481 | defer func() { | 502 | defer func() { |
| 482 | transactionContext.RollbackTransaction() | 503 | transactionContext.RollbackTransaction() |
| 483 | }() | 504 | }() |
| 484 | - userRepository, user, err := factory.FastPgUser(transactionContext, updateUserCommand.UserId) | 505 | + _, user, err := factory.FastPgUser(transactionContext, updateUserCommand.UserId) |
| 485 | if err != nil { | 506 | if err != nil { |
| 486 | return nil, err | 507 | return nil, err |
| 487 | } | 508 | } |
| 488 | - updateData := tool_funs.SimpleStructToMap(updateUserCommand) | ||
| 489 | - if err := user.Update(updateData); err != nil { | ||
| 490 | - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 509 | + user.DepartmentId = updateUserCommand.DepartmentId |
| 510 | + user.OrganizationId = updateUserCommand.OrganizationId | ||
| 511 | + user.UserOrg = updateUserCommand.UserOrg | ||
| 512 | + user.UserRole = updateUserCommand.UserRole | ||
| 513 | + | ||
| 514 | + userInfo := &domain.UserInfo{ | ||
| 515 | + UserName: updateUserCommand.UserName, | ||
| 516 | + Phone: updateUserCommand.Phone, | ||
| 517 | + Avatar: updateUserCommand.Avatar, | ||
| 518 | + Email: updateUserCommand.Email, | ||
| 491 | } | 519 | } |
| 492 | - if user, err := userRepository.Save(user); err != nil { | ||
| 493 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 494 | - } else { | 520 | + |
| 521 | + updateUserService, _ := factory.CreatePgUpdateUserService(map[string]interface{}{ | ||
| 522 | + "transactionContext": transactionContext, | ||
| 523 | + }) | ||
| 524 | + if user, err = updateUserService.UpdateUser(nil, user, userInfo, updateUserCommand.EnableStatus); err != nil { | ||
| 525 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 526 | + } | ||
| 527 | + | ||
| 495 | if err := transactionContext.CommitTransaction(); err != nil { | 528 | if err := transactionContext.CommitTransaction(); err != nil { |
| 496 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 529 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 497 | } | 530 | } |
| 498 | return user, nil | 531 | return user, nil |
| 499 | - } | ||
| 500 | } | 532 | } |
| 501 | 533 | ||
| 502 | // 更新用户基础信息数据 | 534 | // 更新用户基础信息数据 |
pkg/domain/service/pg_update_user.go
0 → 100644
| 1 | +package service | ||
| 2 | + | ||
| 3 | +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 4 | + | ||
| 5 | +// PgUpdateUserService 用户更新服务 | ||
| 6 | +type PgUpdateUserService interface { | ||
| 7 | + UpdateUser(optUser *domain.CheckOptions, user *domain.User, userInfo *domain.UserInfo, enableStatus int) (*domain.User, error) | ||
| 8 | +} |
| @@ -84,9 +84,9 @@ func (user *User) Update(data map[string]interface{}) error { | @@ -84,9 +84,9 @@ func (user *User) Update(data map[string]interface{}) error { | ||
| 84 | //if companyId, ok := data["companyId"]; ok { | 84 | //if companyId, ok := data["companyId"]; ok { |
| 85 | // user.CompanyId = companyId.(int64) | 85 | // user.CompanyId = companyId.(int64) |
| 86 | //} | 86 | //} |
| 87 | - //if userBaseId, ok := data["userBaseId"]; ok { | ||
| 88 | - // user.UserBaseId = userBaseId.(int64) | ||
| 89 | - //} | 87 | + if userBaseId, ok := data["userBaseId"]; ok { |
| 88 | + user.UserBaseId = userBaseId.(int64) | ||
| 89 | + } | ||
| 90 | //if userType, ok := data["userType"]; ok { | 90 | //if userType, ok := data["userType"]; ok { |
| 91 | // user.UserType = userType.(int) | 91 | // user.UserType = userType.(int) |
| 92 | //} | 92 | //} |
| @@ -170,7 +170,7 @@ func (user *User) SetEnableStatus(enableStatus int) error { | @@ -170,7 +170,7 @@ func (user *User) SetEnableStatus(enableStatus int) error { | ||
| 170 | return fmt.Errorf("账号已注销") | 170 | return fmt.Errorf("账号已注销") |
| 171 | } | 171 | } |
| 172 | if user.EnableStatus == enableStatus { | 172 | if user.EnableStatus == enableStatus { |
| 173 | - return fmt.Errorf("重复设置状态") | 173 | + return nil //fmt.Errorf("重复设置状态") |
| 174 | } | 174 | } |
| 175 | if !(userStatus == UserStatusEnable || userStatus == UserStatusDisable || userStatus == UserStatusDestroy) { | 175 | if !(userStatus == UserStatusEnable || userStatus == UserStatusDisable || userStatus == UserStatusDestroy) { |
| 176 | return fmt.Errorf("非法启用状态") | 176 | return fmt.Errorf("非法启用状态") |
| @@ -164,3 +164,15 @@ func (userBase *UserBase) DestroyAccount(accountAfter string) error { | @@ -164,3 +164,15 @@ func (userBase *UserBase) DestroyAccount(accountAfter string) error { | ||
| 164 | userBase.UserInfo.Phone = accountAfter | 164 | userBase.UserInfo.Phone = accountAfter |
| 165 | return nil | 165 | return nil |
| 166 | } | 166 | } |
| 167 | + | ||
| 168 | +// UpdateUserInfo 更新用户信息 | ||
| 169 | +// | ||
| 170 | +// userInfo 用户信息 | ||
| 171 | +func (userBase *UserBase) UpdateUserInfo(userInfo *UserInfo) error { | ||
| 172 | + //userBase.UserInfo.Phone = userInfo.Phone | ||
| 173 | + userBase.UserInfo.UserName = userInfo.UserName | ||
| 174 | + userBase.UserInfo.Email = userInfo.Email | ||
| 175 | + userBase.UserInfo.Avatar = userInfo.Avatar | ||
| 176 | + userBase.UpdatedAt = time.Now() | ||
| 177 | + return nil | ||
| 178 | +} |
| @@ -28,6 +28,9 @@ func (ptr *PgAuthResetPhoneService) ResetPhone(optUser *domain.User, oldPhone, n | @@ -28,6 +28,9 @@ func (ptr *PgAuthResetPhoneService) ResetPhone(optUser *domain.User, oldPhone, n | ||
| 28 | var err error | 28 | var err error |
| 29 | var userBase *domain.UserBase | 29 | var userBase *domain.UserBase |
| 30 | userBaseRepository, _ := repository.NewUserBaseRepository(ptr.transactionContext) | 30 | userBaseRepository, _ := repository.NewUserBaseRepository(ptr.transactionContext) |
| 31 | + if userBase, err = userBaseRepository.FindOne(map[string]interface{}{"account": newPhone}); err == nil && userBase != nil { | ||
| 32 | + return fmt.Errorf("手机号已存在") | ||
| 33 | + } | ||
| 31 | if userBase, err = userBaseRepository.FindOne(map[string]interface{}{"account": oldPhone}); err != nil { | 34 | if userBase, err = userBaseRepository.FindOne(map[string]interface{}{"account": oldPhone}); err != nil { |
| 32 | return err | 35 | return err |
| 33 | } | 36 | } |
| @@ -46,7 +49,7 @@ func (ptr *PgAuthResetPhoneService) ResetPhone(optUser *domain.User, oldPhone, n | @@ -46,7 +49,7 @@ func (ptr *PgAuthResetPhoneService) ResetPhone(optUser *domain.User, oldPhone, n | ||
| 46 | for i := 0; i < len(userBase.RelatedUsers); i++ { | 49 | for i := 0; i < len(userBase.RelatedUsers); i++ { |
| 47 | userId := userBase.RelatedUsers[i] | 50 | userId := userBase.RelatedUsers[i] |
| 48 | if user, _ := userRepository.FindOne(map[string]interface{}{"userId": userId}); user != nil { | 51 | if user, _ := userRepository.FindOne(map[string]interface{}{"userId": userId}); user != nil { |
| 49 | - user.Update(map[string]interface{}{"phone": newPhone}) | 52 | + user.Update(map[string]interface{}{"phone": newPhone}) //,"userBaseId":userBase.UserBaseId |
| 50 | if _, err := userRepository.Save(user); err != nil { | 53 | if _, err := userRepository.Save(user); err != nil { |
| 51 | return err | 54 | return err |
| 52 | } | 55 | } |
| 1 | +package domainService | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/repository" | ||
| 8 | + "strings" | ||
| 9 | + "time" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +// PgUpdateUserService 用户更新服务 | ||
| 13 | +type PgUpdateUserService struct { | ||
| 14 | + transactionContext *pgTransaction.TransactionContext | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.CheckOptions, user *domain.User, userInfo *domain.UserInfo, enableStatus int) (*domain.User, error) { | ||
| 18 | + var err error | ||
| 19 | + roleRepository, _ := repository.NewRoleRepository(ptr.transactionContext) | ||
| 20 | + //1.更新所属组织、部门 | ||
| 21 | + var org, dep *domain.Org | ||
| 22 | + orgRepository, _ := repository.NewOrgRepository(ptr.transactionContext) | ||
| 23 | + if user.OrganizationId > 0 { | ||
| 24 | + org, err = orgRepository.FindOne(map[string]interface{}{"orgId": user.OrganizationId}) | ||
| 25 | + if err != nil { | ||
| 26 | + return nil, err | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + if user.DepartmentId > 0 { | ||
| 30 | + dep, err = orgRepository.FindOne(map[string]interface{}{"orgId": user.DepartmentId}) | ||
| 31 | + if err != nil { | ||
| 32 | + return nil, err | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + //2.更新关联角色,组织 | ||
| 37 | + var userOrg = make([]*domain.Org, 0) | ||
| 38 | + for i := range user.UserOrg { | ||
| 39 | + var tmpOrg *domain.Org | ||
| 40 | + tmpOrg, err = orgRepository.FindOne(map[string]interface{}{"orgId": user.UserOrg[i].OrgId}) | ||
| 41 | + if err != nil { | ||
| 42 | + return nil, err | ||
| 43 | + } | ||
| 44 | + userOrg = append(userOrg, tmpOrg.CloneSample()) | ||
| 45 | + } | ||
| 46 | + var userRole = make([]*domain.Role, 0) | ||
| 47 | + for i := range user.UserRole { | ||
| 48 | + var tmpRole *domain.Role | ||
| 49 | + tmpRole, err = roleRepository.FindOne(map[string]interface{}{"roleId": user.UserRole[i].RoleId}) | ||
| 50 | + if err != nil { | ||
| 51 | + return nil, err | ||
| 52 | + } | ||
| 53 | + userRole = append(userRole, tmpRole.CloneSample()) | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + //3.更新用户信息 | ||
| 57 | + userBaseRepository, _ := repository.NewUserBaseRepository(ptr.transactionContext) | ||
| 58 | + var userBase *domain.UserBase | ||
| 59 | + if userBase, err = userBaseRepository.FindOne(map[string]interface{}{"userBaseId": user.UserBaseId}); err != nil { | ||
| 60 | + return nil, err | ||
| 61 | + } | ||
| 62 | + if userBase.Account != strings.TrimSpace(userInfo.Phone) && len(userInfo.Phone) > 0 { // 修改了手机号 | ||
| 63 | + if _, err = userBaseRepository.FindOne(map[string]interface{}{"account": strings.TrimSpace(userInfo.Phone)}); err == nil { | ||
| 64 | + return nil, fmt.Errorf("手机号已存在") | ||
| 65 | + } | ||
| 66 | + if err = userBase.ResetPhone(userBase.Account, userInfo.Phone); err != nil { | ||
| 67 | + return nil, err | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + if err = userBase.UpdateUserInfo(userInfo); err != nil { | ||
| 71 | + return nil, err | ||
| 72 | + } | ||
| 73 | + if userBase, err = userBaseRepository.Save(userBase); err != nil { | ||
| 74 | + return nil, err | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + //4.更新用户、冗余信息 | ||
| 78 | + userRepository, _ := repository.NewUserRepository(ptr.transactionContext) | ||
| 79 | + user.UserRole = userRole | ||
| 80 | + user.UserOrg = userOrg | ||
| 81 | + if org != nil { | ||
| 82 | + user.Ext.OrgName = org.OrgName | ||
| 83 | + } | ||
| 84 | + if dep != nil { | ||
| 85 | + user.Ext.DepName = dep.OrgName | ||
| 86 | + } | ||
| 87 | + user.Ext.Phone = userBase.UserInfo.Phone | ||
| 88 | + user.Ext.UserName = userBase.UserInfo.UserName | ||
| 89 | + user.UpdatedAt = time.Now() | ||
| 90 | + if err = user.SetEnableStatus(enableStatus); err != nil { | ||
| 91 | + return nil, err | ||
| 92 | + } | ||
| 93 | + if user, err = userRepository.Save(user); err != nil { | ||
| 94 | + return nil, err | ||
| 95 | + } | ||
| 96 | + return user, nil | ||
| 97 | +} | ||
| 98 | + | ||
| 99 | +func NewPgUpdateUserService(transactionContext *pgTransaction.TransactionContext) (*PgUpdateUserService, error) { | ||
| 100 | + if transactionContext == nil { | ||
| 101 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 102 | + } else { | ||
| 103 | + return &PgUpdateUserService{ | ||
| 104 | + transactionContext: transactionContext, | ||
| 105 | + }, nil | ||
| 106 | + } | ||
| 107 | +} |
| @@ -3,6 +3,7 @@ package user | @@ -3,6 +3,7 @@ package user | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/go-pg/pg/v10" | 4 | "github.com/go-pg/pg/v10" |
| 5 | "net/http" | 5 | "net/http" |
| 6 | + "time" | ||
| 6 | 7 | ||
| 7 | "github.com/gavv/httpexpect" | 8 | "github.com/gavv/httpexpect" |
| 8 | . "github.com/onsi/ginkgo" | 9 | . "github.com/onsi/ginkgo" |
| @@ -11,13 +12,25 @@ import ( | @@ -11,13 +12,25 @@ import ( | ||
| 11 | ) | 12 | ) |
| 12 | 13 | ||
| 13 | var _ = Describe("更新共创用户", func() { | 14 | var _ = Describe("更新共创用户", func() { |
| 14 | - return | ||
| 15 | var userId int64 | 15 | var userId int64 |
| 16 | BeforeEach(func() { | 16 | BeforeEach(func() { |
| 17 | - _, err := pG.DB.QueryOne( | 17 | + var err error |
| 18 | + _, err = pG.DB.QueryOne( | ||
| 18 | pg.Scan(&userId), | 19 | 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") | 20 | + "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;", |
| 21 | + ) | ||
| 22 | + Expect(err).NotTo(HaveOccurred()) | ||
| 23 | + | ||
| 24 | + _, err = pG.DB.QueryOne( | ||
| 25 | + pg.Scan(&userId), | ||
| 26 | + "INSERT INTO \"users\".\"user\"(\"user_id\", \"company_id\", \"user_base_id\", \"user_type\", \"user_code\", \"organization_id\", \"department_id\", \"favorite_menus\", \"cooperation_info\", \"enable_status\", \"ext\", \"created_at\", \"updated_at\") VALUES (999, 5, 999, 1025, 'ADMIN01', 5, 5, '[]', '{\"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", | ||
| 27 | + ) | ||
| 28 | + Expect(err).NotTo(HaveOccurred()) | ||
| 29 | + | ||
| 30 | + _, err = pG.DB.QueryOne( | ||
| 31 | + pg.Scan(&userId), | ||
| 32 | + "INSERT INTO users.org (org_id,company_id,created_at,updated_at,deleted_at,org_code,org_name,ext,org_status,is_org,parent_id,parent_path) VALUES (5,999,'2021-07-26 08:06:29.3101584+00:00:00','2021-07-26 08:06:29.3101584+00:00:00','0001-01-01 00:00:00+00:00:00','ENTERPRISE01','string1','{}',1,1,0,'');", | ||
| 33 | + ) | ||
| 21 | Expect(err).NotTo(HaveOccurred()) | 34 | Expect(err).NotTo(HaveOccurred()) |
| 22 | }) | 35 | }) |
| 23 | Describe("更新共创用户", func() { | 36 | Describe("更新共创用户", func() { |
| @@ -26,15 +39,16 @@ var _ = Describe("更新共创用户", func() { | @@ -26,15 +39,16 @@ var _ = Describe("更新共创用户", func() { | ||
| 26 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 39 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 27 | body := map[string]interface{}{ | 40 | body := map[string]interface{}{ |
| 28 | "cooperationCompany": "string", | 41 | "cooperationCompany": "string", |
| 29 | - "cooperationDeadline": "datetime", | 42 | + "cooperationDeadline": time.Now(), |
| 30 | "email": "string", | 43 | "email": "string", |
| 31 | - "enableStatus": "int", | 44 | + "enableStatus": 1, |
| 32 | "userCode": "string", | 45 | "userCode": "string", |
| 33 | "userName": "string", | 46 | "userName": "string", |
| 34 | "avatar": "string", | 47 | "avatar": "string", |
| 35 | - "orgId": "int64", | 48 | + "orgId": 5, |
| 49 | + "phone": "phone", | ||
| 36 | } | 50 | } |
| 37 | - httpExpect.PUT("/user/cooperator/{userId}"). | 51 | + httpExpect.PUT("/user/cooperator/999"). |
| 38 | WithJSON(body). | 52 | WithJSON(body). |
| 39 | Expect(). | 53 | Expect(). |
| 40 | Status(http.StatusOK). | 54 | Status(http.StatusOK). |
| @@ -47,7 +61,11 @@ var _ = Describe("更新共创用户", func() { | @@ -47,7 +61,11 @@ var _ = Describe("更新共创用户", func() { | ||
| 47 | }) | 61 | }) |
| 48 | }) | 62 | }) |
| 49 | AfterEach(func() { | 63 | AfterEach(func() { |
| 50 | - _, err := pG.DB.Exec("DELETE FROM users WHERE true") | 64 | + _, err := pG.DB.Exec("DELETE FROM users.user_base WHERE user_base_id = 999") |
| 65 | + Expect(err).NotTo(HaveOccurred()) | ||
| 66 | + _, err = pG.DB.Exec(`DELETE FROM users."user" WHERE user_id = 999`) | ||
| 67 | + Expect(err).NotTo(HaveOccurred()) | ||
| 68 | + _, err = pG.DB.Exec(`DELETE FROM users."org" WHERE org_id = 999`) | ||
| 51 | Expect(err).NotTo(HaveOccurred()) | 69 | Expect(err).NotTo(HaveOccurred()) |
| 52 | }) | 70 | }) |
| 53 | }) | 71 | }) |
| @@ -11,13 +11,25 @@ import ( | @@ -11,13 +11,25 @@ import ( | ||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | var _ = Describe("更新", func() { | 13 | var _ = Describe("更新", func() { |
| 14 | - return | ||
| 15 | var userId int64 | 14 | var userId int64 |
| 16 | BeforeEach(func() { | 15 | BeforeEach(func() { |
| 17 | - _, err := pG.DB.QueryOne( | 16 | + var err error |
| 17 | + _, err = pG.DB.QueryOne( | ||
| 18 | pg.Scan(&userId), | 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") | 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(&userId), | ||
| 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 | + ) | ||
| 27 | + Expect(err).NotTo(HaveOccurred()) | ||
| 28 | + | ||
| 29 | + _, err = pG.DB.QueryOne( | ||
| 30 | + pg.Scan(&userId), | ||
| 31 | + "INSERT INTO users.org (org_id,company_id,created_at,updated_at,deleted_at,org_code,org_name,ext,org_status,is_org,parent_id,parent_path) VALUES (999,999,'2021-07-26 08:06:29.3101584+00:00:00','2021-07-26 08:06:29.3101584+00:00:00','0001-01-01 00:00:00+00:00:00','ENTERPRISE01','string1','{}',1,1,0,'');", | ||
| 32 | + ) | ||
| 21 | Expect(err).NotTo(HaveOccurred()) | 33 | Expect(err).NotTo(HaveOccurred()) |
| 22 | }) | 34 | }) |
| 23 | Describe("提交数据更新", func() { | 35 | Describe("提交数据更新", func() { |
| @@ -25,19 +37,19 @@ var _ = Describe("更新", func() { | @@ -25,19 +37,19 @@ var _ = Describe("更新", func() { | ||
| 25 | It("返回更新后的用户数据", func() { | 37 | It("返回更新后的用户数据", func() { |
| 26 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 38 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 27 | body := map[string]interface{}{ | 39 | body := map[string]interface{}{ |
| 28 | - "organizationId": "int64", | ||
| 29 | - "departmentId": "int64", | ||
| 30 | - "userOrg": "array", | ||
| 31 | - "userRole": "array", | 40 | + "organizationId": 999, |
| 41 | + "departmentId": 999, | ||
| 42 | + //"userOrg": "array", | ||
| 43 | + //"userRole": "array", | ||
| 32 | "cooperationCompany": "string", | 44 | "cooperationCompany": "string", |
| 33 | - "cooperationDeadline": "datetime", | ||
| 34 | - "enableStatus": "int", | 45 | + //"cooperationDeadline": "datetime", |
| 46 | + "enableStatus": 1, | ||
| 35 | "userName": "string", | 47 | "userName": "string", |
| 36 | - "phone": "string", | 48 | + "phone": "phone", |
| 37 | "avatar": "string", | 49 | "avatar": "string", |
| 38 | "email": "string", | 50 | "email": "string", |
| 39 | } | 51 | } |
| 40 | - httpExpect.PUT("/user/{userId}"). | 52 | + httpExpect.PUT("/user/999"). |
| 41 | WithJSON(body). | 53 | WithJSON(body). |
| 42 | Expect(). | 54 | Expect(). |
| 43 | Status(http.StatusOK). | 55 | Status(http.StatusOK). |
| @@ -51,7 +63,11 @@ var _ = Describe("更新", func() { | @@ -51,7 +63,11 @@ var _ = Describe("更新", func() { | ||
| 51 | }) | 63 | }) |
| 52 | }) | 64 | }) |
| 53 | AfterEach(func() { | 65 | AfterEach(func() { |
| 54 | - _, err := pG.DB.Exec("DELETE FROM users WHERE true") | 66 | + _, err := pG.DB.Exec("DELETE FROM users.user_base WHERE user_base_id = 999") |
| 67 | + Expect(err).NotTo(HaveOccurred()) | ||
| 68 | + _, err = pG.DB.Exec(`DELETE FROM users."user" WHERE user_id = 999`) | ||
| 69 | + Expect(err).NotTo(HaveOccurred()) | ||
| 70 | + _, err = pG.DB.Exec(`DELETE FROM users."org" WHERE org_id = 999`) | ||
| 55 | Expect(err).NotTo(HaveOccurred()) | 71 | Expect(err).NotTo(HaveOccurred()) |
| 56 | }) | 72 | }) |
| 57 | }) | 73 | }) |
-
请 注册 或 登录 后发表评论