service_3.go 28.2 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
package service

import (
	"fmt"

	"github.com/linmadan/egglib-go/core/application"
	"github.com/xuri/excelize/v2"
	"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) ListAllAssessCycle(companyid int) (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()
	}()
	assessDao := dao.NewStaffAssessDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	cycleList, err := assessDao.AllAssessCycleList(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())
	}
	result := map[string]interface{}{
		"list": cycleList,
	}
	return result, nil

}

// 获取周期内的考核日期
func (srv StaffAssessServeice) ListAllAssessCycleDay(param *query.ListAssessCycleDay) (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()
	}()
	assessDao := dao.NewStaffAssessDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	cycleDayList, err := assessDao.AllAssessCycleDayList(param.CompanyId, param.CycleId)
	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{}{
		"list": cycleDayList,
	}
	return result, nil
}

// 根据周期id和日期获取 员工填写评估内容
// 有过滤查看权限
func (srv StaffAssessServeice) ListUserAssessContentCycleDay(param *query.ListAssessContentCycleDay) (*adapter.ListUserAssessContent, 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()
	}()

	hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperaterId)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}

	//roleRepo := factory.CreateRoleRepository(map[string]interface{}{
	//	"transactionContext": transactionContext,
	//})
	//roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{
	//	"transactionContext": transactionContext,
	//})
	//_, roleList, err := roleRepo.Find(map[string]interface{}{
	//	"type":      domain.RoleTypeSystem,
	//	"companyId": param.CompanyId,
	//})
	//if err != nil {
	//	return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
	//}
	//_, userRoleList, err := roleUserRepo.Find(map[string]interface{}{
	//	"companyId": param.CompanyId,
	//	"userId":    param.OperaterId,
	//})
	//if err != nil {
	//	return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
	//}
	//hrbp := -1
	//for _, v := range userRoleList {
	//	for _, v2 := range roleList {
	//		if v.RoleId == v2.Id {
	//			hrbp = 1
	//			break
	//		}
	//	}
	//	if hrbp == 1 {
	//		break
	//	}
	//}
	assessDao := dao.NewStaffAssessDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})

	limit := param.PageSize
	offset := (param.PageNumber - 1) * limit
	cnt, err := assessDao.CountUserAssess(dao.SearchConditin1{
		CompanyId:      param.CompanyId,
		CycleId:        param.CycleId,
		BeginDay:       param.BeginDay,
		TargetUserName: param.TargetUserName,
		Limit:          5000,
		Offset:         0,
		OperaterId:     param.OperaterId,
		Hrbp:           hrbp,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计总数"+err.Error())
	}
	contentList, err := assessDao.SearchUserAssessContent(dao.SearchConditin1{
		CompanyId:      param.CompanyId,
		CycleId:        param.CycleId,
		BeginDay:       param.BeginDay,
		TargetUserName: param.TargetUserName,
		Limit:          limit,
		Offset:         offset,
		OperaterId:     param.OperaterId,
		Hrbp:           hrbp,
	})
	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())
	}
	log.Logger.Debug(fmt.Sprintf("获取到的数据列表%d", len(contentList)))
	//可变的表格列
	changeableHeader := []adapter.ListTableHeader{
		{Key: "targetUserName", Name: "姓名"}, //固定列
	}
	//过滤重复的列
	headerMap := map[string]string{}
	// 获取已经填报的内容
	changeableRows := map[string]map[string]interface{}{}
	tableSort := []string{} //确定列表行数据的顺序
	for i, v := range contentList {
		if _, ok := changeableRows[v.TargetUserId]; !ok {
			changeableRows[v.TargetUserId] = map[string]interface{}{}
			tableSort = append(tableSort, v.TargetUserId)
		}
		changeableRows[v.TargetUserId]["targetUserName"] = v.TargetUserName
		changeableRows[v.TargetUserId]["targetUserId"] = v.TargetUserId
		changeableRows[v.TargetUserId]["assessId"] = v.AssessId
		changeableRows[v.TargetUserId]["cycleId"] = v.CycleId
		changeableRows[v.TargetUserId]["beginDay"] = v.BeginDay
		if v.ContentId > 0 {
			name := fmt.Sprintf("%s-%s", v.Category, v.ContentName)
			key := fmt.Sprintf("k%d", i)
			if _, ok := headerMap[name]; !ok {
				changeableHeader = append(changeableHeader, adapter.ListTableHeader{
					Key: key, Name: name,
				})
				headerMap[name] = key
			}
			key = headerMap[name]
			changeableRows[v.TargetUserId][key] = v.Value
		}
	}
	list := []map[string]interface{}{}
	for _, v := range tableSort {
		for _, v2 := range changeableHeader {
			if _, ok := changeableRows[v][v2.Key]; ok {
				continue
			}
			changeableRows[v][v2.Key] = ""
		}
		list = append(list, changeableRows[v])
	}
	result := adapter.ListUserAssessContent{
		TableHeader: changeableHeader,
		Total:       cnt,
		List:        list,
	}
	return &result, nil
}

// func (srv StaffAssessServeice) ExportUserAssess(param *query.ExportAssessContentCycleDay) (*excelize.File, 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()
// 	}()

// 	hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperaterId)
// 	if err != nil {
// 		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// 	}

// 	assessDao := dao.NewStaffAssessDao(map[string]interface{}{
// 		"transactionContext": transactionContext,
// 	})
// 	contentList, err := assessDao.ExportDataUserAssess(dao.SearchConditin1{
// 		CompanyId:      param.CompanyId,
// 		CycleId:        param.CycleId,
// 		BeginDay:       param.BeginDay,
// 		TargetUserName: param.TargetUserName,
// 		TargetUserId:   param.TargetUserId,
// 		Limit:          5000,
// 		Offset:         0,
// 		OperaterId:     param.OperaterId,
// 		Hrbp:           hrbp,
// 	})
// 	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())
// 	}
// 	//选择导出的评估项
// 	includeCol := map[string]struct{}{}
// 	for _, v := range param.ExportItems {
// 		includeCol[v.Category+"+"+v.Name] = struct{}{}
// 	}

// 	//处理查询到的数据
// 	//汇总 Excel表格的表头描述
// 	level1 := []string{}            //分类
// 	level3 := map[string][]string{} //key=分类+得分项类型  val=名称
// 	level4 := map[string]string{}   //key=分类+名称 val=评估标准
// 	for _, v := range contentList {
// 		if v.ContentId == 0 {
// 			continue
// 		}
// 		if len(includeCol) > 0 {
// 			if _, ok := includeCol[v.Category+"+"+v.ContentName]; !ok {
// 				continue
// 			}
// 		}
// 		level1Item := ""
// 		for _, v1 := range level1 {
// 			if v.Category == v1 {
// 				level1Item = v1
// 			}
// 		}
// 		if len(level1Item) == 0 {
// 			level1 = append(level1, v.Category)
// 		}
// 		if v.Weight == 0 {
// 			level3Key := v.Category + "-加分项"
// 			if _, ok := level3[level3Key]; !ok {
// 				level3[level3Key] = []string{}
// 			}
// 			level3Item := ""
// 			for _, v3 := range level3[level3Key] {
// 				if v3 == v.ContentName {
// 					level3Item = v.ContentName
// 				}
// 			}
// 			if len(level3Item) == 0 {
// 				level3[level3Key] = append(level3[level3Key], v.ContentName)
// 			}
// 		}
// 		if v.Weight > 0 {
// 			level3Key := v.Category + "-得分项"
// 			if _, ok := level3[level3Key]; !ok {
// 				level3[level3Key] = []string{}
// 			}
// 			level3Item := ""
// 			for _, v3 := range level3[level3Key] {
// 				if v3 == v.ContentName {
// 					level3Item = v.ContentName
// 				}
// 			}
// 			if len(level3Item) == 0 {
// 				level3[level3Key] = append(level3[level3Key], v.ContentName)
// 			}
// 		}

// 		level4Key := v.Category + "+" + v.ContentName
// 		if _, ok := level4[level4Key]; !ok {
// 			level4[level4Key] = v.PromptText
// 		}
// 	}
// 	//汇总表头,按列
// 	headerList := []excelTableHeader{
// 		{
// 			Level1: "日期",
// 			Level2: "",
// 			Level3: "",
// 			Level4: "评估标准",
// 		}, {
// 			Level1: "姓名",
// 			Level2: "",
// 			Level3: "",
// 			Level4: "",
// 		},
// 	}
// 	for _, v := range level1 {
// 		item := excelTableHeader{
// 			Level1: v,
// 		}
// 		level3Key := v + "-加分项"
// 		if _, ok := level3[level3Key]; ok {
// 			for _, v2 := range level3[level3Key] {
// 				item.Level2 = "加分项"
// 				item.Level3 = v2
// 				level4Key := v + "+" + v2
// 				item.Level4 = level4[level4Key]
// 				headerList = append(headerList, item)
// 			}
// 		}
// 		level3Key = v + "-得分项"
// 		if _, ok := level3[level3Key]; ok {
// 			for _, v2 := range level3[level3Key] {
// 				item.Level2 = "得分项"
// 				item.Level3 = v2
// 				level4Key := v + "+" + v2
// 				item.Level4 = level4[level4Key]
// 				headerList = append(headerList, item)
// 			}
// 		}
// 	}
// 	//数据形式 进行 行列转换
// 	tableRows := map[string]map[string]string{}
// 	tableRowSort := []string{}
// 	for _, v := range contentList {
// 		if _, ok := tableRows[v.TargetUserId]; !ok {
// 			tableRows[v.TargetUserId] = map[string]string{}
// 			tableRowSort = append(tableRowSort, v.TargetUserId)
// 		}
// 		tableRows[v.TargetUserId]["TargetUserName"] = v.TargetUserName
// 		tableRows[v.TargetUserId]["BeginDay"] = v.BeginDay
// 		if v.ContentId > 0 {
// 			if len(includeCol) > 0 {
// 				if _, ok := includeCol[v.Category+"+"+v.ContentName]; !ok {
// 					continue
// 				}
// 			}
// 			value := []string{v.Value}
// 			for _, v2 := range v.Remark {
// 				value = append(value, v2.RemarkText)
// 			}
// 			key := v.Category + "+" + v.ContentName
// 			tableRows[v.TargetUserId][key] = strings.Join(value, "\n")
// 		}
// 	}
// 	//将数据写入xlsx
// 	xlsxFile := excelize.NewFile()
// 	sheetIndex := xlsxFile.GetActiveSheetIndex()
// 	sheetName := xlsxFile.GetSheetName(sheetIndex)
// 	//写入第一行
// 	xlsxFile.SetCellStr(sheetName, "A1", "每日绩效汇总")
// 	//写入二到五行
// 	for k, v := range headerList {
// 		colName, _ := excelize.ColumnNumberToName(k + 1)
// 		xlsxFile.SetCellStr(sheetName, colName+"2", v.Level1)
// 		xlsxFile.SetCellStr(sheetName, colName+"3", v.Level2)
// 		xlsxFile.SetCellStr(sheetName, colName+"4", v.Level3)
// 		xlsxFile.SetCellStr(sheetName, colName+"5", v.Level4)
// 	}
// 	//从第六行开始写入用户填写的评估数据
// 	for k, v := range tableRowSort {
// 		rowNum := strconv.Itoa(k + 6)
// 		row := tableRows[v]
// 		for k2, v2 := range headerList {
// 			if k2 == 0 {
// 				xlsxFile.SetCellStr(sheetName, "A"+rowNum, row["BeginDay"])
// 				continue
// 			}
// 			if k2 == 1 {
// 				xlsxFile.SetCellStr(sheetName, "B"+rowNum, row["TargetUserName"])
// 				continue
// 			}
// 			colName, _ := excelize.ColumnNumberToName(k2 + 1)
// 			key := v2.Level1 + "+" + v2.Level3
// 			if mVal, ok := row[key]; ok {
// 				xlsxFile.SetCellStr(sheetName, colName+rowNum, mVal)
// 			}
// 		}
// 	}
// 	//TODO 调整样式
// 	xlsxFile.MergeCell(sheetName, "A2", "A4")
// 	xlsxFile.MergeCell(sheetName, "B2", "B4")
// 	xlsxFile.MergeCell(sheetName, "B5", "B5")
// 	//设置行高
// 	for i := range tableRowSort {
// 		xlsxFile.SetRowHeight(sheetName, i+5, 50)
// 	}
// 	//设置列宽
// 	for i := range headerList {
// 		colName, _ := excelize.ColumnNumberToName(i + 1)
// 		if i == 0 {
// 			xlsxFile.SetColWidth(sheetName, colName, colName, 30)
// 		}
// 	}
// 	return xlsxFile, nil
// }

//员工绩效-项目管理-矩阵分析

func (srv StaffAssessServeice) AnalysisData(param *query.ListAssessContentCycleDay) (*adapter.AssessAnalysisResp, 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()
	}()

	hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperaterId)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	assessDao := dao.NewStaffAssessDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	contentList, err := assessDao.SearchUserAssessContent(dao.SearchConditin1{
		CompanyId:      param.CompanyId,
		CycleId:        param.CycleId,
		BeginDay:       param.BeginDay,
		TargetUserName: param.TargetUserName,
		Limit:          9000,
		Offset:         0,
		OperaterId:     param.OperaterId,
		Hrbp:           hrbp,
	})
	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())
	}
	log.Logger.Debug(fmt.Sprintf("获取到的数据列表%d", len(contentList)))

	var groupList []string                               //评估指标项列表
	var uncompleteItems []string                         //未完成填写评估的员工
	completeUser := map[string]struct{}{}                //完成填写评估的员工
	completeItems := map[string]adapter.AssessComplete{} //已完成填写的评估内容

	for _, v := range contentList {
		if v.ContentId == 0 {
			uncompleteItems = append(uncompleteItems, v.TargetUserName)
			continue
		}
		completeUser[v.TargetUserId] = struct{}{}
		key := v.Category + "-" + v.ContentName

		if _, ok := completeItems[key]; !ok {
			groupList = append(groupList, key)
			//初始化数据结构
			completeItems[key] = adapter.AssessComplete{
				GroupKey:    key,
				Items:       []string{},
				UserItem:    map[string][]string{},
				PercentItem: map[string]string{},
				CountItem:   map[string]int{},
			}
		}
		completeItem := completeItems[key]
		if v.Rule.Type == domain.EvaluationTypeRating {
			//提取出所有可选的评级
			for _, v2 := range v.Rule.Rating.Levels {
				if _, ok := completeItem.CountItem[v2.Code]; !ok {
					completeItem.CountItem[v2.Code] = 0
					completeItem.PercentItem[v2.Code] = ""
					completeItem.UserItem[v2.Code] = []string{}
					completeItem.Items = append(completeItem.Items, v2.Code)
				}
			}
		}
		if v.Rule.Type == domain.EvaluationTypeScore {
			for _, v2 := range v.Rule.Score.Levels {
				//提取出所有可选的评级
				if _, ok := completeItem.CountItem[v2.Code]; !ok {
					completeItem.CountItem[v2.Code] = 0
					completeItem.PercentItem[v2.Code] = ""
					completeItem.UserItem[v2.Code] = []string{}
					completeItem.Items = append(completeItem.Items, v2.Code)
				}
			}
		}
		//根据填写的评级填充数据
		completeItem.TotalUser = completeItem.TotalUser + 1
		completeItem.CountItem[v.LevelValue] = completeItem.CountItem[v.LevelValue] + 1
		percentSum := float64(completeItem.CountItem[v.LevelValue]) / float64(completeItem.TotalUser) * 100
		completeItem.PercentItem[v.LevelValue] = fmt.Sprintf("%.2f %%", percentSum)
		completeItem.UserItem[v.LevelValue] = append(completeItem.UserItem[v.LevelValue], v.TargetUserName)
		completeItems[key] = completeItem
	}
	result := adapter.AssessAnalysisResp{
		GroupList:  groupList,
		Uncomplete: uncompleteItems,
		Complete:   completeItems,
		UserCount: map[string]int{
			"total":      len(uncompleteItems) + len(completeUser),
			"uncomplete": len(uncompleteItems),
			"complete":   len(completeUser),
		},
	}
	return &result, nil
}

// 员工绩效-综合管理-导出绩效-个人
func (srv StaffAssessServeice) ExportUserAssess2(param *query.ExportUserAssess2Commad) (*excelize.File, 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()
	}()
	hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperatorId)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	assessDao := dao.NewStaffAssessDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	// 获取所有的评估项
	categoryNameList, err := assessDao.SearchContentCategoryName(param.CompanyId, param.CycleId, param.OperatorId, hrbp)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	//获取员工填写的评估
	userAssessList, err := assessDao.ExportDataUserAssess2(
		param.CompanyId,
		param.CycleId,
		param.OperatorId,
		hrbp,
		param.ExportUserId,
	)
	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())
	}
	eData := newExportData()
	eData.setCategoryNameList(categoryNameList)
	eData.setData(userAssessList)
	xlsxFile := excelize.NewFile()
	//设置默认的第一个sheet
	sheetIndex := xlsxFile.GetActiveSheetIndex()
	firstSheetName := xlsxFile.GetSheetName(sheetIndex)
	cycleName := ""
	if len(userAssessList) > 0 {
		cycleName = userAssessList[0].CycleName
	}
	//填入excel 文件
	for _, v := range eData.userName {
		// 根据员工名称 添加一个sheet
		xlsxFile.NewSheet(v)
		//填写前4行数据
		tableHeader, ok := eData.tableHeader[v]
		if !ok {
			continue
		}
		xlsxFile.SetCellStr(v, "B2", v)
		xlsxFile.MergeCell(v, "B2", "B4")
		//填充第一列数据
		xlsxFile.SetCellStr(v, "A1", tableHeader.Name)
		xlsxFile.SetCellStr(v, "A2", cycleName)
		xlsxFile.MergeCell(v, "A2", "A4")
		xlsxFile.SetCellStr(v, "A5", "权重")
		xlsxFile.MergeCell(v, "A5", "B5")
		xlsxFile.SetCellStr(v, "A6", "评估标准")
		xlsxFile.MergeCell(v, "A6", "B6")
		//日期
		dayList := eData.userDayMap[v]
		for ii, vv := range dayList {
			//填写在第几行
			axisNum := 7 + 3*ii
			axis := fmt.Sprintf("A%d", axisNum)
			xlsxFile.SetCellStr(v, axis, vv)
			axisEnd := fmt.Sprintf("B%d", axisNum+2)
			xlsxFile.MergeCell(v, axis, axisEnd) //单元格高度按三个单元格合并
		}
		allColNum := 0 //计算总共有多少列
		//第一行
		for _, v2 := range tableHeader.Child {

			//第二行
			for _, v3 := range v2.Child {
				//第三行
				for _, v4 := range v3.Child {
					allColNum++
					//按列填充数据
					colName, _ := excelize.ColumnNumberToName(allColNum + 2) //第3列开始
					xlsxFile.SetCellStr(v, colName+"2", v2.Name)             //分类
					xlsxFile.SetCellStr(v, colName+"3", v3.Name)             //加分项 得分项
					xlsxFile.SetCellStr(v, colName+"4", v4.Name)             // 评估项名称
					//权重 填写第5行数据
					k23 := eData.data23Key(v, v2.Name, v3.Name, v4.Name)
					xlsxFile.SetCellStr(v, colName+"5", eData.data3[k23])
					//评估标准 填写第6行数据
					xlsxFile.SetCellStr(v, colName+"6", eData.data2[k23])
					//按日期填充评估的填写的值
					for i5, v5 := range dayList {
						k1 := eData.dataKey(v, v5, v2.Name, v3.Name, v4.Name)
						//填写在第几行
						axisNum := 7 + 3*i5
						axis := fmt.Sprintf("%s%d", colName, axisNum)
						if d, ok := eData.data[k1]; ok {
							xlsxFile.SetCellStr(v, axis, d.String())
						}
						//单元格高度按三个单元格合并
						axisEnd := fmt.Sprintf("%s%d", colName, axisNum+2)
						xlsxFile.MergeCell(v, axis, axisEnd)
					}
				}
			}
		}
		//
		colName, _ := excelize.ColumnNumberToName(allColNum + 2)
		xlsxFile.MergeCell(v, "A1", fmt.Sprintf("%s1", colName))
	}
	//删除默认的第一个sheet
	xlsxFile.DeleteSheet(firstSheetName)
	return xlsxFile, nil
}

// 获取所有的评估的指标
func (srv StaffAssessServeice) QueryPerformanceIndicator(param *query.ListAssessContentCycleDay) (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()
	}()

	hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperaterId)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	assessDao := dao.NewStaffAssessDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})

	contentItems, err := assessDao.SearchUserAssessContentItem(dao.SearchConditin1{
		CompanyId:  param.CompanyId,
		CycleId:    param.CycleId,
		BeginDay:   param.BeginDay,
		OperaterId: param.OperaterId,
		Hrbp:       hrbp,
	})
	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())
	}

	headerList := HeaderLevel{
		Name:   "",
		Filter: map[string]int{},
		Child:  []HeaderLevel{},
	}
	for _, v := range contentItems {
		child := headerList.addChild(v.Category)
		child.addChild(v.Name)
	}
	result := map[string]interface{}{
		"headerList": headerList.Child,
	}
	return result, nil
}

// 员工绩效-项目管理-成员列表导出

func (srv StaffAssessServeice) ExportUserAssess(param *query.ExportAssessContentCycleDay) (*excelize.File, 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()
	}()

	hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperaterId)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}

	assessDao := dao.NewStaffAssessDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	contentList, err := assessDao.ExportDataUserAssess(dao.SearchConditin1{
		CompanyId:      param.CompanyId,
		CycleId:        param.CycleId,
		BeginDay:       "",
		TargetUserName: param.TargetUserName,
		TargetUserId:   param.TargetUserId,
		Limit:          5000,
		Offset:         0,
		OperaterId:     param.OperaterId,
		Hrbp:           hrbp,
	})
	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())
	}
	//选择导出的评估项
	includeCol := map[string]struct{}{}
	for _, v := range param.ExportItems {
		includeCol[v.Category+"+"+v.Name] = struct{}{}
	}
	includeBeginDay := map[string]struct{}{}
	for _, v := range param.BeginDayList {
		includeBeginDay[v] = struct{}{}
	}

	eData := newExportData2()
	eData.setData(contentList)
	//将数据写入xlsx
	xlsxFile := excelize.NewFile()
	sheetIndex := xlsxFile.GetActiveSheetIndex()
	sheetName := xlsxFile.GetSheetName(sheetIndex)
	//写入第一行
	xlsxFile.SetCellStr(sheetName, "A1", "每日绩效汇总")
	xlsxFile.SetCellStr(sheetName, "A2", "日期")
	xlsxFile.MergeCell(sheetName, "A2", "A4")
	xlsxFile.SetCellStr(sheetName, "B2", "姓名")
	xlsxFile.MergeCell(sheetName, "B2", "B4")
	xlsxFile.SetCellStr(sheetName, "A5", "评估标准")

	//行数量
	rowNum := 0
	for _, v := range eData.rowSort.Child {
		//纵向-索引-第一列-日期
		if len(includeBeginDay) > 0 {
			if _, ok := includeBeginDay[v.Name]; !ok {
				continue
			}
		}
		for _, v2 := range v.Child {
			//纵向-索引-第二列-员工id
			//填充1,2 列
			rowNum++
			axisNum := fmt.Sprintf("%d", rowNum+5)
			userName := eData.userIdMap[v2.Name]
			xlsxFile.SetCellStr(sheetName, "A"+axisNum, v.Name)
			xlsxFile.SetCellStr(sheetName, "B"+axisNum, userName)
		}
	}
	//列数量
	colNum := 0
	for _, v := range eData.tableHeader.Child {
		//横向-评估指标-分类
		for _, v2 := range v.Child {
			//横向-评估指标-加分项、得分项
			for _, v3 := range v2.Child {
				// 横向-评估指标-名称
				//检查是否在指定的导出选项中
				if len(includeCol) > 0 {
					if _, ok := includeCol[v.Name+"+"+v3.Name]; !ok {
						continue
					}
				}
				colNum++
				//第几列
				colName, _ := excelize.ColumnNumberToName(colNum + 2)
				//填充 分类
				xlsxFile.SetCellStr(sheetName, colName+"2", v.Name)
				// 填充 加分项、得分项
				xlsxFile.SetCellStr(sheetName, colName+"3", v2.Name)
				// 填充 名称
				xlsxFile.SetCellStr(sheetName, colName+"4", v3.Name)
				if len(v3.Child) > 0 {
					//填充, 评估标准
					xlsxFile.SetCellStr(sheetName, colName+"5", v3.Child[0].Name)
				}
				xlsxFile.SetColWidth(sheetName, colName, colName, 30)
				rowNum = 0
				for _, v4 := range eData.rowSort.Child {
					//纵向-索引-第一列-日期
					if len(includeBeginDay) > 0 {
						if _, ok := includeBeginDay[v.Name]; !ok {
							continue
						}
					}
					for _, v5 := range v4.Child {
						//纵向-索引-第二列-员工id
						rowNum++
						axis := fmt.Sprintf("%s%d", colName, rowNum+5)
						key := eData.dataKey(v5.Name, v4.Name, v.Name, v3.Name)
						if d, ok := eData.data[key]; ok {
							xlsxFile.SetCellStr(sheetName, axis, d.String())
						}
						xlsxFile.SetRowHeight(sheetName, rowNum+5, 50)
					}
				}
			}
		}
	}
	xlsxFile.MergeCell(sheetName, "A1", fmt.Sprintf("A%d", colNum))
	return xlsxFile, nil
}