|
|
package service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
"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/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
|
|
|
)
|
|
|
|
|
|
// 定时自动确认周期评估考核结果
|
|
|
func TaskConfirmScore() error {
|
|
|
nowTime := time.Now()
|
|
|
defer func() {
|
|
|
str := fmt.Sprintf("自动确认周期评估考核结果耗时%.2f s", time.Since(nowTime).Seconds())
|
|
|
log.Logger.Info(str)
|
|
|
}()
|
|
|
for {
|
|
|
evaluationList, err := catchEvaluation()
|
|
|
if err != nil {
|
|
|
log.Logger.Error(fmt.Sprintf("获取周期考核结果%s", err.Error()))
|
|
|
}
|
|
|
if len(evaluationList) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
evluationSrv := NewSummaryEvaluationService()
|
|
|
for _, val := range evaluationList {
|
|
|
targetUserId, err := strconv.Atoi(val.TargetUserId)
|
|
|
if err != nil {
|
|
|
log.Logger.Error(fmt.Sprintf("获取员工id%s", err))
|
|
|
continue
|
|
|
}
|
|
|
err = evluationSrv.ConfirmScoreEvaluation(&command.ConfirmScore{
|
|
|
SummaryEvaluationId: val.SummaryEvaluationId,
|
|
|
UserId: targetUserId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
log.Logger.Error(fmt.Sprintf("确认周期考核结果%s", err.Error()))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func catchEvaluation() ([]dao.SummaryEvaluationData1, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
evaluationList, err := evaluationDao.ListEvaluationFinishNoResult()
|
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("获取综合评估数据%s", err)
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
return evaluationList, nil
|
|
|
} |
...
|
...
|
|