作者 tangxvhui

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

@@ -35,6 +35,12 @@ func TaskSendSummaryEvaluationV2() error { @@ -35,6 +35,12 @@ func TaskSendSummaryEvaluationV2() error {
35 return nil 35 return nil
36 } 36 }
37 37
  38 +func dayEndTime(t time.Time) time.Time {
  39 + y, m, d := t.Local().Date()
  40 + t2 := time.Date(y, m, d, 23, 59, 59, 0, time.Local)
  41 + return t2
  42 +}
  43 +
38 // 获取周期 44 // 获取周期
39 func getPrepareEvaluationCycle() ([]*domain.EvaluationCycle, error) { 45 func getPrepareEvaluationCycle() ([]*domain.EvaluationCycle, error) {
40 transactionContext, err := factory.CreateTransactionContext(nil) 46 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -58,37 +64,6 @@ func getPrepareEvaluationCycle() ([]*domain.EvaluationCycle, error) { @@ -58,37 +64,6 @@ func getPrepareEvaluationCycle() ([]*domain.EvaluationCycle, error) {
58 return cycleList, nil 64 return cycleList, nil
59 } 65 }
60 66
61 -// 获取可用的项目  
62 -// func getPrepareSummaryEvaluation(cycleId int) ([]*domain.EvaluationProject, error) {  
63 -// transactionContext, err := factory.CreateTransactionContext(nil)  
64 -// if err != nil {  
65 -// return nil, err  
66 -// }  
67 -// if err := transactionContext.StartTransaction(); err != nil {  
68 -// return nil, err  
69 -// }  
70 -// defer func() {  
71 -// _ = transactionContext.RollbackTransaction()  
72 -// }()  
73 -// projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{  
74 -// "transactionContext": transactionContext,  
75 -// })  
76 -// // 获取项目数据总数  
77 -// _, projectList, err := projectRepo.Find(map[string]interface{}{  
78 -// "cycleId": cycleId,  
79 -// "summaryState": domain.ProjectSummaryStateNo,  
80 -// "state": domain.ProjectStateEnable,  
81 -// "limit": 200,  
82 -// }, "template")  
83 -// if err != nil {  
84 -// return nil, fmt.Errorf("获取可用的项目数据,%s", err)  
85 -// }  
86 -// if err := transactionContext.CommitTransaction(); err != nil {  
87 -// return nil, err  
88 -// }  
89 -// return projectList, nil  
90 -// }  
91 -  
92 // 按周期下发 综合评估任务 67 // 按周期下发 综合评估任务
93 func sendSummaryEvaluationByCycle(cycleParam *domain.EvaluationCycle) error { 68 func sendSummaryEvaluationByCycle(cycleParam *domain.EvaluationCycle) error {
94 transactionContext, err := factory.CreateTransactionContext(nil) 69 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -115,10 +90,14 @@ func sendSummaryEvaluationByCycle(cycleParam *domain.EvaluationCycle) error { @@ -115,10 +90,14 @@ func sendSummaryEvaluationByCycle(cycleParam *domain.EvaluationCycle) error {
115 if err != nil { 90 if err != nil {
116 return fmt.Errorf("获取可用的项目数据,%s", err) 91 return fmt.Errorf("获取可用的项目数据,%s", err)
117 } 92 }
  93 + permissionData, err := getPermission(cycleParam.CompanyId)
  94 + if err != nil {
  95 + return fmt.Errorf("获取公司的周期评估设置项,%s", err)
  96 + }
118 var newEvaluationList []domain.SummaryEvaluation 97 var newEvaluationList []domain.SummaryEvaluation
119 newPublisher := summaryEvaluationPublisher{} 98 newPublisher := summaryEvaluationPublisher{}
120 for _, val := range projectList { 99 for _, val := range projectList {
121 - evaluationList, err := newPublisher.sendSummaryEvaluationV2(transactionContext, val, cycleParam) 100 + evaluationList, err := newPublisher.sendSummaryEvaluationV2(transactionContext, val, cycleParam, *permissionData)
122 if err != nil { 101 if err != nil {
123 return fmt.Errorf("按项目下发综合评估任务数据,%s", err) 102 return fmt.Errorf("按项目下发综合评估任务数据,%s", err)
124 } 103 }
@@ -148,18 +127,10 @@ type summaryEvaluationPublisher struct { @@ -148,18 +127,10 @@ type summaryEvaluationPublisher struct {
148 127
149 func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2( 128 func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
150 transactionContext application.TransactionContext, 129 transactionContext application.TransactionContext,
151 - projectParam *domain.EvaluationProject, cycleData *domain.EvaluationCycle, 130 + projectParam *domain.EvaluationProject,
  131 + cycleData *domain.EvaluationCycle,
  132 + permissioData domain.Permission,
152 ) ([]domain.SummaryEvaluation, error) { 133 ) ([]domain.SummaryEvaluation, error) {
153 - // transactionContext, err := factory.CreateTransactionContext(nil)  
154 - // if err != nil {  
155 - // return err  
156 - // }  
157 - // if err := transactionContext.StartTransaction(); err != nil {  
158 - // return err  
159 - // }  
160 - // defer func() {  
161 - // _ = transactionContext.RollbackTransaction()  
162 - // }()  
163 userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) 134 userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
164 departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{"transactionContext": transactionContext}) 135 departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{"transactionContext": transactionContext})
165 evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext}) 136 evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
@@ -193,16 +164,31 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2( @@ -193,16 +164,31 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
193 if cycleData.TimeEnd == nil { 164 if cycleData.TimeEnd == nil {
194 return nil, fmt.Errorf("周期%d:%s 结束时间错误", cycleData.Id, cycleData.Name) 165 return nil, fmt.Errorf("周期%d:%s 结束时间错误", cycleData.Id, cycleData.Name)
195 } 166 }
  167 +
196 //自评的时间范围 168 //自评的时间范围
197 - beginTimeSelf := *cycleData.TimeEnd 169 + beginTimeSelf := *cycleData.TimeEnd //
  170 + beginDay := dayEndTime(beginTimeSelf)
198 //修改 周期结束时间那天的第二天开始计算 171 //修改 周期结束时间那天的第二天开始计算
199 - endTimeSelf := dayZeroTime(beginTimeSelf).Add(4*24*time.Hour - time.Second) 172 + endTimeSelf := beginDay.Add(time.Duration(permissioData.CycleDeadLine.AssessmentSelf.Hour) * time.Hour).
  173 + Add(time.Duration(permissioData.CycleDeadLine.AssessmentSelf.Minute) * time.Minute)
200 //人资、360评估的时间范围 174 //人资、360评估的时间范围
201 beginTime360 := endTimeSelf 175 beginTime360 := endTimeSelf
202 - endTime360 := endTimeSelf.Add(2 * 24 * time.Hour) 176 + endTime360 := beginDay.Add(time.Duration(permissioData.CycleDeadLine.AssessmentAll.Hour) * time.Hour).
  177 + Add(time.Duration(permissioData.CycleDeadLine.AssessmentAll.Minute) * time.Minute)
  178 + //人资评估的时间范围
  179 + beginTimeHr := endTimeSelf
  180 + endTimeHr := beginDay.Add(time.Duration(permissioData.CycleDeadLine.AssessmentHr.Hour) * time.Hour).
  181 + Add(time.Duration(permissioData.CycleDeadLine.AssessmentHr.Minute) * time.Minute)
  182 +
203 //上级评估的是时间范围 183 //上级评估的是时间范围
204 - beginTimeSuper := endTime360  
205 - endTimeSuper := endTime360.Add(2 * 24 * time.Hour) 184 + beginTimeSuper := endTimeHr
  185 + endTimeSuper := beginDay.Add(time.Duration(permissioData.CycleDeadLine.AssessmentSuperior.Hour) * time.Hour).
  186 + Add(time.Duration(permissioData.CycleDeadLine.AssessmentSuperior.Minute) * time.Minute)
  187 +
  188 + //考核结果的时间范围
  189 + beginTimeFinish := endTimeSuper
  190 + endTimeFinish := beginDay.Add(time.Duration(permissioData.CycleDeadLine.ViewMyPerf.Hour) * time.Hour).
  191 + Add(time.Duration(permissioData.CycleDeadLine.ViewMyPerf.Minute) * time.Minute)
206 // 创建周期评估任务 192 // 创建周期评估任务
207 var newEvaluationList []domain.SummaryEvaluation 193 var newEvaluationList []domain.SummaryEvaluation
208 evaluationTemp := domain.SummaryEvaluation{ 194 evaluationTemp := domain.SummaryEvaluation{
@@ -287,8 +273,8 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2( @@ -287,8 +273,8 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
287 { 273 {
288 if hrbpExist { 274 if hrbpExist {
289 //处理人资评估 275 //处理人资评估
290 - evaluationTemp.BeginTime = beginTime360  
291 - evaluationTemp.EndTime = endTime360 276 + evaluationTemp.BeginTime = beginTimeHr
  277 + evaluationTemp.EndTime = endTimeHr
292 evaluationTemp.Executor = domain.StaffDesc{} 278 evaluationTemp.Executor = domain.StaffDesc{}
293 evaluationTemp.Types = domain.EvaluationHrbp 279 evaluationTemp.Types = domain.EvaluationHrbp
294 newEvaluationList = append(newEvaluationList, evaluationTemp) 280 newEvaluationList = append(newEvaluationList, evaluationTemp)
@@ -314,8 +300,8 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2( @@ -314,8 +300,8 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
314 { 300 {
315 evaluationTemp.Types = domain.EvaluationFinish 301 evaluationTemp.Types = domain.EvaluationFinish
316 evaluationTemp.Executor = domain.StaffDesc{} 302 evaluationTemp.Executor = domain.StaffDesc{}
317 - evaluationTemp.BeginTime = endTimeSuper  
318 - evaluationTemp.EndTime = endTimeSuper.Add(2 * 24 * time.Hour) 303 + evaluationTemp.BeginTime = beginTimeFinish
  304 + evaluationTemp.EndTime = endTimeFinish
319 newEvaluationList = append(newEvaluationList, evaluationTemp) 305 newEvaluationList = append(newEvaluationList, evaluationTemp)
320 } 306 }
321 } 307 }
@@ -332,30 +318,9 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2( @@ -332,30 +318,9 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
332 if err != nil { 318 if err != nil {
333 return nil, fmt.Errorf("保存项目状态%s", err) 319 return nil, fmt.Errorf("保存项目状态%s", err)
334 } 320 }
335 - // if err := transactionContext.CommitTransaction(); err != nil {  
336 - // return err  
337 - // }  
338 return newEvaluationList, nil 321 return newEvaluationList, nil
339 } 322 }
340 323
341 -// 获取周期设置数据  
342 -// func (se *summaryEvaluationPublisher) getCycleData(cycleRepo domain.EvaluationCycleRepository, cycleId int64) (*domain.EvaluationCycle, error) {  
343 -// var cycleData *domain.EvaluationCycle  
344 -// if val, ok := se.cycleCache[cycleId]; ok {  
345 -// cycleData = val  
346 -// } else {  
347 -// _, cycleList, err := cycleRepo.Find(map[string]interface{}{"id": cycleId})  
348 -// if err != nil {  
349 -// return nil, err  
350 -// }  
351 -// if len(cycleList) == 0 {  
352 -// return nil, nil  
353 -// }  
354 -// cycleData = cycleList[0]  
355 -// }  
356 -// return cycleData, nil  
357 -// }  
358 -  
359 // 获取用户数据 324 // 获取用户数据
360 func (se *summaryEvaluationPublisher) getUserData(userRepo domain.UserRepository, userId int64) (*domain.User, error) { 325 func (se *summaryEvaluationPublisher) getUserData(userRepo domain.UserRepository, userId int64) (*domain.User, error) {
361 if userId == 0 { 326 if userId == 0 {