作者 郑周

1. 超管权限 查看考核详情

... ... @@ -1140,181 +1140,108 @@ func (srv *SummaryEvaluationService) GetEvaluationSuperForAdmin(param *command.Q
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{"id": []int{param.SummaryEvaluationId}})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
return &adapter.EvaluationInfoSuperAdapter{}, nil
result, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
if err != nil || result == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估"+err.Error())
}
evaluationData := evaluationList[0]
if evaluationData.CompanyId != param.CompanyId {
if result.CompanyId != param.CompanyId {
return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
}
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": evaluationData.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
if result.Types != domain.EvaluationFinish {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "考核结果类型错误")
}
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取已填写的评估内容
_, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})
_, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 上级评估未填写或未填写完成,获取360/人资评估的填写值
if len(itemValues) == 0 || evaluationData.Status == domain.EvaluationUncompleted {
_, evaluationListOther, err := evaluationRepo.Find(map[string]interface{}{
"typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
"targetUserId": evaluationData.TargetUser.UserId,
"cycleId": evaluationData.CycleId,
})
// 考核结果不存在 -> 获取上级考核 -> 获取360+HRBP+自评
if len(itemValues) == 0 {
itemValues, evaluationList, err := srv.findCycleItemValueByType(transactionContext, result.CycleId, result.TargetUser.UserId, []int{int(domain.EvaluationSuper)})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var evaluationIds []int
for _, v := range evaluationListOther {
evaluationIds = append(evaluationIds, v.Id)
// 没有上级评估时(有上级考核类型时,不管分数有没有填写都算,没填写当作零)
if len(evaluationList) == 0 {
itemValues, _, err = srv.findCycleItemValueByType(transactionContext, result.CycleId, result.TargetUser.UserId, []int{int(domain.EvaluationSelf)})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationIds) > 0 {
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
hrItemValues, _, err := srv.findCycleItemValueByType(transactionContext, result.CycleId, result.TargetUser.UserId, []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 自评分数
if len(itemValues) == 0 {
itemValues = hrItemValues
} else {
// HR360分数 替换 自评分数
hrItemMap := map[int]*domain.SummaryEvaluationValue{}
for i := range hrItemValues {
hrItemMap[hrItemValues[i].EvaluationItemId] = hrItemValues[i]
}
for i := range itemValues {
it := itemValues[i]
if v, ok := hrItemMap[it.EvaluationItemId]; ok {
itemValues[i] = v
}
evaluationBase := srv.getSummaryEvaluation(transactionContext, evaluationData)
}
}
}
}
evaluationBase := srv.getSummaryEvaluation(transactionContext, result)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//组合 评估填写的值和评估项
itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
result := adapter.EvaluationInfoSuperAdapter{
ra := adapter.EvaluationInfoSuperAdapter{
EvaluationBaseAdapter: evaluationBase,
EvaluationItems: itemValuesAdapter,
}
return &result, nil
return &ra, nil
}
// // EditEvaluationSuper 更新上级评估内容
// func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEvaluationValue) (interface{}, error) {
// lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)
// err := lock.Lock()
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
// }
// defer func() {
// lock.UnLock()
// }()
// 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()
// }()
// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{
// "id": param.SummaryEvaluationId,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if evaluationData.Types != domain.EvaluationSuper {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
// if evaluationData.Executor.UserId != param.ExecutorId {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
// if evaluationData.CompanyId != param.CompanyId {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
// "targetUserId": evaluationData.TargetUser.UserId,
// "typesList": []int{int(domain.EvaluationFinish)},
// "cycleId": evaluationData.CycleId,
// "limit": 1,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// // 如果目标员工已经确认考核结果,就不能在进行评估编辑
// if len(evaluationList) > 0 && evaluationList[0].CheckResult == domain.EvaluationCheckCompleted {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户已经确认该周期的考核结果,不能再编辑!")
// }
func (srv *SummaryEvaluationService) findCycleItemValueByType(
tc application.TransactionContext,
cycleId int64,
targetUserId int,
typesList []int,
) ([]*domain.SummaryEvaluationValue, []*domain.SummaryEvaluation, error) {
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": tc})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": tc})
// _, itemList, err := itemUsedRepo.Find(map[string]interface{}{
// "evaluationProjectId": evaluationData.EvaluationProjectId,
// "nodeType": domain.LinkNodeSelfAssessment,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// //获取已填写的评估内容
// _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{
// "summaryEvaluationId": evaluationData.Id,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// //记录人资评估或者360评估的 填写项id
// hrbpOr360ItemValue, err := srv.getEvaluationSuperDefaultValue(transactionContext, evaluationData)
// if err != nil {
// return nil, err
// }
// err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, hrbpOr360ItemValue, param.IsTemporary)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if !param.IsTemporary {
// //变更评估状态为已填写
// evaluationData.Status = domain.EvaluationCompleted
// }
// for _, v := range itemValueList {
// //保存填写值
// err = itemValueRepo.Save(v)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// }
// //保存填写值
// err = evaluationRepo.Save(evaluationData)
// 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())
// }
// if !param.IsTemporary {
// err = srv.AfterCompletedEvaluationSuper(evaluationData)
// if err != nil {
// return nil, err
// }
// }
// itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
// return map[string][]adapter.EvaluationItemAdapter{
// "EvaluationItems": itemValueAdapter,
// }, nil
// }
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"typesList": typesList,
"limit": len(typesList),
"targetUserId": targetUserId,
"cycleId": cycleId,
})
if err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var eIds []int // 评估类型的ID列表
for _, v := range evaluationList {
eIds = append(eIds, v.Id)
}
if len(eIds) > 0 {
_, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": eIds})
if err != nil {
return nil, evaluationList, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
return itemValues, evaluationList, nil
}
}
return make([]*domain.SummaryEvaluationValue, 0), evaluationList, nil
}
// EditEvaluationSuperForAdmin 更新上级评估内容(超级管理员)
func (srv *SummaryEvaluationService) EditEvaluationSuperForAdmin(param *command.EditEvaluationValue) (interface{}, error) {
... ...
... ... @@ -258,7 +258,7 @@ func (c *SummaryEvaluationController) EditEvaluationHRBP() {
c.Response(data, err)
}
// 获取上级评估
// GetEvaluationSuper 获取上级评估、或考核结果
func (c *SummaryEvaluationController) GetEvaluationSuper() {
srv := service.NewSummaryEvaluationService()
param := &command.QueryEvaluationSuper{}
... ... @@ -272,9 +272,9 @@ func (c *SummaryEvaluationController) GetEvaluationSuper() {
param.CompanyId = int(userReq.CompanyId)
param.UserId = int(userReq.UserId)
// 超级管理员可以修改上级评估数据
// 超级管理员获取考核结果
if param.Advanced == 1 {
data, err := srv.GetEvaluationSuperForAdmin(param)
data, err := srv.GetEvaluationFinish(param)
c.Response(data, err)
} else {
data, err := srv.GetEvaluationSuper(param)
... ... @@ -282,7 +282,7 @@ func (c *SummaryEvaluationController) GetEvaluationSuper() {
}
}
// 编辑上级评估
// EditEvaluationSuper 编辑上级评估、编辑考核结果
func (c *SummaryEvaluationController) EditEvaluationSuper() {
srv := service.NewSummaryEvaluationService()
param := &command.EditEvaluationValue{}
... ... @@ -296,9 +296,9 @@ func (c *SummaryEvaluationController) EditEvaluationSuper() {
param.CompanyId = int(userReq.CompanyId)
param.ExecutorId = int(userReq.UserId)
// 超级管理员重新修改上级评估数据
// 超级管理员获取评估考核结果
if param.Advanced == 1 {
data, err := srv.EditEvaluationSuperForAdmin(param)
data, err := srv.EditEvaluationFinish(param)
c.Response(data, err)
} else {
data, err := srv.EditEvaluationSuper(param)
... ...