作者 tangxuhui
... ... @@ -10,7 +10,7 @@ import (
type DestroyAccountCommand struct {
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"`
Account string `cname:"账号" json:"account" valid:"Required"`
}
func (destroyAccountCommand *DestroyAccountCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -7,6 +7,7 @@ import (
type UserBaseDto struct {
// 用户基础数据id
UserBaseId int64 `json:"userBaseId,omitempty"`
UserType int `json:"userType"`
// 用户信息
UserInfo *domain.UserInfo `json:"userInfo,omitempty"`
// 手机号码
... ... @@ -28,5 +29,6 @@ type UserBaseDto struct {
func (u *UserBaseDto) LoadDto(ub *domain.UserBase) {
u.UserBaseId = ub.UserBaseId
u.UserInfo = ub.UserInfo
u.UserType = domain.UserTypeVisitor
u.Im = ub.Im
}
... ...
... ... @@ -9,11 +9,15 @@ import (
)
type UserInfoQuery struct {
Account string `cname:"账号" json:"account" valid:"Required"`
Account string `cname:"账号" json:"account"`
UserBaseId int64 `cname:"用户编号" json:"userBaseId"`
}
func (userInfoQuery *UserInfoQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
if len(userInfoQuery.Account) == 0 && userInfoQuery.UserBaseId <= 0 {
validation.SetError("CustomValid", "参数不能为空")
}
}
func (userInfoQuery *UserInfoQuery) ValidateQuery() error {
... ...
... ... @@ -81,7 +81,7 @@ func (authService *AuthService) DestroyAccount(destroyAccountCommand *command.De
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := accountDestroyService.DestroyAccount(nil, destroyAccountCommand.UserId); err != nil {
if err := accountDestroyService.DestroyAccount(nil, destroyAccountCommand.Account); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -319,8 +319,13 @@ func (authService *AuthService) UserInfo(userInfoQuery *query.UserInfoQuery) (in
transactionContext.RollbackTransaction()
}()
var userBase *domain.UserBase
userBaseRepository, _, _ := factory.FastPgUserBase(transactionContext, 0)
userBase, err := userBaseRepository.FindOne(map[string]interface{}{"account": userInfoQuery.Account})
if len(userInfoQuery.Account) > 0 {
userBase, err = userBaseRepository.FindOne(map[string]interface{}{"account": userInfoQuery.Account})
} else if userInfoQuery.UserBaseId > 0 {
userBase, err = userBaseRepository.FindOne(map[string]interface{}{"userBaseId": userInfoQuery.UserBaseId})
}
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
... ...
... ... @@ -25,6 +25,8 @@ type ListOrgQuery struct {
ParentId int64 `cname:"父级ID" json:"parentId,omitempty"`
// 是否是组织(是:1 不是:2)
IsOrg int `cname:"是否是组织(是:1 不是:2)" json:"isOrg,omitempty"`
// 模糊匹配组织名称
MatchOrgName string `cname:"部门名称" json:"matchOrgName,omitempty"`
}
func (listOrgQuery *ListOrgQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -12,7 +12,7 @@ import (
type GetRoleRelatedUsersQuery struct {
OperateInfo *domain.OperateInfo `json:"-"`
// 组织ID
OrgId int64 `cname:"组织ID" json:"orgId,string,omitempty"`
OrgId int64 `cname:"组织ID" json:"orgId,omitempty"`
// 角色ID
RoleId int64 `cname:"角色ID" json:"roleId" valid:"Required"`
... ... @@ -20,6 +20,8 @@ type GetRoleRelatedUsersQuery struct {
DepartmentId int64 `cname:"部门编号" json:"departmentId,omitempty"`
// 只需要关联的用户 true:仅返回关联用户信息 false:返回所有其他信息(未关联的用户)
//OnlyRelatedUser bool `cname:"部门编号" json:"onlyRelatedUser,omitempty"`
// 组织ID
InOrgIds []int64 `cname:"组织ID" json:"orgIds,omitempty"`
}
func (getRoleRelatedUsersQuery *GetRoleRelatedUsersQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -27,6 +27,8 @@ type ListRoleQuery struct {
OrgId int64 `cname:"组织ID" json:"orgId,omitempty"`
// 匹配多个组织
InOrgIds []int64 `cname:"匹配多个组织" json:"inOrgIds,omitempty"`
// 角色名称
MatchRoleName string `cname:"匹配角色名称" json:"matchRoleName,omitempty"`
}
func (listRoleQuery *ListRoleQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -218,10 +218,15 @@ func (roleService *RoleService) GetRoleRelatedUsers(getRoleRelatedUsersQuery *qu
}
queryOptions := make(map[string]interface{})
queryOptions["companyId"] = role.CompanyId
queryOptions["organizationId"] = getRoleRelatedUsersQuery.OrgId
if getRoleRelatedUsersQuery.DepartmentId > 0 {
queryOptions["departmentId"] = getRoleRelatedUsersQuery.DepartmentId
}
// 按组织过滤
if len(getRoleRelatedUsersQuery.InOrgIds) > 0 {
queryOptions["inOrgIds"] = getRoleRelatedUsersQuery.InOrgIds
} else {
queryOptions["organizationId"] = getRoleRelatedUsersQuery.OrgId
}
queryOptions["userType"] = domain.UserTypeEmployee
_, users, err := userRepository.Find(queryOptions)
if err != nil {
... ...
... ... @@ -9,6 +9,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log"
"time"
)
... ... @@ -359,12 +360,24 @@ func (userService *UserService) GetUser(getUserQuery *query.GetUserQuery) (inter
_, org, _ := factory.FastPgOrg(transactionContext, user.OrganizationId)
_, company, _ := factory.FastPgCompany(transactionContext, user.CompanyId)
_, userBase, _ := factory.FastPgUserBase(transactionContext, user.UserBaseId)
if dep != nil && org != nil && userBase != nil {
user.Department = dep.ConvDep()
user.Organization = org.CloneSample()
if company != nil {
user.Company = company.CloneSample()
}
if org != nil {
user.Organization = org.CloneSample()
}
if dep != nil {
user.Department = dep.ConvDep()
}
if userBase != nil {
user.UserInfo = userBase.UserInfo
}
// TODO:后期可以移除有冗余roleType
for i := range user.UserRole {
if _, role, _ := factory.FastPgRole(transactionContext, user.UserRole[i].RoleId); role != nil {
user.UserRole[i].RoleType = role.RoleType
}
}
userDto := &dto.UserDto{Im: userBase.Im}
if err := userDto.LoadDto(user, company); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -486,6 +499,7 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in
userRepository = value
}
var company *domain.Company
var mapCompany = make(map[int64]*domain.Company)
var dtoUsers []*dto.UserDto
queryOptions := utils.ObjectToMap(listUserQuery)
if len(listUserQuery.Phone) > 0 {
... ... @@ -502,8 +516,14 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in
for i := range users {
user := users[i]
userDto := &dto.UserDto{}
if company == nil && user.CompanyId != 0 {
_, company, _ = factory.FastPgCompany(transactionContext, user.CompanyId)
var ok bool
if company, ok = mapCompany[user.CompanyId]; !ok {
_, company, err = factory.FastPgCompany(transactionContext, user.CompanyId)
if err != nil {
log.Logger.Error(err.Error())
continue
}
mapCompany[company.CompanyId] = company
}
if listUserQuery.PullRealTime {
_, dep, _ := factory.FastPgOrg(transactionContext, user.DepartmentId)
... ...
... ... @@ -127,6 +127,7 @@ func (role *Role) CloneSample() *Role {
RoleId: role.RoleId,
RoleName: role.RoleName,
Ext: role.Ext,
RoleType: role.RoleType,
}
}
... ...
... ... @@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
// PgAuthAccountDestroyService 账号注销服务
type PgAuthAccountDestroyService interface {
DestroyAccount(optUser *domain.User, userId int64) error
DestroyAccount(optUser *domain.User, userId string) error
}
... ...
... ... @@ -14,6 +14,7 @@ const (
const (
UserTypeEmployee = 1
UserTypeCooperation = 2
UserTypeVisitor = 4 // 游客
UserTypeCompanyAdmin = 1024
)
... ...
... ... @@ -13,21 +13,21 @@ type PgAuthAccountDestroyService struct {
transactionContext *pgTransaction.TransactionContext
}
func (ptr *PgAuthAccountDestroyService) DestroyAccount(optUser *domain.User, userId int64) error {
func (ptr *PgAuthAccountDestroyService) DestroyAccount(optUser *domain.User, account string) error {
// 1.查询账号记录
userRepository, _ := repository.NewUserRepository(ptr.transactionContext)
var userBaseId int64
if user, err := userRepository.FindOne(map[string]interface{}{"userId": userId}); err != nil {
if err == domain.ErrorNotFound {
return fmt.Errorf("该用户不存在")
}
return err
} else {
userBaseId = user.UserBaseId
}
//var userBaseId int64
//if user, err := userRepository.FindOne(map[string]interface{}{"userId": userId}); err != nil {
// if err == domain.ErrorNotFound {
// return fmt.Errorf("该用户不存在")
// }
// return err
//} else {
// userBaseId = user.UserBaseId
//}
userBaseRepository, _ := repository.NewUserBaseRepository(ptr.transactionContext)
userBase, err := userBaseRepository.FindOne(map[string]interface{}{"userBaseId": userBaseId})
userBase, err := userBaseRepository.FindOne(map[string]interface{}{"account": account})
if err != nil {
return err
}
... ...
... ... @@ -14,9 +14,6 @@ type PgBatchAddOrgService struct {
}
func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgList []*domain.BatchAddOrgItem) error {
var (
err error
)
orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
if err != nil {
return err
... ...
... ... @@ -191,6 +191,9 @@ func (repository *OrgRepository) Find(queryOptions map[string]interface{}) (int6
query.SetWhereByQueryOption("org_name = ?", "depName")
query.SetWhereByQueryOption("org_code = ?", "orgCode")
query.SetWhereByQueryOption("parent_id = ?", "parentId")
if v, ok := queryOptions["matchOrgName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`org_name like '%%%v%%'`, v))
}
query.SetOrderDirect("org_id", "ASC")
if count, err := query.SelectAndCount(); err != nil {
return 0, orgs, err
... ...
... ... @@ -185,6 +185,9 @@ func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int
if orgName, ok := queryOptions["orgName"]; ok && len(orgName.(string)) > 0 {
query.Where(fmt.Sprintf("ext->>'orgName' like '%%%v%%'", orgName))
}
if matchRoleName, ok := queryOptions["matchRoleName"]; ok && len(matchRoleName.(string)) > 0 {
query.Where(fmt.Sprintf("role_name like '%%%v%%'", matchRoleName))
}
// 包含删除的
if v, ok := queryOptions["includeDeleted"]; ok && !(v.(bool)) {
query.Where("deleted_at is null")
... ...
... ... @@ -92,6 +92,17 @@ func (controller *RoleController) GetRoleRelatedUsers() {
controller.Response(data, err)
}
func (controller *RoleController) RoleRelatedUsers() {
roleService := service.NewRoleService(nil)
getRoleRelatedUsersQuery := &query.GetRoleRelatedUsersQuery{}
controller.Unmarshal(getRoleRelatedUsersQuery)
roleId, _ := controller.GetInt64(":roleId")
getRoleRelatedUsersQuery.RoleId = roleId
getRoleRelatedUsersQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
data, err := roleService.GetRoleRelatedUsers(getRoleRelatedUsersQuery)
controller.Response(data, err)
}
func (controller *RoleController) GetRoleAccessMenus() {
roleService := service.NewRoleService(nil)
getRoleAccessMenusQuery := &query.GetRoleAccessMenusQuery{}
... ...
... ... @@ -13,5 +13,5 @@ func init() {
web.Router("/auth/reset-phone", &controllers.AuthController{}, "Post:PhoneAuthResetPhone")
web.Router("/auth/destroy-account", &controllers.AuthController{}, "Post:DestroyAccount")
web.Router("/auth/refresh-im", &controllers.AuthController{}, "Post:RefreshIM")
web.Router("/auth/user-base-info", &controllers.AuthController{}, "Post:UserInfo")
web.Router("/auth/user-info", &controllers.AuthController{}, "Post:UserInfo")
}
... ...
... ... @@ -12,6 +12,7 @@ func init() {
web.Router("/role/:roleId", &controllers.RoleController{}, "Delete:RemoveRole")
web.Router("/role/search", &controllers.RoleController{}, "Post:SearchRole")
web.Router("/role/:roleId/related-user", &controllers.RoleController{}, "Get:GetRoleRelatedUsers")
web.Router("/role/:roleId/related-user", &controllers.RoleController{}, "Post:RoleRelatedUsers")
web.Router("/role/:roleId/access-menus", &controllers.RoleController{}, "Get:GetRoleAccessMenus")
web.Router("/role/:roleId/access-menus", &controllers.RoleController{}, "Put:UpdateRoleAccessMenus")
web.Router("/role/assign", &controllers.RoleController{}, "Post:AssginRoleToUsers")
... ...