...
|
...
|
@@ -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 {
|
...
|
...
|
|