作者 tangxvhui

调整逻辑,编辑上级综评后同步考核结果

package service
import (
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter"
"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"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
)
//编辑上级周期评估
// 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, "没有操作权限")
}
//按照被评估人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()
}()
_, 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, "用户已经确认该周期的考核结果,不能再编辑!")
}
_, 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(transactionContext, evaluationData, itemValueList)
if err != nil {
return nil, err
}
}
itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
return map[string][]adapter.EvaluationItemAdapter{
"EvaluationItems": itemValueAdapter,
}, nil
}
// 员工提交上级评估后
// 生成考核结果
func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(
transactionContext application.TransactionContext,
evaluationData *domain.SummaryEvaluation,
evaluationValue []*domain.SummaryEvaluationValue,
) error {
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//没有上级评估
//直接进入考核结果阶段
_, 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 application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) > 0 {
//调整考核结果的开始时间
nowTime := time.Now()
if evaluationList[0].BeginTime.After(nowTime) {
evaluationList[0].BeginTime = nowTime
}
evaluationList[0].Status = domain.EvaluationCompleted
err = srv.syncEvaluationFinishValue(transactionContext, evaluationList[0], evaluationValue)
if err != nil {
return err
}
//添加确认绩效成绩提醒短信提醒
err = notify.AddNotifyConfirmEvaluationScore(evaluationList[0])
if err != nil {
log.Logger.Error("添加确认绩效成绩提醒短信提醒失败:" + err.Error())
}
}
return nil
}
// 从其他评估那边同步考核结果的评估内容
// evaluationData 考核结果评估
// updateValue 更新评估项需要的值
func (srv *SummaryEvaluationService) syncEvaluationFinishValue(
transactionContext application.TransactionContext,
evaluationData *domain.SummaryEvaluation,
updateValue []*domain.SummaryEvaluationValue,
) error {
if len(updateValue) == 0 {
return nil
}
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
evaluationValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, itemList, err := itemUsedRepo.Find(map[string]interface{}{
"evaluationProjectId": evaluationData.EvaluationProjectId,
"nodeType": domain.LinkNodeSelfAssessment,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//填写项的map EvaluationItemId =>SummaryEvaluationValue
oldEvaluationValue := map[int]*domain.SummaryEvaluationValue{}
//查询已有的考核结果评估内容
_, evaluationValueList, err := evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i, val := range evaluationValueList {
oldEvaluationValue[val.EvaluationItemId] = evaluationValueList[i]
}
// 待更新的评估填写项map EvaluationItemId =>SummaryEvaluationValue
updateValueMap := map[int]*domain.SummaryEvaluationValue{}
for i, val := range updateValue {
updateValueMap[val.EvaluationItemId] = updateValue[i]
}
//更新考核结果
for _, val := range itemList {
oldValue, ok := oldEvaluationValue[val.Id]
if !ok {
//补全考核结果中可能缺失的评估项
newValue := &domain.SummaryEvaluationValue{}
newValue.SetBlankValue(evaluationData, val)
oldEvaluationValue[val.Id] = newValue
oldValue = oldEvaluationValue[val.Id]
}
if item, ok := updateValueMap[val.Id]; ok {
oldValue.Executor = item.Executor
oldValue.Types = item.Types
oldValue.Rating = item.Rating
oldValue.Value = item.Value
oldValue.Score = item.Score
oldValue.Remark = item.Remark
}
}
evaluationData.TotalRating = nil
for i := range itemList {
evaluationData.ResetTotalRating(itemList[i])
}
newEvaluationValue := []*domain.SummaryEvaluationValue{}
for _, val := range oldEvaluationValue {
newEvaluationValue = append(newEvaluationValue, val)
}
evaluationData.EvaluationTotalScore(newEvaluationValue)
err = evaluationRepo.Save(evaluationData)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())
}
err = evaluationValueRepo.RemoveBySummaryEvaluationId(evaluationData.Id)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())
}
for _, val := range newEvaluationValue {
val.Id = 0
err = evaluationValueRepo.Save(val)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())
}
}
return nil
}
... ...
package service
// sendSummaryEvaluafionTask 根据评估项目设置,确认是否下发评估任务
// project 需要处理的项目
// userList 全体的员工数据 map[id]=>domain.User
// departmetList 全部的部门数据 map[id]=>domain.Department
// func sendSummaryEvaluation(project *domain.EvaluationProject,
// userMap map[int64]*domain.User, departmentMap map[int64]*domain.Department) ([]domain.SummaryEvaluation, error) {
// //自评的时间范围
// beginTimeSelf := project.EndTime
// endTimeSelf := dayZeroTime(project.EndTime).Add(4*24*time.Hour - time.Second)
// //人资、360评估的时间范围
// beginTime360 := endTimeSelf
// endTime360 := endTimeSelf.Add(2 * 24 * time.Hour)
// //上级评估的是时间范围
// beginTimeSuper := endTime360
// endTimeSuper := endTime360.Add(2 * 24 * time.Hour)
// //
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return nil, err
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, err
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
// cycleRepo := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
// evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
// cycleData, err := cycleRepo.FindOne(map[string]interface{}{"id": project.CycleId})
// if err != nil {
// return nil, err
// }
// //确定 被评估的人
// targetUserId := []int64{}
// for _, v := range project.Recipients {
// id, err := strconv.ParseInt(v, 10, 64)
// if err == nil {
// targetUserId = append(targetUserId, id)
// }
// }
// if len(targetUserId) == 0 {
// return nil, nil
// }
// //被评估的员工
// targetUserMap := map[int64]*domain.User{}
// for _, v := range targetUserId {
// u, ok := userMap[v]
// if ok {
// targetUserMap[v] = u
// }
// }
// //确定360评估的执行人
// _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": project.Id, "nodeType": int(domain.LinkNodeSelfAssessment)})
// if err != nil {
// return nil, err
// }
// nodeId := 0
// executor360Map := map[int64]*domain.User{}
// hrbpExist := false
// for _, v := range itemList {
// nodeId = v.NodeId
// if v.EvaluatorId < 0 {
// hrbpExist = true
// }
// if v.EvaluatorId <= 0 {
// continue
// }
// if u, ok := userMap[int64(v.EvaluatorId)]; ok {
// executor360Map[u.Id] = u
// }
// }
// //创建周期评估任务
// var newEvaluationList []domain.SummaryEvaluation
// evaluationTemp := domain.SummaryEvaluation{
// Id: 0,
// CompanyId: int(project.CompanyId),
// EvaluationProjectId: int(project.Id),
// EvaluationProjectName: project.Name,
// CycleId: cycleData.Id,
// CycleName: cycleData.Name,
// NodeId: nodeId,
// TargetUser: domain.StaffDesc{},
// TargetDepartment: []domain.StaffDepartment{},
// Executor: domain.StaffDesc{},
// Types: 0,
// Status: domain.EvaluationUncompleted,
// CheckResult: domain.EvaluationCheckUncompleted,
// BeginTime: time.Time{},
// EndTime: time.Time{},
// TotalScore: "",
// CreatedAt: time.Now(),
// UpdatedAt: time.Now(),
// DeletedAt: nil,
// }
// //确定周期评估
// for _, v := range targetUserMap {
// //处理自评
// evaluationTemp.TargetUser = domain.StaffDesc{
// UserId: int(v.Id),
// Account: v.Account,
// UserName: v.Name,
// }
// evaluationTemp.Executor = domain.StaffDesc{
// UserId: int(v.Id),
// Account: v.Account,
// UserName: v.Name,
// }
// evaluationTemp.BeginTime = beginTimeSelf
// evaluationTemp.EndTime = endTimeSelf
// evaluationTemp.TargetDepartment = []domain.StaffDepartment{}
// evaluationTemp.Types = domain.EvaluationSelf
// for _, departId := range v.DepartmentId {
// depart, ok := departmentMap[int64(departId)]
// if !ok {
// continue
// }
// evaluationTemp.TargetDepartment = append(evaluationTemp.TargetDepartment, domain.StaffDepartment{
// DepartmentId: int(depart.Id),
// DepartmentName: depart.Name,
// })
// }
// newEvaluationList = append(newEvaluationList, evaluationTemp)
// if hrbpExist {
// //处理人资评估
// evaluationTemp.BeginTime = beginTime360
// evaluationTemp.EndTime = endTime360
// evaluationTemp.Executor = domain.StaffDesc{}
// evaluationTemp.Types = domain.EvaluationHrbp
// newEvaluationList = append(newEvaluationList, evaluationTemp)
// }
// //处理360 评估
// for _, v2 := range executor360Map {
// evaluationTemp.BeginTime = beginTime360
// evaluationTemp.EndTime = endTime360
// evaluationTemp.Executor = domain.StaffDesc{
// UserId: int(v2.Id),
// Account: v2.Account,
// UserName: v2.Name,
// }
// evaluationTemp.Types = domain.Evaluation360
// newEvaluationList = append(newEvaluationList, evaluationTemp)
// }
// //处理上级评估
// superUser, ok := userMap[v.ParentId]
// if ok {
// evaluationTemp.Types = domain.EvaluationSuper
// evaluationTemp.Executor = domain.StaffDesc{
// UserId: int(superUser.Id),
// Account: superUser.Account,
// UserName: superUser.Name,
// }
// evaluationTemp.BeginTime = beginTimeSuper
// evaluationTemp.EndTime = endTimeSuper
// //确定上级评估
// newEvaluationList = append(newEvaluationList, evaluationTemp)
// }
// // 确定 考核结果 的评估记录
// evaluationTemp.Types = domain.EvaluationFinish
// evaluationTemp.Executor = domain.StaffDesc{}
// evaluationTemp.BeginTime = endTimeSuper
// evaluationTemp.EndTime = endTimeSuper.Add(2 * 24 * time.Hour)
// newEvaluationList = append(newEvaluationList, evaluationTemp)
// }
// summaryEvaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
// for i := range newEvaluationList {
// err = summaryEvaluationRepo.Save(&newEvaluationList[i])
// if err != nil {
// return nil, err
// }
// }
// //回填 项目的状态
// projectDao := dao.NewEvaluationProjectDao(map[string]interface{}{"transactionContext": transactionContext})
// err = projectDao.UpdateSummaryState(project.Id, domain.ProjectSummaryStateYes)
// if err != nil {
// return nil, err
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, err
// }
// return newEvaluationList, nil
// }
// func dayZeroTime(t time.Time) time.Time {
// y, m, d := t.Local().Date()
// t2 := time.Date(y, m, d, 0, 0, 0, 0, time.Local)
// return t2
// }
// // 下发周期评估
// func TaskSendSummaryEvaluation() error {
// nowTime := time.Now()
// defer func() {
// str := fmt.Sprintf("下发周期评估耗时%.2f s", time.Since(nowTime).Seconds())
// log.Logger.Info(str)
// }()
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return err
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return err
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
// projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
// departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{"transactionContext": transactionContext})
// _, projectList, err := projectRepo.Find(map[string]interface{}{
// "endTime": time.Now(),
// "summaryState": domain.ProjectSummaryStateNo,
// "state": domain.ProjectStateEnable,
// }, "template")
// if err != nil {
// return fmt.Errorf("获取可用的项目数据,%s", err)
// }
// companyIdMap := map[int64]struct{}{}
// for _, v := range projectList {
// companyIdMap[v.CompanyId] = struct{}{}
// }
// var createdEvalationList []domain.SummaryEvaluation
// //获取可执行的项目
// for companyId := range companyIdMap {
// //获取员工数据,部门数据
// _, userList, err := userRepo.Find(map[string]interface{}{"companyId": companyId})
// if err != nil {
// log.Logger.Error("TaskSendSummaryEvaluation 获取员工数据:" + err.Error())
// continue
// }
// _, departmentList, err := departmentRepo.Find(map[string]interface{}{"companyId": companyId})
// if err != nil {
// log.Logger.Error("TaskSendSummaryEvaluation 获取部门数据:" + err.Error())
// continue
// }
// //转map
// userMap := map[int64]*domain.User{}
// for _, v := range userList {
// userMap[v.Id] = v
// }
// departmentMap := map[int64]*domain.Department{}
// for _, v := range departmentList {
// departmentMap[v.Id] = v
// }
// for _, v := range projectList {
// if v.CompanyId != companyId {
// continue
// }
// evalationList, err := sendSummaryEvaluation(v, userMap, departmentMap)
// if err != nil {
// log.Logger.Error("TaskSendSummaryEvaluation 下发评估任务:" + err.Error())
// continue
// }
// createdEvalationList = append(createdEvalationList, evalationList...)
// }
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return err
// }
// //添加待发送的短信通知
// err = sendSmsEvalation(createdEvalationList)
// return err
// }
... ... @@ -786,68 +786,70 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *doma
return nil
}
// 员工提交上级评估后
// 生成考核结果
func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(param *domain.SummaryEvaluation) error {
lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
err := lock.Lock()
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//没有上级评估
//直接进入考核结果阶段
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"targetUserId": param.TargetUser.UserId,
"typesList": []int{int(domain.EvaluationFinish)},
"cycleId": param.CycleId,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) > 0 {
//上级评估的结束时间
// evaluationList[0].BeginTime = param.EndTime
nowTime := time.Now()
if evaluationList[0].BeginTime.After(nowTime) {
evaluationList[0].BeginTime = nowTime
}
evaluationList[0].Status = domain.EvaluationCompleted
err = evaluationRepo.Save(evaluationList[0])
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
}
//添加确认绩效成绩提醒短信提醒
err = notify.AddNotifyConfirmEvaluationScore(evaluationList[0])
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
// // 员工提交上级评估后
// // 生成考核结果
// func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(param *domain.SummaryEvaluation) error {
// lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
// err := lock.Lock()
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
// }
// defer func() {
// lock.UnLock()
// }()
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// //没有上级评估
// //直接进入考核结果阶段
// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
// "targetUserId": param.TargetUser.UserId,
// "typesList": []int{int(domain.EvaluationFinish)},
// "cycleId": param.CycleId,
// "limit": 1,
// })
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if len(evaluationList) > 0 {
// //上级评估的结束时间
// // evaluationList[0].BeginTime = param.EndTime
// nowTime := time.Now()
// if evaluationList[0].BeginTime.After(nowTime) {
// evaluationList[0].BeginTime = nowTime
// }
// evaluationList[0].Status = domain.EvaluationCompleted
// err = evaluationRepo.Save(evaluationList[0])
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
// }
// //TODO 更新考核成绩
// //添加确认绩效成绩提醒短信提醒
// err = notify.AddNotifyConfirmEvaluationScore(evaluationList[0])
// if err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error())
// }
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// return nil
// }
// GetTargetUserCycleList
// 获取周期列表,被评估的周期列表
... ... @@ -1195,124 +1197,124 @@ func (srv *SummaryEvaluationService) GetEvaluationSuperForAdmin(param *command.Q
return &result, 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, "用户已经确认该周期的考核结果,不能再编辑!")
}
_, 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
}
// // 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, "用户已经确认该周期的考核结果,不能再编辑!")
// }
// _, 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
// }
// EditEvaluationSuperForAdmin 更新上级评估内容(超级管理员)
func (srv *SummaryEvaluationService) EditEvaluationSuperForAdmin(param *command.EditEvaluationValue) (interface{}, error) {
... ... @@ -1400,10 +1402,10 @@ func (srv *SummaryEvaluationService) EditEvaluationSuperForAdmin(param *command.
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.AfterCompletedEvaluationSuper(evaluationData)
if err != nil {
return nil, err
}
// err = srv.AfterCompletedEvaluationSuper(evaluationData)
// if err != nil {
// return nil, err
// }
itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
return map[string][]adapter.EvaluationItemAdapter{"EvaluationItems": itemValueAdapter}, nil
... ...
... ... @@ -115,39 +115,3 @@ func (itemValue *SummaryEvaluationValue) valueTypeScore(item *EvaluationItemUsed
}
return nil
}
// 填写综合自评
// func (itemValue *SummaryEvaluationValue) EvaluationSelfFillValue(item *EvaluationItemUsed, value string, remark string) error {
// itemValue.Remark = remark
// if item.Weight == 0 {
// //使用评级的形式
// err := itemValue.valueTypeRating(item, value)
// return err
// }
// //综合自评 评分的形式,特殊处理
// err := itemValue.valueTypeScoreEvaluationSelf(item, value)
// return err
// }
// func (itemValue *SummaryEvaluationValue) valueTypeScoreEvaluationSelf(item *EvaluationItemUsed, value string) error {
// if item.Weight <= 0 {
// return errors.New("评分方式错误")
// }
// value = strings.TrimSpace(value)
// itemValue.Value = value
// //处理空值
// if len(value) == 0 {
// itemValue.Score = "0"
// return nil
// }
// valueNumber, err := strconv.ParseFloat(value, 64)
// if err != nil {
// return fmt.Errorf("条目%d:%s-%s评分值异常", item.Id, item.Category, item.Name)
// }
// // 分数保留2位小数
// score := valueNumber * item.Weight
// itemValue.Score = fmt.Sprintf("%.2f", score)
// return nil
// }
... ...