作者 tangxvhui

修改 员工直属上级 展示

... ... @@ -8,4 +8,7 @@ prod 环境 http://performance-back-prd.fjmaimaimai.com/
前端页面地址
test环境 https://enterprise-platform-dev.fjmaimaimai.com/#/login
测试账号 17708397664 密码123456
\ No newline at end of file
测试账号 17708397664 密码123456
短信模板ID:5475050 短信内容: 您好,#name#,百忙之中不要忘记填写今天的绩效自评反馈哦
\ No newline at end of file
... ...
... ... @@ -1182,108 +1182,114 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
}
// 获取员工的上级是谁
func (srv StaffAssessServeice) getStaffSuper(transactionContext application.TransactionContext, targetUser domain.User) ([]*domain.User, error) {
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
var departmemtList []*domain.Department
var err error
if len(targetUser.DepartmentId) > 0 {
_, departmemtList, err = departmentRepo.Find(map[string]interface{}{
"ids": targetUser.DepartmentId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的部门列表"+err.Error())
}
}
if len(departmemtList) == 0 {
//找不到员工的部门
companyRepo := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
companyData, err := companyRepo.FindOne(map[string]interface{}{
"id": targetUser.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的公司"+err.Error())
}
//公司作为最顶级
departmemtList = append(departmemtList, &domain.Department{
Id: 0,
CompanyId: companyData.Id,
Level: 0,
Name: companyData.Name,
ParentId: 0,
ChargeUserIds: companyData.ChargeUserIds,
Path: "",
CreatedAt: time.Time{},
UpdatedAt: time.Time{},
DeletedAt: &time.Time{},
})
// func (srv StaffAssessServeice) getStaffSuper(transactionContext application.TransactionContext, targetUser domain.User) ([]*domain.User, error) {
// departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// userRepo := factory.CreateUserRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
}
//获取部门管理员
var chargeUserIds []int64
var targetUserAsManager *domain.Department
loop:
for _, v := range departmemtList {
if len(v.ChargeUserIds) == 0 {
continue
}
//检查员工自身是否是管理员
for _, vv := range v.ChargeUserIds {
if vv == targetUser.Id {
targetUserAsManager = v
break loop
}
}
chargeUserIds = append(chargeUserIds, v.ChargeUserIds...)
}
if targetUserAsManager != nil {
//清空原有的管理员
chargeUserIds = []int64{}
//员工自身是否是管理员,查找父级部门
_, parentDepartment, err := departmentRepo.Find(map[string]interface{}{
"id": targetUserAsManager.ParentId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工现在部门的父级"+err.Error())
}
for _, v := range parentDepartment {
chargeUserIds = append(chargeUserIds, v.ChargeUserIds...)
}
}
// var departmemtList []*domain.Department
// var err error
// if len(targetUser.DepartmentId) > 0 {
// _, departmemtList, err = departmentRepo.Find(map[string]interface{}{
// "ids": targetUser.DepartmentId,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的部门列表"+err.Error())
// }
// }
// if len(departmemtList) == 0 {
// //找不到员工的部门
// companyRepo := factory.CreateCompanyRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// companyData, err := companyRepo.FindOne(map[string]interface{}{
// "id": targetUser.CompanyId,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的公司"+err.Error())
// }
// //公司作为最顶级
// departmemtList = append(departmemtList, &domain.Department{
// Id: 0,
// CompanyId: companyData.Id,
// Level: 0,
// Name: companyData.Name,
// ParentId: 0,
// ChargeUserIds: companyData.ChargeUserIds,
// Path: "",
// CreatedAt: time.Time{},
// UpdatedAt: time.Time{},
// DeletedAt: &time.Time{},
// })
var chargeUserList []*domain.User
if len(chargeUserIds) > 0 {
_, chargeUserList, err = userRepo.Find(map[string]interface{}{
"ids": chargeUserIds,
"status": 1, //正常的用户
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取主管员工数据"+err.Error())
}
}
return chargeUserList, nil
}
// }
// //获取部门管理员
// var chargeUserIds []int64
// var targetUserAsManager *domain.Department
// loop:
// for _, v := range departmemtList {
// if len(v.ChargeUserIds) == 0 {
// continue
// }
// //检查员工自身是否是管理员
// for _, vv := range v.ChargeUserIds {
// if vv == targetUser.Id {
// targetUserAsManager = v
// break loop
// }
// }
// chargeUserIds = append(chargeUserIds, v.ChargeUserIds...)
// }
// if targetUserAsManager != nil {
// //清空原有的管理员
// chargeUserIds = []int64{}
// //员工自身是否是管理员,查找父级部门
// _, parentDepartment, err := departmentRepo.Find(map[string]interface{}{
// "id": targetUserAsManager.ParentId,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工现在部门的父级"+err.Error())
// }
// for _, v := range parentDepartment {
// chargeUserIds = append(chargeUserIds, v.ChargeUserIds...)
// }
// }
// TODO
func (srv *StaffAssessServeice) getStaffSuperV2(transactionContext application.TransactionContext, targetUser domain.User) ([]*domain.User, error) {
// var chargeUserList []*domain.User
// if len(chargeUserIds) > 0 {
// _, chargeUserList, err = userRepo.Find(map[string]interface{}{
// "ids": chargeUserIds,
// "status": 1, //正常的用户
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取主管员工数据"+err.Error())
// }
// }
// return chargeUserList, nil
// }
// 获取员工的上级是谁
func (srv StaffAssessServeice) getStaffSuper(transactionContext application.TransactionContext, targetUser domain.User) ([]*domain.User, error) {
if targetUser.ParentId == 0 {
return nil, nil
}
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
userRepo.Find(map[string]interface{}{})
return nil, nil
userData, err := userRepo.FindOne(map[string]interface{}{
"id": targetUser.ParentId,
})
if err != nil {
return nil, err
}
return []*domain.User{userData}, nil
}
func (srv *StaffAssessServeice) recoverAssessCache(context application.TransactionContext, assessId int, dataArray []*domain.StaffAssessContent) {
func (srv StaffAssessServeice) recoverAssessCache(context application.TransactionContext, assessId int, dataArray []*domain.StaffAssessContent) {
cacheRepository := factory.CreateStaffAssessCacheRepository(map[string]interface{}{"transactionContext": context})
_, caches, err := cacheRepository.Find(map[string]interface{}{"assessId": assessId, "limit": 1})
if err != nil || len(caches) == 0 {
... ...
... ... @@ -832,3 +832,77 @@ func (srv StaffAssessServeice) ListTargetUserSuperAssess(param *query.ListTarget
}
return tool_funs.SimpleWrapGridMap(int64(cnt), resultList), nil
}
// 选择员工评估可邀请的用户
func (srv StaffAssessServeice) SelectAssessInviteUserV2(param *query.SelectAssessInviteUser) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//获取被评估的目标用户
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取公司信息
companyRepo := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
companyInfo, _ := companyRepo.FindOne(map[string]interface{}{
"id": param.CompanyId,
})
targetUser, err := userRepo.FindOne(map[string]interface{}{
"id": param.TargetUserId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工信息"+err.Error())
}
//查询员工数据
condition := map[string]interface{}{
"companyId": param.CompanyId,
"name": param.InviteUserName,
"limit": 20,
"status": 1,
}
if param.PageSize > 0 {
condition["limit"] = param.PageSize
}
offset := (param.PageNumber - 1) * param.PageSize
if offset > 0 {
condition["offset"] = offset
}
cnt, userList, err := userRepo.Find(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工列表信息"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
listData := []adapter.SelectInviteUser{}
companyName := ""
if companyInfo != nil {
companyName = companyInfo.Name
}
for _, v := range userList {
_ = v
_ = companyName
item := adapter.SelectInviteUser{
UserId: int(v.Id),
UserName: v.Name,
CompanyName: companyName,
IsSupper: false,
Types: 2, //默认是不同上级
}
if targetUser.ParentId == v.ParentId {
item.Types = 1
}
listData = append(listData, item)
}
return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
}
... ...
... ... @@ -143,12 +143,10 @@ func (c *StaffAssessController) SelectAssessInviteUser() {
c.Response(nil, e)
return
}
// paramReq.CompanyId = 1
// paramReq.TargetUserId = 1
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
paramReq.TargetUserId = int(userReq.UserId)
data, err := srv.SelectAssessInviteUser(paramReq)
data, err := srv.SelectAssessInviteUserV2(paramReq)
c.Response(data, err)
}
... ...