作者 yangfu

Merge branch 'dev' into test

FROM 192.168.0.243:5000/mmm/allied-creation-user:20210809
ENV APP_DIR $GOPATH/src/project-20210825
ENV APP_DIR $GOPATH/src/project-20210906
RUN mkdir -p $APP_DIR
WORKDIR $APP_DIR/
COPY ./pkg pkg
... ...
... ... @@ -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) {
... ...
... ... @@ -185,7 +185,7 @@ func (orgService *OrgService) GetOrgSubDepartment(getOrgSubDepartmentQuery *quer
treeNodes[i] = orgs[i]
}
tree := domain.NewTrees(treeNodes)
nodes := tree.AllChildNodes(org)
nodes := tree.AllSubDepartment(org)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -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 {
... ...
... ... @@ -39,6 +39,8 @@ type ListUserQuery struct {
PullRealTime bool `cname:"拉取最新数据" json:"pullRealTime,omitempty"`
// 状态(1:启用 2:禁用 3:注销)
EnableStatus int `cname:"状态(1:启用 2:禁用 3:注销)" json:"enableStatus,omitempty"`
// 状态(1:启用 2:禁用 3:注销)
InEnableStatus []int `cname:"状态(1:启用 2:禁用 3:注销)" json:"inEnableStatus,omitempty"`
}
func (listUserQuery *ListUserQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -65,10 +65,15 @@ func (userService *UserService) BatchAdd2(batchAddCommand *command.BatchAdd2Comm
batchAddUserService, _ := factory.CreateBatchAddUserService(map[string]interface{}{
"transactionContext": transactionContext,
})
if err = batchAddUserService.BatchAddUser2(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
var failRows []*domain.BatchAddUserItem
if failRows, err = batchAddUserService.BatchAddUser2(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil {
return batchAddCommand.Users, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if len(failRows) != 0 {
return map[string]interface{}{
"failRows": failRows,
}, nil //有错误行,回滚
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -360,12 +365,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())
... ... @@ -402,7 +419,7 @@ func (userService *UserService) GetUserAccessMenus(getUserAccessMenusQuery *quer
"transactionContext": transactionContext,
})
menus, err := roleAccessMenusService.AccessMenus(nil, user.UserRoleIds(), domain.AccessMenusOptions{
menus, err := roleAccessMenusService.AccessMenus(getUserAccessMenusQuery.OperateInfo, user.UserRoleIds(), domain.AccessMenusOptions{
CompanyId: user.CompanyId,
MenuCategory: getUserAccessMenusQuery.MenuCategory,
OrgId: getUserAccessMenusQuery.OrgId,
... ...
... ... @@ -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
}
... ...
... ... @@ -5,5 +5,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
// PgBatchAddUserService 批量添加用户服务
type PgBatchAddUserService interface {
BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error
BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) error
BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error)
}
... ...
... ... @@ -111,6 +111,35 @@ func traverse(tree *Tree, node TreeNode) bool {
return match
}
// 返回tree下的所有子部门 (如果节点是组织,跳过)
func (tree *Tree) AllSubDepartment(node TreeNode) []TreeNode {
treeNode := tree.find(node)
if treeNode == nil {
return []TreeNode{}
}
var stack []*Tree
stack = append(stack, treeNode)
var res []TreeNode
rootId := treeNode.Node.(*Org).OrgId
for {
if len(stack) == 0 {
break
}
pop := stack[0]
stack = stack[1:]
/***特殊处理***/
if org, ok := pop.Node.(*Org); ok && org.OrgId != int64(rootId) {
if org.IsOrg == IsOrgFlag {
continue
}
}
/***特殊处理***/
stack = append(stack, pop.Nodes...)
res = append(res, pop.Node)
}
return res
}
// Int64String 1 -> "1" 1->1
type Int64String int64
... ...
... ... @@ -14,6 +14,7 @@ const (
const (
UserTypeEmployee = 1
UserTypeCooperation = 2
UserTypeVisitor = 4 // 游客
UserTypeCompanyAdmin = 1024
)
... ... @@ -293,21 +294,24 @@ type BatchAddUserItem struct {
// 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)
UserType int `json:"userType,omitempty"`
// 用户姓名
UserName string `json:"userName,omitempty"`
UserName string `json:"userName"`
// 手机号码
Phone string `json:"phone,omitempty"`
Phone string `json:"phone"`
// 邮箱
Email string `json:"email,omitempty"`
Email string `json:"email"`
// 用户编号 企业内标识
UserCode string `json:"userCode,omitempty"`
UserCode string `json:"userCode"`
// 组织编码
Org string `json:"org,omitempty"`
Org string `json:"org"`
// 部门编码
Department string `json:"department,omitempty"`
Department string `json:"department"`
// 状态(1:启用 2:禁用 3:注销)
EnableStatus int `json:"enableStatus,omitempty"`
// 共创公司 cooperationCompany
CooperationCompany string `json:"cooperationCompany"`
// 共创到期时间 (yyyy-MM-dd) cooperationDeadline
CooperationDeadline time.Time `json:"cooperationDeadline"`
// 失败理由
FailReason string `json:"failReason"`
}
... ...
... ... @@ -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
... ... @@ -37,7 +34,7 @@ func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgLis
CompanyId: optUser.CompanyId,
OrgCode: item.OrgCode,
OrgName: item.OrgName,
IsOrg: domain.IsOrgFlag,
IsOrg: domain.IsNotOrgFlag,
ParentId: 0,
OrgStatus: domain.OrgStatusEnable,
CreatedAt: time.Now(),
... ...
... ... @@ -82,17 +82,18 @@ func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, user
return nil
}
func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) error {
func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error) {
var (
err error
)
var failRows = make([]*domain.BatchAddUserItem, 0)
orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
if err != nil {
return err
return failRows, err
}
_, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId, "limit": 10000})
if err != nil {
return err
return failRows, err
}
var mapOrg = make(map[string]*domain.Org)
for i := range orgs {
... ... @@ -103,15 +104,24 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
for i := range users {
user := users[i]
if err = ptr.preCheck2(user); err != nil {
return err
user.FailReason = err.Error()
failRows = append(failRows, user)
continue
//return err
}
var org, dep *domain.Org
var ok bool
if org, ok = mapOrg[user.Org]; !ok {
return fmt.Errorf("导入的组织机构不存在:" + user.Org)
user.FailReason = "导入的组织机构不存在:" + user.Org
failRows = append(failRows, user)
continue
//return fmt.Errorf("导入的组织机构不存在:" + user.Org)
}
if dep, ok = mapOrg[user.Department]; !ok {
return fmt.Errorf("导入的所属部门不存在:" + user.Department)
user.FailReason = "导入的所属部门不存在:" + user.Department
failRows = append(failRows, user)
continue
//return fmt.Errorf("导入的所属部门不存在:" + user.Department)
}
newUser := &domain.User{
CompanyId: user.CompanyId,
... ... @@ -143,10 +153,13 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
UpdatedAt: time.Now(),
}
if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil {
return fmt.Errorf("%v %v", user.UserName, err.Error())
user.FailReason = err.Error()
failRows = append(failRows, user)
continue
//return fmt.Errorf("%v %v", user.UserName, err.Error())
}
}
return nil
return failRows, nil
}
func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error {
... ...
... ... @@ -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")
... ...
... ... @@ -204,7 +204,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int
query.SetWhereByQueryOption("(user_type & ?)>0", "userType")
query.SetWhereByQueryOption("enable_status=?", "enableStatus")
query.SetWhereByQueryOption(fmt.Sprintf(`user_role @> '[{"roleId":%v}]'`, queryOptions["roleId"]), "roleId")
if v, ok := queryOptions["inEnableStatus"]; ok && len(v.([]int)) > 0 {
query.Where(`enable_status in (?)`, pg.In(v))
}
if v, ok := queryOptions["depName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`ext->>'depName' like '%%%v%%'`, v))
}
... ...
... ... @@ -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")
... ...