作者 yangfu

用户启用、用户重置密码、用户列表、创建共创用户、获取用户

package factory
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
)
// FastPgUser 快速返回领域用户
//
// transactionContext 事务
// userId 用户ID
func FastPgUser(transactionContext application.TransactionContext, userId int64) (domain.UserRepository, *domain.User, error) {
var rep domain.UserRepository
var mod *domain.User
var err error
if value, err := CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if userId > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"userId": userId}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该用户不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
// FastPgUser 快速返回领域用户基础
//
// transactionContext 事务
// userBaseId 用户基础ID
func FastPgUserBase(transactionContext application.TransactionContext, userBaseId int64) (domain.UserBaseRepository, *domain.UserBase, error) {
var rep domain.UserBaseRepository
var mod *domain.UserBase
var err error
if value, err := CreateUserBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if userBaseId > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"userBaseId": userBaseId}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "用户基础不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
// FastPgRole 快速返回领域角色
//
// transactionContext 事务
// roleId 角色Id
func FastPgRole(transactionContext application.TransactionContext, roleId int64) (domain.RoleRepository, *domain.Role, error) {
var rep domain.RoleRepository
var mod *domain.Role
var err error
if value, err := CreateRoleRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if roleId > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"roleId": roleId}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该角色不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
// FastPgRole 快速返回领域组织
//
// transactionContext 事务
// orgId 组织Id
func FastPgOrg(transactionContext application.TransactionContext, orgId int64) (domain.OrgRepository, *domain.Org, error) {
var rep domain.OrgRepository
var mod *domain.Org
var err error
if value, err := CreateOrgRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if orgId > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"orgId": orgId}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该角色不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
// FastPgCompany 快速返回领域公司
//
// transactionContext 事务
// companyId 公司Id
func FastPgCompany(transactionContext application.TransactionContext, companyId int64) (domain.CompanyRepository, *domain.Company, error) {
var rep domain.CompanyRepository
var mod *domain.Company
var err error
if value, err := CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if companyId > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"companyId": companyId}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该企业不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
// FastPgMenu 快速返回领域菜单
//
// transactionContext 事务
// menuId 菜单Id
func FastPgMenu(transactionContext application.TransactionContext, menuId int64) (domain.MenuRepository, *domain.Menu, error) {
var rep domain.MenuRepository
var mod *domain.Menu
var err error
if value, err := CreateMenuRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if menuId > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"menuId": menuId}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该菜单不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
// FastPgCustomizeMenu 快速返回领域自定义菜单
//
// transactionContext 事务
// customizeMenuId 自定义菜单Id
func FastPgCustomizeMenu(transactionContext application.TransactionContext, customizeMenuId int64) (domain.CustomizeMenuRepository, *domain.CustomizeMenu, error) {
var rep domain.CustomizeMenuRepository
var mod *domain.CustomizeMenu
var err error
if value, err := CreateCustomizeMenuRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if customizeMenuId > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"customizeMenuId": customizeMenuId}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "自定义菜单不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
// FastPgAccountDestroyRecord 快速返回领域账号注销记录
//
// transactionContext 事务
// accountDestroyRecordId 账号注销记录Id
func FastPgAccountDestroyRecord(transactionContext application.TransactionContext, accountDestroyRecordId int64) (domain.AccountDestroyRecordRepository, *domain.AccountDestroyRecord, error) {
var rep domain.AccountDestroyRecordRepository
var mod *domain.AccountDestroyRecord
var err error
if value, err := CreateAccountDestroyRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if accountDestroyRecordId > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"accountDestroyRecord": accountDestroyRecordId}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "账号注销记录不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
... ...
... ... @@ -2,6 +2,7 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
"reflect"
"strings"
... ... @@ -16,6 +17,9 @@ type BatchEnableCommand struct {
func (batchEnableCommand *BatchEnableCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
if !(batchEnableCommand.EnableStatus == int(domain.UserStatusEnable) || batchEnableCommand.EnableStatus == int(domain.UserStatusDisable)) {
validation.SetError("CustomValid", "非法启用状态")
}
}
func (batchEnableCommand *BatchEnableCommand) ValidateCommand() error {
... ...
... ... @@ -10,15 +10,15 @@ import (
type ListUserQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
Limit int `cname:"查询限制" json:"limit"`
// 企业id
CompanyId int64 `cname:"企业id" json:"companyId,string,omitempty"`
CompanyId int64 `cname:"企业id" json:"companyId,omitempty"`
// 组织ID
OrganizationId int64 `cname:"组织ID" json:"organizationId,string,omitempty"`
OrganizationId int64 `cname:"组织ID" json:"organizationId,omitempty"`
// 部门编号
DepartmentId int64 `cname:"部门编号" json:"departmentId,string,omitempty"`
DepartmentId int64 `cname:"部门编号" json:"departmentId,omitempty"`
// 用户姓名
UserName string `cname:"用户姓名" json:"userName,omitempty"`
// 部门名称
... ...
... ... @@ -51,10 +51,28 @@ func (userService *UserService) BatchEnable(batchEnableCommand *command.BatchEna
defer func() {
transactionContext.RollbackTransaction()
}()
userRepository, _, err := factory.FastPgUser(transactionContext, 0)
if err != nil {
return nil, err
}
for i := 0; i < len(batchEnableCommand.UserIds); i++ {
if user, err := userRepository.FindOne(map[string]interface{}{"userId": batchEnableCommand.UserIds[i]}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := user.SetEnableStatus(batchEnableCommand.EnableStatus); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err := userRepository.Save(user); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return struct{}{}, nil
}
// 批量重置密码
... ... @@ -72,10 +90,28 @@ func (userService *UserService) BatchResetPassword(batchResetPasswordCommand *co
defer func() {
transactionContext.RollbackTransaction()
}()
for i := range batchResetPasswordCommand.UserIds {
_, user, err := factory.FastPgUser(transactionContext, batchResetPasswordCommand.UserIds[i])
if err != nil {
return nil, err
}
userBaseRepository, userBase, err := factory.FastPgUserBase(transactionContext, user.UserBaseId)
if err != nil {
return nil, err
}
if err := userBase.ResetPassword(userBase.Account, batchResetPasswordCommand.Password); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err := userBaseRepository.Save(userBase); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return struct{}{}, nil
}
// 创建共创用户
... ... @@ -249,26 +285,25 @@ func (userService *UserService) GetUser(getUserQuery *query.GetUserQuery) (inter
defer func() {
transactionContext.RollbackTransaction()
}()
var userRepository domain.UserRepository
if value, err := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
userRepository = value
}
user, err := userRepository.FindOne(map[string]interface{}{"userId": getUserQuery.UserId})
_, user, err := factory.FastPgUser(transactionContext, getUserQuery.UserId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
return nil, err
}
if user == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getUserQuery.UserId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return user, nil
_, dep, _ := factory.FastPgOrg(transactionContext, user.DepartmentId)
_, org, _ := factory.FastPgOrg(transactionContext, user.OrganizationId)
_, company, _ := factory.FastPgCompany(transactionContext, user.CompanyId)
_, userBase, _ := factory.FastPgUserBase(transactionContext, user.UserBaseId)
if dep != nil && org != nil && company != nil && userBase != nil {
user.Department = dep.ConvDep()
user.Organization = org.CloneSample()
user.Company = company.CloneSample()
user.UserInfo = userBase.UserInfo
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return user, nil
}
// 返回用户有权限的菜单
... ... @@ -446,22 +481,12 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser
defer func() {
transactionContext.RollbackTransaction()
}()
var userRepository domain.UserRepository
if value, err := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
userRepository = value
}
user, err := userRepository.FindOne(map[string]interface{}{"userId": updateUserCommand.UserId})
userRepository, user, err := factory.FastPgUser(transactionContext, updateUserCommand.UserId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if user == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateUserCommand.UserId)))
return nil, err
}
if err := user.Update(tool_funs.SimpleStructToMap(updateUserCommand)); err != nil {
updateData := tool_funs.SimpleStructToMap(updateUserCommand)
if err := user.Update(updateData); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if user, err := userRepository.Save(user); err != nil {
... ...
... ... @@ -81,3 +81,11 @@ func (company *Company) Update(data map[string]interface{}) error {
}
return nil
}
func (company *Company) CloneSample() *Company {
return &Company{
CompanyId: company.CompanyId,
Status: company.Status,
CompanyInfo: company.CompanyInfo,
}
}
... ...
... ... @@ -5,19 +5,19 @@ import "time"
// 公司信息
type CompanyInfo struct {
// 企业名称
CompanyName string `json:"companyName"`
CompanyName string `json:"companyName,omitempty"`
// 规模
Scale string `json:"scale"`
Scale string `json:"scale,omitempty"`
// 公司Logo地址
Logo string `json:"logo"`
Logo string `json:"logo,omitempty"`
// 公司地址
Address string `json:"address"`
Address string `json:"address,omitempty"`
// 所属行业
IndustryCategory string `json:"industryCategory"`
IndustryCategory string `json:"industryCategory,omitempty"`
// 联系人
//Contacts string `json:"contacts"`
// 注册时间
RegisteredTime time.Time `json:"registeredTime"`
RegisteredTime time.Time `json:"registeredTime,omitempty"`
// 状态 1:已注册 2:待认证 3:已认证
//Status int `json:"status"`
}
... ...
... ... @@ -113,6 +113,16 @@ type Department struct {
// 部门编号
DepartmentNumber string `json:"departmentNumber"`
}
type SampleOrg struct {
// 组织ID
OrgId int64 `json:"orgId,omitempty"`
// 企业id
CompanyId int64 `json:"companyId,omitempty"`
// 组织名称
OrgName string `json:"orgName,omitempty"`
// 组织编码
OrgCode string `json:"orgCode,omitempty"`
}
// 通过组织获取当前部门信息
func (org *Org) ConvDep() *Department {
... ...
package domain
import (
"fmt"
"time"
)
... ... @@ -36,14 +37,8 @@ type User struct {
UserCode string `json:"userCode,omitempty"`
// 组织机构
OrganizationId int64 `json:"organizationId,omitempty"`
// 组织机构
Organization *Org `json:"org,omitempty"`
// 所属部门
DepartmentId int64 `json:"departmentId,omitempty"`
// 部门
Department *Department `json:"department,omitempty"`
// 用户信息 (冗余,数据存在userBase里面)
UserInfo *UserInfo `json:"userInfo,omitempty"`
// 用户关联的组织
UserOrg []*Org `json:"userOrg,omitempty"`
// 用户关联的角色
... ... @@ -60,6 +55,15 @@ type User struct {
CreatedAt time.Time `json:"createdAt,omitempty"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt,omitempty"`
// 用户信息 (冗余,数据存在userBase里面)
UserInfo *UserInfo `json:"userInfo,omitempty"`
// 企业id
Company *Company `json:"company,omitempty"`
// 组织机构
Organization *Org `json:"org,omitempty"`
// 部门
Department *Department `json:"department,omitempty"`
}
type UserRepository interface {
... ... @@ -77,21 +81,18 @@ func (user *User) Identify() interface{} {
}
func (user *User) Update(data map[string]interface{}) error {
if userId, ok := data["userId"]; ok {
user.UserId = userId.(int64)
}
if companyId, ok := data["companyId"]; ok {
user.CompanyId = companyId.(int64)
}
if userBaseId, ok := data["userBaseId"]; ok {
user.UserBaseId = userBaseId.(int64)
}
//if companyId, ok := data["companyId"]; ok {
// user.CompanyId = companyId.(int64)
//}
//if userBaseId, ok := data["userBaseId"]; ok {
// user.UserBaseId = userBaseId.(int64)
//}
//if userType, ok := data["userType"]; ok {
// user.UserType = userType.(int)
//}
if userCode, ok := data["userCode"]; ok {
user.UserCode = userCode.(string)
}
//if userCode, ok := data["userCode"]; ok {
// user.UserCode = userCode.(string)
//}
if organizationId, ok := data["organizationId"]; ok {
user.OrganizationId = organizationId.(int64)
}
... ... @@ -143,9 +144,6 @@ func (user *User) Update(data map[string]interface{}) error {
if parentDepName, ok := data["parentDepName"]; ok {
user.Ext.ParentDepName = parentDepName.(string)
}
if createdAt, ok := data["createdAt"]; ok {
user.CreatedAt = createdAt.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
user.UpdatedAt = updatedAt.(time.Time)
}
... ... @@ -159,7 +157,24 @@ type UserStatus int
//
// accountAfter 变更后的账号
func (user *User) DestroyAccount(accountAfter string) error {
user.EnableStatus = int(UserStatusDestroy)
if err := user.SetEnableStatus(int(UserStatusDestroy)); err != nil {
return err
}
user.Ext.Phone = accountAfter
return nil
}
func (user *User) SetEnableStatus(enableStatus int) error {
userStatus := UserStatus(user.EnableStatus)
if userStatus == UserStatusDestroy {
return fmt.Errorf("账号已注销")
}
if user.EnableStatus == enableStatus {
return fmt.Errorf("重复设置状态")
}
if !(userStatus == UserStatusEnable || userStatus == UserStatusDisable || userStatus == UserStatusDestroy) {
return fmt.Errorf("非法启用状态")
}
user.EnableStatus = enableStatus
return nil
}
... ...
... ... @@ -83,9 +83,10 @@ func (ptr *PgSignUpCompanyService) SignUpCompany(registerPhone string, password
EnableStatus: int(domain.UserStatusEnable),
UserInfo: userInfo,
Ext: &domain.Ext{
OrgName: org.OrgName,
DepName: org.OrgName,
Phone: registerPhone,
UserName: userInfo.UserName,
OrgName: org.OrgName,
DepName: org.OrgName,
Phone: registerPhone,
},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
... ...
... ... @@ -165,8 +165,19 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int
var userModels []*models.User
users := make([]*domain.User, 0)
query := sqlbuilder.BuildQuery(tx.Model(&userModels), queryOptions)
query.SetWhereByQueryOption("company_id=?", "companyId")
query.SetWhereByQueryOption("organization_id=?", "organizationId")
query.SetWhereByQueryOption("user_base_id=?", "userBaseId")
query.SetOffsetAndLimit(20)
if v, ok := queryOptions["depName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`ext->>'depName' like '%%%v%%'`, v))
}
if v, ok := queryOptions["userName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`ext->>'userName' like '%%%v%%'`, v))
}
if v, ok := queryOptions["cooperationCompany"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`cooperation_info->>'cooperationCompany'' like '%%%v%%'`, v))
}
query.SetOffsetAndLimit(999)
query.SetOrderDirect("user_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, users, err
... ...
... ... @@ -126,3 +126,11 @@ func (controller *UserController) UpdateCooperator() {
data, err := userService.UpdateCooperator(updateCooperatorCommand)
controller.Response(data, err)
}
func (controller *UserController) SearchUser() {
userService := service.NewUserService(nil)
listUserQuery := &query.ListUserQuery{}
Must(controller.Unmarshal(listUserQuery))
data, err := userService.ListUser(listUserQuery)
controller.Response(data, err)
}
... ...
... ... @@ -10,7 +10,7 @@ func init() {
web.Router("/user/:userId", &controllers.UserController{}, "Put:UpdateUser")
web.Router("/user/:userId", &controllers.UserController{}, "Get:GetUser")
web.Router("/user/:userId", &controllers.UserController{}, "Delete:RemoveUser")
web.Router("/user/search", &controllers.UserController{}, "Post:ListUser")
web.Router("/user/search", &controllers.UserController{}, "Post:SearchUser")
web.Router("/user/:userId/access-menus", &controllers.UserController{}, "Get:GetUserAccessMenus")
web.Router("/user/:userId/profile", &controllers.UserController{}, "Get:GetUserProfile")
web.Router("/user/batch-add", &controllers.UserController{}, "Post:BatchAdd")
... ...
... ... @@ -11,13 +11,19 @@ import (
)
var _ = Describe("批量修改启用状态", func() {
return
var userId int64
var Id int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"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",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
var err error
_, err = pG.DB.QueryOne(
pg.Scan(&Id),
"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;",
)
Expect(err).NotTo(HaveOccurred())
_, err = pG.DB.QueryOne(
pg.Scan(&Id),
"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",
)
Expect(err).NotTo(HaveOccurred())
})
Describe("批量修改启用状态", func() {
... ... @@ -25,8 +31,8 @@ var _ = Describe("批量修改启用状态", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"userIds": "array",
"enableStatus": "int",
"userIds": []int64{999},
"enableStatus": 2,
}
httpExpect.POST("/user/batch-enable").
WithJSON(body).
... ... @@ -41,7 +47,9 @@ var _ = Describe("批量修改启用状态", func() {
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
_, err := pG.DB.Exec("DELETE FROM users.user_base WHERE user_base_id = 999")
Expect(err).NotTo(HaveOccurred())
_, err = pG.DB.Exec(`DELETE FROM users."user" WHERE user_id = 999`)
Expect(err).NotTo(HaveOccurred())
})
})
... ...
... ... @@ -11,13 +11,19 @@ import (
)
var _ = Describe("批量重置密码", func() {
return
var userId int64
var Id int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"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",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
var err error
_, err = pG.DB.QueryOne(
pg.Scan(&Id),
"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;",
)
Expect(err).NotTo(HaveOccurred())
_, err = pG.DB.QueryOne(
pg.Scan(&Id),
"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",
)
Expect(err).NotTo(HaveOccurred())
})
Describe("批量重置密码", func() {
... ... @@ -25,8 +31,8 @@ var _ = Describe("批量重置密码", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"userIds": "array",
"password": "string",
"userIds": []int64{999},
"password": "string999",
}
httpExpect.POST("/user/batch-reset-password").
WithJSON(body).
... ... @@ -41,7 +47,9 @@ var _ = Describe("批量重置密码", func() {
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
_, err := pG.DB.Exec("DELETE FROM users.user_base WHERE user_base_id = 999")
Expect(err).NotTo(HaveOccurred())
_, err = pG.DB.Exec(`DELETE FROM users."user" WHERE user_id = 999`)
Expect(err).NotTo(HaveOccurred())
})
})
... ...
... ... @@ -24,6 +24,7 @@ var _ = Describe("创建共创用户", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": 999,
"cooperationCompany": "string",
"cooperationDeadline": "2021-07-25T15:11:56+08:00",
"email": "string",
... ...
... ... @@ -11,20 +11,26 @@ import (
)
var _ = Describe("返回", func() {
return
var userId int64
var Id int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"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",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
var err error
_, err = pG.DB.QueryOne(
pg.Scan(&Id),
"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;",
)
Expect(err).NotTo(HaveOccurred())
_, err = pG.DB.QueryOne(
pg.Scan(&Id),
"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",
)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据userId参数返回用户", func() {
Context("传入有效的userId", func() {
It("返回用户数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/user/{userId}").
httpExpect.GET("/user/999").
Expect().
Status(http.StatusOK).
JSON().
... ... @@ -36,7 +42,9 @@ var _ = Describe("返回", func() {
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
_, err := pG.DB.Exec("DELETE FROM users.user_base WHERE user_base_id = 999")
Expect(err).NotTo(HaveOccurred())
_, err = pG.DB.Exec(`DELETE FROM users."user" WHERE user_id = 999`)
Expect(err).NotTo(HaveOccurred())
})
})
... ...
... ... @@ -11,13 +11,19 @@ import (
)
var _ = Describe("返回列表", func() {
return
var userId int64
var Id int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"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",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
var err error
_, err = pG.DB.QueryOne(
pg.Scan(&Id),
"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;",
)
Expect(err).NotTo(HaveOccurred())
_, err = pG.DB.QueryOne(
pg.Scan(&Id),
"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",
)
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回用户列表", func() {
... ... @@ -25,11 +31,11 @@ var _ = Describe("返回列表", func() {
It("返回用户数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"offset": "int",
"limit": "int",
"companyId": "int64",
"organizationId": "int64",
"departmentId": "int64",
"offset": 0,
"limit": 20,
"companyId": 5,
"organizationId": 5,
"departmentId": 5,
"userName": "string",
"depName": "string",
"phone": "string",
... ... @@ -43,13 +49,15 @@ var _ = Describe("返回列表", func() {
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
//ContainsKey("count").ValueEqual("count", 1).
ContainsKey("users").Value("users").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
_, err := pG.DB.Exec("DELETE FROM users.user_base WHERE user_base_id = 999")
Expect(err).NotTo(HaveOccurred())
_, err = pG.DB.Exec(`DELETE FROM users."user" WHERE user_id = 999`)
Expect(err).NotTo(HaveOccurred())
})
})
... ...