作者 tangxvhui

更新周期评估的截止时间范围

... ... @@ -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 {
... ...