作者 Your Name

更新

@@ -611,7 +611,7 @@ func (srv StaffAssessServeice) GetAssessInviteUser(param *query.GetAssessInviteU @@ -611,7 +611,7 @@ func (srv StaffAssessServeice) GetAssessInviteUser(param *query.GetAssessInviteU
611 } 611 }
612 612
613 // 保存某个员工360邀请的人员 613 // 保存某个员工360邀请的人员
614 -func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInvite) (*adapter.AssessInviteUserResp, error) { 614 +func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInvite) (map[string]interface{}, error) {
615 inviteSameSuperId := []int{} 615 inviteSameSuperId := []int{}
616 InviteDiffSuperId := []int{} 616 InviteDiffSuperId := []int{}
617 for _, v := range param.InviteDiffSuper { 617 for _, v := range param.InviteDiffSuper {
@@ -659,6 +659,19 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv @@ -659,6 +659,19 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv
659 return nil, application.ThrowError(application.ARG_ERROR, "获取评估任务"+err.Error()) 659 return nil, application.ThrowError(application.ARG_ERROR, "获取评估任务"+err.Error())
660 } 660 }
661 661
  662 + //获取邀请评估的节点
  663 + var inviteNode *domain.AssessTaskStep
  664 + for _, v := range assessTaskData.StepList {
  665 + if v.LinkNodeType == domain.LinkNodeAllAssessment {
  666 + cp := v
  667 + inviteNode = &cp
  668 + break
  669 + }
  670 + }
  671 + if inviteNode == nil {
  672 + return nil, application.ThrowError(application.ARG_ERROR, "评估任务没有邀请评估的环节")
  673 + }
  674 +
662 targetUser, err := userRepo.FindOne(map[string]interface{}{ 675 targetUser, err := userRepo.FindOne(map[string]interface{}{
663 "id": param.TargetUserId, 676 "id": param.TargetUserId,
664 }) 677 })
@@ -725,39 +738,94 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv @@ -725,39 +738,94 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv
725 return nil, application.ThrowError(application.ARG_ERROR, "获取员工邀请的人"+err.Error()) 738 return nil, application.ThrowError(application.ARG_ERROR, "获取员工邀请的人"+err.Error())
726 } 739 }
727 //比对新旧数据 740 //比对新旧数据
728 -  
729 - _ = assessList  
730 - _ = targetUser  
731 - _ = inviteSameSuper  
732 - _ = inviteDiffSuper  
733 - _ = targetUserDepartment  
734 - 741 + nowTime := time.Now()
  742 + assessMap := map[string]*domain.StaffAssess{}
  743 + for _, v := range assessList {
  744 + //假设为删除
  745 + v.DeletedAt = &nowTime
  746 + key := fmt.Sprintf("%s%d", string(v.Types), v.Executor.UserId)
  747 + assessMap[key] = v
  748 + }
  749 + newAssessList := []*domain.StaffAssess{}
  750 + //邀请同上级的员工
  751 + for _, v := range inviteSameSuper {
  752 + key := fmt.Sprintf("%s%d", string(domain.AssessInviteSameSuper), v.UserId)
  753 + if _, ok := assessMap[key]; ok {
  754 + assessMap[key].DeletedAt = nil
  755 + } else {
  756 + newAssessList = append(newAssessList, &domain.StaffAssess{
  757 + Id: 0,
  758 + CompanyId: assessTaskData.CompanyId,
  759 + EvaluationProjectId: assessTaskData.EvaluationProjectId,
  760 + EvaluationProjectName: assessTaskData.EvaluationProjectName,
  761 + CycleId: assessTaskData.CycleId,
  762 + CycleName: assessTaskData.CycleName,
  763 + StaffAssessTaskId: assessTaskData.Id,
  764 + TargetUser: domain.StaffDesc{
  765 + UserId: int(targetUser.Id),
  766 + Account: targetUser.Account,
  767 + UserName: targetUser.Name,
  768 + },
  769 + TargetDepartment: targetUserDepartment,
  770 + Executor: v,
  771 + Types: domain.AssessInviteSameSuper,
  772 + LinkNodeId: inviteNode.LinkNodeId,
  773 + LinkNodeName: inviteNode.LinkNodeName,
  774 + Status: domain.StaffAssessUncompleted,
  775 + BeginTime: inviteNode.BeginTime,
  776 + EndTime: inviteNode.EndTime,
  777 + CreatedAt: nowTime,
  778 + UpdatedAt: nowTime,
  779 + DeletedAt: nil,
  780 + })
  781 + }
  782 + }
  783 + for _, v := range inviteDiffSuper {
  784 + key := fmt.Sprintf("%s%d", string(domain.AssessInviteDiffSuper), v.UserId)
  785 + if _, ok := assessMap[key]; ok {
  786 + assessMap[key].DeletedAt = nil
  787 + } else {
  788 + newAssessList = append(newAssessList, &domain.StaffAssess{
  789 + Id: 0,
  790 + CompanyId: assessTaskData.CompanyId,
  791 + EvaluationProjectId: assessTaskData.EvaluationProjectId,
  792 + EvaluationProjectName: assessTaskData.EvaluationProjectName,
  793 + CycleId: assessTaskData.CycleId,
  794 + CycleName: assessTaskData.CycleName,
  795 + StaffAssessTaskId: assessTaskData.Id,
  796 + TargetUser: domain.StaffDesc{
  797 + UserId: int(targetUser.Id),
  798 + Account: targetUser.Account,
  799 + UserName: targetUser.Name,
  800 + },
  801 + TargetDepartment: targetUserDepartment,
  802 + Executor: v,
  803 + Types: domain.AssessInviteDiffSuper,
  804 + LinkNodeId: inviteNode.LinkNodeId,
  805 + LinkNodeName: inviteNode.LinkNodeName,
  806 + Status: domain.StaffAssessUncompleted,
  807 + BeginTime: inviteNode.BeginTime,
  808 + EndTime: inviteNode.EndTime,
  809 + CreatedAt: nowTime,
  810 + UpdatedAt: nowTime,
  811 + DeletedAt: nil,
  812 + })
  813 + }
  814 + }
  815 + assessList = append(assessList, newAssessList...)
  816 + for i := range assessList {
  817 + _, err = assessReps.Save(assessList[i])
  818 + if err != nil {
  819 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存员工邀请评估"+err.Error())
  820 + }
  821 + }
735 if err := transactionContext.CommitTransaction(); err != nil { 822 if err := transactionContext.CommitTransaction(); err != nil {
736 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 823 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
737 } 824 }
738 -  
739 - result := adapter.AssessInviteUserResp{  
740 - AssessTaskId: assessTaskData.Id,  
741 - }  
742 - // for _, v := range assessTaskData.StepList {  
743 - // if v.LinkNodeType != domain.LinkNodeAllInvite {  
744 - // continue  
745 - // }  
746 - // result.LinkNodeId = v.LinkNodeId  
747 - // result.LinkNodeName = v.LinkNodeName  
748 - // result.BeginTime = v.BeginTime.Local().Format("2006-01-02 15:04:05")  
749 - // result.EndTime = v.EndTime.Local().Format("2006-01-02 15:04:05")  
750 - // break  
751 - // }  
752 - // for _, v := range assessList {  
753 - // if v.Types == domain.AssessInviteDiffSuper {  
754 - // result.InviteDiffSuper = append(result.InviteDiffSuper, v.Executor)  
755 - // }  
756 - // if v.Types == domain.AssessInviteSameSuper {  
757 - // result.InviteSameSuper = append(result.InviteDiffSuper, v.Executor)  
758 - // }  
759 - // }  
760 - return &result, nil 825 + result := map[string]interface{}{
  826 + "assessTaskId": assessTaskData.Id,
  827 + }
  828 + return result, nil
761 } 829 }
762 830
763 // 获取员工自评的评估内容详情 831 // 获取员工自评的评估内容详情