正在显示
11 个修改的文件
包含
45 行增加
和
11 行删除
@@ -323,6 +323,10 @@ func (menuService *MenuService) BatchDeleteMenu(batchDeleteMenu *command.BatchDe | @@ -323,6 +323,10 @@ func (menuService *MenuService) BatchDeleteMenu(batchDeleteMenu *command.BatchDe | ||
323 | if menu, err := menuRepository.FindOne(map[string]interface{}{"menuId": batchDeleteMenu.MenuIds[i]}); err != nil { | 323 | if menu, err := menuRepository.FindOne(map[string]interface{}{"menuId": batchDeleteMenu.MenuIds[i]}); err != nil { |
324 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 324 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
325 | } else { | 325 | } else { |
326 | + // 2. 是否存在子节点 | ||
327 | + if m, err := menuRepository.FindOne(map[string]interface{}{"parentId": menu.MenuId}); err == nil && m != nil { | ||
328 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "下级菜单不为空") | ||
329 | + } | ||
326 | if _, err := menuRepository.Remove(menu); err != nil { | 330 | if _, err := menuRepository.Remove(menu); err != nil { |
327 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 331 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
328 | } | 332 | } |
@@ -19,9 +19,9 @@ type UpdateUserCommand struct { | @@ -19,9 +19,9 @@ type UpdateUserCommand struct { | ||
19 | // 所属部门 | 19 | // 所属部门 |
20 | DepartmentId int64 `cname:"所属部门" json:"departmentId,omitempty" valid:"Required"` | 20 | DepartmentId int64 `cname:"所属部门" json:"departmentId,omitempty" valid:"Required"` |
21 | // 用户关联的组织 | 21 | // 用户关联的组织 |
22 | - UserOrg []*domain.Org `cname:"用户关联的组织" json:"userOrg,omitempty"` | 22 | + UserOrg []int64 `cname:"用户关联的组织" json:"userOrg,omitempty"` |
23 | // 用户关联的角色 | 23 | // 用户关联的角色 |
24 | - UserRole []*domain.Role `cname:"用户关联的角色" json:"userRole,omitempty"` | 24 | + UserRole []int64 `cname:"用户关联的角色" json:"userRole,omitempty"` |
25 | // 共创公司 | 25 | // 共创公司 |
26 | CooperationCompany string `cname:"共创公司" json:"cooperationCompany,omitempty"` | 26 | CooperationCompany string `cname:"共创公司" json:"cooperationCompany,omitempty"` |
27 | // 共创到期时间 (yyyy-MM-dd) | 27 | // 共创到期时间 (yyyy-MM-dd) |
@@ -33,6 +33,8 @@ type ListUserQuery struct { | @@ -33,6 +33,8 @@ type ListUserQuery struct { | ||
33 | Phone string `cname:"手机号码" json:"phone,omitempty"` | 33 | Phone string `cname:"手机号码" json:"phone,omitempty"` |
34 | // 用户类型 | 34 | // 用户类型 |
35 | UserType int `cname:"用户类型 1:普通用户 2:共创用户 1024:企业注册用户" json:"userType,omitempty"` | 35 | UserType int `cname:"用户类型 1:普通用户 2:共创用户 1024:企业注册用户" json:"userType,omitempty"` |
36 | + // 在组织范围内 | ||
37 | + InOrgIds []int64 `cname:"在组织范围内" json:"inOrgIds,omitempty"` | ||
36 | // 实时拉取数据 (获取最新的) | 38 | // 实时拉取数据 (获取最新的) |
37 | PullRealTime bool `cname:"拉取最新数据" json:"pullRealTime,omitempty"` | 39 | PullRealTime bool `cname:"拉取最新数据" json:"pullRealTime,omitempty"` |
38 | } | 40 | } |
@@ -364,7 +364,7 @@ func (userService *UserService) GetUserAccessMenus(getUserAccessMenusQuery *quer | @@ -364,7 +364,7 @@ func (userService *UserService) GetUserAccessMenus(getUserAccessMenusQuery *quer | ||
364 | "transactionContext": transactionContext, | 364 | "transactionContext": transactionContext, |
365 | }) | 365 | }) |
366 | 366 | ||
367 | - menus, err := roleAccessMenusService.AccessMenus(nil, user.UserOrgIds(), domain.AccessMenusOptions{ | 367 | + menus, err := roleAccessMenusService.AccessMenus(nil, user.UserRoleIds(), domain.AccessMenusOptions{ |
368 | CompanyId: user.CompanyId, | 368 | CompanyId: user.CompanyId, |
369 | MenuCategory: getUserAccessMenusQuery.MenuCategory, | 369 | MenuCategory: getUserAccessMenusQuery.MenuCategory, |
370 | OrgId: getUserAccessMenusQuery.OrgId, | 370 | OrgId: getUserAccessMenusQuery.OrgId, |
@@ -626,8 +626,16 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser | @@ -626,8 +626,16 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser | ||
626 | } | 626 | } |
627 | user.DepartmentId = updateUserCommand.DepartmentId | 627 | user.DepartmentId = updateUserCommand.DepartmentId |
628 | user.OrganizationId = updateUserCommand.OrganizationId | 628 | user.OrganizationId = updateUserCommand.OrganizationId |
629 | - user.UserOrg = updateUserCommand.UserOrg | ||
630 | - user.UserRole = updateUserCommand.UserRole | 629 | + var userOrg = make([]*domain.Org, 0) |
630 | + for i := range updateUserCommand.UserOrg { | ||
631 | + userOrg = append(userOrg, &domain.Org{OrgId: updateUserCommand.UserOrg[i]}) | ||
632 | + } | ||
633 | + user.UserOrg = userOrg | ||
634 | + var userRole = make([]*domain.Role, 0) | ||
635 | + for i := range updateUserCommand.UserRole { | ||
636 | + userRole = append(userRole, &domain.Role{RoleId: updateUserCommand.UserRole[i]}) | ||
637 | + } | ||
638 | + user.UserRole = userRole | ||
631 | 639 | ||
632 | userInfo := &domain.UserInfo{ | 640 | userInfo := &domain.UserInfo{ |
633 | UserName: updateUserCommand.UserName, | 641 | UserName: updateUserCommand.UserName, |
@@ -45,21 +45,21 @@ func (info OperateInfo) Valid() bool { | @@ -45,21 +45,21 @@ func (info OperateInfo) Valid() bool { | ||
45 | } | 45 | } |
46 | 46 | ||
47 | func (info OperateInfo) GetCompanyId(companyId int64) int64 { | 47 | func (info OperateInfo) GetCompanyId(companyId int64) int64 { |
48 | - if info.CompanyId == 0 { | 48 | + if companyId != 0 { |
49 | return companyId | 49 | return companyId |
50 | } | 50 | } |
51 | return info.CompanyId | 51 | return info.CompanyId |
52 | } | 52 | } |
53 | 53 | ||
54 | func (info OperateInfo) GetOrgId(orgId int64) int64 { | 54 | func (info OperateInfo) GetOrgId(orgId int64) int64 { |
55 | - if info.OrgId == 0 { | 55 | + if orgId != 0 { |
56 | return orgId | 56 | return orgId |
57 | } | 57 | } |
58 | return info.OrgId | 58 | return info.OrgId |
59 | } | 59 | } |
60 | 60 | ||
61 | func (info OperateInfo) GetUserId(userId int64) int64 { | 61 | func (info OperateInfo) GetUserId(userId int64) int64 { |
62 | - if info.UserId == 0 { | 62 | + if userId != 0 { |
63 | return userId | 63 | return userId |
64 | } | 64 | } |
65 | return info.UserId | 65 | return info.UserId |
@@ -119,7 +119,7 @@ func (t Int64String) MarshalJSON() ([]byte, error) { | @@ -119,7 +119,7 @@ func (t Int64String) MarshalJSON() ([]byte, error) { | ||
119 | return []byte(stamp), nil | 119 | return []byte(stamp), nil |
120 | } | 120 | } |
121 | 121 | ||
122 | -func (t *Int64String) UnMarshalJSON(data []byte) error { | 122 | +func (t *Int64String) UnmarshalJSON(data []byte) error { |
123 | v, err := strconv.ParseInt(string(data), 10, 64) | 123 | v, err := strconv.ParseInt(string(data), 10, 64) |
124 | *t = Int64String(v) | 124 | *t = Int64String(v) |
125 | return err | 125 | return err |
@@ -181,9 +181,17 @@ func (user *User) SetEnableStatus(enableStatus int) error { | @@ -181,9 +181,17 @@ func (user *User) SetEnableStatus(enableStatus int) error { | ||
181 | } | 181 | } |
182 | 182 | ||
183 | func (user *User) UserOrgIds() []int64 { | 183 | func (user *User) UserOrgIds() []int64 { |
184 | - var roleIds = make([]int64, len(user.UserOrg)) | 184 | + var orgIds = make([]int64, len(user.UserOrg)) |
185 | for i := range user.UserOrg { | 185 | for i := range user.UserOrg { |
186 | - roleIds[i] = user.UserOrg[i].OrgId | 186 | + orgIds[i] = user.UserOrg[i].OrgId |
187 | + } | ||
188 | + return orgIds | ||
189 | +} | ||
190 | + | ||
191 | +func (user *User) UserRoleIds() []int64 { | ||
192 | + var roleIds = make([]int64, len(user.UserRole)) | ||
193 | + for i := range user.UserRole { | ||
194 | + roleIds[i] = user.UserRole[i].RoleId | ||
187 | } | 195 | } |
188 | return roleIds | 196 | return roleIds |
189 | } | 197 | } |
@@ -76,6 +76,10 @@ func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.OperateInfo, user *do | @@ -76,6 +76,10 @@ func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.OperateInfo, user *do | ||
76 | 76 | ||
77 | //4.更新用户、冗余信息 | 77 | //4.更新用户、冗余信息 |
78 | userRepository, _ := repository.NewUserRepository(ptr.transactionContext) | 78 | userRepository, _ := repository.NewUserRepository(ptr.transactionContext) |
79 | + if _, err = userRepository.FindOne(map[string]interface{}{"companyId": user.CompanyId, "organizationId": user.OrganizationId, "userCode": user.UserCode, "notEqualUserId": user.UserId}); err == nil { | ||
80 | + return nil, fmt.Errorf("用户编号在该企业内已存在,请重新输入") | ||
81 | + } | ||
82 | + | ||
79 | user.UserRole = userRole | 83 | user.UserRole = userRole |
80 | user.UserOrg = userOrg | 84 | user.UserOrg = userOrg |
81 | if org != nil { | 85 | if org != nil { |
@@ -186,6 +186,7 @@ func (repository *OrgRepository) Find(queryOptions map[string]interface{}) (int6 | @@ -186,6 +186,7 @@ func (repository *OrgRepository) Find(queryOptions map[string]interface{}) (int6 | ||
186 | orgs := make([]*domain.Org, 0) | 186 | orgs := make([]*domain.Org, 0) |
187 | query := sqlbuilder.BuildQuery(tx.Model(&orgModels), queryOptions) | 187 | query := sqlbuilder.BuildQuery(tx.Model(&orgModels), queryOptions) |
188 | query.SetOffsetAndLimit(20) | 188 | query.SetOffsetAndLimit(20) |
189 | + query.SetWhereByQueryOption("company_id = ?", "companyId") | ||
189 | query.SetWhereByQueryOption("is_org = ?", "isOrg") | 190 | query.SetWhereByQueryOption("is_org = ?", "isOrg") |
190 | query.SetWhereByQueryOption("org_name = ?", "depName") | 191 | query.SetWhereByQueryOption("org_name = ?", "depName") |
191 | query.SetWhereByQueryOption("org_code = ?", "orgCode") | 192 | query.SetWhereByQueryOption("org_code = ?", "orgCode") |
@@ -177,6 +177,9 @@ func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int | @@ -177,6 +177,9 @@ func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int | ||
177 | query.SetOffsetAndLimit(20) | 177 | query.SetOffsetAndLimit(20) |
178 | query.SetWhereByQueryOption("company_id = ?", "companyId") | 178 | query.SetWhereByQueryOption("company_id = ?", "companyId") |
179 | query.SetWhereByQueryOption("org_id = ?", "orgId") | 179 | query.SetWhereByQueryOption("org_id = ?", "orgId") |
180 | + if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int64)) > 0 { | ||
181 | + query.Where(`org_id in (?)`, pg.In(v)) | ||
182 | + } | ||
180 | query.SetWhereByQueryOption("role_name = ?", "roleName") | 183 | query.SetWhereByQueryOption("role_name = ?", "roleName") |
181 | query.SetWhereByQueryOption("(role_type & ?) >0", "roleType") | 184 | query.SetWhereByQueryOption("(role_type & ?) >0", "roleType") |
182 | if orgName, ok := queryOptions["orgName"]; ok && len(orgName.(string)) > 0 { | 185 | if orgName, ok := queryOptions["orgName"]; ok && len(orgName.(string)) > 0 { |
@@ -166,6 +166,7 @@ func (repository *UserRepository) FindOne(queryOptions map[string]interface{}) ( | @@ -166,6 +166,7 @@ func (repository *UserRepository) FindOne(queryOptions map[string]interface{}) ( | ||
166 | query.SetWhereByQueryOption("company_id=?", "companyId") | 166 | query.SetWhereByQueryOption("company_id=?", "companyId") |
167 | query.SetWhereByQueryOption("organization_id=?", "organizationId") | 167 | query.SetWhereByQueryOption("organization_id=?", "organizationId") |
168 | query.SetWhereByQueryOption("user_code = ?", "userCode") | 168 | query.SetWhereByQueryOption("user_code = ?", "userCode") |
169 | + query.SetWhereByQueryOption("user_id != ?", "notEqualUserId") | ||
169 | if err := query.First(); err != nil { | 170 | if err := query.First(); err != nil { |
170 | if err.Error() == "pg: no rows in result set" { | 171 | if err.Error() == "pg: no rows in result set" { |
171 | return nil, fmt.Errorf("没有此资源") | 172 | return nil, fmt.Errorf("没有此资源") |
@@ -195,6 +196,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int | @@ -195,6 +196,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int | ||
195 | query := sqlbuilder.BuildQuery(tx.Model(&userModels), queryOptions) | 196 | query := sqlbuilder.BuildQuery(tx.Model(&userModels), queryOptions) |
196 | query.SetWhereByQueryOption("company_id=?", "companyId") | 197 | query.SetWhereByQueryOption("company_id=?", "companyId") |
197 | query.SetWhereByQueryOption("organization_id=?", "organizationId") | 198 | query.SetWhereByQueryOption("organization_id=?", "organizationId") |
199 | + if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int64)) > 0 { | ||
200 | + query.Where(`organization_id in (?)`, pg.In(v)) | ||
201 | + } | ||
198 | query.SetWhereByQueryOption("user_base_id=?", "userBaseId") | 202 | query.SetWhereByQueryOption("user_base_id=?", "userBaseId") |
199 | query.SetWhereByQueryOption("(user_type & ?)>0", "userType") | 203 | query.SetWhereByQueryOption("(user_type & ?)>0", "userType") |
200 | if v, ok := queryOptions["depName"]; ok && len(v.(string)) > 0 { | 204 | if v, ok := queryOptions["depName"]; ok && len(v.(string)) > 0 { |
-
请 注册 或 登录 后发表评论