正在显示
35 个修改的文件
包含
201 行增加
和
33 行删除
| @@ -192,7 +192,7 @@ func (authService *AuthService) PhoneAuthCheck(phoneAuthCheckCommand *command.Ph | @@ -192,7 +192,7 @@ func (authService *AuthService) PhoneAuthCheck(phoneAuthCheckCommand *command.Ph | ||
| 192 | if err := transactionContext.CommitTransaction(); err != nil { | 192 | if err := transactionContext.CommitTransaction(); err != nil { |
| 193 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 193 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 194 | } | 194 | } |
| 195 | - return struct{}{}, nil | 195 | + return userBase, nil |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | // 重置密码(忘记密码) | 198 | // 重置密码(忘记密码) |
| @@ -212,3 +212,7 @@ func FastPgAccountDestroyRecord(transactionContext application.TransactionContex | @@ -212,3 +212,7 @@ func FastPgAccountDestroyRecord(transactionContext application.TransactionContex | ||
| 212 | } | 212 | } |
| 213 | return rep, mod, err | 213 | return rep, mod, err |
| 214 | } | 214 | } |
| 215 | + | ||
| 216 | +func FastPgDataAuth(transactionContext application.TransactionContext, operateInfo *domain.OperateInfo) error { | ||
| 217 | + return nil | ||
| 218 | +} |
| @@ -153,7 +153,9 @@ func (orgService *OrgService) GetOrgSubDepartment(getOrgSubDepartmentQuery *quer | @@ -153,7 +153,9 @@ func (orgService *OrgService) GetOrgSubDepartment(getOrgSubDepartmentQuery *quer | ||
| 153 | if err := transactionContext.CommitTransaction(); err != nil { | 153 | if err := transactionContext.CommitTransaction(); err != nil { |
| 154 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 154 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 155 | } | 155 | } |
| 156 | - return orgs, nil | 156 | + return map[string]interface{}{ |
| 157 | + "orgs": orgs, | ||
| 158 | + }, nil | ||
| 157 | } | 159 | } |
| 158 | 160 | ||
| 159 | // 返回组织列表 | 161 | // 返回组织列表 |
| @@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -9,6 +10,7 @@ import ( | @@ -9,6 +10,7 @@ import ( | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type AssginRoleToUsersCommand struct { | 12 | type AssginRoleToUsersCommand struct { |
| 13 | + OperateInfo *domain.OperateInfo `json:"-"` | ||
| 12 | // 角色ID | 14 | // 角色ID |
| 13 | RoleId int64 `cname:"角色ID" json:"roleId" valid:"Required"` | 15 | RoleId int64 `cname:"角色ID" json:"roleId" valid:"Required"` |
| 14 | // 用户列表 | 16 | // 用户列表 |
| @@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -9,6 +10,7 @@ import ( | @@ -9,6 +10,7 @@ import ( | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type BatchDeleteRoleCommand struct { | 12 | type BatchDeleteRoleCommand struct { |
| 13 | + OperateInfo *domain.OperateInfo `json:"-"` | ||
| 12 | // 用户ID | 14 | // 用户ID |
| 13 | UserId int64 `cname:"用户ID" json:"userId"` | 15 | UserId int64 `cname:"用户ID" json:"userId"` |
| 14 | // 组织ID | 16 | // 组织ID |
| @@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -9,10 +10,12 @@ import ( | @@ -9,10 +10,12 @@ import ( | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type CreateRoleCommand struct { | 12 | type CreateRoleCommand struct { |
| 13 | + OperateInfo *domain.OperateInfo `json:"-"` | ||
| 12 | // 用户ID | 14 | // 用户ID |
| 13 | - UserId int64 `cname:"用户ID" json:"userId" valid:"Required"` | 15 | + UserId int64 `cname:"用户ID" json:"userId"` |
| 14 | // 组织ID | 16 | // 组织ID |
| 15 | - OrgId int64 `cname:"组织ID" json:"orgId" valid:"Required"` | 17 | + OrgId int64 `cname:"组织ID" json:"orgId"` |
| 18 | + | ||
| 16 | // 角色名称 | 19 | // 角色名称 |
| 17 | RoleName string `cname:"角色名称" json:"roleName" valid:"Required"` | 20 | RoleName string `cname:"角色名称" json:"roleName" valid:"Required"` |
| 18 | // 描述 | 21 | // 描述 |
| @@ -21,6 +24,9 @@ type CreateRoleCommand struct { | @@ -21,6 +24,9 @@ type CreateRoleCommand struct { | ||
| 21 | 24 | ||
| 22 | func (createRoleCommand *CreateRoleCommand) Valid(validation *validation.Validation) { | 25 | func (createRoleCommand *CreateRoleCommand) Valid(validation *validation.Validation) { |
| 23 | //validation.SetError("CustomValid", "未实现的自定义认证") | 26 | //validation.SetError("CustomValid", "未实现的自定义认证") |
| 27 | + if !createRoleCommand.OperateInfo.Valid() { | ||
| 28 | + validation.SetError("CustomValid", "操作信息不能为空 :"+createRoleCommand.OperateInfo.String()) | ||
| 29 | + } | ||
| 24 | } | 30 | } |
| 25 | 31 | ||
| 26 | func (createRoleCommand *CreateRoleCommand) ValidateCommand() error { | 32 | func (createRoleCommand *CreateRoleCommand) ValidateCommand() error { |
| @@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -9,6 +10,7 @@ import ( | @@ -9,6 +10,7 @@ import ( | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type RemoveRoleCommand struct { | 12 | type RemoveRoleCommand struct { |
| 13 | + OperateInfo *domain.OperateInfo `json:"-"` | ||
| 12 | // 角色ID | 14 | // 角色ID |
| 13 | RoleId int64 `cname:"角色ID" json:"roleId" valid:"Required"` | 15 | RoleId int64 `cname:"角色ID" json:"roleId" valid:"Required"` |
| 14 | } | 16 | } |
| @@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -9,6 +10,7 @@ import ( | @@ -9,6 +10,7 @@ import ( | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type UnAssginRoleToUsersCommand struct { | 12 | type UnAssginRoleToUsersCommand struct { |
| 13 | + OperateInfo *domain.OperateInfo `json:"-"` | ||
| 12 | // 角色ID | 14 | // 角色ID |
| 13 | RoleId int64 `cname:"角色ID" json:"roleId" valid:"Required"` | 15 | RoleId int64 `cname:"角色ID" json:"roleId" valid:"Required"` |
| 14 | // 用户列表 | 16 | // 用户列表 |
| @@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -9,6 +10,7 @@ import ( | @@ -9,6 +10,7 @@ import ( | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type UpdateRoleCommand struct { | 12 | type UpdateRoleCommand struct { |
| 13 | + OperateInfo *domain.OperateInfo `json:"-"` | ||
| 12 | // 角色ID | 14 | // 角色ID |
| 13 | RoleId int64 `cname:"角色ID" json:"roleId,string" valid:"Required"` | 15 | RoleId int64 `cname:"角色ID" json:"roleId,string" valid:"Required"` |
| 14 | // 角色名称 | 16 | // 角色名称 |
| @@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -9,6 +10,7 @@ import ( | @@ -9,6 +10,7 @@ import ( | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type UpdateRoleAccessMenusCommand struct { | 12 | type UpdateRoleAccessMenusCommand struct { |
| 13 | + OperateInfo *domain.OperateInfo `json:"-"` | ||
| 12 | // 角色ID | 14 | // 角色ID |
| 13 | RoleId int64 `cname:"角色ID" json:"roleId,string" valid:"Required"` | 15 | RoleId int64 `cname:"角色ID" json:"roleId,string" valid:"Required"` |
| 14 | // 菜单编号列表 | 16 | // 菜单编号列表 |
| @@ -25,8 +25,10 @@ func (dto *RoleRelatedUsersDto) LoadDto(users []*domain.User, relatedRoleId int6 | @@ -25,8 +25,10 @@ func (dto *RoleRelatedUsersDto) LoadDto(users []*domain.User, relatedRoleId int6 | ||
| 25 | 25 | ||
| 26 | func newRelatedUsers(user *domain.User) map[string]interface{} { | 26 | func newRelatedUsers(user *domain.User) map[string]interface{} { |
| 27 | return map[string]interface{}{ | 27 | return map[string]interface{}{ |
| 28 | + "departmentId": user.DepartmentId, | ||
| 28 | "departmentName": user.Ext.DepName, | 29 | "departmentName": user.Ext.DepName, |
| 29 | "userId": user.UserId, | 30 | "userId": user.UserId, |
| 30 | "userName": user.Ext.UserName, | 31 | "userName": user.Ext.UserName, |
| 32 | + "userCode": user.UserCode, | ||
| 31 | } | 33 | } |
| 32 | } | 34 | } |
| @@ -2,6 +2,7 @@ package query | @@ -2,6 +2,7 @@ package query | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -9,6 +10,7 @@ import ( | @@ -9,6 +10,7 @@ import ( | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type GetRoleQuery struct { | 12 | type GetRoleQuery struct { |
| 13 | + OperateInfo *domain.OperateInfo `json:"-"` | ||
| 12 | // 角色ID | 14 | // 角色ID |
| 13 | RoleId int64 `cname:"角色ID" json:"roleId" valid:"Required"` | 15 | RoleId int64 `cname:"角色ID" json:"roleId" valid:"Required"` |
| 14 | } | 16 | } |
| @@ -2,6 +2,7 @@ package query | @@ -2,6 +2,7 @@ package query | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -9,6 +10,7 @@ import ( | @@ -9,6 +10,7 @@ import ( | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type GetRoleAccessMenusQuery struct { | 12 | type GetRoleAccessMenusQuery struct { |
| 13 | + OperateInfo *domain.OperateInfo `json:"-"` | ||
| 12 | // 角色ID | 14 | // 角色ID |
| 13 | RoleId int64 `cname:"角色ID" json:"roleId,string" valid:"Required"` | 15 | RoleId int64 `cname:"角色ID" json:"roleId,string" valid:"Required"` |
| 14 | } | 16 | } |
| @@ -2,6 +2,7 @@ package query | @@ -2,6 +2,7 @@ package query | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -9,10 +10,12 @@ import ( | @@ -9,10 +10,12 @@ import ( | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type GetRoleRelatedUsersQuery struct { | 12 | type GetRoleRelatedUsersQuery struct { |
| 12 | - // 角色ID | ||
| 13 | - RoleId int64 `cname:"角色ID" json:"roleId" valid:"Required"` | 13 | + OperateInfo *domain.OperateInfo `json:"-"` |
| 14 | // 组织ID | 14 | // 组织ID |
| 15 | OrgId int64 `cname:"组织ID" json:"orgId,string,omitempty"` | 15 | OrgId int64 `cname:"组织ID" json:"orgId,string,omitempty"` |
| 16 | + | ||
| 17 | + // 角色ID | ||
| 18 | + RoleId int64 `cname:"角色ID" json:"roleId" valid:"Required"` | ||
| 16 | // 部门编号 | 19 | // 部门编号 |
| 17 | DepartmentId int64 `cname:"部门编号" json:"departmentId,omitempty"` | 20 | DepartmentId int64 `cname:"部门编号" json:"departmentId,omitempty"` |
| 18 | // 只需要关联的用户 true:仅返回关联用户信息 false:返回所有其他信息(未关联的用户) | 21 | // 只需要关联的用户 true:仅返回关联用户信息 false:返回所有其他信息(未关联的用户) |
| @@ -2,6 +2,7 @@ package query | @@ -2,6 +2,7 @@ package query | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -9,6 +10,7 @@ import ( | @@ -9,6 +10,7 @@ import ( | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type ListRoleQuery struct { | 12 | type ListRoleQuery struct { |
| 13 | + OperateInfo *domain.OperateInfo `json:"-"` | ||
| 12 | // 查询偏离量 | 14 | // 查询偏离量 |
| 13 | Offset int `cname:"查询偏离量" json:"offset"` | 15 | Offset int `cname:"查询偏离量" json:"offset"` |
| 14 | // 查询限制 | 16 | // 查询限制 |
| @@ -20,7 +22,7 @@ type ListRoleQuery struct { | @@ -20,7 +22,7 @@ type ListRoleQuery struct { | ||
| 20 | // 组织名称 | 22 | // 组织名称 |
| 21 | OrgName string `cname:"组织名称" json:"orgName,omitempty"` | 23 | OrgName string `cname:"组织名称" json:"orgName,omitempty"` |
| 22 | // 企业id | 24 | // 企业id |
| 23 | - CompanyId int64 `cname:"企业id" json:"companyId" valid:"Required"` | 25 | + CompanyId int64 `cname:"企业id" json:"companyId"` |
| 24 | // 组织ID | 26 | // 组织ID |
| 25 | OrgId int64 `cname:"组织ID" json:"orgId,omitempty"` | 27 | OrgId int64 `cname:"组织ID" json:"orgId,omitempty"` |
| 26 | // 匹配多个组织 | 28 | // 匹配多个组织 |
| @@ -32,7 +32,7 @@ func (roleService *RoleService) AssginRoleToUsers(assignRoleToUsersCommand *comm | @@ -32,7 +32,7 @@ func (roleService *RoleService) AssginRoleToUsers(assignRoleToUsersCommand *comm | ||
| 32 | defer func() { | 32 | defer func() { |
| 33 | transactionContext.RollbackTransaction() | 33 | transactionContext.RollbackTransaction() |
| 34 | }() | 34 | }() |
| 35 | - | 35 | + // TODO:数据权限 |
| 36 | _, role, err := factory.FastPgRole(transactionContext, assignRoleToUsersCommand.RoleId) | 36 | _, role, err := factory.FastPgRole(transactionContext, assignRoleToUsersCommand.RoleId) |
| 37 | if err != nil { | 37 | if err != nil { |
| 38 | return nil, err | 38 | return nil, err |
| @@ -74,7 +74,7 @@ func (roleService *RoleService) CreateRole(createRoleCommand *command.CreateRole | @@ -74,7 +74,7 @@ func (roleService *RoleService) CreateRole(createRoleCommand *command.CreateRole | ||
| 74 | transactionContext.RollbackTransaction() | 74 | transactionContext.RollbackTransaction() |
| 75 | }() | 75 | }() |
| 76 | 76 | ||
| 77 | - _, org, err := factory.FastPgOrg(transactionContext, createRoleCommand.OrgId) | 77 | + _, org, err := factory.FastPgOrg(transactionContext, createRoleCommand.OperateInfo.GetOrgId(createRoleCommand.OrgId)) |
| 78 | if err != nil { | 78 | if err != nil { |
| 79 | return nil, err | 79 | return nil, err |
| 80 | } | 80 | } |
| @@ -183,7 +183,9 @@ func (roleService *RoleService) GetRoleAccessMenus(getRoleAccessMenusQuery *quer | @@ -183,7 +183,9 @@ func (roleService *RoleService) GetRoleAccessMenus(getRoleAccessMenusQuery *quer | ||
| 183 | if err := transactionContext.CommitTransaction(); err != nil { | 183 | if err := transactionContext.CommitTransaction(); err != nil { |
| 184 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 184 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 185 | } | 185 | } |
| 186 | - return menus, nil | 186 | + return map[string]interface{}{ |
| 187 | + "menus": menus, | ||
| 188 | + }, nil | ||
| 187 | } | 189 | } |
| 188 | 190 | ||
| 189 | // 获取角色相关联的用户 | 191 | // 获取角色相关联的用户 |
| @@ -216,7 +218,7 @@ func (roleService *RoleService) GetRoleRelatedUsers(getRoleRelatedUsersQuery *qu | @@ -216,7 +218,7 @@ func (roleService *RoleService) GetRoleRelatedUsers(getRoleRelatedUsersQuery *qu | ||
| 216 | } | 218 | } |
| 217 | queryOptions := make(map[string]interface{}) | 219 | queryOptions := make(map[string]interface{}) |
| 218 | queryOptions["companyId"] = role.CompanyId | 220 | queryOptions["companyId"] = role.CompanyId |
| 219 | - queryOptions["organizationId"] = getRoleRelatedUsersQuery.OrgId | 221 | + queryOptions["organizationId"] = getRoleRelatedUsersQuery.OperateInfo.GetOrgId(getRoleRelatedUsersQuery.OrgId) |
| 220 | if getRoleRelatedUsersQuery.DepartmentId > 0 { | 222 | if getRoleRelatedUsersQuery.DepartmentId > 0 { |
| 221 | queryOptions["departmentId"] = getRoleRelatedUsersQuery.DepartmentId | 223 | queryOptions["departmentId"] = getRoleRelatedUsersQuery.DepartmentId |
| 222 | } | 224 | } |
| @@ -255,8 +257,10 @@ func (roleService *RoleService) ListRole(listRoleQuery *query.ListRoleQuery) (in | @@ -255,8 +257,10 @@ func (roleService *RoleService) ListRole(listRoleQuery *query.ListRoleQuery) (in | ||
| 255 | } else { | 257 | } else { |
| 256 | roleRepository = value | 258 | roleRepository = value |
| 257 | } | 259 | } |
| 260 | + | ||
| 258 | queryOptions := utils.ObjectToMap(listRoleQuery) | 261 | queryOptions := utils.ObjectToMap(listRoleQuery) |
| 259 | queryOptions["includeDeleted"] = false | 262 | queryOptions["includeDeleted"] = false |
| 263 | + queryOptions["companyId"] = listRoleQuery.OperateInfo.GetCompanyId(listRoleQuery.CompanyId) | ||
| 260 | if count, roles, err := roleRepository.Find(queryOptions); err != nil { | 264 | if count, roles, err := roleRepository.Find(queryOptions); err != nil { |
| 261 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 265 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 262 | } else { | 266 | } else { |
| @@ -285,6 +289,7 @@ func (roleService *RoleService) RemoveRole(removeRoleCommand *command.RemoveRole | @@ -285,6 +289,7 @@ func (roleService *RoleService) RemoveRole(removeRoleCommand *command.RemoveRole | ||
| 285 | defer func() { | 289 | defer func() { |
| 286 | transactionContext.RollbackTransaction() | 290 | transactionContext.RollbackTransaction() |
| 287 | }() | 291 | }() |
| 292 | + // TODO:数据权限 | ||
| 288 | var roleRepository domain.RoleRepository | 293 | var roleRepository domain.RoleRepository |
| 289 | if value, err := factory.CreateRoleRepository(map[string]interface{}{ | 294 | if value, err := factory.CreateRoleRepository(map[string]interface{}{ |
| 290 | "transactionContext": transactionContext, | 295 | "transactionContext": transactionContext, |
| @@ -329,6 +334,7 @@ func (roleService *RoleService) BatchDeleteRole(removeRoleCommand *command.Batch | @@ -329,6 +334,7 @@ func (roleService *RoleService) BatchDeleteRole(removeRoleCommand *command.Batch | ||
| 329 | defer func() { | 334 | defer func() { |
| 330 | transactionContext.RollbackTransaction() | 335 | transactionContext.RollbackTransaction() |
| 331 | }() | 336 | }() |
| 337 | + // TODO:数据权限 | ||
| 332 | var roleRepository domain.RoleRepository | 338 | var roleRepository domain.RoleRepository |
| 333 | if value, err := factory.CreateRoleRepository(map[string]interface{}{ | 339 | if value, err := factory.CreateRoleRepository(map[string]interface{}{ |
| 334 | "transactionContext": transactionContext, | 340 | "transactionContext": transactionContext, |
| @@ -376,7 +382,7 @@ func (roleService *RoleService) UnAssginRoleToUsers(unAssignRoleToUsersCommand * | @@ -376,7 +382,7 @@ func (roleService *RoleService) UnAssginRoleToUsers(unAssignRoleToUsersCommand * | ||
| 376 | defer func() { | 382 | defer func() { |
| 377 | transactionContext.RollbackTransaction() | 383 | transactionContext.RollbackTransaction() |
| 378 | }() | 384 | }() |
| 379 | - | 385 | + // TODO:数据权限 |
| 380 | _, role, err := factory.FastPgRole(transactionContext, unAssignRoleToUsersCommand.RoleId) | 386 | _, role, err := factory.FastPgRole(transactionContext, unAssignRoleToUsersCommand.RoleId) |
| 381 | if err != nil { | 387 | if err != nil { |
| 382 | return nil, err | 388 | return nil, err |
| @@ -416,7 +422,7 @@ func (roleService *RoleService) UpdateRole(updateRoleCommand *command.UpdateRole | @@ -416,7 +422,7 @@ func (roleService *RoleService) UpdateRole(updateRoleCommand *command.UpdateRole | ||
| 416 | defer func() { | 422 | defer func() { |
| 417 | transactionContext.RollbackTransaction() | 423 | transactionContext.RollbackTransaction() |
| 418 | }() | 424 | }() |
| 419 | - | 425 | + // TODO:数据权限 |
| 420 | roleRepository, role, err := factory.FastPgRole(transactionContext, updateRoleCommand.RoleId) | 426 | roleRepository, role, err := factory.FastPgRole(transactionContext, updateRoleCommand.RoleId) |
| 421 | if err != nil { | 427 | if err != nil { |
| 422 | return nil, err | 428 | return nil, err |
| @@ -456,7 +462,7 @@ func (roleService *RoleService) UpdateRoleAccessMenus(updateRoleAccessMenusComma | @@ -456,7 +462,7 @@ func (roleService *RoleService) UpdateRoleAccessMenus(updateRoleAccessMenusComma | ||
| 456 | defer func() { | 462 | defer func() { |
| 457 | transactionContext.RollbackTransaction() | 463 | transactionContext.RollbackTransaction() |
| 458 | }() | 464 | }() |
| 459 | - | 465 | + // TODO:数据权限 |
| 460 | roleRepository, role, err := factory.FastPgRole(transactionContext, updateRoleAccessMenusCommand.RoleId) | 466 | roleRepository, role, err := factory.FastPgRole(transactionContext, updateRoleAccessMenusCommand.RoleId) |
| 461 | if err != nil { | 467 | if err != nil { |
| 462 | return nil, err | 468 | return nil, err |
| @@ -19,6 +19,8 @@ type ListUserQuery struct { | @@ -19,6 +19,8 @@ type ListUserQuery struct { | ||
| 19 | OrganizationId int64 `cname:"组织ID" json:"organizationId,omitempty"` | 19 | OrganizationId int64 `cname:"组织ID" json:"organizationId,omitempty"` |
| 20 | // 部门编号 | 20 | // 部门编号 |
| 21 | DepartmentId int64 `cname:"部门编号" json:"departmentId,omitempty"` | 21 | DepartmentId int64 `cname:"部门编号" json:"departmentId,omitempty"` |
| 22 | + // 用户基础ID | ||
| 23 | + UserBaseId string `cname:"用户基础ID" json:"userBaseId,omitempty"` | ||
| 22 | // 用户姓名 | 24 | // 用户姓名 |
| 23 | UserName string `cname:"用户姓名" json:"userName,omitempty"` | 25 | UserName string `cname:"用户姓名" json:"userName,omitempty"` |
| 24 | // 用户姓名 | 26 | // 用户姓名 |
| @@ -446,7 +446,16 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in | @@ -446,7 +446,16 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in | ||
| 446 | } | 446 | } |
| 447 | _, company, _ := factory.FastPgCompany(transactionContext, listUserQuery.CompanyId) | 447 | _, company, _ := factory.FastPgCompany(transactionContext, listUserQuery.CompanyId) |
| 448 | var dtoUsers []*dto.UserDto | 448 | var dtoUsers []*dto.UserDto |
| 449 | - if count, users, err := userRepository.Find(utils.ObjectToMap(listUserQuery)); err != nil { | 449 | + queryOptions := utils.ObjectToMap(listUserQuery) |
| 450 | + if len(listUserQuery.Phone) > 0 { | ||
| 451 | + userBaseRepository, _, _ := factory.FastPgUserBase(transactionContext, 0) | ||
| 452 | + if userBase, err := userBaseRepository.FindOne(map[string]interface{}{"account": listUserQuery.Phone}); err != nil { | ||
| 453 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "账号不存在") | ||
| 454 | + } else { | ||
| 455 | + queryOptions["userBaseId"] = userBase.UserBaseId | ||
| 456 | + } | ||
| 457 | + } | ||
| 458 | + if count, users, err := userRepository.Find(queryOptions); err != nil { | ||
| 450 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 459 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 451 | } else { | 460 | } else { |
| 452 | for i := range users { | 461 | for i := range users { |
| @@ -10,6 +10,11 @@ var SERVICE_ENV = "dev" | @@ -10,6 +10,11 @@ var SERVICE_ENV = "dev" | ||
| 10 | var CACHE_PREFIX = "allied-creation-user-dev" | 10 | var CACHE_PREFIX = "allied-creation-user-dev" |
| 11 | var LOG_LEVEL = "debug" | 11 | var LOG_LEVEL = "debug" |
| 12 | 12 | ||
| 13 | +/***** 1.数据传输 *****/ | ||
| 14 | +const HeaderCompanyId = "companyId" | ||
| 15 | +const HeaderUserId = "userId" | ||
| 16 | +const HeaderOrgId = "orgId" | ||
| 17 | + | ||
| 13 | func init() { | 18 | func init() { |
| 14 | if os.Getenv("LOG_LEVEL") != "" { | 19 | if os.Getenv("LOG_LEVEL") != "" { |
| 15 | LOG_LEVEL = os.Getenv("LOG_LEVEL") | 20 | LOG_LEVEL = os.Getenv("LOG_LEVEL") |
| @@ -9,7 +9,7 @@ var ( | @@ -9,7 +9,7 @@ var ( | ||
| 9 | /***** 1.数据权限 *****/ | 9 | /***** 1.数据权限 *****/ |
| 10 | // DataAuthor 数据验证器 | 10 | // DataAuthor 数据验证器 |
| 11 | type DataAuthor interface { | 11 | type DataAuthor interface { |
| 12 | - DataAuth(options CheckOptions, data AuthedData) error | 12 | + DataAuth(options OperateInfo, data AuthedData) error |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | // AuthedData 需要认证的数据 | 15 | // AuthedData 需要认证的数据 |
| @@ -19,18 +19,52 @@ type AuthedData interface { | @@ -19,18 +19,52 @@ type AuthedData interface { | ||
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | // 验证参数 | 21 | // 验证参数 |
| 22 | -type CheckOptions struct { | 22 | +type OperateInfo struct { |
| 23 | // 当前操作人 | 23 | // 当前操作人 |
| 24 | - OptUser int64 | 24 | + UserId int64 |
| 25 | + // 当前公司 | ||
| 26 | + CompanyId int64 | ||
| 25 | // 当前登录的组织 | 27 | // 当前登录的组织 |
| 26 | - Org int64 | 28 | + OrgId int64 |
| 27 | // 菜单模块 | 29 | // 菜单模块 |
| 28 | MenuCode string | 30 | MenuCode string |
| 29 | } | 31 | } |
| 30 | 32 | ||
| 31 | -func NewCheckOptions(optUser, org int64) CheckOptions { | ||
| 32 | - return CheckOptions{ | ||
| 33 | - OptUser: optUser, | ||
| 34 | - Org: org, | 33 | +func NewCheckOptions(optUser, org int64) OperateInfo { |
| 34 | + return OperateInfo{ | ||
| 35 | + UserId: optUser, | ||
| 36 | + OrgId: org, | ||
| 35 | } | 37 | } |
| 36 | } | 38 | } |
| 39 | + | ||
| 40 | +func (info OperateInfo) Valid() bool { | ||
| 41 | + if info.UserId == 0 || info.CompanyId == 0 || info.OrgId == 0 { | ||
| 42 | + return false | ||
| 43 | + } | ||
| 44 | + return true | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +func (info OperateInfo) GetCompanyId(companyId int64) int64 { | ||
| 48 | + if info.CompanyId == 0 { | ||
| 49 | + return companyId | ||
| 50 | + } | ||
| 51 | + return info.CompanyId | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +func (info OperateInfo) GetOrgId(orgId int64) int64 { | ||
| 55 | + if info.OrgId == 0 { | ||
| 56 | + return orgId | ||
| 57 | + } | ||
| 58 | + return info.OrgId | ||
| 59 | +} | ||
| 60 | + | ||
| 61 | +func (info OperateInfo) GetUserId(userId int64) int64 { | ||
| 62 | + if info.UserId == 0 { | ||
| 63 | + return userId | ||
| 64 | + } | ||
| 65 | + return info.UserId | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +func (info OperateInfo) String() string { | ||
| 69 | + return fmt.Sprintf("UserId: %v OrgId:%v CompanyId:%v", info.UserId, info.OrgId, info.CompanyId) | ||
| 70 | +} |
| @@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | @@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 4 | 4 | ||
| 5 | // PgCreateOrgService 创建组织服务 | 5 | // PgCreateOrgService 创建组织服务 |
| 6 | type PgCreateOrgService interface { | 6 | type PgCreateOrgService interface { |
| 7 | - CreateOrg(optUser *domain.CheckOptions, orgInfo *domain.Org) (*domain.Org, error) | 7 | + CreateOrg(optUser *domain.OperateInfo, orgInfo *domain.Org) (*domain.Org, error) |
| 8 | } | 8 | } |
| @@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | @@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 4 | 4 | ||
| 5 | // PgCreateRoleService 传教角色服务 | 5 | // PgCreateRoleService 传教角色服务 |
| 6 | type PgCreateRoleService interface { | 6 | type PgCreateRoleService interface { |
| 7 | - CreateRole(optUser *domain.CheckOptions, roleInfo *domain.Role) (*domain.Role, error) | 7 | + CreateRole(optUser *domain.OperateInfo, roleInfo *domain.Role) (*domain.Role, error) |
| 8 | } | 8 | } |
| @@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | @@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 4 | 4 | ||
| 5 | // 角色有权限的菜单 | 5 | // 角色有权限的菜单 |
| 6 | type PgRoleAccessMenusService interface { | 6 | type PgRoleAccessMenusService interface { |
| 7 | - AccessMenus(options *domain.CheckOptions, roleId []int64, option domain.AccessMenusOptions) ([]*domain.Menu, error) | 7 | + AccessMenus(options *domain.OperateInfo, roleId []int64, option domain.AccessMenusOptions) ([]*domain.Menu, error) |
| 8 | } | 8 | } |
| @@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | @@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 4 | 4 | ||
| 5 | // PgUpdateUserService 用户更新服务 | 5 | // PgUpdateUserService 用户更新服务 |
| 6 | type PgUpdateUserService interface { | 6 | type PgUpdateUserService interface { |
| 7 | - UpdateUser(optUser *domain.CheckOptions, user *domain.User, userInfo *domain.UserInfo, enableStatus int) (*domain.User, error) | 7 | + UpdateUser(optUser *domain.OperateInfo, user *domain.User, userInfo *domain.UserInfo, enableStatus int) (*domain.User, error) |
| 8 | } | 8 | } |
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "strconv" | ||
| 6 | +) | ||
| 7 | + | ||
| 3 | const ( | 8 | const ( |
| 4 | StructTree = "tree" | 9 | StructTree = "tree" |
| 5 | StructList = "list" | 10 | StructList = "list" |
| @@ -105,3 +110,18 @@ func traverse(tree *Tree, node TreeNode) bool { | @@ -105,3 +110,18 @@ func traverse(tree *Tree, node TreeNode) bool { | ||
| 105 | } | 110 | } |
| 106 | return match | 111 | return match |
| 107 | } | 112 | } |
| 113 | + | ||
| 114 | +// Int64String 1 -> "1" "" | ||
| 115 | +type Int64String int64 | ||
| 116 | + | ||
| 117 | +func (t Int64String) MarshalJSON() ([]byte, error) { | ||
| 118 | + stamp := fmt.Sprintf(`"%d"`, t) | ||
| 119 | + return []byte(stamp), nil | ||
| 120 | +} | ||
| 121 | +func (t Int64String) UnMarshalJSON(data []byte) error { | ||
| 122 | + v, err := strconv.ParseInt(string(data), 10, 64) | ||
| 123 | + t = Int64String(v) | ||
| 124 | + return err | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +type StringInt64 int64 |
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "encoding/json" | ||
| 4 | "github.com/stretchr/testify/assert" | 5 | "github.com/stretchr/testify/assert" |
| 5 | "strconv" | 6 | "strconv" |
| 6 | "testing" | 7 | "testing" |
| @@ -47,3 +48,20 @@ func (t *st) PID() string { | @@ -47,3 +48,20 @@ func (t *st) PID() string { | ||
| 47 | func (t *st) ID() string { | 48 | func (t *st) ID() string { |
| 48 | return strconv.Itoa(t.Id) | 49 | return strconv.Itoa(t.Id) |
| 49 | } | 50 | } |
| 51 | + | ||
| 52 | +func TestInt64String(t *testing.T) { | ||
| 53 | + type value struct { | ||
| 54 | + Value Int64String `json:"v"` | ||
| 55 | + } | ||
| 56 | + jsonData := `{"v":1}` | ||
| 57 | + var v = value{} | ||
| 58 | + if err := json.Unmarshal([]byte(jsonData), &v); err != nil { | ||
| 59 | + assert.Error(t, err) | ||
| 60 | + } | ||
| 61 | + assert.Equal(t, v.Value, Int64String(1)) | ||
| 62 | + if data, err := json.Marshal(v); err != nil { | ||
| 63 | + assert.Error(t, err) | ||
| 64 | + } else { | ||
| 65 | + t.Log(string(data)) | ||
| 66 | + } | ||
| 67 | +} |
| @@ -16,7 +16,7 @@ type PgCreateOrgService struct { | @@ -16,7 +16,7 @@ type PgCreateOrgService struct { | ||
| 16 | // | 16 | // |
| 17 | // optUser 操作人 | 17 | // optUser 操作人 |
| 18 | // orgInfo 组织信息 | 18 | // orgInfo 组织信息 |
| 19 | -func (ptr *PgCreateOrgService) CreateOrg(optUser *domain.CheckOptions, orgInfo *domain.Org) (*domain.Org, error) { | 19 | +func (ptr *PgCreateOrgService) CreateOrg(optUser *domain.OperateInfo, orgInfo *domain.Org) (*domain.Org, error) { |
| 20 | var ( | 20 | var ( |
| 21 | err error | 21 | err error |
| 22 | org *domain.Org | 22 | org *domain.Org |
| @@ -16,7 +16,7 @@ type PgCreateRoleService struct { | @@ -16,7 +16,7 @@ type PgCreateRoleService struct { | ||
| 16 | // | 16 | // |
| 17 | // optUser 操作用户 | 17 | // optUser 操作用户 |
| 18 | // roleInfo 角色信息 | 18 | // roleInfo 角色信息 |
| 19 | -func (ptr *PgCreateRoleService) CreateRole(optUser *domain.CheckOptions, roleInfo *domain.Role) (*domain.Role, error) { | 19 | +func (ptr *PgCreateRoleService) CreateRole(optUser *domain.OperateInfo, roleInfo *domain.Role) (*domain.Role, error) { |
| 20 | if len(roleInfo.RoleName) == 0 { | 20 | if len(roleInfo.RoleName) == 0 { |
| 21 | return nil, fmt.Errorf("角色名称不能为空") | 21 | return nil, fmt.Errorf("角色名称不能为空") |
| 22 | } | 22 | } |
| @@ -16,7 +16,7 @@ type PgDataAuthService struct { | @@ -16,7 +16,7 @@ type PgDataAuthService struct { | ||
| 16 | // | 16 | // |
| 17 | // options 数据参数 | 17 | // options 数据参数 |
| 18 | // data 需要验证权限的数据 | 18 | // data 需要验证权限的数据 |
| 19 | -func (ptr *PgDataAuthService) DataAuth(options domain.CheckOptions, data domain.AuthedData) error { | 19 | +func (ptr *PgDataAuthService) DataAuth(options domain.OperateInfo, data domain.AuthedData) error { |
| 20 | return nil | 20 | return nil |
| 21 | } | 21 | } |
| 22 | 22 |
| @@ -19,7 +19,7 @@ type PgRoleAccessMenusService struct { | @@ -19,7 +19,7 @@ type PgRoleAccessMenusService struct { | ||
| 19 | // | 19 | // |
| 20 | // options 数据参数 | 20 | // options 数据参数 |
| 21 | // data 需要验证权限的数据 | 21 | // data 需要验证权限的数据 |
| 22 | -func (ptr *PgRoleAccessMenusService) AccessMenus(options *domain.CheckOptions, roleId []int64, option domain.AccessMenusOptions) ([]*domain.Menu, error) { | 22 | +func (ptr *PgRoleAccessMenusService) AccessMenus(options *domain.OperateInfo, roleId []int64, option domain.AccessMenusOptions) ([]*domain.Menu, error) { |
| 23 | var err error | 23 | var err error |
| 24 | var menus []*domain.Menu | 24 | var menus []*domain.Menu |
| 25 | menuIdSet := hashset.New() | 25 | menuIdSet := hashset.New() |
| @@ -14,7 +14,7 @@ type PgUpdateUserService struct { | @@ -14,7 +14,7 @@ type PgUpdateUserService struct { | ||
| 14 | transactionContext *pgTransaction.TransactionContext | 14 | transactionContext *pgTransaction.TransactionContext |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | -func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.CheckOptions, user *domain.User, userInfo *domain.UserInfo, enableStatus int) (*domain.User, error) { | 17 | +func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.OperateInfo, user *domain.User, userInfo *domain.UserInfo, enableStatus int) (*domain.User, error) { |
| 18 | var err error | 18 | var err error |
| 19 | roleRepository, _ := repository.NewRoleRepository(ptr.transactionContext) | 19 | roleRepository, _ := repository.NewRoleRepository(ptr.transactionContext) |
| 20 | //1.更新所属组织、部门 | 20 | //1.更新所属组织、部门 |
| @@ -179,6 +179,9 @@ func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int | @@ -179,6 +179,9 @@ func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int | ||
| 179 | query.SetWhereByQueryOption("org_id = ?", "orgId") | 179 | query.SetWhereByQueryOption("org_id = ?", "orgId") |
| 180 | query.SetWhereByQueryOption("role_name = ?", "roleName") | 180 | query.SetWhereByQueryOption("role_name = ?", "roleName") |
| 181 | query.SetWhereByQueryOption("(role_type & ?) >0", "roleType") | 181 | query.SetWhereByQueryOption("(role_type & ?) >0", "roleType") |
| 182 | + if orgName, ok := queryOptions["orgName"]; ok && len(orgName.(string)) > 0 { | ||
| 183 | + query.Where(fmt.Sprintf("ext->>'orgName' like '%%%v%%'", orgName)) | ||
| 184 | + } | ||
| 182 | // 包含删除的 | 185 | // 包含删除的 |
| 183 | if v, ok := queryOptions["includeDeleted"]; ok && !(v.(bool)) { | 186 | if v, ok := queryOptions["includeDeleted"]; ok && !(v.(bool)) { |
| 184 | query.Where("deleted_at is null") | 187 | query.Where("deleted_at is null") |
| @@ -16,7 +16,7 @@ func init() { | @@ -16,7 +16,7 @@ func init() { | ||
| 16 | web.BConfig.AppName = "project" | 16 | web.BConfig.AppName = "project" |
| 17 | web.BConfig.CopyRequestBody = true | 17 | web.BConfig.CopyRequestBody = true |
| 18 | web.BConfig.RunMode = "dev" | 18 | web.BConfig.RunMode = "dev" |
| 19 | - web.BConfig.Listen.HTTPPort = 8080 | 19 | + web.BConfig.Listen.HTTPPort = 8081 |
| 20 | web.BConfig.Listen.EnableAdmin = false | 20 | web.BConfig.Listen.EnableAdmin = false |
| 21 | web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego/routers" | 21 | web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego/routers" |
| 22 | if os.Getenv("RUN_MODE") != "" { | 22 | if os.Getenv("RUN_MODE") != "" { |
| @@ -4,7 +4,10 @@ import ( | @@ -4,7 +4,10 @@ import ( | ||
| 4 | "github.com/beego/beego/v2/server/web/context" | 4 | "github.com/beego/beego/v2/server/web/context" |
| 5 | "github.com/linmadan/egglib-go/web/beego" | 5 | "github.com/linmadan/egglib-go/web/beego" |
| 6 | "github.com/linmadan/egglib-go/web/beego/utils" | 6 | "github.com/linmadan/egglib-go/web/beego/utils" |
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/constant" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log" |
| 10 | + "strconv" | ||
| 8 | ) | 11 | ) |
| 9 | 12 | ||
| 10 | func ResponseGrid(c beego.BaseController, data interface{}, err error) { | 13 | func ResponseGrid(c beego.BaseController, data interface{}, err error) { |
| @@ -32,3 +35,24 @@ func Must(err error) { | @@ -32,3 +35,24 @@ func Must(err error) { | ||
| 32 | log.Logger.Error(err.Error()) | 35 | log.Logger.Error(err.Error()) |
| 33 | } | 36 | } |
| 34 | } | 37 | } |
| 38 | + | ||
| 39 | +// ParseOperateInfo 从头部解析操作对象信息 | ||
| 40 | +func ParseOperateInfo(c beego.BaseController) *domain.OperateInfo { | ||
| 41 | + opt := &domain.OperateInfo{} | ||
| 42 | + opt.UserId = header(c, constant.HeaderUserId) | ||
| 43 | + opt.CompanyId = header(c, constant.HeaderCompanyId) | ||
| 44 | + opt.OrgId = header(c, constant.HeaderOrgId) | ||
| 45 | + return opt | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +func header(c beego.BaseController, key string) int64 { | ||
| 49 | + if len(c.Ctx.Input.Header(key)) == 0 { | ||
| 50 | + return 0 | ||
| 51 | + } | ||
| 52 | + res, err := strconv.ParseInt(c.Ctx.Input.Header(key), 10, 64) | ||
| 53 | + if err != nil { | ||
| 54 | + log.Logger.Error(err.Error()) | ||
| 55 | + return 0 | ||
| 56 | + } | ||
| 57 | + return res | ||
| 58 | +} |
| @@ -15,6 +15,7 @@ func (controller *RoleController) CreateRole() { | @@ -15,6 +15,7 @@ func (controller *RoleController) CreateRole() { | ||
| 15 | roleService := service.NewRoleService(nil) | 15 | roleService := service.NewRoleService(nil) |
| 16 | createRoleCommand := &command.CreateRoleCommand{} | 16 | createRoleCommand := &command.CreateRoleCommand{} |
| 17 | Must(controller.Unmarshal(createRoleCommand)) | 17 | Must(controller.Unmarshal(createRoleCommand)) |
| 18 | + createRoleCommand.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 18 | data, err := roleService.CreateRole(createRoleCommand) | 19 | data, err := roleService.CreateRole(createRoleCommand) |
| 19 | controller.Response(data, err) | 20 | controller.Response(data, err) |
| 20 | } | 21 | } |
| @@ -25,6 +26,7 @@ func (controller *RoleController) UpdateRole() { | @@ -25,6 +26,7 @@ func (controller *RoleController) UpdateRole() { | ||
| 25 | controller.Unmarshal(updateRoleCommand) | 26 | controller.Unmarshal(updateRoleCommand) |
| 26 | roleId, _ := controller.GetInt64(":roleId") | 27 | roleId, _ := controller.GetInt64(":roleId") |
| 27 | updateRoleCommand.RoleId = roleId | 28 | updateRoleCommand.RoleId = roleId |
| 29 | + updateRoleCommand.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 28 | data, err := roleService.UpdateRole(updateRoleCommand) | 30 | data, err := roleService.UpdateRole(updateRoleCommand) |
| 29 | controller.Response(data, err) | 31 | controller.Response(data, err) |
| 30 | } | 32 | } |
| @@ -34,6 +36,7 @@ func (controller *RoleController) GetRole() { | @@ -34,6 +36,7 @@ func (controller *RoleController) GetRole() { | ||
| 34 | getRoleQuery := &query.GetRoleQuery{} | 36 | getRoleQuery := &query.GetRoleQuery{} |
| 35 | roleId, _ := controller.GetInt64(":roleId") | 37 | roleId, _ := controller.GetInt64(":roleId") |
| 36 | getRoleQuery.RoleId = roleId | 38 | getRoleQuery.RoleId = roleId |
| 39 | + getRoleQuery.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 37 | data, err := roleService.GetRole(getRoleQuery) | 40 | data, err := roleService.GetRole(getRoleQuery) |
| 38 | controller.Response(data, err) | 41 | controller.Response(data, err) |
| 39 | } | 42 | } |
| @@ -44,6 +47,7 @@ func (controller *RoleController) RemoveRole() { | @@ -44,6 +47,7 @@ func (controller *RoleController) RemoveRole() { | ||
| 44 | controller.Unmarshal(removeRoleCommand) | 47 | controller.Unmarshal(removeRoleCommand) |
| 45 | roleId, _ := controller.GetInt64(":roleId") | 48 | roleId, _ := controller.GetInt64(":roleId") |
| 46 | removeRoleCommand.RoleId = roleId | 49 | removeRoleCommand.RoleId = roleId |
| 50 | + removeRoleCommand.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 47 | data, err := roleService.RemoveRole(removeRoleCommand) | 51 | data, err := roleService.RemoveRole(removeRoleCommand) |
| 48 | controller.Response(data, err) | 52 | controller.Response(data, err) |
| 49 | } | 53 | } |
| @@ -52,6 +56,7 @@ func (controller *RoleController) BatchDeleteRole() { | @@ -52,6 +56,7 @@ func (controller *RoleController) BatchDeleteRole() { | ||
| 52 | roleService := service.NewRoleService(nil) | 56 | roleService := service.NewRoleService(nil) |
| 53 | removeRoleCommand := &command.BatchDeleteRoleCommand{} | 57 | removeRoleCommand := &command.BatchDeleteRoleCommand{} |
| 54 | controller.Unmarshal(removeRoleCommand) | 58 | controller.Unmarshal(removeRoleCommand) |
| 59 | + removeRoleCommand.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 55 | data, err := roleService.BatchDeleteRole(removeRoleCommand) | 60 | data, err := roleService.BatchDeleteRole(removeRoleCommand) |
| 56 | controller.Response(data, err) | 61 | controller.Response(data, err) |
| 57 | } | 62 | } |
| @@ -59,6 +64,7 @@ func (controller *RoleController) BatchDeleteRole() { | @@ -59,6 +64,7 @@ func (controller *RoleController) BatchDeleteRole() { | ||
| 59 | func (controller *RoleController) ListRole() { | 64 | func (controller *RoleController) ListRole() { |
| 60 | roleService := service.NewRoleService(nil) | 65 | roleService := service.NewRoleService(nil) |
| 61 | listRoleQuery := &query.ListRoleQuery{} | 66 | listRoleQuery := &query.ListRoleQuery{} |
| 67 | + listRoleQuery.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 62 | data, err := roleService.ListRole(listRoleQuery) | 68 | data, err := roleService.ListRole(listRoleQuery) |
| 63 | controller.Response(data, err) | 69 | controller.Response(data, err) |
| 64 | } | 70 | } |
| @@ -67,6 +73,7 @@ func (controller *RoleController) SearchRole() { | @@ -67,6 +73,7 @@ func (controller *RoleController) SearchRole() { | ||
| 67 | roleService := service.NewRoleService(nil) | 73 | roleService := service.NewRoleService(nil) |
| 68 | listRoleQuery := &query.ListRoleQuery{} | 74 | listRoleQuery := &query.ListRoleQuery{} |
| 69 | Must(controller.Unmarshal(listRoleQuery)) | 75 | Must(controller.Unmarshal(listRoleQuery)) |
| 76 | + listRoleQuery.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 70 | data, err := roleService.ListRole(listRoleQuery) | 77 | data, err := roleService.ListRole(listRoleQuery) |
| 71 | controller.Response(data, err) | 78 | controller.Response(data, err) |
| 72 | } | 79 | } |
| @@ -80,6 +87,7 @@ func (controller *RoleController) GetRoleRelatedUsers() { | @@ -80,6 +87,7 @@ func (controller *RoleController) GetRoleRelatedUsers() { | ||
| 80 | getRoleRelatedUsersQuery.OrgId = orgId | 87 | getRoleRelatedUsersQuery.OrgId = orgId |
| 81 | departmentId, _ := controller.GetInt64("departmentId") | 88 | departmentId, _ := controller.GetInt64("departmentId") |
| 82 | getRoleRelatedUsersQuery.DepartmentId = departmentId | 89 | getRoleRelatedUsersQuery.DepartmentId = departmentId |
| 90 | + getRoleRelatedUsersQuery.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 83 | data, err := roleService.GetRoleRelatedUsers(getRoleRelatedUsersQuery) | 91 | data, err := roleService.GetRoleRelatedUsers(getRoleRelatedUsersQuery) |
| 84 | controller.Response(data, err) | 92 | controller.Response(data, err) |
| 85 | } | 93 | } |
| @@ -89,6 +97,7 @@ func (controller *RoleController) GetRoleAccessMenus() { | @@ -89,6 +97,7 @@ func (controller *RoleController) GetRoleAccessMenus() { | ||
| 89 | getRoleAccessMenusQuery := &query.GetRoleAccessMenusQuery{} | 97 | getRoleAccessMenusQuery := &query.GetRoleAccessMenusQuery{} |
| 90 | roleId, _ := controller.GetInt64(":roleId") | 98 | roleId, _ := controller.GetInt64(":roleId") |
| 91 | getRoleAccessMenusQuery.RoleId = roleId | 99 | getRoleAccessMenusQuery.RoleId = roleId |
| 100 | + getRoleAccessMenusQuery.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 92 | data, err := roleService.GetRoleAccessMenus(getRoleAccessMenusQuery) | 101 | data, err := roleService.GetRoleAccessMenus(getRoleAccessMenusQuery) |
| 93 | controller.Response(data, err) | 102 | controller.Response(data, err) |
| 94 | } | 103 | } |
| @@ -99,6 +108,7 @@ func (controller *RoleController) UpdateRoleAccessMenus() { | @@ -99,6 +108,7 @@ func (controller *RoleController) UpdateRoleAccessMenus() { | ||
| 99 | controller.Unmarshal(updateRoleAccessMenusCommand) | 108 | controller.Unmarshal(updateRoleAccessMenusCommand) |
| 100 | roleId, _ := controller.GetInt64(":roleId") | 109 | roleId, _ := controller.GetInt64(":roleId") |
| 101 | updateRoleAccessMenusCommand.RoleId = roleId | 110 | updateRoleAccessMenusCommand.RoleId = roleId |
| 111 | + updateRoleAccessMenusCommand.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 102 | data, err := roleService.UpdateRoleAccessMenus(updateRoleAccessMenusCommand) | 112 | data, err := roleService.UpdateRoleAccessMenus(updateRoleAccessMenusCommand) |
| 103 | controller.Response(data, err) | 113 | controller.Response(data, err) |
| 104 | } | 114 | } |
| @@ -107,6 +117,7 @@ func (controller *RoleController) AssginRoleToUsers() { | @@ -107,6 +117,7 @@ func (controller *RoleController) AssginRoleToUsers() { | ||
| 107 | roleService := service.NewRoleService(nil) | 117 | roleService := service.NewRoleService(nil) |
| 108 | assginRoleToUsersCommand := &command.AssginRoleToUsersCommand{} | 118 | assginRoleToUsersCommand := &command.AssginRoleToUsersCommand{} |
| 109 | controller.Unmarshal(assginRoleToUsersCommand) | 119 | controller.Unmarshal(assginRoleToUsersCommand) |
| 120 | + assginRoleToUsersCommand.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 110 | data, err := roleService.AssginRoleToUsers(assginRoleToUsersCommand) | 121 | data, err := roleService.AssginRoleToUsers(assginRoleToUsersCommand) |
| 111 | controller.Response(data, err) | 122 | controller.Response(data, err) |
| 112 | } | 123 | } |
| @@ -115,6 +126,7 @@ func (controller *RoleController) UnAssginRoleToUsers() { | @@ -115,6 +126,7 @@ func (controller *RoleController) UnAssginRoleToUsers() { | ||
| 115 | roleService := service.NewRoleService(nil) | 126 | roleService := service.NewRoleService(nil) |
| 116 | unAssginRoleToUsersCommand := &command.UnAssginRoleToUsersCommand{} | 127 | unAssginRoleToUsersCommand := &command.UnAssginRoleToUsersCommand{} |
| 117 | controller.Unmarshal(unAssginRoleToUsersCommand) | 128 | controller.Unmarshal(unAssginRoleToUsersCommand) |
| 129 | + unAssginRoleToUsersCommand.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 118 | data, err := roleService.UnAssginRoleToUsers(unAssginRoleToUsersCommand) | 130 | data, err := roleService.UnAssginRoleToUsers(unAssginRoleToUsersCommand) |
| 119 | controller.Response(data, err) | 131 | controller.Response(data, err) |
| 120 | } | 132 | } |
-
请 注册 或 登录 后发表评论