service_v2.go 34.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986
package service

import (
	"fmt"
	"sort"
	"strconv"

	"github.com/linmadan/egglib-go/core/application"
	"github.com/linmadan/egglib-go/utils/tool_funs"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
	"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 (srv StaffAssessServeice) SearchAssessTaskMeV2(param *query.SearchAssessMeQuery) (map[string]interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()

	staffAssessDao := dao.NewStaffAssessDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	var limit int = 360
	var offset int = 0
	if param.PageSize > 0 {
		limit = param.PageSize
	}
	offset = (param.PageNumber - 1) * param.PageSize

	assessCycleList, cnt, err := staffAssessDao.SearchExecutorAssessBeforeNow(param.UserId, param.CompanyId, limit, offset)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询评估周期"+err.Error())
	}
	assessCycleList2, err := staffAssessDao.SearchExecutorAssessAfterNow(param.UserId, param.CompanyId)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询评估周期"+err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	listData := make([]adapter.AssessCycleDayResp, 0, len(assessCycleList))

	var temp adapter.AssessCycleDayResp
	for _, v := range assessCycleList2 {
		temp = adapter.AssessCycleDayResp{
			CycleId:   v.CycleId,
			CycleName: v.CycleName,
			BeginDay:  v.BeginDay,
			BeginTime: v.BeginTime,
			EndTime:   v.EndTime,
		}
		listData = append(listData, temp)
	}
	for _, v := range assessCycleList {
		temp = adapter.AssessCycleDayResp{
			CycleId:   v.CycleId,
			CycleName: v.CycleName,
			BeginDay:  v.BeginDay,
			BeginTime: v.BeginTime,
			EndTime:   v.EndTime,
		}
		listData = append(listData, temp)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
}

// 获取我的项目周期进度描述
func (srv StaffAssessServeice) AssessTaskDescV2(param *query.AssessTaskDescV2Query) (*adapter.AssessCycleDescResp, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	// 获取评估任务
	staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取个人参与的评估流程
	staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})

	_, assessTaskList, err := staffAssessTaskRepo.Find(map[string]interface{}{
		"beginDay":  param.BeginDay,
		"cycleId":   param.CycleId,
		"companyId": param.CompanyId,
		"limit":     1,
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "评估任务不存在,"+err.Error())
	}
	if len(assessTaskList) == 0 {
		return &adapter.AssessCycleDescResp{}, nil
	}
	assessTaskDataAny := assessTaskList[0]
	//返回的数据结果
	result := adapter.AssessCycleDescResp{
		CycleId:   int(assessTaskDataAny.CycleId),
		CycleName: assessTaskDataAny.CycleName,
		BeginDay:  assessTaskDataAny.BeginDay,
		StepList:  []adapter.AssessTaskStep{},
	}

	for _, v := range assessTaskDataAny.StepList {
		stepItem := adapter.AssessTaskStep{
			SortBy:       v.SortBy,
			LinkNodeName: v.LinkNodeName,
			LinkNodeId:   v.LinkNodeId,
			BeginTime:    v.BeginTime.Local().Format("2006-01-02 15:04:05"),
			EndTime:      v.EndTime.Local().Format("2006-01-02 15:04:05"),
			LinkNodeType: v.LinkNodeType,
			Desc:         fmt.Sprintf("截止日期:%s", v.EndTime.Local().Format("2006-01-02 15:04:05")),
			Status:       "",
		}
		switch v.LinkNodeType {
		case domain.LinkNodeSelfAssessment:
			//个人自评完成情况
			_, assessSelfData, err := staffAssessRepo.Find(map[string]interface{}{
				"cycleId":    assessTaskDataAny.CycleId,
				"beginDay":   assessTaskDataAny.BeginDay,
				"executorId": param.UserId, //我作为执行人
				"typesList":  []string{string(domain.AssessSelf)},
			})
			if err != nil {
				return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
			}
			if len(assessSelfData) > 0 {
				stepItem.Status = string(assessSelfData[0].Status)
			}
			stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
		case domain.LinkNodeAllInvite:
			//邀请别人评估自己
			_, assessInviteData, err := staffAssessRepo.Find(map[string]interface{}{
				"cycleId":      assessTaskDataAny.CycleId,
				"beginDay":     assessTaskDataAny.BeginDay,
				"targetUserId": param.UserId, //我被作为目标
				"typesList":    []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
				"limit":        5,
			})
			if err != nil {
				return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
			}
			if len(assessInviteData) > 0 {
				stepItem.Status = string(domain.StaffAssessCompleted)
			} else {
				stepItem.Status = string(domain.StaffAssessUncompleted)
			}
			//待邀请人数,为5人减去已邀请的人数。若邀请人数已等于或大于5人,则只显示截止日期即可
			if len(assessInviteData) > 5 {
				stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
			} else {
				stepItem.Desc = fmt.Sprintf("截止日期:%s  待邀请%d人", stepItem.EndTime, 5-len(assessInviteData))
			}
		case domain.LinkNodeAllAssessment:
			//我评估别人,被邀请评估
			_, assessInviteList, err := staffAssessRepo.Find(map[string]interface{}{
				"cycleId":    assessTaskDataAny.CycleId,
				"beginDay":   assessTaskDataAny.BeginDay,
				"executorId": param.UserId, //我作为执行人
				"typesList":  []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
			})
			if err != nil {
				return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
			}
			if len(assessInviteList) > 0 {
				stepItem.Status = string(domain.StaffAssessCompleted)
				stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
				for _, v := range assessInviteList {
					if v.Status == domain.StaffAssessUncompleted {
						stepItem.Status = string(domain.StaffAssessUncompleted)
						break
					}
				}
			}
		case domain.LinkNodeSuperiorAssessment:
			//我评估别人,上级评估
			cnnt, _, err := staffAssessRepo.Find(map[string]interface{}{
				"cycleId":    assessTaskDataAny.CycleId,
				"beginDay":   assessTaskDataAny.BeginDay,
				"executorId": param.UserId,
				"typesList":  []string{string(domain.AssessSuper)},
				"status":     domain.StaffAssessUncompleted,
				"limit":      1,
			})
			if err != nil {
				return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取未完成的评估环节"+err.Error())
			}
			cnnt2, _, err := staffAssessRepo.Find(map[string]interface{}{
				"cycleId":    assessTaskDataAny.CycleId,
				"beginDay":   assessTaskDataAny.BeginDay,
				"executorId": param.UserId,
				"typesList":  []string{string(domain.AssessSuper)},
				"status":     domain.StaffAssessCompleted,
				"limit":      1,
			})
			if err != nil {
				return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取已完成的评估环节"+err.Error())
			}
			if (cnnt + cnnt2) > 0 {
				stepItem.Status = string(domain.StaffAssessCompleted)
				stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
				uncompletedNum := cnnt
				if uncompletedNum > 0 {
					stepItem.Status = string(domain.StaffAssessUncompleted)
					stepItem.Desc = fmt.Sprintf("截止日期:%s 待评估%d人", stepItem.EndTime, uncompletedNum)
				}
			}
		}
		result.StepList = append(result.StepList, stepItem)
	}
	//排序评估阶段
	sort.Slice(result.StepList, func(i, j int) bool {
		return result.StepList[i].SortBy < result.StepList[j].SortBy
	})
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	return &result, nil
}

// 根据周期获取,我的自评任务添加的邀请人
func (srv StaffAssessServeice) ListAssessInviteUserV2(param *query.ListInviteUserQuery) (*adapter.AssessInviteUserResp, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()

	assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	companyReps := factory.CreateCompanyRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	companyInfo, _ := companyReps.FindOne(map[string]interface{}{
		"id": param.CompanyId,
	})
	assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	_, myAssessTask, err := assessTaskRepo.Find(map[string]interface{}{
		"cycleId":    param.CycleId,
		"beginDay":   param.BeginDay,
		"executorId": param.TargetUserId,
		"limit":      1,
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "我的自评任务不存在,"+err.Error())
	}

	if len(myAssessTask) == 0 {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "未参与本次的自评")
	}

	assessTaskData := myAssessTask[0]

	_, assessList, err := assessReps.Find(map[string]interface{}{
		"typesList":         []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
		"staffAssessTaskId": assessTaskData.Id,
		"targetUserId":      param.TargetUserId,
	})
	if err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, "获取个人邀请列表"+err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}

	result := adapter.AssessInviteUserResp{
		AssessTaskId:    assessTaskData.Id,
		InviteDiffSuper: []domain.StaffDesc{},
		InviteSameSuper: []domain.StaffDesc{},
	}
	for _, v := range assessTaskData.StepList {
		if v.LinkNodeType != domain.LinkNodeAllInvite {
			continue
		}
		result.LinkNodeId = v.LinkNodeId
		result.LinkNodeName = v.LinkNodeName
		result.BeginTime = v.BeginTime.Local().Format("2006-01-02 15:04:05")
		result.EndTime = v.EndTime.Local().Format("2006-01-02 15:04:05")
		break
	}
	companyName := ""
	if companyInfo != nil {
		companyName = companyInfo.Name
	}
	for _, v := range assessList {
		if v.Types == domain.AssessInviteDiffSuper {
			v.Executor.CompanyName = companyName
			result.InviteDiffSuper = append(result.InviteDiffSuper, v.Executor)
		}
		if v.Types == domain.AssessInviteSameSuper {
			v.Executor.CompanyName = companyName
			result.InviteSameSuper = append(result.InviteSameSuper, v.Executor)
		}
	}
	return &result, nil
}

// 根据周期和日期获取我要执行的的360评估,用户列表和评估填写的值
func (srv StaffAssessServeice) ListExecutorInviteAssessV2(param *query.ListExecutorAssessQuery) (
	*adapter.ListInviteUserAssessResp, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	//获取对应的评估任务
	assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	companyRepo := factory.CreateCompanyRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	companyInfo, _ := companyRepo.FindOne(map[string]interface{}{
		"id": param.CompanyId,
	})
	//获取 executorId 对应的360评估任务 用户
	condition := map[string]interface{}{
		"beginDay":   param.BeginDay,
		"cycleId":    param.CycleId,
		"executorId": param.ExecutorId,
		"typesList":  []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
		"limit":      20,
	}
	if len(param.UserName) > 0 {
		condition["targetUserName"] = param.UserName
	}
	if param.PageSize > 0 {
		condition["limit"] = param.PageSize
	}
	offset := (param.PageNumber - 1) * param.PageSize
	if offset > 0 {
		condition["offset"] = offset
	}

	cnt, assessList, err := assessRepo.Find(condition)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	var assessContentList []*domain.StaffAssessContent
	projectIdMap := map[int]struct{}{}
	//获取评估用的所有评估项
	for i := range assessList {
		if _, ok := projectIdMap[assessList[i].EvaluationProjectId]; ok {
			continue
		}
		projectIdMap[assessList[i].EvaluationProjectId] = struct{}{}
		assessContentListTemp, err := srv.getAssessSelfInfoUncompleted(transactionContext, assessList[i])
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估任务"+err.Error())
		}
		assessContentList = append(assessContentList, assessContentListTemp...)
	}
	//可变的表格列
	changeableHeader := []adapter.ListTableHeader{}
	//列名与字段对应
	keyMap := map[string]string{}
	for i, v := range assessContentList {
		name := fmt.Sprintf("%s-%s", v.Category, v.Name)
		key := fmt.Sprintf("k%d", i)
		if _, ok := keyMap[name]; ok {
			continue
		}
		keyMap[name] = key
		changeableHeader = append(changeableHeader, adapter.ListTableHeader{
			Key:  key,
			Name: name,
		})
	}
	assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	// 获取已经填报的内容
	changeableRows := map[int]map[string]string{}
	for _, v := range assessList {
		_, contentList, err := assessContentRepo.Find(map[string]interface{}{
			"staffAssessId": v.Id,
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估内容"+err.Error())
		}
		row := map[string]string{}
		for _, vv := range contentList {
			name := fmt.Sprintf("%s-%s", vv.Category, vv.Name)
			if kk, ok := keyMap[name]; ok {
				row[kk] = vv.Value
			}
		}
		changeableRows[v.TargetUser.UserId] = row
	}

	//获取360邀请评估完成情况
	//我评估别人,被邀请评估
	cnnt, _, err := assessRepo.Find(map[string]interface{}{
		"beginDay":   param.BeginDay,
		"cycleId":    param.CycleId,
		"executorId": param.ExecutorId,
		"typesList":  []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
		"status":     domain.StaffAssessUncompleted,
		"limit":      1,
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
	}

	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}

	//评估填写数据行转列
	tableHeader := []adapter.ListTableHeader{
		{Key: "userName", Name: "姓名"},
		{Key: "status", Name: "状态"},
		{Key: "types", Name: "360°评估关系"},
		{Key: "endTime", Name: "360°评估截止日期"},
	}
	tableHeader = append(tableHeader, changeableHeader...)
	listData := []map[string]interface{}{}
	companyName := ""
	if companyInfo != nil {
		companyName = companyInfo.Name
	}
	for _, v := range assessList {
		m := map[string]interface{}{
			"staffAssessTaskId": v.StaffAssessTaskId,
			"userName":          v.TargetUser.UserName,
			"userId":            strconv.Itoa(v.TargetUser.UserId),
			"status":            string(v.Status),
			"cycleId":           strconv.FormatInt(v.CycleId, 10),
			"beginDay":          v.BeginTime.Local().Format("2006-01-02"),
			"types":             string(v.Types),
			"endTime":           v.EndTime.Local().Format("2006-01-02 15:04:05"),
			"assessId":          strconv.Itoa(v.Id),
			"companyName":       companyName,
		}
		switch v.Status {
		case domain.StaffAssessCompleted:
			m["status"] = "已经完成"
		case domain.StaffAssessUncompleted:
			m["status"] = "未完成"
		}
		switch v.Types {
		case domain.AssessInviteDiffSuper:
			m["types"] = "不同上级同事"
		case domain.AssessInviteSameSuper:
			m["types"] = "相同上级同事"
		}
		if row, ok := changeableRows[v.TargetUser.UserId]; ok {
			for k, v := range row {
				m[k] = v
			}
		} else {
			for _, v := range changeableHeader {
				m[v.Key] = ""
			}
		}
		listData = append(listData, m)
	}
	result := adapter.ListInviteUserAssessResp{
		TableHeader: tableHeader,
		List:        listData,
		Total:       cnt,
	}

	if len(assessList) > 0 {
		result.BeginDay = assessList[0].BeginTime.Local().Format("2006-01-02")
		result.CycleId = int(assessList[0].CycleId)
		result.LintNodeDesc = fmt.Sprintf("截止时间 %s 待评估%d人", assessList[0].EndTime.Local().Format("2006-01-02 15:04:05"), cnnt)
	}

	return &result, nil
}

// 根据周期和日期获取我需要执行的上级评估成员列表
func (srv StaffAssessServeice) ListExecutorSupperAssessV2(param *query.ListExecutorAssessQuery) (map[string]interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	//获取对应的评估任务
	assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//公司存储
	companyRepo := factory.CreateCompanyRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})

	companyInfo, _ := companyRepo.FindOne(map[string]interface{}{
		"id": param.CompanyId,
	})

	limit := 20
	if param.PageSize > 0 {
		limit = param.PageSize
	}
	condition := map[string]interface{}{
		"beginDay":   param.BeginDay,
		"cycleId":    param.CycleId,
		"executorId": param.ExecutorId,
		"typesList":  []string{string(domain.AssessSuper)},
		"limit":      limit,
	}
	if len(param.UserName) > 0 {
		condition["targetUserName"] = param.UserName
	}
	offset := (param.PageNumber - 1) * param.PageSize
	if offset > 0 {
		condition["offset"] = offset
	}
	//获取 executorId 对应的上级评估列表
	cnt, assessList, err := assessRepo.Find(condition)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}

	//获取目标用户
	userIds := []int{}
	for _, v := range assessList {
		userIds = append(userIds, v.TargetUser.UserId)
	}
	//获取员工信息
	userRepo := factory.CreateUserRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	var targetUserList []*domain.User
	if len(userIds) > 0 {
		_, targetUserList, _ = userRepo.Find(map[string]interface{}{
			"ids": userIds,
		})
	}
	//获取职位信息
	positionRepo := factory.CreatePositionRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取员工的职位
	userPositionMap := map[int64][]*domain.Position{}
	for _, v := range targetUserList {
		if len(v.PositionId) == 0 {
			continue
		}
		_, positionList, _ := positionRepo.Find(map[string]interface{}{
			"ids": v.PositionId,
		})
		userPositionMap[v.Id] = positionList
	}
	//获取目标员工邀请的人完成360评估的数量
	var inviteCompletedCount []dao.CountData
	d := dao.NewStaffAssessDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	if len(userIds) > 0 {
		inviteCompletedCount, err = d.CountTargetUserInviteAssess1(userIds, param.CycleId, param.BeginDay)
		if err != nil {
			log.Logger.Error("获取员工邀请的人完成情况" + err.Error())
		}
	}

	//我评估别人,被邀请评估
	cnnt, _, err := assessRepo.Find(map[string]interface{}{
		"beginDay":   param.BeginDay,
		"cycleId":    param.CycleId,
		"executorId": param.ExecutorId,
		"typesList":  []string{string(domain.AssessSuper)},
		"status":     string(domain.StaffAssessUncompleted),
		"limit":      1,
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
	}
	var allAssessId []int
	for _, v := range assessList {
		allAssessId = append(allAssessId, v.Id)
	}

	assessValueMap := d.SearchContentValueByAssessId(allAssessId)

	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	companyName := ""
	if companyInfo != nil {
		companyName = companyInfo.Name
	}
	resultList := []adapter.ListSupperAssessResp{}
	for _, v := range assessList {
		item := adapter.ListSupperAssessResp{
			StaffAssessTaskId: v.StaffAssessTaskId,
			AssessId:          v.Id,
			CycleId:           int(v.CycleId),
			BeginDay:          v.BeginTime.Local().Format("2006-01-02"),
			UserId:            v.TargetUser.UserId,
			UserName:          v.TargetUser.UserName,
			EndTime:           v.EndTime.Local().Format("2006-01-02 15:04:05"),
			InviteCompleted:   0,
			Status:            string(v.Status),
			InviteTotal:       5,
			Department:        "",
			Position:          "",
			CompanyName:       companyName,
			DutyTime:          "",
			ContentValue:      []string{},
		}
		if values, ok := assessValueMap[v.Id]; ok {
			item.ContentValue = values
		}
		//填入部门
		for _, vv := range v.TargetDepartment {
			item.Department += vv.DepartmentName + " "
		}
		for _, vv := range targetUserList {
			if vv.Id != int64(v.TargetUser.UserId) {
				continue
			}
			//填入入职时间
			item.DutyTime = vv.CreatedAt.Local().Format("2006-01-02 15:04:05")
			//填入职位
			for _, vvv := range userPositionMap[vv.Id] {
				item.Position += vvv.Name + " "
			}
			break
		}
		//
		for _, vv := range inviteCompletedCount {
			if v.TargetUser.UserId == vv.TargetUserId {
				item.InviteCompleted = vv.InviteCompleted
				item.InviteTotal = vv.InviteTotal
				break
			}
		}
		resultList = append(resultList, item)
	}
	result := tool_funs.SimpleWrapGridMap(int64(cnt), resultList)
	result["lintNodeDesc"] = ""
	if len(assessList) > 0 {
		result["cycleId"] = assessList[0].CycleId
		result["beginDay"] = assessList[0].BeginTime.Local().Format("2006-01-02")
		result["lintNodeDesc"] = fmt.Sprintf("截止时间 %s 待评估 %d 人", assessList[0].EndTime.Local().Format("2006-01-02 15:04:05"), cnnt)
	}
	return result, nil
}

// 根据周期和日期,获取员工的自评内容
func (srv StaffAssessServeice) GetAssessSelfInfoV2(param *query.GetExecutorSelfAssessQuery) (*adapter.AssessInfoResp, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	// 获取员工的评估
	_, assessList, err := assessReps.Find(map[string]interface{}{
		"companyId":  param.CompanyId,
		"executorId": param.TargetUserId,
		"cycleId":    param.CycleId,
		"beginDay":   param.BeginDay,
		"typesList":  []string{string(domain.AssessSelf)},
		"limit":      1,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
	}
	if len(assessList) == 0 {
		return &adapter.AssessInfoResp{AssessId: -1}, nil
	}
	assessData := assessList[0]

	assessContentList := []*domain.StaffAssessContent{}
	if assessData.Status == domain.StaffAssessCompleted {
		//已完成
		assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
			"transactionContext": transactionContext,
		})
		_, assessContentList, err = assessContentRepo.Find(map[string]interface{}{
			"staffAssessId": assessData.Id,
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
		}
	} else if assessData.Status == domain.StaffAssessUncompleted {
		//未完成
		assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessData)
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
		}
	}

	// 恢复缓存数据
	if param.AcquireCache != 0 {
		srv.recoverAssessCache(transactionContext, assessData.Id, assessContentList)
	}

	//获取员工描述
	staffDesc, _ := srv.getStaffDescrip(transactionContext, int64(param.TargetUserId))
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	result := adapter.AssessInfoResp{
		AssessId:              assessData.Id,
		CycleId:               assessData.CycleId,
		CycleName:             assessData.CycleName,
		LinkNodeId:            assessData.LinkNodeId,
		LinkNodeName:          assessData.LinkNodeName,
		EvaluationProjectId:   assessData.EvaluationProjectId,
		EvaluationProjectName: assessData.EvaluationProjectName,
		BeginTime:             assessData.BeginTime.Local().Format("2006-01-02 15:04:05"),
		EndTime:               assessData.EndTime.Local().Format("2006-01-02 15:04:05"),
		Status:                string(assessData.Status),
		TargetUserId:          assessData.TargetUser.UserId,
		TargetUserName:        assessData.TargetUser.UserName,
		CompanyId:             assessData.CompanyId,
		CompanyName:           "",
		CompanyLogo:           "",
		SupperUser:            "",
		DutyTime:              "",
		AssessContent:         assessContentList,
	}
	if staffDesc != nil {
		result.CompanyName = staffDesc.CompanyName
		result.CompanyLogo = staffDesc.CompanyLogo
		result.SupperUser = staffDesc.SupperUserName
		result.DutyTime = staffDesc.DutyTime
	}
	return &result, nil
}

// 根据周期和日期。获取360评估的列表,员工的被其他人评估
func (srv StaffAssessServeice) ListTargetUserInviteAssess(param *query.ListTargetAssessQuery) (map[string]interface{}, error) {

	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取员工的评估
	cnt, assessList, err := assessReps.Find(map[string]interface{}{
		"cycleId":      param.CycleId,
		"beginDay":     param.BeginDay,
		"companyId":    param.CompanyId,
		"targetUserId": param.TargetUserId,
		"typesList":    []string{string(domain.AssessInviteSameSuper), string(domain.AssessInviteDiffSuper)},
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	var resultList []map[string]interface{}
	for _, v := range assessList {
		item := map[string]interface{}{
			"id":         v.Id,
			"targetUser": v.TargetUser,
			"executor":   v.Executor,
		}
		resultList = append(resultList, item)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), resultList), nil
}

// 根据周期和日期。获取上级评估的列表,员工的被其他人评估
func (srv StaffAssessServeice) ListTargetUserSuperAssess(param *query.ListTargetAssessQuery) (map[string]interface{}, error) {

	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取员工的评估
	cnt, assessList, err := assessReps.Find(map[string]interface{}{
		"cycleId":      param.CycleId,
		"beginDay":     param.BeginDay,
		"companyId":    param.CompanyId,
		"targetUserId": param.TargetUserId,
		"typesList":    []string{string(domain.AssessSuper)},
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	resultList := []map[string]interface{}{}
	for _, v := range assessList {
		item := map[string]interface{}{
			"id":         v.Id,
			"targetUser": v.TargetUser,
			"executor":   v.Executor,
		}
		resultList = append(resultList, item)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), resultList), nil
}

// 选择员工评估可邀请的用户
func (srv StaffAssessServeice) SelectAssessInviteUserV2(param *query.SelectAssessInviteUser) (map[string]interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	//获取被评估的目标用户
	userRepo := factory.CreateUserRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取公司信息
	companyRepo := factory.CreateCompanyRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	companyInfo, _ := companyRepo.FindOne(map[string]interface{}{
		"id": param.CompanyId,
	})
	targetUser, err := userRepo.FindOne(map[string]interface{}{
		"id": param.TargetUserId,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工信息"+err.Error())
	}

	//查询员工数据
	condition := map[string]interface{}{
		"companyId": param.CompanyId,
		"name":      param.InviteUserName,
		"limit":     20,
		"status":    1,
	}
	if param.PageSize > 0 {
		condition["limit"] = param.PageSize
	}
	offset := (param.PageNumber - 1) * param.PageSize
	if offset > 0 {
		condition["offset"] = offset
	}
	cnt, userList, err := userRepo.Find(condition)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工列表信息"+err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	listData := []adapter.SelectInviteUser{}
	companyName := ""
	if companyInfo != nil {
		companyName = companyInfo.Name
	}
	for _, v := range userList {
		_ = v
		_ = companyName
		item := adapter.SelectInviteUser{
			UserId:      int(v.Id),
			UserName:    v.Name,
			CompanyName: companyName,
			IsSupper:    false,
			Types:       2, //默认是不同上级
		}
		if targetUser.ParentId == v.ParentId {
			item.Types = 1
		}
		listData = append(listData, item)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
}

// 获取未完成的员工评估内容
// func (srv StaffAssessServeice) getAssessInfoUncompletedV2(transactionContext application.TransactionContext,
// 	assess *domain.StaffAssess) ([]*domain.StaffAssessContent, error) {
// 	evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
// 		"transactionContext": transactionContext,
// 	})
// 	var evaluationItemList []*domain.EvaluationItemUsed
// 	var err error
// 	_, evaluationItemList, err = evaluationItemRepo.Find(map[string]interface{}{
// 		"evaluationProjectId": assess.EvaluationProjectId,
// 		"nodeId":              assess.LinkNodeId,
// 	})
// 	if err != nil {
// 		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
// 	}
// 	if len(evaluationItemList) == 0 {
// 		//如果当前节点没有评估内容,就去 使用自评节点的评估内容
// 		_, evaluationItemList, err = evaluationItemRepo.Find(map[string]interface{}{
// 			"evaluationProjectId": assess.EvaluationProjectId,
// 			"nodeType":            domain.LinkNodeSelfAssessment,
// 		})
// 		if err != nil {
// 			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取自评项目填写内容"+err.Error())
// 		}
// 	}
// 	var contentList []*domain.StaffAssessContent
// 	nowTime := time.Now()
// 	for i, v := range evaluationItemList {
// 		item := &domain.StaffAssessContent{
// 			Id:            0,
// 			StaffAssessId: assess.Id,
// 			SortBy:        i + 1,
// 			Category:      v.Category,
// 			Name:          v.Name,
// 			PromptTitle:   v.PromptTitle,
// 			PromptText:    v.PromptText,
// 			Remark:        nil,
// 			Value:         "",
// 			ReteResult:    "",
// 			CreatedAt:     nowTime,
// 			Weight:        v.Weight,
// 			Required:      v.Required,
// 			UpdatedAt:     nowTime,
// 			DeletedAt:     nil,
// 			Rule:          v.Rule,
// 		}
// 		var remarks []domain.AssessContemtRemark
// 		for _, vv := range v.EntryItems {
// 			ritem := domain.AssessContemtRemark{
// 				Title:      vv.Title,
// 				HintText:   vv.HintText,
// 				Definition: vv.Definition,
// 				RemarkText: "",
// 			}
// 			remarks = append(remarks, ritem)
// 		}
// 		item.Remark = remarks
// 		contentList = append(contentList, item)
// 	}
// 	return contentList, nil
// }