service.go 60.1 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 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683
package service

import (
	"fmt"
	"strconv"
	"time"

	"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/command"
	"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"
)

// 员工评绩效评估
type StaffAssessServeice struct {
}

func NewStaffAssessServeice() *StaffAssessServeice {
	newService := &StaffAssessServeice{}
	return newService
}

// 获取我参与过的评估任务列表
func (srv StaffAssessServeice) SearchAssessTaskMe(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()
	}()
	staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	var limit int = 20
	var offset int = 0
	if param.PageSize > 0 {
		limit = param.PageSize
	}
	offset = (param.PageNumber - 1) * param.PageSize
	condition := map[string]interface{}{
		"executorId": param.UserId,
		"companyId":  param.CompanyId,
		"limit":      limit,
	}
	if offset > 0 {
		condition["offset"] = offset
	}
	cnt, assessTaskList, err := staffAssessTaskRepo.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 := make([]adapter.SearchAssessMeResp, 0, len(assessTaskList))
	var temp adapter.SearchAssessMeResp
	for _, v := range assessTaskList {
		temp = adapter.SearchAssessMeResp{
			AssessTaskId:          v.Id,
			BeginTime:             v.BeginTime.Format("2006-01-02 15:04:05"),
			EndTime:               v.EndTime.Format("2006-01-02 15:04:05"),
			CycleId:               v.CycleId,
			CycleName:             v.CycleName,
			EvaluationProjectId:   v.EvaluationProjectId,
			EvaluationProjectName: v.EvaluationProjectName,
		}
		listData = append(listData, temp)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
}

// 获取项目评估进度描述
func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery) (*adapter.AssessTaskDescResp, 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,
	})
	assessTaskData, err := staffAssessTaskRepo.FindOne(map[string]interface{}{
		"id": param.AssessTaskId,
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "评估任务不存在,"+err.Error())
	}
	//返回的数据结果
	result := adapter.AssessTaskDescResp{
		AssessTaskId:          assessTaskData.Id,
		EvaluationProjectId:   assessTaskData.EvaluationProjectId,
		EvaluationProjectName: assessTaskData.EvaluationProjectName,
		CycleName:             assessTaskData.CycleName,
		BeginTime:             assessTaskData.BeginTime.Local().Format("2006-01-02 15:04-05"),
		EndTime:               assessTaskData.EndTime.Local().Format("2006-01-02 15:04-05"),
		StepList:              []adapter.AssessTaskStep{},
	}

	for _, v := range assessTaskData.StepList {
		stepItem := adapter.AssessTaskStep{
			SortBy:       v.SortBy,
			LinkNodeName: v.LinkNodeName,
			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{}{
				"staffAssessTaskId": assessTaskData.Id,
				"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{}{
				"staffAssessTaskId": assessTaskData.Id,
				"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())
			}
			//待邀请人数,为5人减去已邀请的人数。若邀请人数已等于或大于5人,则只显示截止日期即可
			if len(assessInviteData) > 5 {
				stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
				stepItem.Status = string(domain.StaffAssessCompleted)
			} else {
				stepItem.Desc = fmt.Sprintf("截止日期:%s  待邀请%d人", stepItem.EndTime, 5-len(assessInviteData))
				stepItem.Status = string(domain.StaffAssessUncompleted)
			}
		case domain.LinkNodeAllAssessment:
			//我评估别人,被邀请评估
			_, assessInviteList, err := staffAssessRepo.Find(map[string]interface{}{
				"staffAssessTaskId": assessTaskData.Id,
				"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:
			//我评估别人,上级评估
			_, assessSupperList, err := staffAssessRepo.Find(map[string]interface{}{
				"staffAssessTaskId": assessTaskData.Id,
				"executorId":        param.UserId,
				"typesList":         []string{string(domain.AssessSuper)},
			})
			if err != nil {
				return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
			}
			if len(assessSupperList) > 0 {
				stepItem.Status = string(domain.StaffAssessCompleted)
				stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
				uncompletedNum := 0
				for _, v := range assessSupperList {
					if v.Status == domain.StaffAssessUncompleted {
						uncompletedNum += 1
					}
				}
				if uncompletedNum > 0 {
					stepItem.Desc = fmt.Sprintf("截止日期:%s 待评估%d人", stepItem.EndTime, uncompletedNum)
				}
			}
		}
		result.StepList = append(result.StepList, stepItem)
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	return &result, nil
}

// 获取个人的自评反馈历史记录列表
func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) (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()
	}()
	//获取个人参与的评估流程
	staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	var limit int = 20
	var offset int = 0
	if param.PageSize > 0 {
		limit = param.PageSize
	}
	offset = (param.PageNumber - 1) * param.PageSize
	condition := map[string]interface{}{
		"executorId": param.UserId,
		"companyId":  param.CompanyId,
		"typesList":  []string{string(domain.AssessSelf)},
		"limit":      limit,
		"status":     string(domain.StaffAssessCompleted),
	}
	if offset > 0 {
		condition["offset"] = offset
	}
	//获取历史列表
	cnt, assessList, err := staffAssessRepo.Find(condition)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取评估任务列表,"+err.Error())
	}

	//获取公司数据
	companyRep := factory.CreateCompanyRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})

	companyData, err := companyRep.FindOne(map[string]interface{}{
		"id": param.CompanyId,
	})
	if err != nil {
		log.Logger.Error("获取公司信息," + err.Error())
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取公司信息,"+err.Error())
	}

	//获取用户数据
	userRepo := factory.CreateUserRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	userData, err := userRepo.FindOne(map[string]interface{}{
		"id": param.UserId,
	})
	if err != nil {
		log.Logger.Error("获取用户信息," + err.Error())
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取用户信息,"+err.Error())
	}
	departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	var supperUserList []*domain.User
	if len(userData.DepartmentId) > 0 {
		_, departmentList, err := departmentRepo.Find(map[string]interface{}{
			"ids": userData.DepartmentId,
		})
		if err != nil {
			return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取部门信息,"+err.Error())
		}
		var chargeUserIds []int64
		for _, v := range departmentList {
			chargeUserIds = append(chargeUserIds, v.ChargeUserIds...)
		}
		if len(chargeUserIds) > 0 {
			_, supperUserList, err = userRepo.Find(map[string]interface{}{
				"ids": chargeUserIds,
			})
			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())
	}
	listData := make([]adapter.AssessSelfList, 0, len(assessList))
	var itemTemp adapter.AssessSelfList
	for _, v := range assessList {
		itemTemp = adapter.AssessSelfList{
			AssessId:              v.Id,
			BeginTime:             v.BeginTime.Local().Format("2006-01-02 15:04:05"),
			EndTime:               v.EndTime.Local().Format("2006-01-02 15:04:05"),
			CycleId:               v.CycleId,
			CycleName:             v.CycleName,
			EvaluationProjectId:   v.EvaluationProjectId,
			EvaluationProjectName: v.EvaluationProjectName,
		}
		listData = append(listData, itemTemp)
	}
	userInfo := adapter.StaffInfo{
		UserName:       userData.Name,
		CompanyName:    companyData.Name,
		SupperUserName: "",
		DutyTime:       userData.CreatedAt.Local().Format("2006-01-02 15:04:05"),
	}
	for _, v := range supperUserList {
		userInfo.SupperUserName = userInfo.SupperUserName + v.Name + " "
	}
	result := tool_funs.SimpleWrapGridMap(int64(cnt), listData)
	result["userInfo"] = userInfo
	return result, nil
}

// 根据项目评估的配置,创建员工的评估任务
func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (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()
	// }()
	assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	taskBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
	if err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, "任务开始时间填写错误,"+param.BeginTime)
	}
	taskEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
	if err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, "任务结束时间填写错误,"+param.EndTime)
	}
	nowTime := time.Now()
	var assessTaskData *domain.StaffAssessTask
	_, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{
		"evaluationProjectId": param.EvaluationProjectId,
		"beginDay":            taskBeginTime.Local().Format("2006-01-02"),
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期已存在评估任务"+err.Error())
	}
	// 获取旧数据

	if len(assassessTaskList) > 0 {
		assessTaskData = assassessTaskList[0]
		assessTaskData.UpdatedAt = nowTime
	} else {
		//建立评估任务
		assessTaskData = &domain.StaffAssessTask{
			Id:                    0,
			CompanyId:             param.CompanyId,
			EvaluationProjectId:   param.EvaluationProjectId,
			EvaluationProjectName: param.EvaluationProjectName,
			CycleId:               param.CycleId,
			CycleName:             param.CycleName,
			BeginTime:             taskBeginTime,
			EndTime:               taskEndTime,
			StepList:              []domain.AssessTaskStep{},
			ExecutorId:            nil,
			CreatedAt:             nowTime,
			UpdatedAt:             nowTime,
			DeletedAt:             nil,
		}
	}

	//填充评估环节
	for _, v := range param.StepList {
		for _, vv := range assessTaskData.StepList {
			if vv.LinkNodeType == v.LinkNodeType {
				continue
			}
		}
		stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
		if err != nil {
			return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime)
		}
		stepEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
		if err != nil {
			return nil, application.ThrowError(application.ARG_ERROR, "评估环节结束时间填写错误,"+param.EndTime)
		}
		step := domain.AssessTaskStep{
			SortBy:       v.SortBy,
			LinkNodeId:   v.LinkNodeId,
			LinkNodeName: v.LinkNodeName,
			LinkNodeType: v.LinkNodeType,
			BeginTime:    stepBeginTime,
			EndTime:      stepEndTime,
		}
		assessTaskData.StepList = append(assessTaskData.StepList, step)
	}

	assessList, err := srv.createStaffAssess(transactionContext, assessTaskData)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
	}

	//评估的参与人
	executorIds := []int{}
	executorIdMap := map[int]struct{}{} //过滤重复的用户
	for _, v := range param.ExecutorId {
		if _, ok := executorIdMap[v]; ok {
			continue
		}
		executorIds = append(executorIds, v)
	}
	//过滤就数据
	for _, v := range assessTaskData.ExecutorId {
		if _, ok := executorIdMap[v]; ok {
			continue
		}
		executorIds = append(executorIds, v)
	}
	assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	assessTaskData.ExecutorId = executorIds
	_, err = assessTaskRepo.Save(assessTaskData)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
	}

	for i := range assessList {
		assessList[i].StaffAssessTaskId = assessTaskData.Id
		_, err = assessRepo.Save(&assessList[i])
		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())
	// }
	return map[string]interface{}{
		"assessTaskId": assessTaskData.Id,
	}, nil
}

// 添加节点任务
func (srv StaffAssessServeice) createStaffAssess(transactionContext application.TransactionContext, param *domain.StaffAssessTask) ([]domain.StaffAssess, error) {
	//评估的参与人
	selfUserId := []int{}
	userIdMap := map[int]struct{}{} //过滤重复的用户
	for _, v := range param.ExecutorId {
		if _, ok := userIdMap[v]; ok {
			continue
		}
		selfUserId = append(selfUserId, v)
	}
	// 获取用户的信息
	if len(selfUserId) == 0 {
		return nil, application.ThrowError(application.ARG_ERROR, "未填写评估任务的执行人")
	}
	userRepo := factory.CreateUserRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取员工信息
	_, userList, err := userRepo.Find(map[string]interface{}{
		"ids": selfUserId,
	})
	if err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, "获取员工信息"+err.Error())
	}
	departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//获取用户的部门
	userDepartmentMap := map[int64][]*domain.Department{}
	for _, v := range userList {
		_, departmemtList, err := departmentRepo.Find(map[string]interface{}{
			"ids": v.DepartmentId,
		})
		if err != nil {
			return nil, application.ThrowError(application.ARG_ERROR, "获取员工的部门信息"+err.Error())
		}
		userDepartmentMap[v.Id] = departmemtList
	}
	assessList := []domain.StaffAssess{}
	//数据样板
	stepSelfTemp := domain.StaffAssess{
		Id:                    0,
		CompanyId:             param.CompanyId,
		EvaluationProjectId:   param.EvaluationProjectId,
		EvaluationProjectName: param.EvaluationProjectName,
		CycleId:               param.CycleId,
		CycleName:             param.CycleName,
		StaffAssessTaskId:     param.Id,
		// TargetUser:            domain.StaffDesc{},
		// TargetDepartment:      nil,
		// Executor:              domain.StaffDesc{},
		Types: domain.AssessSelf,
		// LinkNodeId: v.LinkNodeId,
		Status: domain.StaffAssessUncompleted,
		// BeginTime:  time.Time{},
		// EndTime:    time.Time{},
		CreatedAt: param.CreatedAt,
		UpdatedAt: param.UpdatedAt,
		DeletedAt: nil,
	}
	for _, v := range param.StepList {
		if v.LinkNodeType == domain.LinkNodeSelfAssessment {
			//员工自评
			stepSelfTemp.BeginTime = v.BeginTime
			stepSelfTemp.EndTime = v.EndTime
			stepSelfTemp.LinkNodeId = v.LinkNodeId
			stepSelfTemp.LinkNodeName = v.LinkNodeName
			assessListTemp := srv.createStaffAssessSelf(stepSelfTemp, userList, userDepartmentMap)
			assessList = append(assessList, assessListTemp...)
		}
		if v.LinkNodeType == domain.LinkNodeSuperiorAssessment {
			// TODO
			stepSelfTemp.BeginTime = v.BeginTime
			stepSelfTemp.EndTime = v.EndTime
			stepSelfTemp.LinkNodeId = v.LinkNodeId
			stepSelfTemp.LinkNodeName = v.LinkNodeName
			assessListTemp, err := srv.createStaffAssessSupper(transactionContext, stepSelfTemp, userList, userDepartmentMap)
			if err != nil {
				return nil, err
			}
			assessList = append(assessList, assessListTemp...)
		}
	}
	return assessList, nil
}

// 构建员工自评
func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAssess,
	userList []*domain.User, userDepartmentMap map[int64][]*domain.Department) []domain.StaffAssess {
	result := []domain.StaffAssess{}
	for _, usr := range userList {
		assessTemp.TargetUser = domain.StaffDesc{
			UserId:   int(usr.Id),
			Account:  usr.Account,
			UserName: usr.Account,
		}
		assessTemp.Executor = domain.StaffDesc{
			UserId:   int(usr.Id),
			Account:  usr.Account,
			UserName: usr.Account,
		}
		if depList, ok := userDepartmentMap[usr.Id]; ok {
			for _, dep := range depList {
				assessTemp.TargetDepartment = append(assessTemp.TargetDepartment, domain.StaffDepartment{
					DepartmentId:   int(dep.Id),
					DepartmentName: dep.Name,
				})
			}
		}
		result = append(result, assessTemp)
	}
	return result
}

// 构建员工上级评估
func (srv StaffAssessServeice) createStaffAssessSupper(
	transactionContext application.TransactionContext,
	assessTemp domain.StaffAssess,
	userList []*domain.User, userDepartmentMap map[int64][]*domain.Department,
) ([]domain.StaffAssess, error) {
	var assessList []domain.StaffAssess
	// 获取员工的上级用户
	userRepo := factory.CreateUserRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	for _, v := range userList {
		departmentList, ok := userDepartmentMap[v.Id]
		if !ok {
			continue
		}
		for _, vv2 := range departmentList {
			if len(vv2.ChargeUserIds) == 0 {
				continue
			}
			_, chargeUserList, err := userRepo.Find(map[string]interface{}{
				"ids":   vv2.ChargeUserIds,
				"limit": 40,
			})
			if err != nil {
				return nil, application.ThrowError(application.ARG_ERROR, "获取部门主管信息"+err.Error())
			}
			for _, vvv3 := range chargeUserList {
				assessTemp.TargetDepartment = []domain.StaffDepartment{
					{DepartmentId: int(vv2.Id), DepartmentName: vv2.Name},
				}
				assessTemp.TargetUser = domain.StaffDesc{
					UserId:   int(v.Id),
					Account:  v.Account,
					UserName: v.Name,
				}
				assessTemp.Executor = domain.StaffDesc{
					UserId:   int(vvv3.Id),
					Account:  vvv3.Account,
					UserName: vvv3.Name,
				}
				assessList = append(assessList, assessTemp)
			}
		}
	}
	return assessList, nil
}

// 获取某个员工360评估邀请的人员
func (srv StaffAssessServeice) GetAssessInviteUser(param *query.GetAssessInviteUserQuery) (*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,
	})

	assessTaskReps := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	assessTaskData, err := assessTaskReps.FindOne(map[string]interface{}{
		"id": param.AssessTaskId,
	})
	if err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, "获取评估任务"+err.Error())
	}
	_, assessList, err := assessReps.Find(map[string]interface{}{
		"typesList":         []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
		"staffAssessTaskId": param.AssessTaskId,
		"targetUserId":      param.UserId,
	})
	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
	}
	for _, v := range assessList {
		if v.Types == domain.AssessInviteDiffSuper {
			result.InviteDiffSuper = append(result.InviteDiffSuper, v.Executor)
		}
		if v.Types == domain.AssessInviteSameSuper {
			result.InviteSameSuper = append(result.InviteDiffSuper, v.Executor)
		}
	}
	return &result, nil
}

// 保存某个员工360邀请的人员
func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInvite) (map[string]interface{}, error) {
	inviteSameSuperId := []int{}
	InviteDiffSuperId := []int{}
	for _, v := range param.InviteDiffSuper {
		id, err := strconv.Atoi(v)
		if err != nil {
			return nil, application.ThrowError(application.ARG_ERROR, "用户填写错误")
		}
		InviteDiffSuperId = append(InviteDiffSuperId, id)
	}
	for _, v := range param.InviteSameSuper {
		id, err := strconv.Atoi(v)
		if err != nil {
			return nil, application.ThrowError(application.ARG_ERROR, "用户填写错误")
		}
		inviteSameSuperId = append(inviteSameSuperId, id)
	}
	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,
	})
	userRepo := factory.CreateUserRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})

	assessTaskReps := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	assessTaskData, err := assessTaskReps.FindOne(map[string]interface{}{
		"id": param.AssessTaskId,
	})
	if err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, "获取评估任务"+err.Error())
	}

	//获取邀请评估的节点
	var inviteNode *domain.AssessTaskStep
	for _, v := range assessTaskData.StepList {
		if v.LinkNodeType == domain.LinkNodeAllAssessment {
			cp := v
			inviteNode = &cp
			break
		}
	}
	if inviteNode == nil {
		return nil, application.ThrowError(application.ARG_ERROR, "评估任务没有邀请评估的环节")
	}

	targetUser, err := userRepo.FindOne(map[string]interface{}{
		"id": param.TargetUserId,
	})
	if err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, "获取被评估员工"+err.Error())
	}
	//被评估人的部门
	var targetUserDepartment []domain.StaffDepartment
	if len(targetUser.DepartmentId) > 0 {
		_, departmentList, err := departmentRepo.Find(map[string]interface{}{
			"ids": targetUser.DepartmentId,
		})
		if err != nil {
			return nil, application.ThrowError(application.ARG_ERROR, "获取部门信息"+err.Error())
		}
		for _, v := range departmentList {
			targetUserDepartment = append(targetUserDepartment, domain.StaffDepartment{
				DepartmentId:   int(v.Id),
				DepartmentName: v.Name,
			})
		}
	}
	//邀请的相同上级的员工
	var inviteSameSuper []domain.StaffDesc
	if len(inviteSameSuperId) > 0 {
		_, userList, err := userRepo.Find(map[string]interface{}{
			"ids": inviteSameSuperId,
		})
		if err != nil {
			return nil, application.ThrowError(application.ARG_ERROR, "获取用户信息"+err.Error())
		}
		for _, v := range userList {
			inviteSameSuper = append(inviteSameSuper, domain.StaffDesc{
				UserId:   int(v.Id),
				UserName: v.Name,
				Account:  v.Account,
			})
		}
	}
	//邀请的不同上级的员工
	var inviteDiffSuper []domain.StaffDesc
	if len(InviteDiffSuperId) > 0 {
		_, userList, err := userRepo.Find(map[string]interface{}{
			"ids": InviteDiffSuperId,
		})
		if err != nil {
			return nil, application.ThrowError(application.ARG_ERROR, "获取用户信息"+err.Error())
		}
		for _, v := range userList {
			inviteDiffSuper = append(inviteDiffSuper, domain.StaffDesc{
				UserId:   int(v.Id),
				UserName: v.Name,
				Account:  v.Account,
			})
		}
	}
	//获取员工邀请的人
	_, assessList, err := assessReps.Find(map[string]interface{}{
		"typesList":         []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
		"staffAssessTaskId": param.AssessTaskId,
		"targetUserId":      param.TargetUserId,
	})
	if err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, "获取员工邀请的人"+err.Error())
	}
	//比对新旧数据
	nowTime := time.Now()
	assessMap := map[string]*domain.StaffAssess{}
	for _, v := range assessList {
		//假设为删除
		v.DeletedAt = &nowTime
		key := fmt.Sprintf("%s%d", string(v.Types), v.Executor.UserId)
		assessMap[key] = v
	}
	newAssessList := []*domain.StaffAssess{}
	//邀请同上级的员工
	for _, v := range inviteSameSuper {
		key := fmt.Sprintf("%s%d", string(domain.AssessInviteSameSuper), v.UserId)
		if _, ok := assessMap[key]; ok {
			assessMap[key].DeletedAt = nil
		} else {
			newAssessList = append(newAssessList, &domain.StaffAssess{
				Id:                    0,
				CompanyId:             assessTaskData.CompanyId,
				EvaluationProjectId:   assessTaskData.EvaluationProjectId,
				EvaluationProjectName: assessTaskData.EvaluationProjectName,
				CycleId:               assessTaskData.CycleId,
				CycleName:             assessTaskData.CycleName,
				StaffAssessTaskId:     assessTaskData.Id,
				TargetUser: domain.StaffDesc{
					UserId:   int(targetUser.Id),
					Account:  targetUser.Account,
					UserName: targetUser.Name,
				},
				TargetDepartment: targetUserDepartment,
				Executor:         v,
				Types:            domain.AssessInviteSameSuper,
				LinkNodeId:       inviteNode.LinkNodeId,
				LinkNodeName:     inviteNode.LinkNodeName,
				Status:           domain.StaffAssessUncompleted,
				BeginTime:        inviteNode.BeginTime,
				EndTime:          inviteNode.EndTime,
				CreatedAt:        nowTime,
				UpdatedAt:        nowTime,
				DeletedAt:        nil,
			})
		}
	}
	for _, v := range inviteDiffSuper {
		key := fmt.Sprintf("%s%d", string(domain.AssessInviteDiffSuper), v.UserId)
		if _, ok := assessMap[key]; ok {
			assessMap[key].DeletedAt = nil
		} else {
			newAssessList = append(newAssessList, &domain.StaffAssess{
				Id:                    0,
				CompanyId:             assessTaskData.CompanyId,
				EvaluationProjectId:   assessTaskData.EvaluationProjectId,
				EvaluationProjectName: assessTaskData.EvaluationProjectName,
				CycleId:               assessTaskData.CycleId,
				CycleName:             assessTaskData.CycleName,
				StaffAssessTaskId:     assessTaskData.Id,
				TargetUser: domain.StaffDesc{
					UserId:   int(targetUser.Id),
					Account:  targetUser.Account,
					UserName: targetUser.Name,
				},
				TargetDepartment: targetUserDepartment,
				Executor:         v,
				Types:            domain.AssessInviteDiffSuper,
				LinkNodeId:       inviteNode.LinkNodeId,
				LinkNodeName:     inviteNode.LinkNodeName,
				Status:           domain.StaffAssessUncompleted,
				BeginTime:        inviteNode.BeginTime,
				EndTime:          inviteNode.EndTime,
				CreatedAt:        nowTime,
				UpdatedAt:        nowTime,
				DeletedAt:        nil,
			})
		}
	}
	assessList = append(assessList, newAssessList...)
	for i := range assessList {
		_, err = assessReps.Save(assessList[i])
		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())
	}
	result := map[string]interface{}{
		"assessTaskId": assessTaskData.Id,
	}
	return result, nil
}

// 获取员工自评的评估内容详情
func (srv StaffAssessServeice) GetAssessSelfInfo(param *query.AssessSelfInfoQuery) (*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,
		"staffAssessTaskId": param.AssessTaskId,
		"targetUserId":      param.TargetUserId,
		"typesList":         []string{string(domain.AssessSelf)},
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
	}
	if len(assessList) == 0 {
		return &adapter.AssessInfoResp{}, 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())
		}
	}

	//获取员工描述
	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:           "",
		SupperUser:            "",
		DutyTime:              "",
		AssessContent:         assessContentList,
	}
	if staffDesc != nil {
		result.CompanyName = staffDesc.CompanyName
		result.SupperUser = staffDesc.SupperUserName
		result.DutyTime = staffDesc.DutyTime
	}
	return &result, nil
}

// 获取未完成的员工评估内容
func (srv StaffAssessServeice) getAssessSelfInfoUncompleted(transactionContext application.TransactionContext,
	assess *domain.StaffAssess) ([]*domain.StaffAssessContent, error) {
	projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	projectData, err := projectRepo.FindOne(map[string]interface{}{
		"id": assess.EvaluationProjectId,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
	}
	var linkNode *domain.LinkNode
	for _, v := range projectData.Template.LinkNodes {
		if v.Id == int64(assess.LinkNodeId) {
			linkNode = v
			break
		}
	}
	if linkNode == nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未获得评估环节配置"+err.Error())
	}
	ruleRepo := factory.CreateEvaluationRuleRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	ruleMap := map[int64]*domain.EvaluationRule{}
	for _, v := range linkNode.NodeContents {
		if _, ok := ruleMap[v.RuleId]; ok {
			continue
		}
		ruleData, err := ruleRepo.FindOne(map[string]interface{}{
			"id": v.RuleId,
		})
		if err == nil {
			ruleMap[v.RuleId] = ruleData
		}
	}

	var contentList []*domain.StaffAssessContent
	nowTime := time.Now()
	for i, v := range linkNode.NodeContents {
		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,
			UpdatedAt:     nowTime,
			DeletedAt:     nil,
			// Rule: ,
		}
		if ruleVal, ok := ruleMap[v.RuleId]; ok {
			item.Rule = *ruleVal
		}
		var remarks []domain.AssessContemtRemark
		for _, vv := range v.EntryItems {
			ritem := domain.AssessContemtRemark{
				Title:      vv.Title,
				HintText:   vv.HintText,
				RemarkText: "",
			}
			remarks = append(remarks, ritem)
		}
		item.Remark = remarks
		contentList = append(contentList, item)
	}
	return contentList, nil
}

// 选择员工评估可邀请的用户
func (srv StaffAssessServeice) SelectAssessInviteUser(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,
	})
	targetUser, err := userRepo.FindOne(map[string]interface{}{
		"id": param.TargetUserId,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工信息"+err.Error())
	}
	//获取被评估的目标用户的部门
	departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	var targetUserDepartment []*domain.Department
	if len(targetUser.DepartmentId) > 0 {
		_, targetUserDepartment, err = departmentRepo.Find(map[string]interface{}{
			"ids": targetUser.DepartmentId,
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取部门信息"+err.Error())
		}
	}
	//获取部门主管的id
	targetUserCharge := map[int64]struct{}{}
	for _, v := range targetUserDepartment {
		for _, vv := range v.ChargeUserIds {
			targetUserCharge[vv] = struct{}{}
		}
	}
	//
	targetUserDepartmentMap := map[int64]struct{}{}
	for _, v := range targetUserDepartment {
		targetUserDepartmentMap[v.Id] = struct{}{}
	}
	//查询员工数据
	condition := map[string]interface{}{
		"companyId": param.CompanyId,
		"name":      param.InviteUserName,
		"limit":     20,
	}
	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{}
	for _, v := range userList {
		item := adapter.SelectInviteUser{
			UserId:   int(v.Id),
			UserName: v.Name,
			IsSupper: false,
			Types:    2, //默认是不同上级
		}
		if _, ok := targetUserCharge[v.Id]; ok {
			item.IsSupper = true
		}
		for _, vv := range v.DepartmentId {
			if _, ok := targetUserDepartmentMap[int64(vv)]; ok {
				item.Types = 1 //设为相同上级
				break
			}
		}
		listData = append(listData, item)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
}

// 获取我要执行的的360评估,用户列表和评估填写的值
func (srv StaffAssessServeice) ListExecutorInviteAssess(param *query.ListInviteUserAssessQuery) (
	*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,
	})
	assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})

	//获取 executorId 对应的360评估任务 用户
	condition := map[string]interface{}{
		"staffAssessTaskId": param.AssessTaskId,
		"executorId":        param.ExecutorId,
		"typesList":         []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
		"limit":             20,
	}
	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
	if len(assessList) > 0 {
		//获取评估用的所有评估项
		assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessList[0])
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估任务"+err.Error())
		}
	}
	//可变的表格列
	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)
		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{}{
		"staffAssessTaskId": param.AssessTaskId,
		"executorId":        param.ExecutorId,
		"typesList":         []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
		"status":            domain.StaffAssessUncompleted,
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
	}

	assessTaskData, err := assessTaskRepo.FindOne(map[string]interface{}{
		"id": param.AssessTaskId,
	})
	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]string{}
	for _, v := range assessList {
		m := map[string]string{
			"userName": v.TargetUser.UserName,
			"userId":   strconv.Itoa(v.TargetUser.UserId),
			"status":   string(v.Status),
			"types":    string(v.Types),
			"endTime":  v.EndTime.Local().Format("2006-01-02 15:04:05"),
			"assessId": strconv.Itoa(v.Id),
		}
		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,
	}
	for _, v := range assessTaskData.StepList {
		if v.LinkNodeType == domain.LinkNodeAllAssessment {
			result.LinkNodeId = v.LinkNodeId
			result.LinkNodeName = v.LinkNodeName
			result.LintNodeDesc = fmt.Sprintf("截止时间 %s 待评估%d人", v.EndTime.Local().Format("2006-01-02 15:04:05"), cnnt)
		}
	}
	return &result, nil
}

// 获取我需要执行的上级评估成员列表
func (srv StaffAssessServeice) ListExecutorSupperAssess(param *query.ListSupperAssessQuery) (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,
	})

	limit := 20
	if param.PageSize > 0 {
		limit = param.PageSize
	}
	condition := map[string]interface{}{
		"staffAssessTaskId": param.AssessTaskId,
		"executorId":        param.ExecutorId,
		"typesList":         []string{string(domain.AssessSuper)},
		"limit":             limit,
		"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
	if len(userIds) > 0 {
		d := dao.NewStaffAssessDao(map[string]interface{}{
			"transactionContext": transactionContext,
		})
		inviteCompletedCount, err = d.CountInviteAssessByTargetUser(userIds, param.AssessTaskId)
		if err != nil {
			log.Logger.Error("获取员工邀请的人完成情况" + err.Error())
		}
	}

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

	resultList := []adapter.ListSupperAssessResp{}
	for _, v := range assessList {
		item := adapter.ListSupperAssessResp{
			AssessId:        v.Id,
			UsrId:           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:        "",
			DutyTime:        "",
		}
		//填入部门
		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)
	}
	return tool_funs.SimpleWrapGridMap(int64(cnt), resultList), nil
}

// 根据staffAssessId 获取评估的填写信息
func (srv StaffAssessServeice) GetAssessInfo(param *query.AssessInfoQuery) (*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,
		"id":        param.AssessId,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
	}
	if len(assessList) == 0 {
		return &adapter.AssessInfoResp{}, 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())
		}
	}

	targetUserDesc, err := srv.getStaffDescrip(transactionContext, int64(assessData.TargetUser.UserId))
	if err != nil {
		log.Logger.Error("获取员工描述" + err.Error())
	}
	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:           "",
		SupperUser:            "",
		DutyTime:              "",
		AssessContent:         assessContentList,
	}
	if len(assessContentList) == 0 {
		result.AssessContent = []*domain.StaffAssessContent{}
	}
	if targetUserDesc != nil {
		result.CompanyName = targetUserDesc.CompanyName
		result.SupperUser = targetUserDesc.SupperUserName
		result.DutyTime = targetUserDesc.DutyTime
	}
	return &result, nil
}

// 获取员工信息描述
func (srv *StaffAssessServeice) getStaffDescrip(transactionContext application.TransactionContext, userid int64) (*adapter.StaffInfo, error) {
	//获取用户数据
	userRepo := factory.CreateUserRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	userData, err := userRepo.FindOne(map[string]interface{}{
		"id": userid,
	})
	if err != nil {
		log.Logger.Error("获取用户信息," + err.Error())
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取用户信息,"+err.Error())
	}

	//获取公司数据
	companyRep := factory.CreateCompanyRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	companyData, err := companyRep.FindOne(map[string]interface{}{
		"id": userData.CompanyId,
	})
	if err != nil {
		log.Logger.Error("获取公司信息," + err.Error())
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取公司信息,"+err.Error())
	}
	departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	var supperUserList []*domain.User
	if len(userData.DepartmentId) > 0 {
		_, departmentList, err := departmentRepo.Find(map[string]interface{}{
			"ids": userData.DepartmentId,
		})
		if err != nil {
			return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取部门信息,"+err.Error())
		}
		var chargeUserIds []int64
		for _, v := range departmentList {
			chargeUserIds = append(chargeUserIds, v.ChargeUserIds...)
		}
		if len(chargeUserIds) > 0 {
			_, supperUserList, err = userRepo.Find(map[string]interface{}{
				"ids": chargeUserIds,
			})
			if err != nil {
				return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取员工上级信息,"+err.Error())
			}
		}
	}
	userInfo := adapter.StaffInfo{
		UserName:       userData.Name,
		CompanyName:    companyData.Name,
		SupperUserName: "",
		DutyTime:       userData.CreatedAt.Local().Format("2006-01-02 15:04:05"),
	}
	for _, v := range supperUserList {
		userInfo.SupperUserName = userInfo.SupperUserName + v.Name + " "
	}
	return &userInfo, nil
}

// 提交评估数据
func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoCommand) (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,
	})
	//获取员工的评估
	assessData, err := assessReps.FindOne(map[string]interface{}{
		"id": param.AssessId,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
	}
	assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	//待更新的评估填写信息
	assessContentList := []*domain.StaffAssessContent{}
	if assessData.Status == domain.StaffAssessCompleted {
		//已完成

		_, 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())
		}
	}
	//处理提交上来的数据
	paramContentMap := map[string]command.AssesssContent{}
	for i, v := range param.AssessContent {
		key := fmt.Sprintf("%s-%s", v.Category, v.Name)
		paramContentMap[key] = param.AssessContent[i]
	}
	//更新的评估填写信息
	for _, v := range assessContentList {
		key := fmt.Sprintf("%s-%s", v.Category, v.Name)
		item, ok := paramContentMap[key]
		if !ok {
			continue
		}
		v.Value = item.Value
		for ii := range v.Remark {
			for _, vvv := range item.Remark {
				if v.Remark[ii].Title == vvv.Title {
					v.Remark[ii].RemarkText = vvv.RemarkText
					break
				}
			}
		}
	}
	//保存信息
	for i := range assessContentList {
		_, err = assessContentRepo.Save(assessContentList[i])
		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())
	}
	return map[string]interface{}{
		"assessId": assessData.Id,
	}, nil
}

// 获取员工被评估的列表
func (srv StaffAssessServeice) ListTargetUserAssess(param *query.ListTargetUserAssessQuery) (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{}{
		"assessTaskId": param.AssessTaskId,
		"companyId":    param.CompanyId,
		"targetUserId": param.TargetUserId,
	})
	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())
	}

	return tool_funs.SimpleWrapGridMap(int64(cnt), assessList), nil
}