...
|
...
|
@@ -4,6 +4,9 @@ import ( |
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
|
|
service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/adapter"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
)
|
...
|
...
|
@@ -46,6 +49,8 @@ func (us *UserService) ListByDepartment(in *query.ListByDepartmentQuery) (interf |
|
|
}()
|
|
|
|
|
|
userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
positionRepo := factory.CreatePositionRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
|
|
|
inMap := tool_funs.SimpleStructToMap(in)
|
|
|
if in.DepartmentId == 0 {
|
|
|
delete(inMap, "departmentId") // 删除部门ID字段
|
...
|
...
|
@@ -54,8 +59,108 @@ func (us *UserService) ListByDepartment(in *query.ListByDepartmentQuery) (interf |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
parentIds := make([]int64, 0) // 上级ID
|
|
|
positionIds := make([]int, 0) // 职位ID
|
|
|
for i := range list {
|
|
|
if list[i].ParentId > 0 {
|
|
|
parentIds = append(parentIds, list[i].ParentId)
|
|
|
}
|
|
|
|
|
|
pList := list[i].PositionId
|
|
|
for i2 := range pList {
|
|
|
if pList[i2] > 0 {
|
|
|
positionIds = append(positionIds, pList[i2])
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取上级
|
|
|
parentMap := map[int64]*domain.User{}
|
|
|
if len(parentIds) > 0 {
|
|
|
_, parentList, err := userRepo.Find(map[string]interface{}{"ids": parentIds})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
for i := range parentList {
|
|
|
parentMap[parentList[i].Id] = parentList[i]
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取职位
|
|
|
positionMap := map[int64]*domain.Position{}
|
|
|
if len(positionIds) > 0 {
|
|
|
_, positionList, err := positionRepo.Find(map[string]interface{}{"ids": positionIds})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
for i := range positionList {
|
|
|
positionMap[positionList[i].Id] = positionList[i]
|
|
|
}
|
|
|
}
|
|
|
|
|
|
adapters := make([]*adapter.UserResp, 0)
|
|
|
for i := range list {
|
|
|
adp := &adapter.UserResp{
|
|
|
User: list[i],
|
|
|
}
|
|
|
// 上级名称
|
|
|
if v, ok := parentMap[list[i].ParentId]; ok {
|
|
|
adp.ParentName = v.Name
|
|
|
}
|
|
|
// 职位名称数组
|
|
|
adp.PositionNames = make([]string, 0)
|
|
|
pList := list[i].PositionId
|
|
|
for i2 := range pList {
|
|
|
if v2, ok := positionMap[int64(pList[i2])]; ok {
|
|
|
adp.PositionNames = append(adp.PositionNames, v2.Name)
|
|
|
}
|
|
|
}
|
|
|
adapters = append(adapters, adp)
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return tool_funs.SimpleWrapGridMap(int64(count), list), nil
|
|
|
return tool_funs.SimpleWrapGridMap(int64(count), adapters), nil
|
|
|
}
|
|
|
|
|
|
// EditParentUser 保存上级
|
|
|
func (us *UserService) EditParentUser(in *command.EditParentCommand) error {
|
|
|
transactionContext, err := factory.ValidateStartTransaction(in)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
hrbp, err := service.GetHRBP(transactionContext, in.CompanyId, in.OperatorId)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if hrbp != 1 {
|
|
|
return application.ThrowError(application.BUSINESS_ERROR, "拥有HRBP权限才能编辑")
|
|
|
}
|
|
|
|
|
|
userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
user, err := userRepo.FindOne(map[string]interface{}{"id": in.Id})
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
// 上级ID是否存在
|
|
|
_, err = userRepo.FindOne(map[string]interface{}{"id": in.ParentId})
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
user.ParentId = in.ParentId
|
|
|
|
|
|
if _, err = userRepo.Update(user); err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|