作者 tangxvhui

调整 每日评估的下发逻辑

@@ -359,7 +359,10 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application. @@ -359,7 +359,10 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application.
359 stepSelfTemp.LinkNodeId = v.LinkNodeId 359 stepSelfTemp.LinkNodeId = v.LinkNodeId
360 stepSelfTemp.LinkNodeName = v.LinkNodeName 360 stepSelfTemp.LinkNodeName = v.LinkNodeName
361 stepSelfTemp.Types = domain.AssessSelf 361 stepSelfTemp.Types = domain.AssessSelf
362 - assessListTemp := srv.createStaffAssessSelf(stepSelfTemp, userList, userDepartmentMap) 362 + assessListTemp, err := srv.createStaffAssessSelf(transactionContext, stepSelfTemp, userList, userDepartmentMap)
  363 + if err != nil {
  364 + return nil, err
  365 + }
363 assessList = append(assessList, assessListTemp...) 366 assessList = append(assessList, assessListTemp...)
364 } 367 }
365 if v.LinkNodeType == domain.LinkNodeSuperiorAssessment { 368 if v.LinkNodeType == domain.LinkNodeSuperiorAssessment {
@@ -380,10 +383,28 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application. @@ -380,10 +383,28 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application.
380 } 383 }
381 384
382 // 构建员工自评 385 // 构建员工自评
383 -func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAssess,  
384 - userList []*domain.User, userDepartmentMap map[int64][]*domain.Department) []domain.StaffAssess {  
385 - result := []domain.StaffAssess{}  
386 - for _, usr := range userList { 386 +func (srv StaffAssessServeice) createStaffAssessSelf(
  387 + transactionContext application.TransactionContext,
  388 + assessTemp domain.StaffAssess,
  389 + userList []*domain.User,
  390 + userDepartmentMap map[int64][]*domain.Department) ([]domain.StaffAssess, error) {
  391 + assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
  392 + "transactionContext": transactionContext,
  393 + })
  394 + beginDay := assessTemp.BeginTime.Format("2006-01-02")
  395 + _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSelf})
  396 + if err != nil {
  397 + return nil, err
  398 + }
  399 + userMapReal := map[int]*domain.User{}
  400 + for _, val := range userList {
  401 + userMapReal[int(val.Id)] = val
  402 + }
  403 + for _, val := range assessListOld {
  404 + delete(userMapReal, val.TargetUser.UserId)
  405 + }
  406 + assessListNew := []domain.StaffAssess{}
  407 + for _, usr := range userMapReal {
387 assessTemp.TargetUser = domain.StaffDesc{ 408 assessTemp.TargetUser = domain.StaffDesc{
388 UserId: int(usr.Id), 409 UserId: int(usr.Id),
389 Account: usr.Account, 410 Account: usr.Account,
@@ -402,9 +423,9 @@ func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAsse @@ -402,9 +423,9 @@ func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAsse
402 }) 423 })
403 } 424 }
404 } 425 }
405 - result = append(result, assessTemp) 426 + assessListNew = append(assessListNew, assessTemp)
406 } 427 }
407 - return result 428 + return assessListNew, nil
408 } 429 }
409 430
410 // 构建员工的上级评估 431 // 构建员工的上级评估
@@ -413,8 +434,24 @@ func (srv StaffAssessServeice) createStaffAssessSupper( @@ -413,8 +434,24 @@ func (srv StaffAssessServeice) createStaffAssessSupper(
413 assessTemp domain.StaffAssess, 434 assessTemp domain.StaffAssess,
414 userList []*domain.User, userDepartmentMap map[int64][]*domain.Department, 435 userList []*domain.User, userDepartmentMap map[int64][]*domain.Department,
415 ) ([]domain.StaffAssess, error) { 436 ) ([]domain.StaffAssess, error) {
416 - var assessList []domain.StaffAssess  
417 - for _, v := range userList { 437 + assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
  438 + "transactionContext": transactionContext,
  439 + })
  440 + beginDay := assessTemp.BeginTime.Format("2006-01-02")
  441 + _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSuper})
  442 + if err != nil {
  443 + return nil, err
  444 + }
  445 + userMapReal := map[int]*domain.User{}
  446 + for _, val := range userList {
  447 + userMapReal[int(val.Id)] = val
  448 + }
  449 + for _, val := range assessListOld {
  450 + delete(userMapReal, val.TargetUser.UserId)
  451 + }
  452 +
  453 + var assessListNew []domain.StaffAssess
  454 + for _, v := range userMapReal {
418 //获取上级 455 //获取上级
419 chargeUserList, err := srv.getStaffSuper(transactionContext, *v) 456 chargeUserList, err := srv.getStaffSuper(transactionContext, *v)
420 if err != nil { 457 if err != nil {
@@ -444,11 +481,11 @@ func (srv StaffAssessServeice) createStaffAssessSupper( @@ -444,11 +481,11 @@ func (srv StaffAssessServeice) createStaffAssessSupper(
444 } 481 }
445 } 482 }
446 assessTemp.TargetDepartment = targetDepartment 483 assessTemp.TargetDepartment = targetDepartment
447 - assessList = append(assessList, assessTemp) 484 + assessListNew = append(assessListNew, assessTemp)
448 } 485 }
449 486
450 } 487 }
451 - return assessList, nil 488 + return assessListNew, nil
452 } 489 }
453 490
454 // 获取某个员工360评估邀请的人员 491 // 获取某个员工360评估邀请的人员