作者 yangfu

菜单用户、角色修改

... ... @@ -323,6 +323,10 @@ func (menuService *MenuService) BatchDeleteMenu(batchDeleteMenu *command.BatchDe
if menu, err := menuRepository.FindOne(map[string]interface{}{"menuId": batchDeleteMenu.MenuIds[i]}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// 2. 是否存在子节点
if m, err := menuRepository.FindOne(map[string]interface{}{"parentId": menu.MenuId}); err == nil && m != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "下级菜单不为空")
}
if _, err := menuRepository.Remove(menu); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -19,9 +19,9 @@ type UpdateUserCommand struct {
// 所属部门
DepartmentId int64 `cname:"所属部门" json:"departmentId,omitempty" valid:"Required"`
// 用户关联的组织
UserOrg []*domain.Org `cname:"用户关联的组织" json:"userOrg,omitempty"`
UserOrg []int64 `cname:"用户关联的组织" json:"userOrg,omitempty"`
// 用户关联的角色
UserRole []*domain.Role `cname:"用户关联的角色" json:"userRole,omitempty"`
UserRole []int64 `cname:"用户关联的角色" json:"userRole,omitempty"`
// 共创公司
CooperationCompany string `cname:"共创公司" json:"cooperationCompany,omitempty"`
// 共创到期时间 (yyyy-MM-dd)
... ...
... ... @@ -33,6 +33,8 @@ type ListUserQuery struct {
Phone string `cname:"手机号码" json:"phone,omitempty"`
// 用户类型
UserType int `cname:"用户类型 1:普通用户 2:共创用户 1024:企业注册用户" json:"userType,omitempty"`
// 在组织范围内
InOrgIds []int64 `cname:"在组织范围内" json:"inOrgIds,omitempty"`
// 实时拉取数据 (获取最新的)
PullRealTime bool `cname:"拉取最新数据" json:"pullRealTime,omitempty"`
}
... ...
... ... @@ -364,7 +364,7 @@ func (userService *UserService) GetUserAccessMenus(getUserAccessMenusQuery *quer
"transactionContext": transactionContext,
})
menus, err := roleAccessMenusService.AccessMenus(nil, user.UserOrgIds(), domain.AccessMenusOptions{
menus, err := roleAccessMenusService.AccessMenus(nil, user.UserRoleIds(), domain.AccessMenusOptions{
CompanyId: user.CompanyId,
MenuCategory: getUserAccessMenusQuery.MenuCategory,
OrgId: getUserAccessMenusQuery.OrgId,
... ... @@ -626,8 +626,16 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser
}
user.DepartmentId = updateUserCommand.DepartmentId
user.OrganizationId = updateUserCommand.OrganizationId
user.UserOrg = updateUserCommand.UserOrg
user.UserRole = updateUserCommand.UserRole
var userOrg = make([]*domain.Org, 0)
for i := range updateUserCommand.UserOrg {
userOrg = append(userOrg, &domain.Org{OrgId: updateUserCommand.UserOrg[i]})
}
user.UserOrg = userOrg
var userRole = make([]*domain.Role, 0)
for i := range updateUserCommand.UserRole {
userRole = append(userRole, &domain.Role{RoleId: updateUserCommand.UserRole[i]})
}
user.UserRole = userRole
userInfo := &domain.UserInfo{
UserName: updateUserCommand.UserName,
... ...
... ... @@ -45,21 +45,21 @@ func (info OperateInfo) Valid() bool {
}
func (info OperateInfo) GetCompanyId(companyId int64) int64 {
if info.CompanyId == 0 {
if companyId != 0 {
return companyId
}
return info.CompanyId
}
func (info OperateInfo) GetOrgId(orgId int64) int64 {
if info.OrgId == 0 {
if orgId != 0 {
return orgId
}
return info.OrgId
}
func (info OperateInfo) GetUserId(userId int64) int64 {
if info.UserId == 0 {
if userId != 0 {
return userId
}
return info.UserId
... ...
... ... @@ -119,7 +119,7 @@ func (t Int64String) MarshalJSON() ([]byte, error) {
return []byte(stamp), nil
}
func (t *Int64String) UnMarshalJSON(data []byte) error {
func (t *Int64String) UnmarshalJSON(data []byte) error {
v, err := strconv.ParseInt(string(data), 10, 64)
*t = Int64String(v)
return err
... ...
... ... @@ -181,9 +181,17 @@ func (user *User) SetEnableStatus(enableStatus int) error {
}
func (user *User) UserOrgIds() []int64 {
var roleIds = make([]int64, len(user.UserOrg))
var orgIds = make([]int64, len(user.UserOrg))
for i := range user.UserOrg {
roleIds[i] = user.UserOrg[i].OrgId
orgIds[i] = user.UserOrg[i].OrgId
}
return orgIds
}
func (user *User) UserRoleIds() []int64 {
var roleIds = make([]int64, len(user.UserRole))
for i := range user.UserRole {
roleIds[i] = user.UserRole[i].RoleId
}
return roleIds
}
... ...
... ... @@ -76,6 +76,10 @@ func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.OperateInfo, user *do
//4.更新用户、冗余信息
userRepository, _ := repository.NewUserRepository(ptr.transactionContext)
if _, err = userRepository.FindOne(map[string]interface{}{"companyId": user.CompanyId, "organizationId": user.OrganizationId, "userCode": user.UserCode, "notEqualUserId": user.UserId}); err == nil {
return nil, fmt.Errorf("用户编号在该企业内已存在,请重新输入")
}
user.UserRole = userRole
user.UserOrg = userOrg
if org != nil {
... ...
... ... @@ -186,6 +186,7 @@ func (repository *OrgRepository) Find(queryOptions map[string]interface{}) (int6
orgs := make([]*domain.Org, 0)
query := sqlbuilder.BuildQuery(tx.Model(&orgModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("is_org = ?", "isOrg")
query.SetWhereByQueryOption("org_name = ?", "depName")
query.SetWhereByQueryOption("org_code = ?", "orgCode")
... ...
... ... @@ -177,6 +177,9 @@ func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int
query.SetOffsetAndLimit(20)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int64)) > 0 {
query.Where(`org_id in (?)`, pg.In(v))
}
query.SetWhereByQueryOption("role_name = ?", "roleName")
query.SetWhereByQueryOption("(role_type & ?) >0", "roleType")
if orgName, ok := queryOptions["orgName"]; ok && len(orgName.(string)) > 0 {
... ...
... ... @@ -166,6 +166,7 @@ func (repository *UserRepository) FindOne(queryOptions map[string]interface{}) (
query.SetWhereByQueryOption("company_id=?", "companyId")
query.SetWhereByQueryOption("organization_id=?", "organizationId")
query.SetWhereByQueryOption("user_code = ?", "userCode")
query.SetWhereByQueryOption("user_id != ?", "notEqualUserId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
... ... @@ -195,6 +196,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int
query := sqlbuilder.BuildQuery(tx.Model(&userModels), queryOptions)
query.SetWhereByQueryOption("company_id=?", "companyId")
query.SetWhereByQueryOption("organization_id=?", "organizationId")
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int64)) > 0 {
query.Where(`organization_id in (?)`, pg.In(v))
}
query.SetWhereByQueryOption("user_base_id=?", "userBaseId")
query.SetWhereByQueryOption("(user_type & ?)>0", "userType")
if v, ok := queryOptions["depName"]; ok && len(v.(string)) > 0 {
... ...