作者 Administrator

合并分支 'test' 到 'master'

Test



查看合并请求 !8
... ... @@ -26,6 +26,8 @@ type CreateMenuCommand struct {
IsPublish int `json:"isPublish" valid:"Required"`
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `json:"enableStatus" `
// 外链接(需要菜单跳转的时候使用)
Link string `json:"link"`
}
func (createMenuCommand *CreateMenuCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -29,6 +29,8 @@ type UpdateMenuCommand struct {
IsPublish int `json:"isPublish,omitempty"`
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `json:"enableStatus"`
// 外链接(需要菜单跳转的时候使用)
Link string `json:"link"`
}
func (updateMenuCommand *UpdateMenuCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -34,6 +34,8 @@ type Menu struct {
//IsPublish int `json:"isPublish,omitempty"`
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `json:"enableStatus,omitempty"`
// 外链接(需要菜单跳转的时候使用)
Link string `json:"link"`
}
func (dto *UserAccessMenuDto) LoadDto(menus []*domain.Menu) error {
... ... @@ -49,6 +51,7 @@ func (dto *UserAccessMenuDto) LoadDto(menus []*domain.Menu) error {
Sort: v.Sort,
EnableStatus: v.EnableStatus,
ParentPath: v.ParentPath,
Link: v.Link,
})
}
... ...
... ... @@ -66,7 +66,7 @@ func (userService *UserService) BatchAdd2(batchAddCommand *command.BatchAdd2Comm
"transactionContext": transactionContext,
})
var failRows []*domain.BatchAddUserItem
if failRows, err = batchAddUserService.BatchAddUser2(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil {
if failRows, err = batchAddUserService.BatchAddUser(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil {
return batchAddCommand.Users, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if len(failRows) != 0 {
... ...
... ... @@ -68,9 +68,10 @@ type Menu struct {
ParentPath string `json:"parentPath,omitempty"`
// 菜单是否公开状态,[1:显示],[2:隐藏],默认显示
IsPublish int `json:"isPublish,omitempty"`
// 启用状态(启用:1 禁用:2),默认启用
// 启用状态(启用:1 禁用:2),默认启用 (移除不使用,现在只有is_publish状态)
EnableStatus int `json:"enableStatus,omitempty"`
// 外链接(需要菜单跳转的时候使用)
Link string `json:"link"`
// 父级菜单名称
ParentMenuName string `json:"parentMenuName,omitempty"`
}
... ...
... ... @@ -3,6 +3,8 @@ package domain
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/constant"
"strconv"
"strings"
"time"
)
... ... @@ -44,7 +46,7 @@ type Org struct {
OrgStatus int `json:"orgStatus,omitempty"`
// 父级ID
ParentId int64 `json:"parentId,omitempty"`
// 父级节点路径("0,11,12,")
// 父级节点路径("11,12") 注意:parent_id为0时 parentPath "",公司级别的组织没有父级组织
ParentPath string `json:"parentPath,omitempty"`
// 企业id
... ... @@ -197,6 +199,23 @@ func (org *Org) ID() string {
return org.GetFullPath()
}
func (org *Org) IsChild(pid int64) bool {
paths := strings.Split(org.ParentPath, PathSegment)
pidStr := strconv.FormatInt(pid, 10)
if org.OrgId == pid {
return true
}
if org.ParentId == pid {
return true
}
for _, v := range paths {
if strings.EqualFold(pidStr, v) {
return true
}
}
return false
}
/***** 2.缓存模块 *****/
func (m *Org) CacheKeyFunc() string {
... ...
... ... @@ -4,6 +4,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) ([]*domain.BatchAddUserItem, error)
BatchAddUser(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error)
}
... ...
... ... @@ -18,71 +18,71 @@ type PgBatchAddUserService struct {
// optUser 操作用户
// users 待添加用户列表数据
// password 密码
func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error {
var (
err error
)
orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
if err != nil {
return err
}
_, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId})
if err != nil {
return err
}
var mapOrg = make(map[int64]*domain.Org)
for i := range orgs {
mapOrg[orgs[i].OrgId] = orgs[i]
}
createUserService, _ := NewPgCreateUserService(ptr.transactionContext)
for i := range users {
user := users[i]
if err = ptr.preCheck(user); err != nil {
return err
}
newUser := &domain.User{
CompanyId: user.CompanyId,
UserType: user.UserType,
UserCode: user.UserCode,
OrganizationId: user.OrganizationId,
DepartmentId: user.DepartmentId,
UserOrg: []*domain.Org{},
UserRole: []*domain.Role{},
FavoriteMenus: []string{},
CooperationInfo: user.CooperationInfo,
UserInfo: user.UserInfo,
EnableStatus: int(domain.UserStatusEnable),
Ext: &domain.Ext{
Phone: user.UserInfo.Phone,
UserName: user.UserInfo.UserName,
},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
if user.OrganizationId > 0 {
if v, ok := mapOrg[user.OrganizationId]; ok && v.CompanyId == user.CompanyId {
newUser.Ext.OrgName = v.OrgName
} else {
return fmt.Errorf("导入的组织机构不存在")
}
}
if user.DepartmentId > 0 {
if v, ok := mapOrg[user.DepartmentId]; ok && v.CompanyId == user.CompanyId {
newUser.Ext.DepName = v.OrgName
} else {
return fmt.Errorf("导入的所属部门不存在")
}
}
if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil {
return err
}
}
return nil
}
//func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error {
// var (
// err error
// )
// orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
// if err != nil {
// return err
// }
// _, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId})
// if err != nil {
// return err
// }
// var mapOrg = make(map[int64]*domain.Org)
// for i := range orgs {
// mapOrg[orgs[i].OrgId] = orgs[i]
// }
//
// createUserService, _ := NewPgCreateUserService(ptr.transactionContext)
// for i := range users {
// user := users[i]
// if err = ptr.preCheck(user); err != nil {
// return err
// }
// newUser := &domain.User{
// CompanyId: user.CompanyId,
// UserType: user.UserType,
// UserCode: user.UserCode,
// OrganizationId: user.OrganizationId,
// DepartmentId: user.DepartmentId,
// UserOrg: []*domain.Org{},
// UserRole: []*domain.Role{},
// FavoriteMenus: []string{},
// CooperationInfo: user.CooperationInfo,
// UserInfo: user.UserInfo,
// EnableStatus: int(domain.UserStatusEnable),
// Ext: &domain.Ext{
// Phone: user.UserInfo.Phone,
// UserName: user.UserInfo.UserName,
// },
// CreatedAt: time.Now(),
// UpdatedAt: time.Now(),
// }
// if user.OrganizationId > 0 {
// if v, ok := mapOrg[user.OrganizationId]; ok && v.CompanyId == user.CompanyId {
// newUser.Ext.OrgName = v.OrgName
// } else {
// return fmt.Errorf("导入的组织机构不存在")
// }
// }
// if user.DepartmentId > 0 {
// if v, ok := mapOrg[user.DepartmentId]; ok && v.CompanyId == user.CompanyId {
// newUser.Ext.DepName = v.OrgName
// } else {
// return fmt.Errorf("导入的所属部门不存在")
// }
// }
//
// if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil {
// return err
// }
// }
// return nil
//}
func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error) {
func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error) {
var (
err error
)
... ... @@ -99,6 +99,10 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
for i := range orgs {
mapOrg[orgs[i].OrgCode] = orgs[i]
}
optUserOrg, err := orgRepository.FindOne(map[string]interface{}{"orgId": optUser.OrgId})
if err != nil {
return failRows, err
}
createUserService, _ := NewPgCreateUserService(ptr.transactionContext)
for i := range users {
... ... @@ -108,23 +112,31 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
failRows = append(failRows, user)
continue
}
var org, dep *domain.Org
var org = optUserOrg
var dep *domain.Org
var ok bool
if org, ok = mapOrg[user.Org]; !ok {
user.FailReason = "导入的组织机构不存在:" + user.Org
failRows = append(failRows, user)
continue
}
// 使用导入用户的组织作为默认组织
//if org, ok = mapOrg[user.Org]; !ok {
// user.FailReason = "导入的组织机构不存在:" + user.Org
// failRows = append(failRows, user)
// continue
//}
if dep, ok = mapOrg[user.Department]; !ok && user.UserType != domain.UserTypeCooperation {
user.FailReason = "导入的所属部门不存在:" + user.Department
failRows = append(failRows, user)
continue
}
//TODO:子部门判断
//if dep != nil && !dep.IsChild(optUser.OrgId) {
// user.FailReason = fmt.Sprintf("导入的所属部门不是当前登录组织(%v)的子部门:%v", optUserOrg.OrgName, user.Department)
// failRows = append(failRows, user)
// continue
//}
newUser := &domain.User{
CompanyId: user.CompanyId,
UserType: user.UserType,
UserCode: user.UserCode,
OrganizationId: org.OrgId,
OrganizationId: optUser.OrgId,
UserOrg: []*domain.Org{},
UserRole: []*domain.Role{},
FavoriteMenus: []string{},
... ... @@ -172,24 +184,24 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
return failRows, nil
}
func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error {
if len(user.UserCode) == 0 {
return fmt.Errorf("导入的用户编码为空值")
}
if len(user.UserInfo.UserName) == 0 {
return fmt.Errorf("导入的用户姓名为空值")
}
if len(user.UserInfo.Phone) == 0 || len(user.UserInfo.Phone) != 11 {
return fmt.Errorf("导入的手机号不是有效手机号")
}
if user.OrganizationId == 0 {
return fmt.Errorf("导入的组织机构不存在")
}
if user.DepartmentId == 0 && user.UserType == domain.UserTypeEmployee {
return fmt.Errorf("导入的所属部门不存在")
}
return nil
}
//func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error {
// if len(user.UserCode) == 0 {
// return fmt.Errorf("导入的用户编码为空值")
// }
// if len(user.UserInfo.UserName) == 0 {
// return fmt.Errorf("导入的用户姓名为空值")
// }
// if len(user.UserInfo.Phone) == 0 || len(user.UserInfo.Phone) != 11 {
// return fmt.Errorf("导入的手机号不是有效手机号")
// }
// if user.OrganizationId == 0 {
// return fmt.Errorf("导入的组织机构不存在")
// }
// if user.DepartmentId == 0 && user.UserType == domain.UserTypeEmployee {
// return fmt.Errorf("导入的所属部门不存在")
// }
// return nil
//}
func (ptr *PgBatchAddUserService) preCheck2(user *domain.BatchAddUserItem) error {
if len(user.UserCode) == 0 {
... ...
... ... @@ -22,6 +22,7 @@ type PgRoleAccessMenusService struct {
func (ptr *PgRoleAccessMenusService) AccessMenus(options *domain.OperateInfo, roleIds []int64, option domain.AccessMenusOptions) ([]*domain.Menu, error) {
var err error
var menus []*domain.Menu
var hasAdminRole bool = false
menuIdSet := hashset.New()
if len(roleIds) == 0 {
return menus, nil
... ... @@ -34,6 +35,9 @@ func (ptr *PgRoleAccessMenusService) AccessMenus(options *domain.OperateInfo, ro
if role, _ = roleRepository.FindOne(map[string]interface{}{"roleId": roleIds[i]}); role == nil {
continue
}
if role.RoleType&domain.RoleTypeAdmin > 0 {
hasAdminRole = true
}
// 只要当前登录组织的有权限菜单
if option.OrgId > 0 && option.OrgId != role.OrgId {
continue
... ... @@ -66,7 +70,7 @@ func (ptr *PgRoleAccessMenusService) AccessMenus(options *domain.OperateInfo, ro
if err != nil {
return nil, err
}
_, alias, err := customizeMenuRepository.Find(map[string]interface{}{"companyId": option.CompanyId})
_, menuAlias, err := customizeMenuRepository.Find(map[string]interface{}{"companyId": option.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -75,17 +79,22 @@ func (ptr *PgRoleAccessMenusService) AccessMenus(options *domain.OperateInfo, ro
var mapMenus = make(map[int64]*domain.Menu)
for i := range menus {
menus[i].EnableStatus = domain.MenuStatusDisable
if menus[i].IsPublish == domain.MenuPublic && hasAdminRole {
menus[i].EnableStatus = domain.MenuStatusEnable //管理员角色,返回所有权限
}
mapMenus[menus[i].MenuId] = menus[i]
}
for i := range alias {
if v, ok := mapMenus[alias[i].MenuId]; ok {
v.MenuName = alias[i].MenuAlias // 设置别名
v.Sort = alias[i].Sort
// 4.1.设置别名
for i := range menuAlias {
if v, ok := mapMenus[menuAlias[i].MenuId]; ok {
v.MenuName = menuAlias[i].MenuAlias
v.Sort = menuAlias[i].Sort
}
}
// 4.2.设置菜单权限状态
values := menuIdSet.Values()
for i := range values {
menuId := (values[i]).(int64) // 设置菜单权限状态
menuId := (values[i]).(int64)
if v, ok := mapMenus[menuId]; ok {
v.EnableStatus = domain.MenuStatusEnable
}
... ...
... ... @@ -28,6 +28,8 @@ type Menu struct {
IsPublish int `comment:"菜单是否公开状态,[2:隐藏],[1:显示],默认显示"`
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `comment:"启用状态(启用:1 禁用:2),默认启用"`
// 外链接(需要菜单跳转的时候使用)
Link string `json:"link"`
// 删除时间
//DeletedAt time.Time `comment:"删除时间"`
}
... ...
... ... @@ -21,5 +21,6 @@ func TransformToMenuDomainModelFromPgModels(menuModel *models.Menu) (*domain.Men
ParentPath: menuModel.ParentPath,
IsPublish: menuModel.IsPublish,
EnableStatus: menuModel.EnableStatus,
Link: menuModel.Link,
}, nil
}
... ...