作者 yangfu

用户概要数据、更新用户基础数据

... ... @@ -12,7 +12,7 @@ type ListCompanyCustomizeMenusCommand struct {
// 企业id
CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"`
// 菜单类别 web app
MenuCategory string `json:"menuCategory,omitempty" valid:"Required"`
MenuCategory string `cname:"菜单类别" json:"menuCategory,omitempty" valid:"Required"`
}
func (listCompanyCustomizeMenusCommand *ListCompanyCustomizeMenusCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -12,11 +12,11 @@ type GetUserProfileQuery struct {
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string,omitempty"`
// 手机号码
Phone string `cname:"手机号码" json:"phone,omitempty"`
//Phone string `cname:"手机号码" json:"phone,omitempty"`
// 企业id
CompanyId int64 `cname:"企业id" json:"companyId,string,omitempty"`
//CompanyId int64 `cname:"企业id" json:"companyId,string,omitempty"`
// 用户编号 企业内标识
UserCode string `cname:"用户编号 企业内标识" json:"userCode,omitempty"`
//UserCode string `cname:"用户编号 企业内标识" json:"userCode,omitempty"`
}
func (getUserProfileQuery *GetUserProfileQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -164,11 +164,14 @@ func (userService *UserService) CreateCooperator(createCooperatorCommand *comman
if user, err = createUserService.CreateUser(nil, newUser, createCooperatorCommand.Password); err != nil {
return nil, err
}
userDto := &dto.UserDto{}
if err := userDto.LoadDto(user, nil); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return user, nil
return userDto, nil
}
// 创建
... ... @@ -219,7 +222,7 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser
UserOrg: sampleUserOrg,
UserRole: sampleUserRole,
FavoriteMenus: []string{},
CooperationInfo: &domain.CooperationInfo{},
//CooperationInfo: &domain.CooperationInfo{},
UserInfo: nweUserInfo,
EnableStatus: createUserCommand.EnableStatus,
Ext: &domain.Ext{
... ... @@ -236,10 +239,14 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser
if user, err = createUserService.CreateUser(nil, newUser, createUserCommand.Password); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
userDto := &dto.UserDto{}
if err := userDto.LoadDto(user, nil); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return user, nil
return userDto, nil
}
// 移除我收藏的菜单
... ... @@ -404,7 +411,7 @@ func (userService *UserService) GetUserAccessMenus(getUserAccessMenusQuery *quer
}, nil
}
// TODO:获取用户概要数据
// 获取用户概要数据
func (userService *UserService) GetUserProfile(getUserProfileQuery *query.GetUserProfileQuery) (interface{}, error) {
if err := getUserProfileQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -419,10 +426,29 @@ func (userService *UserService) GetUserProfile(getUserProfileQuery *query.GetUse
defer func() {
transactionContext.RollbackTransaction()
}()
_, user, err := factory.FastPgUser(transactionContext, getUserProfileQuery.UserId)
if err != nil {
return nil, err
}
_, userBase, err := factory.FastPgUserBase(transactionContext, user.UserBaseId)
if err != nil {
return nil, err
}
var userProfile = make(map[string]interface{})
userProfile["userId"] = user.UserId
userProfile["userCode"] = user.UserCode
userProfile["userBaseId"] = user.UserBaseId
userProfile["phone"] = userBase.UserInfo.Phone
userProfile["avatar"] = userBase.UserInfo.Avatar
userProfile["email"] = userBase.UserInfo.Email
userProfile["userName"] = userBase.UserInfo.UserName
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return userProfile, nil
}
// 返回列表
... ... @@ -557,11 +583,14 @@ func (userService *UserService) UpdateCooperator(updateCooperatorCommand *comman
if user, err = updateUserService.UpdateUser(nil, user, userInfo, updateCooperatorCommand.EnableStatus); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
userDto := &dto.UserDto{}
if err := userDto.LoadDto(user, nil); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
return userDto, nil
}
// 更新我喜欢菜单列表
... ... @@ -630,11 +659,14 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser
if user, err = updateUserService.UpdateUser(nil, user, userInfo, updateUserCommand.EnableStatus); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
userDto := &dto.UserDto{}
if err := userDto.LoadDto(user, nil); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return user, nil
return userDto, nil
}
// 更新用户基础信息数据
... ... @@ -652,10 +684,27 @@ func (userService *UserService) UpdateUsersBase(updateUsersBaseCommand *command.
defer func() {
transactionContext.RollbackTransaction()
}()
_, user, err := factory.FastPgUser(transactionContext, updateUsersBaseCommand.UserId)
if err != nil {
return nil, err
}
userInfo := &domain.UserInfo{
UserName: updateUsersBaseCommand.UserName,
Phone: updateUsersBaseCommand.Phone,
Avatar: updateUsersBaseCommand.Avatar,
Email: updateUsersBaseCommand.Email,
}
updateUserService, _ := factory.CreatePgUpdateUserService(map[string]interface{}{
"transactionContext": transactionContext,
})
if user, err = updateUserService.UpdateUser(nil, user, userInfo, user.EnableStatus); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return struct{}{}, nil
}
func NewUserService(options map[string]interface{}) *UserService {
... ...
... ... @@ -45,7 +45,7 @@ type Menu struct {
// 菜单编号
MenuId int64 `json:"menuId,omitempty"`
// 父级id
ParentId int64 `json:"parentId,omitempty"`
ParentId int64 `json:"parentId"`
// 菜单名称
MenuName string `json:"menuName,omitempty"`
// 菜单别名
... ...
... ... @@ -28,7 +28,7 @@ func init() {
web.BConfig.Listen.HTTPPort = port
}
}
web.InsertFilter("/*", web.BeforeExec, filters.AllowCors())
web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors())
web.InsertFilter("/*", web.BeforeExec, CreateRequestLogFilter(Logger))
web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false))
}
... ...
... ... @@ -15,6 +15,6 @@ func init() {
web.Router("/company/:companyId/customize-menus", &controllers.CompanyController{}, "Put:UpdateCompanyCustomizeMenus")
// 适配web
web.Router("/v1/web/menus/search", &controllers.CompanyController{}, "Post:SearchCompanyCustomizeMenus")
web.Router("/v1/web/menus", &controllers.CompanyController{}, "Put:AdapterUpdateCompanyCustomizeMenus")
//web.Router("/v1/web/menus/search", &controllers.CompanyController{}, "Post:SearchCompanyCustomizeMenus")
//web.Router("/v1/web/menus", &controllers.CompanyController{}, "Put:AdapterUpdateCompanyCustomizeMenus")
}
... ...
... ... @@ -13,12 +13,12 @@ func init() {
web.Router("/menus/", &controllers.MenuController{}, "Get:ListMenu")
web.Router("/menus/search", &controllers.MenuController{}, "Post:SearchMenu")
web.Router("/v1/opt/menus/", &controllers.MenuController{}, "Post:CreateMenu")
web.Router("/v1/opt/menus/:menuId", &controllers.MenuController{}, "Put:UpdateMenu")
web.Router("/v1/opt/menus/:menuId", &controllers.MenuController{}, "Get:GetMenu")
web.Router("/v1/opt/menus/:menuId", &controllers.MenuController{}, "Delete:RemoveMenu")
web.Router("/v1/opt/menus/search", &controllers.MenuController{}, "Get:ListMenu")
web.Router("/v1/opt/menus/search", &controllers.MenuController{}, "Post:SearchMenu")
web.Router("/v1/web/menus/", &controllers.MenuController{}, "Post:CreateMenu")
web.Router("/v1/web/menus/:menuId", &controllers.MenuController{}, "Put:UpdateMenu")
web.Router("/v1/web/menus/:menuId", &controllers.MenuController{}, "Get:GetMenu")
web.Router("/v1/web/menus/:menuId", &controllers.MenuController{}, "Delete:RemoveMenu")
web.Router("/v1/web/menus/search", &controllers.MenuController{}, "Get:ListMenu")
web.Router("/v1/web/menus/search", &controllers.MenuController{}, "Post:SearchMenu")
web.Router("/v1/web/common/dictionary/search", &controllers.CommonController{}, "Post:DictionarySearch")
}
... ...
... ... @@ -11,20 +11,32 @@ import (
)
var _ = Describe("获取用户概要数据", func() {
return
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
var err error
_, 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")
"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(&userId),
"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())
_, err = pG.DB.QueryOne(
pg.Scan(&userId),
"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,'');",
)
Expect(err).NotTo(HaveOccurred())
})
Describe("获取用户概要数据", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/user/{userId}/profile").
httpExpect.GET("/user/999/profile").
Expect().
Status(http.StatusOK).
JSON().
... ... @@ -36,7 +48,11 @@ 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())
_, err = pG.DB.Exec(`DELETE FROM users."org" WHERE org_id = 999`)
Expect(err).NotTo(HaveOccurred())
})
})
... ...
... ... @@ -11,13 +11,25 @@ import (
)
var _ = Describe("更新用户基础信息数据", func() {
return
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
var err error
_, 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")
"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(&userId),
"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())
_, err = pG.DB.QueryOne(
pg.Scan(&userId),
"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,'');",
)
Expect(err).NotTo(HaveOccurred())
})
Describe("更新用户基础信息数据", func() {
... ... @@ -30,7 +42,7 @@ var _ = Describe("更新用户基础信息数据", func() {
"phone": "string",
"email": "string",
}
httpExpect.PUT("/user/{userId}/base-info").
httpExpect.PUT("/user/999/base-info").
WithJSON(body).
Expect().
Status(http.StatusOK).
... ... @@ -43,7 +55,11 @@ 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())
_, err = pG.DB.Exec(`DELETE FROM users."org" WHERE org_id = 999`)
Expect(err).NotTo(HaveOccurred())
})
})
... ...