作者 郑周

Merge remote-tracking branch 'origin/1.2.4' into 1.2.4

... ... @@ -17,6 +17,7 @@ import (
func main() {
startNodeTask()
startSummaryEvaluation()
startConfirmEvaluationScore()
go notify.RunTaskSmsNotify()
go consumer.Run()
web.Run()
... ... @@ -63,3 +64,23 @@ func startSummaryEvaluation() {
}
}()
}
// 定时自动确认周期评估考核结果
func startConfirmEvaluationScore() {
go func() {
var duration time.Duration
if constant.Env == "prd" {
duration = time.Minute * 5
} else {
duration = time.Minute * 1
}
timer := time.NewTimer(duration)
for {
<-timer.C
if err := serviceSummary.TaskConfirmScore(); err != nil {
log.Logger.Error(err.Error())
}
timer.Reset(duration) // 重置定时
}
}()
}
... ...
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/domain"
"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)
}()
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 {
permissionData, err := getPermission(val.CompanyId)
if err != nil {
log.Logger.Error(fmt.Sprintf("获取公司的权限配置失败%s", err.Error()))
}
if permissionData.OptConfirmPerf != domain.PermissionOn {
continue
}
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()))
}
}
return nil
}
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
}
... ...
... ... @@ -35,6 +35,12 @@ func TaskSendSummaryEvaluationV2() error {
return nil
}
func dayEndTime(t time.Time) time.Time {
y, m, d := t.Local().Date()
t2 := time.Date(y, m, d, 23, 59, 59, 0, time.Local)
return t2
}
// 获取周期
func getPrepareEvaluationCycle() ([]*domain.EvaluationCycle, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -58,37 +64,6 @@ func getPrepareEvaluationCycle() ([]*domain.EvaluationCycle, error) {
return cycleList, nil
}
// 获取可用的项目
// func getPrepareSummaryEvaluation(cycleId int) ([]*domain.EvaluationProject, 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()
// }()
// projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// // 获取项目数据总数
// _, projectList, err := projectRepo.Find(map[string]interface{}{
// "cycleId": cycleId,
// "summaryState": domain.ProjectSummaryStateNo,
// "state": domain.ProjectStateEnable,
// "limit": 200,
// }, "template")
// if err != nil {
// return nil, fmt.Errorf("获取可用的项目数据,%s", err)
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, err
// }
// return projectList, nil
// }
// 按周期下发 综合评估任务
func sendSummaryEvaluationByCycle(cycleParam *domain.EvaluationCycle) error {
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -115,10 +90,14 @@ func sendSummaryEvaluationByCycle(cycleParam *domain.EvaluationCycle) error {
if err != nil {
return fmt.Errorf("获取可用的项目数据,%s", err)
}
permissionData, err := getPermission(cycleParam.CompanyId)
if err != nil {
return fmt.Errorf("获取公司的周期评估设置项,%s", err)
}
var newEvaluationList []domain.SummaryEvaluation
newPublisher := summaryEvaluationPublisher{}
for _, val := range projectList {
evaluationList, err := newPublisher.sendSummaryEvaluationV2(transactionContext, val, cycleParam)
evaluationList, err := newPublisher.sendSummaryEvaluationV2(transactionContext, val, cycleParam, *permissionData)
if err != nil {
return fmt.Errorf("按项目下发综合评估任务数据,%s", err)
}
... ... @@ -148,18 +127,10 @@ type summaryEvaluationPublisher struct {
func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
transactionContext application.TransactionContext,
projectParam *domain.EvaluationProject, cycleData *domain.EvaluationCycle,
projectParam *domain.EvaluationProject,
cycleData *domain.EvaluationCycle,
permissioData domain.Permission,
) ([]domain.SummaryEvaluation, error) {
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return err
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return err
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
... ... @@ -193,16 +164,31 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
if cycleData.TimeEnd == nil {
return nil, fmt.Errorf("周期%d:%s 结束时间错误", cycleData.Id, cycleData.Name)
}
//自评的时间范围
beginTimeSelf := *cycleData.TimeEnd
beginTimeSelf := *cycleData.TimeEnd //
beginDay := dayEndTime(beginTimeSelf)
//修改 周期结束时间那天的第二天开始计算
endTimeSelf := dayZeroTime(beginTimeSelf).Add(4*24*time.Hour - time.Second)
endTimeSelf := beginDay.Add(time.Duration(permissioData.CycleDeadLine.AssessmentSelf.Hour) * time.Hour).
Add(time.Duration(permissioData.CycleDeadLine.AssessmentSelf.Minute) * time.Minute)
//人资、360评估的时间范围
beginTime360 := endTimeSelf
endTime360 := endTimeSelf.Add(2 * 24 * time.Hour)
endTime360 := beginDay.Add(time.Duration(permissioData.CycleDeadLine.AssessmentAll.Hour) * time.Hour).
Add(time.Duration(permissioData.CycleDeadLine.AssessmentAll.Minute) * time.Minute)
//人资评估的时间范围
beginTimeHr := endTimeSelf
endTimeHr := beginDay.Add(time.Duration(permissioData.CycleDeadLine.AssessmentHr.Hour) * time.Hour).
Add(time.Duration(permissioData.CycleDeadLine.AssessmentHr.Minute) * time.Minute)
//上级评估的是时间范围
beginTimeSuper := endTime360
endTimeSuper := endTime360.Add(2 * 24 * time.Hour)
beginTimeSuper := endTimeHr
endTimeSuper := beginDay.Add(time.Duration(permissioData.CycleDeadLine.AssessmentSuperior.Hour) * time.Hour).
Add(time.Duration(permissioData.CycleDeadLine.AssessmentSuperior.Minute) * time.Minute)
//考核结果的时间范围
beginTimeFinish := endTimeSuper
endTimeFinish := beginDay.Add(time.Duration(permissioData.CycleDeadLine.ViewMyPerf.Hour) * time.Hour).
Add(time.Duration(permissioData.CycleDeadLine.ViewMyPerf.Minute) * time.Minute)
// 创建周期评估任务
var newEvaluationList []domain.SummaryEvaluation
evaluationTemp := domain.SummaryEvaluation{
... ... @@ -287,8 +273,8 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
{
if hrbpExist {
//处理人资评估
evaluationTemp.BeginTime = beginTime360
evaluationTemp.EndTime = endTime360
evaluationTemp.BeginTime = beginTimeHr
evaluationTemp.EndTime = endTimeHr
evaluationTemp.Executor = domain.StaffDesc{}
evaluationTemp.Types = domain.EvaluationHrbp
newEvaluationList = append(newEvaluationList, evaluationTemp)
... ... @@ -314,8 +300,8 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
{
evaluationTemp.Types = domain.EvaluationFinish
evaluationTemp.Executor = domain.StaffDesc{}
evaluationTemp.BeginTime = endTimeSuper
evaluationTemp.EndTime = endTimeSuper.Add(2 * 24 * time.Hour)
evaluationTemp.BeginTime = beginTimeFinish
evaluationTemp.EndTime = endTimeFinish
newEvaluationList = append(newEvaluationList, evaluationTemp)
}
}
... ... @@ -332,30 +318,9 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
if err != nil {
return nil, fmt.Errorf("保存项目状态%s", err)
}
// if err := transactionContext.CommitTransaction(); err != nil {
// return err
// }
return newEvaluationList, nil
}
// 获取周期设置数据
// func (se *summaryEvaluationPublisher) getCycleData(cycleRepo domain.EvaluationCycleRepository, cycleId int64) (*domain.EvaluationCycle, error) {
// var cycleData *domain.EvaluationCycle
// if val, ok := se.cycleCache[cycleId]; ok {
// cycleData = val
// } else {
// _, cycleList, err := cycleRepo.Find(map[string]interface{}{"id": cycleId})
// if err != nil {
// return nil, err
// }
// if len(cycleList) == 0 {
// return nil, nil
// }
// cycleData = cycleList[0]
// }
// return cycleData, nil
// }
// 获取用户数据
func (se *summaryEvaluationPublisher) getUserData(userRepo domain.UserRepository, userId int64) (*domain.User, error) {
if userId == 0 {
... ...
... ... @@ -1015,11 +1015,15 @@ func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEval
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
permissionRepository := factory.CreatePermissionRepository(map[string]interface{}{"transactionContext": transactionContext})
// permissionRepository := factory.CreatePermissionRepository(map[string]interface{}{"transactionContext": transactionContext})
// 获取权限配置
_, permissionList, err := permissionRepository.Find(map[string]interface{}{"companyId": param.CompanyId})
// _, permissionList, err := permissionRepository.Find(map[string]interface{}{"companyId": param.CompanyId})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
permissinData, err := getPermission(int64(param.CompanyId))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
return nil, err
}
evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{
"id": param.SummaryEvaluationId,
... ... @@ -1078,17 +1082,15 @@ func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEval
//组合 评估填写的值和评估项
itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
for i, v := range itemValuesAdapter {
if len(permissionList) > 0 {
if permissionList[0].OptEvalScore == domain.PermissionOff &&
if permissinData.OptEvalScore == domain.PermissionOff &&
v.EvaluatorId > 0 {
itemValuesAdapter[i].ForbidEdit = true
}
if permissionList[0].OptHrScore == domain.PermissionOff &&
if permissinData.OptHrScore == domain.PermissionOff &&
v.EvaluatorId < 0 {
itemValuesAdapter[i].ForbidEdit = true
}
}
}
result := adapter.EvaluationInfoSuperAdapter{
EvaluationBaseAdapter: evaluationBase,
// LevelCount: codeList,
... ... @@ -1214,16 +1216,19 @@ func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionC
"transactionContext": transactionContext,
})
permissionRepository := factory.CreatePermissionRepository(map[string]interface{}{"transactionContext": transactionContext})
// 获取权限配置
_, permissionList, err := permissionRepository.Find(map[string]interface{}{"companyId": evaluationData.CompanyId})
// permissionRepository := factory.CreatePermissionRepository(map[string]interface{}{"transactionContext": transactionContext})
// // 获取权限配置
// _, permissionList, err := permissionRepository.Find(map[string]interface{}{"companyId": evaluationData.CompanyId})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if len(permissionList) == 0 {
// return nil, nil
// }
permissionData, err := getPermission(int64(evaluationData.CompanyId))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(permissionList) == 0 {
return nil, nil
}
permissionData := permissionList[0]
if permissionData.OptEvalScore == domain.PermissionOn && permissionData.OptHrScore == domain.PermissionOn {
return nil, nil
}
... ...
package service
import (
permissionSrv "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/permission"
permissionCmd "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/permission/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
func getPermission(companyId int64) (*domain.Permission, error) {
srv := &permissionSrv.PermissionService{}
permissionData, err := srv.Get(&permissionCmd.GetPermissionCommand{
CompanyId: companyId,
})
if err != nil {
return nil, err
}
return permissionData, nil
}
... ...
... ... @@ -151,3 +151,29 @@ func (d *SummaryEvaluationDao) UpdateBeginTime(ids []int, beginTime time.Time) e
_, err := tx.Exec(sqlStr, condition...)
return err
}
type SummaryEvaluationData1 struct {
SummaryEvaluationId int `pg:"summary_evaluation_id"`
TargetUserId string `pg:"target_user_id"`
CompanyId int64 `pg:"company_id"`
}
// 查询周期考核结果
// 条件:已过截止时间,并且还没确认周期考核结果
func (d *SummaryEvaluationDao) ListEvaluationFinishNoResult() ([]SummaryEvaluationData1, error) {
sqlStr := `select
summary_evaluation.id as summary_evaluation_id,
summary_evaluation.target_user ->>'userName' as target_user_name,
summary_evaluation.company_id
from summary_evaluation
where 1=1
and summary_evaluation."types" = 5
and summary_evaluation.status ='completed'
and summary_evaluation.check_result ='uncompleted'
and summary_evaluation.end_time <=now()
`
result := []SummaryEvaluationData1{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr)
return result, err
}
... ...