作者 tangxvhui

调整人资稽查编辑

package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/xredis"
)
//人员填写周期评估
// 人资稽查-填写评估内容
func (srv *SummaryEvaluationService) EditEvaluationByHrCheck(param *command.EditEvaluationValue) (result interface{}, err 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()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
//根据 SummaryEvaluationId 查找记录
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.CompanyId != param.CompanyId {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
//按照被评估人id ,加锁
lock := xredis.NewLockSummaryEvaluation(evaluationData.TargetUser.UserId)
err = lock.Lock()
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
// 人员周期对应的所有评估 360 ,人资 ,自评,上级,考核结果
_, allEvaluationList, err := evaluationRepo.Find(map[string]interface{}{"targetUserId": evaluationData.TargetUser.UserId, "cycleId": evaluationData.CycleId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 评估的所有题目
_, itemUsedList, err := itemUsedRepo.Find(map[string]interface{}{
"evaluationProjectId": evaluationData.EvaluationProjectId,
"nodeType": domain.LinkNodeSelfAssessment,
})
// 上级评估
var evaluationSuper *domain.SummaryEvaluation
// 人资评估
var evalutionHrbp *domain.SummaryEvaluation
// 360评估 SummaryEvaluation.Executor.UserId => SummaryEvaluation
evaluation360Map := map[int]*domain.SummaryEvaluation{}
for _, val := range allEvaluationList {
switch val.Types {
case domain.Evaluation360:
evaluation360Map[val.Executor.UserId] = val
case domain.EvaluationSuper:
evaluationSuper = val
case domain.EvaluationHrbp:
evalutionHrbp = val
}
}
// 填写值和填写项id的映射
itemValueParam := map[int]command.UpdatedItemValue{}
for _, val := range param.EvaluationItems {
itemValueParam[val.EvaluationItemId] = val
}
//新的上级评估填写值
newSuperItemValueList := []*domain.SummaryEvaluationValue{}
//新的人资评估填写值
newHrbpItemValueList := []*domain.SummaryEvaluationValue{}
//新的360评估填写值 SummaryEvaluation.Executor.UserId => []*domain.SummaryEvaluationValue
new360ItemValueList := map[int][]*domain.SummaryEvaluationValue{}
for _, val := range itemUsedList {
if evaluationSuper != nil {
newItemValue := domain.SummaryEvaluationValue{}
newItemValue.SetBlankValue(evaluationSuper, val)
newItemValue.Remark = itemValueParam[val.Id].Remark
evaluationSuper.FillItemValue(val, &newItemValue, itemValueParam[val.Id].Value)
newSuperItemValueList = append(newSuperItemValueList, &newItemValue)
}
if evalutionHrbp != nil && val.EvaluatorId == -1 {
newItemValue := domain.SummaryEvaluationValue{}
newItemValue.SetBlankValue(evalutionHrbp, val)
newItemValue.Remark = itemValueParam[val.Id].Remark
evaluationSuper.FillItemValue(val, &newItemValue, itemValueParam[val.Id].Value)
newHrbpItemValueList = append(newHrbpItemValueList, &newItemValue)
}
if val.EvaluatorId > 0 {
evaluation360, ok := evaluation360Map[val.EvaluatorId]
if ok {
itemValue360List, ok := new360ItemValueList[evaluation360.Executor.UserId]
if !ok {
itemValue360List = make([]*domain.SummaryEvaluationValue, 0)
}
newItemValue := domain.SummaryEvaluationValue{}
newItemValue.SetBlankValue(evaluation360, val)
newItemValue.Remark = itemValueParam[val.Id].Remark
evaluationSuper.FillItemValue(val, &newItemValue, itemValueParam[val.Id].Value)
itemValue360List = append(itemValue360List, &newItemValue)
new360ItemValueList[evaluation360.Executor.UserId] = itemValue360List
}
}
}
// 处理上级评估
if evaluationSuper != nil {
evaluationSuper.EvaluationTotalScore(newSuperItemValueList)
//删除旧的填写值,使用新的填写内容
err = itemValueRepo.RemoveBySummaryEvaluationId(evaluationSuper.Id)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for _, val := range newSuperItemValueList {
err = itemValueRepo.Save(val)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
// 处理人资评估
if evalutionHrbp != nil {
evalutionHrbp.EvaluationTotalScore(newHrbpItemValueList)
//删除旧的填写值,使用新的填写内容
err = itemValueRepo.RemoveBySummaryEvaluationId(evalutionHrbp.Id)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for _, val := range newHrbpItemValueList {
err = itemValueRepo.Save(val)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
// 处理360评估
for key, val := range evaluation360Map {
val.EvaluationTotalScore(new360ItemValueList[key])
//删除旧的填写值,使用新的填写内容
err = itemValueRepo.RemoveBySummaryEvaluationId(val.Id)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for _, val := range new360ItemValueList[key] {
err = itemValueRepo.Save(val)
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())
}
return nil, nil
}
... ...
... ... @@ -123,7 +123,7 @@ import (
// }, nil
// }
// EditEvaluation360 编辑提交360综评
// EditEvaluation360 360评估 编辑提交360综评
// 填写规则变更。v2
func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
... ...
... ... @@ -16,108 +16,108 @@ import (
)
// 编辑综合自评详情
func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, 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()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
// func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, 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()
// }()
// 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.EvaluationSelf {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
// 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.EvaluationSelf {
// 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, "没有操作权限")
}
//按照 被评估人加锁
lock := xredis.NewLockSummaryEvaluation(evaluationData.TargetUser.UserId)
err = lock.Lock()
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
_, 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 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, "没有操作权限")
// }
// //按照 被评估人加锁
// lock := xredis.NewLockSummaryEvaluation(evaluationData.TargetUser.UserId)
// err = lock.Lock()
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
// }
// defer func() {
// lock.UnLock()
// }()
// _, 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())
}
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
// err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
// if err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
// }
if !param.IsTemporary {
evaluationData.Status = domain.EvaluationCompleted
//删除旧的填写值,使用新的填写内容
err = itemValueRepo.RemoveBySummaryEvaluationId(evaluationData.Id)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for _, val := range itemValueList {
val.Id = 0
}
}
err = evaluationRepo.Save(evaluationData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//保存填写值
for _, v := range itemValueList {
err = itemValueRepo.Save(v)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if !param.IsTemporary {
err = srv.AfterCompletedEvaluationSelf(transactionContext, evaluationData, itemValueList)
if err != nil {
return nil, err
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
return map[string][]adapter.EvaluationItemAdapter{
"EvaluationItems": itemValueAdapter,
}, nil
}
// if !param.IsTemporary {
// evaluationData.Status = domain.EvaluationCompleted
// //删除旧的填写值,使用新的填写内容
// err = itemValueRepo.RemoveBySummaryEvaluationId(evaluationData.Id)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// for _, val := range itemValueList {
// val.Id = 0
// }
// }
// err = evaluationRepo.Save(evaluationData)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// //保存填写值
// for _, v := range itemValueList {
// err = itemValueRepo.Save(v)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// }
// if !param.IsTemporary {
// err = srv.AfterCompletedEvaluationSelf(transactionContext, evaluationData, itemValueList)
// if err != nil {
// return nil, err
// }
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
// return map[string][]adapter.EvaluationItemAdapter{
// "EvaluationItems": itemValueAdapter,
// }, nil
// }
// 员工提交自评内容后,员工作为被评估人,
// 变更360评估/人资评估/的开始时间 或者变更上级评估的开始时间
... ...
... ... @@ -344,6 +344,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
"limit": 1,
})
if err != nil {
// nil
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 如果目标员工已经确认考核结果,就不能在进行评估编辑
... ...
... ... @@ -27,15 +27,6 @@ func (srv *SummaryEvaluationService) ListEvaluationShow1(param command.QueryEval
_ = transactionContext.RollbackTransaction()
}()
// // 必须是HRBP权限的人才能编辑操作
// hrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.UserId)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if hrbp != domain.RoleTypeSystem {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
staffAssessDaoRepo := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
... ...
... ... @@ -35,6 +35,7 @@ func (c *SummaryEvaluationController) GetUnconfirmedScoreCycleList() {
c.Response(data, err)
}
// 根据周期获取菜单显示
func (c *SummaryEvaluationController) GetMenu() {
srv := service.NewSummaryEvaluationService()
paramReq := &command.QueryMenu{}
... ... @@ -82,7 +83,7 @@ func (c *SummaryEvaluationController) EditEvaluationSelf() {
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
paramReq.ExecutorId = int(userReq.UserId)
data, err := srv.EditEvaluationSelf(paramReq)
data, err := srv.EditEvaluationSelfV2(paramReq)
c.Response(data, err)
}
... ...